Version 0.9.3.2 - Alpha (see changelog.txt)

This commit is contained in:
Kenny Shields 2012-09-29 19:20:41 -04:00
parent d6190b4757
commit 0e327e5d01
41 changed files with 5041 additions and 2770 deletions

View File

@ -1,3 +1,65 @@
================================================
Version 0.9.3.2 - Alpha (Spetember 29 - 2012)
================================================
[ADDED] a new text input method: SetMultiline(bool)
[ADDED] a new text input method: GetVerticalScrollBody()
[ADDED] a new text input method: GetHorizontalScrollBody()
[ADDED] a new text input method: SetText(text)
[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()
[ADDED] a new text input method: GetTextY()
[ADDED] a new text input method: IsAllTextSelected()
[ADDED] a new text input method: GetLines()
[ADDED] a new text input method: GetOffsetX()
[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: GetLineNumbersEnabled()
[ADDED] a new text input method: GetItemWidth()
[ADDED] a new text input method: GetItemHeight()
[ADDED] a new text input method: SetTabReplacement(tabreplacement)
[ADDED] a new text input method: GetTabReplacement()
[ADDED] a new scroll area method: GetBarType()
[ADDED] a new scroll bar method: IsDragging()
[ADDED] a new scroll bar method: GetBarType()
[ADDED] a new scroll button method: GetScrollType()
[ADDED] a new tab button method: GetText()
[ADDED] a new tab button method: GetImage()
[ADDED] a new tab button method: GetTabNumber()
[ADDED] a new column list header method: GetName()
[ADDED] a new column list row method: GetColumnData()
[ADDED] a new multichoice method: SetText(text)
[ADDED] a new multichoice method: GetText()
[ADDED] a new multichoice row method: GetText()
[ADDED] a new progressbar method: GetBarWidth()
[ADDED] a new internal object: linenumberspanel
[ADDED] multiline support for the text input object
[ADDED] ability to select all text within a text input
[FIXED] progressbar object not positioning itself properly if it's parent was the base object
[FIXED] a typeo in the syntax of loveframes.util.SplitString (was "SplitSring", changed to "SplitString")
[FIXED] the tooltip object not disapearing if it was visible when it's object's visibility was changed to false
[FIXED] the text input object's x offset not being adjusted initially when the width of it's text would would become wider than it's drawing area
[CHANGED] massive code cleanup for optimization and
[CHANGED] frames can now be parent to other objects
[CHANGED] textinput:RunBlink() to textinput:UpdateIndicator()
[CHANGED] textinput:GetBlinkerVisisbility() to textinput:GetIndicatorVisisbility()
[CHANGED] textinput:MoveBlinker(num, exact) to textinput:MoveIndicator(num, exact)
[CHANGED] scrollbars now only autoscroll when their list's item width/height is greater thant their previous list's previous item width/height
[CHANGED] cleaned up the code for the default skins
[CHANGED] the text input object's text is no longer drawn internally by the object and should now be draw within the object's skin drawing function
[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()
================================================ ================================================
Version 0.9.3.1 - Alpha (Spetember 2 - 2012) Version 0.9.3.1 - Alpha (Spetember 2 - 2012)
================================================ ================================================

View File

@ -1,13 +1,14 @@
--[[------------------------------------------------ --[[------------------------------------------------
-- Löve Frames -- -- Love Frames - A GUI library for LOVE --
-- Copyright 2012 Kenny Shields -- -- Copyright (c) 2012 Kenny Shields --
--]]------------------------------------------------ --]]------------------------------------------------
-- debug library -- debug library
loveframes.debug = {} loveframes.debug = {}
local font = love.graphics.newFont(10) local font = love.graphics.newFont(10)
local loremipsum = local changelog, size = love.filesystem.read("libraries/loveframes/changelog.txt")
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. 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.
]] ]]
@ -23,7 +24,7 @@ function loveframes.debug.draw()
local debug = loveframes.config["DEBUG"] local debug = loveframes.config["DEBUG"]
-- do not draw anthing if debug is off -- do not draw anthing if debug is off
if debug == false then if not debug then
return return
end end
@ -38,7 +39,6 @@ function loveframes.debug.draw()
local fps = love.timer.getFPS() local fps = love.timer.getFPS()
local deltatime = love.timer.getDelta() local deltatime = love.timer.getDelta()
-- font for debug text -- font for debug text
love.graphics.setFont(font) love.graphics.setFont(font)
@ -608,14 +608,39 @@ function loveframes.debug.ExamplesMenu()
local frame1 = loveframes.Create("frame") local frame1 = loveframes.Create("frame")
frame1:SetName("Text Input") frame1:SetName("Text Input")
frame1:SetSize(500, 60) frame1:SetSize(500, 90)
frame1:Center() frame1:Center()
local textinput1 = loveframes.Create("textinput", frame1) local textinput1 = loveframes.Create("textinput", frame1)
textinput1:SetPos(5, 30) textinput1:SetPos(5, 30)
textinput1:SetWidth(490) textinput1:SetWidth(490)
textinput1.OnEnter = function(object) textinput1.OnEnter = function(object)
object:Clear() if not textinput1.multiline then
object:Clear()
end
end
textinput1:SetFont(love.graphics.newFont(12))
local togglebutton = loveframes.Create("button", frame1)
togglebutton:SetPos(5, 60)
togglebutton:SetWidth(490)
togglebutton:SetText("Toggle Multiline")
togglebutton.OnClick = function(object)
if textinput1.multiline then
frame1:SetHeight(90)
frame1:Center()
togglebutton:SetPos(5, 60)
textinput1:SetMultiline(false)
textinput1:SetHeight(25)
textinput1:SetText("")
else
frame1:SetHeight(365)
frame1:Center()
togglebutton:SetPos(5, 335)
textinput1:SetMultiline(true)
textinput1:SetHeight(300)
textinput1:SetText(changelog)
end
end end
end end

View File

@ -1,6 +1,6 @@
--[[------------------------------------------------ --[[------------------------------------------------
-- Löve Frames -- -- Love Frames - A GUI library for LOVE --
-- Copyright 2012 Kenny Shields -- -- Copyright (c) 2012 Kenny Shields --
--]]------------------------------------------------ --]]------------------------------------------------
-- central library table -- central library table
@ -9,7 +9,7 @@ loveframes = {}
-- library info -- library info
loveframes.info = {} loveframes.info = {}
loveframes.info.author = "Nikolai Resokav" loveframes.info.author = "Nikolai Resokav"
loveframes.info.version = "0.9.3.1" loveframes.info.version = "0.9.3.2"
loveframes.info.stage = "Alpha" loveframes.info.stage = "Alpha"
-- library configurations -- library configurations
@ -36,7 +36,7 @@ function loveframes.load()
local dir = loveframes.config["DIRECTORY"] local dir = loveframes.config["DIRECTORY"]
-- require the internal base libraries -- require the internal base libraries
require(dir .. "/third-party/middleclass/middleclass") require(dir .. "/third-party/middleclass")
require(dir .. "/util") require(dir .. "/util")
require(dir .. "/skins") require(dir .. "/skins")
require(dir .. "/templates") require(dir .. "/templates")
@ -172,7 +172,7 @@ function loveframes.Create(data, parent)
end end
-- remove the object if it is an internal -- remove the object if it is an internal
if object.internal == true then if object.internal then
object:Remove() object:Remove()
return return
end end
@ -182,7 +182,7 @@ function loveframes.Create(data, parent)
table.insert(loveframes.base.children, object) table.insert(loveframes.base.children, object)
-- if the parent argument is not nil, make that argument the object's new parent -- if the parent argument is not nil, make that argument the object's new parent
if parent ~= nil then if parent then
object:SetParent(parent) object:SetParent(parent)
end end

View File

@ -1,6 +1,6 @@
--[[------------------------------------------------ --[[------------------------------------------------
-- Löve Frames -- -- Love Frames - A GUI library for LOVE --
-- Copyright 2012 Kenny Shields -- -- Copyright (c) 2012 Kenny Shields --
--]]------------------------------------------------ --]]------------------------------------------------
-- base object -- base object
@ -74,7 +74,7 @@ function base:mousepressed(x, y, button)
local children = self.children local children = self.children
local internals = self.internals local internals = self.internals
if visible == false then if not visible then
return return
end end
@ -102,7 +102,7 @@ function base:mousereleased(x, y, button)
local children = self.children local children = self.children
local internals = self.internals local internals = self.internals
if visible == false then if not visible then
return return
end end
@ -130,7 +130,7 @@ function base:keypressed(key, unicode)
local children = self.children local children = self.children
local internals = self.internals local internals = self.internals
if visible == false then if not visible then
return return
end end
@ -158,7 +158,7 @@ function base:keyreleased(key)
local children = self.children local children = self.children
local internals = self.internals local internals = self.internals
if visible == false then if not visible then
return return
end end
@ -466,10 +466,6 @@ function base:SetParent(parent)
return return
end end
if stype == "frame" then
return
end
self:Remove() self:Remove()
self.parent = tparent self.parent = tparent
@ -498,23 +494,19 @@ function base:Remove()
local pchildren = self.parent.children local pchildren = self.parent.children
if pinternals then if pinternals then
for k, v in ipairs(pinternals) do for k, v in ipairs(pinternals) do
if v == self then if v == self then
table.remove(pinternals, k) table.remove(pinternals, k)
end end
end end
end end
if pchildren then if pchildren then
for k, v in ipairs(pchildren) do for k, v in ipairs(pchildren) do
if v == self then if v == self then
table.remove(pchildren, k) table.remove(pchildren, k)
end end
end end
end end
self.removed = true self.removed = true
@ -658,12 +650,12 @@ function base:CheckHover()
local clickbounds = self.clickbounds local clickbounds = self.clickbounds
-- is the mouse inside the object? -- is the mouse inside the object?
if selfcol == true then if selfcol then
local top = self:IsTopCollision() local top = self:IsTopCollision()
if top == true then if top then
if hoverobject == false then if not hoverobject then
self.hover = true self.hover = true
else else
if hoverobject == self then if hoverobject == self then
@ -677,7 +669,7 @@ function base:CheckHover()
end end
if clickbounds then if clickbounds then
if self:InClickBounds() == false then if not self:InClickBounds() then
self.hover = false self.hover = false
end end
end end
@ -688,7 +680,7 @@ function base:CheckHover()
end end
if modalobject ~= false then if modalobject then
if modalobject ~= self then if modalobject ~= self then
@ -711,9 +703,9 @@ function base:CheckHover()
-- this chunk of code handles mouse enter and exit -- this chunk of code handles mouse enter and exit
if self.hover == true then if self.hover == true then
if self.calledmousefunc == false then if not self.calledmousefunc then
if self.OnMouseEnter ~= nil then if self.OnMouseEnter then
self.OnMouseEnter(self) self.OnMouseEnter(self)
self.calledmousefunc = true self.calledmousefunc = true
else else
@ -724,9 +716,9 @@ function base:CheckHover()
else else
if self.calledmousefunc == true then if self.calledmousefunc then
if self.OnMouseExit ~= nil then if self.OnMouseExit then
self.OnMouseExit(self) self.OnMouseExit(self)
self.calledmousefunc = false self.calledmousefunc = false
else else
@ -849,7 +841,7 @@ function base:MoveToTop()
self:Remove() self:Remove()
if internal == true then if internal then
table.insert(pinternals, self) table.insert(pinternals, self)
else else
table.insert(pchildren, self) table.insert(pchildren, self)

View File

@ -1,9 +1,9 @@
--[[------------------------------------------------ --[[------------------------------------------------
-- Löve Frames -- -- Love Frames - A GUI library for LOVE --
-- Copyright 2012 Kenny Shields -- -- Copyright (c) 2012 Kenny Shields --
--]]------------------------------------------------ --]]------------------------------------------------
-- button clas -- button class
button = class("button", base) button = class("button", base)
button:include(loveframes.templates.default) button:include(loveframes.templates.default)
@ -13,15 +13,15 @@ button:include(loveframes.templates.default)
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function button:initialize() function button:initialize()
self.type = "button" self.type = "button"
self.text = "Button" self.text = "Button"
self.width = 80 self.width = 80
self.height = 25 self.height = 25
self.internal = false self.internal = false
self.down = false self.down = false
self.clickable = true self.clickable = true
self.enabled = true self.enabled = true
self.OnClick = nil self.OnClick = nil
end end
@ -34,38 +34,41 @@ function button:update(dt)
local visible = self.visible local visible = self.visible
local alwaysupdate = self.alwaysupdate local alwaysupdate = self.alwaysupdate
if visible == false then if not visible then
if alwaysupdate == false then if not alwaysupdate then
return return
end end
end end
self:CheckHover() self:CheckHover()
local hover = self.hover local hover = self.hover
local down = self.down local down = self.down
local hoverobject = loveframes.hoverobject local hoverobject = loveframes.hoverobject
local parent = self.parent
local base = loveframes.base
local update = self.Update
if hover == false then if not hover then
self.down = false self.down = false
elseif hover == true then else
if hoverobject == self then if hoverobject == self then
self.down = true self.down = true
end end
end end
if down == false and hoverobject == self then if not down and hoverobject == self then
self.hover = true self.hover = true
end end
-- move to parent if there is a parent -- move to parent if there is a parent
if self.parent ~= loveframes.base then if parent ~= base then
self.x = self.parent.x + self.staticx self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy self.y = self.parent.y + self.staticy
end end
if self.Update then if update then
self.Update(self, dt) update(self, dt)
end end
end end
@ -78,22 +81,24 @@ function button:draw()
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
local skins = loveframes.skins.available local skins = loveframes.skins.available
local skinindex = loveframes.config["ACTIVESKIN"] local skinindex = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"] local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin local selfskin = self.skin
local skin = skins[selfskin] or skins[skinindex] local skin = skins[selfskin] or skins[skinindex]
local drawfunc = skin.DrawButton or skins[defaultskin].DrawButton local drawfunc = skin.DrawButton or skins[defaultskin].DrawButton
local draw = self.Draw
local drawcount = loveframes.drawcount
loveframes.drawcount = loveframes.drawcount + 1 loveframes.drawcount = drawcount + 1
self.draworder = loveframes.drawcount self.draworder = loveframes.drawcount
if self.Draw ~= nil then if draw then
self.Draw(self) draw(self)
else else
drawfunc(self) drawfunc(self)
end end
@ -108,13 +113,13 @@ function button:mousepressed(x, y, button)
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
local hover = self.hover local hover = self.hover
if hover == true and button == "l" then if hover and button == "l" then
local baseparent = self:GetBaseParent() local baseparent = self:GetBaseParent()
@ -137,19 +142,20 @@ function button:mousereleased(x, y, button)
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
local hover = self.hover local hover = self.hover
local down = self.down local down = self.down
local clickable = self.clickable local clickable = self.clickable
local enabled = self.enabled local enabled = self.enabled
local onclick = self.OnClick
if hover == true and down == true and button == "l" and clickable == true then if hover and down and clickable and button == "l" then
if enabled == true then if enabled then
if self.OnClick then if onclick then
self.OnClick(self, x, y) onclick(self, x, y)
end end
end end
end end

View File

@ -1,6 +1,6 @@
--[[------------------------------------------------ --[[------------------------------------------------
-- Löve Frames -- -- Love Frames - A GUI library for LOVE --
-- Copyright 2012 Kenny Shields -- -- Copyright (c) 2012 Kenny Shields --
--]]------------------------------------------------ --]]------------------------------------------------
-- checkbox class -- checkbox class
@ -13,18 +13,18 @@ checkbox:include(loveframes.templates.default)
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function checkbox:initialize() function checkbox:initialize()
self.type = "checkbox" self.type = "checkbox"
self.width = 0 self.width = 0
self.height = 0 self.height = 0
self.boxwidth = 20 self.boxwidth = 20
self.boxheight = 20 self.boxheight = 20
self.font = loveframes.basicfont self.font = loveframes.basicfont
self.checked = false self.checked = false
self.lastvalue = false self.lastvalue = false
self.internal = false self.internal = false
self.down = true self.down = true
self.internals = {} self.internals = {}
self.OnChanged = nil self.OnChanged = nil
end end
@ -37,59 +37,67 @@ function checkbox:update(dt)
local visible = self.visible local visible = self.visible
local alwaysupdate = self.alwaysupdate local alwaysupdate = self.alwaysupdate
if visible == false then if not visible then
if alwaysupdate == false then if not alwaysupdate then
return return
end end
end end
self:CheckHover() self:CheckHover()
if self.hover == false then local hover = self.hover
local internals = self.internals
local boxwidth = self.boxwidth
local boxheight = self.boxheight
local parent = self.parent
local base = loveframes.base
local update = self.Update
if not hover then
self.down = false self.down = false
elseif self.hover == true then else
if loveframes.hoverobject == self then if loveframes.hoverobject == self then
self.down = true self.down = true
end end
end end
if self.down == false and loveframes.hoverobject == self then if not self.down and loveframes.hoverobject == self then
self.hover = true self.hover = true
end end
-- move to parent if there is a parent -- move to parent if there is a parent
if self.parent ~= loveframes.base and self.parent.type ~= "list" then if parent ~= base and parent.type ~= "list" then
self.x = self.parent.x + self.staticx self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy self.y = self.parent.y + self.staticy
end end
if self.internals[1] then if internals[1] then
self.width = self.boxwidth + 5 + self.internals[1].width self.width = boxwidth + 5 + internals[1].width
if self.internals[1].height == self.boxheight then if internals[1].height == boxheight then
self.height = self.boxheight self.height = boxheight
else else
if self.internals[1].height > self.boxheight then if internals[1].height > boxheight then
self.height = self.internals[1].height self.height = internals[1].height
else else
self.height = self.boxheight self.height = boxheight
end end
end end
else else
self.width = self.boxwidth self.width = boxwidth
self.height = self.boxheight self.height = boxheight
end end
for k, v in ipairs(self.internals) do for k, v in ipairs(internals) do
v:update(dt) v:update(dt)
end end
if self.Update then if update then
self.Update(self, dt) update(self, dt)
end end
end end
@ -102,27 +110,30 @@ function checkbox:draw()
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
local skins = loveframes.skins.available local skins = loveframes.skins.available
local skinindex = loveframes.config["ACTIVESKIN"] local skinindex = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"] local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin local selfskin = self.skin
local skin = skins[selfskin] or skins[skinindex] local skin = skins[selfskin] or skins[skinindex]
local drawfunc = skin.DrawCheckBox or skins[defaultskin].DrawCheckBox local drawfunc = skin.DrawCheckBox or skins[defaultskin].DrawCheckBox
local draw = self.Draw
local internals = self.internals
local drawcount = loveframes.drawcount
loveframes.drawcount = loveframes.drawcount + 1 loveframes.drawcount = drawcount + 1
self.draworder = loveframes.drawcount self.draworder = loveframes.drawcount
if self.Draw ~= nil then if draw then
self.Draw(self) draw(self)
else else
drawfunc(self) drawfunc(self)
end end
for k, v in ipairs(self.internals) do for k, v in ipairs(internals) do
v:draw() v:draw()
end end
@ -136,13 +147,13 @@ function checkbox:mousepressed(x, y, button)
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
local hover = self.hover local hover = self.hover
if hover == true and button == "l" then if hover and button == "l" then
local baseparent = self:GetBaseParent() local baseparent = self:GetBaseParent()
@ -165,23 +176,24 @@ function checkbox:mousereleased(x, y, button)
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
local hover = self.hover local hover = self.hover
local checked = self.checked local checked = self.checked
local onchanged = self.OnChanged
if hover == true and button == "l" then if hover and button == "l" then
if checked == true then if checked then
self.checked = false self.checked = false
else else
self.checked = true self.checked = true
end end
if self.OnChanged then if onchanged then
self.OnChanged(self) onchanged(self)
end end
end end
@ -194,6 +206,9 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function checkbox:SetText(text) function checkbox:SetText(text)
local boxwidth = self.boxwidth
local boxheight = self.boxheight
if text ~= "" then if text ~= "" then
self.internals = {} self.internals = {}
@ -205,10 +220,10 @@ function checkbox:SetText(text)
textobject:SetFont(self.font) textobject:SetFont(self.font)
textobject:SetText(text) textobject:SetText(text)
textobject.Update = function(object, dt) textobject.Update = function(object, dt)
if object.height > self.boxheight then if object.height > boxheight then
object:SetPos(self.boxwidth + 5, 0) object:SetPos(boxwidth + 5, 0)
else else
object:SetPos(self.boxwidth + 5, self.boxheight/2 - object.height/2) object:SetPos(boxwidth + 5, boxheight/2 - object.height/2)
end end
end end
@ -216,8 +231,8 @@ function checkbox:SetText(text)
else else
self.width = self.boxwidth self.width = boxwidth
self.height = self.boxheight self.height = boxheight
self.internals = {} self.internals = {}
end end
@ -231,7 +246,7 @@ end
function checkbox:GetText() function checkbox:GetText()
local internals = self.internals local internals = self.internals
local text = internals[1] local text = internals[1]
if text then if text then
return text.text return text.text
@ -247,7 +262,7 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function checkbox:SetSize(width, height) function checkbox:SetSize(width, height)
self.boxwidth = width self.boxwidth = width
self.boxheight = height self.boxheight = height
end end
@ -278,10 +293,12 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function checkbox:SetChecked(bool) function checkbox:SetChecked(bool)
local onchanged = self.OnChanged
self.checked = bool self.checked = bool
if self.OnChanged then if onchanged then
self.OnChanged(self) onchanged(self)
end end
end end
@ -303,7 +320,7 @@ end
function checkbox:SetFont(font) function checkbox:SetFont(font)
local internals = self.internals local internals = self.internals
local text = internals[1] local text = internals[1]
self.font = font self.font = font

View File

@ -1,9 +1,9 @@
--[[------------------------------------------------ --[[------------------------------------------------
-- Löve Frames -- -- Love Frames - A GUI library for LOVE --
-- Copyright 2012 Kenny Shields -- -- Copyright (c) 2012 Kenny Shields --
--]]------------------------------------------------ --]]------------------------------------------------
-- button clas -- collapsiblecategory class
collapsiblecategory = class("collapsiblecategory", base) collapsiblecategory = class("collapsiblecategory", base)
collapsiblecategory:include(loveframes.templates.default) collapsiblecategory:include(loveframes.templates.default)
@ -13,17 +13,17 @@ collapsiblecategory:include(loveframes.templates.default)
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function collapsiblecategory:initialize() function collapsiblecategory:initialize()
self.type = "collapsiblecategory" self.type = "collapsiblecategory"
self.text = "Category" self.text = "Category"
self.width = 200 self.width = 200
self.height = 25 self.height = 25
self.closedheight = 25 self.closedheight = 25
self.padding = 5 self.padding = 5
self.internal = false self.internal = false
self.open = false self.open = false
self.down = false self.down = false
self.children = {} self.children = {}
self.OnOpenedClosed = nil self.OnOpenedClosed = nil
end end
@ -33,34 +33,37 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function collapsiblecategory:update(dt) function collapsiblecategory:update(dt)
local visible = self.visible local visible = self.visible
local alwaysupdate = self.alwaysupdate local alwaysupdate = self.alwaysupdate
if visible == false then if not visible then
if alwaysupdate == false then if not alwaysupdate then
return return
end end
end end
local open = self.open local open = self.open
local children = self.children local children = self.children
local curobject = children[1] local curobject = children[1]
local parent = self.parent
local base = loveframes.base
local update = self.Update
self:CheckHover() self:CheckHover()
-- move to parent if there is a parent -- move to parent if there is a parent
if self.parent ~= loveframes.base and self.parent.type ~= "list" then if parent ~= base and parent.type ~= "list" then
self.x = self.parent.x + self.staticx self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy self.y = self.parent.y + self.staticy
end end
if open == true then if open == true then
curobject:SetWidth(self.width - self.padding*2) curobject:SetWidth(self.width - self.padding * 2)
curobject:update(dt) curobject:update(dt)
end end
if self.Update then if update then
self.Update(self, dt) update(self, dt)
end end
end end
@ -77,26 +80,28 @@ function collapsiblecategory:draw()
return return
end end
local open = self.open local open = self.open
local children = self.children local children = self.children
local curobject = children[1] local curobject = children[1]
local skins = loveframes.skins.available local skins = loveframes.skins.available
local skinindex = loveframes.config["ACTIVESKIN"] local skinindex = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"] local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin local selfskin = self.skin
local skin = skins[selfskin] or skins[skinindex] local skin = skins[selfskin] or skins[skinindex]
local drawfunc = skin.DrawCollapsibleCategory or skins[defaultskin].DrawCollapsibleCategory local drawfunc = skin.DrawCollapsibleCategory or skins[defaultskin].DrawCollapsibleCategory
local draw = self.Draw
local drawcount = loveframes.drawcount
loveframes.drawcount = loveframes.drawcount + 1 loveframes.drawcount = drawcount + 1
self.draworder = loveframes.drawcount self.draworder = loveframes.drawcount
if self.Draw ~= nil then if draw then
self.Draw(self) draw(self)
else else
drawfunc(self) drawfunc(self)
end end
if open == true then if open then
curobject:draw() curobject:draw()
end end
@ -110,20 +115,20 @@ function collapsiblecategory:mousepressed(x, y, button)
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
local hover = self.hover local hover = self.hover
local open = self.open local open = self.open
local children = self.children local children = self.children
local curobject = children[1] local curobject = children[1]
if hover == true then if hover then
local col = loveframes.util.BoundingBox(self.x, x, self.y, y, self.width, 1, self.closedheight, 1) local col = loveframes.util.BoundingBox(self.x, x, self.y, y, self.width, 1, self.closedheight, 1)
if button == "l" and col == true then if button == "l" and col then
local baseparent = self:GetBaseParent() local baseparent = self:GetBaseParent()
@ -138,7 +143,7 @@ function collapsiblecategory:mousepressed(x, y, button)
end end
if open == true then if open then
curobject:mousepressed(x, y, button) curobject:mousepressed(x, y, button)
end end
@ -152,22 +157,22 @@ function collapsiblecategory:mousereleased(x, y, button)
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
local hover = self.hover local hover = self.hover
local down = self.down local down = self.down
local clickable = self.clickable local clickable = self.clickable
local enabled = self.enabled local enabled = self.enabled
local open = self.open local open = self.open
local col = loveframes.util.BoundingBox(self.x, x, self.y, y, self.width, 1, self.closedheight, 1) local col = loveframes.util.BoundingBox(self.x, x, self.y, y, self.width, 1, self.closedheight, 1)
local children = self.children local children = self.children
local curobject = children[1] local curobject = children[1]
if hover == true and button == "l" and col == true and self.down == true then if hover and col and down and button == "l" then
if open == true then if open then
self:SetOpen(false) self:SetOpen(false)
else else
self:SetOpen(true) self:SetOpen(true)
@ -177,7 +182,7 @@ function collapsiblecategory:mousereleased(x, y, button)
end end
if open == true then if open then
curobject:mousepressed(x, y, button) curobject:mousepressed(x, y, button)
end end
@ -209,7 +214,7 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function collapsiblecategory:SetObject(object) function collapsiblecategory:SetObject(object)
local children = self.children local children = self.children
local curobject = children[1] local curobject = children[1]
if curobject then if curobject then
@ -232,7 +237,7 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function collapsiblecategory:GetObject() function collapsiblecategory:GetObject()
local children = self.children local children = self.children
local curobject = children[1] local curobject = children[1]
if curobject then if curobject then
@ -289,25 +294,30 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function collapsiblecategory:SetOpen(bool) function collapsiblecategory:SetOpen(bool)
local children = self.children local children = self.children
local curobject = children[1] local curobject = children[1]
local closedheight = self.closedheight
local padding = self.padding
local curobjectheight = curobject.height
local onopenedclosed = self.OnOpenedClosed
self.open = bool self.open = bool
if bool == false then if not bool then
self.height = self.closedheight self.height = closedheight
if curobject then if curobject then
curobject:SetVisible(false) curobject:SetVisible(false)
end end
else else
self.height = self.closedheight + self.padding*2 + curobject.height self.height = closedheight + padding * 2 + curobjectheight
if curobject then if curobject then
curobject:SetVisible(true) curobject:SetVisible(true)
end end
end end
if self.OnOpenedClosed then -- call the on opened closed callback if it exists
self.OnOpenedClosed(self) if onopenedclosed then
onopenedclosed(self)
end end
end end

View File

@ -1,9 +1,9 @@
--[[------------------------------------------------ --[[------------------------------------------------
-- Löve Frames -- -- Love Frames - A GUI library for LOVE --
-- Copyright 2012 Kenny Shields -- -- Copyright (c) 2012 Kenny Shields --
--]]------------------------------------------------ --]]------------------------------------------------
-- columnlist object -- columnlist class
columnlist = class("columnlist", base) columnlist = class("columnlist", base)
columnlist:include(loveframes.templates.default) columnlist:include(loveframes.templates.default)
@ -13,15 +13,15 @@ columnlist:include(loveframes.templates.default)
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function columnlist:initialize() function columnlist:initialize()
self.type = "columnlist" self.type = "columnlist"
self.width = 300 self.width = 300
self.height = 100 self.height = 100
self.autoscroll = false self.autoscroll = false
self.internal = false self.internal = false
self.children = {} self.children = {}
self.internals = {} self.internals = {}
self.OnRowClicked = nil self.OnRowClicked = nil
self.OnScroll = nil self.OnScroll = nil
local list = columnlistarea:new(self) local list = columnlistarea:new(self)
table.insert(self.internals, list) table.insert(self.internals, list)
@ -37,19 +37,22 @@ function columnlist:update(dt)
local visible = self.visible local visible = self.visible
local alwaysupdate = self.alwaysupdate local alwaysupdate = self.alwaysupdate
if visible == false then if not visible then
if alwaysupdate == false then if not alwaysupdate then
return return
end end
end end
local children = self.children local parent = self.parent
local base = loveframes.base
local children = self.children
local internals = self.internals local internals = self.internals
local update = self.Update
self:CheckHover() self:CheckHover()
-- move to parent if there is a parent -- move to parent if there is a parent
if self.parent ~= loveframes.base then if parent ~= base then
self.x = self.parent.x + self.staticx self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy self.y = self.parent.y + self.staticy
end end
@ -62,8 +65,8 @@ function columnlist:update(dt)
v:update(dt) v:update(dt)
end end
if self.Update then if update then
self.Update(self, dt) update(self, dt)
end end
end end
@ -76,27 +79,26 @@ function columnlist:draw()
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
loveframes.drawcount = loveframes.drawcount + 1 local children = self.children
local internals = self.internals
local skins = loveframes.skins.available
local skinindex = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin
local skin = skins[selfskin] or skins[skinindex]
local drawfunc = skin.DrawColumnList or skins[defaultskin].DrawColumnList
local draw = self.Draw
local drawcount = loveframes.drawcount
loveframes.drawcount = drawcount + 1
self.draworder = loveframes.drawcount self.draworder = loveframes.drawcount
local children = self.children if draw then
local internals = self.internals draw(self)
local skins = loveframes.skins.available
local skinindex = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin
local skin = skins[selfskin] or skins[skinindex]
local drawfunc = skin.DrawColumnList or skins[defaultskin].DrawColumnList
loveframes.drawcount = loveframes.drawcount + 1
self.draworder = loveframes.drawcount
if self.Draw ~= nil then
self.Draw(self)
else else
drawfunc(self) drawfunc(self)
end end
@ -123,8 +125,8 @@ function columnlist:mousepressed(x, y, button)
return return
end end
local hover = self.hover local hover = self.hover
local children = self.children local children = self.children
local internals = self.internals local internals = self.internals
if hover == true and button == "l" then if hover == true and button == "l" then
@ -179,16 +181,16 @@ end
function columnlist:AdjustColumns() function columnlist:AdjustColumns()
local width = self.width local width = self.width
local bar = self.internals[1].bar local bar = self.internals[1].bar
if bar == true then if bar == true then
width = width - 16 width = width - 16
end end
local children = self.children local children = self.children
local numchildren = #children local numchildren = #children
local columnwidth = width/numchildren local columnwidth = width/numchildren
local x = 0 local x = 0
for k, v in ipairs(children) do for k, v in ipairs(children) do
if bar == true then if bar == true then
@ -210,12 +212,13 @@ end
function columnlist:AddColumn(name) function columnlist:AddColumn(name)
local internals = self.internals local internals = self.internals
local list = internals[1] local list = internals[1]
local height = self.height
columnlistheader:new(name, self) columnlistheader:new(name, self)
self:AdjustColumns() self:AdjustColumns()
list:SetSize(self.width, self.height) list:SetSize(self.width, height)
list:SetPos(0, 0) list:SetPos(0, 0)
end end
@ -227,7 +230,7 @@ end
function columnlist:AddRow(...) function columnlist:AddRow(...)
local internals = self.internals local internals = self.internals
local list = internals[1] local list = internals[1]
list:AddRow(arg) list:AddRow(arg)
@ -239,11 +242,11 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function columnlist:GetColumnSize() function columnlist:GetColumnSize()
local children = self.children local children = self.children
local numchildren = #self.children local numchildren = #self.children
local column = self.children[1] local column = self.children[1]
local colwidth = column.width local colwidth = column.width
local colheight = column.height local colheight = column.height
if numchildren > 0 then if numchildren > 0 then
return colwidth, colheight return colwidth, colheight
@ -260,7 +263,7 @@ end
function columnlist:SetSize(width, height) function columnlist:SetSize(width, height)
local internals = self.internals local internals = self.internals
local list = internals[1] local list = internals[1]
self.width = width self.width = width
self.height = height self.height = height
@ -277,7 +280,7 @@ end
function columnlist:SetWidth(width) function columnlist:SetWidth(width)
local internals = self.internals local internals = self.internals
local list = internals[1] local list = internals[1]
self.width = width self.width = width
@ -293,7 +296,7 @@ end
function columnlist:SetHeight(height) function columnlist:SetHeight(height)
local internals = self.internals local internals = self.internals
local list = internals[1] local list = internals[1]
self.height = height self.height = height
@ -310,7 +313,7 @@ end
function columnlist:SetMaxColorIndex(num) function columnlist:SetMaxColorIndex(num)
local internals = self.internals local internals = self.internals
local list = internals[1] local list = internals[1]
list.colorindexmax = num list.colorindexmax = num
@ -323,7 +326,7 @@ end
function columnlist:Clear() function columnlist:Clear()
local internals = self.internals local internals = self.internals
local list = internals[1] local list = internals[1]
list:Clear() list:Clear()
@ -338,13 +341,14 @@ end
function columnlist:SetAutoScroll(bool) function columnlist:SetAutoScroll(bool)
local internals = self.internals local internals = self.internals
local list = internals[1] local list = internals[1]
local scrollbar = list:GetScrollBar()
self.autoscroll = bool self.autoscroll = bool
if list then if list then
if list:GetScrollBar() ~= false then if scrollbar then
list:GetScrollBar().autoscroll = bool scrollbar.autoscroll = bool
end end
end end

View File

@ -1,6 +1,6 @@
--[[------------------------------------------------ --[[------------------------------------------------
-- Löve Frames -- -- Love Frames - A GUI library for LOVE --
-- Copyright 2012 Kenny Shields -- -- Copyright (c) 2012 Kenny Shields --
--]]------------------------------------------------ --]]------------------------------------------------
-- frame class -- frame class
@ -13,34 +13,33 @@ frame:include(loveframes.templates.default)
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function frame:initialize() function frame:initialize()
self.type = "frame" self.type = "frame"
self.name = "Frame" self.name = "Frame"
self.width = 300 self.width = 300
self.height = 150 self.height = 150
self.clickx = 0 self.clickx = 0
self.clicky = 0 self.clicky = 0
self.internal = false self.internal = false
self.draggable = true self.draggable = true
self.screenlocked = false self.screenlocked = false
self.dragging = false self.dragging = false
self.modal = false self.modal = false
self.modalbackground = false self.modalbackground = false
self.showclose = true self.showclose = true
self.internals = {} self.internals = {}
self.children = {} self.children = {}
self.OnClose = nil self.OnClose = nil
-- create the close button for the frame
local close = closebutton:new() local close = closebutton:new()
close.parent = self close.parent = self
close:SetSize(16, 16) close:SetSize(16, 16)
close.OnClick = function() close.OnClick = function()
local onclose = self.OnClose
self:Remove() self:Remove()
if onclose then
if self.OnClose then onclose(self)
self.OnClose(self)
end end
end end
table.insert(self.internals, close) table.insert(self.internals, close)
@ -53,33 +52,34 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function frame:update(dt) function frame:update(dt)
local visible = self.visible local visible = self.visible
local alwaysupdate = self.alwaysupdate local alwaysupdate = self.alwaysupdate
if visible == false then if not visible then
if alwaysupdate == false then if not alwaysupdate then
return return
end end
end end
local x, y = love.mouse.getPosition() local x, y = love.mouse.getPosition()
local showclose = self.showclose local showclose = self.showclose
local close = self.internals[1] local close = self.internals[1]
local dragging = self.dragging local dragging = self.dragging
local screenlocked = self.screenlocked local screenlocked = self.screenlocked
local modal = self.modal local modal = self.modal
local base = loveframes.base local base = loveframes.base
local basechildren = base.children local basechildren = base.children
local numbasechildren = #basechildren local numbasechildren = #basechildren
local draworder = self.draworder local draworder = self.draworder
local children = self.children local children = self.children
local internals = self.internals local internals = self.internals
local update = self.Update
close:SetPos(self.width - 20, 4) close:SetPos(self.width - 20, 4)
self:CheckHover() self:CheckHover()
-- dragging check -- dragging check
if dragging == true then if dragging then
self.x = x - self.clickx self.x = x - self.clickx
self.y = y - self.clicky self.y = y - self.clicky
end end
@ -89,18 +89,20 @@ function frame:update(dt)
local width = love.graphics.getWidth() local width = love.graphics.getWidth()
local height = love.graphics.getHeight() local height = love.graphics.getHeight()
local selfwidth = self.width
local selfheight = self.height
if self.x < 0 then if self.x < 0 then
self.x = 0 self.x = 0
end end
if self.x + self.width > width then if self.x + selfwidth > width then
self.x = width - self.width self.x = width - selfwidth
end end
if self.y < 0 then if self.y < 0 then
self.y = 0 self.y = 0
end end
if self.y + self.height > height then if self.y + selfheight > height then
self.y = height - self.height self.y = height - selfheight
end end
end end
@ -138,8 +140,8 @@ function frame:update(dt)
v:update(dt) v:update(dt)
end end
if self.Update then if update then
self.Update(self, dt) update(self, dt)
end end
end end
@ -152,24 +154,26 @@ function frame:draw()
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
local children = self.children local children = self.children
local internals = self.internals local internals = self.internals
local skins = loveframes.skins.available local skins = loveframes.skins.available
local skinindex = loveframes.config["ACTIVESKIN"] local skinindex = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"] local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin local selfskin = self.skin
local skin = skins[selfskin] or skins[skinindex] local skin = skins[selfskin] or skins[skinindex]
local drawfunc = skin.DrawFrame or skins[defaultskin].DrawFrame local drawfunc = skin.DrawFrame or skins[defaultskin].DrawFrame
local draw = self.Draw
local drawcount = loveframes.drawcount
loveframes.drawcount = loveframes.drawcount + 1 loveframes.drawcount = drawcount + 1
self.draworder = loveframes.drawcount self.draworder = loveframes.drawcount
if self.Draw ~= nil then if draw then
self.Draw(self) draw(self)
else else
drawfunc(self) drawfunc(self)
end end
@ -193,30 +197,30 @@ function frame:mousepressed(x, y, button)
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
local width = self.width local width = self.width
local height = self.height local height = self.height
local selfcol = loveframes.util.BoundingBox(x, self.x, y, self.y, 1, self.width, 1, self.height) local selfcol = loveframes.util.BoundingBox(x, self.x, y, self.y, 1, self.width, 1, self.height)
local children = self.children
local internals = self.internals local internals = self.internals
local children = self.children
if selfcol == true then if selfcol then
local top = self:IsTopCollision() local top = self:IsTopCollision()
-- initiate dragging if not currently dragging -- initiate dragging if not currently dragging
if self.dragging == false and top == true and button == "l" then if not self.dragging and top and button == "l" then
if y < self.y + 25 and self.draggable == true then if y < self.y + 25 and self.draggable then
self.clickx = x - self.x self.clickx = x - self.x
self.clicky = y - self.y self.clicky = y - self.y
self.dragging = true self.dragging = true
end end
end end
if top == true and button == "l" then if top and button == "l" then
self:MakeTop() self:MakeTop()
end end
@ -240,16 +244,16 @@ function frame:mousereleased(x, y, button)
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
local dragging = self.dragging local dragging = self.dragging
local children = self.children local children = self.children
local internals = self.internals local internals = self.internals
-- exit the dragging state -- exit the dragging state
if dragging == true then if dragging then
self.dragging = false self.dragging = false
end end
@ -346,10 +350,10 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function frame:MakeTop() function frame:MakeTop()
local x, y = love.mouse.getPosition() local x, y = love.mouse.getPosition()
local key = 0 local key = 0
local base = loveframes.base local base = loveframes.base
local basechildren = base.children local basechildren = base.children
local numbasechildren = #basechildren local numbasechildren = #basechildren
if numbasechildren == 1 then if numbasechildren == 1 then
@ -386,15 +390,15 @@ function frame:SetModal(bool)
self.modal = bool self.modal = bool
if bool == true then if bool then
if modalobject ~= false then if modalobject then
modalobject:SetModal(false) modalobject:SetModal(false)
end end
loveframes.modalobject = self loveframes.modalobject = self
if mbackground == false then if not mbackground then
self.modalbackground = modalbackground:new(self) self.modalbackground = modalbackground:new(self)
self.modal = true self.modal = true
end end
@ -405,7 +409,7 @@ function frame:SetModal(bool)
loveframes.modalobject = false loveframes.modalobject = false
if mbackground ~= false then if mbackground then
self.modalbackground:Remove() self.modalbackground:Remove()
self.modalbackground = false self.modalbackground = false
self.modal = false self.modal = false
@ -434,8 +438,8 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function frame:SetVisible(bool) function frame:SetVisible(bool)
local children = self.children local children = self.children
local internals = self.internals local internals = self.internals
local closebutton = internals[1] local closebutton = internals[1]
self.visible = bool self.visible = bool
@ -444,7 +448,7 @@ function frame:SetVisible(bool)
v:SetVisible(bool) v:SetVisible(bool)
end end
if self.showclose == true then if self.showclose then
closebutton.visible = bool closebutton.visible = bool
end end

View File

@ -1,9 +1,9 @@
--[[------------------------------------------------ --[[------------------------------------------------
-- Löve Frames -- -- Love Frames - A GUI library for LOVE --
-- Copyright 2012 Kenny Shields -- -- Copyright (c) 2012 Kenny Shields --
--]]------------------------------------------------ --]]------------------------------------------------
-- progress bar class -- progressbar class
image = class("image", base) image = class("image", base)
image:include(loveframes.templates.default) image:include(loveframes.templates.default)
@ -13,12 +13,12 @@ image:include(loveframes.templates.default)
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function image:initialize() function image:initialize()
self.type = "image" self.type = "image"
self.width = 0 self.width = 0
self.height = 0 self.height = 0
self.internal = false self.internal = false
self.image = nil self.image = nil
self.imagecolor = nil self.imagecolor = nil
end end
@ -28,23 +28,27 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function image:update(dt) function image:update(dt)
local visible = self.visible local visible = self.visible
local alwaysupdate = self.alwaysupdate local alwaysupdate = self.alwaysupdate
if visible == false then if not visible then
if alwaysupdate == false then if not alwaysupdate then
return return
end end
end end
local parent = self.parent
local base = loveframes.base
local update = self.Update
-- move to parent if there is a parent -- move to parent if there is a parent
if self.parent ~= nil then if parent ~= base then
self.x = self.parent.x + self.staticx self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy self.y = self.parent.y + self.staticy
end end
if self.Update then if update then
self.Update(self, dt) update(self, dt)
end end
end end
@ -57,22 +61,24 @@ function image:draw()
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
local skins = loveframes.skins.available local skins = loveframes.skins.available
local skinindex = loveframes.config["ACTIVESKIN"] local skinindex = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"] local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin local selfskin = self.skin
local skin = skins[selfskin] or skins[skinindex] local skin = skins[selfskin] or skins[skinindex]
local drawfunc = skin.DrawImage or skins[defaultskin].DrawImage local drawfunc = skin.DrawImage or skins[defaultskin].DrawImage
local draw = self.Draw
local drawcount = loveframes.drawcount
loveframes.drawcount = loveframes.drawcount + 1 loveframes.drawcount = drawcount + 1
self.draworder = loveframes.drawcount self.draworder = loveframes.drawcount
if self.Draw ~= nil then if draw then
self.Draw(self) draw(self)
else else
drawfunc(self) drawfunc(self)
end end

View File

@ -1,9 +1,9 @@
--[[------------------------------------------------ --[[------------------------------------------------
-- Löve Frames -- -- Love Frames - A GUI library for LOVE --
-- Copyright 2012 Kenny Shields -- -- Copyright (c) 2012 Kenny Shields --
--]]------------------------------------------------ --]]------------------------------------------------
-- imagebutton clas -- imagebutton class
imagebutton = class("imagebutton", base) imagebutton = class("imagebutton", base)
imagebutton:include(loveframes.templates.default) imagebutton:include(loveframes.templates.default)
@ -13,16 +13,16 @@ imagebutton:include(loveframes.templates.default)
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function imagebutton:initialize() function imagebutton:initialize()
self.type = "imagebutton" self.type = "imagebutton"
self.text = "Image Button" self.text = "Image Button"
self.width = 50 self.width = 50
self.height = 50 self.height = 50
self.internal = false self.internal = false
self.down = false self.down = false
self.clickable = true self.clickable = true
self.enabled = true self.enabled = true
self.image = nil self.image = nil
self.OnClick = nil self.OnClick = nil
end end
@ -32,41 +32,44 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function imagebutton:update(dt) function imagebutton:update(dt)
local visible = self.visible local visible = self.visible
local alwaysupdate = self.alwaysupdate local alwaysupdate = self.alwaysupdate
if visible == false then if not visible then
if alwaysupdate == false then if not alwaysupdate then
return return
end end
end end
self:CheckHover() self:CheckHover()
local hover = self.hover local hover = self.hover
local hoverobject = loveframes.hoverobject local hoverobject = loveframes.hoverobject
local down = self.down local down = self.down
local parent = self.parent
local base = loveframes.base
local update = self.Update
if hover == false then if not hover then
self.down = false self.down = false
elseif hover == true then else
if hoverobject == self then if hoverobject == self then
self.down = true self.down = true
end end
end end
if down == false and hoverobject == self then if not down and hoverobject == self then
self.hover = true self.hover = true
end end
-- move to parent if there is a parent -- move to parent if there is a parent
if self.parent ~= loveframes.base then if parent ~= base then
self.x = self.parent.x + self.staticx self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy self.y = self.parent.y + self.staticy
end end
if self.Update then if update then
self.Update(self, dt) update(self, dt)
end end
end end
@ -79,22 +82,24 @@ function imagebutton:draw()
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
local skins = loveframes.skins.available local skins = loveframes.skins.available
local skinindex = loveframes.config["ACTIVESKIN"] local skinindex = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"] local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin local selfskin = self.skin
local skin = skins[selfskin] or skins[skinindex] local skin = skins[selfskin] or skins[skinindex]
local drawfunc = skin.DrawImageButton or skins[defaultskin].DrawImageButton local drawfunc = skin.DrawImageButton or skins[defaultskin].DrawImageButton
local draw = self.Draw
local drawcount = loveframes.drawcount
loveframes.drawcount = loveframes.drawcount + 1 loveframes.drawcount = drawcount + 1
self.draworder = loveframes.drawcount self.draworder = loveframes.drawcount
if self.Draw ~= nil then if draw then
self.Draw(self) draw(self)
else else
drawfunc(self) drawfunc(self)
end end
@ -109,13 +114,13 @@ function imagebutton:mousepressed(x, y, button)
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
local hover = self.hover local hover = self.hover
if hover == true and button == "l" then if hover and button == "l" then
local baseparent = self:GetBaseParent() local baseparent = self:GetBaseParent()
@ -138,19 +143,20 @@ function imagebutton:mousereleased(x, y, button)
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
local hover = self.hover local hover = self.hover
local down = self.down local down = self.down
local clickable = self.clickable local clickable = self.clickable
local enabled = self.enabled local enabled = self.enabled
local onclick = self.OnClick
if hover == true and down == true and button == "l" and clickable == true then if hover and down and clickable and button == "l" then
if enabled == true then if enabled then
if self.OnClick then if onclick then
self.OnClick(self, x, y) onclick(self, x, y)
end end
end end
end end

View File

@ -1,9 +1,9 @@
--[[------------------------------------------------ --[[------------------------------------------------
-- Löve Frames -- -- Love Frames - A GUI library for LOVE --
-- Copyright 2012 Kenny Shields -- -- Copyright (c) 2012 Kenny Shields --
--]]------------------------------------------------ --]]------------------------------------------------
-- closebutton clas -- closebutton class
closebutton = class("closebutton", base) closebutton = class("closebutton", base)
closebutton:include(loveframes.templates.default) closebutton:include(loveframes.templates.default)
@ -13,13 +13,13 @@ closebutton:include(loveframes.templates.default)
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function closebutton:initialize() function closebutton:initialize()
self.type = "closebutton" self.type = "closebutton"
self.width = 80 self.width = 80
self.height = 25 self.height = 25
self.internal = true self.internal = true
self.hover = false self.hover = false
self.down = false self.down = false
self.OnClick = function() end self.OnClick = function() end
end end
@ -29,41 +29,44 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function closebutton:update(dt) function closebutton:update(dt)
local visible = self.visible local visible = self.visible
local alwaysupdate = self.alwaysupdate local alwaysupdate = self.alwaysupdate
if visible == false then if not visible then
if alwaysupdate == false then if not alwaysupdate then
return return
end end
end end
self:CheckHover() self:CheckHover()
local hover = self.hover local hover = self.hover
local down = self.down local down = self.down
local hoverobject = loveframes.hoverobject local hoverobject = loveframes.hoverobject
local parent = self.parent
local base = loveframes.base
local update = self.Update
if hover == false then if not hover then
self.down = false self.down = false
elseif hover == true then else
if loveframes.hoverobject == self then if loveframes.hoverobject == self then
self.down = true self.down = true
end end
end end
if down == false and hoverobject == self then if not down and hoverobject == self then
self.hover = true self.hover = true
end end
-- move to parent if there is a parent -- move to parent if there is a parent
if self.parent ~= loveframes.base then if parent ~= base then
self.x = self.parent.x + self.staticx self.x = parent.x + self.staticx
self.y = self.parent.y + self.staticy self.y = parent.y + self.staticy
end end
if self.Update then if update then
self.Update(self, dt) update(self, dt)
end end
end end
@ -76,22 +79,24 @@ function closebutton:draw()
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
local skins = loveframes.skins.available local skins = loveframes.skins.available
local skinindex = loveframes.config["ACTIVESKIN"] local skinindex = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"] local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin local selfskin = self.skin
local skin = skins[selfskin] or skins[skinindex] local skin = skins[selfskin] or skins[skinindex]
local drawfunc = skin.DrawCloseButton or skins[defaultskin].DrawCloseButton local drawfunc = skin.DrawCloseButton or skins[defaultskin].DrawCloseButton
local draw = self.Draw
local drawcount = loveframes.drawcount
loveframes.drawcount = loveframes.drawcount + 1 loveframes.drawcount = drawcount + 1
self.draworder = loveframes.drawcount self.draworder = loveframes.drawcount
if self.Draw ~= nil then if draw then
self.Draw(self) draw(self)
else else
drawfunc(self) drawfunc(self)
end end
@ -106,13 +111,13 @@ function closebutton:mousepressed(x, y, button)
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
local hover = self.hover local hover = self.hover
if hover == true and button == "l" then if hover and button == "l" then
local baseparent = self:GetBaseParent() local baseparent = self:GetBaseParent()
@ -135,16 +140,17 @@ function closebutton:mousereleased(x, y, button)
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
local hover = self.hover local hover = self.hover
local onclick = self.OnClick
if hover == true and self.down == true then if hover and self.down then
if button == "l" then if button == "l" then
self.OnClick(x, y, self) onclick(x, y, self)
end end
end end

View File

@ -1,9 +1,9 @@
--[[------------------------------------------------ --[[------------------------------------------------
-- Löve Frames -- -- Love Frames - A GUI library for LOVE --
-- Copyright 2012 Kenny Shields -- -- Copyright (c) 2012 Kenny Shields --
--]]------------------------------------------------ --]]------------------------------------------------
-- columnlistarea object -- columnlistarea class
columnlistarea = class("columnlistarea", base) columnlistarea = class("columnlistarea", base)
columnlistarea:include(loveframes.templates.default) columnlistarea:include(loveframes.templates.default)
@ -13,22 +13,23 @@ columnlistarea:include(loveframes.templates.default)
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function columnlistarea:initialize(parent) function columnlistarea:initialize(parent)
self.type = "columnlistarea" self.type = "columnlistarea"
self.display = "vertical" self.display = "vertical"
self.parent = parent self.parent = parent
self.width = 80 self.width = 80
self.height = 25 self.height = 25
self.clickx = 0 self.clickx = 0
self.clicky = 0 self.clicky = 0
self.offsety = 0 self.offsety = 0
self.offsetx = 0 self.offsetx = 0
self.extra = 0 self.extrawidth = 0
self.rowcolorindex = 1 self.extraheight = 0
self.rowcolorindexmax = 2 self.rowcolorindex = 1
self.bar = false self.rowcolorindexmax = 2
self.internal = true self.bar = false
self.internals = {} self.internal = true
self.children = {} self.internals = {}
self.children = {}
end end
@ -38,40 +39,43 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function columnlistarea:update(dt) function columnlistarea:update(dt)
local visible = self.visible local visible = self.visible
local alwaysupdate = self.alwaysupdate local alwaysupdate = self.alwaysupdate
if visible == false then if not visible then
if alwaysupdate == false then if not alwaysupdate then
return return
end end
end end
local cwidth, cheight = self.parent:GetColumnSize() local cwidth, cheight = self.parent:GetColumnSize()
local parent = self.parent
local base = loveframes.base
local update = self.Update
local internals = self.internals
local children = self.children
self:CheckHover() self:CheckHover()
-- move to parent if there is a parent -- move to parent if there is a parent
if self.parent ~= loveframes.base then if parent ~= base then
self.x = self.parent.x + self.staticx self.x = parent.x + self.staticx
self.y = self.parent.y + self.staticy self.y = parent.y + self.staticy
end end
for k, v in ipairs(self.internals) do for k, v in ipairs(internals) do
v:update(dt) v:update(dt)
end end
for k, v in ipairs(self.children) do for k, v in ipairs(children) do
v:update(dt) v:update(dt)
v:SetClickBounds(self.x, self.y, self.width, self.height) v:SetClickBounds(self.x, self.y, self.width, self.height)
v.y = (v.parent.y + v.staticy) - self.offsety + cheight v.y = (v.parent.y + v.staticy) - self.offsety + cheight
v.x = (v.parent.x + v.staticx) - self.offsetx v.x = (v.parent.x + v.staticx) - self.offsetx
end end
if self.Update then if update then
self.Update(self, dt) update(self, dt)
end end
end end
@ -84,31 +88,36 @@ function columnlistarea:draw()
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
local stencilfunc = function() love.graphics.rectangle("fill", self.x, self.y, self.width, self.height) end local stencilfunc = function() love.graphics.rectangle("fill", self.x, self.y, self.width, self.height) end
local stencil = love.graphics.newStencil(stencilfunc) local stencil = love.graphics.newStencil(stencilfunc)
local skins = loveframes.skins.available local skins = loveframes.skins.available
local skinindex = loveframes.config["ACTIVESKIN"] local skinindex = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"] local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin local selfskin = self.skin
local skin = skins[selfskin] or skins[skinindex] local skin = skins[selfskin] or skins[skinindex]
local drawfunc = skin.DrawColumnListArea or skins[defaultskin].DrawColumnListArea local drawfunc = skin.DrawColumnListArea or skins[defaultskin].DrawColumnListArea
local drawoverfunc = skin.DrawOverColumnListArea or skins[defaultskin].DrawOverColumnListArea
local draw = self.Draw
local drawcount = loveframes.drawcount
local internals = self.internals
local children = self.children
loveframes.drawcount = loveframes.drawcount + 1 loveframes.drawcount = drawcount + 1
self.draworder = loveframes.drawcount self.draworder = loveframes.drawcount
if self.Draw ~= nil then if draw then
self.Draw(self) draw(self)
else else
drawfunc(self) drawfunc(self)
end end
love.graphics.setStencil(stencil) love.graphics.setStencil(stencil)
for k, v in ipairs(self.children) do for k, v in ipairs(children) do
local col = loveframes.util.BoundingBox(self.x, v.x, self.y, v.y, self.width, v.width, self.height, v.height) local col = loveframes.util.BoundingBox(self.x, v.x, self.y, v.y, self.width, v.width, self.height, v.height)
if col == true then if col == true then
v:draw() v:draw()
@ -117,11 +126,11 @@ function columnlistarea:draw()
love.graphics.setStencil() love.graphics.setStencil()
for k, v in ipairs(self.internals) do for k, v in ipairs(internals) do
v:draw() v:draw()
end end
if self.Draw == nil then if not draw then
skin.DrawOverColumnListArea(self) skin.DrawOverColumnListArea(self)
end end
@ -133,9 +142,11 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function columnlistarea:mousepressed(x, y, button) function columnlistarea:mousepressed(x, y, button)
local toplist = self:IsTopList() local toplist = self:IsTopList()
local internals = self.internals
local children = self.children
if self.hover == true and button == "l" then if self.hover and button == "l" then
local baseparent = self:GetBaseParent() local baseparent = self:GetBaseParent()
@ -145,27 +156,23 @@ function columnlistarea:mousepressed(x, y, button)
end end
if self.bar == true then if self.bar and toplist then
if toplist == true then local bar = self:GetScrollBar()
local bar = self:GetScrollBar()
if button == "wu" then
bar:Scroll(-5)
elseif button == "wd" then
bar:Scroll(5)
end
if button == "wu" then
bar:Scroll(-5)
elseif button == "wd" then
bar:Scroll(5)
end end
end end
for k, v in ipairs(self.internals) do for k, v in ipairs(internals) do
v:mousepressed(x, y, button) v:mousepressed(x, y, button)
end end
for k, v in ipairs(self.children) do for k, v in ipairs(children) do
v:mousepressed(x, y, button) v:mousepressed(x, y, button)
end end
@ -177,11 +184,14 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function columnlistarea:mousereleased(x, y, button) function columnlistarea:mousereleased(x, y, button)
for k, v in ipairs(self.internals) do local internals = self.internals
local children = self.children
for k, v in ipairs(internals) do
v:mousereleased(x, y, button) v:mousereleased(x, y, button)
end end
for k, v in ipairs(self.children) do for k, v in ipairs(children) do
v:mousereleased(x, y, button) v:mousereleased(x, y, button)
end end
@ -193,15 +203,16 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function columnlistarea:CalculateSize() function columnlistarea:CalculateSize()
local iw, ih = self.parent:GetColumnSize() local iw, ih = self.parent:GetColumnSize()
local numitems = #self.children local numitems = #self.children
local height = self.height local height = self.height
local width = self.width local width = self.width
local itemheight = ih local itemheight = ih
local itemwidth = 0 local itemwidth = 0
local bar = self.bar local bar = self.bar
local children = self.children
for k, v in ipairs(self.children) do for k, v in ipairs(children) do
itemheight = itemheight + v.height itemheight = itemheight + v.height
end end
@ -209,9 +220,9 @@ function columnlistarea:CalculateSize()
if self.itemheight > height then if self.itemheight > height then
self.extra = self.itemheight - height self.extraheight = self.itemheight - height
if bar == false then if not bar then
table.insert(self.internals, scrollbody:new(self, "vertical")) table.insert(self.internals, scrollbody:new(self, "vertical"))
self.bar = true self.bar = true
self:GetScrollBar().autoscroll = self.parent.autoscroll self:GetScrollBar().autoscroll = self.parent.autoscroll
@ -219,7 +230,7 @@ function columnlistarea:CalculateSize()
else else
if bar == true then if bar then
self.internals[1]:Remove() self.internals[1]:Remove()
self.bar = false self.bar = false
self.offsety = 0 self.offsety = 0
@ -236,10 +247,10 @@ end
function columnlistarea:RedoLayout() function columnlistarea:RedoLayout()
local children = self.children local children = self.children
local starty = 0 local starty = 0
local startx = 0 local startx = 0
local bar = self.bar local bar = self.bar
local display = self.display local display = self.display
if #children > 0 then if #children > 0 then
@ -250,7 +261,7 @@ function columnlistarea:RedoLayout()
v.staticx = startx v.staticx = startx
v.staticy = starty v.staticy = starty
if bar == true then if bar then
v:SetWidth(self.width - self.internals[1].width) v:SetWidth(self.width - self.internals[1].width)
self.internals[1].staticx = self.width - self.internals[1].width self.internals[1].staticx = self.width - self.internals[1].width
self.internals[1].height = self.height self.internals[1].height = self.height
@ -276,7 +287,7 @@ function columnlistarea:AddRow(data)
local row = columnlistrow:new(self, data) local row = columnlistrow:new(self, data)
local colorindex = self.rowcolorindex local colorindex = self.rowcolorindex
local colorindexmax = self.rowcolorindexmax local colorindexmax = self.rowcolorindexmax
if colorindex == colorindexmax then if colorindex == colorindexmax then
@ -298,16 +309,15 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function columnlistarea:GetScrollBar() function columnlistarea:GetScrollBar()
if self.bar ~= false then local internals = self.internals
local scrollbar = self.internals[1].internals[1].internals[1]
if self.bar then
local scrollbody = internals[1]
local scrollarea = scrollbody.internals[1]
local scrollbar = scrollarea.internals[1]
return scrollbar return scrollbar
else else
return false return false
end end
end end
@ -321,8 +331,9 @@ function columnlistarea:Sort(column, desc)
self.rowcolorindex = 1 self.rowcolorindex = 1
local colorindexmax = self.rowcolorindexmax local colorindexmax = self.rowcolorindexmax
local children = self.children
table.sort(self.children, function(a, b) table.sort(children, function(a, b)
if desc then if desc then
return a.columndata[column] < b.columndata[column] return a.columndata[column] < b.columndata[column]
else else
@ -330,7 +341,7 @@ function columnlistarea:Sort(column, desc)
end end
end) end)
for k, v in ipairs(self.children) do for k, v in ipairs(children) do
local colorindex = self.rowcolorindex local colorindex = self.rowcolorindex

View File

@ -1,9 +1,9 @@
--[[------------------------------------------------ --[[------------------------------------------------
-- Löve Frames -- -- Love Frames - A GUI library for LOVE --
-- Copyright 2012 Kenny Shields -- -- Copyright (c) 2012 Kenny Shields --
--]]------------------------------------------------ --]]------------------------------------------------
-- columnlistrow object -- columnlistrow class
columnlistrow = class("columnlistrow", base) columnlistrow = class("columnlistrow", base)
columnlistrow:include(loveframes.templates.default) columnlistrow:include(loveframes.templates.default)
@ -13,17 +13,16 @@ columnlistrow:include(loveframes.templates.default)
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function columnlistrow:initialize(parent, data) function columnlistrow:initialize(parent, data)
self.type = "columnlistrow" self.type = "columnlistrow"
self.parent = parent self.parent = parent
self.colorindex = self.parent.rowcolorindex self.colorindex = self.parent.rowcolorindex
self.font = loveframes.basicfontsmall self.font = loveframes.basicfontsmall
self.textcolor = {0, 0, 0, 255} self.width = 80
self.width = 80 self.height = 25
self.height = 25 self.textx = 5
self.textx = 5 self.texty = 5
self.texty = 5 self.internal = true
self.internal = true self.columndata = data
self.columndata = data
end end
@ -33,25 +32,29 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function columnlistrow:update(dt) function columnlistrow:update(dt)
local visible = self.visible local visible = self.visible
local alwaysupdate = self.alwaysupdate local alwaysupdate = self.alwaysupdate
if visible == false then if not visible then
if alwaysupdate == false then if not alwaysupdate then
return return
end end
end end
local parent = self.parent
local base = loveframes.base
local update = self.Update
self:CheckHover() self:CheckHover()
-- move to parent if there is a parent -- move to parent if there is a parent
if self.parent ~= loveframes.base then if parent ~= base then
self.x = self.parent.x + self.staticx self.x = parent.x + self.staticx
self.y = self.parent.y + self.staticy self.y = parent.y + self.staticy
end end
if self.Update then if update then
self.Update(self, dt) update(self, dt)
end end
end end
@ -68,32 +71,24 @@ function columnlistrow:draw()
return return
end end
local cwidth, cheight = self:GetParent():GetParent():GetColumnSize() local skins = loveframes.skins.available
local x = self.textx local skinindex = loveframes.config["ACTIVESKIN"]
local textcolor = self.textcolor local defaultskin = loveframes.config["DEFAULTSKIN"]
local skins = loveframes.skins.available local selfskin = self.skin
local skinindex = loveframes.config["ACTIVESKIN"] local skin = skins[selfskin] or skins[skinindex]
local defaultskin = loveframes.config["DEFAULTSKIN"] local drawfunc = skin.DrawColumnListRow or skins[defaultskin].DrawColumnListRow
local selfskin = self.skin local draw = self.Draw
local skin = skins[selfskin] or skins[skinindex] local drawcount = loveframes.drawcount
local drawfunc = skin.DrawColumnListRow or skins[defaultskin].DrawColumnListRow
loveframes.drawcount = loveframes.drawcount + 1 loveframes.drawcount = drawcount + 1
self.draworder = loveframes.drawcount self.draworder = loveframes.drawcount
if self.Draw ~= nil then if draw then
self.Draw(self) draw(self)
else else
drawfunc(self) drawfunc(self)
end end
for k, v in ipairs(self.columndata) do
love.graphics.setFont(self.font)
love.graphics.setColor(unpack(textcolor))
love.graphics.print(v, self.x + x, self.y + self.texty)
x = x + cwidth
end
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -102,11 +97,11 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function columnlistrow:mousepressed(x, y, button) function columnlistrow:mousepressed(x, y, button)
if self.visible == false then if not self.visible then
return return
end end
if self.hover == true and button == "l" then if self.hover and button == "l" then
local baseparent = self:GetBaseParent() local baseparent = self:GetBaseParent()
@ -124,17 +119,18 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function columnlistrow:mousereleased(x, y, button) function columnlistrow:mousereleased(x, y, button)
if self.visible == false then if not self.visible then
return return
end end
if self.hover == true and button == "l" then if self.hover and button == "l" then
local parent1 = self:GetParent() local parent1 = self:GetParent()
local parent2 = parent1:GetParent() local parent2 = parent1:GetParent()
local onrowclicked = parent2.OnRowClicked
if parent2.OnRowClicked then if onrowclicked then
parent2.OnRowClicked(parent2, self, self.columndata) onrowclicked(parent2, self, self.columndata)
end end
end end
@ -152,6 +148,26 @@ function columnlistrow:SetTextPos(x, y)
end end
--[[---------------------------------------------------------
- func: GetTextX()
- desc: gets the object's text x position
--]]---------------------------------------------------------
function columnlistrow:GetTextX()
return self.textx
end
--[[---------------------------------------------------------
- func: GetTextY()
- desc: gets the object's text y position
--]]---------------------------------------------------------
function columnlistrow:GetTextY()
return self.texty
end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
- func: SetFont(font) - func: SetFont(font)
- desc: sets the object's font - desc: sets the object's font
@ -183,11 +199,11 @@ function columnlistrow:GetColorIndex()
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
- func: SetTextColor(color) - func: GetColumnData()
- desc: sets the object's text color - desc: gets the object's column data
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function columnlistrow:SetTextColor(color) function columnlistrow:GetColumnData()
self.textcolor = color return self.columndata
end end

View File

@ -1,9 +1,9 @@
--[[------------------------------------------------ --[[------------------------------------------------
-- Löve Frames -- -- Love Frames - A GUI library for LOVE --
-- Copyright 2012 Kenny Shields -- -- Copyright (c) 2012 Kenny Shields --
--]]------------------------------------------------ --]]------------------------------------------------
-- columnlistheader object -- columnlistheader class
columnlistheader = class("columnlistheader", base) columnlistheader = class("columnlistheader", base)
columnlistheader:include(loveframes.templates.default) columnlistheader:include(loveframes.templates.default)
@ -13,17 +13,17 @@ columnlistheader:include(loveframes.templates.default)
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function columnlistheader:initialize(name, parent) function columnlistheader:initialize(name, parent)
self.type = "columnlistheader" self.type = "columnlistheader"
self.parent = parent self.parent = parent
self.name = name self.name = name
self.width = 80 self.width = 80
self.height = 16 self.height = 16
self.hover = false self.hover = false
self.down = false self.down = false
self.clickable = true self.clickable = true
self.enabled = true self.enabled = true
self.descending = true self.descending = true
self.internal = true self.internal = true
table.insert(parent.children, self) table.insert(parent.children, self)
@ -52,37 +52,41 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function columnlistheader:update(dt) function columnlistheader:update(dt)
local visible = self.visible local visible = self.visible
local alwaysupdate = self.alwaysupdate local alwaysupdate = self.alwaysupdate
if visible == false then if not visible then
if alwaysupdate == false then if not alwaysupdate then
return return
end end
end end
local parent = self.parent
local base = loveframes.base
local update = self.Update
self:CheckHover() self:CheckHover()
if self.hover == false then if not self.hover then
self.down = false self.down = false
elseif self.hover == true then else
if loveframes.hoverobject == self then if loveframes.hoverobject == self then
self.down = true self.down = true
end end
end end
if self.down == false and loveframes.hoverobject == self then if self.down and loveframes.hoverobject == self then
self.hover = true self.hover = true
end end
-- move to parent if there is a parent -- move to parent if there is a parent
if self.parent ~= loveframes.base then if parent ~= base then
self.x = self.parent.x + self.staticx self.x = parent.x + self.staticx
self.y = self.parent.y + self.staticy self.y = parent.y + self.staticy
end end
if self.Update then if update then
self.Update(self, dt) update(self, dt)
end end
end end
@ -95,22 +99,24 @@ function columnlistheader:draw()
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
local skins = loveframes.skins.available local skins = loveframes.skins.available
local skinindex = loveframes.config["ACTIVESKIN"] local skinindex = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"] local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin local selfskin = self.skin
local skin = skins[selfskin] or skins[skinindex] local skin = skins[selfskin] or skins[skinindex]
local drawfunc = skin.DrawColumnListHeader or skins[defaultskin].DrawColumnListHeader local drawfunc = skin.DrawColumnListHeader or skins[defaultskin].DrawColumnListHeader
local draw = self.Draw
local drawcount = loveframes.drawcount
loveframes.drawcount = loveframes.drawcount + 1 loveframes.drawcount = drawcount + 1
self.draworder = loveframes.drawcount self.draworder = loveframes.drawcount
if self.Draw ~= nil then if draw then
self.Draw(self) draw(self)
else else
drawfunc(self) drawfunc(self)
end end
@ -123,7 +129,7 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function columnlistheader:mousepressed(x, y, button) function columnlistheader:mousepressed(x, y, button)
if self.hover == true and button == "l" then if self.hover and button == "l" then
local baseparent = self:GetBaseParent() local baseparent = self:GetBaseParent()
@ -144,21 +150,32 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function columnlistheader:mousereleased(x, y, button) function columnlistheader:mousereleased(x, y, button)
if self.visible == false then if not self.visible then
return return
end end
local hover = self.hover local hover = self.hover
local down = self.down local down = self.down
local clickable = self.clickable local clickable = self.clickable
local enabled = self.enabled local enabled = self.enabled
local onclick = self.OnClick
if hover == true and down == true and button == "l" and clickable == true then if hover and down and clickable and button == "l" then
if enabled == true then if enabled then
self.OnClick(self, x, y) onclick(self, x, y)
end end
end end
self.down = false self.down = false
end end
--[[---------------------------------------------------------
- func: GetName()
- desc: gets the object's name
--]]---------------------------------------------------------
function columnlistheader:GetName()
return self.name
end

View File

@ -0,0 +1,161 @@
--[[------------------------------------------------
-- Love Frames - A GUI library for LOVE --
-- Copyright (c) 2012 Kenny Shields --
--]]------------------------------------------------
-- linenumberspanel class
linenumberspanel = class("linenumberspanel", base)
linenumberspanel:include(loveframes.templates.default)
--[[---------------------------------------------------------
- func: initialize()
- desc: initializes the object
--]]---------------------------------------------------------
function linenumberspanel:initialize(parent)
self.parent = parent
self.type = "linenumberspanel"
self.width = 5
self.height = 5
self.offsety = 0
self.staticx = 0
self.staticy = 0
self.internal = true
end
--[[---------------------------------------------------------
- func: update(deltatime)
- desc: updates the element
--]]---------------------------------------------------------
function linenumberspanel:update(dt)
local visible = self.visible
local alwaysupdate = self.alwaysupdate
if not visible then
if not alwaysupdate then
return
end
end
local parent = self.parent
local base = loveframes.base
local update = self.Update
local height = self.parent.height
local parentinternals = parent.internals
self.height = height
self.offsety = self.parent.offsety - self.parent.textoffsety
-- move to parent if there is a parent
if parent ~= base then
self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy
end
if parentinternals[1] ~= self then
self:Remove()
table.insert(parentinternals, 1, self)
return
end
self:CheckHover()
if update then
update(self, dt)
end
end
--[[---------------------------------------------------------
- func: draw()
- desc: draws the object
--]]---------------------------------------------------------
function linenumberspanel:draw()
local visible = self.visible
if not visible then
return
end
local skins = loveframes.skins.available
local skinindex = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin
local skin = skins[selfskin] or skins[skinindex]
local drawfunc = skin.DrawLineNumbersPanel or skins[defaultskin].DrawLineNumbersPanel
local draw = self.Draw
local drawcount = loveframes.drawcount
local stencilfunc = function() love.graphics.rectangle("fill", self.parent.x, self.parent.y, self.width, self.height) end
local stencil = love.graphics.newStencil(stencilfunc)
if self.parent.hbar then
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
love.graphics.setStencil(stencilfunc)
if draw then
draw(self)
else
drawfunc(self)
end
love.graphics.setStencil()
end
--[[---------------------------------------------------------
- func: mousepressed(x, y, button)
- desc: called when the player presses a mouse button
--]]---------------------------------------------------------
function linenumberspanel:mousepressed(x, y, button)
local visible = self.visible
if not visible then
return
end
local hover = self.hover
if hover and button == "l" then
local baseparent = self:GetBaseParent()
if baseparent and baseparent.type == "frame" then
baseparent:MakeTop()
end
end
end
--[[---------------------------------------------------------
- func: mousereleased(x, y, button)
- desc: called when the player releases a mouse button
--]]---------------------------------------------------------
function linenumberspanel:mousereleased(x, y, button)
local visible = self.visible
if not visible then
return
end
end
--[[---------------------------------------------------------
- func: GetOffsetY()
- desc: gets the object's y offset
--]]---------------------------------------------------------
function linenumberspanel:GetOffsetY()
return self.offsety
end

View File

@ -1,6 +1,6 @@
--[[------------------------------------------------ --[[------------------------------------------------
-- Löve Frames -- -- Love Frames - A GUI library for LOVE --
-- Copyright 2012 Kenny Shields -- -- Copyright (c) 2012 Kenny Shields --
--]]------------------------------------------------ --]]------------------------------------------------
-- modalbackground class -- modalbackground class
@ -13,14 +13,14 @@ modalbackground:include(loveframes.templates.default)
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function modalbackground:initialize(object) function modalbackground:initialize(object)
self.type = "modalbackground" self.type = "modalbackground"
self.width = love.graphics.getWidth() self.width = love.graphics.getWidth()
self.height = love.graphics.getHeight() self.height = love.graphics.getHeight()
self.x = 0 self.x = 0
self.y = 0 self.y = 0
self.internal = true self.internal = true
self.parent = loveframes.base self.parent = loveframes.base
self.object = object self.object = object
table.insert(loveframes.base.children, self) table.insert(loveframes.base.children, self)
@ -36,24 +36,25 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function modalbackground:update(dt) function modalbackground:update(dt)
local visible = self.visible local visible = self.visible
local alwaysupdate = self.alwaysupdate local alwaysupdate = self.alwaysupdate
if visible == false then if not visible then
if alwaysupdate == false then if not alwaysupdate then
return return
end end
end end
local object = self.object local object = self.object
local update = self.Update
if object:IsActive() == false then if not object:IsActive() then
self:Remove() self:Remove()
loveframes.modalobject = false loveframes.modalobject = false
end end
if self.Update then if update then
self.Update(self, dt) update(self, dt)
end end
end end
@ -64,22 +65,24 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function modalbackground:draw() function modalbackground:draw()
if self.visible == false then if not self.visible then
return return
end end
local skins = loveframes.skins.available local skins = loveframes.skins.available
local skinindex = loveframes.config["ACTIVESKIN"] local skinindex = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"] local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin local selfskin = self.skin
local skin = skins[selfskin] or skins[skinindex] local skin = skins[selfskin] or skins[skinindex]
local drawfunc = skin.DrawModalBackground or skins[defaultskin].DrawModalBackground local drawfunc = skin.DrawModalBackground or skins[defaultskin].DrawModalBackground
local draw = self.Draw
local drawcount = loveframes.drawcount
loveframes.drawcount = loveframes.drawcount + 1 loveframes.drawcount = drawcount + 1
self.draworder = loveframes.drawcount self.draworder = loveframes.drawcount
if self.Draw ~= nil then if draw then
self.Draw(self) draw(self)
else else
drawfunc(self) drawfunc(self)
end end

View File

@ -1,6 +1,6 @@
--[[------------------------------------------------ --[[------------------------------------------------
-- Löve Frames -- -- Love Frames - A GUI library for LOVE --
-- Copyright 2012 Kenny Shields -- -- Copyright (c) 2012 Kenny Shields --
--]]------------------------------------------------ --]]------------------------------------------------
-- multichoicelist class -- multichoicelist class
@ -13,25 +13,25 @@ multichoicelist:include(loveframes.templates.default)
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function multichoicelist:initialize(object) function multichoicelist:initialize(object)
self.type = "multichoice-list" self.type = "multichoice-list"
self.parent = loveframes.base self.parent = loveframes.base
self.list = object self.list = object
self.x = object.x self.x = object.x
self.y = object.y + self.list.height self.y = object.y + self.list.height
self.width = self.list.width self.width = self.list.width
self.height = 0 self.height = 0
self.clickx = 0 self.clickx = 0
self.clicky = 0 self.clicky = 0
self.padding = self.list.listpadding self.padding = self.list.listpadding
self.spacing = self.list.listspacing self.spacing = self.list.listspacing
self.offsety = 0 self.offsety = 0
self.offsetx = 0 self.offsetx = 0
self.extra = 0 self.extra = 0
self.canremove = false self.canremove = false
self.internal = true self.internal = true
self.vbar = false self.vbar = false
self.children = {} self.children = {}
self.internals = {} self.internals = {}
for k, v in ipairs(object.choices) do for k, v in ipairs(object.choices) do
local row = multichoicerow:new() local row = multichoicerow:new()
@ -49,24 +49,29 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function multichoicelist:update(dt) function multichoicelist:update(dt)
local visible = self.visible local visible = self.visible
local alwaysupdate = self.alwaysupdate local alwaysupdate = self.alwaysupdate
if visible == false then if not visible then
if alwaysupdate == false then if not alwaysupdate then
return return
end end
end end
local width = love.graphics.getWidth() local width = love.graphics.getWidth()
local height = love.graphics.getHeight() local height = love.graphics.getHeight()
local x, y = love.mouse.getPosition() local x, y = love.mouse.getPosition()
local selfcol = loveframes.util.BoundingBox(x, self.x, y, self.y, 1, self.width, 1, self.height) local selfcol = loveframes.util.BoundingBox(x, self.x, y, self.y, 1, self.width, 1, self.height)
local parent = self.parent
local base = loveframes.base
local upadte = self.Update
local internals = self.internals
local children = self.children
-- move to parent if there is a parent -- move to parent if there is a parent
if self.parent ~= loveframes.base then if parent ~= base then
self.x = self.parent.x + self.staticx self.x = parent.x + self.staticx
self.y = self.parent.y + self.staticy self.y = parent.y + self.staticy
end end
if self.x < 0 then if self.x < 0 then
@ -85,19 +90,19 @@ function multichoicelist:update(dt)
self.y = height - self.height self.y = height - self.height
end end
for k, v in ipairs(self.internals) do for k, v in ipairs(internals) do
v:update(dt) v:update(dt)
end end
for k, v in ipairs(self.children) do for k, v in ipairs(children) do
v:update(dt) v:update(dt)
v:SetClickBounds(self.x, self.y, self.width, self.height) v:SetClickBounds(self.x, self.y, self.width, self.height)
v.y = (v.parent.y + v.staticy) - self.offsety v.y = (v.parent.y + v.staticy) - self.offsety
v.x = (v.parent.x + v.staticx) - self.offsetx v.x = (v.parent.x + v.staticx) - self.offsetx
end end
if self.Update then if upadte then
self.Update(self, dt) upadte(self, dt)
end end
end end
@ -108,44 +113,52 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function multichoicelist:draw() function multichoicelist:draw()
loveframes.drawcount = loveframes.drawcount + 1 local visible = self.visible
if not visible then
return
end
local stencilfunc = function() love.graphics.rectangle("fill", self.x, self.y, self.width, self.height) end
local stencil = love.graphics.newStencil(stencilfunc)
local skins = loveframes.skins.available
local skinindex = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin
local skin = skins[selfskin] or skins[skinindex]
local drawfunc = skin.DrawMultiChoiceList or skins[defaultskin].DrawMultiChoiceList
local drawoverfunc = skin.DrawOverMultiChoiceList or skins[defaultskin].DrawOverMultiChoiceList
local draw = self.Draw
local drawcount = loveframes.drawcount
local internals = self.internals
local children = self.children
loveframes.drawcount = drawcount + 1
self.draworder = loveframes.drawcount self.draworder = loveframes.drawcount
local stencilfunc = function() love.graphics.rectangle("fill", self.x, self.y, self.width, self.height) end if draw then
local stencil = love.graphics.newStencil(stencilfunc) draw(self)
local skins = loveframes.skins.available
local skinindex = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin
local skin = skins[selfskin] or skins[skinindex]
local drawfunc = skin.DrawMultiChoiceList or skins[defaultskin].DrawMultiChoiceList
loveframes.drawcount = loveframes.drawcount + 1
self.draworder = loveframes.drawcount
if self.Draw ~= nil then
self.Draw(self)
else else
drawfunc(self) drawfunc(self)
end end
for k, v in ipairs(self.internals) do for k, v in ipairs(internals) do
v:draw() v:draw()
end end
love.graphics.setStencil(stencil) love.graphics.setStencil(stencil)
for k, v in ipairs(self.children) do for k, v in ipairs(children) do
local col = loveframes.util.BoundingBox(self.x, v.x, self.y, v.y, self.width, v.width, self.height, v.height) local col = loveframes.util.BoundingBox(self.x, v.x, self.y, v.y, self.width, v.width, self.height, v.height)
if col == true then if col then
v:draw() v:draw()
end end
end end
love.graphics.setStencil() love.graphics.setStencil()
if self.Draw == nil and skin.DrawOverMultiChoiceList then if not draw then
skin.DrawOverMultiChoiceList(self) drawoverfunc(self)
end end
end end
@ -156,32 +169,36 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function multichoicelist:mousepressed(x, y, button) function multichoicelist:mousepressed(x, y, button)
if self.visible == false then local visible = self.visible
if not visible then
return return
end end
local selfcol = loveframes.util.BoundingBox(x, self.x, y, self.y, 1, self.width, 1, self.height) local selfcol = loveframes.util.BoundingBox(x, self.x, y, self.y, 1, self.width, 1, self.height)
local toplist = self:IsTopList() local toplist = self:IsTopList()
local internals = self.internals
local children = self.children
if selfcol == false and button == "l" and self.canremove == true then if not selfcol and self.canremove and button == "l" then
self:Close() self:Close()
end end
if self.vbar == true and toplist == true then if self.vbar and toplist then
if button == "wu" then if button == "wu" then
self.internals[1].internals[1].internals[1]:Scroll(-5) internals[1].internals[1].internals[1]:Scroll(-5)
elseif button == "wd" then elseif button == "wd" then
self.internals[1].internals[1].internals[1]:Scroll(5) internals[1].internals[1].internals[1]:Scroll(5)
end end
end end
for k, v in ipairs(self.internals) do for k, v in ipairs(internals) do
v:mousepressed(x, y, button) v:mousepressed(x, y, button)
end end
for k, v in ipairs(self.children) do for k, v in ipairs(children) do
v:mousepressed(x, y, button) v:mousepressed(x, y, button)
end end
@ -193,17 +210,22 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function multichoicelist:mousereleased(x, y, button) function multichoicelist:mousereleased(x, y, button)
if self.visible == false then local visible = self.visible
if not visible then
return return
end end
local internals = self.internals
local children = self.children
self.canremove = true self.canremove = true
for k, v in ipairs(self.internals) do for k, v in ipairs(internals) do
v:mousereleased(x, y, button) v:mousereleased(x, y, button)
end end
for k, v in ipairs(self.children) do for k, v in ipairs(children) do
v:mousereleased(x, y, button) v:mousereleased(x, y, button)
end end
@ -234,10 +256,12 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function multichoicelist:RemoveItem(object) function multichoicelist:RemoveItem(object)
for k, v in ipairs(self.children) do local children = self.children
for k, v in ipairs(children) do
if v == object then if v == object then
table.remove(self.children, k) table.remove(children, k)
end end
end end
@ -267,14 +291,15 @@ function multichoicelist:CalculateSize()
self.height = love.graphics.getHeight() self.height = love.graphics.getHeight()
end end
local numitems = #self.children local numitems = #self.children
local height = self.height local height = self.height
local padding = self.padding local padding = self.padding
local spacing = self.spacing local spacing = self.spacing
local itemheight = self.padding local itemheight = self.padding
local vbar = self.vbar local vbar = self.vbar
local children = self.children
for k, v in ipairs(self.children) do for k, v in ipairs(children) do
itemheight = itemheight + v.height + spacing itemheight = itemheight + v.height + spacing
end end
@ -284,7 +309,7 @@ function multichoicelist:CalculateSize()
self.extra = self.itemheight - height self.extra = self.itemheight - height
if vbar == false then if not vbar then
local scroll = scrollbody:new(self, "vertical") local scroll = scrollbody:new(self, "vertical")
table.insert(self.internals, scroll) table.insert(self.internals, scroll)
self.vbar = true self.vbar = true
@ -292,7 +317,7 @@ function multichoicelist:CalculateSize()
else else
if vbar == true then if vbar then
self.internals[1]:Remove() self.internals[1]:Remove()
self.vbar = false self.vbar = false
self.offsety = 0 self.offsety = 0
@ -309,10 +334,10 @@ end
function multichoicelist:RedoLayout() function multichoicelist:RedoLayout()
local children = self.children local children = self.children
local padding = self.padding local padding = self.padding
local spacing = self.spacing local spacing = self.spacing
local starty = padding local starty = padding
local vbar = self.vbar local vbar = self.vbar
if #children > 0 then if #children > 0 then
@ -321,12 +346,12 @@ function multichoicelist:RedoLayout()
v.staticx = padding v.staticx = padding
v.staticy = starty v.staticy = starty
if vbar == true then if vbar then
v.width = (self.width - self.internals[1].width) - padding*2 v.width = (self.width - self.internals[1].width) - padding * 2
self.internals[1].staticx = self.width - self.internals[1].width self.internals[1].staticx = self.width - self.internals[1].width
self.internals[1].height = self.height self.internals[1].height = self.height
else else
v.width = self.width - padding*2 v.width = self.width - padding * 2
end end
starty = starty + v.height starty = starty + v.height

View File

@ -1,6 +1,6 @@
--[[------------------------------------------------ --[[------------------------------------------------
-- Löve Frames -- -- Love Frames - A GUI library for LOVE --
-- Copyright 2012 Kenny Shields -- -- Copyright (c) 2012 Kenny Shields --
--]]------------------------------------------------ --]]------------------------------------------------
-- multichoicerow class -- multichoicerow class
@ -13,14 +13,14 @@ multichoicerow:include(loveframes.templates.default)
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function multichoicerow:initialize() function multichoicerow:initialize()
self.type = "multichoice-row" self.type = "multichoice-row"
self.text = "" self.text = ""
self.width = 50 self.width = 50
self.height = 25 self.height = 25
self.hover = false self.hover = false
self.internal = true self.internal = true
self.down = false self.down = false
self.canclick = false self.canclick = false
end end
@ -30,37 +30,41 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function multichoicerow:update(dt) function multichoicerow:update(dt)
local visible = self.visible local visible = self.visible
local alwaysupdate = self.alwaysupdate local alwaysupdate = self.alwaysupdate
if visible == false then if not visible then
if alwaysupdate == false then if not alwaysupdate then
return return
end end
end end
local parent = self.parent
local base = loveframes.base
local update = self.Update
self:CheckHover() self:CheckHover()
if self.hover == false then if not self.hover then
self.down = false self.down = false
elseif self.hover == true then else
if loveframes.hoverobject == self then if loveframes.hoverobject == self then
self.down = true self.down = true
end end
end end
if self.down == false and loveframes.hoverobject == self then if not self.down and loveframes.hoverobject == self then
self.hover = true self.hover = true
end end
-- move to parent if there is a parent -- move to parent if there is a parent
if self.parent ~= loveframes.base then if parent ~= base then
self.x = self.parent.x + self.staticx self.x = parent.x + self.staticx
self.y = self.parent.y + self.staticy self.y = parent.y + self.staticy
end end
if self.Update then if update then
self.Update(self, dt) update(self, dt)
end end
end end
@ -73,22 +77,24 @@ function multichoicerow:draw()
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
local skins = loveframes.skins.available local skins = loveframes.skins.available
local skinindex = loveframes.config["ACTIVESKIN"] local skinindex = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"] local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin local selfskin = self.skin
local skin = skins[selfskin] or skins[skinindex] local skin = skins[selfskin] or skins[skinindex]
local drawfunc = skin.DrawMultiChoiceRow or skins[defaultskin].DrawMultiChoiceRow local drawfunc = skin.DrawMultiChoiceRow or skins[defaultskin].DrawMultiChoiceRow
local draw = self.Draw
local drawcount = loveframes.drawcount
loveframes.drawcount = loveframes.drawcount + 1 loveframes.drawcount = drawcount + 1
self.draworder = loveframes.drawcount self.draworder = loveframes.drawcount
if self.Draw ~= nil then if draw then
self.Draw(self) draw(self)
else else
drawfunc(self) drawfunc(self)
end end
@ -101,11 +107,15 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function multichoicerow:mousepressed(x, y, button) function multichoicerow:mousepressed(x, y, button)
if self.visible == false then local visible = self.visible
if not visible then
return return
end end
if self.hover == true and button == "l" then local hover = self.hover
if hover and button == "l" then
self.down = true self.down = true
loveframes.hoverobject = self loveframes.hoverobject = self
@ -120,12 +130,16 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function multichoicerow:mousereleased(x, y, button) function multichoicerow:mousereleased(x, y, button)
if self.visible == false then local visible = self.visible
if not visible then
return return
end end
if self.hover == true and self.down == true and self.canclick == true and button == "l" then local text = self.text
self.parent.list:SelectChoice(self.text)
if self.hover and self.down and self.canclick and button == "l" then
self.parent.list:SelectChoice(text)
end end
self.down = false self.down = false
@ -142,3 +156,13 @@ function multichoicerow:SetText(text)
self.text = text self.text = text
end end
--[[---------------------------------------------------------
- func: GetText()
- desc: gets the object's text
--]]---------------------------------------------------------
function multichoicerow:GetText()
return self.text
end

View File

@ -1,9 +1,9 @@
--[[------------------------------------------------ --[[------------------------------------------------
-- Löve Frames -- -- Love Frames - A GUI library for LOVE --
-- Copyright 2012 Kenny Shields -- -- Copyright (c) 2012 Kenny Shields --
--]]------------------------------------------------ --]]------------------------------------------------
-- scrollbar class -- scrollarea class
scrollarea = class("scrollarea", base) scrollarea = class("scrollarea", base)
--[[--------------------------------------------------------- --[[---------------------------------------------------------
@ -12,16 +12,16 @@ scrollarea = class("scrollarea", base)
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function scrollarea:initialize(parent, bartype) function scrollarea:initialize(parent, bartype)
self.type = "scroll-area" self.type = "scroll-area"
self.bartype = bartype self.bartype = bartype
self.parent = parent self.parent = parent
self.x = 0 self.x = 0
self.y = 0 self.y = 0
self.scrolldelay = 0 self.scrolldelay = 0
self.delayamount = 0.05 self.delayamount = 0.05
self.down = false self.down = false
self.internal = true self.internal = true
self.internals = {} self.internals = {}
table.insert(self.internals, scrollbar:new(self, bartype)) table.insert(self.internals, scrollbar:new(self, bartype))
@ -33,36 +33,40 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function scrollarea:update(dt) function scrollarea:update(dt)
local visible = self.visible local visible = self.visible
local alwaysupdate = self.alwaysupdate local alwaysupdate = self.alwaysupdate
if visible == false then if not visible then
if alwaysupdate == false then if not alwaysupdate then
return return
end end
end end
local parent = self.parent
local base = loveframes.base
local update = self.Update
-- move to parent if there is a parent -- move to parent if there is a parent
if self.parent ~= loveframes.base then if parent ~= base then
self.x = self.parent.x + self.staticx self.x = parent.x + self.staticx
self.y = self.parent.y + self.staticy self.y = parent.y + self.staticy
end end
self:CheckHover() self:CheckHover()
local parent = self.parent local parent = self.parent
local pinternals = parent.internals local pinternals = parent.internals
local button = pinternals[2] local button = pinternals[2]
local bartype = self.bartype local bartype = self.bartype
local time = love.timer.getTime() local time = love.timer.getTime()
local x, y = love.mouse.getPosition() local x, y = love.mouse.getPosition()
local listo = parent.parent local listo = parent.parent
local down = self.down local down = self.down
local scrolldelay = self.scrolldelay local scrolldelay = self.scrolldelay
local delayamount = self.delayamount local delayamount = self.delayamount
local internals = self.internals local internals = self.internals
local bar = internals[1] local bar = internals[1]
local hover = self.hover local hover = self.hover
if button then if button then
@ -80,16 +84,16 @@ function scrollarea:update(dt)
end end
if down == true then if down then
if scrolldelay < time then if scrolldelay < time then
self.scrolldelay = time + delayamount self.scrolldelay = time + delayamount
if listo.display == "vertical" then if self.bartype == "vertical" then
if y > bar.y then if y > bar.y then
bar:Scroll(bar.height) bar:Scroll(bar.height)
else else
bar:Scroll(-bar.height) bar:Scroll(-bar.height)
end end
elseif listo.display == "horizontal" then elseif self.bartype == "horizontal" then
if x > bar.x then if x > bar.x then
bar:Scroll(bar.width) bar:Scroll(bar.width)
else else
@ -97,7 +101,7 @@ function scrollarea:update(dt)
end end
end end
end end
if hover == false then if not hover then
self.down = false self.down = false
end end
end end
@ -106,8 +110,8 @@ function scrollarea:update(dt)
v:update(dt) v:update(dt)
end end
if self.Update then if update then
self.Update(self, dt) update(self, dt)
end end
end end
@ -120,23 +124,25 @@ function scrollarea:draw()
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
local internals = self.internals local internals = self.internals
local skins = loveframes.skins.available local skins = loveframes.skins.available
local skinindex = loveframes.config["ACTIVESKIN"] local skinindex = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"] local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin local selfskin = self.skin
local skin = skins[selfskin] or skins[skinindex] local skin = skins[selfskin] or skins[skinindex]
local drawfunc = skin.DrawScrollArea or skins[defaultskin].DrawScrollArea local drawfunc = skin.DrawScrollArea or skins[defaultskin].DrawScrollArea
local draw = self.Draw
local drawcount = loveframes.drawcount
loveframes.drawcount = loveframes.drawcount + 1 loveframes.drawcount = drawcount + 1
self.draworder = loveframes.drawcount self.draworder = loveframes.drawcount
if self.Draw ~= nil then if draw then
self.Draw(self) draw(self)
else else
drawfunc(self) drawfunc(self)
end end
@ -155,18 +161,18 @@ function scrollarea:mousepressed(x, y, button)
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
local listo = self.parent.parent local listo = self.parent.parent
local time = love.timer.getTime() local time = love.timer.getTime()
local internals = self.internals local internals = self.internals
local bar = internals[1] local bar = internals[1]
local hover = self.hover local hover = self.hover
local delayamount = self.delayamount local delayamount = self.delayamount
if hover == true and button == "l" then if hover and button == "l" then
self.down = true self.down = true
self.scrolldelay = time + delayamount + 0.5 self.scrolldelay = time + delayamount + 0.5
@ -176,13 +182,13 @@ function scrollarea:mousepressed(x, y, button)
baseparent:MakeTop() baseparent:MakeTop()
end end
if listo.display == "vertical" then if self.bartype == "vertical" then
if y > self.internals[1].y then if y > self.internals[1].y then
bar:Scroll(bar.height) bar:Scroll(bar.height)
else else
bar:Scroll(-bar.height) bar:Scroll(-bar.height)
end end
elseif listo.display == "horizontal" then elseif self.bartype == "horizontal" then
if x > bar.x then if x > bar.x then
bar:Scroll(bar.width) bar:Scroll(bar.width)
else else
@ -208,7 +214,7 @@ function scrollarea:mousereleased(x, y, button)
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
@ -223,3 +229,13 @@ function scrollarea:mousereleased(x, y, button)
end end
end end
--[[---------------------------------------------------------
- func: GetBarType()
- desc: gets the object's bar type
--]]---------------------------------------------------------
function scrollarea:GetBarType()
return self.bartype
end

View File

@ -1,6 +1,6 @@
--[[------------------------------------------------ --[[------------------------------------------------
-- Löve Frames -- -- Love Frames - A GUI library for LOVE --
-- Copyright 2012 Kenny Shields -- -- Copyright (c) 2012 Kenny Shields --
--]]------------------------------------------------ --]]------------------------------------------------
-- scrollbar class -- scrollbar class
@ -12,27 +12,27 @@ scrollbar = class("scrollbar", base)
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function scrollbar:initialize(parent, bartype) function scrollbar:initialize(parent, bartype)
self.type = "scrollbar" self.type = "scrollbar"
self.bartype = bartype self.bartype = bartype
self.parent = parent self.parent = parent
self.x = 0 self.x = 0
self.y = 0 self.y = 0
self.staticx = 0 self.staticx = 0
self.staticy = 0 self.staticy = 0
self.maxx = 0 self.maxx = 0
self.maxy = 0 self.maxy = 0
self.clickx = 0 self.clickx = 0
self.clicky = 0 self.clicky = 0
self.starty = 0 self.starty = 0
self.lastwidth = 0 self.lastwidth = 0
self.lastheight = 0 self.lastheight = 0
self.lastx = 0 self.lastx = 0
self.lasty = 0 self.lasty = 0
self.internal = true self.internal = true
self.hover = false self.hover = false
self.dragging = false self.dragging = false
self.autoscroll = false self.autoscroll = false
self.internal = true self.internal = true
if self.bartype == "vertical" then if self.bartype == "vertical" then
self.width = self.parent.width self.width = self.parent.width
@ -50,20 +50,20 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function scrollbar:update(dt) function scrollbar:update(dt)
local visible = self.visible local visible = self.visible
local alwaysupdate = self.alwaysupdate local alwaysupdate = self.alwaysupdate
if visible == false then if not visible then
if alwaysupdate == false then if not alwaysupdate then
return return
end end
end end
self:CheckHover() self:CheckHover()
local x, y = love.mouse.getPosition() local x, y = love.mouse.getPosition()
local bartype = self.bartype local bartype = self.bartype
local cols = {} local cols = {}
local basecols = {} local basecols = {}
local dragging = self.dragging local dragging = self.dragging
@ -76,8 +76,9 @@ function scrollbar:update(dt)
if bartype == "vertical" then if bartype == "vertical" then
local parent = self.parent local parent = self.parent
local listo = parent.parent.parent local listo = parent.parent.parent
local height = parent.height * (listo.height/listo.itemheight) local height = parent.height * (listo.height/listo.itemheight)
local update = self.Update
if height < 20 then if height < 20 then
self.height = 20 self.height = 20
@ -89,7 +90,7 @@ function scrollbar:update(dt)
self.x = parent.x + parent.width - self.width self.x = parent.x + parent.width - self.width
self.y = parent.y + self.staticy self.y = parent.y + self.staticy
if dragging == true then if dragging then
if self.staticy ~= self.lasty then if self.staticy ~= self.lasty then
if listo.OnScroll then if listo.OnScroll then
listo.OnScroll(listo) listo.OnScroll(listo)
@ -99,10 +100,10 @@ function scrollbar:update(dt)
self.staticy = self.starty + (y - self.clicky) self.staticy = self.starty + (y - self.clicky)
end end
local space = (self.maxy - parent.y) local space = (self.maxy - parent.y)
local remaining = (0 + self.staticy) local remaining = (0 + self.staticy)
local percent = remaining/space local percent = remaining/space
local extra = listo.extra * percent local extra = listo.extraheight * percent
local autoscroll = self.autoscroll local autoscroll = self.autoscroll
local lastheight = self.lastheight local lastheight = self.lastheight
@ -110,7 +111,7 @@ function scrollbar:update(dt)
if self.staticy > space then if self.staticy > space then
self.staticy = space self.staticy = space
listo.offsety = listo.extra listo.offsety = listo.extraheight
end end
if self.staticy < 0 then if self.staticy < 0 then
@ -118,8 +119,8 @@ function scrollbar:update(dt)
listo.offsety = 0 listo.offsety = 0
end end
if autoscroll == true then if autoscroll then
if listo.itemheight ~= lastheight then if listo.itemheight > lastheight then
self.lastheight = listo.itemheight self.lastheight = listo.itemheight
self:Scroll(self.maxy) self:Scroll(self.maxy)
end end
@ -127,11 +128,9 @@ function scrollbar:update(dt)
elseif bartype == "horizontal" then elseif bartype == "horizontal" then
self.lastwidth = self.width
local parent = self.parent local parent = self.parent
local listo = self.parent.parent.parent local listo = self.parent.parent.parent
local width = self.parent.width * (listo.width/listo.itemwidth) local width = self.parent.width * (listo.width/listo.itemwidth)
if width < 20 then if width < 20 then
self.width = 20 self.width = 20
@ -143,7 +142,7 @@ function scrollbar:update(dt)
self.x = parent.x + self.staticx self.x = parent.x + self.staticx
self.y = parent.y + self.staticy self.y = parent.y + self.staticy
if dragging == true then if dragging then
if self.staticx ~= self.lastx then if self.staticx ~= self.lastx then
if listo.OnScroll then if listo.OnScroll then
listo.OnScroll(listo) listo.OnScroll(listo)
@ -153,18 +152,18 @@ function scrollbar:update(dt)
self.staticx = self.startx + (x - self.clickx) self.staticx = self.startx + (x - self.clickx)
end end
local space = (self.maxx - parent.x) local space = (self.maxx - parent.x)
local remaining = (0 + self.staticx) local remaining = (0 + self.staticx)
local percent = remaining/space local percent = remaining/space
local extra = listo.extra * percent local extra = listo.extrawidth * percent
local autoscroll = self.autoscroll local autoscroll = self.autoscroll
local lastwidth = self.lastwidth local lastwidth = self.lastwidth
listo.offsetx = 0 + extra listo.offsetx = 0 + extra
if self.staticx > space then if self.staticx > space then
self.staticx = space self.staticx = space
listo.offsetx = listo.extra listo.offsetx = listo.extrawidth
end end
if self.staticx < 0 then if self.staticx < 0 then
@ -172,17 +171,17 @@ function scrollbar:update(dt)
listo.offsetx = 0 listo.offsetx = 0
end end
if autoscroll == true then if autoscroll then
if self.width ~= lastwidth then if listo.itemwidth > lastwidth then
self.width = self.width self.lastwidth = listo.itemwidth
self:Scroll(self.maxx) self:Scroll(self.maxx)
end end
end end
end end
if self.Update then if update then
self.Update(self, dt) update(self, dt)
end end
end end
@ -195,22 +194,24 @@ function scrollbar:draw()
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
local skins = loveframes.skins.available local skins = loveframes.skins.available
local skinindex = loveframes.config["ACTIVESKIN"] local skinindex = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"] local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin local selfskin = self.skin
local skin = skins[selfskin] or skins[skinindex] local skin = skins[selfskin] or skins[skinindex]
local drawfunc = skin.DrawScrollBar or skins[defaultskin].DrawScrollBar local drawfunc = skin.DrawScrollBar or skins[defaultskin].DrawScrollBar
local draw = self.Draw
local drawcount = loveframes.drawcount
loveframes.drawcount = loveframes.drawcount + 1 loveframes.drawcount = drawcount + 1
self.draworder = loveframes.drawcount self.draworder = loveframes.drawcount
if self.Draw ~= nil then if draw then
self.Draw(self) draw(self)
else else
drawfunc(self) drawfunc(self)
end end
@ -224,13 +225,13 @@ end
function scrollbar:mousepressed(x, y, button) function scrollbar:mousepressed(x, y, button)
local visible = self.visible local visible = self.visible
local hover = self.hover local hover = self.hover
if visible == false then if not visible then
return return
end end
if hover == false then if not hover then
return return
end end
@ -242,7 +243,7 @@ function scrollbar:mousepressed(x, y, button)
local dragging = self.dragging local dragging = self.dragging
if dragging == false then if not dragging then
if button == "l" then if button == "l" then
@ -267,11 +268,11 @@ function scrollbar:mousereleased(x, y, button)
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
if self.dragging == true then if self.dragging then
self.dragging = false self.dragging = false
end end
@ -303,8 +304,9 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function scrollbar:Scroll(amount) function scrollbar:Scroll(amount)
local bartype = self.bartype local bartype = self.bartype
local listo = self.parent.parent.parent local listo = self.parent.parent.parent
local onscroll = listo.OnScroll
if bartype == "vertical" then if bartype == "vertical" then
local newy = (self.y + amount) local newy = (self.y + amount)
@ -328,8 +330,28 @@ function scrollbar:Scroll(amount)
end end
end end
if listo.OnScroll then if onscroll then
listo.OnScroll(listo) onscroll(listo)
end end
end end
--[[---------------------------------------------------------
- func: IsDragging()
- desc: gets whether the object is being dragged or not
--]]---------------------------------------------------------
function scrollbar:IsDragging()
return self.dragging
end
--[[---------------------------------------------------------
- func: GetBarType()
- desc: gets the object's bartype
--]]---------------------------------------------------------
function scrollbar:GetBarType()
return self.bartype
end

View File

@ -1,6 +1,6 @@
--[[------------------------------------------------ --[[------------------------------------------------
-- Löve Frames -- -- Love Frames - A GUI library for LOVE --
-- Copyright 2012 Kenny Shields -- -- Copyright (c) 2012 Kenny Shields --
--]]------------------------------------------------ --]]------------------------------------------------
-- scrollbar class -- scrollbar class
@ -12,24 +12,24 @@ scrollbody = class("scrollbody", base)
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function scrollbody:initialize(parent, bartype) function scrollbody:initialize(parent, bartype)
self.type = "scroll-body" self.type = "scrollbody"
self.bartype = bartype self.bartype = bartype
self.parent = parent self.parent = parent
self.x = 0 self.x = 0
self.y = 0 self.y = 0
self.internal = true self.internal = true
self.internals = {} self.internals = {}
if self.bartype == "vertical" then if self.bartype == "vertical" then
self.width = 16 self.width = 16
self.height = self.parent.height self.height = self.parent.height
self.staticx = self.parent.width - self.width self.staticx = self.parent.width - self.width
self.staticy = 0 self.staticy = 0
elseif self.bartype == "horizontal" then elseif self.bartype == "horizontal" then
self.width = self.parent.width self.width = self.parent.width
self.height = 16 self.height = 16
self.staticx = 0 self.staticx = 0
self.staticy = self.parent.height - self.height self.staticy = self.parent.height - self.height
end end
table.insert(self.internals, scrollarea:new(self, bartype)) table.insert(self.internals, scrollarea:new(self, bartype))
@ -38,22 +38,22 @@ function scrollbody:initialize(parent, bartype)
if self.bartype == "vertical" then if self.bartype == "vertical" then
local upbutton = scrollbutton:new("up") local upbutton = scrollbutton:new("up")
upbutton.parent = self upbutton.parent = self
upbutton.Update = function(object, dt) upbutton.Update = function(object, dt)
upbutton.staticx = 0 + self.width - upbutton.width upbutton.staticx = 0 + self.width - upbutton.width
upbutton.staticy = 0 upbutton.staticy = 0
if object.down == true and object.hover == true then if object.down and object.hover then
bar:Scroll(-0.10) bar:Scroll(-0.10)
end end
end end
local downbutton = scrollbutton:new("down") local downbutton = scrollbutton:new("down")
downbutton.parent = self downbutton.parent = self
downbutton.Update = function(object, dt) downbutton.Update = function(object, dt)
downbutton.staticx = 0 + self.width - downbutton.width downbutton.staticx = 0 + self.width - downbutton.width
downbutton.staticy = 0 + self.height - downbutton.height downbutton.staticy = 0 + self.height - downbutton.height
if object.down == true and object.hover == true then if object.down and object.hover then
bar:Scroll(0.10) bar:Scroll(0.10)
end end
end end
@ -63,22 +63,22 @@ function scrollbody:initialize(parent, bartype)
elseif self.bartype == "horizontal" then elseif self.bartype == "horizontal" then
local leftbutton = scrollbutton:new("left") local leftbutton = scrollbutton:new("left")
leftbutton.parent = self leftbutton.parent = self
leftbutton.Update = function(object, dt) leftbutton.Update = function(object, dt)
leftbutton.staticx = 0 leftbutton.staticx = 0
leftbutton.staticy = 0 leftbutton.staticy = 0
if object.down == true and object.hover == true then if object.down and object.hover then
bar:Scroll(-0.10) bar:Scroll(-0.10)
end end
end end
local rightbutton = scrollbutton:new("right") local rightbutton = scrollbutton:new("right")
rightbutton.parent = self rightbutton.parent = self
rightbutton.Update = function(object, dt) rightbutton.Update = function(object, dt)
rightbutton.staticx = 0 + self.width - rightbutton.width rightbutton.staticx = 0 + self.width - rightbutton.width
rightbutton.staticy = 0 rightbutton.staticy = 0
if object.down == true and object.hover == true then if object.down and object.hover then
bar:Scroll(0.10) bar:Scroll(0.10)
end end
end end
@ -96,26 +96,34 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function scrollbody:update(dt) function scrollbody:update(dt)
if self.visible == false then local visible = self.visible
if self.alwaysupdate == false then local alwaysupdate = self.alwaysupdate
if not visible then
if not alwaysupdate then
return return
end end
end end
local parent = self.parent
local base = loveframes.base
local update = self.Update
local internals = self.internals
-- move to parent if there is a parent -- move to parent if there is a parent
if self.parent ~= loveframes.base then if parent ~= base then
self.x = self.parent.x + self.staticx self.x = parent.x + self.staticx
self.y = self.parent.y + self.staticy self.y = parent.y + self.staticy
end end
self:CheckHover() self:CheckHover()
for k, v in ipairs(self.internals) do for k, v in ipairs(internals) do
v:update(dt) v:update(dt)
end end
if self.Update then if update then
self.Update(self, dt) update(self, dt)
end end
end end
@ -126,27 +134,32 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function scrollbody:draw() function scrollbody:draw()
if self.visible == false then local visible = self.visible
if not visible then
return return
end end
local skins = loveframes.skins.available local skins = loveframes.skins.available
local skinindex = loveframes.config["ACTIVESKIN"] local skinindex = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"] local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin local selfskin = self.skin
local skin = skins[selfskin] or skins[skinindex] local skin = skins[selfskin] or skins[skinindex]
local drawfunc = skin.DrawScrollBody or skins[defaultskin].DrawScrollBody local drawfunc = skin.DrawScrollBody or skins[defaultskin].DrawScrollBody
local draw = self.Draw
local drawcount = loveframes.drawcount
local internals = self.internals
loveframes.drawcount = loveframes.drawcount + 1 loveframes.drawcount = drawcount + 1
self.draworder = loveframes.drawcount self.draworder = loveframes.drawcount
if self.Draw ~= nil then if draw then
self.Draw(self) draw(self)
else else
drawfunc(self) drawfunc(self)
end end
for k, v in ipairs(self.internals) do for k, v in ipairs(internals) do
v:draw() v:draw()
end end

View File

@ -1,6 +1,6 @@
--[[------------------------------------------------ --[[------------------------------------------------
-- Löve Frames -- -- Love Frames - A GUI library for LOVE --
-- Copyright 2012 Kenny Shields -- -- Copyright (c) 2012 Kenny Shields --
--]]------------------------------------------------ --]]------------------------------------------------
-- scrollbutton clas -- scrollbutton clas
@ -13,13 +13,13 @@ scrollbutton:include(loveframes.templates.default)
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function scrollbutton:initialize(scrolltype) function scrollbutton:initialize(scrolltype)
self.type = "scrollbutton" self.type = "scrollbutton"
self.scrolltype = scrolltype self.scrolltype = scrolltype
self.width = 16 self.width = 16
self.height = 16 self.height = 16
self.down = false self.down = false
self.internal = true self.internal = true
self.OnClick = function() end self.OnClick = function() end
end end
@ -29,34 +29,42 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function scrollbutton:update(dt) function scrollbutton:update(dt)
if self.visible == false then local visible = self.visible
if self.alwaysupdate == false then local alwaysupdate = self.alwaysupdate
if not visible then
if not alwaysupdate then
return return
end end
end end
self:CheckHover() self:CheckHover()
if self.hover == false then local hover = self.hover
local parent = self.parent
local base = loveframes.base
local update = self.Update
if not hover then
self.down = false self.down = false
elseif self.hover == true then else
if loveframes.hoverobject == self then if loveframes.hoverobject == self then
self.down = true self.down = true
end end
end end
if self.down == false and loveframes.hoverobject == self then if not self.down and loveframes.hoverobject == self then
self.hover = true self.hover = true
end end
-- move to parent if there is a parent -- move to parent if there is a parent
if self.parent ~= loveframes.base then if parent ~= base then
self.x = self.parent.x + self.staticx self.x = parent.x + self.staticx
self.y = self.parent.y + self.staticy self.y = parent.y + self.staticy
end end
if self.Update then if update then
self.Update(self, dt) update(self, dt)
end end
end end
@ -67,22 +75,26 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function scrollbutton:draw() function scrollbutton:draw()
if self.visible == false then local visible = self.visible
if not visible then
return return
end end
local skins = loveframes.skins.available local skins = loveframes.skins.available
local skinindex = loveframes.config["ACTIVESKIN"] local skinindex = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"] local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin local selfskin = self.skin
local skin = skins[selfskin] or skins[skinindex] local skin = skins[selfskin] or skins[skinindex]
local drawfunc = skin.DrawScrollButton or skins[defaultskin].DrawScrollButton local drawfunc = skin.DrawScrollButton or skins[defaultskin].DrawScrollButton
local draw = self.Draw
local drawcount = loveframes.drawcount
loveframes.drawcount = loveframes.drawcount + 1 loveframes.drawcount = drawcount + 1
self.draworder = loveframes.drawcount self.draworder = loveframes.drawcount
if self.Draw ~= nil then if draw then
self.Draw(self) draw(self)
else else
drawfunc(self) drawfunc(self)
end end
@ -90,17 +102,20 @@ function scrollbutton:draw()
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
- func: mousepressed(x, y, scrollbutton) - func: mousepressed(x, y, button)
- desc: called when the player presses a mouse button - desc: called when the player presses a mouse button
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function scrollbutton:mousepressed(x, y, scrollbutton) function scrollbutton:mousepressed(x, y, button)
local visible = self.visible
if self.visible == false then if not visible then
return return
end end
if self.hover == true then local hover = self.hover
if hover and button == "l" then
local baseparent = self:GetBaseParent() local baseparent = self:GetBaseParent()
@ -116,19 +131,25 @@ function scrollbutton:mousepressed(x, y, scrollbutton)
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
- func: mousereleased(x, y, scrollbutton) - func: mousereleased(x, y, button)
- desc: called when the player releases a mouse button - desc: called when the player releases a mouse button
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function scrollbutton:mousereleased(x, y, scrollbutton) function scrollbutton:mousereleased(x, y, button)
if self.visible == false then local visible = self.visible
if not visible then
return return
end end
if self.hover == true and self.down == true then local hover = self.hover
local down = self.down
local onclick = self.OnClick
if scrollbutton == "l" then if hover and down then
self.OnClick(x, y, self)
if button == "l" then
onclick(x, y, self)
end end
end end
@ -146,3 +167,14 @@ function scrollbutton:SetText(text)
return return
end end
--[[---------------------------------------------------------
- func: GetScrollType()
- desc: gets the object's scroll type
--]]---------------------------------------------------------
function scrollbutton:GetScrollType()
return self.scrolltype
end

View File

@ -1,9 +1,9 @@
--[[------------------------------------------------ --[[------------------------------------------------
-- Löve Frames -- -- Love Frames - A GUI library for LOVE --
-- Copyright 2012 Kenny Shields -- -- Copyright (c) 2012 Kenny Shields --
--]]------------------------------------------------ --]]------------------------------------------------
-- closebutton clas -- sliderbutton class
sliderbutton = class("sliderbutton", base) sliderbutton = class("sliderbutton", base)
sliderbutton:include(loveframes.templates.default) sliderbutton:include(loveframes.templates.default)
@ -13,20 +13,20 @@ sliderbutton:include(loveframes.templates.default)
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function sliderbutton:initialize(parent) function sliderbutton:initialize(parent)
self.type = "sliderbutton" self.type = "sliderbutton"
self.width = 10 self.width = 10
self.height = 20 self.height = 20
self.staticx = 0 self.staticx = 0
self.staticy = 0 self.staticy = 0
self.startx = 0 self.startx = 0
self.clickx = 0 self.clickx = 0
self.starty = 0 self.starty = 0
self.clicky = 0 self.clicky = 0
self.intervals = true self.intervals = true
self.internal = true self.internal = true
self.down = false self.down = false
self.dragging = false self.dragging = false
self.parent = parent self.parent = parent
end end
@ -36,49 +36,52 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function sliderbutton:update(dt) function sliderbutton:update(dt)
local visible = self.visible local visible = self.visible
local alwaysupdate = self.alwaysupdate local alwaysupdate = self.alwaysupdate
if visible == false then if not visible then
if alwaysupdate == false then if not alwaysupdate then
return return
end end
end end
self:CheckHover() self:CheckHover()
local x, y = love.mouse.getPosition() local x, y = love.mouse.getPosition()
local intervals = self.intervals local intervals = self.intervals
local progress = 0 local progress = 0
local nvalue = 0 local nvalue = 0
local pvalue = self.parent.value local pvalue = self.parent.value
local hover = self.hover local hover = self.hover
local down = self.down local down = self.down
local hoverobject = loveframes.hoverobject local hoverobject = loveframes.hoverobject
local parent = self.parent local parent = self.parent
local slidetype = parent.slidetype local slidetype = parent.slidetype
local dragging = self.dragging local dragging = self.dragging
local parent = self.parent
local base = loveframes.base
local update = self.Update
if hover == false then if not hover then
self.down = false self.down = false
elseif hover == true then else
if hoverobject == self then if hoverobject == self then
self.down = true self.down = true
end end
end end
if down == false and hoverobject == self then if not down and hoverobject == self then
self.hover = true self.hover = true
end end
-- move to parent if there is a parent -- move to parent if there is a parent
if self.parent ~= loveframes.base then if parent ~= base then
self.x = self.parent.x + self.staticx self.x = parent.x + self.staticx
self.y = self.parent.y + self.staticy self.y = parent.y + self.staticy
end end
-- start calculations if the button is being dragged -- start calculations if the button is being dragged
if dragging == true then if dragging then
-- calculations for horizontal sliders -- calculations for horizontal sliders
if slidetype == "horizontal" then if slidetype == "horizontal" then
@ -142,8 +145,8 @@ function sliderbutton:update(dt)
end end
end end
if self.Update then if update then
self.Update(self, dt) update(self, dt)
end end
end end
@ -156,22 +159,24 @@ function sliderbutton:draw()
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
local skins = loveframes.skins.available local skins = loveframes.skins.available
local skinindex = loveframes.config["ACTIVESKIN"] local skinindex = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"] local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin local selfskin = self.skin
local skin = skins[selfskin] or skins[skinindex] local skin = skins[selfskin] or skins[skinindex]
local drawfunc = skin.DrawSliderButton or skins[defaultskin].DrawSliderButton local drawfunc = skin.DrawSliderButton or skins[defaultskin].DrawSliderButton
local draw = self.Draw
local drawcount = loveframes.drawcount
loveframes.drawcount = loveframes.drawcount + 1 loveframes.drawcount = drawcount + 1
self.draworder = loveframes.drawcount self.draworder = loveframes.drawcount
if self.Draw ~= nil then if draw then
self.Draw(self) draw(self)
else else
drawfunc(self) drawfunc(self)
end end
@ -186,13 +191,13 @@ function sliderbutton:mousepressed(x, y, button)
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
local hover = self.hover local hover = self.hover
if hover == true and button == "l" then if hover and button == "l" then
local baseparent = self:GetBaseParent() local baseparent = self:GetBaseParent()
@ -200,12 +205,12 @@ function sliderbutton:mousepressed(x, y, button)
baseparent:MakeTop() baseparent:MakeTop()
end end
self.down = true self.down = true
self.dragging = true self.dragging = true
self.startx = self.staticx self.startx = self.staticx
self.clickx = x self.clickx = x
self.starty = self.staticy self.starty = self.staticy
self.clicky = y self.clicky = y
loveframes.hoverobject = self loveframes.hoverobject = self
end end
@ -220,7 +225,7 @@ function sliderbutton:mousereleased(x, y, button)
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end

View File

@ -1,9 +1,9 @@
--[[------------------------------------------------ --[[------------------------------------------------
-- Löve Frames -- -- Love Frames - A GUI library for LOVE --
-- Copyright 2012 Kenny Shields -- -- Copyright (c) 2012 Kenny Shields --
--]]------------------------------------------------ --]]------------------------------------------------
-- tabbutton clas -- tabbutton class
tabbutton = class("tabbutton", base) tabbutton = class("tabbutton", base)
tabbutton:include(loveframes.templates.default) tabbutton:include(loveframes.templates.default)
@ -13,17 +13,17 @@ tabbutton:include(loveframes.templates.default)
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function tabbutton:initialize(parent, text, tabnumber, tip, image) function tabbutton:initialize(parent, text, tabnumber, tip, image)
self.type = "tabbutton" self.type = "tabbutton"
self.text = text self.text = text
self.tabnumber = tabnumber self.tabnumber = tabnumber
self.parent = parent self.parent = parent
self.staticx = 0 self.staticx = 0
self.staticy = 0 self.staticy = 0
self.width = 50 self.width = 50
self.height = 25 self.height = 25
self.internal = true self.internal = true
self.down = false self.down = false
self.image = nil self.image = nil
if tip then if tip then
self.tooltip = tooltip:new(self, tip) self.tooltip = tooltip:new(self, tip)
@ -43,26 +43,30 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function tabbutton:update(dt) function tabbutton:update(dt)
local visible = self.visible local visible = self.visible
local alwaysupdate = self.alwaysupdate local alwaysupdate = self.alwaysupdate
if visible == false then if not visible then
if alwaysupdate == false then if not alwaysupdate then
return return
end end
end end
local parent = self.parent
local base = loveframes.base
local update = self.Update
self:CheckHover() self:CheckHover()
self:SetClickBounds(self.parent.x, self.parent.y, self.parent.width, self.parent.height) self:SetClickBounds(parent.x, parent.y, parent.width, parent.height)
-- move to parent if there is a parent -- move to parent if there is a parent
if self.parent ~= loveframes.base then if parent ~= base then
self.x = self.parent.x + self.staticx self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy self.y = self.parent.y + self.staticy
end end
if self.Update then if update then
self.Update(self, dt) update(self, dt)
end end
end end
@ -73,25 +77,27 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function tabbutton:draw() function tabbutton:draw()
if self.visible == false then if not self.visible then
return return
end end
local font = love.graphics.getFont() local font = love.graphics.getFont()
local width = font:getWidth(self.text) local width = font:getWidth(self.text)
local image = self.image local image = self.image
local skins = loveframes.skins.available local skins = loveframes.skins.available
local skinindex = loveframes.config["ACTIVESKIN"] local skinindex = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"] local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin local selfskin = self.skin
local skin = skins[selfskin] or skins[skinindex] local skin = skins[selfskin] or skins[skinindex]
local drawfunc = skin.DrawTabButton or skins[defaultskin].DrawTabButton local drawfunc = skin.DrawTabButton or skins[defaultskin].DrawTabButton
local draw = self.Draw
local drawcount = loveframes.drawcount
loveframes.drawcount = loveframes.drawcount + 1 loveframes.drawcount = drawcount + 1
self.draworder = loveframes.drawcount self.draworder = loveframes.drawcount
if self.Draw ~= nil then if draw then
self.Draw(self) draw(self)
else else
drawfunc(self) drawfunc(self)
end end
@ -113,13 +119,13 @@ function tabbutton:mousepressed(x, y, button)
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
local hover = self.hover local hover = self.hover
if hover == true and button == "l" then if hover and button == "l" then
local baseparent = self:GetBaseParent() local baseparent = self:GetBaseParent()
@ -142,15 +148,15 @@ function tabbutton:mousereleased(x, y, button)
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
local hover = self.hover local hover = self.hover
local parent = self.parent local parent = self.parent
local tabnumber = self.tabnumber local tabnumber = self.tabnumber
if hover == true and button == "l" then if hover and button == "l" then
if button == "l" then if button == "l" then
parent:SwitchToTab(tabnumber) parent:SwitchToTab(tabnumber)
@ -172,6 +178,16 @@ function tabbutton:SetText(text)
end end
--[[---------------------------------------------------------
- func: GetText()
- desc: gets the object's text
--]]---------------------------------------------------------
function tabbutton:GetText()
return self.text
end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
- func: SetImage(image) - func: SetImage(image)
- desc: adds an image to the object - desc: adds an image to the object
@ -185,3 +201,23 @@ function tabbutton:SetImage(image)
end end
end end
--[[---------------------------------------------------------
- func: GetImage()
- desc: gets the object's image
--]]---------------------------------------------------------
function tabbutton:GetImage()
return self.image
end
--[[---------------------------------------------------------
- func: GetTabNumber()
- desc: gets the object's tab number
--]]---------------------------------------------------------
function tabbutton:GetTabNumber()
return self.tabnumber
end

View File

@ -1,6 +1,6 @@
--[[------------------------------------------------ --[[------------------------------------------------
-- Löve Frames -- -- Love Frames - A GUI library for LOVE --
-- Copyright 2012 Kenny Shields -- -- Copyright (c) 2012 Kenny Shields --
--]]------------------------------------------------ --]]------------------------------------------------
-- tooltip clas -- tooltip clas
@ -15,18 +15,18 @@ function tooltip:initialize(object, text, width)
local width = width or 0 local width = width or 0
self.type = "tooltip" self.type = "tooltip"
self.parent = loveframes.base self.parent = loveframes.base
self.object = object or nil self.object = object or nil
self.width = width or 0 self.width = width or 0
self.height = 0 self.height = 0
self.padding = 5 self.padding = 5
self.xoffset = 10 self.xoffset = 10
self.yoffset = -10 self.yoffset = -10
self.internal = true self.internal = true
self.show = false self.show = false
self.followcursor = true self.followcursor = true
self.alwaysupdate = true self.alwaysupdate = true
self.text = loveframes.Create("text") self.text = loveframes.Create("text")
self.text:Remove() self.text:Remove()
@ -45,22 +45,22 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function tooltip:update(dt) function tooltip:update(dt)
local visible = self.visible local visible = self.visible
local alwaysupdate = self.alwaysupdate local alwaysupdate = self.alwaysupdate
if visible == false then if not visible then
if alwaysupdate == false then if not alwaysupdate then
return return
end end
end end
local text = self.text local text = self.text
local object = self.object
self.width = text.width + self.padding*2
self.height = text.height + self.padding*2
local object = self.object
local draworder = self.draworder local draworder = self.draworder
local update = self.Update
self.width = text.width + self.padding * 2
self.height = text.height + self.padding * 2
if object then if object then
@ -69,17 +69,17 @@ function tooltip:update(dt)
return return
end end
local hover = object.hover local hover = object.hover
local odraworder = object.draworder local odraworder = object.draworder
local ovisible = object.visible
local ohover = object.hover
self.show = object.hover self.show = ohover
self.visible = self.show self.visible = ovisible
local show = self.show if ohover and ovisible then
if show == true then
local top = self:IsTopInternal() local top = self:IsTopInternal()
if self.followcursor == true then if self.followcursor then
local x, y = love.mouse.getPosition() local x, y = love.mouse.getPosition()
self.x = x + self.xoffset self.x = x + self.xoffset
self.y = y - self.height + self.yoffset self.y = y - self.height + self.yoffset
@ -88,7 +88,7 @@ function tooltip:update(dt)
self.y = object.y - self.height + self.yoffset self.y = object.y - self.height + self.yoffset
end end
if top == false then if not top then
self:MoveToTop() self:MoveToTop()
end end
@ -99,7 +99,7 @@ function tooltip:update(dt)
local baseparent = object:GetBaseParent() local baseparent = object:GetBaseParent()
if baseparent then if baseparent then
if baseparent.removed and baseparent.removed == true then if baseparent.removed and baseparent.removed then
self:Remove() self:Remove()
end end
elseif object.removed then elseif object.removed then
@ -110,8 +110,8 @@ function tooltip:update(dt)
text:update(dt) text:update(dt)
if self.Update then if update then
self.Update(self, dt) update(self, dt)
end end
end end
@ -124,26 +124,28 @@ function tooltip:draw()
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
local show = self.show local show = self.show
local text = self.text local text = self.text
local skins = loveframes.skins.available local skins = loveframes.skins.available
local skinindex = loveframes.config["ACTIVESKIN"] local skinindex = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"] local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin local selfskin = self.skin
local skin = skins[selfskin] or skins[skinindex] local skin = skins[selfskin] or skins[skinindex]
local drawfunc = skin.DrawToolTip or skins[defaultskin].DrawToolTip local drawfunc = skin.DrawToolTip or skins[defaultskin].DrawToolTip
local draw = self.Draw
local drawcount = loveframes.drawcount
loveframes.drawcount = loveframes.drawcount + 1 loveframes.drawcount = drawcount + 1
self.draworder = loveframes.drawcount self.draworder = loveframes.drawcount
if show == true then if show then
if self.Draw ~= nil then if draw then
self.Draw(self) draw(self)
else else
drawfunc(self) drawfunc(self)
end end

View File

@ -1,6 +1,6 @@
--[[------------------------------------------------ --[[------------------------------------------------
-- Löve Frames -- -- Love Frames - A GUI library for LOVE --
-- Copyright 2012 Kenny Shields -- -- Copyright (c) 2012 Kenny Shields --
--]]------------------------------------------------ --]]------------------------------------------------
-- list class -- list class
@ -13,24 +13,25 @@ list:include(loveframes.templates.default)
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function list:initialize() function list:initialize()
self.type = "list" self.type = "list"
self.display = "vertical" self.display = "vertical"
self.width = 300 self.width = 300
self.height = 150 self.height = 150
self.clickx = 0 self.clickx = 0
self.clicky = 0 self.clicky = 0
self.padding = 0 self.padding = 0
self.spacing = 0 self.spacing = 0
self.offsety = 0 self.offsety = 0
self.offsetx = 0 self.offsetx = 0
self.extra = 0 self.extrawidth = 0
self.internal = false self.extraheight = 0
self.hbar = false self.internal = false
self.vbar = false self.hbar = false
self.autoscroll = false self.vbar = false
self.internals = {} self.autoscroll = false
self.children = {} self.internals = {}
self.OnScroll = nil self.children = {}
self.OnScroll = nil
end end
@ -43,18 +44,21 @@ function list:update(dt)
local visible = self.visible local visible = self.visible
local alwaysupdate = self.alwaysupdate local alwaysupdate = self.alwaysupdate
if visible == false then if not visible then
if alwaysupdate == false then if not alwaysupdate then
return return
end end
end end
local internals = self.internals local internals = self.internals
local children = self.children local children = self.children
local display = self.display local display = self.display
local parent = self.parent
local base = loveframes.base
local update = self.Update
-- move to parent if there is a parent -- move to parent if there is a parent
if self.parent ~= loveframes.base then if parent ~= base then
self.x = self.parent.x + self.staticx self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy self.y = self.parent.y + self.staticy
end end
@ -80,8 +84,8 @@ function list:update(dt)
end end
if self.Update then if update then
self.Update(self, dt) update(self, dt)
end end
end end
@ -94,26 +98,29 @@ function list:draw()
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
local internals = self.internals local internals = self.internals
local children = self.children local children = self.children
local stencilfunc = function() love.graphics.rectangle("fill", self.x, self.y, self.width, self.height) end local stencilfunc = function() love.graphics.rectangle("fill", self.x, self.y, self.width, self.height) end
local stencil = love.graphics.newStencil(stencilfunc) local stencil = love.graphics.newStencil(stencilfunc)
local skins = loveframes.skins.available local skins = loveframes.skins.available
local skinindex = loveframes.config["ACTIVESKIN"] local skinindex = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"] local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin local selfskin = self.skin
local skin = skins[selfskin] or skins[skinindex] local skin = skins[selfskin] or skins[skinindex]
local drawfunc = skin.DrawList or skins[defaultskin].DrawList local drawfunc = skin.DrawList or skins[defaultskin].DrawList
local drawoverfunc = skin.DrawOverList or skins[defaultskin].DrawOverList
local draw = self.Draw
local drawcount = loveframes.drawcount
loveframes.drawcount = loveframes.drawcount + 1 loveframes.drawcount = drawcount + 1
self.draworder = loveframes.drawcount self.draworder = loveframes.drawcount
if self.Draw ~= nil then if draw then
self.Draw(self) draw(self)
else else
drawfunc(self) drawfunc(self)
end end
@ -133,8 +140,8 @@ function list:draw()
v:draw() v:draw()
end end
if self.Draw == nil then if not draw then
skin.DrawOverList(self) drawoverfunc(self)
end end
end end
@ -147,7 +154,7 @@ function list:mousepressed(x, y, button)
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
@ -158,7 +165,7 @@ function list:mousepressed(x, y, button)
local children = self.children local children = self.children
local internals = self.internals local internals = self.internals
if hover == true and button == "l" then if hover and button == "l" then
local baseparent = self:GetBaseParent() local baseparent = self:GetBaseParent()
@ -168,9 +175,9 @@ function list:mousepressed(x, y, button)
end end
if vbar == true or hbar == true then if vbar or hbar then
if toplist == true then if toplist then
local bar = self:GetScrollBar() local bar = self:GetScrollBar()
@ -206,11 +213,14 @@ function list:AddItem(object)
local children = self.children local children = self.children
-- remove the item object from it's current parent and make it's new parent the list object
object:Remove() object:Remove()
object.parent = self object.parent = self
-- insert the item object into the list object's children table
table.insert(children, object) table.insert(children, object)
-- resize the list and redo it's layout
self:CalculateSize() self:CalculateSize()
self:RedoLayout() self:RedoLayout()
@ -259,9 +269,9 @@ function list:CalculateSize()
if itemheight > height then if itemheight > height then
self.extra = itemheight - height self.extraheight = itemheight - height
if vbar == false then if not vbar then
local scrollbar = scrollbody:new(self, display) local scrollbar = scrollbody:new(self, display)
table.insert(internals, scrollbar) table.insert(internals, scrollbar)
self.vbar = true self.vbar = true
@ -270,7 +280,7 @@ function list:CalculateSize()
else else
if vbar == true then if vbar then
local bar = internals[1] local bar = internals[1]
bar:Remove() bar:Remove()
self.vbar = false self.vbar = false
@ -291,9 +301,9 @@ function list:CalculateSize()
if itemwidth > width then if itemwidth > width then
self.extra = itemwidth - width self.extrawidth = itemwidth - width
if hbar == false then if not hbar then
local scrollbar = scrollbody:new(self, display) local scrollbar = scrollbody:new(self, display)
table.insert(internals, scrollbar) table.insert(internals, scrollbar)
self.hbar = true self.hbar = true
@ -302,7 +312,7 @@ function list:CalculateSize()
else else
if hbar == true then if hbar then
local bar = internals[1] local bar = internals[1]
bar:Remove() bar:Remove()
self.hbar = false self.hbar = false
@ -342,17 +352,17 @@ function list:RedoLayout()
v.staticy = starty v.staticy = starty
v.lastheight = v.height v.lastheight = v.height
if vbar == true then if vbar then
if v.width + padding > (self.width - self.internals[1].width) then if v.width + padding > (self.width - self.internals[1].width) then
v:SetWidth((self.width - self.internals[1].width) - (padding*2)) v:SetWidth((self.width - self.internals[1].width) - (padding*2))
end end
if v.retainsize == false then if not v.retainsize then
v:SetWidth((self.width - self.internals[1].width) - (padding*2)) v:SetWidth((self.width - self.internals[1].width) - (padding*2))
end end
self.internals[1].staticx = self.width - self.internals[1].width self.internals[1].staticx = self.width - self.internals[1].width
self.internals[1].height = self.height self.internals[1].height = self.height
else else
if v.retainsize == false then if not v.retainsize then
v:SetWidth(self.width - (padding*2)) v:SetWidth(self.width - (padding*2))
end end
end end
@ -365,17 +375,17 @@ function list:RedoLayout()
v.staticx = startx v.staticx = startx
v.staticy = padding v.staticy = padding
if hbar == true then if hbar then
if v.height + padding > (self.height - self.internals[1].height) then if v.height + padding > (self.height - self.internals[1].height) then
v:SetHeight((self.height - self.internals[1].height) - (padding*2)) v:SetHeight((self.height - self.internals[1].height) - (padding*2))
end end
if v.retainsize == false then if not v.retainsize then
v:SetHeight((self.height - self.internals[1].height) - (padding*2)) v:SetHeight((self.height - self.internals[1].height) - (padding*2))
end end
self.internals[1].staticy = self.height - self.internals[1].height self.internals[1].staticy = self.height - self.internals[1].height
self.internals[1].width = self.width self.internals[1].width = self.width
else else
if v.retainsize == false then if not v.retainsize then
v:SetHeight(self.height - (padding*2)) v:SetHeight(self.height - (padding*2))
end end
end end
@ -400,13 +410,12 @@ function list:SetDisplayType(type)
local children = self.children local children = self.children
local numchildren = #children local numchildren = #children
self.display = type self.display = type
self.vbar = false
self.hbar = false
self.offsetx = 0
self.offsety = 0
self.internals = {} self.internals = {}
self.vbar = false
self.hbar = false
self.offsetx = 0
self.offsety = 0
if numchildren > 0 then if numchildren > 0 then
self:CalculateSize() self:CalculateSize()
@ -516,11 +525,14 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function list:GetScrollBar() function list:GetScrollBar()
local vbar = self.vbar local vbar = self.vbar
local hbar = self.hbar local hbar = self.hbar
local internals = self.internals
if vbar == true or hbar == true then if vbar or hbar then
local scrollbar = self.internals[1].internals[1].internals[1] local scrollbody = internals[1]
local scrollarea = scrollbody.internals[1]
local scrollbar = scrollarea.internals[1]
return scrollbar return scrollbar
else else
return false return false
@ -536,10 +548,12 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function list:SetAutoScroll(bool) function list:SetAutoScroll(bool)
local scrollbar = self:GetScrollBar()
self.autoscroll = bool self.autoscroll = bool
if self:GetScrollBar() ~= false then if scrollbar then
self:GetScrollBar().autoscroll = bool scrollbar.autoscroll = bool
end end
end end

View File

@ -1,9 +1,9 @@
--[[------------------------------------------------ --[[------------------------------------------------
-- Löve Frames -- -- Love Frames - A GUI library for LOVE --
-- Copyright 2012 Kenny Shields -- -- Copyright (c) 2012 Kenny Shields --
--]]------------------------------------------------ --]]------------------------------------------------
-- progress bar class -- multichoice class
multichoice = class("multichoice", base) multichoice = class("multichoice", base)
multichoice:include(loveframes.templates.default) multichoice:include(loveframes.templates.default)
@ -13,17 +13,17 @@ multichoice:include(loveframes.templates.default)
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function multichoice:initialize() function multichoice:initialize()
self.type = "multichoice" self.type = "multichoice"
self.choice = "" self.choice = ""
self.text = "Select an option" self.text = "Select an option"
self.width = 200 self.width = 200
self.height = 25 self.height = 25
self.listpadding = 0 self.listpadding = 0
self.listspacing = 0 self.listspacing = 0
self.listheight = nil self.haslist = false
self.haslist = false self.internal = false
self.internal = false self.choices = {}
self.choices = {} self.listheight = nil
end end
@ -33,25 +33,28 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function multichoice:update(dt) function multichoice:update(dt)
local visible = self.visible local visible = self.visible
local alwaysupdate = self.alwaysupdate local alwaysupdate = self.alwaysupdate
if visible == false then if not visible then
if alwaysupdate == false then if not alwaysupdate then
return return
end end
end end
local parent = self.parent
local update = self.Update
self:CheckHover() self:CheckHover()
-- move to parent if there is a parent -- move to parent if there is a parent
if self.parent ~= nil then if parent then
self.x = self.parent.x + self.staticx self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy self.y = self.parent.y + self.staticy
end end
if self.Update then if update then
self.Update(self, dt) update(self, dt)
end end
end end
@ -64,22 +67,24 @@ function multichoice:draw()
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
local skins = loveframes.skins.available local skins = loveframes.skins.available
local skinindex = loveframes.config["ACTIVESKIN"] local skinindex = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"] local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin local selfskin = self.skin
local skin = skins[selfskin] or skins[skinindex] local skin = skins[selfskin] or skins[skinindex]
local drawfunc = skin.DrawMultiChoice or skins[defaultskin].DrawMultiChoice local drawfunc = skin.DrawMultiChoice or skins[defaultskin].DrawMultiChoice
local draw = self.Draw
local drawcount = loveframes.drawcount
loveframes.drawcount = loveframes.drawcount + 1 loveframes.drawcount = drawcount + 1
self.draworder = loveframes.drawcount self.draworder = loveframes.drawcount
if self.Draw ~= nil then if draw then
self.Draw(self) draw(self)
else else
drawfunc(self) drawfunc(self)
end end
@ -94,14 +99,14 @@ function multichoice:mousepressed(x, y, button)
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
local hover = self.hover local hover = self.hover
local haslist = self.haslist local haslist = self.haslist
if hover == true and haslist == false and button == "l" then if hover and not haslist and button == "l" then
local baseparent = self:GetBaseParent() local baseparent = self:GetBaseParent()
@ -125,7 +130,7 @@ function multichoice:mousereleased(x, y, button)
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
@ -158,11 +163,13 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function multichoice:SelectChoice(choice) function multichoice:SelectChoice(choice)
local onchoiceselected = self.OnChoiceSelected
self.choice = choice self.choice = choice
self.list:Close() self.list:Close()
if self.OnChoiceSelected then if onchoiceselected then
self.OnChoiceSelected(self, choice) onchoiceselected(self, choice)
end end
end end
@ -216,3 +223,23 @@ function multichoice:GetChoice()
return self.choice return self.choice
end end
--[[---------------------------------------------------------
- func: SetText(text)
- desc: sets the object's text
--]]---------------------------------------------------------
function multichoice:SetText(text)
self.text = text
end
--[[---------------------------------------------------------
- func: GetText()
- desc: gets the object's text
--]]---------------------------------------------------------
function multichoice:GetText()
return self.text
end

View File

@ -1,6 +1,6 @@
--[[------------------------------------------------ --[[------------------------------------------------
-- Löve Frames -- -- Love Frames - A GUI library for LOVE --
-- Copyright 2012 Kenny Shields -- -- Copyright (c) 2012 Kenny Shields --
--]]------------------------------------------------ --]]------------------------------------------------
-- panel class -- panel class
@ -13,11 +13,11 @@ panel:include(loveframes.templates.default)
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function panel:initialize() function panel:initialize()
self.type = "panel" self.type = "panel"
self.width = 200 self.width = 200
self.height = 50 self.height = 50
self.internal = false self.internal = false
self.children = {} self.children = {}
end end
@ -30,16 +30,19 @@ function panel:update(dt)
local visible = self.visible local visible = self.visible
local alwaysupdate = self.alwaysupdate local alwaysupdate = self.alwaysupdate
if visible == false then if not visible then
if alwaysupdate == false then if not alwaysupdate then
return return
end end
end end
local children = self.children local children = self.children
local parent = self.parent
local base = loveframes.base
local update = self.Update
-- move to parent if there is a parent -- move to parent if there is a parent
if self.parent ~= loveframes.base and self.parent.type ~= "list" then if parent ~= base and parent.type ~= "list" then
self.x = self.parent.x + self.staticx self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy self.y = self.parent.y + self.staticy
end end
@ -50,8 +53,8 @@ function panel:update(dt)
v:update(dt) v:update(dt)
end end
if self.Update then if update then
self.Update(self, dt) update(self, dt)
end end
end end
@ -64,23 +67,25 @@ function panel:draw()
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
local children = self.children local children = self.children
local skins = loveframes.skins.available local skins = loveframes.skins.available
local skinindex = loveframes.config["ACTIVESKIN"] local skinindex = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"] local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin local selfskin = self.skin
local skin = skins[selfskin] or skins[skinindex] local skin = skins[selfskin] or skins[skinindex]
local drawfunc = skin.DrawPanel or skins[defaultskin].DrawPanel local drawfunc = skin.DrawPanel or skins[defaultskin].DrawPanel
local draw = self.Draw
local drawcount = loveframes.drawcount
loveframes.drawcount = loveframes.drawcount + 1 loveframes.drawcount = drawcount + 1
self.draworder = loveframes.drawcount self.draworder = loveframes.drawcount
if self.Draw ~= nil then if draw then
self.Draw(self) draw(self)
else else
drawfunc(self) drawfunc(self)
end end
@ -100,14 +105,14 @@ function panel:mousepressed(x, y, button)
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
local children = self.children local children = self.children
local hover = self.hover local hover = self.hover
if hover == true and button == "l" then if hover and button == "l" then
local baseparent = self:GetBaseParent() local baseparent = self:GetBaseParent()
@ -129,10 +134,10 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function panel:mousereleased(x, y, button) function panel:mousereleased(x, y, button)
local visible = self.visible local visible = self.visible
local children = self.children local children = self.children
if visible == false then if not visible then
return return
end end

View File

@ -1,6 +1,6 @@
--[[------------------------------------------------ --[[------------------------------------------------
-- Löve Frames -- -- Love Frames - A GUI library for LOVE --
-- Copyright 2012 Kenny Shields -- -- Copyright (c) 2012 Kenny Shields --
--]]------------------------------------------------ --]]------------------------------------------------
-- progressbar class -- progressbar class
@ -13,21 +13,21 @@ progressbar:include(loveframes.templates.default)
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function progressbar:initialize() function progressbar:initialize()
self.type = "progressbar" self.type = "progressbar"
self.width = 100 self.width = 100
self.height = 25 self.height = 25
self.min = 0 self.min = 0
self.max = 10 self.max = 10
self.value = 0 self.value = 0
self.progress = 0 self.barwidth = 0
self.lerprate = 1000 self.lerprate = 1000
self.lerpvalue = 0 self.lerpvalue = 0
self.lerpto = 0 self.lerpto = 0
self.lerpfrom = 0 self.lerpfrom = 0
self.completed = false self.completed = false
self.lerp = false self.lerp = false
self.internal = false self.internal = false
self.OnComplete = nil self.OnComplete = nil
end end
@ -37,27 +37,31 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function progressbar:update(dt) function progressbar:update(dt)
local visible = self.visible local visible = self.visible
local alwaysupdate = self.alwaysupdate local alwaysupdate = self.alwaysupdate
if visible == false then if not visible then
if alwaysupdate == false then if not alwaysupdate then
return return
end end
end end
local lerp = self.lerp local lerp = self.lerp
local lerprate = self.lerprate local lerprate = self.lerprate
local lerpvalue = self.lerpvalue local lerpvalue = self.lerpvalue
local lerpto = self.lerpto local lerpto = self.lerpto
local lerpfrom = self.lerpfrom local lerpfrom = self.lerpfrom
local value = self.value local value = self.value
local completed = self.completed local completed = self.completed
local parent = self.parent
local base = loveframes.base
local update = self.Update
local oncomplete = self.OnComplete
self:CheckHover() self:CheckHover()
-- caclulate progress -- caclulate barwidth
if lerp == true then if lerp then
if lerpfrom < lerpto then if lerpfrom < lerpto then
if lerpvalue < lerpto then if lerpvalue < lerpto then
self.lerpvalue = lerpvalue + lerprate*dt self.lerpvalue = lerpvalue + lerprate*dt
@ -74,7 +78,7 @@ function progressbar:update(dt)
self.lerpvalue = lerpto self.lerpvalue = lerpto
end end
self.progress = self.lerpvalue/self.max * self.width self.barwidth = self.lerpvalue/self.max * self.width
-- min check -- min check
if self.lerpvalue < self.min then if self.lerpvalue < self.min then
@ -86,37 +90,34 @@ function progressbar:update(dt)
self.lerpvalue = self.max self.lerpvalue = self.max
end end
else else
self.progress = self.value/self.max * self.width self.barwidth = value/self.max * self.width
-- min check -- min max check
if self.value < self.min then if value < self.min then
self.value = self.min self.value = self.min
end elseif value > self.max then
-- max check
if self.value > self.max then
self.value = self.max self.value = self.max
end end
end end
-- move to parent if there is a parent -- move to parent if there is a parent
if self.parent ~= nil then if parent ~= base then
self.x = self.parent.x + self.staticx self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy self.y = self.parent.y + self.staticy
end end
-- completion check -- completion check
if completed == false then if not completed then
if self.value >= self.max then if self.value >= self.max then
self.completed = true self.completed = true
if self.OnComplete then if oncomplete then
self.OnComplete(self) oncomplete(self)
end end
end end
end end
if self.Update then if update then
self.Update(self, dt) update(self, dt)
end end
end end
@ -129,22 +130,24 @@ function progressbar:draw()
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
local skins = loveframes.skins.available local skins = loveframes.skins.available
local skinindex = loveframes.config["ACTIVESKIN"] local skinindex = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"] local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin local selfskin = self.skin
local skin = skins[selfskin] or skins[skinindex] local skin = skins[selfskin] or skins[skinindex]
local drawfunc = skin.DrawProgressBar or skins[defaultskin].DrawProgressBar local drawfunc = skin.DrawProgressBar or skins[defaultskin].DrawProgressBar
local draw = self.Draw
local drawcount = loveframes.drawcount
loveframes.drawcount = loveframes.drawcount + 1 loveframes.drawcount = drawcount + 1
self.draworder = loveframes.drawcount self.draworder = loveframes.drawcount
if self.Draw ~= nil then if draw then
self.Draw(self) draw(self)
else else
drawfunc(self) drawfunc(self)
end end
@ -220,7 +223,7 @@ function progressbar:SetValue(value)
local lerp = self.lerp local lerp = self.lerp
if lerp == true then if lerp then
self.lerpvalue = self.lerpvalue self.lerpvalue = self.lerpvalue
self.lerpto = value self.lerpto = value
self.lerpfrom = self.lerpvalue self.lerpfrom = self.lerpvalue
@ -295,3 +298,13 @@ function progressbar:GetCompleted()
return self.completed return self.completed
end end
--[[---------------------------------------------------------
- func: GetBarWidth()
- desc: gets the object's bar width
--]]---------------------------------------------------------
function progressbar:GetBarWidth()
return self.barwidth
end

View File

@ -1,6 +1,6 @@
--[[------------------------------------------------ --[[------------------------------------------------
-- Löve Frames -- -- Love Frames - A GUI library for LOVE --
-- Copyright 2012 Kenny Shields -- -- Copyright (c) 2012 Kenny Shields --
--]]------------------------------------------------ --]]------------------------------------------------
-- text clas -- text clas
@ -13,17 +13,17 @@ slider:include(loveframes.templates.default)
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function slider:initialize() function slider:initialize()
self.type = "slider" self.type = "slider"
self.text = "Slider" self.text = "Slider"
self.slidetype = "horizontal" self.slidetype = "horizontal"
self.width = 5 self.width = 5
self.height = 5 self.height = 5
self.max = 10 self.max = 10
self.min = 0 self.min = 0
self.value = 0 self.value = 0
self.decimals = 5 self.decimals = 5
self.internal = false self.internal = false
self.internals = {} self.internals = {}
self.OnValueChanged = nil self.OnValueChanged = nil
-- create the slider button -- create the slider button
@ -40,22 +40,25 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function slider:update(dt) function slider:update(dt)
local visible = self.visible local visible = self.visible
local alwaysupdate = self.alwaysupdate local alwaysupdate = self.alwaysupdate
if visible == false then if not visible then
if alwaysupdate == false then if not alwaysupdate then
return return
end end
end end
local internals = self.internals local internals = self.internals
local sliderbutton = internals[1] local sliderbutton = internals[1]
local parent = self.parent
local base = loveframes.base
local update = self.Update
self:CheckHover() self:CheckHover()
-- move to parent if there is a parent -- move to parent if there is a parent
if self.parent ~= loveframes.base and self.parent.type ~= "list" then if parent ~= base and parent.type ~= "list" then
self.x = self.parent.x + self.staticx self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy self.y = self.parent.y + self.staticy
end end
@ -73,8 +76,8 @@ function slider:update(dt)
v:update(dt) v:update(dt)
end end
if self.Update then if update then
self.Update(self, dt) update(self, dt)
end end
end end
@ -87,23 +90,25 @@ function slider:draw()
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
local internals = self.internals local internals = self.internals
local skins = loveframes.skins.available local skins = loveframes.skins.available
local skinindex = loveframes.config["ACTIVESKIN"] local skinindex = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"] local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin local selfskin = self.skin
local skin = skins[selfskin] or skins[skinindex] local skin = skins[selfskin] or skins[skinindex]
local drawfunc = skin.DrawSlider or skins[defaultskin].DrawSlider local drawfunc = skin.DrawSlider or skins[defaultskin].DrawSlider
local draw = self.Draw
local drawcount = loveframes.drawcount
loveframes.drawcount = loveframes.drawcount + 1 loveframes.drawcount = drawcount + 1
self.draworder = loveframes.drawcount self.draworder = loveframes.drawcount
if self.Draw ~= nil then if draw then
self.Draw(self) draw(self)
else else
drawfunc(self) drawfunc(self)
end end
@ -123,16 +128,18 @@ function slider:mousepressed(x, y, button)
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
if self.hover == true and button == "l" then local internals = self.internals
if self.hover and button == "l" then
if self.slidetype == "horizontal" then if self.slidetype == "horizontal" then
local xpos = x - self.x local xpos = x - self.x
local button = self.internals[1] local button = internals[1]
local baseparent = self:GetBaseParent() local baseparent = self:GetBaseParent()
if baseparent and baseparent.type == "frame" then if baseparent and baseparent.type == "frame" then
@ -148,7 +155,7 @@ function slider:mousepressed(x, y, button)
elseif self.slidetype == "vertical" then elseif self.slidetype == "vertical" then
local ypos = y - self.y local ypos = y - self.y
local button = self.internals[1] local button = internals[1]
local baseparent = self:GetBaseParent() local baseparent = self:GetBaseParent()
if baseparent and baseparent.type == "frame" then if baseparent and baseparent.type == "frame" then
@ -166,7 +173,7 @@ function slider:mousepressed(x, y, button)
end end
for k, v in ipairs(self.internals) do for k, v in ipairs(internals) do
v:mousepressed(x, y, button) v:mousepressed(x, y, button)
end end
@ -186,28 +193,34 @@ function slider:SetValue(value)
return return
end end
local decimals = self.decimals local decimals = self.decimals
local newval = loveframes.util.Round(value, decimals) local newval = loveframes.util.Round(value, decimals)
local internals = self.internals local internals = self.internals
local onvaluechanged = self.OnValueChanged
-- set the new value -- set the new value
self.value = newval self.value = newval
-- slider button object -- slider button object
local sliderbutton = internals[1] local sliderbutton = internals[1]
local slidetype = self.slidetype
local width = self.width
local height = self.height
local min = self.min
local max = self.max
-- move the slider button to the new position -- move the slider button to the new position
if self.slidetype == "horizontal" then if slidetype == "horizontal" then
local xpos = self.width * (( newval - self.min ) / (self.max - self.min)) local xpos = width * ((newval - min) / (max - min))
sliderbutton:MoveToX(xpos) sliderbutton:MoveToX(xpos)
elseif self.slidetype == "vertical" then elseif slidetype == "vertical" then
local ypos = self.height - self.height * (( newval - self.min ) / (self.max - self.min)) local ypos = height - height * ((newval - min) / (max - min))
sliderbutton:MoveToY(ypos) sliderbutton:MoveToY(ypos)
end end
-- call OnValueChanged -- call OnValueChanged
if self.OnValueChanged then if onvaluechanged then
self.OnValueChanged(self) onvaluechanged(self)
end end
end end
@ -335,8 +348,8 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function slider:SetButtonSize(width, height) function slider:SetButtonSize(width, height)
local internals = self.internals local internals = self.internals
local sliderbutton = self.internals[1] local sliderbutton = internals[1]
if sliderbutton then if sliderbutton then
sliderbutton.width = width sliderbutton.width = width
@ -351,8 +364,8 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function slider:GetButtonSize() function slider:GetButtonSize()
local internals = self.internals local internals = self.internals
local sliderbutton = self.internals[1] local sliderbutton = internals[1]
if sliderbutton then if sliderbutton then
return sliderbutton.width, sliderbutton.height return sliderbutton.width, sliderbutton.height
@ -375,3 +388,13 @@ function slider:SetSlideType(slidetype)
end end
end end
--[[---------------------------------------------------------
- func: GetSlideType()
- desc: gets the objects's slide type
--]]---------------------------------------------------------
function slider:GetSlideType()
return self.slidetype
end

View File

@ -1,6 +1,6 @@
--[[------------------------------------------------ --[[------------------------------------------------
-- Löve Frames -- -- Love Frames - A GUI library for LOVE --
-- Copyright 2012 Kenny Shields -- -- Copyright (c) 2012 Kenny Shields --
--]]------------------------------------------------ --]]------------------------------------------------
-- tabs class -- tabs class
@ -13,22 +13,22 @@ tabs:include(loveframes.templates.default)
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function tabs:initialize() function tabs:initialize()
self.type = "tabs" self.type = "tabs"
self.width = 100 self.width = 100
self.height = 50 self.height = 50
self.clickx = 0 self.clickx = 0
self.clicky = 0 self.clicky = 0
self.offsetx = 0 self.offsetx = 0
self.tab = 1 self.tab = 1
self.tabnumber = 1 self.tabnumber = 1
self.padding = 5 self.padding = 5
self.tabheight = 25 self.tabheight = 25
self.autosize = true self.autosize = true
self.internal = false self.internal = false
self.tooltipfont = loveframes.basicfontsmall self.tooltipfont = loveframes.basicfontsmall
self.tabs = {} self.tabs = {}
self.internals = {} self.internals = {}
self.children = {} self.children = {}
end end
@ -38,29 +38,32 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function tabs:update(dt) function tabs:update(dt)
local visible = self.visible local visible = self.visible
local alwaysupdate = self.alwaysupdate local alwaysupdate = self.alwaysupdate
if visible == false then if not visible then
if alwaysupdate == false then if not alwaysupdate then
return return
end end
end end
local x, y = love.mouse.getPosition() local x, y = love.mouse.getPosition()
local tabheight = self.tabheight local tabheight = self.tabheight
local padding = self.padding local padding = self.padding
local autosize = self.autosize local autosize = self.autosize
local tabheight = self.tabheight local tabheight = self.tabheight
local padding = self.padding local padding = self.padding
local autosize = self.autosize local autosize = self.autosize
local children = self.children local children = self.children
local numchildren = #children local numchildren = #children
local internals = self.internals local internals = self.internals
local tab = self.tab local tab = self.tab
local parent = self.parent
local base = loveframes.base
local update = self.Update
-- move to parent if there is a parent -- move to parent if there is a parent
if self.parent ~= loveframes.base then if parent ~= base then
self.x = self.parent.x + self.staticx self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy self.y = self.parent.y + self.staticy
end end
@ -87,8 +90,8 @@ function tabs:update(dt)
v:SetPos(padding, tabheight + padding) v:SetPos(padding, tabheight + padding)
end end
if self.Update then if update then
self.Update(self, dt) update(self, dt)
end end
end end
@ -101,27 +104,29 @@ function tabs:draw()
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
local internals = self.internals local internals = self.internals
local tabheight = self:GetHeightOfButtons() local tabheight = self:GetHeightOfButtons()
local stencilfunc = function() love.graphics.rectangle("fill", self.x, self.y, self.width, tabheight) end local stencilfunc = function() love.graphics.rectangle("fill", self.x, self.y, self.width, tabheight) end
local stencil = love.graphics.newStencil(stencilfunc) local stencil = love.graphics.newStencil(stencilfunc)
local internals = self.internals local internals = self.internals
local skins = loveframes.skins.available local skins = loveframes.skins.available
local skinindex = loveframes.config["ACTIVESKIN"] local skinindex = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"] local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin local selfskin = self.skin
local skin = skins[selfskin] or skins[skinindex] local skin = skins[selfskin] or skins[skinindex]
local drawfunc = skin.DrawTabPanel or skins[defaultskin].DrawTabPanel local drawfunc = skin.DrawTabPanel or skins[defaultskin].DrawTabPanel
local draw = self.Draw
local drawcount = loveframes.drawcount
loveframes.drawcount = loveframes.drawcount + 1 loveframes.drawcount = drawcount + 1
self.draworder = loveframes.drawcount self.draworder = loveframes.drawcount
if self.Draw ~= nil then if draw then
self.Draw(self) draw(self)
else else
drawfunc(self) drawfunc(self)
end end
@ -148,18 +153,18 @@ function tabs:mousepressed(x, y, button)
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
local children = self.children local children = self.children
local numchildren = #children local numchildren = #children
local tab = self.tab local tab = self.tab
local internals = self.internals local internals = self.internals
local numinternals = #internals local numinternals = #internals
local hover = self.hover local hover = self.hover
if hover == true then if hover then
if button == "l" then if button == "l" then
@ -176,10 +181,10 @@ function tabs:mousepressed(x, y, button)
if button == "wu" then if button == "wu" then
local buttonheight = self:GetHeightOfButtons() local buttonheight = self:GetHeightOfButtons()
local col = loveframes.util.BoundingBox(self.x, x, self.y, y, self.width, 1, buttonheight, 1) local col = loveframes.util.BoundingBox(self.x, x, self.y, y, self.width, 1, buttonheight, 1)
local visible = internals[numinternals - 1]:GetVisible() local visible = internals[numinternals - 1]:GetVisible()
if col == true and visible == true then if col and visible then
self.offsetx = self.offsetx + 5 self.offsetx = self.offsetx + 5
if self.offsetx > 0 then if self.offsetx > 0 then
self.offsetx = 0 self.offsetx = 0
@ -191,10 +196,10 @@ function tabs:mousepressed(x, y, button)
if button == "wd" then if button == "wd" then
local buttonheight = self:GetHeightOfButtons() local buttonheight = self:GetHeightOfButtons()
local col = loveframes.util.BoundingBox(self.x, x, self.y, y, self.width, 1, buttonheight, 1) local col = loveframes.util.BoundingBox(self.x, x, self.y, y, self.width, 1, buttonheight, 1)
local visible = internals[numinternals]:GetVisible() local visible = internals[numinternals]:GetVisible()
if col == true and visible == true then if col and visible then
local bwidth = self:GetWidthOfButtons() local bwidth = self:GetWidthOfButtons()
if (self.offsetx + bwidth) < self.width then if (self.offsetx + bwidth) < self.width then
self.offsetx = bwidth - self.width self.offsetx = bwidth - self.width
@ -221,13 +226,13 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function tabs:mousereleased(x, y, button) function tabs:mousereleased(x, y, button)
local visible = self.visible local visible = self.visible
local children = self.children local children = self.children
local numchildren = #children local numchildren = #children
local tab = self.tab local tab = self.tab
local internals = self.internals local internals = self.internals
if visible == false then if not visible then
return return
end end
@ -247,12 +252,12 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function tabs:AddTab(name, object, tip, image) function tabs:AddTab(name, object, tip, image)
local tabheight = self.tabheight local tabheight = self.tabheight
local padding = self.padding local padding = self.padding
local autosize = self.autosize local autosize = self.autosize
local retainsize = object.retainsize local retainsize = object.retainsize
local tabnumber = self.tabnumber local tabnumber = self.tabnumber
local internals = self.internals local internals = self.internals
object:Remove() object:Remove()
object.parent = self object.parent = self
@ -273,7 +278,7 @@ function tabs:AddTab(name, object, tip, image)
self:AddScrollButtons() self:AddScrollButtons()
if autosize == true and retainsize == false then if autosize and not retainsize then
object:SetSize(self.width - padding*2, (self.height - tabheight) - padding*2) object:SetSize(self.width - padding*2, (self.height - tabheight) - padding*2)
end end
@ -348,7 +353,7 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function tabs:GetWidthOfButtons() function tabs:GetWidthOfButtons()
local width = 0 local width = 0
local internals = self.internals local internals = self.internals
for k, v in ipairs(internals) do for k, v in ipairs(internals) do
@ -464,6 +469,6 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function tabs:GetTabNumber() function tabs:GetTabNumber()
return self.tabnumber return self.tab
end end

View File

@ -1,6 +1,6 @@
--[[------------------------------------------------ --[[------------------------------------------------
-- Löve Frames -- -- Love Frames - A GUI library for LOVE --
-- Copyright 2012 Kenny Shields -- -- Copyright (c) 2012 Kenny Shields --
--]]------------------------------------------------ --]]------------------------------------------------
--[[------------------------------------------------ --[[------------------------------------------------
@ -17,16 +17,16 @@ text:include(loveframes.templates.default)
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function text:initialize() function text:initialize()
self.type = "text" self.type = "text"
self.text = "" self.text = ""
self.font = loveframes.basicfont self.font = loveframes.basicfont
self.width = 5 self.width = 5
self.height = 5 self.height = 5
self.maxw = 0 self.maxw = 0
self.lines = 1 self.lines = 1
self.text = {} self.text = {}
self.original = {} self.original = {}
self.internal = false self.internal = false
end end
@ -36,22 +36,26 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function text:update(dt) function text:update(dt)
if self.visible == false then if not self.visible then
if self.alwaysupdate == false then if not self.alwaysupdate then
return return
end end
end end
local parent = self.parent
local base = loveframes.base
local update = self.Update
self:CheckHover() self:CheckHover()
-- move to parent if there is a parent -- move to parent if there is a parent
if self.parent ~= loveframes.base then if parent ~= base then
self.x = self.parent.x + self.staticx self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy self.y = self.parent.y + self.staticy
end end
if self.Update then if update then
self.Update(self, dt) update(self, dt)
end end
end end
@ -62,22 +66,24 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function text:draw() function text:draw()
if self.visible == false then if not self.visible then
return return
end end
local skins = loveframes.skins.available local skins = loveframes.skins.available
local skinindex = loveframes.config["ACTIVESKIN"] local skinindex = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"] local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin local selfskin = self.skin
local skin = skins[selfskin] or skins[skinindex] local skin = skins[selfskin] or skins[skinindex]
local drawfunc = skin.DrawText or skins[defaultskin].DrawText local drawfunc = skin.DrawText or skins[defaultskin].DrawText
local draw = self.Draw
local drawcount = loveframes.drawcount
loveframes.drawcount = loveframes.drawcount + 1 loveframes.drawcount = drawcount + 1
self.draworder = loveframes.drawcount self.draworder = loveframes.drawcount
if self.Draw ~= nil then if draw then
self.Draw(self) draw(self)
else else
drawfunc(self) drawfunc(self)
end end
@ -94,13 +100,13 @@ function text:mousepressed(x, y, button)
local visible = self.visible local visible = self.visible
if visible == false then if not visible then
return return
end end
local hover = self.hover local hover = self.hover
if hover == true and button == "l" then if hover and button == "l" then
local baseparent = self:GetBaseParent() local baseparent = self:GetBaseParent()
@ -118,9 +124,9 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function text:SetText(t) function text:SetText(t)
local dtype = type(t) local dtype = type(t)
local maxw = self.maxw local maxw = self.maxw
local font = self.font local font = self.font
local inserts = {} local inserts = {}
local tdata, prevcolor local tdata, prevcolor
@ -158,7 +164,7 @@ function text:SetText(t)
v = v:gsub(string.char(9), " ") v = v:gsub(string.char(9), " ")
v = v:gsub(string.char(92) .. string.char(110), string.char(10)) v = v:gsub(string.char(92) .. string.char(110), string.char(10))
local parts = loveframes.util.SplitSring(v, " ") local parts = loveframes.util.SplitString(v, " ")
for i, j in ipairs(parts) do for i, j in ipairs(parts) do
table.insert(self.text, {color = prevcolor, text = j}) table.insert(self.text, {color = prevcolor, text = j})
@ -172,11 +178,11 @@ function text:SetText(t)
for k, v in ipairs(self.text) do for k, v in ipairs(self.text) do
local data = v.text local data = v.text
local width = font:getWidth(data) local width = font:getWidth(data)
local curw = 0 local curw = 0
local new = "" local new = ""
local key = k local key = k
if width > maxw then if width > maxw then
@ -216,18 +222,18 @@ function text:SetText(t)
table.insert(self.text, v.key, {color = v.color, text = v.text}) table.insert(self.text, v.key, {color = v.color, text = v.text})
end end
local textdata = self.text local textdata = self.text
local maxw = self.maxw local maxw = self.maxw
local font = self.font local font = self.font
local height = font:getHeight("a") local height = font:getHeight("a")
local twidth = 0 local twidth = 0
local drawx = 0 local drawx = 0
local drawy = 0 local drawy = 0
local lines = 0 local lines = 0
local totalwidth = 0 local totalwidth = 0
local prevtextwidth local x = self.x
local x = self.x local y = self.y
local y = self.y local prevtextwidth = 0
for k, v in ipairs(textdata) do for k, v in ipairs(textdata) do
@ -311,13 +317,13 @@ end
function text:DrawText() function text:DrawText()
local textdata = self.text local textdata = self.text
local font = self.font local font = self.font
local x = self.x local x = self.x
local y = self.y local y = self.y
for k, v in ipairs(textdata) do for k, v in ipairs(textdata) do
local text = v.text local text = v.text
local color = v.color local color = v.color
love.graphics.setFont(font) love.graphics.setFont(font)

File diff suppressed because it is too large Load Diff

View File

@ -1,18 +1,18 @@
# Löve Frames # Love Frames
## Information ## Information
For information on installation and usage, please visit the wiki. Love Frames is a GUI library for LÖVE. For information on installation and usage, please visit the wiki. A demo of the library can be found at: http://nikolairesokav.com/projects/loveframes/
## License ## License
Löve Frames is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) license. Love Frames is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) license.
For more information on this license, please read license.html or visit this web page: http://creativecommons.org/licenses/by-sa/3.0/ For more information on this license, please read license.txt or visit this web page: http://creativecommons.org/licenses/by-sa/3.0/
## Credits ## Credits
Created by Nikolai Resokav Created by Kenny Shields
**Third Party Stuff** **Third Party Libraries**
- middleclass: kikito - middleclass: kikito

View File

@ -1,6 +1,6 @@
--[[------------------------------------------------ --[[------------------------------------------------
-- Löve Frames -- -- Love Frames - A GUI library for LOVE --
-- Copyright 2012 Kenny Shields -- -- Copyright (c) 2012 Kenny Shields --
--]]------------------------------------------------ --]]------------------------------------------------
loveframes.skins = {} loveframes.skins = {}
@ -17,11 +17,11 @@ function loveframes.skins.Register(skin)
local images = loveframes.util.GetDirContents(dir .. "/images") local images = loveframes.util.GetDirContents(dir .. "/images")
local indeximages = loveframes.config["INDEXSKINIMAGES"] local indeximages = loveframes.config["INDEXSKINIMAGES"]
if name == "" or name == nil then if name == "" or not name then
error("Could not register skin: Invalid or missing name data.") error("Could not register skin: Invalid or missing name data.")
end end
if author == "" or author == nil then if author == "" or not author then
error("Could not register skin: Invalid or missing author data.") error("Could not register skin: Invalid or missing author data.")
end end
@ -29,11 +29,11 @@ function loveframes.skins.Register(skin)
error("Could not register skin: Invalid or missing version data.") error("Could not register skin: Invalid or missing version data.")
end end
if namecheck ~= nil then if namecheck then
error("Could not register skin: A skin with the name '" ..name.. "' already exists.") error("Could not register skin: A skin with the name '" ..name.. "' already exists.")
end end
if dircheck == false then if not dircheck then
error("Could not register skin: Could not find a directory for skin '" ..name.. "'.") error("Could not register skin: Could not find a directory for skin '" ..name.. "'.")
end end

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
--[[------------------------------------------------ --[[------------------------------------------------
-- Löve Frames -- -- Love Frames - A GUI library for LOVE --
-- Copyright 2012 Kenny Shields -- -- Copyright (c) 2012 Kenny Shields --
--]]------------------------------------------------ --]]------------------------------------------------
-- templates -- templates

139
third-party/middleclass.lua vendored Normal file
View File

@ -0,0 +1,139 @@
-- middleclass.lua - v2.0 (2011-09)
-- Copyright (c) 2011 Enrique García Cota
-- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-- Based on YaciCode, from Julien Patte and LuaObject, from Sebastien Rocca-Serra
local _classes = setmetatable({}, {__mode = "k"})
local function _setClassDictionariesMetatables(klass)
local dict = klass.__instanceDict
dict.__index = dict
local super = klass.super
if super then
local superStatic = super.static
setmetatable(dict, super.__instanceDict)
setmetatable(klass.static, { __index = function(_,k) return dict[k] or superStatic[k] end })
else
setmetatable(klass.static, { __index = function(_,k) return dict[k] end })
end
end
local function _setClassMetatable(klass)
setmetatable(klass, {
__tostring = function() return "class " .. klass.name end,
__index = klass.static,
__newindex = klass.__instanceDict,
__call = function(self, ...) return self:new(...) end
})
end
local function _createClass(name, super)
local klass = { name = name, super = super, static = {}, __mixins = {}, __instanceDict={} }
klass.subclasses = setmetatable({}, {__mode = "k"})
_setClassDictionariesMetatables(klass)
_setClassMetatable(klass)
_classes[klass] = true
return klass
end
local function _createLookupMetamethod(klass, name)
return function(...)
local method = klass.super[name]
assert( type(method)=='function', tostring(klass) .. " doesn't implement metamethod '" .. name .. "'" )
return method(...)
end
end
local function _setClassMetamethods(klass)
for _,m in ipairs(klass.__metamethods) do
klass[m]= _createLookupMetamethod(klass, m)
end
end
local function _setDefaultInitializeMethod(klass, super)
klass.initialize = function(instance, ...)
return super.initialize(instance, ...)
end
end
local function _includeMixin(klass, mixin)
assert(type(mixin)=='table', "mixin must be a table")
for name,method in pairs(mixin) do
if name ~= "included" and name ~= "static" then klass[name] = method end
end
if mixin.static then
for name,method in pairs(mixin.static) do
klass.static[name] = method
end
end
if type(mixin.included)=="function" then mixin:included(klass) end
klass.__mixins[mixin] = true
end
Object = _createClass("Object", nil)
Object.static.__metamethods = { '__add', '__call', '__concat', '__div', '__le', '__lt',
'__mod', '__mul', '__pow', '__sub', '__tostring', '__unm' }
function Object.static:allocate()
assert(_classes[self], "Make sure that you are using 'Class:allocate' instead of 'Class.allocate'")
return setmetatable({ class = self }, self.__instanceDict)
end
function Object.static:new(...)
local instance = self:allocate()
instance:initialize(...)
return instance
end
function Object.static:subclass(name)
assert(_classes[self], "Make sure that you are using 'Class:subclass' instead of 'Class.subclass'")
assert(type(name) == "string", "You must provide a name(string) for your class")
local subclass = _createClass(name, self)
_setClassMetamethods(subclass)
_setDefaultInitializeMethod(subclass, self)
self.subclasses[subclass] = true
self:subclassed(subclass)
return subclass
end
function Object.static:subclassed(other) end
function Object.static:include( ... )
assert(_classes[self], "Make sure you that you are using 'Class:include' instead of 'Class.include'")
for _,mixin in ipairs({...}) do _includeMixin(self, mixin) end
return self
end
function Object:initialize() end
function Object:__tostring() return "instance of " .. tostring(self.class) end
function class(name, super, ...)
super = super or Object
return super:subclass(name, ...)
end
function instanceOf(aClass, obj)
if not _classes[aClass] or type(obj) ~= 'table' or not _classes[obj.class] then return false end
if obj.class == aClass then return true end
return subclassOf(aClass, obj.class)
end
function subclassOf(other, aClass)
if not _classes[aClass] or not _classes[other] or aClass.super == nil then return false end
return aClass.super == other or subclassOf(other, aClass.super)
end
function includes(mixin, aClass)
if not _classes[aClass] then return false end
if aClass.__mixins[mixin] then return true end
return includes(mixin, aClass.super)
end

View File

@ -1,6 +1,6 @@
--[[------------------------------------------------ --[[------------------------------------------------
-- Löve Frames -- -- Love Frames - A GUI library for LOVE --
-- Copyright 2012 Kenny Shields -- -- Copyright (c) 2012 Kenny Shields --
--]]------------------------------------------------ --]]------------------------------------------------
-- util library -- util library
@ -163,7 +163,7 @@ function loveframes.util.GetDirContents(dir, t)
if isdir == true then if isdir == true then
table.insert(dirs, dir.. "/" ..v) table.insert(dirs, dir.. "/" ..v)
else else
local parts = loveframes.util.SplitSring(v, "([.])") local parts = loveframes.util.SplitString(v, "([.])")
local extension = parts[#parts] local extension = parts[#parts]
local name = restore(parts) local name = restore(parts)
table.insert(t, {path = dir, fullpath = dir.. "/" ..v, name = name, extension = extension}) table.insert(t, {path = dir, fullpath = dir.. "/" ..v, name = name, extension = extension})
@ -195,11 +195,11 @@ function loveframes.util.Round(num, idp)
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------
- func: SplitSring(string, pattern) - func: SplitString(string, pattern)
- desc: splits a string into a table based on a given pattern - desc: splits a string into a table based on a given pattern
- note: i take no credit for this function - note: i take no credit for this function
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function loveframes.util.SplitSring(str, pat) function loveframes.util.SplitString(str, pat)
local t = {} -- NOTE: use {n = 0} in Lua-5.0 local t = {} -- NOTE: use {n = 0} in Lua-5.0