mirror of
https://github.com/linux-man/LoveFrames.git
synced 2024-12-11 07:24:24 +00:00
Version 0.9.3.2 - Alpha (see changelog.txt)
This commit is contained in:
parent
d6190b4757
commit
0e327e5d01
@ -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)
|
||||
================================================
|
||||
|
41
debug.lua
41
debug.lua
@ -1,13 +1,14 @@
|
||||
--[[------------------------------------------------
|
||||
-- Löve Frames --
|
||||
-- Copyright 2012 Kenny Shields --
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- debug library
|
||||
loveframes.debug = {}
|
||||
|
||||
local font = love.graphics.newFont(10)
|
||||
local loremipsum =
|
||||
local font = love.graphics.newFont(10)
|
||||
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.
|
||||
]]
|
||||
@ -23,7 +24,7 @@ function loveframes.debug.draw()
|
||||
local debug = loveframes.config["DEBUG"]
|
||||
|
||||
-- do not draw anthing if debug is off
|
||||
if debug == false then
|
||||
if not debug then
|
||||
return
|
||||
end
|
||||
|
||||
@ -38,7 +39,6 @@ function loveframes.debug.draw()
|
||||
local fps = love.timer.getFPS()
|
||||
local deltatime = love.timer.getDelta()
|
||||
|
||||
|
||||
-- font for debug text
|
||||
love.graphics.setFont(font)
|
||||
|
||||
@ -608,14 +608,39 @@ function loveframes.debug.ExamplesMenu()
|
||||
|
||||
local frame1 = loveframes.Create("frame")
|
||||
frame1:SetName("Text Input")
|
||||
frame1:SetSize(500, 60)
|
||||
frame1:SetSize(500, 90)
|
||||
frame1:Center()
|
||||
|
||||
local textinput1 = loveframes.Create("textinput", frame1)
|
||||
textinput1:SetPos(5, 30)
|
||||
textinput1:SetWidth(490)
|
||||
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
|
||||
|
12
init.lua
12
init.lua
@ -1,6 +1,6 @@
|
||||
--[[------------------------------------------------
|
||||
-- Löve Frames --
|
||||
-- Copyright 2012 Kenny Shields --
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- central library table
|
||||
@ -9,7 +9,7 @@ loveframes = {}
|
||||
-- library info
|
||||
loveframes.info = {}
|
||||
loveframes.info.author = "Nikolai Resokav"
|
||||
loveframes.info.version = "0.9.3.1"
|
||||
loveframes.info.version = "0.9.3.2"
|
||||
loveframes.info.stage = "Alpha"
|
||||
|
||||
-- library configurations
|
||||
@ -36,7 +36,7 @@ function loveframes.load()
|
||||
local dir = loveframes.config["DIRECTORY"]
|
||||
|
||||
-- require the internal base libraries
|
||||
require(dir .. "/third-party/middleclass/middleclass")
|
||||
require(dir .. "/third-party/middleclass")
|
||||
require(dir .. "/util")
|
||||
require(dir .. "/skins")
|
||||
require(dir .. "/templates")
|
||||
@ -172,7 +172,7 @@ function loveframes.Create(data, parent)
|
||||
end
|
||||
|
||||
-- remove the object if it is an internal
|
||||
if object.internal == true then
|
||||
if object.internal then
|
||||
object:Remove()
|
||||
return
|
||||
end
|
||||
@ -182,7 +182,7 @@ function loveframes.Create(data, parent)
|
||||
table.insert(loveframes.base.children, object)
|
||||
|
||||
-- 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)
|
||||
end
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
--[[------------------------------------------------
|
||||
-- Löve Frames --
|
||||
-- Copyright 2012 Kenny Shields --
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- base object
|
||||
@ -74,7 +74,7 @@ function base:mousepressed(x, y, button)
|
||||
local children = self.children
|
||||
local internals = self.internals
|
||||
|
||||
if visible == false then
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
@ -102,7 +102,7 @@ function base:mousereleased(x, y, button)
|
||||
local children = self.children
|
||||
local internals = self.internals
|
||||
|
||||
if visible == false then
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
@ -130,7 +130,7 @@ function base:keypressed(key, unicode)
|
||||
local children = self.children
|
||||
local internals = self.internals
|
||||
|
||||
if visible == false then
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
@ -158,7 +158,7 @@ function base:keyreleased(key)
|
||||
local children = self.children
|
||||
local internals = self.internals
|
||||
|
||||
if visible == false then
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
@ -466,10 +466,6 @@ function base:SetParent(parent)
|
||||
return
|
||||
end
|
||||
|
||||
if stype == "frame" then
|
||||
return
|
||||
end
|
||||
|
||||
self:Remove()
|
||||
self.parent = tparent
|
||||
|
||||
@ -498,23 +494,19 @@ function base:Remove()
|
||||
local pchildren = self.parent.children
|
||||
|
||||
if pinternals then
|
||||
|
||||
for k, v in ipairs(pinternals) do
|
||||
if v == self then
|
||||
table.remove(pinternals, k)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if pchildren then
|
||||
|
||||
for k, v in ipairs(pchildren) do
|
||||
if v == self then
|
||||
table.remove(pchildren, k)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
self.removed = true
|
||||
@ -658,12 +650,12 @@ function base:CheckHover()
|
||||
local clickbounds = self.clickbounds
|
||||
|
||||
-- is the mouse inside the object?
|
||||
if selfcol == true then
|
||||
if selfcol then
|
||||
|
||||
local top = self:IsTopCollision()
|
||||
|
||||
if top == true then
|
||||
if hoverobject == false then
|
||||
if top then
|
||||
if not hoverobject then
|
||||
self.hover = true
|
||||
else
|
||||
if hoverobject == self then
|
||||
@ -677,7 +669,7 @@ function base:CheckHover()
|
||||
end
|
||||
|
||||
if clickbounds then
|
||||
if self:InClickBounds() == false then
|
||||
if not self:InClickBounds() then
|
||||
self.hover = false
|
||||
end
|
||||
end
|
||||
@ -688,7 +680,7 @@ function base:CheckHover()
|
||||
|
||||
end
|
||||
|
||||
if modalobject ~= false then
|
||||
if modalobject then
|
||||
|
||||
if modalobject ~= self then
|
||||
|
||||
@ -711,9 +703,9 @@ function base:CheckHover()
|
||||
-- this chunk of code handles mouse enter and exit
|
||||
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.calledmousefunc = true
|
||||
else
|
||||
@ -724,9 +716,9 @@ function base:CheckHover()
|
||||
|
||||
else
|
||||
|
||||
if self.calledmousefunc == true then
|
||||
if self.calledmousefunc then
|
||||
|
||||
if self.OnMouseExit ~= nil then
|
||||
if self.OnMouseExit then
|
||||
self.OnMouseExit(self)
|
||||
self.calledmousefunc = false
|
||||
else
|
||||
@ -849,7 +841,7 @@ function base:MoveToTop()
|
||||
|
||||
self:Remove()
|
||||
|
||||
if internal == true then
|
||||
if internal then
|
||||
table.insert(pinternals, self)
|
||||
else
|
||||
table.insert(pchildren, self)
|
||||
|
@ -1,9 +1,9 @@
|
||||
--[[------------------------------------------------
|
||||
-- Löve Frames --
|
||||
-- Copyright 2012 Kenny Shields --
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- button clas
|
||||
-- button class
|
||||
button = class("button", base)
|
||||
button:include(loveframes.templates.default)
|
||||
|
||||
@ -13,15 +13,15 @@ button:include(loveframes.templates.default)
|
||||
--]]---------------------------------------------------------
|
||||
function button:initialize()
|
||||
|
||||
self.type = "button"
|
||||
self.text = "Button"
|
||||
self.width = 80
|
||||
self.height = 25
|
||||
self.internal = false
|
||||
self.down = false
|
||||
self.clickable = true
|
||||
self.enabled = true
|
||||
self.OnClick = nil
|
||||
self.type = "button"
|
||||
self.text = "Button"
|
||||
self.width = 80
|
||||
self.height = 25
|
||||
self.internal = false
|
||||
self.down = false
|
||||
self.clickable = true
|
||||
self.enabled = true
|
||||
self.OnClick = nil
|
||||
|
||||
end
|
||||
|
||||
@ -34,38 +34,41 @@ function button:update(dt)
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
if not visible then
|
||||
if not alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
local hover = self.hover
|
||||
local down = self.down
|
||||
local hover = self.hover
|
||||
local down = self.down
|
||||
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
|
||||
elseif hover == true then
|
||||
else
|
||||
if hoverobject == self then
|
||||
self.down = true
|
||||
end
|
||||
end
|
||||
|
||||
if down == false and hoverobject == self then
|
||||
if not down and hoverobject == self then
|
||||
self.hover = true
|
||||
end
|
||||
|
||||
-- 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.y = self.parent.y + self.staticy
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
@ -78,22 +81,24 @@ function button:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
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.DrawButton or skins[defaultskin].DrawButton
|
||||
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.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
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
if draw then
|
||||
draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
@ -108,13 +113,13 @@ function button:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
|
||||
if hover == true and button == "l" then
|
||||
if hover and button == "l" then
|
||||
|
||||
local baseparent = self:GetBaseParent()
|
||||
|
||||
@ -137,19 +142,20 @@ function button:mousereleased(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
local down = self.down
|
||||
local hover = self.hover
|
||||
local down = self.down
|
||||
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 enabled == true then
|
||||
if self.OnClick then
|
||||
self.OnClick(self, x, y)
|
||||
if hover and down and clickable and button == "l" then
|
||||
if enabled then
|
||||
if onclick then
|
||||
onclick(self, x, y)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,6 +1,6 @@
|
||||
--[[------------------------------------------------
|
||||
-- Löve Frames --
|
||||
-- Copyright 2012 Kenny Shields --
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- checkbox class
|
||||
@ -13,18 +13,18 @@ checkbox:include(loveframes.templates.default)
|
||||
--]]---------------------------------------------------------
|
||||
function checkbox:initialize()
|
||||
|
||||
self.type = "checkbox"
|
||||
self.width = 0
|
||||
self.height = 0
|
||||
self.boxwidth = 20
|
||||
self.boxheight = 20
|
||||
self.font = loveframes.basicfont
|
||||
self.checked = false
|
||||
self.lastvalue = false
|
||||
self.internal = false
|
||||
self.down = true
|
||||
self.internals = {}
|
||||
self.OnChanged = nil
|
||||
self.type = "checkbox"
|
||||
self.width = 0
|
||||
self.height = 0
|
||||
self.boxwidth = 20
|
||||
self.boxheight = 20
|
||||
self.font = loveframes.basicfont
|
||||
self.checked = false
|
||||
self.lastvalue = false
|
||||
self.internal = false
|
||||
self.down = true
|
||||
self.internals = {}
|
||||
self.OnChanged = nil
|
||||
|
||||
end
|
||||
|
||||
@ -37,59 +37,67 @@ function checkbox:update(dt)
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
if not visible then
|
||||
if not alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
elseif self.hover == true then
|
||||
else
|
||||
if loveframes.hoverobject == self then
|
||||
self.down = true
|
||||
end
|
||||
end
|
||||
|
||||
if self.down == false and loveframes.hoverobject == self then
|
||||
if not self.down and loveframes.hoverobject == self then
|
||||
self.hover = true
|
||||
end
|
||||
|
||||
-- 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.y = self.parent.y + self.staticy
|
||||
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
|
||||
self.height = self.boxheight
|
||||
if internals[1].height == boxheight then
|
||||
self.height = boxheight
|
||||
else
|
||||
if self.internals[1].height > self.boxheight then
|
||||
self.height = self.internals[1].height
|
||||
if internals[1].height > boxheight then
|
||||
self.height = internals[1].height
|
||||
else
|
||||
self.height = self.boxheight
|
||||
self.height = boxheight
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
self.width = self.boxwidth
|
||||
self.height = self.boxheight
|
||||
self.width = boxwidth
|
||||
self.height = boxheight
|
||||
|
||||
end
|
||||
|
||||
for k, v in ipairs(self.internals) do
|
||||
for k, v in ipairs(internals) do
|
||||
v:update(dt)
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
@ -102,27 +110,30 @@ function checkbox:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
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.DrawCheckBox or skins[defaultskin].DrawCheckBox
|
||||
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.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
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
if draw then
|
||||
draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
|
||||
for k, v in ipairs(self.internals) do
|
||||
for k, v in ipairs(internals) do
|
||||
v:draw()
|
||||
end
|
||||
|
||||
@ -136,13 +147,13 @@ function checkbox:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
|
||||
if hover == true and button == "l" then
|
||||
if hover and button == "l" then
|
||||
|
||||
local baseparent = self:GetBaseParent()
|
||||
|
||||
@ -165,23 +176,24 @@ function checkbox:mousereleased(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
local checked = self.checked
|
||||
local hover = self.hover
|
||||
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
|
||||
else
|
||||
self.checked = true
|
||||
end
|
||||
|
||||
if self.OnChanged then
|
||||
self.OnChanged(self)
|
||||
if onchanged then
|
||||
onchanged(self)
|
||||
end
|
||||
|
||||
end
|
||||
@ -194,6 +206,9 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function checkbox:SetText(text)
|
||||
|
||||
local boxwidth = self.boxwidth
|
||||
local boxheight = self.boxheight
|
||||
|
||||
if text ~= "" then
|
||||
|
||||
self.internals = {}
|
||||
@ -205,10 +220,10 @@ function checkbox:SetText(text)
|
||||
textobject:SetFont(self.font)
|
||||
textobject:SetText(text)
|
||||
textobject.Update = function(object, dt)
|
||||
if object.height > self.boxheight then
|
||||
object:SetPos(self.boxwidth + 5, 0)
|
||||
if object.height > boxheight then
|
||||
object:SetPos(boxwidth + 5, 0)
|
||||
else
|
||||
object:SetPos(self.boxwidth + 5, self.boxheight/2 - object.height/2)
|
||||
object:SetPos(boxwidth + 5, boxheight/2 - object.height/2)
|
||||
end
|
||||
end
|
||||
|
||||
@ -216,8 +231,8 @@ function checkbox:SetText(text)
|
||||
|
||||
else
|
||||
|
||||
self.width = self.boxwidth
|
||||
self.height = self.boxheight
|
||||
self.width = boxwidth
|
||||
self.height = boxheight
|
||||
self.internals = {}
|
||||
|
||||
end
|
||||
@ -231,7 +246,7 @@ end
|
||||
function checkbox:GetText()
|
||||
|
||||
local internals = self.internals
|
||||
local text = internals[1]
|
||||
local text = internals[1]
|
||||
|
||||
if text then
|
||||
return text.text
|
||||
@ -247,7 +262,7 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function checkbox:SetSize(width, height)
|
||||
|
||||
self.boxwidth = width
|
||||
self.boxwidth = width
|
||||
self.boxheight = height
|
||||
|
||||
end
|
||||
@ -278,10 +293,12 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function checkbox:SetChecked(bool)
|
||||
|
||||
local onchanged = self.OnChanged
|
||||
|
||||
self.checked = bool
|
||||
|
||||
if self.OnChanged then
|
||||
self.OnChanged(self)
|
||||
if onchanged then
|
||||
onchanged(self)
|
||||
end
|
||||
|
||||
end
|
||||
@ -303,7 +320,7 @@ end
|
||||
function checkbox:SetFont(font)
|
||||
|
||||
local internals = self.internals
|
||||
local text = internals[1]
|
||||
local text = internals[1]
|
||||
|
||||
self.font = font
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
--[[------------------------------------------------
|
||||
-- Löve Frames --
|
||||
-- Copyright 2012 Kenny Shields --
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- button clas
|
||||
-- collapsiblecategory class
|
||||
collapsiblecategory = class("collapsiblecategory", base)
|
||||
collapsiblecategory:include(loveframes.templates.default)
|
||||
|
||||
@ -13,17 +13,17 @@ collapsiblecategory:include(loveframes.templates.default)
|
||||
--]]---------------------------------------------------------
|
||||
function collapsiblecategory:initialize()
|
||||
|
||||
self.type = "collapsiblecategory"
|
||||
self.text = "Category"
|
||||
self.width = 200
|
||||
self.height = 25
|
||||
self.closedheight = 25
|
||||
self.padding = 5
|
||||
self.internal = false
|
||||
self.open = false
|
||||
self.down = false
|
||||
self.children = {}
|
||||
self.OnOpenedClosed = nil
|
||||
self.type = "collapsiblecategory"
|
||||
self.text = "Category"
|
||||
self.width = 200
|
||||
self.height = 25
|
||||
self.closedheight = 25
|
||||
self.padding = 5
|
||||
self.internal = false
|
||||
self.open = false
|
||||
self.down = false
|
||||
self.children = {}
|
||||
self.OnOpenedClosed = nil
|
||||
|
||||
end
|
||||
|
||||
@ -33,34 +33,37 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function collapsiblecategory:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
if not visible then
|
||||
if not alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local open = self.open
|
||||
local children = self.children
|
||||
local open = self.open
|
||||
local children = self.children
|
||||
local curobject = children[1]
|
||||
local parent = self.parent
|
||||
local base = loveframes.base
|
||||
local update = self.Update
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
-- 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.y = self.parent.y + self.staticy
|
||||
end
|
||||
|
||||
if open == true then
|
||||
curobject:SetWidth(self.width - self.padding*2)
|
||||
curobject:SetWidth(self.width - self.padding * 2)
|
||||
curobject:update(dt)
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
@ -77,26 +80,28 @@ function collapsiblecategory:draw()
|
||||
return
|
||||
end
|
||||
|
||||
local open = self.open
|
||||
local children = self.children
|
||||
local curobject = children[1]
|
||||
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.DrawCollapsibleCategory or skins[defaultskin].DrawCollapsibleCategory
|
||||
local open = self.open
|
||||
local children = self.children
|
||||
local curobject = children[1]
|
||||
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.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
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
if draw then
|
||||
draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
|
||||
if open == true then
|
||||
if open then
|
||||
curobject:draw()
|
||||
end
|
||||
|
||||
@ -110,20 +115,20 @@ function collapsiblecategory:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
local open = self.open
|
||||
local children = self.children
|
||||
local hover = self.hover
|
||||
local open = self.open
|
||||
local children = self.children
|
||||
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)
|
||||
|
||||
if button == "l" and col == true then
|
||||
if button == "l" and col then
|
||||
|
||||
local baseparent = self:GetBaseParent()
|
||||
|
||||
@ -138,7 +143,7 @@ function collapsiblecategory:mousepressed(x, y, button)
|
||||
|
||||
end
|
||||
|
||||
if open == true then
|
||||
if open then
|
||||
curobject:mousepressed(x, y, button)
|
||||
end
|
||||
|
||||
@ -152,22 +157,22 @@ function collapsiblecategory:mousereleased(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
local down = self.down
|
||||
local hover = self.hover
|
||||
local down = self.down
|
||||
local clickable = self.clickable
|
||||
local enabled = self.enabled
|
||||
local open = self.open
|
||||
local col = loveframes.util.BoundingBox(self.x, x, self.y, y, self.width, 1, self.closedheight, 1)
|
||||
local children = self.children
|
||||
local enabled = self.enabled
|
||||
local open = self.open
|
||||
local col = loveframes.util.BoundingBox(self.x, x, self.y, y, self.width, 1, self.closedheight, 1)
|
||||
local children = self.children
|
||||
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)
|
||||
else
|
||||
self:SetOpen(true)
|
||||
@ -177,7 +182,7 @@ function collapsiblecategory:mousereleased(x, y, button)
|
||||
|
||||
end
|
||||
|
||||
if open == true then
|
||||
if open then
|
||||
curobject:mousepressed(x, y, button)
|
||||
end
|
||||
|
||||
@ -209,7 +214,7 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function collapsiblecategory:SetObject(object)
|
||||
|
||||
local children = self.children
|
||||
local children = self.children
|
||||
local curobject = children[1]
|
||||
|
||||
if curobject then
|
||||
@ -232,7 +237,7 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function collapsiblecategory:GetObject()
|
||||
|
||||
local children = self.children
|
||||
local children = self.children
|
||||
local curobject = children[1]
|
||||
|
||||
if curobject then
|
||||
@ -289,25 +294,30 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function collapsiblecategory:SetOpen(bool)
|
||||
|
||||
local children = self.children
|
||||
local curobject = children[1]
|
||||
local children = self.children
|
||||
local curobject = children[1]
|
||||
local closedheight = self.closedheight
|
||||
local padding = self.padding
|
||||
local curobjectheight = curobject.height
|
||||
local onopenedclosed = self.OnOpenedClosed
|
||||
|
||||
self.open = bool
|
||||
|
||||
if bool == false then
|
||||
self.height = self.closedheight
|
||||
if not bool then
|
||||
self.height = closedheight
|
||||
if curobject then
|
||||
curobject:SetVisible(false)
|
||||
end
|
||||
else
|
||||
self.height = self.closedheight + self.padding*2 + curobject.height
|
||||
self.height = closedheight + padding * 2 + curobjectheight
|
||||
if curobject then
|
||||
curobject:SetVisible(true)
|
||||
end
|
||||
end
|
||||
|
||||
if self.OnOpenedClosed then
|
||||
self.OnOpenedClosed(self)
|
||||
-- call the on opened closed callback if it exists
|
||||
if onopenedclosed then
|
||||
onopenedclosed(self)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -1,9 +1,9 @@
|
||||
--[[------------------------------------------------
|
||||
-- Löve Frames --
|
||||
-- Copyright 2012 Kenny Shields --
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- columnlist object
|
||||
-- columnlist class
|
||||
columnlist = class("columnlist", base)
|
||||
columnlist:include(loveframes.templates.default)
|
||||
|
||||
@ -13,15 +13,15 @@ columnlist:include(loveframes.templates.default)
|
||||
--]]---------------------------------------------------------
|
||||
function columnlist:initialize()
|
||||
|
||||
self.type = "columnlist"
|
||||
self.width = 300
|
||||
self.height = 100
|
||||
self.autoscroll = false
|
||||
self.internal = false
|
||||
self.children = {}
|
||||
self.internals = {}
|
||||
self.OnRowClicked = nil
|
||||
self.OnScroll = nil
|
||||
self.type = "columnlist"
|
||||
self.width = 300
|
||||
self.height = 100
|
||||
self.autoscroll = false
|
||||
self.internal = false
|
||||
self.children = {}
|
||||
self.internals = {}
|
||||
self.OnRowClicked = nil
|
||||
self.OnScroll = nil
|
||||
|
||||
local list = columnlistarea:new(self)
|
||||
table.insert(self.internals, list)
|
||||
@ -37,19 +37,22 @@ function columnlist:update(dt)
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
if not visible then
|
||||
if not alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local children = self.children
|
||||
local parent = self.parent
|
||||
local base = loveframes.base
|
||||
local children = self.children
|
||||
local internals = self.internals
|
||||
local update = self.Update
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
-- 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.y = self.parent.y + self.staticy
|
||||
end
|
||||
@ -62,8 +65,8 @@ function columnlist:update(dt)
|
||||
v:update(dt)
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
@ -76,27 +79,26 @@ function columnlist:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
if not visible then
|
||||
return
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
if draw then
|
||||
draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
@ -123,8 +125,8 @@ function columnlist:mousepressed(x, y, button)
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
local children = self.children
|
||||
local hover = self.hover
|
||||
local children = self.children
|
||||
local internals = self.internals
|
||||
|
||||
if hover == true and button == "l" then
|
||||
@ -179,16 +181,16 @@ end
|
||||
function columnlist:AdjustColumns()
|
||||
|
||||
local width = self.width
|
||||
local bar = self.internals[1].bar
|
||||
local bar = self.internals[1].bar
|
||||
|
||||
if bar == true then
|
||||
width = width - 16
|
||||
end
|
||||
|
||||
local children = self.children
|
||||
local children = self.children
|
||||
local numchildren = #children
|
||||
local columnwidth = width/numchildren
|
||||
local x = 0
|
||||
local x = 0
|
||||
|
||||
for k, v in ipairs(children) do
|
||||
if bar == true then
|
||||
@ -210,12 +212,13 @@ end
|
||||
function columnlist:AddColumn(name)
|
||||
|
||||
local internals = self.internals
|
||||
local list = internals[1]
|
||||
local list = internals[1]
|
||||
local height = self.height
|
||||
|
||||
columnlistheader:new(name, self)
|
||||
self:AdjustColumns()
|
||||
|
||||
list:SetSize(self.width, self.height)
|
||||
list:SetSize(self.width, height)
|
||||
list:SetPos(0, 0)
|
||||
|
||||
end
|
||||
@ -227,7 +230,7 @@ end
|
||||
function columnlist:AddRow(...)
|
||||
|
||||
local internals = self.internals
|
||||
local list = internals[1]
|
||||
local list = internals[1]
|
||||
|
||||
list:AddRow(arg)
|
||||
|
||||
@ -239,11 +242,11 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function columnlist:GetColumnSize()
|
||||
|
||||
local children = self.children
|
||||
local children = self.children
|
||||
local numchildren = #self.children
|
||||
local column = self.children[1]
|
||||
local colwidth = column.width
|
||||
local colheight = column.height
|
||||
local column = self.children[1]
|
||||
local colwidth = column.width
|
||||
local colheight = column.height
|
||||
|
||||
if numchildren > 0 then
|
||||
return colwidth, colheight
|
||||
@ -260,7 +263,7 @@ end
|
||||
function columnlist:SetSize(width, height)
|
||||
|
||||
local internals = self.internals
|
||||
local list = internals[1]
|
||||
local list = internals[1]
|
||||
|
||||
self.width = width
|
||||
self.height = height
|
||||
@ -277,7 +280,7 @@ end
|
||||
function columnlist:SetWidth(width)
|
||||
|
||||
local internals = self.internals
|
||||
local list = internals[1]
|
||||
local list = internals[1]
|
||||
|
||||
self.width = width
|
||||
|
||||
@ -293,7 +296,7 @@ end
|
||||
function columnlist:SetHeight(height)
|
||||
|
||||
local internals = self.internals
|
||||
local list = internals[1]
|
||||
local list = internals[1]
|
||||
|
||||
self.height = height
|
||||
|
||||
@ -310,7 +313,7 @@ end
|
||||
function columnlist:SetMaxColorIndex(num)
|
||||
|
||||
local internals = self.internals
|
||||
local list = internals[1]
|
||||
local list = internals[1]
|
||||
|
||||
list.colorindexmax = num
|
||||
|
||||
@ -323,7 +326,7 @@ end
|
||||
function columnlist:Clear()
|
||||
|
||||
local internals = self.internals
|
||||
local list = internals[1]
|
||||
local list = internals[1]
|
||||
|
||||
list:Clear()
|
||||
|
||||
@ -338,13 +341,14 @@ end
|
||||
function columnlist:SetAutoScroll(bool)
|
||||
|
||||
local internals = self.internals
|
||||
local list = internals[1]
|
||||
local list = internals[1]
|
||||
local scrollbar = list:GetScrollBar()
|
||||
|
||||
self.autoscroll = bool
|
||||
|
||||
if list then
|
||||
if list:GetScrollBar() ~= false then
|
||||
list:GetScrollBar().autoscroll = bool
|
||||
if scrollbar then
|
||||
scrollbar.autoscroll = bool
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
--[[------------------------------------------------
|
||||
-- Löve Frames --
|
||||
-- Copyright 2012 Kenny Shields --
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- frame class
|
||||
@ -13,34 +13,33 @@ frame:include(loveframes.templates.default)
|
||||
--]]---------------------------------------------------------
|
||||
function frame:initialize()
|
||||
|
||||
self.type = "frame"
|
||||
self.name = "Frame"
|
||||
self.width = 300
|
||||
self.height = 150
|
||||
self.clickx = 0
|
||||
self.clicky = 0
|
||||
self.internal = false
|
||||
self.draggable = true
|
||||
self.screenlocked = false
|
||||
self.dragging = false
|
||||
self.modal = false
|
||||
self.modalbackground = false
|
||||
self.showclose = true
|
||||
self.internals = {}
|
||||
self.children = {}
|
||||
self.OnClose = nil
|
||||
self.type = "frame"
|
||||
self.name = "Frame"
|
||||
self.width = 300
|
||||
self.height = 150
|
||||
self.clickx = 0
|
||||
self.clicky = 0
|
||||
self.internal = false
|
||||
self.draggable = true
|
||||
self.screenlocked = false
|
||||
self.dragging = false
|
||||
self.modal = false
|
||||
self.modalbackground = false
|
||||
self.showclose = true
|
||||
self.internals = {}
|
||||
self.children = {}
|
||||
self.OnClose = nil
|
||||
|
||||
-- create the close button for the frame
|
||||
local close = closebutton:new()
|
||||
close.parent = self
|
||||
close:SetSize(16, 16)
|
||||
close.OnClick = function()
|
||||
|
||||
local onclose = self.OnClose
|
||||
self:Remove()
|
||||
|
||||
if self.OnClose then
|
||||
self.OnClose(self)
|
||||
if onclose then
|
||||
onclose(self)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
table.insert(self.internals, close)
|
||||
@ -53,33 +52,34 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function frame:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
if not visible then
|
||||
if not alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local x, y = love.mouse.getPosition()
|
||||
local showclose = self.showclose
|
||||
local close = self.internals[1]
|
||||
local dragging = self.dragging
|
||||
local screenlocked = self.screenlocked
|
||||
local modal = self.modal
|
||||
local base = loveframes.base
|
||||
local basechildren = base.children
|
||||
local numbasechildren = #basechildren
|
||||
local draworder = self.draworder
|
||||
local children = self.children
|
||||
local internals = self.internals
|
||||
local x, y = love.mouse.getPosition()
|
||||
local showclose = self.showclose
|
||||
local close = self.internals[1]
|
||||
local dragging = self.dragging
|
||||
local screenlocked = self.screenlocked
|
||||
local modal = self.modal
|
||||
local base = loveframes.base
|
||||
local basechildren = base.children
|
||||
local numbasechildren = #basechildren
|
||||
local draworder = self.draworder
|
||||
local children = self.children
|
||||
local internals = self.internals
|
||||
local update = self.Update
|
||||
|
||||
close:SetPos(self.width - 20, 4)
|
||||
self:CheckHover()
|
||||
|
||||
-- dragging check
|
||||
if dragging == true then
|
||||
if dragging then
|
||||
self.x = x - self.clickx
|
||||
self.y = y - self.clicky
|
||||
end
|
||||
@ -89,18 +89,20 @@ function frame:update(dt)
|
||||
|
||||
local width = love.graphics.getWidth()
|
||||
local height = love.graphics.getHeight()
|
||||
local selfwidth = self.width
|
||||
local selfheight = self.height
|
||||
|
||||
if self.x < 0 then
|
||||
self.x = 0
|
||||
end
|
||||
if self.x + self.width > width then
|
||||
self.x = width - self.width
|
||||
if self.x + selfwidth > width then
|
||||
self.x = width - selfwidth
|
||||
end
|
||||
if self.y < 0 then
|
||||
self.y = 0
|
||||
end
|
||||
if self.y + self.height > height then
|
||||
self.y = height - self.height
|
||||
if self.y + selfheight > height then
|
||||
self.y = height - selfheight
|
||||
end
|
||||
|
||||
end
|
||||
@ -138,8 +140,8 @@ function frame:update(dt)
|
||||
v:update(dt)
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
@ -152,24 +154,26 @@ function frame:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
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.DrawFrame or skins[defaultskin].DrawFrame
|
||||
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.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
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
if draw then
|
||||
draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
@ -193,30 +197,30 @@ function frame:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
local width = self.width
|
||||
local height = self.height
|
||||
local selfcol = loveframes.util.BoundingBox(x, self.x, y, self.y, 1, self.width, 1, self.height)
|
||||
local children = self.children
|
||||
local width = self.width
|
||||
local height = self.height
|
||||
local selfcol = loveframes.util.BoundingBox(x, self.x, y, self.y, 1, self.width, 1, self.height)
|
||||
local internals = self.internals
|
||||
local children = self.children
|
||||
|
||||
if selfcol == true then
|
||||
if selfcol then
|
||||
|
||||
local top = self:IsTopCollision()
|
||||
|
||||
-- initiate dragging if not currently dragging
|
||||
if self.dragging == false and top == true and button == "l" then
|
||||
if y < self.y + 25 and self.draggable == true then
|
||||
if not self.dragging and top and button == "l" then
|
||||
if y < self.y + 25 and self.draggable then
|
||||
self.clickx = x - self.x
|
||||
self.clicky = y - self.y
|
||||
self.dragging = true
|
||||
end
|
||||
end
|
||||
|
||||
if top == true and button == "l" then
|
||||
if top and button == "l" then
|
||||
self:MakeTop()
|
||||
end
|
||||
|
||||
@ -240,16 +244,16 @@ function frame:mousereleased(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
local dragging = self.dragging
|
||||
local children = self.children
|
||||
local dragging = self.dragging
|
||||
local children = self.children
|
||||
local internals = self.internals
|
||||
|
||||
-- exit the dragging state
|
||||
if dragging == true then
|
||||
if dragging then
|
||||
self.dragging = false
|
||||
end
|
||||
|
||||
@ -346,10 +350,10 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function frame:MakeTop()
|
||||
|
||||
local x, y = love.mouse.getPosition()
|
||||
local key = 0
|
||||
local base = loveframes.base
|
||||
local basechildren = base.children
|
||||
local x, y = love.mouse.getPosition()
|
||||
local key = 0
|
||||
local base = loveframes.base
|
||||
local basechildren = base.children
|
||||
local numbasechildren = #basechildren
|
||||
|
||||
if numbasechildren == 1 then
|
||||
@ -386,15 +390,15 @@ function frame:SetModal(bool)
|
||||
|
||||
self.modal = bool
|
||||
|
||||
if bool == true then
|
||||
if bool then
|
||||
|
||||
if modalobject ~= false then
|
||||
if modalobject then
|
||||
modalobject:SetModal(false)
|
||||
end
|
||||
|
||||
loveframes.modalobject = self
|
||||
|
||||
if mbackground == false then
|
||||
if not mbackground then
|
||||
self.modalbackground = modalbackground:new(self)
|
||||
self.modal = true
|
||||
end
|
||||
@ -405,7 +409,7 @@ function frame:SetModal(bool)
|
||||
|
||||
loveframes.modalobject = false
|
||||
|
||||
if mbackground ~= false then
|
||||
if mbackground then
|
||||
self.modalbackground:Remove()
|
||||
self.modalbackground = false
|
||||
self.modal = false
|
||||
@ -434,8 +438,8 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function frame:SetVisible(bool)
|
||||
|
||||
local children = self.children
|
||||
local internals = self.internals
|
||||
local children = self.children
|
||||
local internals = self.internals
|
||||
local closebutton = internals[1]
|
||||
|
||||
self.visible = bool
|
||||
@ -444,7 +448,7 @@ function frame:SetVisible(bool)
|
||||
v:SetVisible(bool)
|
||||
end
|
||||
|
||||
if self.showclose == true then
|
||||
if self.showclose then
|
||||
closebutton.visible = bool
|
||||
end
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
--[[------------------------------------------------
|
||||
-- Löve Frames --
|
||||
-- Copyright 2012 Kenny Shields --
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- progress bar class
|
||||
-- progressbar class
|
||||
image = class("image", base)
|
||||
image:include(loveframes.templates.default)
|
||||
|
||||
@ -13,12 +13,12 @@ image:include(loveframes.templates.default)
|
||||
--]]---------------------------------------------------------
|
||||
function image:initialize()
|
||||
|
||||
self.type = "image"
|
||||
self.width = 0
|
||||
self.height = 0
|
||||
self.internal = false
|
||||
self.image = nil
|
||||
self.imagecolor = nil
|
||||
self.type = "image"
|
||||
self.width = 0
|
||||
self.height = 0
|
||||
self.internal = false
|
||||
self.image = nil
|
||||
self.imagecolor = nil
|
||||
|
||||
end
|
||||
|
||||
@ -28,23 +28,27 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function image:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
if not visible then
|
||||
if not alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local parent = self.parent
|
||||
local base = loveframes.base
|
||||
local update = self.Update
|
||||
|
||||
-- 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.y = self.parent.y + self.staticy
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
@ -57,22 +61,24 @@ function image:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
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.DrawImage or skins[defaultskin].DrawImage
|
||||
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.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
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
if draw then
|
||||
draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
|
@ -1,9 +1,9 @@
|
||||
--[[------------------------------------------------
|
||||
-- Löve Frames --
|
||||
-- Copyright 2012 Kenny Shields --
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- imagebutton clas
|
||||
-- imagebutton class
|
||||
imagebutton = class("imagebutton", base)
|
||||
imagebutton:include(loveframes.templates.default)
|
||||
|
||||
@ -13,16 +13,16 @@ imagebutton:include(loveframes.templates.default)
|
||||
--]]---------------------------------------------------------
|
||||
function imagebutton:initialize()
|
||||
|
||||
self.type = "imagebutton"
|
||||
self.text = "Image Button"
|
||||
self.width = 50
|
||||
self.height = 50
|
||||
self.internal = false
|
||||
self.down = false
|
||||
self.clickable = true
|
||||
self.enabled = true
|
||||
self.image = nil
|
||||
self.OnClick = nil
|
||||
self.type = "imagebutton"
|
||||
self.text = "Image Button"
|
||||
self.width = 50
|
||||
self.height = 50
|
||||
self.internal = false
|
||||
self.down = false
|
||||
self.clickable = true
|
||||
self.enabled = true
|
||||
self.image = nil
|
||||
self.OnClick = nil
|
||||
|
||||
end
|
||||
|
||||
@ -32,41 +32,44 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function imagebutton:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
if not visible then
|
||||
if not alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
local hover = self.hover
|
||||
local hover = self.hover
|
||||
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
|
||||
elseif hover == true then
|
||||
else
|
||||
if hoverobject == self then
|
||||
self.down = true
|
||||
end
|
||||
end
|
||||
|
||||
if down == false and hoverobject == self then
|
||||
if not down and hoverobject == self then
|
||||
self.hover = true
|
||||
end
|
||||
|
||||
-- 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.y = self.parent.y + self.staticy
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
@ -79,22 +82,24 @@ function imagebutton:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
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.DrawImageButton or skins[defaultskin].DrawImageButton
|
||||
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.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
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
if draw then
|
||||
draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
@ -109,13 +114,13 @@ function imagebutton:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
|
||||
if hover == true and button == "l" then
|
||||
if hover and button == "l" then
|
||||
|
||||
local baseparent = self:GetBaseParent()
|
||||
|
||||
@ -138,19 +143,20 @@ function imagebutton:mousereleased(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
local down = self.down
|
||||
local hover = self.hover
|
||||
local down = self.down
|
||||
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 enabled == true then
|
||||
if self.OnClick then
|
||||
self.OnClick(self, x, y)
|
||||
if hover and down and clickable and button == "l" then
|
||||
if enabled then
|
||||
if onclick then
|
||||
onclick(self, x, y)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,9 +1,9 @@
|
||||
--[[------------------------------------------------
|
||||
-- Löve Frames --
|
||||
-- Copyright 2012 Kenny Shields --
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- closebutton clas
|
||||
-- closebutton class
|
||||
closebutton = class("closebutton", base)
|
||||
closebutton:include(loveframes.templates.default)
|
||||
|
||||
@ -13,13 +13,13 @@ closebutton:include(loveframes.templates.default)
|
||||
--]]---------------------------------------------------------
|
||||
function closebutton:initialize()
|
||||
|
||||
self.type = "closebutton"
|
||||
self.width = 80
|
||||
self.height = 25
|
||||
self.internal = true
|
||||
self.hover = false
|
||||
self.down = false
|
||||
self.OnClick = function() end
|
||||
self.type = "closebutton"
|
||||
self.width = 80
|
||||
self.height = 25
|
||||
self.internal = true
|
||||
self.hover = false
|
||||
self.down = false
|
||||
self.OnClick = function() end
|
||||
|
||||
end
|
||||
|
||||
@ -29,41 +29,44 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function closebutton:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
if not visible then
|
||||
if not alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
local hover = self.hover
|
||||
local down = self.down
|
||||
local hover = self.hover
|
||||
local down = self.down
|
||||
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
|
||||
elseif hover == true then
|
||||
else
|
||||
if loveframes.hoverobject == self then
|
||||
self.down = true
|
||||
end
|
||||
end
|
||||
|
||||
if down == false and hoverobject == self then
|
||||
if not down and hoverobject == self then
|
||||
self.hover = true
|
||||
end
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if self.parent ~= loveframes.base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
if parent ~= base then
|
||||
self.x = parent.x + self.staticx
|
||||
self.y = parent.y + self.staticy
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
@ -76,22 +79,24 @@ function closebutton:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
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.DrawCloseButton or skins[defaultskin].DrawCloseButton
|
||||
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.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
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
if draw then
|
||||
draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
@ -106,13 +111,13 @@ function closebutton:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
|
||||
if hover == true and button == "l" then
|
||||
if hover and button == "l" then
|
||||
|
||||
local baseparent = self:GetBaseParent()
|
||||
|
||||
@ -135,16 +140,17 @@ function closebutton:mousereleased(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
if not visible then
|
||||
return
|
||||
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
|
||||
self.OnClick(x, y, self)
|
||||
onclick(x, y, self)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -1,9 +1,9 @@
|
||||
--[[------------------------------------------------
|
||||
-- Löve Frames --
|
||||
-- Copyright 2012 Kenny Shields --
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- columnlistarea object
|
||||
-- columnlistarea class
|
||||
columnlistarea = class("columnlistarea", base)
|
||||
columnlistarea:include(loveframes.templates.default)
|
||||
|
||||
@ -13,22 +13,23 @@ columnlistarea:include(loveframes.templates.default)
|
||||
--]]---------------------------------------------------------
|
||||
function columnlistarea:initialize(parent)
|
||||
|
||||
self.type = "columnlistarea"
|
||||
self.display = "vertical"
|
||||
self.parent = parent
|
||||
self.width = 80
|
||||
self.height = 25
|
||||
self.clickx = 0
|
||||
self.clicky = 0
|
||||
self.offsety = 0
|
||||
self.offsetx = 0
|
||||
self.extra = 0
|
||||
self.rowcolorindex = 1
|
||||
self.rowcolorindexmax = 2
|
||||
self.bar = false
|
||||
self.internal = true
|
||||
self.internals = {}
|
||||
self.children = {}
|
||||
self.type = "columnlistarea"
|
||||
self.display = "vertical"
|
||||
self.parent = parent
|
||||
self.width = 80
|
||||
self.height = 25
|
||||
self.clickx = 0
|
||||
self.clicky = 0
|
||||
self.offsety = 0
|
||||
self.offsetx = 0
|
||||
self.extrawidth = 0
|
||||
self.extraheight = 0
|
||||
self.rowcolorindex = 1
|
||||
self.rowcolorindexmax = 2
|
||||
self.bar = false
|
||||
self.internal = true
|
||||
self.internals = {}
|
||||
self.children = {}
|
||||
|
||||
end
|
||||
|
||||
@ -38,40 +39,43 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function columnlistarea:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
if not visible then
|
||||
if not alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
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()
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if self.parent ~= loveframes.base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
if parent ~= base then
|
||||
self.x = parent.x + self.staticx
|
||||
self.y = parent.y + self.staticy
|
||||
end
|
||||
|
||||
for k, v in ipairs(self.internals) do
|
||||
for k, v in ipairs(internals) do
|
||||
v:update(dt)
|
||||
end
|
||||
|
||||
for k, v in ipairs(self.children) do
|
||||
|
||||
for k, v in ipairs(children) do
|
||||
v:update(dt)
|
||||
v:SetClickBounds(self.x, self.y, self.width, self.height)
|
||||
v.y = (v.parent.y + v.staticy) - self.offsety + cheight
|
||||
v.x = (v.parent.x + v.staticx) - self.offsetx
|
||||
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
@ -84,31 +88,36 @@ function columnlistarea:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
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.DrawColumnListArea or skins[defaultskin].DrawColumnListArea
|
||||
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.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
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
if draw then
|
||||
draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
|
||||
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)
|
||||
if col == true then
|
||||
v:draw()
|
||||
@ -117,11 +126,11 @@ function columnlistarea:draw()
|
||||
|
||||
love.graphics.setStencil()
|
||||
|
||||
for k, v in ipairs(self.internals) do
|
||||
for k, v in ipairs(internals) do
|
||||
v:draw()
|
||||
end
|
||||
|
||||
if self.Draw == nil then
|
||||
if not draw then
|
||||
skin.DrawOverColumnListArea(self)
|
||||
end
|
||||
|
||||
@ -133,9 +142,11 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
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()
|
||||
|
||||
@ -145,27 +156,23 @@ function columnlistarea:mousepressed(x, y, button)
|
||||
|
||||
end
|
||||
|
||||
if self.bar == true then
|
||||
if self.bar and toplist then
|
||||
|
||||
if toplist == true then
|
||||
|
||||
local bar = self:GetScrollBar()
|
||||
|
||||
if button == "wu" then
|
||||
bar:Scroll(-5)
|
||||
elseif button == "wd" then
|
||||
bar:Scroll(5)
|
||||
end
|
||||
local bar = self:GetScrollBar()
|
||||
|
||||
if button == "wu" then
|
||||
bar:Scroll(-5)
|
||||
elseif button == "wd" then
|
||||
bar:Scroll(5)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
for k, v in ipairs(self.internals) do
|
||||
for k, v in ipairs(internals) do
|
||||
v:mousepressed(x, y, button)
|
||||
end
|
||||
|
||||
for k, v in ipairs(self.children) do
|
||||
for k, v in ipairs(children) do
|
||||
v:mousepressed(x, y, button)
|
||||
end
|
||||
|
||||
@ -177,11 +184,14 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
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)
|
||||
end
|
||||
|
||||
for k, v in ipairs(self.children) do
|
||||
for k, v in ipairs(children) do
|
||||
v:mousereleased(x, y, button)
|
||||
end
|
||||
|
||||
@ -193,15 +203,16 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function columnlistarea:CalculateSize()
|
||||
|
||||
local iw, ih = self.parent:GetColumnSize()
|
||||
local numitems = #self.children
|
||||
local height = self.height
|
||||
local width = self.width
|
||||
local itemheight = ih
|
||||
local itemwidth = 0
|
||||
local bar = self.bar
|
||||
local iw, ih = self.parent:GetColumnSize()
|
||||
local numitems = #self.children
|
||||
local height = self.height
|
||||
local width = self.width
|
||||
local itemheight = ih
|
||||
local itemwidth = 0
|
||||
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
|
||||
end
|
||||
|
||||
@ -209,9 +220,9 @@ function columnlistarea:CalculateSize()
|
||||
|
||||
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"))
|
||||
self.bar = true
|
||||
self:GetScrollBar().autoscroll = self.parent.autoscroll
|
||||
@ -219,7 +230,7 @@ function columnlistarea:CalculateSize()
|
||||
|
||||
else
|
||||
|
||||
if bar == true then
|
||||
if bar then
|
||||
self.internals[1]:Remove()
|
||||
self.bar = false
|
||||
self.offsety = 0
|
||||
@ -236,10 +247,10 @@ end
|
||||
function columnlistarea:RedoLayout()
|
||||
|
||||
local children = self.children
|
||||
local starty = 0
|
||||
local startx = 0
|
||||
local bar = self.bar
|
||||
local display = self.display
|
||||
local starty = 0
|
||||
local startx = 0
|
||||
local bar = self.bar
|
||||
local display = self.display
|
||||
|
||||
if #children > 0 then
|
||||
|
||||
@ -250,7 +261,7 @@ function columnlistarea:RedoLayout()
|
||||
v.staticx = startx
|
||||
v.staticy = starty
|
||||
|
||||
if bar == true then
|
||||
if bar then
|
||||
v:SetWidth(self.width - self.internals[1].width)
|
||||
self.internals[1].staticx = self.width - self.internals[1].width
|
||||
self.internals[1].height = self.height
|
||||
@ -276,7 +287,7 @@ function columnlistarea:AddRow(data)
|
||||
|
||||
local row = columnlistrow:new(self, data)
|
||||
|
||||
local colorindex = self.rowcolorindex
|
||||
local colorindex = self.rowcolorindex
|
||||
local colorindexmax = self.rowcolorindexmax
|
||||
|
||||
if colorindex == colorindexmax then
|
||||
@ -298,16 +309,15 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function columnlistarea:GetScrollBar()
|
||||
|
||||
if self.bar ~= false then
|
||||
|
||||
local scrollbar = self.internals[1].internals[1].internals[1]
|
||||
local internals = self.internals
|
||||
|
||||
if self.bar then
|
||||
local scrollbody = internals[1]
|
||||
local scrollarea = scrollbody.internals[1]
|
||||
local scrollbar = scrollarea.internals[1]
|
||||
return scrollbar
|
||||
|
||||
else
|
||||
|
||||
return false
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
@ -321,8 +331,9 @@ function columnlistarea:Sort(column, desc)
|
||||
self.rowcolorindex = 1
|
||||
|
||||
local colorindexmax = self.rowcolorindexmax
|
||||
local children = self.children
|
||||
|
||||
table.sort(self.children, function(a, b)
|
||||
table.sort(children, function(a, b)
|
||||
if desc then
|
||||
return a.columndata[column] < b.columndata[column]
|
||||
else
|
||||
@ -330,7 +341,7 @@ function columnlistarea:Sort(column, desc)
|
||||
end
|
||||
end)
|
||||
|
||||
for k, v in ipairs(self.children) do
|
||||
for k, v in ipairs(children) do
|
||||
|
||||
local colorindex = self.rowcolorindex
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
--[[------------------------------------------------
|
||||
-- Löve Frames --
|
||||
-- Copyright 2012 Kenny Shields --
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- columnlistrow object
|
||||
-- columnlistrow class
|
||||
columnlistrow = class("columnlistrow", base)
|
||||
columnlistrow:include(loveframes.templates.default)
|
||||
|
||||
@ -13,17 +13,16 @@ columnlistrow:include(loveframes.templates.default)
|
||||
--]]---------------------------------------------------------
|
||||
function columnlistrow:initialize(parent, data)
|
||||
|
||||
self.type = "columnlistrow"
|
||||
self.parent = parent
|
||||
self.colorindex = self.parent.rowcolorindex
|
||||
self.font = loveframes.basicfontsmall
|
||||
self.textcolor = {0, 0, 0, 255}
|
||||
self.width = 80
|
||||
self.height = 25
|
||||
self.textx = 5
|
||||
self.texty = 5
|
||||
self.internal = true
|
||||
self.columndata = data
|
||||
self.type = "columnlistrow"
|
||||
self.parent = parent
|
||||
self.colorindex = self.parent.rowcolorindex
|
||||
self.font = loveframes.basicfontsmall
|
||||
self.width = 80
|
||||
self.height = 25
|
||||
self.textx = 5
|
||||
self.texty = 5
|
||||
self.internal = true
|
||||
self.columndata = data
|
||||
|
||||
end
|
||||
|
||||
@ -33,25 +32,29 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function columnlistrow:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
if not visible then
|
||||
if not alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local parent = self.parent
|
||||
local base = loveframes.base
|
||||
local update = self.Update
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if self.parent ~= loveframes.base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
if parent ~= base then
|
||||
self.x = parent.x + self.staticx
|
||||
self.y = parent.y + self.staticy
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
@ -68,32 +71,24 @@ function columnlistrow:draw()
|
||||
return
|
||||
end
|
||||
|
||||
local cwidth, cheight = self:GetParent():GetParent():GetColumnSize()
|
||||
local x = self.textx
|
||||
local textcolor = self.textcolor
|
||||
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.DrawColumnListRow or skins[defaultskin].DrawColumnListRow
|
||||
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.DrawColumnListRow or skins[defaultskin].DrawColumnListRow
|
||||
local draw = self.Draw
|
||||
local drawcount = loveframes.drawcount
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
loveframes.drawcount = drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
if draw then
|
||||
draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
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
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -102,11 +97,11 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function columnlistrow:mousepressed(x, y, button)
|
||||
|
||||
if self.visible == false then
|
||||
if not self.visible then
|
||||
return
|
||||
end
|
||||
|
||||
if self.hover == true and button == "l" then
|
||||
if self.hover and button == "l" then
|
||||
|
||||
local baseparent = self:GetBaseParent()
|
||||
|
||||
@ -124,17 +119,18 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function columnlistrow:mousereleased(x, y, button)
|
||||
|
||||
if self.visible == false then
|
||||
if not self.visible then
|
||||
return
|
||||
end
|
||||
|
||||
if self.hover == true and button == "l" then
|
||||
if self.hover and button == "l" then
|
||||
|
||||
local parent1 = self:GetParent()
|
||||
local parent2 = parent1:GetParent()
|
||||
local parent1 = self:GetParent()
|
||||
local parent2 = parent1:GetParent()
|
||||
local onrowclicked = parent2.OnRowClicked
|
||||
|
||||
if parent2.OnRowClicked then
|
||||
parent2.OnRowClicked(parent2, self, self.columndata)
|
||||
if onrowclicked then
|
||||
onrowclicked(parent2, self, self.columndata)
|
||||
end
|
||||
|
||||
end
|
||||
@ -152,6 +148,26 @@ function columnlistrow:SetTextPos(x, y)
|
||||
|
||||
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)
|
||||
- desc: sets the object's font
|
||||
@ -183,11 +199,11 @@ function columnlistrow:GetColorIndex()
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetTextColor(color)
|
||||
- desc: sets the object's text color
|
||||
- func: GetColumnData()
|
||||
- desc: gets the object's column data
|
||||
--]]---------------------------------------------------------
|
||||
function columnlistrow:SetTextColor(color)
|
||||
function columnlistrow:GetColumnData()
|
||||
|
||||
self.textcolor = color
|
||||
return self.columndata
|
||||
|
||||
end
|
@ -1,9 +1,9 @@
|
||||
--[[------------------------------------------------
|
||||
-- Löve Frames --
|
||||
-- Copyright 2012 Kenny Shields --
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- columnlistheader object
|
||||
-- columnlistheader class
|
||||
columnlistheader = class("columnlistheader", base)
|
||||
columnlistheader:include(loveframes.templates.default)
|
||||
|
||||
@ -13,17 +13,17 @@ columnlistheader:include(loveframes.templates.default)
|
||||
--]]---------------------------------------------------------
|
||||
function columnlistheader:initialize(name, parent)
|
||||
|
||||
self.type = "columnlistheader"
|
||||
self.parent = parent
|
||||
self.name = name
|
||||
self.width = 80
|
||||
self.height = 16
|
||||
self.hover = false
|
||||
self.down = false
|
||||
self.clickable = true
|
||||
self.enabled = true
|
||||
self.type = "columnlistheader"
|
||||
self.parent = parent
|
||||
self.name = name
|
||||
self.width = 80
|
||||
self.height = 16
|
||||
self.hover = false
|
||||
self.down = false
|
||||
self.clickable = true
|
||||
self.enabled = true
|
||||
self.descending = true
|
||||
self.internal = true
|
||||
self.internal = true
|
||||
|
||||
table.insert(parent.children, self)
|
||||
|
||||
@ -52,37 +52,41 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function columnlistheader:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
if not visible then
|
||||
if not alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local parent = self.parent
|
||||
local base = loveframes.base
|
||||
local update = self.Update
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
if self.hover == false then
|
||||
if not self.hover then
|
||||
self.down = false
|
||||
elseif self.hover == true then
|
||||
else
|
||||
if loveframes.hoverobject == self then
|
||||
self.down = true
|
||||
end
|
||||
end
|
||||
|
||||
if self.down == false and loveframes.hoverobject == self then
|
||||
if self.down and loveframes.hoverobject == self then
|
||||
self.hover = true
|
||||
end
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if self.parent ~= loveframes.base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
if parent ~= base then
|
||||
self.x = parent.x + self.staticx
|
||||
self.y = parent.y + self.staticy
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
@ -95,22 +99,24 @@ function columnlistheader:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
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.DrawColumnListHeader or skins[defaultskin].DrawColumnListHeader
|
||||
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.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
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
if draw then
|
||||
draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
@ -123,7 +129,7 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
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()
|
||||
|
||||
@ -144,21 +150,32 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function columnlistheader:mousereleased(x, y, button)
|
||||
|
||||
if self.visible == false then
|
||||
if not self.visible then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
local down = self.down
|
||||
local hover = self.hover
|
||||
local down = self.down
|
||||
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 enabled == true then
|
||||
self.OnClick(self, x, y)
|
||||
if hover and down and clickable and button == "l" then
|
||||
if enabled then
|
||||
onclick(self, x, y)
|
||||
end
|
||||
end
|
||||
|
||||
self.down = false
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetName()
|
||||
- desc: gets the object's name
|
||||
--]]---------------------------------------------------------
|
||||
function columnlistheader:GetName()
|
||||
|
||||
return self.name
|
||||
|
||||
end
|
161
objects/internal/linenumberspanel.lua
Normal file
161
objects/internal/linenumberspanel.lua
Normal 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
|
@ -1,6 +1,6 @@
|
||||
--[[------------------------------------------------
|
||||
-- Löve Frames --
|
||||
-- Copyright 2012 Kenny Shields --
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- modalbackground class
|
||||
@ -13,14 +13,14 @@ modalbackground:include(loveframes.templates.default)
|
||||
--]]---------------------------------------------------------
|
||||
function modalbackground:initialize(object)
|
||||
|
||||
self.type = "modalbackground"
|
||||
self.width = love.graphics.getWidth()
|
||||
self.height = love.graphics.getHeight()
|
||||
self.x = 0
|
||||
self.y = 0
|
||||
self.internal = true
|
||||
self.parent = loveframes.base
|
||||
self.object = object
|
||||
self.type = "modalbackground"
|
||||
self.width = love.graphics.getWidth()
|
||||
self.height = love.graphics.getHeight()
|
||||
self.x = 0
|
||||
self.y = 0
|
||||
self.internal = true
|
||||
self.parent = loveframes.base
|
||||
self.object = object
|
||||
|
||||
table.insert(loveframes.base.children, self)
|
||||
|
||||
@ -36,24 +36,25 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function modalbackground:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
if not visible then
|
||||
if not alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local object = self.object
|
||||
local update = self.Update
|
||||
|
||||
if object:IsActive() == false then
|
||||
if not object:IsActive() then
|
||||
self:Remove()
|
||||
loveframes.modalobject = false
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
@ -64,22 +65,24 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function modalbackground:draw()
|
||||
|
||||
if self.visible == false then
|
||||
if not self.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.DrawModalBackground or skins[defaultskin].DrawModalBackground
|
||||
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.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
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
if draw then
|
||||
draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
|
@ -1,6 +1,6 @@
|
||||
--[[------------------------------------------------
|
||||
-- Löve Frames --
|
||||
-- Copyright 2012 Kenny Shields --
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- multichoicelist class
|
||||
@ -13,25 +13,25 @@ multichoicelist:include(loveframes.templates.default)
|
||||
--]]---------------------------------------------------------
|
||||
function multichoicelist:initialize(object)
|
||||
|
||||
self.type = "multichoice-list"
|
||||
self.parent = loveframes.base
|
||||
self.list = object
|
||||
self.x = object.x
|
||||
self.y = object.y + self.list.height
|
||||
self.width = self.list.width
|
||||
self.height = 0
|
||||
self.clickx = 0
|
||||
self.clicky = 0
|
||||
self.padding = self.list.listpadding
|
||||
self.spacing = self.list.listspacing
|
||||
self.offsety = 0
|
||||
self.offsetx = 0
|
||||
self.extra = 0
|
||||
self.canremove = false
|
||||
self.internal = true
|
||||
self.vbar = false
|
||||
self.children = {}
|
||||
self.internals = {}
|
||||
self.type = "multichoice-list"
|
||||
self.parent = loveframes.base
|
||||
self.list = object
|
||||
self.x = object.x
|
||||
self.y = object.y + self.list.height
|
||||
self.width = self.list.width
|
||||
self.height = 0
|
||||
self.clickx = 0
|
||||
self.clicky = 0
|
||||
self.padding = self.list.listpadding
|
||||
self.spacing = self.list.listspacing
|
||||
self.offsety = 0
|
||||
self.offsetx = 0
|
||||
self.extra = 0
|
||||
self.canremove = false
|
||||
self.internal = true
|
||||
self.vbar = false
|
||||
self.children = {}
|
||||
self.internals = {}
|
||||
|
||||
for k, v in ipairs(object.choices) do
|
||||
local row = multichoicerow:new()
|
||||
@ -49,24 +49,29 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function multichoicelist:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
if not visible then
|
||||
if not alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local width = love.graphics.getWidth()
|
||||
local height = love.graphics.getHeight()
|
||||
local x, y = love.mouse.getPosition()
|
||||
local selfcol = loveframes.util.BoundingBox(x, self.x, y, self.y, 1, self.width, 1, self.height)
|
||||
local width = love.graphics.getWidth()
|
||||
local height = love.graphics.getHeight()
|
||||
local x, y = love.mouse.getPosition()
|
||||
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
|
||||
if self.parent ~= loveframes.base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
if parent ~= base then
|
||||
self.x = parent.x + self.staticx
|
||||
self.y = parent.y + self.staticy
|
||||
end
|
||||
|
||||
if self.x < 0 then
|
||||
@ -85,19 +90,19 @@ function multichoicelist:update(dt)
|
||||
self.y = height - self.height
|
||||
end
|
||||
|
||||
for k, v in ipairs(self.internals) do
|
||||
for k, v in ipairs(internals) do
|
||||
v:update(dt)
|
||||
end
|
||||
|
||||
for k, v in ipairs(self.children) do
|
||||
for k, v in ipairs(children) do
|
||||
v:update(dt)
|
||||
v:SetClickBounds(self.x, self.y, self.width, self.height)
|
||||
v.y = (v.parent.y + v.staticy) - self.offsety
|
||||
v.x = (v.parent.x + v.staticx) - self.offsetx
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
if upadte then
|
||||
upadte(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
@ -108,44 +113,52 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
if draw then
|
||||
draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
|
||||
for k, v in ipairs(self.internals) do
|
||||
for k, v in ipairs(internals) do
|
||||
v:draw()
|
||||
end
|
||||
|
||||
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)
|
||||
if col == true then
|
||||
if col then
|
||||
v:draw()
|
||||
end
|
||||
end
|
||||
|
||||
love.graphics.setStencil()
|
||||
|
||||
if self.Draw == nil and skin.DrawOverMultiChoiceList then
|
||||
skin.DrawOverMultiChoiceList(self)
|
||||
if not draw then
|
||||
drawoverfunc(self)
|
||||
end
|
||||
|
||||
end
|
||||
@ -156,32 +169,36 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function multichoicelist:mousepressed(x, y, button)
|
||||
|
||||
if self.visible == false then
|
||||
local visible = self.visible
|
||||
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
local selfcol = loveframes.util.BoundingBox(x, self.x, y, self.y, 1, self.width, 1, self.height)
|
||||
local toplist = self:IsTopList()
|
||||
local selfcol = loveframes.util.BoundingBox(x, self.x, y, self.y, 1, self.width, 1, self.height)
|
||||
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()
|
||||
end
|
||||
|
||||
if self.vbar == true and toplist == true then
|
||||
if self.vbar and toplist 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
|
||||
self.internals[1].internals[1].internals[1]:Scroll(5)
|
||||
internals[1].internals[1].internals[1]:Scroll(5)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
for k, v in ipairs(self.internals) do
|
||||
for k, v in ipairs(internals) do
|
||||
v:mousepressed(x, y, button)
|
||||
end
|
||||
|
||||
for k, v in ipairs(self.children) do
|
||||
for k, v in ipairs(children) do
|
||||
v:mousepressed(x, y, button)
|
||||
end
|
||||
|
||||
@ -193,17 +210,22 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function multichoicelist:mousereleased(x, y, button)
|
||||
|
||||
if self.visible == false then
|
||||
local visible = self.visible
|
||||
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
local internals = self.internals
|
||||
local children = self.children
|
||||
|
||||
self.canremove = true
|
||||
|
||||
for k, v in ipairs(self.internals) do
|
||||
for k, v in ipairs(internals) do
|
||||
v:mousereleased(x, y, button)
|
||||
end
|
||||
|
||||
for k, v in ipairs(self.children) do
|
||||
for k, v in ipairs(children) do
|
||||
v:mousereleased(x, y, button)
|
||||
end
|
||||
|
||||
@ -234,10 +256,12 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
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
|
||||
table.remove(self.children, k)
|
||||
table.remove(children, k)
|
||||
end
|
||||
|
||||
end
|
||||
@ -267,14 +291,15 @@ function multichoicelist:CalculateSize()
|
||||
self.height = love.graphics.getHeight()
|
||||
end
|
||||
|
||||
local numitems = #self.children
|
||||
local height = self.height
|
||||
local padding = self.padding
|
||||
local spacing = self.spacing
|
||||
local numitems = #self.children
|
||||
local height = self.height
|
||||
local padding = self.padding
|
||||
local spacing = self.spacing
|
||||
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
|
||||
end
|
||||
|
||||
@ -284,7 +309,7 @@ function multichoicelist:CalculateSize()
|
||||
|
||||
self.extra = self.itemheight - height
|
||||
|
||||
if vbar == false then
|
||||
if not vbar then
|
||||
local scroll = scrollbody:new(self, "vertical")
|
||||
table.insert(self.internals, scroll)
|
||||
self.vbar = true
|
||||
@ -292,7 +317,7 @@ function multichoicelist:CalculateSize()
|
||||
|
||||
else
|
||||
|
||||
if vbar == true then
|
||||
if vbar then
|
||||
self.internals[1]:Remove()
|
||||
self.vbar = false
|
||||
self.offsety = 0
|
||||
@ -309,10 +334,10 @@ end
|
||||
function multichoicelist:RedoLayout()
|
||||
|
||||
local children = self.children
|
||||
local padding = self.padding
|
||||
local spacing = self.spacing
|
||||
local starty = padding
|
||||
local vbar = self.vbar
|
||||
local padding = self.padding
|
||||
local spacing = self.spacing
|
||||
local starty = padding
|
||||
local vbar = self.vbar
|
||||
|
||||
if #children > 0 then
|
||||
|
||||
@ -321,12 +346,12 @@ function multichoicelist:RedoLayout()
|
||||
v.staticx = padding
|
||||
v.staticy = starty
|
||||
|
||||
if vbar == true then
|
||||
v.width = (self.width - self.internals[1].width) - padding*2
|
||||
if vbar then
|
||||
v.width = (self.width - self.internals[1].width) - padding * 2
|
||||
self.internals[1].staticx = self.width - self.internals[1].width
|
||||
self.internals[1].height = self.height
|
||||
else
|
||||
v.width = self.width - padding*2
|
||||
v.width = self.width - padding * 2
|
||||
end
|
||||
|
||||
starty = starty + v.height
|
||||
|
@ -1,6 +1,6 @@
|
||||
--[[------------------------------------------------
|
||||
-- Löve Frames --
|
||||
-- Copyright 2012 Kenny Shields --
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- multichoicerow class
|
||||
@ -13,14 +13,14 @@ multichoicerow:include(loveframes.templates.default)
|
||||
--]]---------------------------------------------------------
|
||||
function multichoicerow:initialize()
|
||||
|
||||
self.type = "multichoice-row"
|
||||
self.text = ""
|
||||
self.width = 50
|
||||
self.height = 25
|
||||
self.hover = false
|
||||
self.internal = true
|
||||
self.down = false
|
||||
self.canclick = false
|
||||
self.type = "multichoice-row"
|
||||
self.text = ""
|
||||
self.width = 50
|
||||
self.height = 25
|
||||
self.hover = false
|
||||
self.internal = true
|
||||
self.down = false
|
||||
self.canclick = false
|
||||
|
||||
end
|
||||
|
||||
@ -30,37 +30,41 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function multichoicerow:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
if not visible then
|
||||
if not alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local parent = self.parent
|
||||
local base = loveframes.base
|
||||
local update = self.Update
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
if self.hover == false then
|
||||
if not self.hover then
|
||||
self.down = false
|
||||
elseif self.hover == true then
|
||||
else
|
||||
if loveframes.hoverobject == self then
|
||||
self.down = true
|
||||
end
|
||||
end
|
||||
|
||||
if self.down == false and loveframes.hoverobject == self then
|
||||
if not self.down and loveframes.hoverobject == self then
|
||||
self.hover = true
|
||||
end
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if self.parent ~= loveframes.base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
if parent ~= base then
|
||||
self.x = parent.x + self.staticx
|
||||
self.y = parent.y + self.staticy
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
@ -73,22 +77,24 @@ function multichoicerow:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
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.DrawMultiChoiceRow or skins[defaultskin].DrawMultiChoiceRow
|
||||
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.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
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
if draw then
|
||||
draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
@ -101,11 +107,15 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function multichoicerow:mousepressed(x, y, button)
|
||||
|
||||
if self.visible == false then
|
||||
local visible = self.visible
|
||||
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
if self.hover == true and button == "l" then
|
||||
local hover = self.hover
|
||||
|
||||
if hover and button == "l" then
|
||||
|
||||
self.down = true
|
||||
loveframes.hoverobject = self
|
||||
@ -120,12 +130,16 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function multichoicerow:mousereleased(x, y, button)
|
||||
|
||||
if self.visible == false then
|
||||
local visible = self.visible
|
||||
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
if self.hover == true and self.down == true and self.canclick == true and button == "l" then
|
||||
self.parent.list:SelectChoice(self.text)
|
||||
local text = self.text
|
||||
|
||||
if self.hover and self.down and self.canclick and button == "l" then
|
||||
self.parent.list:SelectChoice(text)
|
||||
end
|
||||
|
||||
self.down = false
|
||||
@ -142,3 +156,13 @@ function multichoicerow:SetText(text)
|
||||
self.text = text
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetText()
|
||||
- desc: gets the object's text
|
||||
--]]---------------------------------------------------------
|
||||
function multichoicerow:GetText()
|
||||
|
||||
return self.text
|
||||
|
||||
end
|
@ -1,9 +1,9 @@
|
||||
--[[------------------------------------------------
|
||||
-- Löve Frames --
|
||||
-- Copyright 2012 Kenny Shields --
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- scrollbar class
|
||||
-- scrollarea class
|
||||
scrollarea = class("scrollarea", base)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -12,16 +12,16 @@ scrollarea = class("scrollarea", base)
|
||||
--]]---------------------------------------------------------
|
||||
function scrollarea:initialize(parent, bartype)
|
||||
|
||||
self.type = "scroll-area"
|
||||
self.bartype = bartype
|
||||
self.parent = parent
|
||||
self.x = 0
|
||||
self.y = 0
|
||||
self.scrolldelay = 0
|
||||
self.delayamount = 0.05
|
||||
self.down = false
|
||||
self.internal = true
|
||||
self.internals = {}
|
||||
self.type = "scroll-area"
|
||||
self.bartype = bartype
|
||||
self.parent = parent
|
||||
self.x = 0
|
||||
self.y = 0
|
||||
self.scrolldelay = 0
|
||||
self.delayamount = 0.05
|
||||
self.down = false
|
||||
self.internal = true
|
||||
self.internals = {}
|
||||
|
||||
table.insert(self.internals, scrollbar:new(self, bartype))
|
||||
|
||||
@ -33,36 +33,40 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function scrollarea:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
if not visible then
|
||||
if not alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local parent = self.parent
|
||||
local base = loveframes.base
|
||||
local update = self.Update
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if self.parent ~= loveframes.base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
if parent ~= base then
|
||||
self.x = parent.x + self.staticx
|
||||
self.y = parent.y + self.staticy
|
||||
end
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
local parent = self.parent
|
||||
local pinternals = parent.internals
|
||||
local button = pinternals[2]
|
||||
local bartype = self.bartype
|
||||
local time = love.timer.getTime()
|
||||
local x, y = love.mouse.getPosition()
|
||||
local listo = parent.parent
|
||||
local down = self.down
|
||||
local parent = self.parent
|
||||
local pinternals = parent.internals
|
||||
local button = pinternals[2]
|
||||
local bartype = self.bartype
|
||||
local time = love.timer.getTime()
|
||||
local x, y = love.mouse.getPosition()
|
||||
local listo = parent.parent
|
||||
local down = self.down
|
||||
local scrolldelay = self.scrolldelay
|
||||
local delayamount = self.delayamount
|
||||
local internals = self.internals
|
||||
local bar = internals[1]
|
||||
local hover = self.hover
|
||||
local internals = self.internals
|
||||
local bar = internals[1]
|
||||
local hover = self.hover
|
||||
|
||||
if button then
|
||||
|
||||
@ -80,16 +84,16 @@ function scrollarea:update(dt)
|
||||
|
||||
end
|
||||
|
||||
if down == true then
|
||||
if down then
|
||||
if scrolldelay < time then
|
||||
self.scrolldelay = time + delayamount
|
||||
if listo.display == "vertical" then
|
||||
if self.bartype == "vertical" then
|
||||
if y > bar.y then
|
||||
bar:Scroll(bar.height)
|
||||
else
|
||||
bar:Scroll(-bar.height)
|
||||
end
|
||||
elseif listo.display == "horizontal" then
|
||||
elseif self.bartype == "horizontal" then
|
||||
if x > bar.x then
|
||||
bar:Scroll(bar.width)
|
||||
else
|
||||
@ -97,7 +101,7 @@ function scrollarea:update(dt)
|
||||
end
|
||||
end
|
||||
end
|
||||
if hover == false then
|
||||
if not hover then
|
||||
self.down = false
|
||||
end
|
||||
end
|
||||
@ -106,8 +110,8 @@ function scrollarea:update(dt)
|
||||
v:update(dt)
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
@ -120,23 +124,25 @@ function scrollarea:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
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.DrawScrollArea or skins[defaultskin].DrawScrollArea
|
||||
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.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
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
if draw then
|
||||
draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
@ -155,18 +161,18 @@ function scrollarea:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
local listo = self.parent.parent
|
||||
local time = love.timer.getTime()
|
||||
local internals = self.internals
|
||||
local bar = internals[1]
|
||||
local hover = self.hover
|
||||
local listo = self.parent.parent
|
||||
local time = love.timer.getTime()
|
||||
local internals = self.internals
|
||||
local bar = internals[1]
|
||||
local hover = self.hover
|
||||
local delayamount = self.delayamount
|
||||
|
||||
if hover == true and button == "l" then
|
||||
if hover and button == "l" then
|
||||
self.down = true
|
||||
self.scrolldelay = time + delayamount + 0.5
|
||||
|
||||
@ -176,13 +182,13 @@ function scrollarea:mousepressed(x, y, button)
|
||||
baseparent:MakeTop()
|
||||
end
|
||||
|
||||
if listo.display == "vertical" then
|
||||
if self.bartype == "vertical" then
|
||||
if y > self.internals[1].y then
|
||||
bar:Scroll(bar.height)
|
||||
else
|
||||
bar:Scroll(-bar.height)
|
||||
end
|
||||
elseif listo.display == "horizontal" then
|
||||
elseif self.bartype == "horizontal" then
|
||||
if x > bar.x then
|
||||
bar:Scroll(bar.width)
|
||||
else
|
||||
@ -208,7 +214,7 @@ function scrollarea:mousereleased(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
@ -223,3 +229,13 @@ function scrollarea:mousereleased(x, y, button)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetBarType()
|
||||
- desc: gets the object's bar type
|
||||
--]]---------------------------------------------------------
|
||||
function scrollarea:GetBarType()
|
||||
|
||||
return self.bartype
|
||||
|
||||
end
|
@ -1,6 +1,6 @@
|
||||
--[[------------------------------------------------
|
||||
-- Löve Frames --
|
||||
-- Copyright 2012 Kenny Shields --
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- scrollbar class
|
||||
@ -12,27 +12,27 @@ scrollbar = class("scrollbar", base)
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbar:initialize(parent, bartype)
|
||||
|
||||
self.type = "scrollbar"
|
||||
self.bartype = bartype
|
||||
self.parent = parent
|
||||
self.x = 0
|
||||
self.y = 0
|
||||
self.staticx = 0
|
||||
self.staticy = 0
|
||||
self.maxx = 0
|
||||
self.maxy = 0
|
||||
self.clickx = 0
|
||||
self.clicky = 0
|
||||
self.starty = 0
|
||||
self.lastwidth = 0
|
||||
self.lastheight = 0
|
||||
self.lastx = 0
|
||||
self.lasty = 0
|
||||
self.internal = true
|
||||
self.hover = false
|
||||
self.dragging = false
|
||||
self.autoscroll = false
|
||||
self.internal = true
|
||||
self.type = "scrollbar"
|
||||
self.bartype = bartype
|
||||
self.parent = parent
|
||||
self.x = 0
|
||||
self.y = 0
|
||||
self.staticx = 0
|
||||
self.staticy = 0
|
||||
self.maxx = 0
|
||||
self.maxy = 0
|
||||
self.clickx = 0
|
||||
self.clicky = 0
|
||||
self.starty = 0
|
||||
self.lastwidth = 0
|
||||
self.lastheight = 0
|
||||
self.lastx = 0
|
||||
self.lasty = 0
|
||||
self.internal = true
|
||||
self.hover = false
|
||||
self.dragging = false
|
||||
self.autoscroll = false
|
||||
self.internal = true
|
||||
|
||||
if self.bartype == "vertical" then
|
||||
self.width = self.parent.width
|
||||
@ -50,20 +50,20 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbar:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
if not visible then
|
||||
if not alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
local x, y = love.mouse.getPosition()
|
||||
local bartype = self.bartype
|
||||
local cols = {}
|
||||
local x, y = love.mouse.getPosition()
|
||||
local bartype = self.bartype
|
||||
local cols = {}
|
||||
local basecols = {}
|
||||
local dragging = self.dragging
|
||||
|
||||
@ -76,8 +76,9 @@ function scrollbar:update(dt)
|
||||
if bartype == "vertical" then
|
||||
|
||||
local parent = self.parent
|
||||
local listo = parent.parent.parent
|
||||
local listo = parent.parent.parent
|
||||
local height = parent.height * (listo.height/listo.itemheight)
|
||||
local update = self.Update
|
||||
|
||||
if height < 20 then
|
||||
self.height = 20
|
||||
@ -89,7 +90,7 @@ function scrollbar:update(dt)
|
||||
self.x = parent.x + parent.width - self.width
|
||||
self.y = parent.y + self.staticy
|
||||
|
||||
if dragging == true then
|
||||
if dragging then
|
||||
if self.staticy ~= self.lasty then
|
||||
if listo.OnScroll then
|
||||
listo.OnScroll(listo)
|
||||
@ -99,10 +100,10 @@ function scrollbar:update(dt)
|
||||
self.staticy = self.starty + (y - self.clicky)
|
||||
end
|
||||
|
||||
local space = (self.maxy - parent.y)
|
||||
local remaining = (0 + self.staticy)
|
||||
local percent = remaining/space
|
||||
local extra = listo.extra * percent
|
||||
local space = (self.maxy - parent.y)
|
||||
local remaining = (0 + self.staticy)
|
||||
local percent = remaining/space
|
||||
local extra = listo.extraheight * percent
|
||||
local autoscroll = self.autoscroll
|
||||
local lastheight = self.lastheight
|
||||
|
||||
@ -110,7 +111,7 @@ function scrollbar:update(dt)
|
||||
|
||||
if self.staticy > space then
|
||||
self.staticy = space
|
||||
listo.offsety = listo.extra
|
||||
listo.offsety = listo.extraheight
|
||||
end
|
||||
|
||||
if self.staticy < 0 then
|
||||
@ -118,8 +119,8 @@ function scrollbar:update(dt)
|
||||
listo.offsety = 0
|
||||
end
|
||||
|
||||
if autoscroll == true then
|
||||
if listo.itemheight ~= lastheight then
|
||||
if autoscroll then
|
||||
if listo.itemheight > lastheight then
|
||||
self.lastheight = listo.itemheight
|
||||
self:Scroll(self.maxy)
|
||||
end
|
||||
@ -127,11 +128,9 @@ function scrollbar:update(dt)
|
||||
|
||||
elseif bartype == "horizontal" then
|
||||
|
||||
self.lastwidth = self.width
|
||||
|
||||
local parent = self.parent
|
||||
local listo = self.parent.parent.parent
|
||||
local width = self.parent.width * (listo.width/listo.itemwidth)
|
||||
local listo = self.parent.parent.parent
|
||||
local width = self.parent.width * (listo.width/listo.itemwidth)
|
||||
|
||||
if width < 20 then
|
||||
self.width = 20
|
||||
@ -143,7 +142,7 @@ function scrollbar:update(dt)
|
||||
self.x = parent.x + self.staticx
|
||||
self.y = parent.y + self.staticy
|
||||
|
||||
if dragging == true then
|
||||
if dragging then
|
||||
if self.staticx ~= self.lastx then
|
||||
if listo.OnScroll then
|
||||
listo.OnScroll(listo)
|
||||
@ -153,18 +152,18 @@ function scrollbar:update(dt)
|
||||
self.staticx = self.startx + (x - self.clickx)
|
||||
end
|
||||
|
||||
local space = (self.maxx - parent.x)
|
||||
local remaining = (0 + self.staticx)
|
||||
local percent = remaining/space
|
||||
local extra = listo.extra * percent
|
||||
local space = (self.maxx - parent.x)
|
||||
local remaining = (0 + self.staticx)
|
||||
local percent = remaining/space
|
||||
local extra = listo.extrawidth * percent
|
||||
local autoscroll = self.autoscroll
|
||||
local lastwidth = self.lastwidth
|
||||
local lastwidth = self.lastwidth
|
||||
|
||||
listo.offsetx = 0 + extra
|
||||
|
||||
if self.staticx > space then
|
||||
self.staticx = space
|
||||
listo.offsetx = listo.extra
|
||||
listo.offsetx = listo.extrawidth
|
||||
end
|
||||
|
||||
if self.staticx < 0 then
|
||||
@ -172,17 +171,17 @@ function scrollbar:update(dt)
|
||||
listo.offsetx = 0
|
||||
end
|
||||
|
||||
if autoscroll == true then
|
||||
if self.width ~= lastwidth then
|
||||
self.width = self.width
|
||||
if autoscroll then
|
||||
if listo.itemwidth > lastwidth then
|
||||
self.lastwidth = listo.itemwidth
|
||||
self:Scroll(self.maxx)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
@ -195,22 +194,24 @@ function scrollbar:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
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.DrawScrollBar or skins[defaultskin].DrawScrollBar
|
||||
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.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
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
if draw then
|
||||
draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
@ -224,13 +225,13 @@ end
|
||||
function scrollbar:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
local hover = self.hover
|
||||
local hover = self.hover
|
||||
|
||||
if visible == false then
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
if hover == false then
|
||||
if not hover then
|
||||
return
|
||||
end
|
||||
|
||||
@ -242,7 +243,7 @@ function scrollbar:mousepressed(x, y, button)
|
||||
|
||||
local dragging = self.dragging
|
||||
|
||||
if dragging == false then
|
||||
if not dragging then
|
||||
|
||||
if button == "l" then
|
||||
|
||||
@ -267,11 +268,11 @@ function scrollbar:mousereleased(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
if self.dragging == true then
|
||||
if self.dragging then
|
||||
self.dragging = false
|
||||
end
|
||||
|
||||
@ -303,8 +304,9 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbar:Scroll(amount)
|
||||
|
||||
local bartype = self.bartype
|
||||
local listo = self.parent.parent.parent
|
||||
local bartype = self.bartype
|
||||
local listo = self.parent.parent.parent
|
||||
local onscroll = listo.OnScroll
|
||||
|
||||
if bartype == "vertical" then
|
||||
local newy = (self.y + amount)
|
||||
@ -328,8 +330,28 @@ function scrollbar:Scroll(amount)
|
||||
end
|
||||
end
|
||||
|
||||
if listo.OnScroll then
|
||||
listo.OnScroll(listo)
|
||||
if onscroll then
|
||||
onscroll(listo)
|
||||
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
|
@ -1,6 +1,6 @@
|
||||
--[[------------------------------------------------
|
||||
-- Löve Frames --
|
||||
-- Copyright 2012 Kenny Shields --
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- scrollbar class
|
||||
@ -12,24 +12,24 @@ scrollbody = class("scrollbody", base)
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbody:initialize(parent, bartype)
|
||||
|
||||
self.type = "scroll-body"
|
||||
self.bartype = bartype
|
||||
self.parent = parent
|
||||
self.x = 0
|
||||
self.y = 0
|
||||
self.internal = true
|
||||
self.internals = {}
|
||||
self.type = "scrollbody"
|
||||
self.bartype = bartype
|
||||
self.parent = parent
|
||||
self.x = 0
|
||||
self.y = 0
|
||||
self.internal = true
|
||||
self.internals = {}
|
||||
|
||||
if self.bartype == "vertical" then
|
||||
self.width = 16
|
||||
self.height = self.parent.height
|
||||
self.staticx = self.parent.width - self.width
|
||||
self.staticy = 0
|
||||
self.width = 16
|
||||
self.height = self.parent.height
|
||||
self.staticx = self.parent.width - self.width
|
||||
self.staticy = 0
|
||||
elseif self.bartype == "horizontal" then
|
||||
self.width = self.parent.width
|
||||
self.height = 16
|
||||
self.staticx = 0
|
||||
self.staticy = self.parent.height - self.height
|
||||
self.width = self.parent.width
|
||||
self.height = 16
|
||||
self.staticx = 0
|
||||
self.staticy = self.parent.height - self.height
|
||||
end
|
||||
|
||||
table.insert(self.internals, scrollarea:new(self, bartype))
|
||||
@ -38,22 +38,22 @@ function scrollbody:initialize(parent, bartype)
|
||||
|
||||
if self.bartype == "vertical" then
|
||||
|
||||
local upbutton = scrollbutton:new("up")
|
||||
upbutton.parent = self
|
||||
upbutton.Update = function(object, dt)
|
||||
upbutton.staticx = 0 + self.width - upbutton.width
|
||||
upbutton.staticy = 0
|
||||
if object.down == true and object.hover == true then
|
||||
local upbutton = scrollbutton:new("up")
|
||||
upbutton.parent = self
|
||||
upbutton.Update = function(object, dt)
|
||||
upbutton.staticx = 0 + self.width - upbutton.width
|
||||
upbutton.staticy = 0
|
||||
if object.down and object.hover then
|
||||
bar:Scroll(-0.10)
|
||||
end
|
||||
end
|
||||
|
||||
local downbutton = scrollbutton:new("down")
|
||||
downbutton.parent = self
|
||||
downbutton.Update = function(object, dt)
|
||||
downbutton.staticx = 0 + self.width - downbutton.width
|
||||
downbutton.staticy = 0 + self.height - downbutton.height
|
||||
if object.down == true and object.hover == true then
|
||||
local downbutton = scrollbutton:new("down")
|
||||
downbutton.parent = self
|
||||
downbutton.Update = function(object, dt)
|
||||
downbutton.staticx = 0 + self.width - downbutton.width
|
||||
downbutton.staticy = 0 + self.height - downbutton.height
|
||||
if object.down and object.hover then
|
||||
bar:Scroll(0.10)
|
||||
end
|
||||
end
|
||||
@ -63,22 +63,22 @@ function scrollbody:initialize(parent, bartype)
|
||||
|
||||
elseif self.bartype == "horizontal" then
|
||||
|
||||
local leftbutton = scrollbutton:new("left")
|
||||
leftbutton.parent = self
|
||||
leftbutton.Update = function(object, dt)
|
||||
leftbutton.staticx = 0
|
||||
leftbutton.staticy = 0
|
||||
if object.down == true and object.hover == true then
|
||||
local leftbutton = scrollbutton:new("left")
|
||||
leftbutton.parent = self
|
||||
leftbutton.Update = function(object, dt)
|
||||
leftbutton.staticx = 0
|
||||
leftbutton.staticy = 0
|
||||
if object.down and object.hover then
|
||||
bar:Scroll(-0.10)
|
||||
end
|
||||
end
|
||||
|
||||
local rightbutton = scrollbutton:new("right")
|
||||
rightbutton.parent = self
|
||||
rightbutton.Update = function(object, dt)
|
||||
rightbutton.staticx = 0 + self.width - rightbutton.width
|
||||
rightbutton.staticy = 0
|
||||
if object.down == true and object.hover == true then
|
||||
local rightbutton = scrollbutton:new("right")
|
||||
rightbutton.parent = self
|
||||
rightbutton.Update = function(object, dt)
|
||||
rightbutton.staticx = 0 + self.width - rightbutton.width
|
||||
rightbutton.staticy = 0
|
||||
if object.down and object.hover then
|
||||
bar:Scroll(0.10)
|
||||
end
|
||||
end
|
||||
@ -96,26 +96,34 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbody:update(dt)
|
||||
|
||||
if self.visible == false then
|
||||
if self.alwaysupdate == false then
|
||||
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 internals = self.internals
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if self.parent ~= loveframes.base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
if parent ~= base then
|
||||
self.x = parent.x + self.staticx
|
||||
self.y = parent.y + self.staticy
|
||||
end
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
for k, v in ipairs(self.internals) do
|
||||
for k, v in ipairs(internals) do
|
||||
v:update(dt)
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
@ -126,27 +134,32 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbody:draw()
|
||||
|
||||
if self.visible == false then
|
||||
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.DrawScrollBody or skins[defaultskin].DrawScrollBody
|
||||
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.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
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
if draw then
|
||||
draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
|
||||
for k, v in ipairs(self.internals) do
|
||||
for k, v in ipairs(internals) do
|
||||
v:draw()
|
||||
end
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
--[[------------------------------------------------
|
||||
-- Löve Frames --
|
||||
-- Copyright 2012 Kenny Shields --
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- scrollbutton clas
|
||||
@ -13,13 +13,13 @@ scrollbutton:include(loveframes.templates.default)
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbutton:initialize(scrolltype)
|
||||
|
||||
self.type = "scrollbutton"
|
||||
self.scrolltype = scrolltype
|
||||
self.width = 16
|
||||
self.height = 16
|
||||
self.down = false
|
||||
self.internal = true
|
||||
self.OnClick = function() end
|
||||
self.type = "scrollbutton"
|
||||
self.scrolltype = scrolltype
|
||||
self.width = 16
|
||||
self.height = 16
|
||||
self.down = false
|
||||
self.internal = true
|
||||
self.OnClick = function() end
|
||||
|
||||
end
|
||||
|
||||
@ -29,34 +29,42 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbutton:update(dt)
|
||||
|
||||
if self.visible == false then
|
||||
if self.alwaysupdate == false then
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if not visible then
|
||||
if not alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
elseif self.hover == true then
|
||||
else
|
||||
if loveframes.hoverobject == self then
|
||||
self.down = true
|
||||
end
|
||||
end
|
||||
|
||||
if self.down == false and loveframes.hoverobject == self then
|
||||
if not self.down and loveframes.hoverobject == self then
|
||||
self.hover = true
|
||||
end
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if self.parent ~= loveframes.base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
if parent ~= base then
|
||||
self.x = parent.x + self.staticx
|
||||
self.y = parent.y + self.staticy
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
@ -67,22 +75,26 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbutton:draw()
|
||||
|
||||
if self.visible == false then
|
||||
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.DrawScrollButton or skins[defaultskin].DrawScrollButton
|
||||
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.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
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
if draw then
|
||||
draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
@ -90,17 +102,20 @@ function scrollbutton:draw()
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousepressed(x, y, scrollbutton)
|
||||
- func: mousepressed(x, y, 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
|
||||
end
|
||||
|
||||
if self.hover == true then
|
||||
local hover = self.hover
|
||||
|
||||
if hover and button == "l" then
|
||||
|
||||
local baseparent = self:GetBaseParent()
|
||||
|
||||
@ -116,19 +131,25 @@ function scrollbutton:mousepressed(x, y, scrollbutton)
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousereleased(x, y, scrollbutton)
|
||||
- func: mousereleased(x, y, 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
|
||||
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
|
||||
self.OnClick(x, y, self)
|
||||
if hover and down then
|
||||
|
||||
if button == "l" then
|
||||
onclick(x, y, self)
|
||||
end
|
||||
|
||||
end
|
||||
@ -146,3 +167,14 @@ function scrollbutton:SetText(text)
|
||||
return
|
||||
|
||||
end
|
||||
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetScrollType()
|
||||
- desc: gets the object's scroll type
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbutton:GetScrollType()
|
||||
|
||||
return self.scrolltype
|
||||
|
||||
end
|
@ -1,9 +1,9 @@
|
||||
--[[------------------------------------------------
|
||||
-- Löve Frames --
|
||||
-- Copyright 2012 Kenny Shields --
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- closebutton clas
|
||||
-- sliderbutton class
|
||||
sliderbutton = class("sliderbutton", base)
|
||||
sliderbutton:include(loveframes.templates.default)
|
||||
|
||||
@ -13,20 +13,20 @@ sliderbutton:include(loveframes.templates.default)
|
||||
--]]---------------------------------------------------------
|
||||
function sliderbutton:initialize(parent)
|
||||
|
||||
self.type = "sliderbutton"
|
||||
self.width = 10
|
||||
self.height = 20
|
||||
self.staticx = 0
|
||||
self.staticy = 0
|
||||
self.startx = 0
|
||||
self.clickx = 0
|
||||
self.starty = 0
|
||||
self.clicky = 0
|
||||
self.intervals = true
|
||||
self.internal = true
|
||||
self.down = false
|
||||
self.dragging = false
|
||||
self.parent = parent
|
||||
self.type = "sliderbutton"
|
||||
self.width = 10
|
||||
self.height = 20
|
||||
self.staticx = 0
|
||||
self.staticy = 0
|
||||
self.startx = 0
|
||||
self.clickx = 0
|
||||
self.starty = 0
|
||||
self.clicky = 0
|
||||
self.intervals = true
|
||||
self.internal = true
|
||||
self.down = false
|
||||
self.dragging = false
|
||||
self.parent = parent
|
||||
|
||||
end
|
||||
|
||||
@ -36,49 +36,52 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function sliderbutton:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
if not visible then
|
||||
if not alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
local x, y = love.mouse.getPosition()
|
||||
local intervals = self.intervals
|
||||
local progress = 0
|
||||
local nvalue = 0
|
||||
local pvalue = self.parent.value
|
||||
local hover = self.hover
|
||||
local down = self.down
|
||||
local hoverobject = loveframes.hoverobject
|
||||
local parent = self.parent
|
||||
local slidetype = parent.slidetype
|
||||
local dragging = self.dragging
|
||||
local x, y = love.mouse.getPosition()
|
||||
local intervals = self.intervals
|
||||
local progress = 0
|
||||
local nvalue = 0
|
||||
local pvalue = self.parent.value
|
||||
local hover = self.hover
|
||||
local down = self.down
|
||||
local hoverobject = loveframes.hoverobject
|
||||
local parent = self.parent
|
||||
local slidetype = parent.slidetype
|
||||
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
|
||||
elseif hover == true then
|
||||
else
|
||||
if hoverobject == self then
|
||||
self.down = true
|
||||
end
|
||||
end
|
||||
|
||||
if down == false and hoverobject == self then
|
||||
if not down and hoverobject == self then
|
||||
self.hover = true
|
||||
end
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if self.parent ~= loveframes.base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
if parent ~= base then
|
||||
self.x = parent.x + self.staticx
|
||||
self.y = parent.y + self.staticy
|
||||
end
|
||||
|
||||
-- start calculations if the button is being dragged
|
||||
if dragging == true then
|
||||
if dragging then
|
||||
|
||||
-- calculations for horizontal sliders
|
||||
if slidetype == "horizontal" then
|
||||
@ -142,8 +145,8 @@ function sliderbutton:update(dt)
|
||||
end
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
@ -156,22 +159,24 @@ function sliderbutton:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
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.DrawSliderButton or skins[defaultskin].DrawSliderButton
|
||||
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.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
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
if draw then
|
||||
draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
@ -186,13 +191,13 @@ function sliderbutton:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
|
||||
if hover == true and button == "l" then
|
||||
if hover and button == "l" then
|
||||
|
||||
local baseparent = self:GetBaseParent()
|
||||
|
||||
@ -200,12 +205,12 @@ function sliderbutton:mousepressed(x, y, button)
|
||||
baseparent:MakeTop()
|
||||
end
|
||||
|
||||
self.down = true
|
||||
self.dragging = true
|
||||
self.startx = self.staticx
|
||||
self.clickx = x
|
||||
self.starty = self.staticy
|
||||
self.clicky = y
|
||||
self.down = true
|
||||
self.dragging = true
|
||||
self.startx = self.staticx
|
||||
self.clickx = x
|
||||
self.starty = self.staticy
|
||||
self.clicky = y
|
||||
loveframes.hoverobject = self
|
||||
|
||||
end
|
||||
@ -220,7 +225,7 @@ function sliderbutton:mousereleased(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
--[[------------------------------------------------
|
||||
-- Löve Frames --
|
||||
-- Copyright 2012 Kenny Shields --
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- tabbutton clas
|
||||
-- tabbutton class
|
||||
tabbutton = class("tabbutton", base)
|
||||
tabbutton:include(loveframes.templates.default)
|
||||
|
||||
@ -13,17 +13,17 @@ tabbutton:include(loveframes.templates.default)
|
||||
--]]---------------------------------------------------------
|
||||
function tabbutton:initialize(parent, text, tabnumber, tip, image)
|
||||
|
||||
self.type = "tabbutton"
|
||||
self.text = text
|
||||
self.tabnumber = tabnumber
|
||||
self.parent = parent
|
||||
self.staticx = 0
|
||||
self.staticy = 0
|
||||
self.width = 50
|
||||
self.height = 25
|
||||
self.internal = true
|
||||
self.down = false
|
||||
self.image = nil
|
||||
self.type = "tabbutton"
|
||||
self.text = text
|
||||
self.tabnumber = tabnumber
|
||||
self.parent = parent
|
||||
self.staticx = 0
|
||||
self.staticy = 0
|
||||
self.width = 50
|
||||
self.height = 25
|
||||
self.internal = true
|
||||
self.down = false
|
||||
self.image = nil
|
||||
|
||||
if tip then
|
||||
self.tooltip = tooltip:new(self, tip)
|
||||
@ -43,26 +43,30 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function tabbutton:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
if not visible then
|
||||
if not alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local parent = self.parent
|
||||
local base = loveframes.base
|
||||
local update = self.Update
|
||||
|
||||
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
|
||||
if self.parent ~= loveframes.base then
|
||||
if parent ~= base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
@ -73,25 +77,27 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function tabbutton:draw()
|
||||
|
||||
if self.visible == false then
|
||||
if not self.visible then
|
||||
return
|
||||
end
|
||||
|
||||
local font = love.graphics.getFont()
|
||||
local width = font:getWidth(self.text)
|
||||
local image = self.image
|
||||
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.DrawTabButton or skins[defaultskin].DrawTabButton
|
||||
local font = love.graphics.getFont()
|
||||
local width = font:getWidth(self.text)
|
||||
local image = self.image
|
||||
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.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
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
if draw then
|
||||
draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
@ -113,13 +119,13 @@ function tabbutton:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
|
||||
if hover == true and button == "l" then
|
||||
if hover and button == "l" then
|
||||
|
||||
local baseparent = self:GetBaseParent()
|
||||
|
||||
@ -142,15 +148,15 @@ function tabbutton:mousereleased(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
local parent = self.parent
|
||||
local hover = self.hover
|
||||
local parent = self.parent
|
||||
local tabnumber = self.tabnumber
|
||||
|
||||
if hover == true and button == "l" then
|
||||
if hover and button == "l" then
|
||||
|
||||
if button == "l" then
|
||||
parent:SwitchToTab(tabnumber)
|
||||
@ -172,6 +178,16 @@ function tabbutton:SetText(text)
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetText()
|
||||
- desc: gets the object's text
|
||||
--]]---------------------------------------------------------
|
||||
function tabbutton:GetText()
|
||||
|
||||
return self.text
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetImage(image)
|
||||
- desc: adds an image to the object
|
||||
@ -185,3 +201,23 @@ function tabbutton:SetImage(image)
|
||||
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
|
@ -1,6 +1,6 @@
|
||||
--[[------------------------------------------------
|
||||
-- Löve Frames --
|
||||
-- Copyright 2012 Kenny Shields --
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- tooltip clas
|
||||
@ -15,18 +15,18 @@ function tooltip:initialize(object, text, width)
|
||||
|
||||
local width = width or 0
|
||||
|
||||
self.type = "tooltip"
|
||||
self.parent = loveframes.base
|
||||
self.object = object or nil
|
||||
self.width = width or 0
|
||||
self.height = 0
|
||||
self.padding = 5
|
||||
self.xoffset = 10
|
||||
self.yoffset = -10
|
||||
self.internal = true
|
||||
self.show = false
|
||||
self.followcursor = true
|
||||
self.alwaysupdate = true
|
||||
self.type = "tooltip"
|
||||
self.parent = loveframes.base
|
||||
self.object = object or nil
|
||||
self.width = width or 0
|
||||
self.height = 0
|
||||
self.padding = 5
|
||||
self.xoffset = 10
|
||||
self.yoffset = -10
|
||||
self.internal = true
|
||||
self.show = false
|
||||
self.followcursor = true
|
||||
self.alwaysupdate = true
|
||||
|
||||
self.text = loveframes.Create("text")
|
||||
self.text:Remove()
|
||||
@ -45,22 +45,22 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function tooltip:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
if not visible then
|
||||
if not alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local text = self.text
|
||||
|
||||
self.width = text.width + self.padding*2
|
||||
self.height = text.height + self.padding*2
|
||||
|
||||
local object = self.object
|
||||
local text = self.text
|
||||
local object = self.object
|
||||
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
|
||||
|
||||
@ -69,17 +69,17 @@ function tooltip:update(dt)
|
||||
return
|
||||
end
|
||||
|
||||
local hover = object.hover
|
||||
local hover = object.hover
|
||||
local odraworder = object.draworder
|
||||
local ovisible = object.visible
|
||||
local ohover = object.hover
|
||||
|
||||
self.show = object.hover
|
||||
self.visible = self.show
|
||||
self.show = ohover
|
||||
self.visible = ovisible
|
||||
|
||||
local show = self.show
|
||||
|
||||
if show == true then
|
||||
if ohover and ovisible then
|
||||
local top = self:IsTopInternal()
|
||||
if self.followcursor == true then
|
||||
if self.followcursor then
|
||||
local x, y = love.mouse.getPosition()
|
||||
self.x = x + self.xoffset
|
||||
self.y = y - self.height + self.yoffset
|
||||
@ -88,7 +88,7 @@ function tooltip:update(dt)
|
||||
self.y = object.y - self.height + self.yoffset
|
||||
end
|
||||
|
||||
if top == false then
|
||||
if not top then
|
||||
self:MoveToTop()
|
||||
end
|
||||
|
||||
@ -99,7 +99,7 @@ function tooltip:update(dt)
|
||||
local baseparent = object:GetBaseParent()
|
||||
|
||||
if baseparent then
|
||||
if baseparent.removed and baseparent.removed == true then
|
||||
if baseparent.removed and baseparent.removed then
|
||||
self:Remove()
|
||||
end
|
||||
elseif object.removed then
|
||||
@ -110,8 +110,8 @@ function tooltip:update(dt)
|
||||
|
||||
text:update(dt)
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
@ -124,26 +124,28 @@ function tooltip:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
local show = self.show
|
||||
local text = self.text
|
||||
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.DrawToolTip or skins[defaultskin].DrawToolTip
|
||||
local show = self.show
|
||||
local text = self.text
|
||||
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.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
|
||||
|
||||
if show == true then
|
||||
if show then
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
if draw then
|
||||
draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
|
158
objects/list.lua
158
objects/list.lua
@ -1,6 +1,6 @@
|
||||
--[[------------------------------------------------
|
||||
-- Löve Frames --
|
||||
-- Copyright 2012 Kenny Shields --
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- list class
|
||||
@ -13,24 +13,25 @@ list:include(loveframes.templates.default)
|
||||
--]]---------------------------------------------------------
|
||||
function list:initialize()
|
||||
|
||||
self.type = "list"
|
||||
self.display = "vertical"
|
||||
self.width = 300
|
||||
self.height = 150
|
||||
self.clickx = 0
|
||||
self.clicky = 0
|
||||
self.padding = 0
|
||||
self.spacing = 0
|
||||
self.offsety = 0
|
||||
self.offsetx = 0
|
||||
self.extra = 0
|
||||
self.internal = false
|
||||
self.hbar = false
|
||||
self.vbar = false
|
||||
self.autoscroll = false
|
||||
self.internals = {}
|
||||
self.children = {}
|
||||
self.OnScroll = nil
|
||||
self.type = "list"
|
||||
self.display = "vertical"
|
||||
self.width = 300
|
||||
self.height = 150
|
||||
self.clickx = 0
|
||||
self.clicky = 0
|
||||
self.padding = 0
|
||||
self.spacing = 0
|
||||
self.offsety = 0
|
||||
self.offsetx = 0
|
||||
self.extrawidth = 0
|
||||
self.extraheight = 0
|
||||
self.internal = false
|
||||
self.hbar = false
|
||||
self.vbar = false
|
||||
self.autoscroll = false
|
||||
self.internals = {}
|
||||
self.children = {}
|
||||
self.OnScroll = nil
|
||||
|
||||
end
|
||||
|
||||
@ -43,18 +44,21 @@ function list:update(dt)
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
if not visible then
|
||||
if not alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local internals = self.internals
|
||||
local children = self.children
|
||||
local display = self.display
|
||||
local internals = self.internals
|
||||
local children = self.children
|
||||
local display = self.display
|
||||
local parent = self.parent
|
||||
local base = loveframes.base
|
||||
local update = self.Update
|
||||
|
||||
-- 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.y = self.parent.y + self.staticy
|
||||
end
|
||||
@ -80,8 +84,8 @@ function list:update(dt)
|
||||
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
@ -94,26 +98,29 @@ function list:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
local internals = self.internals
|
||||
local children = self.children
|
||||
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.DrawList or skins[defaultskin].DrawList
|
||||
local internals = self.internals
|
||||
local children = self.children
|
||||
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.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
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
if draw then
|
||||
draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
@ -133,8 +140,8 @@ function list:draw()
|
||||
v:draw()
|
||||
end
|
||||
|
||||
if self.Draw == nil then
|
||||
skin.DrawOverList(self)
|
||||
if not draw then
|
||||
drawoverfunc(self)
|
||||
end
|
||||
|
||||
end
|
||||
@ -147,7 +154,7 @@ function list:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
@ -158,7 +165,7 @@ function list:mousepressed(x, y, button)
|
||||
local children = self.children
|
||||
local internals = self.internals
|
||||
|
||||
if hover == true and button == "l" then
|
||||
if hover and button == "l" then
|
||||
|
||||
local baseparent = self:GetBaseParent()
|
||||
|
||||
@ -168,9 +175,9 @@ function list:mousepressed(x, y, button)
|
||||
|
||||
end
|
||||
|
||||
if vbar == true or hbar == true then
|
||||
if vbar or hbar then
|
||||
|
||||
if toplist == true then
|
||||
if toplist then
|
||||
|
||||
local bar = self:GetScrollBar()
|
||||
|
||||
@ -206,11 +213,14 @@ function list:AddItem(object)
|
||||
|
||||
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.parent = self
|
||||
|
||||
-- insert the item object into the list object's children table
|
||||
table.insert(children, object)
|
||||
|
||||
-- resize the list and redo it's layout
|
||||
self:CalculateSize()
|
||||
self:RedoLayout()
|
||||
|
||||
@ -259,9 +269,9 @@ function list:CalculateSize()
|
||||
|
||||
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)
|
||||
table.insert(internals, scrollbar)
|
||||
self.vbar = true
|
||||
@ -270,7 +280,7 @@ function list:CalculateSize()
|
||||
|
||||
else
|
||||
|
||||
if vbar == true then
|
||||
if vbar then
|
||||
local bar = internals[1]
|
||||
bar:Remove()
|
||||
self.vbar = false
|
||||
@ -291,9 +301,9 @@ function list:CalculateSize()
|
||||
|
||||
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)
|
||||
table.insert(internals, scrollbar)
|
||||
self.hbar = true
|
||||
@ -302,7 +312,7 @@ function list:CalculateSize()
|
||||
|
||||
else
|
||||
|
||||
if hbar == true then
|
||||
if hbar then
|
||||
local bar = internals[1]
|
||||
bar:Remove()
|
||||
self.hbar = false
|
||||
@ -342,17 +352,17 @@ function list:RedoLayout()
|
||||
v.staticy = starty
|
||||
v.lastheight = v.height
|
||||
|
||||
if vbar == true then
|
||||
if vbar then
|
||||
if v.width + padding > (self.width - self.internals[1].width) then
|
||||
v:SetWidth((self.width - self.internals[1].width) - (padding*2))
|
||||
end
|
||||
if v.retainsize == false then
|
||||
if not v.retainsize then
|
||||
v:SetWidth((self.width - self.internals[1].width) - (padding*2))
|
||||
end
|
||||
self.internals[1].staticx = self.width - self.internals[1].width
|
||||
self.internals[1].height = self.height
|
||||
else
|
||||
if v.retainsize == false then
|
||||
if not v.retainsize then
|
||||
v:SetWidth(self.width - (padding*2))
|
||||
end
|
||||
end
|
||||
@ -365,17 +375,17 @@ function list:RedoLayout()
|
||||
v.staticx = startx
|
||||
v.staticy = padding
|
||||
|
||||
if hbar == true then
|
||||
if hbar then
|
||||
if v.height + padding > (self.height - self.internals[1].height) then
|
||||
v:SetHeight((self.height - self.internals[1].height) - (padding*2))
|
||||
end
|
||||
if v.retainsize == false then
|
||||
if not v.retainsize then
|
||||
v:SetHeight((self.height - self.internals[1].height) - (padding*2))
|
||||
end
|
||||
self.internals[1].staticy = self.height - self.internals[1].height
|
||||
self.internals[1].width = self.width
|
||||
else
|
||||
if v.retainsize == false then
|
||||
if not v.retainsize then
|
||||
v:SetHeight(self.height - (padding*2))
|
||||
end
|
||||
end
|
||||
@ -400,13 +410,12 @@ function list:SetDisplayType(type)
|
||||
local children = self.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.vbar = false
|
||||
self.hbar = false
|
||||
self.offsetx = 0
|
||||
self.offsety = 0
|
||||
|
||||
if numchildren > 0 then
|
||||
self:CalculateSize()
|
||||
@ -516,11 +525,14 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function list:GetScrollBar()
|
||||
|
||||
local vbar = self.vbar
|
||||
local hbar = self.hbar
|
||||
local vbar = self.vbar
|
||||
local hbar = self.hbar
|
||||
local internals = self.internals
|
||||
|
||||
if vbar == true or hbar == true then
|
||||
local scrollbar = self.internals[1].internals[1].internals[1]
|
||||
if vbar or hbar then
|
||||
local scrollbody = internals[1]
|
||||
local scrollarea = scrollbody.internals[1]
|
||||
local scrollbar = scrollarea.internals[1]
|
||||
return scrollbar
|
||||
else
|
||||
return false
|
||||
@ -536,10 +548,12 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function list:SetAutoScroll(bool)
|
||||
|
||||
local scrollbar = self:GetScrollBar()
|
||||
|
||||
self.autoscroll = bool
|
||||
|
||||
if self:GetScrollBar() ~= false then
|
||||
self:GetScrollBar().autoscroll = bool
|
||||
if scrollbar then
|
||||
scrollbar.autoscroll = bool
|
||||
end
|
||||
|
||||
end
|
@ -1,9 +1,9 @@
|
||||
--[[------------------------------------------------
|
||||
-- Löve Frames --
|
||||
-- Copyright 2012 Kenny Shields --
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- progress bar class
|
||||
-- multichoice class
|
||||
multichoice = class("multichoice", base)
|
||||
multichoice:include(loveframes.templates.default)
|
||||
|
||||
@ -13,17 +13,17 @@ multichoice:include(loveframes.templates.default)
|
||||
--]]---------------------------------------------------------
|
||||
function multichoice:initialize()
|
||||
|
||||
self.type = "multichoice"
|
||||
self.choice = ""
|
||||
self.text = "Select an option"
|
||||
self.width = 200
|
||||
self.height = 25
|
||||
self.listpadding = 0
|
||||
self.listspacing = 0
|
||||
self.listheight = nil
|
||||
self.haslist = false
|
||||
self.internal = false
|
||||
self.choices = {}
|
||||
self.type = "multichoice"
|
||||
self.choice = ""
|
||||
self.text = "Select an option"
|
||||
self.width = 200
|
||||
self.height = 25
|
||||
self.listpadding = 0
|
||||
self.listspacing = 0
|
||||
self.haslist = false
|
||||
self.internal = false
|
||||
self.choices = {}
|
||||
self.listheight = nil
|
||||
|
||||
end
|
||||
|
||||
@ -33,25 +33,28 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function multichoice:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
if not visible then
|
||||
if not alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local parent = self.parent
|
||||
local update = self.Update
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if self.parent ~= nil then
|
||||
if parent then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
@ -64,22 +67,24 @@ function multichoice:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
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.DrawMultiChoice or skins[defaultskin].DrawMultiChoice
|
||||
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.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
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
if draw then
|
||||
draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
@ -94,14 +99,14 @@ function multichoice:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
local hover = self.hover
|
||||
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()
|
||||
|
||||
@ -125,7 +130,7 @@ function multichoice:mousereleased(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
@ -158,11 +163,13 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function multichoice:SelectChoice(choice)
|
||||
|
||||
local onchoiceselected = self.OnChoiceSelected
|
||||
|
||||
self.choice = choice
|
||||
self.list:Close()
|
||||
|
||||
if self.OnChoiceSelected then
|
||||
self.OnChoiceSelected(self, choice)
|
||||
if onchoiceselected then
|
||||
onchoiceselected(self, choice)
|
||||
end
|
||||
|
||||
end
|
||||
@ -216,3 +223,23 @@ function multichoice:GetChoice()
|
||||
return self.choice
|
||||
|
||||
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
|
@ -1,6 +1,6 @@
|
||||
--[[------------------------------------------------
|
||||
-- Löve Frames --
|
||||
-- Copyright 2012 Kenny Shields --
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- panel class
|
||||
@ -13,11 +13,11 @@ panel:include(loveframes.templates.default)
|
||||
--]]---------------------------------------------------------
|
||||
function panel:initialize()
|
||||
|
||||
self.type = "panel"
|
||||
self.width = 200
|
||||
self.height = 50
|
||||
self.internal = false
|
||||
self.children = {}
|
||||
self.type = "panel"
|
||||
self.width = 200
|
||||
self.height = 50
|
||||
self.internal = false
|
||||
self.children = {}
|
||||
|
||||
end
|
||||
|
||||
@ -30,16 +30,19 @@ function panel:update(dt)
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
if not visible then
|
||||
if not alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local children = self.children
|
||||
local parent = self.parent
|
||||
local base = loveframes.base
|
||||
local update = self.Update
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if 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.y = self.parent.y + self.staticy
|
||||
end
|
||||
@ -50,8 +53,8 @@ function panel:update(dt)
|
||||
v:update(dt)
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
@ -64,23 +67,25 @@ function panel:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
local children = self.children
|
||||
local skins = loveframes.skins.available
|
||||
local skinindex = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = skins[selfskin] or skins[skinindex]
|
||||
local drawfunc = skin.DrawPanel or skins[defaultskin].DrawPanel
|
||||
local children = self.children
|
||||
local skins = loveframes.skins.available
|
||||
local skinindex = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = skins[selfskin] or skins[skinindex]
|
||||
local drawfunc = skin.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
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
if draw then
|
||||
draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
@ -100,14 +105,14 @@ function panel:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
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()
|
||||
|
||||
@ -129,10 +134,10 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function panel:mousereleased(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
local visible = self.visible
|
||||
local children = self.children
|
||||
|
||||
if visible == false then
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
--[[------------------------------------------------
|
||||
-- Löve Frames --
|
||||
-- Copyright 2012 Kenny Shields --
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- progressbar class
|
||||
@ -13,21 +13,21 @@ progressbar:include(loveframes.templates.default)
|
||||
--]]---------------------------------------------------------
|
||||
function progressbar:initialize()
|
||||
|
||||
self.type = "progressbar"
|
||||
self.width = 100
|
||||
self.height = 25
|
||||
self.min = 0
|
||||
self.max = 10
|
||||
self.value = 0
|
||||
self.progress = 0
|
||||
self.lerprate = 1000
|
||||
self.lerpvalue = 0
|
||||
self.lerpto = 0
|
||||
self.lerpfrom = 0
|
||||
self.completed = false
|
||||
self.lerp = false
|
||||
self.internal = false
|
||||
self.OnComplete = nil
|
||||
self.type = "progressbar"
|
||||
self.width = 100
|
||||
self.height = 25
|
||||
self.min = 0
|
||||
self.max = 10
|
||||
self.value = 0
|
||||
self.barwidth = 0
|
||||
self.lerprate = 1000
|
||||
self.lerpvalue = 0
|
||||
self.lerpto = 0
|
||||
self.lerpfrom = 0
|
||||
self.completed = false
|
||||
self.lerp = false
|
||||
self.internal = false
|
||||
self.OnComplete = nil
|
||||
|
||||
end
|
||||
|
||||
@ -37,27 +37,31 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function progressbar:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
if not visible then
|
||||
if not alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local lerp = self.lerp
|
||||
local lerprate = self.lerprate
|
||||
local lerpvalue = self.lerpvalue
|
||||
local lerpto = self.lerpto
|
||||
local lerpfrom = self.lerpfrom
|
||||
local value = self.value
|
||||
local completed = self.completed
|
||||
local lerp = self.lerp
|
||||
local lerprate = self.lerprate
|
||||
local lerpvalue = self.lerpvalue
|
||||
local lerpto = self.lerpto
|
||||
local lerpfrom = self.lerpfrom
|
||||
local value = self.value
|
||||
local completed = self.completed
|
||||
local parent = self.parent
|
||||
local base = loveframes.base
|
||||
local update = self.Update
|
||||
local oncomplete = self.OnComplete
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
-- caclulate progress
|
||||
if lerp == true then
|
||||
-- caclulate barwidth
|
||||
if lerp then
|
||||
if lerpfrom < lerpto then
|
||||
if lerpvalue < lerpto then
|
||||
self.lerpvalue = lerpvalue + lerprate*dt
|
||||
@ -74,7 +78,7 @@ function progressbar:update(dt)
|
||||
self.lerpvalue = lerpto
|
||||
end
|
||||
|
||||
self.progress = self.lerpvalue/self.max * self.width
|
||||
self.barwidth = self.lerpvalue/self.max * self.width
|
||||
|
||||
-- min check
|
||||
if self.lerpvalue < self.min then
|
||||
@ -86,37 +90,34 @@ function progressbar:update(dt)
|
||||
self.lerpvalue = self.max
|
||||
end
|
||||
else
|
||||
self.progress = self.value/self.max * self.width
|
||||
self.barwidth = value/self.max * self.width
|
||||
|
||||
-- min check
|
||||
if self.value < self.min then
|
||||
-- min max check
|
||||
if value < self.min then
|
||||
self.value = self.min
|
||||
end
|
||||
|
||||
-- max check
|
||||
if self.value > self.max then
|
||||
elseif value > self.max then
|
||||
self.value = self.max
|
||||
end
|
||||
end
|
||||
|
||||
-- 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.y = self.parent.y + self.staticy
|
||||
end
|
||||
|
||||
-- completion check
|
||||
if completed == false then
|
||||
if not completed then
|
||||
if self.value >= self.max then
|
||||
self.completed = true
|
||||
if self.OnComplete then
|
||||
self.OnComplete(self)
|
||||
if oncomplete then
|
||||
oncomplete(self)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
@ -129,22 +130,24 @@ function progressbar:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
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.DrawProgressBar or skins[defaultskin].DrawProgressBar
|
||||
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.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
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
if draw then
|
||||
draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
@ -220,7 +223,7 @@ function progressbar:SetValue(value)
|
||||
|
||||
local lerp = self.lerp
|
||||
|
||||
if lerp == true then
|
||||
if lerp then
|
||||
self.lerpvalue = self.lerpvalue
|
||||
self.lerpto = value
|
||||
self.lerpfrom = self.lerpvalue
|
||||
@ -295,3 +298,13 @@ function progressbar:GetCompleted()
|
||||
return self.completed
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetBarWidth()
|
||||
- desc: gets the object's bar width
|
||||
--]]---------------------------------------------------------
|
||||
function progressbar:GetBarWidth()
|
||||
|
||||
return self.barwidth
|
||||
|
||||
end
|
@ -1,6 +1,6 @@
|
||||
--[[------------------------------------------------
|
||||
-- Löve Frames --
|
||||
-- Copyright 2012 Kenny Shields --
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- text clas
|
||||
@ -13,17 +13,17 @@ slider:include(loveframes.templates.default)
|
||||
--]]---------------------------------------------------------
|
||||
function slider:initialize()
|
||||
|
||||
self.type = "slider"
|
||||
self.text = "Slider"
|
||||
self.slidetype = "horizontal"
|
||||
self.width = 5
|
||||
self.height = 5
|
||||
self.max = 10
|
||||
self.min = 0
|
||||
self.value = 0
|
||||
self.decimals = 5
|
||||
self.internal = false
|
||||
self.internals = {}
|
||||
self.type = "slider"
|
||||
self.text = "Slider"
|
||||
self.slidetype = "horizontal"
|
||||
self.width = 5
|
||||
self.height = 5
|
||||
self.max = 10
|
||||
self.min = 0
|
||||
self.value = 0
|
||||
self.decimals = 5
|
||||
self.internal = false
|
||||
self.internals = {}
|
||||
self.OnValueChanged = nil
|
||||
|
||||
-- create the slider button
|
||||
@ -40,22 +40,25 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function slider:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
if not visible then
|
||||
if not alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local internals = self.internals
|
||||
local sliderbutton = internals[1]
|
||||
local parent = self.parent
|
||||
local base = loveframes.base
|
||||
local update = self.Update
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
-- 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.y = self.parent.y + self.staticy
|
||||
end
|
||||
@ -73,8 +76,8 @@ function slider:update(dt)
|
||||
v:update(dt)
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
@ -87,23 +90,25 @@ function slider:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
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.DrawSlider or skins[defaultskin].DrawSlider
|
||||
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.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
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
if draw then
|
||||
draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
@ -123,16 +128,18 @@ function slider:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
if not visible then
|
||||
return
|
||||
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
|
||||
|
||||
local xpos = x - self.x
|
||||
local button = self.internals[1]
|
||||
local button = internals[1]
|
||||
local baseparent = self:GetBaseParent()
|
||||
|
||||
if baseparent and baseparent.type == "frame" then
|
||||
@ -148,7 +155,7 @@ function slider:mousepressed(x, y, button)
|
||||
elseif self.slidetype == "vertical" then
|
||||
|
||||
local ypos = y - self.y
|
||||
local button = self.internals[1]
|
||||
local button = internals[1]
|
||||
local baseparent = self:GetBaseParent()
|
||||
|
||||
if baseparent and baseparent.type == "frame" then
|
||||
@ -166,7 +173,7 @@ function slider:mousepressed(x, y, button)
|
||||
end
|
||||
|
||||
|
||||
for k, v in ipairs(self.internals) do
|
||||
for k, v in ipairs(internals) do
|
||||
v:mousepressed(x, y, button)
|
||||
end
|
||||
|
||||
@ -186,28 +193,34 @@ function slider:SetValue(value)
|
||||
return
|
||||
end
|
||||
|
||||
local decimals = self.decimals
|
||||
local newval = loveframes.util.Round(value, decimals)
|
||||
local internals = self.internals
|
||||
local decimals = self.decimals
|
||||
local newval = loveframes.util.Round(value, decimals)
|
||||
local internals = self.internals
|
||||
local onvaluechanged = self.OnValueChanged
|
||||
|
||||
-- set the new value
|
||||
self.value = newval
|
||||
|
||||
-- slider button object
|
||||
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
|
||||
if self.slidetype == "horizontal" then
|
||||
local xpos = self.width * (( newval - self.min ) / (self.max - self.min))
|
||||
if slidetype == "horizontal" then
|
||||
local xpos = width * ((newval - min) / (max - min))
|
||||
sliderbutton:MoveToX(xpos)
|
||||
elseif self.slidetype == "vertical" then
|
||||
local ypos = self.height - self.height * (( newval - self.min ) / (self.max - self.min))
|
||||
elseif slidetype == "vertical" then
|
||||
local ypos = height - height * ((newval - min) / (max - min))
|
||||
sliderbutton:MoveToY(ypos)
|
||||
end
|
||||
|
||||
-- call OnValueChanged
|
||||
if self.OnValueChanged then
|
||||
self.OnValueChanged(self)
|
||||
if onvaluechanged then
|
||||
onvaluechanged(self)
|
||||
end
|
||||
|
||||
end
|
||||
@ -335,8 +348,8 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function slider:SetButtonSize(width, height)
|
||||
|
||||
local internals = self.internals
|
||||
local sliderbutton = self.internals[1]
|
||||
local internals = self.internals
|
||||
local sliderbutton = internals[1]
|
||||
|
||||
if sliderbutton then
|
||||
sliderbutton.width = width
|
||||
@ -351,8 +364,8 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function slider:GetButtonSize()
|
||||
|
||||
local internals = self.internals
|
||||
local sliderbutton = self.internals[1]
|
||||
local internals = self.internals
|
||||
local sliderbutton = internals[1]
|
||||
|
||||
if sliderbutton then
|
||||
return sliderbutton.width, sliderbutton.height
|
||||
@ -375,3 +388,13 @@ function slider:SetSlideType(slidetype)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetSlideType()
|
||||
- desc: gets the objects's slide type
|
||||
--]]---------------------------------------------------------
|
||||
function slider:GetSlideType()
|
||||
|
||||
return self.slidetype
|
||||
|
||||
end
|
157
objects/tabs.lua
157
objects/tabs.lua
@ -1,6 +1,6 @@
|
||||
--[[------------------------------------------------
|
||||
-- Löve Frames --
|
||||
-- Copyright 2012 Kenny Shields --
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- tabs class
|
||||
@ -13,22 +13,22 @@ tabs:include(loveframes.templates.default)
|
||||
--]]---------------------------------------------------------
|
||||
function tabs:initialize()
|
||||
|
||||
self.type = "tabs"
|
||||
self.width = 100
|
||||
self.height = 50
|
||||
self.clickx = 0
|
||||
self.clicky = 0
|
||||
self.offsetx = 0
|
||||
self.tab = 1
|
||||
self.tabnumber = 1
|
||||
self.padding = 5
|
||||
self.tabheight = 25
|
||||
self.autosize = true
|
||||
self.internal = false
|
||||
self.tooltipfont = loveframes.basicfontsmall
|
||||
self.tabs = {}
|
||||
self.internals = {}
|
||||
self.children = {}
|
||||
self.type = "tabs"
|
||||
self.width = 100
|
||||
self.height = 50
|
||||
self.clickx = 0
|
||||
self.clicky = 0
|
||||
self.offsetx = 0
|
||||
self.tab = 1
|
||||
self.tabnumber = 1
|
||||
self.padding = 5
|
||||
self.tabheight = 25
|
||||
self.autosize = true
|
||||
self.internal = false
|
||||
self.tooltipfont = loveframes.basicfontsmall
|
||||
self.tabs = {}
|
||||
self.internals = {}
|
||||
self.children = {}
|
||||
|
||||
end
|
||||
|
||||
@ -38,29 +38,32 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function tabs:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
if not visible then
|
||||
if not alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local x, y = love.mouse.getPosition()
|
||||
local tabheight = self.tabheight
|
||||
local padding = self.padding
|
||||
local autosize = self.autosize
|
||||
local tabheight = self.tabheight
|
||||
local padding = self.padding
|
||||
local autosize = self.autosize
|
||||
local children = self.children
|
||||
local numchildren = #children
|
||||
local internals = self.internals
|
||||
local tab = self.tab
|
||||
local x, y = love.mouse.getPosition()
|
||||
local tabheight = self.tabheight
|
||||
local padding = self.padding
|
||||
local autosize = self.autosize
|
||||
local tabheight = self.tabheight
|
||||
local padding = self.padding
|
||||
local autosize = self.autosize
|
||||
local children = self.children
|
||||
local numchildren = #children
|
||||
local internals = self.internals
|
||||
local tab = self.tab
|
||||
local parent = self.parent
|
||||
local base = loveframes.base
|
||||
local update = self.Update
|
||||
|
||||
-- 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.y = self.parent.y + self.staticy
|
||||
end
|
||||
@ -87,8 +90,8 @@ function tabs:update(dt)
|
||||
v:SetPos(padding, tabheight + padding)
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
@ -101,27 +104,29 @@ function tabs:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
local internals = self.internals
|
||||
local tabheight = self:GetHeightOfButtons()
|
||||
local stencilfunc = function() love.graphics.rectangle("fill", self.x, self.y, self.width, tabheight) end
|
||||
local stencil = love.graphics.newStencil(stencilfunc)
|
||||
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.DrawTabPanel or skins[defaultskin].DrawTabPanel
|
||||
local internals = self.internals
|
||||
local tabheight = self:GetHeightOfButtons()
|
||||
local stencilfunc = function() love.graphics.rectangle("fill", self.x, self.y, self.width, tabheight) end
|
||||
local stencil = love.graphics.newStencil(stencilfunc)
|
||||
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.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
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
if draw then
|
||||
draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
@ -148,18 +153,18 @@ function tabs:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
local children = self.children
|
||||
local numchildren = #children
|
||||
local tab = self.tab
|
||||
local internals = self.internals
|
||||
local children = self.children
|
||||
local numchildren = #children
|
||||
local tab = self.tab
|
||||
local internals = self.internals
|
||||
local numinternals = #internals
|
||||
local hover = self.hover
|
||||
local hover = self.hover
|
||||
|
||||
if hover == true then
|
||||
if hover then
|
||||
|
||||
if button == "l" then
|
||||
|
||||
@ -176,10 +181,10 @@ function tabs:mousepressed(x, y, button)
|
||||
if button == "wu" then
|
||||
|
||||
local buttonheight = self:GetHeightOfButtons()
|
||||
local col = loveframes.util.BoundingBox(self.x, x, self.y, y, self.width, 1, buttonheight, 1)
|
||||
local visible = internals[numinternals - 1]:GetVisible()
|
||||
local col = loveframes.util.BoundingBox(self.x, x, self.y, y, self.width, 1, buttonheight, 1)
|
||||
local visible = internals[numinternals - 1]:GetVisible()
|
||||
|
||||
if col == true and visible == true then
|
||||
if col and visible then
|
||||
self.offsetx = self.offsetx + 5
|
||||
if self.offsetx > 0 then
|
||||
self.offsetx = 0
|
||||
@ -191,10 +196,10 @@ function tabs:mousepressed(x, y, button)
|
||||
if button == "wd" then
|
||||
|
||||
local buttonheight = self:GetHeightOfButtons()
|
||||
local col = loveframes.util.BoundingBox(self.x, x, self.y, y, self.width, 1, buttonheight, 1)
|
||||
local visible = internals[numinternals]:GetVisible()
|
||||
local col = loveframes.util.BoundingBox(self.x, x, self.y, y, self.width, 1, buttonheight, 1)
|
||||
local visible = internals[numinternals]:GetVisible()
|
||||
|
||||
if col == true and visible == true then
|
||||
if col and visible then
|
||||
local bwidth = self:GetWidthOfButtons()
|
||||
if (self.offsetx + bwidth) < self.width then
|
||||
self.offsetx = bwidth - self.width
|
||||
@ -221,13 +226,13 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function tabs:mousereleased(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
local children = self.children
|
||||
local visible = self.visible
|
||||
local children = self.children
|
||||
local numchildren = #children
|
||||
local tab = self.tab
|
||||
local internals = self.internals
|
||||
local tab = self.tab
|
||||
local internals = self.internals
|
||||
|
||||
if visible == false then
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
@ -247,12 +252,12 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function tabs:AddTab(name, object, tip, image)
|
||||
|
||||
local tabheight = self.tabheight
|
||||
local padding = self.padding
|
||||
local autosize = self.autosize
|
||||
local tabheight = self.tabheight
|
||||
local padding = self.padding
|
||||
local autosize = self.autosize
|
||||
local retainsize = object.retainsize
|
||||
local tabnumber = self.tabnumber
|
||||
local internals = self.internals
|
||||
local tabnumber = self.tabnumber
|
||||
local internals = self.internals
|
||||
|
||||
object:Remove()
|
||||
object.parent = self
|
||||
@ -273,7 +278,7 @@ function tabs:AddTab(name, object, tip, image)
|
||||
|
||||
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)
|
||||
end
|
||||
|
||||
@ -348,7 +353,7 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function tabs:GetWidthOfButtons()
|
||||
|
||||
local width = 0
|
||||
local width = 0
|
||||
local internals = self.internals
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
@ -464,6 +469,6 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function tabs:GetTabNumber()
|
||||
|
||||
return self.tabnumber
|
||||
return self.tab
|
||||
|
||||
end
|
112
objects/text.lua
112
objects/text.lua
@ -1,6 +1,6 @@
|
||||
--[[------------------------------------------------
|
||||
-- Löve Frames --
|
||||
-- Copyright 2012 Kenny Shields --
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
--[[------------------------------------------------
|
||||
@ -17,16 +17,16 @@ text:include(loveframes.templates.default)
|
||||
--]]---------------------------------------------------------
|
||||
function text:initialize()
|
||||
|
||||
self.type = "text"
|
||||
self.text = ""
|
||||
self.font = loveframes.basicfont
|
||||
self.width = 5
|
||||
self.height = 5
|
||||
self.maxw = 0
|
||||
self.lines = 1
|
||||
self.text = {}
|
||||
self.original = {}
|
||||
self.internal = false
|
||||
self.type = "text"
|
||||
self.text = ""
|
||||
self.font = loveframes.basicfont
|
||||
self.width = 5
|
||||
self.height = 5
|
||||
self.maxw = 0
|
||||
self.lines = 1
|
||||
self.text = {}
|
||||
self.original = {}
|
||||
self.internal = false
|
||||
|
||||
end
|
||||
|
||||
@ -36,22 +36,26 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function text:update(dt)
|
||||
|
||||
if self.visible == false then
|
||||
if self.alwaysupdate == false then
|
||||
if not self.visible then
|
||||
if not self.alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local parent = self.parent
|
||||
local base = loveframes.base
|
||||
local update = self.Update
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
-- 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.y = self.parent.y + self.staticy
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
@ -62,22 +66,24 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function text:draw()
|
||||
|
||||
if self.visible == false then
|
||||
if not self.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.DrawText or skins[defaultskin].DrawText
|
||||
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.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
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
if draw then
|
||||
draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
@ -94,13 +100,13 @@ function text:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
|
||||
if hover == true and button == "l" then
|
||||
if hover and button == "l" then
|
||||
|
||||
local baseparent = self:GetBaseParent()
|
||||
|
||||
@ -118,9 +124,9 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function text:SetText(t)
|
||||
|
||||
local dtype = type(t)
|
||||
local maxw = self.maxw
|
||||
local font = self.font
|
||||
local dtype = type(t)
|
||||
local maxw = self.maxw
|
||||
local font = self.font
|
||||
local inserts = {}
|
||||
local tdata, prevcolor
|
||||
|
||||
@ -158,7 +164,7 @@ function text:SetText(t)
|
||||
v = v:gsub(string.char(9), " ")
|
||||
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
|
||||
table.insert(self.text, {color = prevcolor, text = j})
|
||||
@ -172,11 +178,11 @@ function text:SetText(t)
|
||||
|
||||
for k, v in ipairs(self.text) do
|
||||
|
||||
local data = v.text
|
||||
local data = v.text
|
||||
local width = font:getWidth(data)
|
||||
local curw = 0
|
||||
local new = ""
|
||||
local key = k
|
||||
local curw = 0
|
||||
local new = ""
|
||||
local key = k
|
||||
|
||||
if width > maxw then
|
||||
|
||||
@ -216,18 +222,18 @@ function text:SetText(t)
|
||||
table.insert(self.text, v.key, {color = v.color, text = v.text})
|
||||
end
|
||||
|
||||
local textdata = self.text
|
||||
local maxw = self.maxw
|
||||
local font = self.font
|
||||
local height = font:getHeight("a")
|
||||
local twidth = 0
|
||||
local drawx = 0
|
||||
local drawy = 0
|
||||
local lines = 0
|
||||
local totalwidth = 0
|
||||
local prevtextwidth
|
||||
local x = self.x
|
||||
local y = self.y
|
||||
local textdata = self.text
|
||||
local maxw = self.maxw
|
||||
local font = self.font
|
||||
local height = font:getHeight("a")
|
||||
local twidth = 0
|
||||
local drawx = 0
|
||||
local drawy = 0
|
||||
local lines = 0
|
||||
local totalwidth = 0
|
||||
local x = self.x
|
||||
local y = self.y
|
||||
local prevtextwidth = 0
|
||||
|
||||
for k, v in ipairs(textdata) do
|
||||
|
||||
@ -311,13 +317,13 @@ end
|
||||
function text:DrawText()
|
||||
|
||||
local textdata = self.text
|
||||
local font = self.font
|
||||
local x = self.x
|
||||
local y = self.y
|
||||
local font = self.font
|
||||
local x = self.x
|
||||
local y = self.y
|
||||
|
||||
for k, v in ipairs(textdata) do
|
||||
|
||||
local text = v.text
|
||||
local text = v.text
|
||||
local color = v.color
|
||||
|
||||
love.graphics.setFont(font)
|
||||
|
File diff suppressed because it is too large
Load Diff
12
readme.md
12
readme.md
@ -1,18 +1,18 @@
|
||||
# Löve Frames
|
||||
# Love Frames
|
||||
|
||||
## 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
|
||||
|
||||
Löve 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/
|
||||
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.txt or visit this web page: http://creativecommons.org/licenses/by-sa/3.0/
|
||||
|
||||
## Credits
|
||||
|
||||
Created by Nikolai Resokav
|
||||
Created by Kenny Shields
|
||||
|
||||
**Third Party Stuff**
|
||||
**Third Party Libraries**
|
||||
|
||||
- middleclass: kikito
|
12
skins.lua
12
skins.lua
@ -1,6 +1,6 @@
|
||||
--[[------------------------------------------------
|
||||
-- Löve Frames --
|
||||
-- Copyright 2012 Kenny Shields --
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
loveframes.skins = {}
|
||||
@ -17,11 +17,11 @@ function loveframes.skins.Register(skin)
|
||||
local images = loveframes.util.GetDirContents(dir .. "/images")
|
||||
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.")
|
||||
end
|
||||
|
||||
if author == "" or author == nil then
|
||||
if author == "" or not author then
|
||||
error("Could not register skin: Invalid or missing author data.")
|
||||
end
|
||||
|
||||
@ -29,11 +29,11 @@ function loveframes.skins.Register(skin)
|
||||
error("Could not register skin: Invalid or missing version data.")
|
||||
end
|
||||
|
||||
if namecheck ~= nil then
|
||||
if namecheck then
|
||||
error("Could not register skin: A skin with the name '" ..name.. "' already exists.")
|
||||
end
|
||||
|
||||
if dircheck == false then
|
||||
if not dircheck then
|
||||
error("Could not register skin: Could not find a directory for skin '" ..name.. "'.")
|
||||
end
|
||||
|
||||
|
1384
skins/Blue/skin.lua
1384
skins/Blue/skin.lua
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
||||
--[[------------------------------------------------
|
||||
-- Löve Frames --
|
||||
-- Copyright 2012 Kenny Shields --
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- templates
|
||||
|
139
third-party/middleclass.lua
vendored
Normal file
139
third-party/middleclass.lua
vendored
Normal 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
|
10
util.lua
10
util.lua
@ -1,6 +1,6 @@
|
||||
--[[------------------------------------------------
|
||||
-- Löve Frames --
|
||||
-- Copyright 2012 Kenny Shields --
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- util library
|
||||
@ -163,7 +163,7 @@ function loveframes.util.GetDirContents(dir, t)
|
||||
if isdir == true then
|
||||
table.insert(dirs, dir.. "/" ..v)
|
||||
else
|
||||
local parts = loveframes.util.SplitSring(v, "([.])")
|
||||
local parts = loveframes.util.SplitString(v, "([.])")
|
||||
local extension = parts[#parts]
|
||||
local name = restore(parts)
|
||||
table.insert(t, {path = dir, fullpath = dir.. "/" ..v, name = name, extension = extension})
|
||||
@ -195,11 +195,11 @@ function loveframes.util.Round(num, idp)
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SplitSring(string, pattern)
|
||||
- func: SplitString(string, pattern)
|
||||
- desc: splits a string into a table based on a given pattern
|
||||
- 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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user