Version 0.9.4 - Alpha (see changelog.txt)

This commit is contained in:
Kenny Shields 2012-10-22 10:19:02 -04:00
parent 0e327e5d01
commit 851a7feb46
41 changed files with 635 additions and 194 deletions

View File

@ -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()
================================================

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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")

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -15,4 +15,4 @@ Created by Kenny Shields
**Third Party Libraries**
- middleclass: kikito
- middleclass: kikito - https://github.com/kikito/middleclass

View File

@ -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

View File

@ -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))

View File

@ -769,8 +769,6 @@ function skin.DrawTabButton(object)
imagewidth = image:getWidth()
imageheight = image:getHeight()
end
print(tabnumber, ptabnumber)
if tabnumber == ptabnumber then

View File

@ -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,
}
-- 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

1
templates/base.lua Normal file
View File

@ -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)

View File

@ -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