diff --git a/changelog.txt b/changelog.txt index 90c34fa..b2a7b46 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,6 +1,30 @@ +================================================ +Version 0.9.4 - Alpha (October 22 - 2012) +================================================ +[ADDED] a new base method: SetDrawOrder() +[ADDED] a new base method: GetDrawOrder() +[ADDED] a new text method: GetFormattedText() +[ADDED] a new text input method: SetEditable(bool) +[ADDED] a new text input method: GetEditable() +[ADDED] a new text input method: GetUsable() +[ADDED] a new text input method: GetUnusable() +[ADDED] a new system for creating and applying templates to objects + +[FIXED] a few incorrent entries in the changelog and added a few entries that were meant to be in the last upadte's changelog +[FIXED] an error that occured when clicking on a frame that was parented to another frame +[FIXED] frames not being positioned properly if they were parented to another object +[FIXED] modal background object not drawing over umodaled objects in certain situations +[FIXED] an error that would occur when a multichoice list object would become scrollable +[FIXED] an error that would occur when a the column list object had no columns +[FIXED] multichoice object not positioning itself properly if it's parent was the base object + +[CHANGED] text:GetText() now returns a string of the object's text +[CHANGED] parented frames can no longer be modaled + ================================================ Version 0.9.3.2 - Alpha (Spetember 29 - 2012) ================================================ +[ADDED] a new base method: SetDrawOrder() [ADDED] a new text input method: SetMultiline(bool) [ADDED] a new text input method: GetVerticalScrollBody() [ADDED] a new text input method: GetHorizontalScrollBody() @@ -8,7 +32,6 @@ Version 0.9.3.2 - Alpha (Spetember 29 - 2012) [ADDED] a new text input method: HasVerticalScrollBar() [ADDED] a new text input method: HasHorizontalScrollBar() [ADDED] a new text input method: GetFont() -[ADDED] a new text input method: GetTextColor() [ADDED] a new text input method: GetLineNumbersPanel() [ADDED] a new text input method: GetMultiline() [ADDED] a new text input method: GetTextX() @@ -19,6 +42,7 @@ Version 0.9.3.2 - Alpha (Spetember 29 - 2012) [ADDED] a new text input method: GetOffsetY() [ADDED] a new text input method: GetIndicatorX() [ADDED] a new text input method: GetIndicatorY() +[ADDED] a new text input method: SetLineNumbersEnabled(enabled) [ADDED] a new text input method: GetLineNumbersEnabled() [ADDED] a new text input method: GetItemWidth() [ADDED] a new text input method: GetItemHeight() @@ -57,7 +81,6 @@ Version 0.9.3.2 - Alpha (Spetember 29 - 2012) [CHANGED] the column list row object's text is no longer drawn internally by the object and should now be draw within the object's skin drawing function [REMOVED] textinput:SetTextColor(color) -[REMOVED] textinput:GetTextColor() [REMOVED] columnlistrow:SetTextColor() ================================================ diff --git a/debug.lua b/debug.lua index e70ef1d..4b88c82 100644 --- a/debug.lua +++ b/debug.lua @@ -13,7 +13,6 @@ local loremipsum = Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin dui enim, porta eget facilisis quis, laoreet sit amet urna. Maecenas lobortis venenatis euismod. Sed at diam sit amet odio feugiat pretium nec quis libero. Quisque auctor semper imperdiet. Maecenas risus eros, varius pharetra volutpat in, fermentum scelerisque lacus. Proin lectus erat, luctus non facilisis vel, hendrerit vitae nisl. Aliquam vulputate scelerisque odio id faucibus. ]] - --[[--------------------------------------------------------- - func: draw() - desc: draws debug information @@ -29,7 +28,7 @@ function loveframes.debug.draw() end local cols = loveframes.util.GetCollisions() - local topcol = cols[#cols] or {type = none, children = {}, x = 0, y = 0, width = 0, height = 0} + local topcol = {type = none, children = {}, x = 0, y = 0, width = 0, height = 0} local objects = loveframes.util.GetAllObjects() local author = loveframes.info.author local version = loveframes.info.version @@ -39,6 +38,14 @@ function loveframes.debug.draw() local fps = love.timer.getFPS() local deltatime = love.timer.getDelta() + -- set the top most collision object + for k, v in ipairs(cols) do + if v:IsTopCollision() then + topcol = v + break + end + end + -- font for debug text love.graphics.setFont(font) diff --git a/init.lua b/init.lua index 43df181..f0d1ff6 100644 --- a/init.lua +++ b/init.lua @@ -7,24 +7,30 @@ loveframes = {} -- library info -loveframes.info = {} -loveframes.info.author = "Nikolai Resokav" -loveframes.info.version = "0.9.3.2" -loveframes.info.stage = "Alpha" +loveframes.info = {} +loveframes.info.author = "Nikolai Resokav" +loveframes.info.version = "0.9.4" +loveframes.info.stage = "Alpha" -- library configurations -loveframes.config = {} -loveframes.config["DIRECTORY"] = "libraries/loveframes" -loveframes.config["DEFAULTSKIN"] = "Blue" -loveframes.config["ACTIVESKIN"] = "Blue" -loveframes.config["INDEXSKINIMAGES"] = true -loveframes.config["DEBUG"] = true +loveframes.config = {} +loveframes.config["DIRECTORY"] = "libraries/loveframes" +loveframes.config["DEFAULTSKIN"] = "Blue" +loveframes.config["ACTIVESKIN"] = "Blue" +loveframes.config["INDEXSKINIMAGES"] = true +loveframes.config["DEBUG"] = true -loveframes.drawcount = 0 -loveframes.hoverobject = false -loveframes.modalobject = false -loveframes.basicfont = love.graphics.newFont(12) -loveframes.basicfontsmall = love.graphics.newFont(10) +-- misc library vars +loveframes.drawcount = 0 +loveframes.lastselection = 0 +loveframes.selectiondelay = 0.05 +loveframes.selectionstartdelay = 0.50 +loveframes.selecting = false +loveframes.hoverobject = false +loveframes.modalobject = false +loveframes.selectedobject = false +loveframes.basicfont = love.graphics.newFont(12) +loveframes.basicfontsmall = love.graphics.newFont(10) --[[--------------------------------------------------------- - func: load() @@ -45,6 +51,7 @@ function loveframes.load() -- create a list of gui objects and skins local objects = loveframes.util.GetDirContents(dir .. "/objects") local skins = loveframes.util.GetDirContents(dir .. "/skins") + local templates = loveframes.util.GetDirContents(dir .. "/templates") -- loop through a list of all gui objects and require them for k, v in ipairs(objects) do @@ -53,6 +60,13 @@ function loveframes.load() end end + -- loop through a list of all gui templates and require them + for k, v in ipairs(templates) do + if v.extension == "lua" then + require(v.path .. "/" ..v.name) + end + end + -- loop through a list of all gui skins and require them for k, v in ipairs(skins) do if v.extension == "lua" then @@ -118,8 +132,10 @@ function loveframes.mousereleased(x, y, button) object:mousereleased(x, y, button) + -- reset the hover object if button == "l" then loveframes.hoverobject = false + loveframes.selectedobject = false end end @@ -149,7 +165,7 @@ function loveframes.keyreleased(key) end --[[--------------------------------------------------------- - - func: New(type, parent) + - func: Create(type, parent) - desc: creates a new object or multiple new objects (based on the method used) and returns said object or objects for further manipulation @@ -160,12 +176,15 @@ function loveframes.Create(data, parent) -- make sure the object specified is valid if not _G[data] then - error("Error creating object: Invalid object '" ..data.. "'.") + loveframes.util.Error("Error creating object: Invalid object '" ..data.. "'.") end -- create the object local object = _G[data]:new() + -- apply template properties to the object + loveframes.templates.ApplyToObject(object) + -- if the object is a tooltip, return it and go no further if data == "tooltip" then return object diff --git a/objects/base.lua b/objects/base.lua index 3540887..0518b80 100644 --- a/objects/base.lua +++ b/objects/base.lua @@ -5,7 +5,6 @@ -- base object base = class("base") -base:include(loveframes.templates.default) --[[--------------------------------------------------------- - func: initialize() @@ -14,14 +13,15 @@ base:include(loveframes.templates.default) function base:initialize() -- width and height of the window - local w, h = love.graphics.getWidth(), love.graphics.getHeight() + local w = love.graphics.getWidth() + local h = love.graphics.getHeight() - self.type = "base" - self.width = w - self.height = h - self.internal = true - self.children = {} - self.internals = {} + self.type = "base" + self.width = w + self.height = h + self.internal = true + self.children = {} + self.internals = {} end @@ -51,8 +51,8 @@ function base:draw() local children = self.children - loveframes.drawcount = loveframes.drawcount + 1 - self.draworder = loveframes.drawcount + -- set the object's draw order + self:SetDrawOrder() for k, v in ipairs(children) do v:draw() @@ -1012,4 +1012,25 @@ function base:GetType() return self.type +end + +--[[--------------------------------------------------------- + - func: SetDrawOrder() + - desc: sets the object's draw order +--]]--------------------------------------------------------- +function base:SetDrawOrder() + + loveframes.drawcount = loveframes.drawcount + 1 + self.draworder = loveframes.drawcount + +end + +--[[--------------------------------------------------------- + - func: GetDrawOrder() + - desc: sets the object's draw order +--]]--------------------------------------------------------- +function base:GetDrawOrder() + + return self.draworder + end \ No newline at end of file diff --git a/objects/button.lua b/objects/button.lua index 1ad610a..28d6664 100644 --- a/objects/button.lua +++ b/objects/button.lua @@ -5,14 +5,13 @@ -- button class button = class("button", base) -button:include(loveframes.templates.default) --[[--------------------------------------------------------- - func: initialize() - desc: initializes the object --]]--------------------------------------------------------- function button:initialize() - + self.type = "button" self.text = "Button" self.width = 80 @@ -94,8 +93,8 @@ function button:draw() local draw = self.Draw local drawcount = loveframes.drawcount - loveframes.drawcount = drawcount + 1 - self.draworder = loveframes.drawcount + -- set the object's draw order + self:SetDrawOrder() if draw then draw(self) @@ -164,6 +163,27 @@ function button:mousereleased(x, y, button) end +--[[--------------------------------------------------------- + - func: keypressed(key) + - desc: called when the player presses a key +--]]--------------------------------------------------------- +function button:keypressed(key, unicode) + + local visible = self.visible + + if not visible then + return + end + + local selectedobject = loveframes.selectedobject + local onclick = self.OnClick + + if key == "return" and selectedobject == self then + onclick(self, 0, 0) + end + +end + --[[--------------------------------------------------------- - func: SetText(text) - desc: sets the object's text diff --git a/objects/checkbox.lua b/objects/checkbox.lua index 8404574..395fdbf 100644 --- a/objects/checkbox.lua +++ b/objects/checkbox.lua @@ -5,7 +5,6 @@ -- checkbox class checkbox = class("checkbox", base) -checkbox:include(loveframes.templates.default) --[[--------------------------------------------------------- - func: initialize() @@ -124,8 +123,8 @@ function checkbox:draw() local internals = self.internals local drawcount = loveframes.drawcount - loveframes.drawcount = drawcount + 1 - self.draworder = loveframes.drawcount + -- set the object's draw order + self:SetDrawOrder() if draw then draw(self) @@ -200,6 +199,30 @@ function checkbox:mousereleased(x, y, button) end +--[[--------------------------------------------------------- + - func: keypressed(key) + - desc: called when the player presses a key +--]]--------------------------------------------------------- +function checkbox:keypressed(key, unicode) + + local checked = self.checked + local onchanged = self.OnChanged + local selectedobject = loveframes.selectedobject + + if key == "return" and selectedobject == self then + if checked then + self.checked = false + else + self.checked = true + end + + if onchanged then + onchanged(self) + end + end + +end + --[[--------------------------------------------------------- - func: SetText(text) - desc: sets the object's text diff --git a/objects/collapsiblecategory.lua b/objects/collapsiblecategory.lua index c727641..4018137 100644 --- a/objects/collapsiblecategory.lua +++ b/objects/collapsiblecategory.lua @@ -5,7 +5,6 @@ -- collapsiblecategory class collapsiblecategory = class("collapsiblecategory", base) -collapsiblecategory:include(loveframes.templates.default) --[[--------------------------------------------------------- - func: initialize() @@ -92,8 +91,8 @@ function collapsiblecategory:draw() local draw = self.Draw local drawcount = loveframes.drawcount - loveframes.drawcount = drawcount + 1 - self.draworder = loveframes.drawcount + -- set the object's draw order + self:SetDrawOrder() if draw then draw(self) diff --git a/objects/columnlist.lua b/objects/columnlist.lua index feb99c0..6d4c337 100644 --- a/objects/columnlist.lua +++ b/objects/columnlist.lua @@ -5,7 +5,6 @@ -- columnlist class columnlist = class("columnlist", base) -columnlist:include(loveframes.templates.default) --[[--------------------------------------------------------- - func: initialize() @@ -94,8 +93,8 @@ function columnlist:draw() local draw = self.Draw local drawcount = loveframes.drawcount - loveframes.drawcount = drawcount + 1 - self.draworder = loveframes.drawcount + -- set the object's draw order + self:SetDrawOrder() if draw then draw(self) @@ -183,8 +182,8 @@ function columnlist:AdjustColumns() local width = self.width local bar = self.internals[1].bar - if bar == true then - width = width - 16 + if bar then + width = width - self.internals[1].internals[1].width end local children = self.children @@ -244,11 +243,11 @@ function columnlist:GetColumnSize() local children = self.children local numchildren = #self.children - local column = self.children[1] - local colwidth = column.width - local colheight = column.height if numchildren > 0 then + local column = self.children[1] + local colwidth = column.width + local colheight = column.height return colwidth, colheight else return 0, 0 diff --git a/objects/frame.lua b/objects/frame.lua index 09a96b2..35496fa 100644 --- a/objects/frame.lua +++ b/objects/frame.lua @@ -5,7 +5,7 @@ -- frame class frame = class("frame", base) -frame:include(loveframes.templates.default) + --[[--------------------------------------------------------- - func: initialize() @@ -73,6 +73,7 @@ function frame:update(dt) local draworder = self.draworder local children = self.children local internals = self.internals + local parent = self.parent local update = self.Update close:SetPos(self.width - 20, 4) @@ -80,8 +81,10 @@ function frame:update(dt) -- dragging check if dragging then - self.x = x - self.clickx - self.y = y - self.clicky + if parent == base then + self.x = x - self.clickx + self.y = y - self.clicky + end end -- if screenlocked then keep within screen @@ -107,7 +110,7 @@ function frame:update(dt) end - if modal == true then + if modal then local tip = false local key = 0 @@ -132,6 +135,11 @@ function frame:update(dt) end + if parent ~= base then + self.x = self.parent.x + self.staticx + self.y = self.parent.y + self.staticy + end + for k, v in ipairs(internals) do v:update(dt) end @@ -169,8 +177,8 @@ function frame:draw() local draw = self.Draw local drawcount = loveframes.drawcount - loveframes.drawcount = drawcount + 1 - self.draworder = loveframes.drawcount + -- set the object's draw order + self:SetDrawOrder() if draw then draw(self) @@ -206,13 +214,14 @@ function frame:mousepressed(x, y, button) local selfcol = loveframes.util.BoundingBox(x, self.x, y, self.y, 1, self.width, 1, self.height) local internals = self.internals local children = self.children + local dragging = self.dragging if selfcol then local top = self:IsTopCollision() -- initiate dragging if not currently dragging - if not self.dragging and top and button == "l" then + if not dragging and top and button == "l" then if y < self.y + 25 and self.draggable then self.clickx = x - self.x self.clicky = y - self.y @@ -355,11 +364,23 @@ function frame:MakeTop() local base = loveframes.base local basechildren = base.children local numbasechildren = #basechildren + local parent = self.parent + -- check to see if the object's parent is not the base object + if parent ~= base then + local baseparent = self:GetBaseParent() + if baseparent.type == "frame" then + baseparent:MakeTop() + end + return + end + + -- check to see if the object is the only child of the base object if numbasechildren == 1 then return end + -- check to see if the object is already at the top if basechildren[numbasechildren] == self then return end @@ -374,8 +395,6 @@ function frame:MakeTop() end end - basechildren[key]:mousepressed(x, y, "l") - end --[[--------------------------------------------------------- @@ -387,6 +406,12 @@ function frame:SetModal(bool) local modalobject = loveframes.modalobject local mbackground = self.modalbackground + local parent = self.parent + local base = loveframes.base + + if parent ~= base then + return + end self.modal = bool diff --git a/objects/image.lua b/objects/image.lua index 36b1a92..5718849 100644 --- a/objects/image.lua +++ b/objects/image.lua @@ -5,7 +5,6 @@ -- progressbar class image = class("image", base) -image:include(loveframes.templates.default) --[[--------------------------------------------------------- - func: initialize() @@ -74,8 +73,8 @@ function image:draw() local draw = self.Draw local drawcount = loveframes.drawcount - loveframes.drawcount = drawcount + 1 - self.draworder = loveframes.drawcount + -- set the object's draw order + self:SetDrawOrder() if draw then draw(self) diff --git a/objects/imagebutton.lua b/objects/imagebutton.lua index adbd918..ac565d6 100644 --- a/objects/imagebutton.lua +++ b/objects/imagebutton.lua @@ -5,7 +5,6 @@ -- imagebutton class imagebutton = class("imagebutton", base) -imagebutton:include(loveframes.templates.default) --[[--------------------------------------------------------- - func: initialize() @@ -95,8 +94,8 @@ function imagebutton:draw() local draw = self.Draw local drawcount = loveframes.drawcount - loveframes.drawcount = drawcount + 1 - self.draworder = loveframes.drawcount + -- set the object's draw order + self:SetDrawOrder() if draw then draw(self) diff --git a/objects/internal/closebutton.lua b/objects/internal/closebutton.lua index 8851016..6b195e8 100644 --- a/objects/internal/closebutton.lua +++ b/objects/internal/closebutton.lua @@ -5,7 +5,6 @@ -- closebutton class closebutton = class("closebutton", base) -closebutton:include(loveframes.templates.default) --[[--------------------------------------------------------- - func: initialize() @@ -21,6 +20,9 @@ function closebutton:initialize() self.down = false self.OnClick = function() end + -- apply template properties to the object + loveframes.templates.ApplyToObject(self) + end --[[--------------------------------------------------------- @@ -90,10 +92,9 @@ function closebutton:draw() local skin = skins[selfskin] or skins[skinindex] local drawfunc = skin.DrawCloseButton or skins[defaultskin].DrawCloseButton local draw = self.Draw - local drawcount = loveframes.drawcount - loveframes.drawcount = drawcount + 1 - self.draworder = loveframes.drawcount + -- set the object's draw order + self:SetDrawOrder() if draw then draw(self) diff --git a/objects/internal/columnlist/columnlist-listarea.lua b/objects/internal/columnlist/columnlist-listarea.lua index aeed687..3ab6025 100644 --- a/objects/internal/columnlist/columnlist-listarea.lua +++ b/objects/internal/columnlist/columnlist-listarea.lua @@ -5,7 +5,6 @@ -- columnlistarea class columnlistarea = class("columnlistarea", base) -columnlistarea:include(loveframes.templates.default) --[[--------------------------------------------------------- - func: initialize() @@ -31,6 +30,9 @@ function columnlistarea:initialize(parent) self.internals = {} self.children = {} + -- apply template properties to the object + loveframes.templates.ApplyToObject(self) + end --[[--------------------------------------------------------- @@ -106,8 +108,8 @@ function columnlistarea:draw() local internals = self.internals local children = self.children - loveframes.drawcount = drawcount + 1 - self.draworder = loveframes.drawcount + -- set the object's draw order + self:SetDrawOrder() if draw then draw(self) diff --git a/objects/internal/columnlist/columnlist-row.lua b/objects/internal/columnlist/columnlist-row.lua index 0a7083f..5231add 100644 --- a/objects/internal/columnlist/columnlist-row.lua +++ b/objects/internal/columnlist/columnlist-row.lua @@ -5,7 +5,6 @@ -- columnlistrow class columnlistrow = class("columnlistrow", base) -columnlistrow:include(loveframes.templates.default) --[[--------------------------------------------------------- - func: initialize() @@ -24,6 +23,9 @@ function columnlistrow:initialize(parent, data) self.internal = true self.columndata = data + -- apply template properties to the object + loveframes.templates.ApplyToObject(self) + end --[[--------------------------------------------------------- @@ -80,8 +82,8 @@ function columnlistrow:draw() local draw = self.Draw local drawcount = loveframes.drawcount - loveframes.drawcount = drawcount + 1 - self.draworder = loveframes.drawcount + -- set the object's draw order + self:SetDrawOrder() if draw then draw(self) diff --git a/objects/internal/columnlist/coulmnlist-header.lua b/objects/internal/columnlist/coulmnlist-header.lua index 60fd444..74a6b28 100644 --- a/objects/internal/columnlist/coulmnlist-header.lua +++ b/objects/internal/columnlist/coulmnlist-header.lua @@ -5,7 +5,6 @@ -- columnlistheader class columnlistheader = class("columnlistheader", base) -columnlistheader:include(loveframes.templates.default) --[[--------------------------------------------------------- - func: initialize() @@ -44,6 +43,9 @@ function columnlistheader:initialize(name, parent) self.parent.internals[1]:Sort(key, self.descending) end + -- apply template properties to the object + loveframes.templates.ApplyToObject(self) + end --[[--------------------------------------------------------- @@ -112,8 +114,8 @@ function columnlistheader:draw() local draw = self.Draw local drawcount = loveframes.drawcount - loveframes.drawcount = drawcount + 1 - self.draworder = loveframes.drawcount + -- set the object's draw order + self:SetDrawOrder() if draw then draw(self) diff --git a/objects/internal/linenumberspanel.lua b/objects/internal/linenumberspanel.lua index 815ea55..c7aed36 100644 --- a/objects/internal/linenumberspanel.lua +++ b/objects/internal/linenumberspanel.lua @@ -5,7 +5,6 @@ -- linenumberspanel class linenumberspanel = class("linenumberspanel", base) -linenumberspanel:include(loveframes.templates.default) --[[--------------------------------------------------------- - func: initialize() @@ -22,6 +21,9 @@ function linenumberspanel:initialize(parent) self.staticy = 0 self.internal = true + -- apply template properties to the object + loveframes.templates.ApplyToObject(self) + end --[[--------------------------------------------------------- @@ -95,8 +97,8 @@ function linenumberspanel:draw() stencilfunc = function() love.graphics.rectangle("fill", self.parent.x, self.parent.y, self.width, self.parent.height - 16) end end - loveframes.drawcount = drawcount + 1 - self.draworder = loveframes.drawcount + -- set the object's draw order + self:SetDrawOrder() love.graphics.setStencil(stencilfunc) diff --git a/objects/internal/modalbackground.lua b/objects/internal/modalbackground.lua index ea7dbad..1f2f56c 100644 --- a/objects/internal/modalbackground.lua +++ b/objects/internal/modalbackground.lua @@ -5,7 +5,6 @@ -- modalbackground class modalbackground = class("modalbackground", base) -modalbackground:include(loveframes.templates.default) --[[--------------------------------------------------------- - func: initialize() @@ -28,6 +27,9 @@ function modalbackground:initialize(object) self:Remove() end + -- apply template properties to the object + loveframes.templates.ApplyToObject(self) + end --[[--------------------------------------------------------- @@ -45,8 +47,17 @@ function modalbackground:update(dt) end end - local object = self.object - local update = self.Update + local object = self.object + local update = self.Update + local base = loveframes.base + local basechildren = base.children + + if #basechildren > 1 then + if basechildren[#basechildren - 1] ~= self then + self:Remove() + table.insert(basechildren, self) + end + end if not object:IsActive() then self:Remove() @@ -78,8 +89,8 @@ function modalbackground:draw() local draw = self.Draw local drawcount = loveframes.drawcount - loveframes.drawcount = drawcount + 1 - self.draworder = loveframes.drawcount + -- set the object's draw order + self:SetDrawOrder() if draw then draw(self) diff --git a/objects/internal/multichoice/multichoice-list.lua b/objects/internal/multichoice/multichoice-list.lua index bc0c954..dee21be 100644 --- a/objects/internal/multichoice/multichoice-list.lua +++ b/objects/internal/multichoice/multichoice-list.lua @@ -5,7 +5,6 @@ -- multichoicelist class multichoicelist = class("multichoicelist", base) -multichoicelist:include(loveframes.templates.default) --[[--------------------------------------------------------- - func: initialize() @@ -26,7 +25,8 @@ function multichoicelist:initialize(object) self.spacing = self.list.listspacing self.offsety = 0 self.offsetx = 0 - self.extra = 0 + self.extrawidth = 0 + self.extraheight = 0 self.canremove = false self.internal = true self.vbar = false @@ -39,7 +39,10 @@ function multichoicelist:initialize(object) self:AddItem(row) end - table.insert(loveframes.base.children, self) + table.insert(loveframes.base.internals, self) + + -- apply template properties to the object + loveframes.templates.ApplyToObject(self) end @@ -133,8 +136,8 @@ function multichoicelist:draw() local internals = self.internals local children = self.children - loveframes.drawcount = drawcount + 1 - self.draworder = loveframes.drawcount + -- set the object's draw order + self:SetDrawOrder() if draw then draw(self) @@ -307,7 +310,7 @@ function multichoicelist:CalculateSize() if self.itemheight > height then - self.extra = self.itemheight - height + self.extraheight = self.itemheight - height if not vbar then local scroll = scrollbody:new(self, "vertical") diff --git a/objects/internal/multichoice/multichoice-row.lua b/objects/internal/multichoice/multichoice-row.lua index 7092485..16fc1f4 100644 --- a/objects/internal/multichoice/multichoice-row.lua +++ b/objects/internal/multichoice/multichoice-row.lua @@ -5,7 +5,6 @@ -- multichoicerow class multichoicerow = class("multichoicerow", base) -multichoicerow:include(loveframes.templates.default) --[[--------------------------------------------------------- - func: initialize() @@ -22,6 +21,9 @@ function multichoicerow:initialize() self.down = false self.canclick = false + -- apply template properties to the object + loveframes.templates.ApplyToObject(self) + end --[[--------------------------------------------------------- @@ -88,10 +90,9 @@ function multichoicerow:draw() local skin = skins[selfskin] or skins[skinindex] local drawfunc = skin.DrawMultiChoiceRow or skins[defaultskin].DrawMultiChoiceRow local draw = self.Draw - local drawcount = loveframes.drawcount - loveframes.drawcount = drawcount + 1 - self.draworder = loveframes.drawcount + -- set the object's draw order + self:SetDrawOrder() if draw then draw(self) @@ -147,6 +148,21 @@ function multichoicerow:mousereleased(x, y, button) end +--[[--------------------------------------------------------- + - func: keypressed(key) + - desc: called when the player presses a key +--]]--------------------------------------------------------- +function multichoicerow:keypressed(key, unicode) + + local text = self.text + local selectedobject = loveframes.selectedobject + + if key == "return" and selectedobject == self then + self.parent.list:SelectChoice(text) + end + +end + --[[--------------------------------------------------------- - func: SetText(text) - desc: sets the object's text diff --git a/objects/internal/scrollable/scrollarea.lua b/objects/internal/scrollable/scrollarea.lua index 7bf9d5e..770bab4 100644 --- a/objects/internal/scrollable/scrollarea.lua +++ b/objects/internal/scrollable/scrollarea.lua @@ -25,6 +25,9 @@ function scrollarea:initialize(parent, bartype) table.insert(self.internals, scrollbar:new(self, bartype)) + -- apply template properties to the object + loveframes.templates.ApplyToObject(self) + end --[[--------------------------------------------------------- @@ -138,8 +141,8 @@ function scrollarea:draw() local draw = self.Draw local drawcount = loveframes.drawcount - loveframes.drawcount = drawcount + 1 - self.draworder = loveframes.drawcount + -- set the object's draw order + self:SetDrawOrder() if draw then draw(self) diff --git a/objects/internal/scrollable/scrollbar.lua b/objects/internal/scrollable/scrollbar.lua index fecbfb9..80b5872 100644 --- a/objects/internal/scrollable/scrollbar.lua +++ b/objects/internal/scrollable/scrollbar.lua @@ -42,6 +42,9 @@ function scrollbar:initialize(parent, bartype) self.height = self.parent.height end + -- apply template properties to the object + loveframes.templates.ApplyToObject(self) + end --[[--------------------------------------------------------- @@ -207,8 +210,8 @@ function scrollbar:draw() local draw = self.Draw local drawcount = loveframes.drawcount - loveframes.drawcount = drawcount + 1 - self.draworder = loveframes.drawcount + -- set the object's draw order + self:SetDrawOrder() if draw then draw(self) diff --git a/objects/internal/scrollable/scrollbody.lua b/objects/internal/scrollable/scrollbody.lua index 550f221..51f1c57 100644 --- a/objects/internal/scrollable/scrollbody.lua +++ b/objects/internal/scrollable/scrollbody.lua @@ -88,6 +88,9 @@ function scrollbody:initialize(parent, bartype) end + -- apply template properties to the object + loveframes.templates.ApplyToObject(self) + end --[[--------------------------------------------------------- @@ -150,8 +153,8 @@ function scrollbody:draw() local drawcount = loveframes.drawcount local internals = self.internals - loveframes.drawcount = drawcount + 1 - self.draworder = loveframes.drawcount + -- set the object's draw order + self:SetDrawOrder() if draw then draw(self) diff --git a/objects/internal/scrollable/scrollbutton.lua b/objects/internal/scrollable/scrollbutton.lua index 780e133..67a8c8c 100644 --- a/objects/internal/scrollable/scrollbutton.lua +++ b/objects/internal/scrollable/scrollbutton.lua @@ -5,7 +5,6 @@ -- scrollbutton clas scrollbutton = class("scrollbutton", base) -scrollbutton:include(loveframes.templates.default) --[[--------------------------------------------------------- - func: initialize() @@ -21,6 +20,9 @@ function scrollbutton:initialize(scrolltype) self.internal = true self.OnClick = function() end + -- apply template properties to the object + loveframes.templates.ApplyToObject(self) + end --[[--------------------------------------------------------- @@ -90,8 +92,8 @@ function scrollbutton:draw() local draw = self.Draw local drawcount = loveframes.drawcount - loveframes.drawcount = drawcount + 1 - self.draworder = loveframes.drawcount + -- set the object's draw order + self:SetDrawOrder() if draw then draw(self) diff --git a/objects/internal/sliderbutton.lua b/objects/internal/sliderbutton.lua index 1f6b4a9..eb61cbc 100644 --- a/objects/internal/sliderbutton.lua +++ b/objects/internal/sliderbutton.lua @@ -5,7 +5,6 @@ -- sliderbutton class sliderbutton = class("sliderbutton", base) -sliderbutton:include(loveframes.templates.default) --[[--------------------------------------------------------- - func: initialize() @@ -28,6 +27,9 @@ function sliderbutton:initialize(parent) self.dragging = false self.parent = parent + -- apply template properties to the object + loveframes.templates.ApplyToObject(self) + end --[[--------------------------------------------------------- @@ -172,8 +174,8 @@ function sliderbutton:draw() local draw = self.Draw local drawcount = loveframes.drawcount - loveframes.drawcount = drawcount + 1 - self.draworder = loveframes.drawcount + -- set the object's draw order + self:SetDrawOrder() if draw then draw(self) diff --git a/objects/internal/tabbutton.lua b/objects/internal/tabbutton.lua index 01651eb..a54974a 100644 --- a/objects/internal/tabbutton.lua +++ b/objects/internal/tabbutton.lua @@ -5,7 +5,6 @@ -- tabbutton class tabbutton = class("tabbutton", base) -tabbutton:include(loveframes.templates.default) --[[--------------------------------------------------------- - func: initialize() @@ -35,6 +34,9 @@ function tabbutton:initialize(parent, text, tabnumber, tip, image) self:SetImage(image) end + -- apply template properties to the object + loveframes.templates.ApplyToObject(self) + end --[[--------------------------------------------------------- @@ -93,8 +95,8 @@ function tabbutton:draw() local draw = self.Draw local drawcount = loveframes.drawcount - loveframes.drawcount = drawcount + 1 - self.draworder = loveframes.drawcount + -- set the object's draw order + self:SetDrawOrder() if draw then draw(self) diff --git a/objects/internal/tooltip.lua b/objects/internal/tooltip.lua index a3bf4e1..a689fba 100644 --- a/objects/internal/tooltip.lua +++ b/objects/internal/tooltip.lua @@ -5,7 +5,6 @@ -- tooltip clas tooltip = class("tooltip", base) -tooltip:include(loveframes.templates.default) --[[--------------------------------------------------------- - func: initialize() @@ -35,6 +34,9 @@ function tooltip:initialize(object, text, width) self.text:SetWidth(width or 0) self.text:SetPos(0, 0) + -- apply template properties to the object + loveframes.templates.ApplyToObject(self) + table.insert(loveframes.base.internals, self) end @@ -139,8 +141,8 @@ function tooltip:draw() local draw = self.Draw local drawcount = loveframes.drawcount - loveframes.drawcount = drawcount + 1 - self.draworder = loveframes.drawcount + -- set the object's draw order + self:SetDrawOrder() if show then diff --git a/objects/list.lua b/objects/list.lua index 84f3e92..884f3a0 100644 --- a/objects/list.lua +++ b/objects/list.lua @@ -5,7 +5,6 @@ -- list class list = class("list", base) -list:include(loveframes.templates.default) --[[--------------------------------------------------------- - func: initialize() @@ -116,8 +115,8 @@ function list:draw() local draw = self.Draw local drawcount = loveframes.drawcount - loveframes.drawcount = drawcount + 1 - self.draworder = loveframes.drawcount + -- set the object's draw order + self:SetDrawOrder() if draw then draw(self) diff --git a/objects/multichoice.lua b/objects/multichoice.lua index c1390b5..2e0e078 100644 --- a/objects/multichoice.lua +++ b/objects/multichoice.lua @@ -5,7 +5,6 @@ -- multichoice class multichoice = class("multichoice", base) -multichoice:include(loveframes.templates.default) --[[--------------------------------------------------------- - func: initialize() @@ -43,12 +42,13 @@ function multichoice:update(dt) end local parent = self.parent + local base = loveframes.base local update = self.Update self:CheckHover() -- move to parent if there is a parent - if parent then + if parent ~= base then self.x = self.parent.x + self.staticx self.y = self.parent.y + self.staticy end @@ -80,8 +80,8 @@ function multichoice:draw() local draw = self.Draw local drawcount = loveframes.drawcount - loveframes.drawcount = drawcount + 1 - self.draworder = loveframes.drawcount + -- set the object's draw order + self:SetDrawOrder() if draw then draw(self) diff --git a/objects/panel.lua b/objects/panel.lua index 73fd41e..286171e 100644 --- a/objects/panel.lua +++ b/objects/panel.lua @@ -5,7 +5,6 @@ -- panel class panel = class("panel", base) -panel:include(loveframes.templates.default) --[[--------------------------------------------------------- - func: initialize() @@ -81,8 +80,8 @@ function panel:draw() local draw = self.Draw local drawcount = loveframes.drawcount - loveframes.drawcount = drawcount + 1 - self.draworder = loveframes.drawcount + -- set the object's draw order + self:SetDrawOrder() if draw then draw(self) diff --git a/objects/progressbar.lua b/objects/progressbar.lua index 4ada1f6..6a71567 100644 --- a/objects/progressbar.lua +++ b/objects/progressbar.lua @@ -5,7 +5,6 @@ -- progressbar class progressbar = class("progressbar", base) -progressbar:include(loveframes.templates.default) --[[--------------------------------------------------------- - func: initialize() @@ -143,8 +142,8 @@ function progressbar:draw() local draw = self.Draw local drawcount = loveframes.drawcount - loveframes.drawcount = drawcount + 1 - self.draworder = loveframes.drawcount + -- set the object's draw order + self:SetDrawOrder() if draw then draw(self) diff --git a/objects/slider.lua b/objects/slider.lua index 906990b..f1a7b01 100644 --- a/objects/slider.lua +++ b/objects/slider.lua @@ -3,9 +3,8 @@ -- Copyright (c) 2012 Kenny Shields -- --]]------------------------------------------------ --- text clas +-- slider class slider = class("slider", base) -slider:include(loveframes.templates.default) --[[--------------------------------------------------------- - func: initialize() @@ -104,8 +103,8 @@ function slider:draw() local draw = self.Draw local drawcount = loveframes.drawcount - loveframes.drawcount = drawcount + 1 - self.draworder = loveframes.drawcount + -- set the object's draw order + self:SetDrawOrder() if draw then draw(self) diff --git a/objects/tabs.lua b/objects/tabs.lua index 9692e34..5cf0d3a 100644 --- a/objects/tabs.lua +++ b/objects/tabs.lua @@ -5,7 +5,6 @@ -- tabs class tabs = class("tabpanel", base) -tabs:include(loveframes.templates.default) --[[--------------------------------------------------------- - func: initialize() @@ -122,8 +121,8 @@ function tabs:draw() local draw = self.Draw local drawcount = loveframes.drawcount - loveframes.drawcount = drawcount + 1 - self.draworder = loveframes.drawcount + -- set the object's draw order + self:SetDrawOrder() if draw then draw(self) diff --git a/objects/text.lua b/objects/text.lua index 156c50f..31861fc 100644 --- a/objects/text.lua +++ b/objects/text.lua @@ -7,9 +7,9 @@ -- note: the text wrapping of this object is experimental and not final --]]------------------------------------------------ + -- text class text = class("text", base) -text:include(loveframes.templates.default) --[[--------------------------------------------------------- - func: initialize() @@ -24,7 +24,7 @@ function text:initialize() self.height = 5 self.maxw = 0 self.lines = 1 - self.text = {} + self.formattedtext = {} self.original = {} self.internal = false @@ -79,8 +79,8 @@ function text:draw() local draw = self.Draw local drawcount = loveframes.drawcount - loveframes.drawcount = drawcount + 1 - self.draworder = loveframes.drawcount + -- set the object's draw order + self:SetDrawOrder() if draw then draw(self) @@ -130,7 +130,8 @@ function text:SetText(t) local inserts = {} local tdata, prevcolor - self.text = {} + self.text = "" + self.formattedtext = {} if dtype == "string" then tdata = {t} @@ -157,7 +158,7 @@ function text:SetText(t) prevcolor = v elseif dtype == "number" then - table.insert(self.text, {color = prevcolor, text = tostring(v)}) + table.insert(self.formattedtext, {color = prevcolor, text = tostring(v)}) elseif dtype == "string" then @@ -167,7 +168,7 @@ function text:SetText(t) local parts = loveframes.util.SplitString(v, " ") for i, j in ipairs(parts) do - table.insert(self.text, {color = prevcolor, text = j}) + table.insert(self.formattedtext, {color = prevcolor, text = j}) end end @@ -176,7 +177,7 @@ function text:SetText(t) if maxw > 0 then - for k, v in ipairs(self.text) do + for k, v in ipairs(self.formattedtext) do local data = v.text local width = font:getWidth(data) @@ -186,7 +187,7 @@ function text:SetText(t) if width > maxw then - table.remove(self.text, k) + table.remove(self.formattedtext, k) for n=1, #data do @@ -219,10 +220,10 @@ function text:SetText(t) end for k, v in ipairs(inserts) do - table.insert(self.text, v.key, {color = v.color, text = v.text}) + table.insert(self.formattedtext, v.key, {color = v.color, text = v.text}) end - local textdata = self.text + local textdata = self.formattedtext local maxw = self.maxw local font = self.font local height = font:getHeight("a") @@ -242,6 +243,8 @@ function text:SetText(t) if type(text) == "string" then + self.text = self.text .. text + local width = font:getWidth(text) totalwidth = totalwidth + width @@ -310,13 +313,23 @@ function text:GetText() end +--[[--------------------------------------------------------- + - func: GetFormattedText() + - desc: gets the object's formatted text +--]]--------------------------------------------------------- +function text:GetFormattedText() + + return self.formattedtext + +end + --[[--------------------------------------------------------- - func: Format() - desc: formats the text --]]--------------------------------------------------------- function text:DrawText() - local textdata = self.text + local textdata = self.formattedtext local font = self.font local x = self.x local y = self.y diff --git a/objects/textinput.lua b/objects/textinput.lua index c7f9b99..e826249 100644 --- a/objects/textinput.lua +++ b/objects/textinput.lua @@ -5,7 +5,6 @@ -- textinput class textinput = class("textinput", base) -textinput:include(loveframes.templates.default) --[[--------------------------------------------------------- - func: initialize() @@ -54,6 +53,7 @@ function textinput:initialize() self.alltextselected = false self.linenumbers = true self.linenumberspanel = false + self.editable = true self.internal = false self.OnEnter = nil self.OnTextChanged = nil @@ -258,8 +258,8 @@ function textinput:draw() local vbar = self.vbar local hbar = self.hbar - loveframes.drawcount = drawcount + 1 - self.draworder = loveframes.drawcount + -- set the object's draw order + self:SetDrawOrder() if vbar and hbar then stencilfunc = function() love.graphics.rectangle("fill", self.x, self.y, self.width - 16, self.height - 16) end @@ -460,6 +460,7 @@ function textinput:RunKey(key, unicode) local indicatornum = self.indicatornum local multiline = self.multiline local alltextselected = self.alltextselected + local editable = self.editable local ontextchanged = self.OnTextChanged local onenter = self.OnEnter @@ -526,6 +527,9 @@ function textinput:RunKey(key, unicode) -- key input checking system if key == "backspace" then + if not editable then + return + end local curindicatornum = self.indicatornum if alltextselected then self:Clear() @@ -602,6 +606,10 @@ function textinput:RunKey(key, unicode) else if unicode > 31 and unicode < 127 then + if not editable then + return + end + if alltextselected then self.alltextselected = false self:Clear() @@ -1036,6 +1044,17 @@ function textinput:SetUsable(usable) end +--[[--------------------------------------------------------- + - func: GetUsable() + - desc: gets what characters can be used for the + object's text +--]]--------------------------------------------------------- +function textinput:GetUsable() + + return self.usable + +end + --[[--------------------------------------------------------- - func: SetUnusable(unusable) - desc: sets what characters can not be used for the @@ -1047,6 +1066,17 @@ function textinput:SetUnusable(unusable) end +--[[--------------------------------------------------------- + - func: GetUnusable() + - desc: gets what characters can not be used for the + object's text +--]]--------------------------------------------------------- +function textinput:GetUnusable() + + return self.unusable + +end + --[[--------------------------------------------------------- - func: Clear() - desc: clears the object's text @@ -1382,4 +1412,26 @@ function textinput:GetTabReplacement() return self.tabreplacement +end + +--[[--------------------------------------------------------- + - func: SetEditable(bool) + - desc: sets whether or not the user can edit the + object's text +--]]--------------------------------------------------------- +function textinput:SetEditable(bool) + + self.editable = bool + +end + +--[[--------------------------------------------------------- + - func: GetEditable + - desc: gets whether or not the user can edit the + object's text +--]]--------------------------------------------------------- +function textinput:GetEditable() + + return self.editable + end \ No newline at end of file diff --git a/readme.md b/readme.md index 68ec52f..c5942eb 100644 --- a/readme.md +++ b/readme.md @@ -15,4 +15,4 @@ Created by Kenny Shields **Third Party Libraries** -- middleclass: kikito \ No newline at end of file +- middleclass: kikito - https://github.com/kikito/middleclass \ No newline at end of file diff --git a/skins.lua b/skins.lua index 0faf480..402a869 100644 --- a/skins.lua +++ b/skins.lua @@ -3,9 +3,16 @@ -- Copyright (c) 2012 Kenny Shields -- --]]------------------------------------------------ +-- skins library loveframes.skins = {} + +-- available skins loveframes.skins.available = {} +--[[--------------------------------------------------------- + - func: Register(skin) + - desc: registers a skin +--]]--------------------------------------------------------- function loveframes.skins.Register(skin) local name = skin.name @@ -18,23 +25,23 @@ function loveframes.skins.Register(skin) local indeximages = loveframes.config["INDEXSKINIMAGES"] if name == "" or not name then - error("Could not register skin: Invalid or missing name data.") + loveframes.util.Error("Could not register skin: Invalid or missing name data.") end if author == "" or not author then - error("Could not register skin: Invalid or missing author data.") + loveframes.util.Error("Could not register skin: Invalid or missing author data.") end if version == "" or version == nil then - error("Could not register skin: Invalid or missing version data.") + loveframes.util.Error("Could not register skin: Invalid or missing version data.") end if namecheck then - error("Could not register skin: A skin with the name '" ..name.. "' already exists.") + loveframes.util.Error("Could not register skin: A skin with the name '" ..name.. "' already exists.") end if not dircheck then - error("Could not register skin: Could not find a directory for skin '" ..name.. "'.") + loveframes.util.Error("Could not register skin: Could not find a directory for skin '" ..name.. "'.") end loveframes.skins.available[name] = skin diff --git a/skins/Blue/skin.lua b/skins/Blue/skin.lua index 9581598..34ff2bb 100644 --- a/skins/Blue/skin.lua +++ b/skins/Blue/skin.lua @@ -335,7 +335,7 @@ function skin.DrawButton(object) local bordernohovercolor = skin.controls.button_border_down_color local gradientcolor = {} - if down == true then + if down then -- button body love.graphics.setColor(unpack(bodydowncolor)) @@ -353,7 +353,7 @@ function skin.DrawButton(object) love.graphics.setColor(unpack(borderdowncolor)) skin.OutlinedRectangle(x, y, width, height) - elseif hover == true then + elseif hover then -- button body love.graphics.setColor(unpack(bodyhovercolor)) @@ -769,8 +769,6 @@ function skin.DrawTabButton(object) imagewidth = image:getWidth() imageheight = image:getHeight() end - - print(tabnumber, ptabnumber) if tabnumber == ptabnumber then @@ -922,7 +920,7 @@ function skin.DrawMultiChoiceRow(object) love.graphics.setFont(font) - if object.hover == true then + if object.hover then love.graphics.setColor(unpack(bodyhovecolor)) love.graphics.rectangle("fill", x, y, width, height) love.graphics.setColor(unpack(texthovercolor)) diff --git a/skins/Orange/skin.lua b/skins/Orange/skin.lua index a212c94..e54d02d 100644 --- a/skins/Orange/skin.lua +++ b/skins/Orange/skin.lua @@ -769,8 +769,6 @@ function skin.DrawTabButton(object) imagewidth = image:getWidth() imageheight = image:getHeight() end - - print(tabnumber, ptabnumber) if tabnumber == ptabnumber then diff --git a/templates.lua b/templates.lua index 85b3fa8..4fb2311 100644 --- a/templates.lua +++ b/templates.lua @@ -3,29 +3,187 @@ -- Copyright (c) 2012 Kenny Shields -- --]]------------------------------------------------ --- templates +-- templates library loveframes.templates = {} --- default template -loveframes.templates.default = -{ - x = 0, - y = 0, - width = 5, - height = 5, - staticx = 5, - staticy = 5, - draworder = 0, - internal = false, - visible = true, - hover = false, - alwaysupdate = false, - retainsize = false, - calledmousefunc = false, - skin = nil, - clickbounds = nil, - Draw = nil, - Update = nil, - OnMouseEnter = nil, - OnMouseExit = nil, -} \ No newline at end of file +-- available templates +loveframes.templates.available = {} + +-- objects +loveframes.templates.objects = {} + +--[[--------------------------------------------------------- + - func: AddProperty(templatename, property, value) + - desc: creates a property within the specified template + and assigns it to the specified object +--]]--------------------------------------------------------- +function loveframes.templates.AddProperty(templatename, object, property, value) + + -- display and error if name is nil or false + if not templatename then + loveframes.util.Error("Could not create property: No template name given.") + end + + -- display and error if property is nil or false + if not property then + loveframes.util.Error("Could not create property: No property name given.") + end + + -- display and error if value is nil or false + if not value then + loveframes.util.Error("Could not create property: No property value given.") + end + + local templatename = tostring(templatename) + local property = tostring(property) + local templates = loveframes.templates.available + local template = templates[templatename] + + -- display an error message if the property is not a string + if type(property) ~= "string" then + loveframes.util.Error("Could not create property: Property names must be strings.") + end + + -- display an error message if the property is an empty string + if property == "" then + loveframes.util.Error("Could not create property: Property names must not be empty.") + end + + -- display an error message if the template is invalid + if not template then + loveframes.util.Error("Could not add property '" ..property.. "' to template '" ..templatename.. "': Invalid template.") + end + + local properties = template.properties + local object = properties[object] + + if not object then + loveframes.util.Error("Could not add property '" ..property.. "' to template '" ..templatename.. "': Invalid object.") + end + + -- create the property within the template + object[property] = value + +end + +--[[--------------------------------------------------------- + - func: Register(template) + - desc: registers a template +--]]--------------------------------------------------------- +function loveframes.templates.Register(template) + + -- display and error message if template is nil or false + if not template then + loveframes.util.Error("Could not register template: Missing template argument.") + end + + -- display an error message if template is not a table + if type(template) ~= "table" then + loveframes.util.Error("Could not register template: Template argument must be a table.") + end + + local templates = loveframes.templates.available + local registeredobjects = loveframes.templates.objects + local name = template.name + local properties = template.properties + local objects = template.objects + local found = false + local foundall = false + + -- display an error message if a template name was not given + if not name then + loveframes.util.Error("Could not register template: No template name given.") + end + + if name == "Base" then + _G["base"]:include(template.properties["*"]) + end + + -- insert the template into the available templates table + templates[name] = template + +end + +--[[--------------------------------------------------------- + - func: Get(name) + - desc: gets a template +--]]--------------------------------------------------------- +function loveframes.templates.Get(name) + + -- display and error if name is nil or false + if not name then + loveframes.util.Error("Could not create property: No template name given.") + end + + local name = tostring(name) + local templates = loveframes.templates.available + local template = templates[name] + + -- display an error message if the template is invalid + if not template then + loveframes.util.Error("Could not get template: Invalid template.") + end + + -- return the template + return template + +end + +--[[--------------------------------------------------------- + - func: GetAvailable() + - desc: gets all available templates +--]]--------------------------------------------------------- +function loveframes.templates.GetAvailable() + + -- available templates + local templates = loveframes.templates.available + + -- return the templates + return templates + +end + +--[[--------------------------------------------------------- + - func: loveframes.templates.ApplyToObject(object) + - desc: applies the properties of registered templates + to an object +--]]--------------------------------------------------------- +function loveframes.templates.ApplyToObject(object) + + local templates = loveframes.templates.GetAvailable() + local type = object.type + + -- loop through all available templates + for k, v in pairs(templates) do + + -- make sure the base template doesn't get applied more than once + if k ~= "Base" then + + local properties = v.properties + local hasall = loveframes.util.TableHasKey(properties, "*") + local hasobject = false + + if not hasall then + hasobject = loveframes.util.TableHasKey(properties, type) + end + + if hasall then + + for k, v in pairs(properties["*"]) do + object[k] = v + end + + elseif hasobject then + + -- apply the template properties to the object + for k, v in pairs(properties[type]) do + object[k] = v + end + + end + + end + + end + +end \ No newline at end of file diff --git a/templates/base.lua b/templates/base.lua new file mode 100644 index 0000000..d582689 --- /dev/null +++ b/templates/base.lua @@ -0,0 +1 @@ +--[[------------------------------------------------ -- Love Frames - A GUI library for LOVE -- -- Copyright (c) 2012 Kenny Shields -- --]]------------------------------------------------ --[[------------------------------------------------ -- note: This is the base template for all Love Frames objects. You should not edit or delete this template unless you know what you are doing. --]]------------------------------------------------ -- template table local template = {} -- template name template.name = "Base" -- template properties template.properties = {} template.properties["*"] = { x = 0, y = 0, width = 5, height = 5, staticx = 0, staticy = 0, draworder = 0, internal = false, visible = true, hover = false, alwaysupdate = false, retainsize = false, calledmousefunc = false, skin = nil, clickbounds = nil, Draw = nil, Update = nil, OnMouseEnter = nil, OnMouseExit = nil } -- register the template loveframes.templates.Register(template) \ No newline at end of file diff --git a/util.lua b/util.lua index 84d902c..43f2f6f 100644 --- a/util.lua +++ b/util.lua @@ -62,7 +62,7 @@ function loveframes.util.GetCollisions(object, t) if col == true and object.collide ~= false then if object.clickbounds then local clickcol = loveframes.util.BoundingBox(x, object.clickbounds.x, y, object.clickbounds.y, 1, object.clickbounds.width, 1, object.clickbounds.height) - if clickcol == true then + if clickcol then table.insert(t, object) end else @@ -72,22 +72,22 @@ function loveframes.util.GetCollisions(object, t) end - -- check for internals - if object.internals then + -- check for children + if object.children then - for k, v in ipairs(object.internals) do - if v.visible == true and v.type ~= "tooltip" then + for k, v in ipairs(object.children) do + if v.visible then loveframes.util.GetCollisions(v, t) end end end - -- check for children - if object.children then + -- check for internals + if object.internals then - for k, v in ipairs(object.children) do - if v.visible == true then + for k, v in ipairs(object.internals) do + if v.visible and v.type ~= "tooltip" then loveframes.util.GetCollisions(v, t) end end @@ -267,4 +267,33 @@ function loveframes.util.RemoveAll() loveframes.base.children = {} loveframes.base.internals = {} +end + +--[[--------------------------------------------------------- + - func: loveframes.util.TableHasKey(table, key) + - desc: checks to see if a table has a specific key +--]]--------------------------------------------------------- +function loveframes.util.TableHasKey(table, key) + + local haskey = false + + for k, v in pairs(table) do + if k == key then + haskey = true + break + end + end + + return haskey + +end + +--[[--------------------------------------------------------- + - func: loveframes.util.Error(message) + - desc: displays a formatted error message +--]]--------------------------------------------------------- +function loveframes.util.Error(message) + + error("[Love Frames] " ..message) + end \ No newline at end of file