--WZGUIlib --copyright 2011, Jonathan Walker --WZ classes --Not Complete yet color = { black = { 0, 0, 0}, red = { 255, 0, 0}, green = { 0, 255, 0}, blue = { 0, 0, 255}, white = { 255, 255, 255}, aqua = { 0, 255, 255}, hotpink = { 255, 0, 255}, yellow = { 255, 255, 0}, cream = { 255, 255, 200}, brickred = { 50, 25, 30}, brown = { 50, 35, 30}, purple = { 75, 0, 100}, Bcontrol = { 150, 150, 150}, Bdark = { 75, 75, 75}} --this is the color table *incomplete --------------------------- --The table we keep all references to created buttons in ButtonTable = {} lblTable = {} textboxTable = {} radiobTable = {} dialogTable = {} checkboxtable = {} pboxtbl = {} NUDTable = {} --Create the classes window = class() wndTbl = {} function window:init(x, y, width, height, isdrawn, focused) self.x = x self.y = y self.wbx = x self.wby = y self.width = width self.height = height self.isdrawn = isdrawn self.controls = {} self.dialogs = {} self.focused = focused self.type = "MW" table.insert(wndTbl, self) end function window:paint(gc) self:drawControls(gc) for _, Dialog in pairs(self.dialogs) do Dialog:paint(gc) end end function window:drawControls(gc) for _, control in pairs(self.controls) do control:paint(gc) end end function window:udateControl(control) control.x = control.xoff + self.x control.y = control.yoff + self.y end function window:enterKey() for _, control in pairs(self.controls) do if control.selected then control:enterKey() break end end end function window:mouseDown(x, y) for _, control in pairs(self.controls) do if control.parent.focused and control.type ~= "vo\nc" then control:checkClick(x, y) end end for _, dialog in pairs(self.dialogs) do if dialog.isdrawn then-- and dialog.selected then dialog:checkClick(x, y) break end end I() end function window:charIn(ch) for _, control in pairs(self.controls) do if control.selected and control.type == "txt"then control:charIn(ch) break end end end function window:backspaceKey() for _, control in pairs(self.controls) do if control.selected and control.type == "txt" then control:backspaceKey() break end end end function window:getFocus() if curwin() == nil then self.focused = wndTbl[1] end if curwin().allowevents then curwin().focused = false local ltblhold = {} table.insert(ltblhold, self) for i = 1, #wndTbl do if wndTbl[i] == self then b = i break end end table.remove(wndTbl, b) table.insert(wndTbl, ltblhold[1]) return true end end function curwin() for _, wnd in pairs(wndTbl) do if wnd.focused then return wnd end end end function I() platform.window:invalidate() end -------------------------------Button----------------------- button = class() --Create and init the button function button:init(text, x, y, action, txtcolor, bgcolor, opt3D, parent) self.text = text self.parent = parent self.x = x + parent.x self.y = y + parent.y self.xoff = x self.yoff = y self.action = action self.labelwidth = 0 self.width = 0 self.height = 20 self.txtcolor = txtcolor self.bgcolor = bgcolor self.opt3D = opt3D self.type = "ci" table.insert(parent.controls, self) end --Draw the button function button:paint(gc) if not(self.opt3D) then gc:setFont("sansserif", "b", 12) self.labelwidth = gc:getStringWidth(self.text) self.width = self.labelwidth + 6 gc:setColorRGB(unpack(self.bgcolor)) gc:fillRect(self.x, self.y, self.width, self.height) gc:setColorRGB(unpack(color.black)) gc:setPen("thin", "smooth") gc:drawRect(self.x, self.y, self.width, self.height) gc:setColorRGB(unpack(self.txtcolor)) gc:drawString(self.text, self.x + 2, self.y - 1, "top") else gc:setFont("sansserif", "b", 12) self.labelwidth = gc:getStringWidth(self.text) self.width = self.labelwidth + 6 gc:setColorRGB( unpack(self.bgcolor)) gc:fillRect(self.x - 2, self.y - 2, self.width + 2, self.height + 2) gc:setColorRGB(unpack(color.black)) gc:setPen("thin", "smooth") gc:drawRect(self.x, self.y, self.width, self.height) gc:drawLine(self.x, self.y, self.x - 2, self.y - 2) gc:drawRect(self.x - 2, self.y - 2, self.width + 2, self.height + 2) gc:setColorRGB(unpack(self.txtcolor)) gc:drawString(self.text, self.x + 2, self.y - 1, "top") end end function button:click() self.action() end function button: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() end end ----------------------Lable------------------------------- lable = class() function lable:init(x, y, text, txtsize, color, parent) self.x = x + parent.x self.y = y + parent.y self.xoff = x self.yoff = y self.text = text self.txtsize = txtsize self.color = color self.selected = false self.type = "vo\nc" self.parent = parent table.insert(parent.controls, self) end function lable:paint(gc) gc:setColorRGB(unpack(self.color)) gc:setFont("sansserif", "r", self.txtsize) if string.find(self.text, "\n") ~= nil then local offset = gc:getStringHeight(self.text) + 1 local hold = {} hold = string.split(self.text, "\n") gc:drawString(hold[1], self.x, self.y, "middle") for i = 2, table.maxn(hold) do gc:drawString(hold[i], self.x, self.y + offset, "middle") offset = offset + gc:getStringHeight(self.text) end else gc:drawString(self.text, self.x, self.y, "middle") end end ----------------------textbox *incomplete------------------------------------------- textbox = class() function textbox:init(x, y, text, textcolor, tbcolor, parent, selected) self.parent = parent self.x = x + parent.x self.y = y + parent.y self.xoff = x self.yoff = y self.width = 156 self.height = 20 self.text = text self.textcolor = textcolor self.tbcolor = tbcolor self.selected = selected self.cury = self.y + 1 self.curx = self.x + 1 self.curh = (self.y + self.height) - 1 self.parent = parent self.type = "txt" self.stwid = 0 table.insert(parent.controls, self) end function 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("sansserif", "r", 11) self.stwid = gc:getStringWidth(self.text) gc:drawString( self.text, self.x + 4, self.y + 8, "middle") gc:setColorRGB(unpack(color.black)) self.cury = self.y + 1 self.curx = self.x + self.stwid + 3 self.curh = (self.y + self.height) - 1 gc:drawLine(self.curx, self.cury, self.curx, self.curh) end function textbox:charIn(ch) if self.selected then if (self.width - 8) < self.stwid then else self.text = self.text..ch end end end function textbox:backspaceKey() if self.selected then self.text = string.sub(self.text, 1, string.len(self.text) - 1) end end function textbox:click() if self.selected then self.selected = false else for _, tb in pairs(textboxTable) do tb.selected = false end self.selected = true end end function 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() end end -----------------------Radio Button------------------------------------------------ radioButton = class() function radioButton:init( text, x, y, marked, backcolor, markcolor, txtcolor, parent) self.text = text self.x = x + parent.x self.y = y + parent.y self.xoff = x self.yoff = y self.marked = marked self.parent = parent self.backcolor = backcolor self.markcolor = markcolor self.txtcolor = txtcolor self.height = 10 self.width = 10 self.type = "ci" table.insert(parent.controls, self) end function radioButton:paint(gc) gc:setColorRGB(unpack(self.backcolor)) gc:fillArc( self.x, self.y, self.width, self.height, 0, 360) if self.marked then gc:setColorRGB(unpack(self.markcolor)) gc:fillArc( self.x+2, self.y+2, 5, 5, 0, 360) else gc:setColorRGB(unpack(color.white)) gc:fillArc( self.x+2, self.y+2, 5, 5, 0, 360) end gc:setColorRGB(unpack(self.txtcolor)) gc:setFont( "sansserif", "r", 9) gc:drawString(self.text, self.x + 15, self.y, "middle") end function radioButton:click() if self.marked then self.marked = false else for _, rd in pairs(self.parent.controls) do rd.marked = false end self.marked = true end end function radioButton: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() end end ------------------------Dialog Box-----------------------------------------------* incomplete dialog = class() function dialog:init( x, y, text, title, backcolor, textcolor, isdrawn, parent, selected)--add buttons and other features self.titlex = x self.titley = y self.text = text self.title = title self.titlewidth = 200 self.titleheight = 20 self.x = self.titlex + 1 self.y = self.titley + 20 self.height = 156 self.width = self.titlewidth - 2 self.cbw = 5 self.cbh = 5 self.cbx = self.titlex + (self.width / 2)-- in the future this may become the "form" class so having the button centered is important, also this may change to a rectangle self.cby = self.titley + 6 self.selected = selected self.backcolor = backcolor self.textcolor = textcolor self.isdrawn = isdrawn self.moveable = false self.parent = parent self.type = "wo" table.insert(parent.dialogs, self) end function dialog:paint(gc) if self.isdrawn then gc:setFont("sansserif", "b", 6) gc:setColorRGB(unpack(self.backcolor)) gc:fillRect( self.titlex, self.titley, self.titlewidth, self.height) gc:setColorRGB(unpack(color.Bcontrol)) gc:fillRect( self.x, self.y, self.width, self.height - 22) 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.titlex + 4, self.titley + 8, "middle") if string.find(self.text, "\n") ~= nil then local offset = gc:getStringHeight(self.text) + 1 local hold = {} hold = string.split(self.text, "\n") gc:drawString(hold[1], self.x + 2, self.y + 2, "middle") for i = 2, table.maxn(hold) do gc:drawString(hold[i], self.x + 2, self.y + offset, "middle") offset = offset + gc:getStringHeight(self.text) end else gc:drawString(self.text, self.x + 2, self.y + 5, "middle") end gc:setColorRGB(unpack(color.red)) gc:fillArc( self.cbx, self.cby, self.cbw, self.cbh, 0, 360) end end function dialog:checkUnclick() self.moveable = false cursor.set("default") self.selected = false platform.window:invalidate() end function dialog:checkClick(x, y) if self.isdrawn then if (x >= self.cbx and x <= self.cbx + 5) and (y >= self.cby and y <= self.cby + 5) then self:close() elseif self.moveable == false and (x >= self.titlex and x <= self.titlex + self.titlewidth) and (y >=self.titley and y <= self.titley + 20) then self:wasclicked(x, y) else self:checkUnclick() end end end function dialog:close() self.selected = false self.isdrawn = false self.moveable = false cursor.set("default") end function dialog:wasclicked(x, y) self.moveable = true if self.selected ~= self then for _, dlg in pairs(self.parent.dialogs) do dlg.selected = false end self.selected = true end self.xvar = x - self.titlex self.yvar = y - self.titley cursor.set("drag grab") end function dialog:mouseMove(x, y) if self.moveable and self.isdrawn and self.selected then cursor.set("drag grab") self.titlex = x - self.xvar self.titley = y - self.yvar self.cbx = self.titlex + (self.titlewidth / 2)--this also may change with the introduction of a screen manager and the form class wich will containg smaller controlls self.cby = self.titley + 6 self.x = self.titlex + 1 self.y = self.titley + 20 I() end end -----------------------------------Form------------------------------ form = class(window) function form:init(x, y, width, height, fullscreen, title, titlecolor, bordercolor, isdrawn, contextmenu, cmtable) self.fullscreen = fullscreen self.titlecolor = titlecolor self.x = x + 1 self.y = y + 20 self.height = height self.width = width - 2 --self.savedflag = 0 if self.fullscreen then--if self.fullscreen and self.savedflag == 0 then self:saveSettings() self.savedflag = 1 end if self.x == platform.window:width() and self.y == platform.window:height() then self.valsavelist = { x = {0}, y = {0}, width = {100}, height = {100}} -- self.savedflag = 1 self.fullscreen = true end self.titlebarx = x self.titlebary = y self.titlebarwidth = width self.titlebarheight = 20 self.title = title self.cirbwidth = 5 self.cirbheight = 5 self.cirbx = self.titlebarx + (self.titlebarwidth / 2) - 4 self.cirby = self.titlebary + self.titlebarheight / 4 self.bordercolor = bordercolor self.isdrawn = isdrawn self.contextmenu = contextmenu self.cmtable = cmtable self.valsavelist = {} self.controls = {} self.dialogs = {} self.allowevents = true self.moveable = false if self.contextmenu then mycm = contextm( self, self.cmtable) end self.focused = false self.type = "wo" table.insert(wndTbl, self) end function form:paint(gc) if self.isdrawn then if self.fullscreen then if not(self.focused) then self.focused = self:getFocus() end self.allowevents = false elseif not(self.fullscreen) then self.allowevents = true end if self.focused then gc:setColorRGB(unpack(self.bordercolor)) else gc:setColorRGB(unpack(color.Bdark)) end if not(self.fullscreen) then gc:fillRect(self.titlebarx, self.titlebary, self.titlebarwidth, self.height) gc:setColorRGB(unpack(color.Bcontrol)) gc:fillRect(self.x, self.y, self.width, self.height - 22) else gc:fillRect(self.titlebarx, self.titlebary, platform.window:width(), platform.window:height()) gc:setColorRGB(unpack(color.Bcontrol)) gc:fillRect(self.x, self.y, self.width, self.height - 22) end if self.fullscreen or self.x == platform.window:width() and self.y == platform.window:height() then gc:setColorRGB(unpack(color.yellow)) else gc:setColorRGB(unpack(color.green)) end gc:fillArc(self.cirbx, self.cirby, self.cirbwidth, self.cirbheight, 0, 360) gc:setColorRGB(unpack(color.red)) gc:fillArc(self.cirbx + 8, self.cirby, self.cirbwidth, self.cirbheight, 0, 360) for _, dialog in pairs(self.dialogs) do dialog:paint(gc) end gc:setColorRGB(unpack(self.titlecolor)) gc:setFont("sansserif", "r", 6) gc:drawString(self.title, self.titlebarx + 3, self.cirby, "top") if self.contextmenu then mycm.x = self.x mycm.y = self.y mycm.width = self.width end for _, control in pairs(self.controls) do if not(control == mycm) then self:udateControl(control) end end for _, control in pairs(self.controls) do control:paint(gc) end for _, dialog in pairs(self.dialogs) do dialog:paint(gc) end end end function form:checkUnclick() self.moveable = false cursor.set("default") I() end function form:close() self.focused = false self.isdrawn = false self.moveable = false cursor.set("default") for _, dialog in pairs(self.dialogs) do dialog.isdrawn = false end I() end function form:wasclicked(x, y) if not(self.focused) then self.focused = self:getFocus() end self.moveable = true self.xvar = x - self.titlebarx self.yvar = y - self.titlebary cursor.set("drag grab") I() end function form:setFull() self.fullscreen = true self:saveSettings() I() end function form:saveSettings() self.valsavelist = { x = {self.titlebarx}, y = {self.titlebary}, width = {self.titlebarwidth}, height = {self.height}, bx = {self.x}, by = {self.y}, bw = {self.width}, cirbx = {self.cirbx}, cirby = {self.cirby},} self.titlebarx = 0 self.titlebary = 0 self.titlebarheight = 20 self.x = self.titlebarx + 1 self.height = platform.window:height() self.width = platform.window:width() - 2 self.y = self.titlebary + 20 -- self.savedflag = 1 self.titlebarwidth = platform.window:width() self.cirbx = self.titlebarx + (self.titlebarwidth / 2) - 4 self.cirby = self.titlebary + self.titlebarheight / 4 self.allowevents = false I() end function form:restoreSettings() self.titlebarx = self.valsavelist.x[1] self.titlebary = self.valsavelist.y[1] self.titlebarwidth = self.valsavelist.width[1] self.height = self.valsavelist.height[1] self.x = self.valsavelist.bx[1] self.y = self.valsavelist.by[1] self.width = self.valsavelist.bw[1] self.cirbx = self.valsavelist.cirbx[1] self.cirby = self.valsavelist.cirby[1] -- self.savedflag = 0 self.cirbx = self.titlebarx + (self.titlebarwidth / 2) - 4 self.cirby = self.titlebary + self.titlebarheight / 4 self.fullscreen = false self.allowevents = true I() end function form:mouseMove(x, y) if self.moveable and self.isdrawn and self.focused then cursor.set("drag grab") self.titlebarx = x - self.xvar self.titlebary = y - self.yvar self.cirbx = self.titlebarx + (self.titlebarwidth / 2) - 4 self.cirby = self.titlebary + self.titlebarheight / 4 self.x = self.titlebarx + 1 self.y = self.titlebary + 20 I() end end ------------------------------------context menu------------------ contextm = class() function contextm:init(parent, cmtable) self.parent = parent self.x = parent.x self.y = parent.y self.cmtable = cmtable self.width = parent.width self.selected = false self.menOpen = false self.selectedMenu = nil table.insert(parent.controls, table.maxn(parent.controls), self) end function contextm:paint(gc) gc:setFont("sansserif", "r", 6) gc:setColorRGB(unpack(color.black)) gc:drawRect(self.x, self.y, self.width, 10) local y = self.y + 3 local x = self.x + 2 for _, btxt in pairs(self.cmtable) do gc:drawString(btxt.text, x, y, "middle") btxt.x = x btxt.y = y btxt.width = gc:getStringWidth(btxt.text) btxt.height = gc:getStringHeight(btxt.text) - 4 x = x + 5 + btxt.width end if self.menOpen and not(self.parent.moveable) and self.parent.focused then gc:setColorRGB(unpack(color.Bdark)) local bx = self.selectedMenu.x local by = self.y + 10 local bwidth = 35 local bheight = gc:getStringHeight("HSS") * table.maxn(self.selectedMenu.list) gc:fillRect(bx, by, bwidth, bheight) gc:setColorRGB(unpack(color.black)) gc:drawRect(bx, by, bwidth, bheight) local x = bx + 1 local y = by + 6 gc:setColorRGB(unpack(color.white)) local heightfstring = gc:getStringHeight("HIS") for i = 1, table.maxn(self.selectedMenu.list) do gc:drawString(self.selectedMenu.list[i].text, x, y, "middle") self.selectedMenu.list[i].x = x self.selectedMenu.list[i].y = y self.selectedMenu.list[i].width = gc:getStringWidth(self.selectedMenu.list[i].text) self.selectedMenu.list[i].height = heightfstring y = y + heightfstring end else self.menOpen = false end end function contextm:checkClick(x, y) for _, item in pairs(self.cmtable) do if x >= item.x and x <= item.x + item.width and y >= item.y and y <= item.y + item.height - 4 and self.selectedMenu ~= nil and self.selectedMenu == item then self.menOpen = not(self.menOpen) elseif x >= item.x and x <= item.x + item.width and y >= item.y and y <= item.y + item.height and self.selectedMenu ~= nil and self.selectedMenu ~= item then self.selectedMenu = item self.menOpen = true elseif x >= item.x and x <= item.x + item.width and y >= item.y and y <= item.y + item.height and self.selectedMenu == nil then self.menOpen = true self.selectedMenu = item end end if self.menOpen then for _, item in pairs(self.selectedMenu.list) do if x >= item.x and x <= item.x + item.width and y >= item.y and y <= item.y + item.height then item:action() self.menOpen = false self.selectedMenu = nil end end end end function contextm:updateButtons(button) button.x = button.xoff + self.x button.y = button.yoff + self.y end ---------------------------------------checkbox controll------------- checkbox = class() function checkbox:init(x, y, text, checked, backcolor, checkcolor, textcolor, parent) self.x = x + parent.x self.y = y + parent.y self.xoff = x self.yoff = y self.parent = parent self.text = text self.marked = marked self.backcolor = backcolor self.checkcolor = checkcolor self.textcolor = textcolor self.width = 10 self.height = 10 self.type = "ci" table.insert(parent.controls, self) end function checkbox:paint(gc) gc:setColorRGB(unpack(self.backcolor)) gc:fillRect( self.x, self.y, self.width, self.height) if self.marked then gc:setColorRGB(unpack(self.checkcolor)) gc:fillRect( self.x + 2, self.y + 2, self.width - 4, self.height - 4) else gc:setColorRGB(unpack(color.white)) gc:fillRect( self.x + 2, self.y + 2, self.width - 4, self.height - 4) end gc:setColorRGB(unpack(self.textcolor)) gc:setFont( "sansserif", "r", 9) gc:drawString(self.text, self.x + 15, self.y + 2, "middle") end function checkbox:Click() if self.marked then self.marked = false else self.marked = true end end function checkbox: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() end end ----------------picboxes-------------------- pb = class() function pb:init(x, y, width, height, labeltbl, picturetable, txtcolor, index, lablename, parent, selected) self.x = x + parent.x self.y = y + parent.y self.xoff = x self.yoff = y self.parent = parent self.height = height self.width = width self.labeltbl = labeltbl self.pictbl = picturetable self.txtcolor = txtcolor self.index = index self.lbltext = self.labeltbl[index]--x, y, text, txtsize, color, parent self.labelname = lable( self.x, self.y + self.height, self.lbltext, 12, self.txtcolor, self.parent) self.numpix = table.maxn(self.pictbl) self.picxs = self.pictbl[index] self.selected = selected self.type = "vo" table.insert(parent.controls, self) end function pb:paint(gc) gc:drawImage(self.picxs, self.x, self.y) end function pb:nextpic() if self.index < self.numpix then self.index = self.index + 1 else self.index = 1 end self.labelname.text = self.labeltbl[self.index] self.picxs = self.pictbl[self.index] end function pb:prevpic() if self.index > 1 then self.index = self.index - 1 else self.index = self.numpix end self.picxs = self.pictbl[self.index] self.labelname.text = self.labeltbl[self.index] end function pb:clicked(x, y) if not(self.selected) then for _, pbox in pairs(self.parent.controls) do pbox.slected = false end self.selected = true end end function pb: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:clicked(x, y) end end ----------------------------------Numeric Up Downs------------------------ NumericUD = class() function NumericUD:init(x, y, num, linecolor, maxnum, minnumber, textcolor, pmbcolor, parent, selected) self.x = x + parent.x self.y = y + parent.y self.xoff = x self.yoff = y self.parent = parent 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 self.type = "ci" table.insert(parent.controls, self) end function 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("sansserif", "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("sansserif", "r", 11) gc:drawString(self.text, self.x + 2, self.y + 2, "top") end function NumericUD:checkClick(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() end end function NumericUD:Up() if self.num ~= self.maxnum then self.num = self.num + 1 self.text = tostring(self.num) end end function NumericUD:Down() if self.num ~= self.minnumber then self.num = self.num - 1 self.text = tostring(self.num) end end ---------------------------------------------WZGUIlib END---------------------------------------- --~ --params---------- --~ window = x, y, width, height, isdrawn, focused --~ form = x, y, width, height, fullscreen, title, titlecolor, bordercolor, isdrawn, contextmenu, cmtable, focused--fulscreen overrides width and height values --~ checkbox = x, y, text, checked, backcolor, checkcolor, textcolor, parent --~ dialog = x, y, text, title, backcolor, textcolor, isdrawn, parent, selected --~ radioButton = text, x, y, marked, backcolor, markcolor, txtcolor, parent --~ textbox = x, y, text, textcolor, tbcolor, parent, selected --~ lable = x, y, text, txtsize, color, parent --~ button = text, x, y, action, txtcolor, bgcolor, opt3D, parent --~ pb = (x, y, width, height, labeltbl, picturetable, txtcolor, index, lablename, parent, selected --~ NumericUD = x, y, num, linecolor, maxnum, minnumber, textcolor, pmbcolor, parent, selected --~ --end params function on.create() cmtable = { item4 = {text = "New", list = {{text = "Author", action = author, x = 0, y = 0, width = 0, height = 0}, {text = "I/O", action = I_O, x = 0, y = 0, width = 0, height = 0}}, x = 0, y = 0, width = 0, height = 0}, item1 = {text = "About", list = {{text = "Listp1", action = p1, x = 0, y = 0, width = 0, height = 0},{text = "Listp2", action = p2, x = 0, y = 0, width = 0, height = 0}}, x = 0, y = 0, width = 0, height = 0}, item2 = {text = "File", list = {{text = "Add", action = add, x = 0, y = 0, width = 0, height = 0},{text = "BADD", action = badd, x = 0, y = 0, width = 0, height = 0}}, x = 0, y = 0, width = 0, height = 0}, item3 = {text = "Add", list = {{text = "Dialog", action = dialogss, x = 0, y = 0, width = 0, height = 0}}, x = 0, y = 0, width = 0, height = 0}} form1 = form(1, 1, 80, 90, false, "Main", color.white, color.black, true, false, false, true) form2 = form(1, 1, 200, 200, false, "Second Window", color.white, color.black, false, false, false, false) form3 = form(1, 1, 200, 200, false, "Third Window", color.white, color.black, false, true, cmtable, false) f2_show = button("Form2", 1, 1, f2s, color.black, color.Bcontrol, false, form1, false) f3_show = button("Form3", 1, 30, f3s, color.black, color.Bcontrol, false, form1, false) aboutdialog = dialog(50, 50, "CB: Jonathan Walker\n(c)2012, all rights reserved\nTest \ prerelease \ WZGUILIB v 2.0", "About", color.black, color.white, false, form2, false) about = button("About", 1, 1, aboutshow, color.black, color.Bcontrol, false, form2, false) sdia = dialog(50, 50, "", "selected", color.black, color.white, false, form3, false) bt2 = button("SD", 1, 54, showchoices, color.black, color.Bcontrol, false, form3) rdb1 = radioButton("selection one", 1, 13, true, color.Bdark, color.green, color.white, form3) rdb2 = radioButton("selection two", 1, 25, false, color.Bdark, color.green, color.white, form3) rdb3 = radioButton("selection three", 1, 37, false, color.Bdark, color.green, color.white, form3) end function f2s() form2.isdrawn = true form2:getFocus() I() end function author() sdia.isdrawn = true sdia.text = "You have Called: Author" I() end function I_O() sdia.isdrawn = true sdia.text = "You have Called: I_O" I() end function p1() sdia.isdrawn = true sdia.text = "You have Called: p1" I() end function p2() sdia.isdrawn = true sdia.text = "You have Called: p2" I() end function add() sdia.isdrawn = true sdia.text = "You have Called: add" I() end function badd() sdia.isdrawn = true sdia.text = "You have Called: badd" I() end function dialogss() sdia.isdrawn = true sdia.text = "You have Called: dialogss" I() end function f3s() form3.isdrawn = true form3:getFocus() I() end function aboutshow() aboutdialog.isdrawn = true I() end function showchoices() sdia.text = "You Selected: " if rdb1.marked then sdia.text = sdia.text.."1" elseif rdb2.marked then sdia.text = sdia.text.."2" elseif rdb3.marked then sdia.text = sdia.text.."3" else sdia.text = sdia.text.."No Selection!" end sdia.isdrawn = true I() end function on.paint(gc) --draw out the items created in the on.create() event for _, win in pairs(wndTbl) do if win.isdrawn then win:paint(gc) end end end function on.charIn(ch) if curwin() ~= nil then curwin():charIn(ch) end end function on.backspaceKey() if curwin() ~= nil then curwin():backspaceKey() end end function on.mouseMove(x, y) if curwin() ~= nil then curwin():mouseMove(x, y) for _, dialog in pairs(curwin().dialogs) do dialog:mouseMove(x, y) end end end --links class mouseDown functions function on.mouseDown(x, y) for i = #wndTbl, 1, -1 do if wndTbl[i].isdrawn and not(wndTbl[i].moveable) then if not(wndTbl[i].fullscreen) and (x >= wndTbl[i].cirbx and x <= wndTbl[i].cirbx + 5) and (y >= wndTbl[i].cirby and y <= wndTbl[i].cirby + 5) then wndTbl[i]:setFull() elseif wndTbl[i].fullscreen and (x >= wndTbl[i].cirbx and x <= wndTbl[i].cirbx + 5) and (y >= wndTbl[i].cirby and y <= wndTbl[i].cirby + 5) then wndTbl[i]:restoreSettings() elseif (x >= wndTbl[i].cirbx + 8 and x <= wndTbl[i].cirbx + 13) and (y >= wndTbl[i].cirby and y <= wndTbl[i].cirby + 5) then wndTbl[i]:close() break elseif not(wndTbl[i].fullscreen) and (x >= wndTbl[i].titlebarx and x <= wndTbl[i].titlebarx + wndTbl[i].titlebarwidth) and (y >= wndTbl[i].titlebary and y <= wndTbl[i].titlebary + 20) then wndTbl[i]:wasclicked(x, y) break end wndTbl[i]:mouseDown(x, y) end if wndTbl[i].isdrawn and wndTbl[i].moveable then wndTbl[i]:checkUnclick() break end end end