From dbe681ab524c81ce91bae6aba98b2473b4e7ab29 Mon Sep 17 00:00:00 2001 From: Kenny Shields Date: Mon, 25 Nov 2013 08:06:41 -0500 Subject: [PATCH] Added form object --- changelog.txt | 1 + init.lua | 7 +- objects/button.lua | 2 +- objects/checkbox.lua | 2 +- objects/collapsiblecategory.lua | 2 +- objects/columnlist.lua | 2 +- objects/form.lua | 333 ++++++++++++++++++ objects/frame.lua | 31 +- objects/grid.lua | 2 +- objects/image.lua | 2 +- objects/imagebutton.lua | 2 +- .../internal/columnlist/columnlistarea.lua | 4 +- objects/list.lua | 5 +- objects/multichoice.lua | 2 +- objects/numberbox.lua | 2 +- objects/panel.lua | 2 +- objects/progressbar.lua | 2 +- objects/slider.lua | 2 +- objects/tabs.lua | 2 +- objects/text.lua | 6 +- objects/textinput.lua | 2 +- skins/Blue/skin.lua | 35 +- 22 files changed, 412 insertions(+), 38 deletions(-) create mode 100644 objects/form.lua diff --git a/changelog.txt b/changelog.txt index 3bc04cc..ae35e02 100644 --- a/changelog.txt +++ b/changelog.txt @@ -21,6 +21,7 @@ Version 0.9.6.4 - Alpha (Release Date TBD) [ADDED] a new util library function: TableHasValue(table, value) [ADDED] a new util library function: GetHoverObject() [ADDED] a new callback: textinput(text) +[ADDED] a new object: form [ADDED] basic clipboard support for the textinput object (0.9.0 only) [ADDED] custom cursor support for the textinput object [ADDED] support for love.filesystem changes to loveframes.util.GetDirectoryContents (0.9.0 only) diff --git a/init.lua b/init.lua index b962926..c4754e6 100644 --- a/init.lua +++ b/init.lua @@ -123,10 +123,6 @@ function loveframes.update(dt) end end - loveframes.collisions = {} - - base:update(dt) - if version == "0.9.0" then local hoverobject = loveframes.hoverobject if hoverobject then @@ -153,6 +149,9 @@ function loveframes.update(dt) end end end + + loveframes.collisions = {} + base:update(dt) end diff --git a/objects/button.lua b/objects/button.lua index 9b3b57d..6b2bde7 100644 --- a/objects/button.lua +++ b/objects/button.lua @@ -3,7 +3,7 @@ -- Copyright (c) 2013 Kenny Shields -- --]]------------------------------------------------ --- button class +-- button object local newobject = loveframes.NewObject("button", "loveframes_object_button", true) --[[--------------------------------------------------------- diff --git a/objects/checkbox.lua b/objects/checkbox.lua index d4af3a9..6481871 100644 --- a/objects/checkbox.lua +++ b/objects/checkbox.lua @@ -3,7 +3,7 @@ -- Copyright (c) 2013 Kenny Shields -- --]]------------------------------------------------ --- checkbox class +-- checkbox object local newobject = loveframes.NewObject("checkbox", "loveframes_object_checkbox", true) --[[--------------------------------------------------------- diff --git a/objects/collapsiblecategory.lua b/objects/collapsiblecategory.lua index 4b5ce0a..d9ad0e0 100644 --- a/objects/collapsiblecategory.lua +++ b/objects/collapsiblecategory.lua @@ -3,7 +3,7 @@ -- Copyright (c) 2013 Kenny Shields -- --]]------------------------------------------------ --- collapsiblecategory class +-- collapsiblecategory object local newobject = loveframes.NewObject("collapsiblecategory", "loveframes_object_collapsiblecategory", true) --[[--------------------------------------------------------- diff --git a/objects/columnlist.lua b/objects/columnlist.lua index 65f53c2..3e7a55e 100644 --- a/objects/columnlist.lua +++ b/objects/columnlist.lua @@ -3,7 +3,7 @@ -- Copyright (c) 2013 Kenny Shields -- --]]------------------------------------------------ --- columnlist class +-- columnlist object local newobject = loveframes.NewObject("columnlist", "loveframes_object_columnlist", true) --[[--------------------------------------------------------- diff --git a/objects/form.lua b/objects/form.lua new file mode 100644 index 0000000..ca9e839 --- /dev/null +++ b/objects/form.lua @@ -0,0 +1,333 @@ +--[[------------------------------------------------ + -- Love Frames - A GUI library for LOVE -- + -- Copyright (c) 2013 Kenny Shields -- +--]]------------------------------------------------ + +-- form object +local newobject = loveframes.NewObject("form", "loveframes_object_form", true) + +--[[--------------------------------------------------------- + - func: initialize() + - desc: initializes the object +--]]--------------------------------------------------------- +function newobject:initialize() + + self.type = "form" + self.name = "Form" + self.layout = "vertical" + self.width = 200 + self.height = 50 + self.padding = 5 + self.spacing = 5 + self.topmargin = 12 + self.internal = false + self.children = {} + +end + +--[[--------------------------------------------------------- + - func: update(deltatime) + - desc: updates the element +--]]--------------------------------------------------------- +function newobject:update(dt) + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + local alwaysupdate = self.alwaysupdate + + if not visible then + if not alwaysupdate then + return + end + end + + local children = self.children + local parent = self.parent + local base = loveframes.base + local update = self.Update + + -- move to parent if there is a parent + if parent ~= base and parent.type ~= "list" then + self.x = self.parent.x + self.staticx + self.y = self.parent.y + self.staticy + end + + self:CheckHover() + + for k, v in ipairs(children) do + v:update(dt) + end + + if update then + update(self, dt) + end + +end + +--[[--------------------------------------------------------- + - func: draw() + - desc: draws the object +--]]--------------------------------------------------------- +function newobject:draw() + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + + if not visible then + return + end + + local children = self.children + local skins = loveframes.skins.available + local skinindex = loveframes.config["ACTIVESKIN"] + local defaultskin = loveframes.config["DEFAULTSKIN"] + local selfskin = self.skin + local skin = skins[selfskin] or skins[skinindex] + local drawfunc = skin.DrawForm or skins[defaultskin].DrawForm + local draw = self.Draw + local drawcount = loveframes.drawcount + + -- set the object's draw order + self:SetDrawOrder() + + if draw then + draw(self) + else + drawfunc(self) + end + + -- loop through the object's children and draw them + for k, v in ipairs(children) do + v:draw() + end + +end + +--[[--------------------------------------------------------- + - func: mousepressed(x, y, button) + - desc: called when the player presses a mouse button +--]]--------------------------------------------------------- +function newobject:mousepressed(x, y, button) + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + + if not visible then + return + end + + local children = self.children + local hover = self.hover + + if hover and button == "l" then + local baseparent = self:GetBaseParent() + if baseparent and baseparent.type == "frame" then + baseparent:MakeTop() + end + end + + for k, v in ipairs(children) do + v:mousepressed(x, y, button) + end + +end + +--[[--------------------------------------------------------- + - func: mousereleased(x, y, button) + - desc: called when the player releases a mouse button +--]]--------------------------------------------------------- +function newobject:mousereleased(x, y, button) + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + local children = self.children + + if not visible then + return + end + + for k, v in ipairs(children) do + v:mousereleased(x, y, button) + end + +end + +--[[--------------------------------------------------------- + - func: AddItem(object) + - desc: adds an item to the object +--]]--------------------------------------------------------- +function newobject:AddItem(object) + + local objtype = object.type + if objtype == "frame" then + return + end + + local children = self.children + local state = self.state + + object:Remove() + object.parent = self + object:SetState(state) + + table.insert(children, object) + self:LayoutObjects() + +end + +--[[--------------------------------------------------------- + - func: RemoveItem(object or number) + - desc: removes an item from the object +--]]--------------------------------------------------------- +function newobject:RemoveItem(data) + + local dtype = type(data) + + if dtype == "number" then + local children = self.children + local item = children[data] + if item then + item:Remove() + end + else + data:Remove() + end + + self:LayoutObjects() + +end + +--[[--------------------------------------------------------- + - func: LayoutObjects() + - desc: positions the object's children and calculates + a new size for the object +--]]--------------------------------------------------------- +function newobject:LayoutObjects() + + local layout = self.layout + local padding = self.padding + local spacing = self.spacing + local topmargin = self.topmargin + local children = self.children + local width = padding * 2 + local height = padding * 2 + topmargin + local x = padding + local y = padding + topmargin + + if layout == "vertical" then + local largest_width = 0 + for k, v in ipairs(children) do + v.staticx = x + v.staticy = y + y = y + v.height + spacing + height = height + v.height + spacing + if v.width > largest_width then + largest_width = v.width + end + end + height = height - spacing + self.width = width + largest_width + self.height = height + elseif layout == "horizontal" then + local largest_height = 0 + for k, v in ipairs(children) do + v.staticx = x + v.staticy = y + x = x + v.width + spacing + width = width + v.width + spacing + if v.height > largest_height then + largest_height = v.height + end + end + width = width - spacing + self.width = width + self.height = height + largest_height + end + +end + +--[[--------------------------------------------------------- + - func: SetLayoutType(ltype) + - desc: sets the object's layout type +--]]--------------------------------------------------------- +function newobject:SetLayoutType(ltype) + + self.layout = ltype + +end + +--[[--------------------------------------------------------- + - func: GetLayoutType() + - desc: gets the object's layout type +--]]--------------------------------------------------------- +function newobject:GetLayoutType() + + return self.layout + +end + +--[[--------------------------------------------------------- + - func: SetTopMargin(margin) + - desc: sets the margin between the top of the object + and its children +--]]--------------------------------------------------------- +function newobject:SetTopMargin(margin) + + self.topmargin = margin + +end + +--[[--------------------------------------------------------- + - func: GetTopMargin() + - desc: gets the margin between the top of the object + and its children +--]]--------------------------------------------------------- +function newobject:GetTopMargin() + + return self.topmargin + +end + +--[[--------------------------------------------------------- + - func: SetName(name) + - desc: sets the object's name +--]]--------------------------------------------------------- +function newobject:SetName(name) + + self.name = name + +end + +--[[--------------------------------------------------------- + - func: GetName() + - desc: gets the object's name +--]]--------------------------------------------------------- +function newobject:GetName() + + return self.name + +end \ No newline at end of file diff --git a/objects/frame.lua b/objects/frame.lua index 8798576..867ef52 100644 --- a/objects/frame.lua +++ b/objects/frame.lua @@ -3,7 +3,7 @@ -- Copyright (c) 2013 Kenny Shields -- --]]------------------------------------------------ --- frame class +-- frame object local newobject = loveframes.NewObject("frame", "loveframes_object_frame", true) --[[--------------------------------------------------------- @@ -453,7 +453,7 @@ end --[[--------------------------------------------------------- - func: SetName(name) - - desc: sets the frame's name + - desc: sets the object's name --]]--------------------------------------------------------- function newobject:SetName(name) @@ -463,7 +463,7 @@ end --[[--------------------------------------------------------- - func: GetName() - - desc: gets the frame's name + - desc: gets the object's name --]]--------------------------------------------------------- function newobject:GetName() @@ -473,7 +473,7 @@ end --[[--------------------------------------------------------- - func: SetDraggable(true/false) - - desc: sets whether the frame can be dragged or not + - desc: sets whether the object can be dragged or not --]]--------------------------------------------------------- function newobject:SetDraggable(bool) @@ -483,7 +483,7 @@ end --[[--------------------------------------------------------- - func: GetDraggable() - - desc: gets whether the frame can be dragged ot not + - desc: gets whether the object can be dragged ot not --]]--------------------------------------------------------- function newobject:GetDraggable() @@ -494,7 +494,7 @@ end --[[--------------------------------------------------------- - func: SetScreenLocked(bool) - - desc: sets whether the frame can be moved passed the + - desc: sets whether the object can be moved passed the boundaries of the window or not --]]--------------------------------------------------------- function newobject:SetScreenLocked(bool) @@ -505,7 +505,7 @@ end --[[--------------------------------------------------------- - func: GetScreenLocked() - - desc: gets whether the frame can be moved passed the + - desc: gets whether the object can be moved passed the boundaries of window or not --]]--------------------------------------------------------- function newobject:GetScreenLocked() @@ -516,7 +516,8 @@ end --[[--------------------------------------------------------- - func: ShowCloseButton(bool) - - desc: sets whether the close button should be drawn + - desc: sets whether the object's close button should + be drawn --]]--------------------------------------------------------- function newobject:ShowCloseButton(bool) @@ -574,8 +575,8 @@ end --[[--------------------------------------------------------- - func: SetModal(bool) - - desc: makes the object the top object in the drawing - order + - desc: sets whether or not the object is in a modal + state --]]--------------------------------------------------------- function newobject:SetModal(bool) @@ -647,7 +648,7 @@ end --[[--------------------------------------------------------- - func: SetParentLocked(bool) - - desc: sets whether the frame can be moved passed the + - desc: sets whether the object can be moved passed the boundaries of its parent or not --]]--------------------------------------------------------- function newobject:SetParentLocked(bool) @@ -658,7 +659,7 @@ end --[[--------------------------------------------------------- - func: GetParentLocked(bool) - - desc: gets whether the frame can be moved passed the + - desc: gets whether the object can be moved passed the boundaries of its parent or not --]]--------------------------------------------------------- function newobject:GetParentLocked() @@ -700,7 +701,8 @@ end --[[--------------------------------------------------------- - func: SetDockable(dockable) - desc: sets whether or not the object can dock onto - another from or be docked by another frame + another object of its type or be docked + by another object of its type --]]--------------------------------------------------------- function newobject:SetDockable(dockable) @@ -711,7 +713,8 @@ end --[[--------------------------------------------------------- - func: GetDockable() - desc: gets whether or not the object can dock onto - another from or be docked by another frame + another object of its type or be docked + by another object of its type --]]--------------------------------------------------------- function newobject:GetDockable() diff --git a/objects/grid.lua b/objects/grid.lua index 06a8e84..c06c6a8 100644 --- a/objects/grid.lua +++ b/objects/grid.lua @@ -3,7 +3,7 @@ -- Copyright (c) 2013 Kenny Shields -- --]]------------------------------------------------ --- button class +-- grid object local newobject = loveframes.NewObject("grid", "loveframes_object_grid", true) --[[--------------------------------------------------------- diff --git a/objects/image.lua b/objects/image.lua index 3912aab..c2587c4 100644 --- a/objects/image.lua +++ b/objects/image.lua @@ -3,7 +3,7 @@ -- Copyright (c) 2013 Kenny Shields -- --]]------------------------------------------------ --- progressbar class +-- image object local newobject = loveframes.NewObject("image", "loveframes_object_image", true) --[[--------------------------------------------------------- diff --git a/objects/imagebutton.lua b/objects/imagebutton.lua index b42bf10..d9c0eb1 100644 --- a/objects/imagebutton.lua +++ b/objects/imagebutton.lua @@ -3,7 +3,7 @@ -- Copyright (c) 2013 Kenny Shields -- --]]------------------------------------------------ --- imagebutton class +-- imagebutton object local newobject = loveframes.NewObject("imagebutton", "loveframes_object_imagebutton", true) --[[--------------------------------------------------------- diff --git a/objects/internal/columnlist/columnlistarea.lua b/objects/internal/columnlist/columnlistarea.lua index 0d58af9..ceaa9a7 100644 --- a/objects/internal/columnlist/columnlistarea.lua +++ b/objects/internal/columnlist/columnlistarea.lua @@ -340,9 +340,9 @@ function newobject:Sort(column, desc) table.sort(children, function(a, b) if desc then - return (tonumber(a.columndata[column]) or a.columndata[column]) < (tonumber(b.columndata[column]) or b.columndata[column]) + return (tostring(a.columndata[column]) or a.columndata[column]) < (tostring(b.columndata[column]) or b.columndata[column]) else - return (tonumber(a.columndata[column]) or a.columndata[column]) > (tonumber(b.columndata[column]) or b.columndata[column]) + return (tostring(a.columndata[column]) or a.columndata[column]) > (tostring(b.columndata[column]) or b.columndata[column]) end end) diff --git a/objects/list.lua b/objects/list.lua index a7a9154..7a7d4f6 100644 --- a/objects/list.lua +++ b/objects/list.lua @@ -3,7 +3,7 @@ -- Copyright (c) 2013 Kenny Shields -- --]]------------------------------------------------ --- list class +-- list object local newobject = loveframes.NewObject("list", "loveframes_object_list", true) --[[--------------------------------------------------------- @@ -249,7 +249,8 @@ end --]]--------------------------------------------------------- function newobject:AddItem(object) - if object.type == "frame" then + local objtype = object.type + if objtype == "frame" then return end diff --git a/objects/multichoice.lua b/objects/multichoice.lua index e06c4cb..1b1ddc4 100644 --- a/objects/multichoice.lua +++ b/objects/multichoice.lua @@ -3,7 +3,7 @@ -- Copyright (c) 2013 Kenny Shields -- --]]------------------------------------------------ --- multichoice class +-- multichoice object local newobject = loveframes.NewObject("multichoice", "loveframes_object_multichoice", true) --[[--------------------------------------------------------- diff --git a/objects/numberbox.lua b/objects/numberbox.lua index 8d66f6e..ff44051 100644 --- a/objects/numberbox.lua +++ b/objects/numberbox.lua @@ -3,7 +3,7 @@ -- Copyright (c) 2013 Kenny Shields -- --]]------------------------------------------------ --- numberbox class +-- numberbox object local newobject = loveframes.NewObject("numberbox", "loveframes_object_numberbox", true) --[[--------------------------------------------------------- diff --git a/objects/panel.lua b/objects/panel.lua index 48f3922..712dfeb 100644 --- a/objects/panel.lua +++ b/objects/panel.lua @@ -3,7 +3,7 @@ -- Copyright (c) 2013 Kenny Shields -- --]]------------------------------------------------ --- panel class +-- panel object local newobject = loveframes.NewObject("panel", "loveframes_object_panel", true) --[[--------------------------------------------------------- diff --git a/objects/progressbar.lua b/objects/progressbar.lua index f23b8f5..b9d7e8f 100644 --- a/objects/progressbar.lua +++ b/objects/progressbar.lua @@ -3,7 +3,7 @@ -- Copyright (c) 2013 Kenny Shields -- --]]------------------------------------------------ --- progressbar class +-- progressbar object local newobject = loveframes.NewObject("progressbar", "loveframes_object_progressbar", true) --[[--------------------------------------------------------- diff --git a/objects/slider.lua b/objects/slider.lua index 702c3f6..66e8356 100644 --- a/objects/slider.lua +++ b/objects/slider.lua @@ -3,7 +3,7 @@ -- Copyright (c) 2013 Kenny Shields -- --]]------------------------------------------------ --- slider class +-- slider object local newobject = loveframes.NewObject("slider", "loveframes_object_slider", true) --[[--------------------------------------------------------- diff --git a/objects/tabs.lua b/objects/tabs.lua index b7c766f..ffb847d 100644 --- a/objects/tabs.lua +++ b/objects/tabs.lua @@ -3,7 +3,7 @@ -- Copyright (c) 2013 Kenny Shields -- --]]------------------------------------------------ --- tabs class +-- tabs object local newobject = loveframes.NewObject("tabs", "loveframes_object_tabs", true) --[[--------------------------------------------------------- diff --git a/objects/text.lua b/objects/text.lua index d9ee6c5..e5711e7 100644 --- a/objects/text.lua +++ b/objects/text.lua @@ -8,7 +8,7 @@ experimental and not final --]]------------------------------------------------ --- text class +-- text object local newobject = loveframes.NewObject("text", "loveframes_object_text", true) --[[--------------------------------------------------------- @@ -39,6 +39,10 @@ function newobject:initialize() self.OnClickLink = nil local skin = loveframes.util.GetActiveSkin() + if not skin then + skin = loveframes.config["DEFAULTSKIN"] + end + local directives = skin.directives if directives then local text_default_color = directives.text_default_color diff --git a/objects/textinput.lua b/objects/textinput.lua index 6a3c1ac..bba4d40 100644 --- a/objects/textinput.lua +++ b/objects/textinput.lua @@ -3,7 +3,7 @@ -- Copyright (c) 2013 Kenny Shields -- --]]------------------------------------------------ --- textinput class +-- textinput object local newobject = loveframes.NewObject("textinput", "loveframes_object_textinput", true) --[[--------------------------------------------------------- diff --git a/skins/Blue/skin.lua b/skins/Blue/skin.lua index 5e31e0a..5f3cc75 100644 --- a/skins/Blue/skin.lua +++ b/skins/Blue/skin.lua @@ -134,8 +134,12 @@ skin.controls.modalbackground_body_color = {255, 255, 255, 100} skin.controls.linenumberspanel_text_color = {170, 170, 170, 255} skin.controls.linenumberspanel_body_color = {235, 235, 235, 255} +-- form +skin.controls.form_text_color = {0, 0, 0, 255} +skin.controls.form_text_font = smallfont + --[[--------------------------------------------------------- - - func: OutlinedRectangle(object) + - func: OutlinedRectangle(x, y, width, height, ovt, ovb, ovl, ovr) - desc: creates and outlined rectangle --]]--------------------------------------------------------- function skin.OutlinedRectangle(x, y, width, height, ovt, ovb, ovl, ovr) @@ -1627,5 +1631,34 @@ function skin.DrawGrid(object) end +--[[--------------------------------------------------------- + - func: skin.DrawForm(object) + - desc: draws the form object +--]]--------------------------------------------------------- +function skin.DrawForm(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local topmargin = object.topmargin + local name = object.name + local font = skin.controls.form_text_font + local textcolor = skin.controls.form_text_color + local twidth = font:getWidth(name) + + love.graphics.setFont(font) + love.graphics.setColor(textcolor) + love.graphics.print(name, x + 7, y) + + love.graphics.setColor(bordercolor) + love.graphics.rectangle("fill", x, y + 7, 5, 1) + love.graphics.rectangle("fill", x + twidth + 9, y + 7, width - (twidth + 9), 1) + love.graphics.rectangle("fill", x, y + height, width, 1) + love.graphics.rectangle("fill", x, y + 7, 1, height - 7) + love.graphics.rectangle("fill", x + width - 1, y + 7, 1, height - 7) + +end + -- register the skin loveframes.skins.Register(skin)