0 Members and 2 Guests are viewing this topic.
add_unit = Dialog("Add unit","10","7.5","80","85")unit_value = sInput()unit_value.ww = "77"unit_value.number = trueunits_list = sList()units_list.hh = "41"units_list.ww = "77"units_list.shrink = truelbl1 = sLabel("Value:", unit_value)lbl2 = sLabel("Unit:", units_list)button_ok = sButton("OK", compute)button_esc = sButton("Cancel", remove_screen)add_unit:appendWidget(lbl1, "2", "18")add_unit:appendWidget(lbl2, "2", "38")add_unit:appendWidget(unit_value, "20", "18")add_unit:appendWidget(units_list, "20", "38")add_unit:appendWidget(button_ok, "60", "82")add_unit:appendWidget(button_esc, "75", "82")
function NumericUD:init(x, y, num, selected, linecolor, maxnum, minnumber, textcolor, pmbcolor) self.x = x self.y = y self.pmbcolor = pmbcolor self.num = num self.text = tostring(num) self.selected = selected self.linecolor = linecolor self.maxnum = maxnum self.minnumber = minnumber self.textcolor = textcolor self.width = 42 self.height = 23 table.insert(NUDTable, self)endfunction NumericUD:paint(gc) gc:setPen("thin", "smooth") gc:setColorRGB(unpack(self.pmbcolor)) gc:drawLine(self.x + 35, self.y, self.x + 35, self.y + 23) gc:drawLine(self.x + 35, self.y + 11, self.x + 42, self.y + 11) gc:setFont("serif", "r", 6) gc:drawString("+", self.x + 36, self.y - 2, "top") gc:drawString("-", self.x + 36, self.y + 10, "top") gc:setColorRGB(unpack(self.linecolor)) gc:drawRect(self.x, self.y, self.width, self.height) gc:setColorRGB(unpack(self.textcolor)) gc:setFont("serif", "r", 11) gc:drawString(self.text, self.x + 2, self.y + 2, "top")endfunction NumericUD:click(x, y) if y >= self.y and y <= self.y + 11 and x >= self.x + 35 and x <= self.x + 40 then self:Up() elseif y >= self.y + 11 and y <= self.y + 23 and x >= self.x + 35 and x <= self.x + 40 then self:Down() endendfunction NumericUD:Up() if self.num ~= self.maxnum then self.num = self.num + 1 self.text = tostring(self.num) end platform.window:invalidate()endfunction NumericUD:Down() if self.num ~= self.minnumber then self.num = self.num - 1 self.text = tostring(self.num) end platform.window:invalidate()endfunction drawNUD(gc) for _, NUD in pairs(NUDTable) do NUD:paint(gc) endend
----colors:color = { black = {0, 0, 0}, lightgreen = {0, 255, 0},}-----------dialog codedialog = class()function dialog:init( x, y, text, title, isselected, backcolor, textcolor, closecolor, isdrawn)--add buttons and other features self.x = x self.y = y self.text = text self.title = title self.width = 200 self.height = 150 self.cbw = 10 self.cbh = 10 self.cbx = self.x + 175 self.cby = self.y + 7 self.selected = isselected self.backcolor = backcolor self.textcolor = textcolor self.closecolor = closecolor self.isdrawn = isdrawn self.moveable = false table.insert(dialogTable, self)endfunction dialog:paint(gc) if self.isdrawn then gc:setFont("sansserif", "b", 12) gc:setColorRGB(unpack(self.backcolor)) gc:fillRect( self.x, self.y, self.width, self.height) gc:setColorRGB(unpack(color.white)) gc:fillRect( self.x + 5, self.y + 20, self.width - 10, self.height - 30) gc:setColorRGB(unpack(self.textcolor)) if string.len(self.title) > 10 then self.title = string.sub(self.title, 1, 10).."..." end gc:drawString(self.title, self.x + 10, self.y + 8, "middle") gc:drawString(self.text, self.x + 9, self.y + 25, "middle") gc:setColorRGB(unpack(self.closecolor)) gc:fillArc( self.cbx, self.cby, self.cbw, self.cbh, 0, 360) endendfunction dialog:checkUnclick() self.moveable = false cursor.set("default") self.selected = false platform.window:invalidate()endfunction dialog:checkClick(x, y) if self.isdrawn then if (x >= self.cbx and x <= self.cbx + 10) and (y >= self.cby and y <= self.cby + 10) then self:close() elseif self.moveable == false and (x >= self.x and x <= self.x + self.width) and (y >=self.y and y <= self.y + (self.height - 130)) then self:wasclicked(x, y) else self:checkUnclick() end endendfunction dialog:close() self.selected = false self.isdrawn = false self.moveable = false cursor.set("default") platform.window:invalidate()endfunction dialog:wasclicked(x, y) self.moveable = true if self.selected ~= self then for _, dlg in pairs(dialogTable) do dlg.selected = false end self.selected = true end self.xvar = x - self.x self.yvar = y - self.y cursor.set("drag grab") platform.window:invalidate()endfunction dialog:mouseMove(x, y) if self.moveable and self.isdrawn and self.selected then cursor.set("drag grab") self.x = x - self.xvar self.y = y - self.yvar self.cbx = self.x + 175 self.cby = self.y + 7 platform.window:invalidate() endendfunction drawDialog(gc) for _, SD in pairs(dialogTable) do if SD.isdrawn then SD:paint(gc) end endend---------------------------create the dialog boxfunction on.create() dia1 = dialog(45, 23, "Color change", "Colors", false, color.lightgreen, color.red, color.red, true)end----------------------------say a function changes the color like this later on if it is calledfunction color_change() dia1.backcolor = color.black -----after that the color of the boarder would be blackend
textbox = class()function textbox:init(x, y, text, selected, textcolor, tbcolor) self.x = x self.y = y self.width = 156 self.height = 20 self.text = text self.textcolor = textcolor self.tbcolor = tbcolor self.selected = isselected self.curx = self.x + platform.gc():getStringWidth(self.text) self.cury = y + 1 self.curh = (self.y + self.height) - 1 table.insert(textboxTable, self)endfunction textbox:paint(gc) gc:setColorRGB(unpack(self.tbcolor)) gc:drawRect( self.x, self.y, self.width, self.height) gc:setColorRGB(unpack(self.textcolor)) gc:setFont("serif", "r", 11) gc:drawString( self.text, self.x + 4, self.y + 8, "middle") gc:setColorRGB(unpack(color.black)) gc:drawLine(self.curx, self.cury, self.curx, self.curh)endfunction textbox:charIn(ch) if self.selected then if (self.width - 8) < platform.gc():getStringWidth(self.text) then platform.window:invalidate() else self.text = self.text..ch self.curx = self.x + platform.gc():getStringWidth(self.text) + 2 platform.window:invalidate() end endendfunction textbox:backspace() if self.selected then self.text = string.sub(self.text, 1, string.len(self.text) - 1) self.curx = self.x + platform.gc():getStringWidth(self.text) + 2 platform.window:invalidate() endendfunction textbox:click() if self.selected then self.selected = false else for _, tb in pairs(textboxTable) do tb.selected = false end self.selected = true end platform.window:invalidate()endfunction textbox:checkClick(x, y) if y >= self.y and y <= self.y + self.height and x >= self.x and x <= self.x + self.width then self:click() endend