Added time controls and nice clock face
This commit is contained in:
159
loveframes/objects/internal/closebutton.lua
Normal file
159
loveframes/objects/internal/closebutton.lua
Normal file
@ -0,0 +1,159 @@
|
||||
--[[------------------------------------------------
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012-2014 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
return function(loveframes)
|
||||
---------- module start ----------
|
||||
|
||||
-- closebutton class
|
||||
local newobject = loveframes.NewObject("closebutton", "loveframes_object_closebutton", true)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:initialize()
|
||||
|
||||
self.type = "closebutton"
|
||||
self.width = 16
|
||||
self.height = 16
|
||||
self.internal = true
|
||||
self.hover = false
|
||||
self.down = false
|
||||
self.autoposition = true
|
||||
self.OnClick = function() end
|
||||
|
||||
-- apply template properties to the object
|
||||
loveframes.ApplyTemplatesToObject(self)
|
||||
|
||||
self:SetDrawFunc()
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if not visible then
|
||||
if not alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
local hover = self.hover
|
||||
local down = self.down
|
||||
local downobject = loveframes.downobject
|
||||
local parent = self.parent
|
||||
local base = loveframes.base
|
||||
local update = self.Update
|
||||
|
||||
if not hover then
|
||||
self.down = false
|
||||
else
|
||||
if loveframes.downobject == self then
|
||||
self.down = true
|
||||
end
|
||||
end
|
||||
|
||||
if not down and downobject == self then
|
||||
self.hover = true
|
||||
end
|
||||
|
||||
if self.autoposition then
|
||||
self.staticx = self.parent.width - self.width - 4
|
||||
self.staticy = 4
|
||||
end
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if parent ~= base then
|
||||
self.x = parent.x + self.staticx
|
||||
self.y = parent.y + self.staticy
|
||||
end
|
||||
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousepressed(x, y, button)
|
||||
- desc: called when the player presses a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
|
||||
if hover and button == 1 then
|
||||
local baseparent = self:GetBaseParent()
|
||||
if baseparent and baseparent.type == "frame" then
|
||||
baseparent:MakeTop()
|
||||
end
|
||||
self.down = true
|
||||
loveframes.downobject = self
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousereleased(x, y, button)
|
||||
- desc: called when the player releases a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:mousereleased(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
local onclick = self.OnClick
|
||||
|
||||
if hover and self.down then
|
||||
if button == 1 then
|
||||
onclick(x, y, self)
|
||||
end
|
||||
end
|
||||
|
||||
self.down = false
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetAutoPosition(bool)
|
||||
- desc: sets whether or not the object should be
|
||||
positioned automatically
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:SetAutoPosition(bool)
|
||||
|
||||
self.autoposition = bool
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetAutoPosition()
|
||||
- desc: gets whether or not the object should be
|
||||
positioned automatically
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetAutoPosition()
|
||||
|
||||
return self.autoposition
|
||||
|
||||
end
|
||||
|
||||
---------- module end ----------
|
||||
end
|
469
loveframes/objects/internal/columnlist/columnlistarea.lua
Normal file
469
loveframes/objects/internal/columnlist/columnlistarea.lua
Normal file
@ -0,0 +1,469 @@
|
||||
--[[------------------------------------------------
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012-2014 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
return function(loveframes)
|
||||
---------- module start ----------
|
||||
|
||||
-- columnlistarea class
|
||||
local newobject = loveframes.NewObject("columnlistarea", "loveframes_object_columnlistarea", true)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: intializes the element
|
||||
--]]---------------------------------------------------------
|
||||
function newobject: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.extrawidth = 0
|
||||
self.extraheight = 0
|
||||
self.rowcolorindex = 1
|
||||
self.rowcolorindexmax = 2
|
||||
self.buttonscrollamount = parent.buttonscrollamount
|
||||
self.mousewheelscrollamount = parent.mousewheelscrollamount
|
||||
self.vbar = false
|
||||
self.hbar = false
|
||||
self.dtscrolling = parent.dtscrolling
|
||||
self.internal = true
|
||||
self.internals = {}
|
||||
self.children = {}
|
||||
|
||||
-- apply template properties to the object
|
||||
loveframes.ApplyTemplatesToObject(self)
|
||||
self:SetDrawFunc()
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:update(dt)
|
||||
|
||||
if not self.visible then
|
||||
if not self.alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local cwidth, cheight = self.parent:GetColumnSize()
|
||||
local parent = self.parent
|
||||
local update = self.Update
|
||||
local internals = self.internals
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if parent ~= loveframes.base then
|
||||
self.x = parent.x + self.staticx
|
||||
self.y = parent.y + self.staticy
|
||||
end
|
||||
|
||||
for k, v in ipairs(self.children) do
|
||||
local col = loveframes.BoundingBox(self.x, v.x, self.y, v.y, self.width, v.width, self.height, v.height)
|
||||
if col then
|
||||
v:update(dt)
|
||||
end
|
||||
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
|
||||
|
||||
for k, v in ipairs(self.internals) do
|
||||
v:update(dt)
|
||||
end
|
||||
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: draw()
|
||||
- desc: draws the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:draw()
|
||||
if loveframes.state ~= self.state then
|
||||
return
|
||||
end
|
||||
|
||||
if not self.visible then
|
||||
return
|
||||
end
|
||||
|
||||
local x = self.x
|
||||
local y = self.y
|
||||
local width = self.width
|
||||
local height = self.height
|
||||
local swidth = width
|
||||
local sheight = height
|
||||
|
||||
if self.vbar then
|
||||
swidth = swidth - self:GetVerticalScrollBody():GetWidth()
|
||||
end
|
||||
|
||||
if self.hbar then
|
||||
sheight = sheight - self:GetHorizontalScrollBody():GetHeight()
|
||||
end
|
||||
|
||||
local stencilfunc = function() love.graphics.rectangle("fill", x, y, swidth, sheight) end
|
||||
|
||||
self:SetDrawOrder()
|
||||
|
||||
local drawfunc = self.Draw or self.drawfunc
|
||||
if drawfunc then
|
||||
drawfunc(self)
|
||||
end
|
||||
|
||||
love.graphics.stencil(stencilfunc)
|
||||
love.graphics.setStencilTest("greater", 0)
|
||||
|
||||
local children = self.children
|
||||
if children then
|
||||
for k, v in ipairs(self.children) do
|
||||
local col = loveframes.BoundingBox(self.x, v.x, self.y, v.y, width, v.width, height, v.height)
|
||||
if col then
|
||||
v:draw()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
love.graphics.setStencilTest()
|
||||
|
||||
drawfunc = self.DrawOver or self.drawoverfunc
|
||||
if drawfunc then
|
||||
drawfunc(self)
|
||||
end
|
||||
|
||||
local internals = self.internals
|
||||
if internals then
|
||||
for k, v in ipairs(self.internals) do
|
||||
v:draw()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousepressed(x, y, button)
|
||||
- desc: called when the player presses a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:mousepressed(x, y, button)
|
||||
|
||||
local scrollamount = self.mousewheelscrollamount
|
||||
|
||||
if self.hover and button == 1 then
|
||||
local baseparent = self:GetBaseParent()
|
||||
if baseparent and baseparent.type == "frame" then
|
||||
baseparent:MakeTop()
|
||||
end
|
||||
end
|
||||
|
||||
for k, v in ipairs(self.internals) do
|
||||
v:mousepressed(x, y, button)
|
||||
end
|
||||
|
||||
for k, v in ipairs(self.children) do
|
||||
v:mousepressed(x, y, button)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousereleased(x, y, button)
|
||||
- desc: called when the player releases a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:mousereleased(x, y, button)
|
||||
|
||||
local 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(children) do
|
||||
v:mousereleased(x, y, button)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: wheelmoved(x, y)
|
||||
- desc: called when the player moves a mouse wheel
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:wheelmoved(x, y)
|
||||
|
||||
local scrollamount = self.mousewheelscrollamount
|
||||
|
||||
-- FIXME: button is nil
|
||||
-- if self.hover and button == 1 then
|
||||
if self.hover then
|
||||
local baseparent = self:GetBaseParent()
|
||||
if baseparent and baseparent.type == "frame" then
|
||||
baseparent:MakeTop()
|
||||
end
|
||||
end
|
||||
|
||||
local bar = false
|
||||
if self.vbar and self.hbar then
|
||||
bar = self:GetVerticalScrollBody():GetScrollBar()
|
||||
elseif self.vbar and not self.hbar then
|
||||
bar = self:GetVerticalScrollBody():GetScrollBar()
|
||||
elseif not self.vbar and self.hbar then
|
||||
bar = self:GetHorizontalScrollBody():GetScrollBar()
|
||||
end
|
||||
|
||||
if self:IsTopList() and bar then
|
||||
if self.dtscrolling then
|
||||
local dt = love.timer.getDelta()
|
||||
bar:Scroll(-y * scrollamount * dt)
|
||||
else
|
||||
bar:Scroll(-y * scrollamount)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: CalculateSize()
|
||||
- desc: calculates the size of the object's children
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:CalculateSize()
|
||||
|
||||
local height = self.height
|
||||
local width = self.width
|
||||
local parent = self.parent
|
||||
local itemheight = parent.columnheight
|
||||
|
||||
for k, v in ipairs(self.children) do
|
||||
itemheight = itemheight + v.height
|
||||
end
|
||||
|
||||
self.itemheight = itemheight
|
||||
self.itemwidth = parent:GetTotalColumnWidth()
|
||||
|
||||
local hbarheight = 0
|
||||
local hbody = self:GetHorizontalScrollBody()
|
||||
if hbody then
|
||||
hbarheight = hbody.height
|
||||
end
|
||||
|
||||
if self.itemheight > (height - hbarheight) then
|
||||
if hbody then
|
||||
self.itemheight = self.itemheight + hbarheight
|
||||
end
|
||||
self.extraheight = self.itemheight - height
|
||||
if not self.vbar then
|
||||
local newbar = loveframes.objects["scrollbody"]:new(self, "vertical")
|
||||
table.insert(self.internals, newbar)
|
||||
self.vbar = true
|
||||
newbar:GetScrollBar().autoscroll = parent.autoscroll
|
||||
self.itemwidth = self.itemwidth + newbar.width
|
||||
self.extrawidth = self.itemwidth - width
|
||||
end
|
||||
else
|
||||
if self.vbar then
|
||||
self:GetVerticalScrollBody():Remove()
|
||||
self.vbar = false
|
||||
self.offsety = 0
|
||||
end
|
||||
end
|
||||
|
||||
local vbarwidth = 0
|
||||
local vbody = self:GetVerticalScrollBody()
|
||||
if vbody then
|
||||
vbarwidth = vbody.width
|
||||
end
|
||||
|
||||
if self.itemwidth > (width - vbarwidth) then
|
||||
if vbody then
|
||||
self.itemwidth = self.itemwidth + vbarwidth
|
||||
end
|
||||
self.extrawidth = self.itemwidth - width
|
||||
if not self.hbar then
|
||||
local newbar = loveframes.objects["scrollbody"]:new(self, "horizontal")
|
||||
table.insert(self.internals, newbar)
|
||||
self.hbar = true
|
||||
self.itemheight = self.itemheight + newbar.height
|
||||
self.extraheight = self.itemheight - height
|
||||
end
|
||||
else
|
||||
if self.hbar then
|
||||
local hbar = self:GetHorizontalScrollBody()
|
||||
hbar:Remove()
|
||||
self.itemheight = self.itemheight - hbar.height
|
||||
self.extraheight = self.itemheight - height
|
||||
self.hbar = false
|
||||
self.offsetx = 0
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: RedoLayout()
|
||||
- desc: used to redo the layour of the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:RedoLayout()
|
||||
|
||||
local starty = 0
|
||||
self.rowcolorindex = 1
|
||||
|
||||
for k, v in ipairs(self.children) do
|
||||
v:SetWidth(self.parent:GetTotalColumnWidth())
|
||||
v.staticx = 0
|
||||
v.staticy = starty
|
||||
if self.vbar then
|
||||
local vbody = self:GetVerticalScrollBody()
|
||||
vbody.staticx = self.width - vbody.width
|
||||
if self.hbar then
|
||||
vbody.height = self.height - self:GetHorizontalScrollBody().height
|
||||
else
|
||||
vbody.height = self.height
|
||||
end
|
||||
end
|
||||
if self.hbar then
|
||||
local hbody = self:GetHorizontalScrollBody()
|
||||
hbody.staticy = self.height - hbody.height
|
||||
if self.vbar then
|
||||
hbody.width = self.width - self:GetVerticalScrollBody().width
|
||||
else
|
||||
hbody.width = self.width
|
||||
end
|
||||
end
|
||||
starty = starty + v.height
|
||||
v.lastheight = v.height
|
||||
v.colorindex = self.rowcolorindex
|
||||
if self.rowcolorindex == self.rowcolorindexmax then
|
||||
self.rowcolorindex = 1
|
||||
else
|
||||
self.rowcolorindex = self.rowcolorindex + 1
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: AddRow(data)
|
||||
- desc: adds a row to the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:AddRow(data)
|
||||
|
||||
local colorindex = self.rowcolorindex
|
||||
|
||||
if colorindex == self.rowcolorindexmax then
|
||||
self.rowcolorindex = 1
|
||||
else
|
||||
self.rowcolorindex = colorindex + 1
|
||||
end
|
||||
|
||||
table.insert(self.children, loveframes.objects["columnlistrow"]:new(self, data))
|
||||
self:CalculateSize()
|
||||
self:RedoLayout()
|
||||
self.parent:PositionColumns()
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetScrollBar()
|
||||
- desc: gets the object's scroll bar
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetScrollBar()
|
||||
|
||||
if self.bar then
|
||||
return self.internals[1].internals[1].internals[1]
|
||||
else
|
||||
return false
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: Sort()
|
||||
- desc: sorts the object's children
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:Sort(column, desc)
|
||||
|
||||
local children = self.children
|
||||
self.rowcolorindex = 1
|
||||
|
||||
table.sort(children, function(a, b)
|
||||
if desc then
|
||||
return (tostring(a.columndata[column]) or a.columndata[column]) < (tostring(b.columndata[column]) or b.columndata[column])
|
||||
else
|
||||
return (tostring(a.columndata[column]) or a.columndata[column]) > (tostring(b.columndata[column]) or b.columndata[column])
|
||||
end
|
||||
end)
|
||||
|
||||
for k, v in ipairs(children) do
|
||||
local colorindex = self.rowcolorindex
|
||||
v.colorindex = colorindex
|
||||
if colorindex == self.rowcolorindexmax then
|
||||
self.rowcolorindex = 1
|
||||
else
|
||||
self.rowcolorindex = colorindex + 1
|
||||
end
|
||||
end
|
||||
|
||||
self:CalculateSize()
|
||||
self:RedoLayout()
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: Clear()
|
||||
- desc: removes all items from the object's list
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:Clear()
|
||||
|
||||
self.children = {}
|
||||
self:CalculateSize()
|
||||
self:RedoLayout()
|
||||
self.parent:PositionColumns()
|
||||
self.rowcolorindex = 1
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetVerticalScrollBody()
|
||||
- desc: gets the object's vertical scroll body
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetVerticalScrollBody()
|
||||
|
||||
for k, v in ipairs(self.internals) do
|
||||
if v.bartype == "vertical" then
|
||||
return v
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetHorizontalScrollBody()
|
||||
- desc: gets the object's horizontal scroll body
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetHorizontalScrollBody()
|
||||
|
||||
for k, v in ipairs(self.internals) do
|
||||
if v.bartype == "horizontal" then
|
||||
return v
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
|
||||
end
|
||||
|
||||
---------- module end ----------
|
||||
end
|
203
loveframes/objects/internal/columnlist/columnlistheader.lua
Normal file
203
loveframes/objects/internal/columnlist/columnlistheader.lua
Normal file
@ -0,0 +1,203 @@
|
||||
--[[------------------------------------------------
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012-2014 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
return function(loveframes)
|
||||
---------- module start ----------
|
||||
|
||||
-- columnlistheader class
|
||||
local newobject = loveframes.NewObject("columnlistheader", "loveframes_object_columnlistheader", true)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: intializes the element
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:initialize(name, parent)
|
||||
|
||||
self.type = "columnlistheader"
|
||||
self.parent = parent
|
||||
self.name = name
|
||||
self.state = parent.state
|
||||
self.width = parent.defaultcolumnwidth
|
||||
self.height = parent.columnheight
|
||||
self.columnid = 0
|
||||
self.hover = false
|
||||
self.down = false
|
||||
self.clickable = true
|
||||
self.enabled = true
|
||||
self.descending = true
|
||||
self.resizebox = nil
|
||||
self.internal = true
|
||||
|
||||
table.insert(parent.children, self)
|
||||
|
||||
local key = 0
|
||||
|
||||
for k, v in ipairs(parent.children) do
|
||||
if v == self then
|
||||
key = k
|
||||
end
|
||||
end
|
||||
|
||||
self.OnClick = function(object)
|
||||
local descending = object.descending
|
||||
local parent = object.parent
|
||||
local pinternals = parent.internals
|
||||
local list = pinternals[1]
|
||||
if descending then
|
||||
object.descending = false
|
||||
else
|
||||
object.descending = true
|
||||
end
|
||||
list:Sort(key, object.descending)
|
||||
end
|
||||
|
||||
-- apply template properties to the object
|
||||
loveframes.ApplyTemplatesToObject(self)
|
||||
self:SetDrawFunc()
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:update(dt)
|
||||
|
||||
if not self.visible then
|
||||
if not self.alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local update = self.Update
|
||||
local parent = self.parent
|
||||
local list = parent.internals[1]
|
||||
local vbody = list:GetVerticalScrollBody()
|
||||
local width = list.width
|
||||
if vbody then
|
||||
width = width - vbody.width
|
||||
end
|
||||
|
||||
self.clickbounds = {x = list.x, y = list.y, width = width, height = list.height}
|
||||
self:CheckHover()
|
||||
|
||||
if not self.hover then
|
||||
self.down = false
|
||||
else
|
||||
if loveframes.downobject == self then
|
||||
self.down = true
|
||||
end
|
||||
end
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if parent ~= loveframes.base then
|
||||
self.x = (parent.x + self.staticx) - parent.internals[1].offsetx
|
||||
self.y = parent.y + self.staticy
|
||||
end
|
||||
|
||||
local resizecolumn = parent.resizecolumn
|
||||
|
||||
if resizecolumn and resizecolumn == self then
|
||||
local x, y = love.mouse.getPosition()
|
||||
local start = false
|
||||
self.width = x - self.x
|
||||
if self.width < 20 then
|
||||
self.width = 20
|
||||
end
|
||||
parent.startadjustment = true
|
||||
parent.internals[1]:CalculateSize()
|
||||
parent.internals[1]:RedoLayout()
|
||||
elseif resizecolumn and parent.startadjustment then
|
||||
local header = parent.children[self.columnid - 1]
|
||||
self.staticx = header.staticx + header.width
|
||||
end
|
||||
|
||||
self.resizebox = {x = self.x + (self.width - 2), y = self.y, width = 4, height = self.height}
|
||||
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousepressed(x, y, button)
|
||||
- desc: called when the player presses a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:mousepressed(x, y, button)
|
||||
|
||||
if not self.parent.resizecolumn and self.parent.canresizecolumns then
|
||||
local box = self.resizebox
|
||||
local col = loveframes.BoundingBox(x, box.x, y, box.y, 1, box.width, 1, box.height)
|
||||
if col then
|
||||
self.resizing = true
|
||||
self.parent.resizecolumn = self
|
||||
end
|
||||
end
|
||||
|
||||
if self.hover and button == 1 then
|
||||
local baseparent = self:GetBaseParent()
|
||||
if baseparent and baseparent.type == "frame" and button == 1 then
|
||||
baseparent:MakeTop()
|
||||
end
|
||||
self.down = true
|
||||
loveframes.downobject = self
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousereleased(x, y, button)
|
||||
- desc: called when the player releases a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:mousereleased(x, y, button)
|
||||
|
||||
if not self.visible then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
local down = self.down
|
||||
local clickable = self.clickable
|
||||
local enabled = self.enabled
|
||||
local onclick = self.OnClick
|
||||
|
||||
if hover and down and clickable and button == 1 then
|
||||
if enabled then
|
||||
onclick(self, x, y)
|
||||
end
|
||||
end
|
||||
|
||||
local resizecolumn = self.parent.resizecolumn
|
||||
if resizecolumn and resizecolumn == self then
|
||||
self.parent.resizecolumn = nil
|
||||
end
|
||||
|
||||
self.down = false
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetName(name)
|
||||
- desc: sets the object's name
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:SetName(name)
|
||||
|
||||
self.name = name
|
||||
return self
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetName()
|
||||
- desc: gets the object's name
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetName()
|
||||
|
||||
return self.name
|
||||
|
||||
end
|
||||
|
||||
---------- module end ----------
|
||||
end
|
218
loveframes/objects/internal/columnlist/columnlistrow.lua
Normal file
218
loveframes/objects/internal/columnlist/columnlistrow.lua
Normal file
@ -0,0 +1,218 @@
|
||||
--[[------------------------------------------------
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012-2014 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
return function(loveframes)
|
||||
---------- module start ----------
|
||||
|
||||
-- columnlistrow class
|
||||
local newobject = loveframes.NewObject("columnlistrow", "loveframes_object_columnlistrow", true)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: intializes the element
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:initialize(parent, data)
|
||||
|
||||
self.type = "columnlistrow"
|
||||
self.parent = parent
|
||||
self.state = parent.state
|
||||
self.colorindex = self.parent.rowcolorindex
|
||||
self.font = loveframes.basicfontsmall
|
||||
self.width = 80
|
||||
self.height = 25
|
||||
self.textx = 5
|
||||
self.texty = 5
|
||||
self.selected = false
|
||||
self.internal = true
|
||||
self.columndata = {}
|
||||
|
||||
for k, v in ipairs(data) do
|
||||
self.columndata[k] = tostring(v)
|
||||
end
|
||||
|
||||
-- apply template properties to the object
|
||||
loveframes.ApplyTemplatesToObject(self)
|
||||
self:SetDrawFunc()
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:update(dt)
|
||||
|
||||
if not self.visible then
|
||||
if not self.alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local parent = self.parent
|
||||
local update = self.Update
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if parent ~= loveframes.base then
|
||||
self.x = parent.x + self.staticx
|
||||
self.y = parent.y + self.staticy
|
||||
end
|
||||
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousepressed(x, y, button)
|
||||
- desc: called when the player presses a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:mousepressed(x, y, button)
|
||||
|
||||
if not self.visible then
|
||||
return
|
||||
end
|
||||
|
||||
if self.hover and button == 1 then
|
||||
local baseparent = self:GetBaseParent()
|
||||
if baseparent and baseparent.type == "frame" then
|
||||
baseparent:MakeTop()
|
||||
end
|
||||
self:GetParent():GetParent():SelectRow(self, loveframes.IsCtrlDown())
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousereleased(x, y, button)
|
||||
- desc: called when the player releases a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:mousereleased(x, y, button)
|
||||
|
||||
if not self.visible then
|
||||
return
|
||||
end
|
||||
|
||||
if self.hover then
|
||||
local parent = self:GetParent():GetParent()
|
||||
if button == 1 then
|
||||
local onrowclicked = parent.OnRowClicked
|
||||
if onrowclicked then
|
||||
onrowclicked(parent, self, self.columndata)
|
||||
end
|
||||
elseif button == 2 then
|
||||
local onrowrightclicked = parent.OnRowRightClicked
|
||||
if onrowrightclicked then
|
||||
onrowrightclicked(parent, self, self.columndata)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetTextPos(x, y)
|
||||
- desc: sets the positions of the object's text
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:SetTextPos(x, y)
|
||||
|
||||
self.textx = x
|
||||
self.texty = y
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetTextX()
|
||||
- desc: gets the object's text x position
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetTextX()
|
||||
|
||||
return self.textx
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetTextY()
|
||||
- desc: gets the object's text y position
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetTextY()
|
||||
|
||||
return self.texty
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetFont(font)
|
||||
- desc: sets the object's font
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:SetFont(font)
|
||||
|
||||
self.font = font
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetFont()
|
||||
- desc: gets the object's font
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetFont()
|
||||
|
||||
return self.font
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetColorIndex()
|
||||
- desc: gets the object's color index
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetColorIndex()
|
||||
|
||||
return self.colorindex
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetColumnData(data)
|
||||
- desc: sets the object's column data
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:SetColumnData(data)
|
||||
|
||||
self.columndata = data
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetColumnData()
|
||||
- desc: gets the object's column data
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetColumnData()
|
||||
|
||||
return self.columndata
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetSelected(selected)
|
||||
- desc: sets whether or not the object is selected
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:SetSelected(selected)
|
||||
|
||||
self.selected = true
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetSelected()
|
||||
- desc: gets whether or not the object is selected
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetSelected()
|
||||
|
||||
return self.selected
|
||||
|
||||
end
|
||||
|
||||
---------- module end ----------
|
||||
end
|
161
loveframes/objects/internal/linenumberspanel.lua
Normal file
161
loveframes/objects/internal/linenumberspanel.lua
Normal file
@ -0,0 +1,161 @@
|
||||
--[[------------------------------------------------
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012-2014 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
return function(loveframes)
|
||||
---------- module start ----------
|
||||
|
||||
-- linenumberspanel class
|
||||
local newobject = loveframes.NewObject("linenumberspanel", "loveframes_object_linenumberspanel", true)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject: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
|
||||
|
||||
-- apply template properties to the object
|
||||
loveframes.ApplyTemplatesToObject(self)
|
||||
self:SetDrawFunc()
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the element
|
||||
--]]---------------------------------------------------------
|
||||
function newobject: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 newobject:draw()
|
||||
if loveframes.state ~= self.state then
|
||||
return
|
||||
end
|
||||
|
||||
if not self.visible then
|
||||
return
|
||||
end
|
||||
|
||||
local x = self.x
|
||||
local y = self.y
|
||||
local width = self.width
|
||||
local height = self.height
|
||||
local stencilfunc = function() love.graphics.rectangle("fill", self.parent.x, self.parent.y, width, height) end
|
||||
|
||||
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
|
||||
|
||||
self:SetDrawOrder()
|
||||
|
||||
love.graphics.stencil(stencilfunc)
|
||||
love.graphics.setStencilTest("greater", 0)
|
||||
|
||||
local drawfunc = self.Draw or self.drawfunc
|
||||
if drawfunc then
|
||||
drawfunc(self)
|
||||
end
|
||||
|
||||
love.graphics.setStencilTest()
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousepressed(x, y, button)
|
||||
- desc: called when the player presses a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
|
||||
if hover and button == 1 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 newobject: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 newobject:GetOffsetY()
|
||||
|
||||
return self.offsety
|
||||
|
||||
end
|
||||
|
||||
---------- module end ----------
|
||||
end
|
218
loveframes/objects/internal/menuoption.lua
Normal file
218
loveframes/objects/internal/menuoption.lua
Normal file
@ -0,0 +1,218 @@
|
||||
--[[------------------------------------------------
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012-2014 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
return function(loveframes)
|
||||
---------- module start ----------
|
||||
|
||||
-- menuoption object
|
||||
local newobject = loveframes.NewObject("menuoption", "loveframes_object_menuoption", true)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:initialize(parent, option_type, menu)
|
||||
|
||||
self.type = "menuoption"
|
||||
self.text = "Option"
|
||||
self.width = 100
|
||||
self.height = 25
|
||||
self.contentwidth = 0
|
||||
self.contentheight = 0
|
||||
self.parent = parent
|
||||
self.option_type = option_type or "option"
|
||||
self.menu = menu
|
||||
self.activated = false
|
||||
self.internal = true
|
||||
self.icon = false
|
||||
self.func = nil
|
||||
self:SetDrawFunc()
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:update(dt)
|
||||
|
||||
local state = loveframes.state
|
||||
local selfstate = self.state
|
||||
|
||||
if state ~= selfstate then
|
||||
return
|
||||
end
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if not visible then
|
||||
if not alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
local hover = self.hover
|
||||
local parent = self.parent
|
||||
local option_type = self.option_type
|
||||
local activated = self.activated
|
||||
local base = loveframes.base
|
||||
local update = self.Update
|
||||
|
||||
if option_type == "submenu_activator" then
|
||||
if hover and not activated then
|
||||
self.menu:SetVisible(true)
|
||||
self.menu:MoveToTop()
|
||||
self.activated = true
|
||||
elseif not hover and activated then
|
||||
local hoverobject = loveframes.hoverobject
|
||||
if hoverobject and hoverobject:GetBaseParent() == self.parent then
|
||||
self.menu:SetVisible(false)
|
||||
self.activated = false
|
||||
end
|
||||
elseif activated then
|
||||
local screen_width = love.graphics.getWidth()
|
||||
local screen_height = love.graphics.getHeight()
|
||||
local sx = self.x
|
||||
local sy = self.y
|
||||
local width = self.width
|
||||
local height = self.height
|
||||
local x1 = sx + width
|
||||
if x1 + self.menu.width <= screen_width then
|
||||
self.menu.x = x1
|
||||
else
|
||||
self.menu.x = sx - self.menu.width
|
||||
end
|
||||
if sy + self.menu.height <= screen_height then
|
||||
self.menu.y = sy
|
||||
else
|
||||
self.menu.y = (sy + height) - self.menu.height
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- 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 update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousepressed(x, y, button)
|
||||
- desc: called when the player presses a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:mousepressed(x, y, button)
|
||||
|
||||
local state = loveframes.state
|
||||
local selfstate = self.state
|
||||
|
||||
if state ~= selfstate then
|
||||
return
|
||||
end
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousereleased(x, y, button)
|
||||
- desc: called when the player releases a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:mousereleased(x, y, button)
|
||||
|
||||
local state = loveframes.state
|
||||
local selfstate = self.state
|
||||
|
||||
if state ~= selfstate then
|
||||
return
|
||||
end
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
local option_type = self.option_type
|
||||
if hover and option_type ~= "divider" and button == 1 then
|
||||
local func = self.func
|
||||
if func then
|
||||
local text = self.text
|
||||
func(self, text)
|
||||
end
|
||||
local basemenu = self.parent:GetBaseMenu()
|
||||
basemenu:SetVisible(false)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetText(text)
|
||||
- desc: sets the object's text
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:SetText(text)
|
||||
|
||||
self.text = text
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetText()
|
||||
- desc: gets the object's text
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetText()
|
||||
|
||||
return self.text
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetIcon(icon)
|
||||
- desc: sets the object's icon
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:SetIcon(icon)
|
||||
|
||||
if type(icon) == "string" then
|
||||
self.icon = love.graphics.newImage(icon)
|
||||
self.icon:setFilter("nearest", "nearest")
|
||||
elseif type(icon) == "userdata" then
|
||||
self.icon = icon
|
||||
end
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetIcon()
|
||||
- desc: gets the object's icon
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetIcon()
|
||||
|
||||
return self.icon
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetFunction(func)
|
||||
- desc: sets the object's function
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:SetFunction(func)
|
||||
|
||||
self.func = func
|
||||
|
||||
end
|
||||
|
||||
---------- module end ----------
|
||||
end
|
79
loveframes/objects/internal/modalbackground.lua
Normal file
79
loveframes/objects/internal/modalbackground.lua
Normal file
@ -0,0 +1,79 @@
|
||||
--[[------------------------------------------------
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012-2014 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
return function(loveframes)
|
||||
---------- module start ----------
|
||||
|
||||
-- modalbackground class
|
||||
local newobject = loveframes.NewObject("modalbackground", "loveframes_object_modalbackground", true)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject: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
|
||||
|
||||
table.insert(loveframes.base.children, self)
|
||||
|
||||
if self.object.type ~= "frame" then
|
||||
self:Remove()
|
||||
end
|
||||
|
||||
-- apply template properties to the object
|
||||
loveframes.ApplyTemplatesToObject(self)
|
||||
self:SetDrawFunc()
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the element
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if not visible then
|
||||
if not alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local object = self.object
|
||||
local update = self.Update
|
||||
local base = loveframes.base
|
||||
local basechildren = base.children
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
if #basechildren > 1 then
|
||||
if basechildren[#basechildren - 1] ~= self then
|
||||
self:Remove()
|
||||
table.insert(basechildren, self)
|
||||
end
|
||||
end
|
||||
|
||||
if not object:IsActive() then
|
||||
self:Remove()
|
||||
loveframes.modalobject = false
|
||||
end
|
||||
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
---------- module end ----------
|
||||
end
|
420
loveframes/objects/internal/multichoice/multichoicelist.lua
Normal file
420
loveframes/objects/internal/multichoice/multichoicelist.lua
Normal file
@ -0,0 +1,420 @@
|
||||
--[[------------------------------------------------
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012-2014 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
return function(loveframes)
|
||||
---------- module start ----------
|
||||
|
||||
-- multichoicelist class
|
||||
local newobject = loveframes.NewObject("multichoicelist", "loveframes_object_multichoicelist", true)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:initialize(object)
|
||||
|
||||
self.type = "multichoicelist"
|
||||
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.buttonscrollamount = object.buttonscrollamount
|
||||
self.mousewheelscrollamount = object.mousewheelscrollamount
|
||||
self.offsety = 0
|
||||
self.offsetx = 0
|
||||
self.extrawidth = 0
|
||||
self.extraheight = 0
|
||||
self.canremove = false
|
||||
self.dtscrolling = self.list.dtscrolling
|
||||
self.internal = true
|
||||
self.vbar = false
|
||||
self.children = {}
|
||||
self.internals = {}
|
||||
|
||||
for k, v in ipairs(object.choices) do
|
||||
local row = loveframes.objects["multichoicerow"]:new()
|
||||
row:SetText(v)
|
||||
self:AddItem(row)
|
||||
end
|
||||
|
||||
table.insert(loveframes.base.internals, self)
|
||||
|
||||
-- apply template properties to the object
|
||||
loveframes.ApplyTemplatesToObject(self)
|
||||
self:SetDrawFunc()
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:update(dt)
|
||||
|
||||
local state = loveframes.state
|
||||
local selfstate = self.state
|
||||
|
||||
if state ~= selfstate then
|
||||
return
|
||||
end
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if not visible then
|
||||
if not alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local width = love.graphics.getWidth()
|
||||
local height = love.graphics.getHeight()
|
||||
local x, y = love.mouse.getPosition()
|
||||
local selfcol = loveframes.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 parent ~= base then
|
||||
self.x = parent.x + self.staticx
|
||||
self.y = parent.y + self.staticy
|
||||
end
|
||||
|
||||
if self.x < 0 then
|
||||
self.x = 0
|
||||
end
|
||||
|
||||
if self.x + self.width > width then
|
||||
self.x = width - self.width
|
||||
end
|
||||
|
||||
if self.y < 0 then
|
||||
self.y = 0
|
||||
end
|
||||
|
||||
if self.y + self.height > height then
|
||||
self.y = height - self.height
|
||||
end
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
v:update(dt)
|
||||
end
|
||||
|
||||
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 upadte then
|
||||
upadte(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: draw()
|
||||
- desc: draws the object
|
||||
--]]---------------------------------------------------------
|
||||
--[[
|
||||
function newobject:draw()
|
||||
if loveframes.state ~= self.state then
|
||||
return
|
||||
end
|
||||
|
||||
if not self.visible then
|
||||
return
|
||||
end
|
||||
|
||||
self:SetDrawOrder()
|
||||
|
||||
local drawfunc = self.Draw or self.drawfunc
|
||||
if drawfunc then
|
||||
drawfunc(self)
|
||||
end
|
||||
|
||||
local internals = self.internals
|
||||
if internals then
|
||||
for k, v in ipairs(internals) do
|
||||
v:draw()
|
||||
end
|
||||
end
|
||||
|
||||
love.graphics.stencil(stencilfunc)
|
||||
love.graphics.setStencilTest("greater", 0)
|
||||
|
||||
local children = self.children
|
||||
if children then
|
||||
for k, v in ipairs(children) do
|
||||
local col = loveframes.BoundingBox(self.x, v.x, self.y, v.y, self.width, v.width, self.height, v.height)
|
||||
if col then
|
||||
v:draw()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
love.graphics.setStencilTest()
|
||||
|
||||
drawfunc = self.DrawOver or self.drawoverfunc
|
||||
if drawfunc then
|
||||
drawfunc(self)
|
||||
end
|
||||
|
||||
end
|
||||
--]]
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousepressed(x, y, button)
|
||||
- desc: called when the player presses a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:mousepressed(x, y, button)
|
||||
|
||||
local state = loveframes.state
|
||||
local selfstate = self.state
|
||||
|
||||
if state ~= selfstate then
|
||||
return
|
||||
end
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
local selfcol = loveframes.BoundingBox(x, self.x, y, self.y, 1, self.width, 1, self.height)
|
||||
local internals = self.internals
|
||||
local children = self.children
|
||||
|
||||
if not selfcol and self.canremove and button == 1 then
|
||||
self:Close()
|
||||
end
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
v:mousepressed(x, y, button)
|
||||
end
|
||||
|
||||
for k, v in ipairs(children) do
|
||||
v:mousepressed(x, y, button)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousereleased(x, y, button)
|
||||
- desc: called when the player releases a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:mousereleased(x, y, button)
|
||||
|
||||
local state = loveframes.state
|
||||
local selfstate = self.state
|
||||
|
||||
if state ~= selfstate then
|
||||
return
|
||||
end
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
local internals = self.internals
|
||||
local children = self.children
|
||||
|
||||
self.canremove = true
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
v:mousereleased(x, y, button)
|
||||
end
|
||||
|
||||
for k, v in ipairs(children) do
|
||||
v:mousereleased(x, y, button)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: wheelmoved(x, y)
|
||||
- desc: called when the player moves a mouse wheel
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:wheelmoved(x, y)
|
||||
|
||||
local toplist = self:IsTopList()
|
||||
local internals = self.internals
|
||||
local scrollamount = self.mousewheelscrollamount
|
||||
|
||||
if self.vbar and toplist then
|
||||
local bar = internals[1].internals[1].internals[1]
|
||||
local dtscrolling = self.dtscrolling
|
||||
if dtscrolling then
|
||||
local dt = love.timer.getDelta()
|
||||
bar:Scroll(-y * scrollamount * dt)
|
||||
else
|
||||
bar:Scroll(-y * scrollamount)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: AddItem(object)
|
||||
- desc: adds an item to the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:AddItem(object)
|
||||
|
||||
if object.type ~= "multichoicerow" then
|
||||
return
|
||||
end
|
||||
|
||||
object.parent = self
|
||||
table.insert(self.children, object)
|
||||
|
||||
self:CalculateSize()
|
||||
self:RedoLayout()
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: RemoveItem(object)
|
||||
- desc: removes an item from the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:RemoveItem(object)
|
||||
|
||||
local children = self.children
|
||||
|
||||
for k, v in ipairs(children) do
|
||||
if v == object then
|
||||
table.remove(children, k)
|
||||
end
|
||||
end
|
||||
|
||||
self:CalculateSize()
|
||||
self:RedoLayout()
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: CalculateSize()
|
||||
- desc: calculates the size of the object's children
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:CalculateSize()
|
||||
|
||||
self.height = self.padding
|
||||
|
||||
if self.list.listheight then
|
||||
self.height = self.list.listheight
|
||||
else
|
||||
for k, v in ipairs(self.children) do
|
||||
self.height = self.height + (v.height + self.spacing)
|
||||
end
|
||||
end
|
||||
|
||||
if self.height > love.graphics.getHeight() then
|
||||
self.height = love.graphics.getHeight()
|
||||
end
|
||||
|
||||
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 children = self.children
|
||||
|
||||
for k, v in ipairs(children) do
|
||||
itemheight = itemheight + v.height + spacing
|
||||
end
|
||||
|
||||
self.itemheight = (itemheight - spacing) + padding
|
||||
|
||||
if self.itemheight > height then
|
||||
self.extraheight = self.itemheight - height
|
||||
if not vbar then
|
||||
local scroll = loveframes.objects["scrollbody"]:new(self, "vertical")
|
||||
table.insert(self.internals, scroll)
|
||||
self.vbar = true
|
||||
end
|
||||
else
|
||||
if vbar then
|
||||
self.internals[1]:Remove()
|
||||
self.vbar = false
|
||||
self.offsety = 0
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: RedoLayout()
|
||||
- desc: used to redo the layour of the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:RedoLayout()
|
||||
|
||||
local children = self.children
|
||||
local padding = self.padding
|
||||
local spacing = self.spacing
|
||||
local starty = padding
|
||||
local vbar = self.vbar
|
||||
|
||||
if #children > 0 then
|
||||
for k, v in ipairs(children) do
|
||||
v.staticx = padding
|
||||
v.staticy = starty
|
||||
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
|
||||
end
|
||||
starty = starty + v.height
|
||||
starty = starty + spacing
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetPadding(amount)
|
||||
- desc: sets the object's padding
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:SetPadding(amount)
|
||||
|
||||
self.padding = amount
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetSpacing(amount)
|
||||
- desc: sets the object's spacing
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:SetSpacing(amount)
|
||||
|
||||
self.spacing = amount
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: Close()
|
||||
- desc: closes the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:Close()
|
||||
|
||||
self:Remove()
|
||||
self.list.haslist = false
|
||||
|
||||
end
|
||||
|
||||
---------- module end ----------
|
||||
end
|
157
loveframes/objects/internal/multichoice/multichoicerow.lua
Normal file
157
loveframes/objects/internal/multichoice/multichoicerow.lua
Normal file
@ -0,0 +1,157 @@
|
||||
--[[------------------------------------------------
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012-2014 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
return function(loveframes)
|
||||
---------- module start ----------
|
||||
|
||||
-- multichoicerow class
|
||||
local newobject = loveframes.NewObject("multichoicerow", "loveframes_object_multichoicerow", true)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:initialize()
|
||||
|
||||
self.type = "multichoicerow"
|
||||
self.text = ""
|
||||
self.width = 50
|
||||
self.height = 25
|
||||
self.hover = false
|
||||
self.internal = true
|
||||
self.down = false
|
||||
self.canclick = false
|
||||
|
||||
-- apply template properties to the object
|
||||
loveframes.ApplyTemplatesToObject(self)
|
||||
self:SetDrawFunc()
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject: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
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
if not self.hover then
|
||||
self.down = false
|
||||
else
|
||||
if loveframes.downobject == self then
|
||||
self.down = true
|
||||
end
|
||||
end
|
||||
|
||||
if not self.down and loveframes.downobject == self then
|
||||
self.hover = true
|
||||
end
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if parent ~= base then
|
||||
self.x = parent.x + self.staticx
|
||||
self.y = parent.y + self.staticy
|
||||
end
|
||||
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousepressed(x, y, button)
|
||||
- desc: called when the player presses a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
|
||||
if hover and button == 1 then
|
||||
self.down = true
|
||||
loveframes.downobject = self
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousereleased(x, y, button)
|
||||
- desc: called when the player releases a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:mousereleased(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
local text = self.text
|
||||
|
||||
if self.hover and self.down and self.canclick and button == 1 then
|
||||
self.parent.list:SelectChoice(text)
|
||||
end
|
||||
|
||||
self.down = false
|
||||
self.canclick = true
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: keypressed(key, isrepeat)
|
||||
- desc: called when the player presses a key
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:keypressed(key, isrepeat)
|
||||
|
||||
local text = self.text
|
||||
local selectedobject = loveframes.selectedobject
|
||||
|
||||
if key == "return" and selectedobject == self then
|
||||
self.parent.list:SelectChoice(text)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetText(text)
|
||||
- desc: sets the object's text
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:SetText(text)
|
||||
|
||||
self.text = text
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetText()
|
||||
- desc: gets the object's text
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetText()
|
||||
|
||||
return self.text
|
||||
|
||||
end
|
||||
|
||||
---------- module end ----------
|
||||
end
|
204
loveframes/objects/internal/scrollable/scrollarea.lua
Normal file
204
loveframes/objects/internal/scrollable/scrollarea.lua
Normal file
@ -0,0 +1,204 @@
|
||||
--[[------------------------------------------------
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012-2014 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
return function(loveframes)
|
||||
---------- module start ----------
|
||||
|
||||
-- scrollarea class
|
||||
local newobject = loveframes.NewObject("scrollarea", "loveframes_object_scrollarea", true)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject: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 = {}
|
||||
|
||||
table.insert(self.internals, loveframes.objects["scrollbar"]:new(self, bartype))
|
||||
|
||||
-- apply template properties to the object
|
||||
loveframes.ApplyTemplatesToObject(self)
|
||||
self:SetDrawFunc()
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if not visible then
|
||||
if not alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
local base = loveframes.base
|
||||
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 update = self.Update
|
||||
|
||||
if button then
|
||||
if bartype == "vertical" then
|
||||
self.staticx = 0
|
||||
self.staticy = button.height - 1
|
||||
self.width = parent.width
|
||||
self.height = parent.height - button.height*2 + 2
|
||||
elseif bartype == "horizontal" then
|
||||
self.staticx = button.width - 1
|
||||
self.staticy = 0
|
||||
self.width = parent.width - button.width*2 + 2
|
||||
self.height = parent.height
|
||||
end
|
||||
end
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if parent ~= base then
|
||||
self.x = parent.x + self.staticx
|
||||
self.y = parent.y + self.staticy
|
||||
end
|
||||
|
||||
if down then
|
||||
if scrolldelay < time then
|
||||
self.scrolldelay = time + delayamount
|
||||
if self.bartype == "vertical" then
|
||||
if y > bar.y then
|
||||
bar:Scroll(bar.height)
|
||||
else
|
||||
bar:Scroll(-bar.height)
|
||||
end
|
||||
elseif self.bartype == "horizontal" then
|
||||
if x > bar.x then
|
||||
bar:Scroll(bar.width)
|
||||
else
|
||||
bar:Scroll(-bar.width)
|
||||
end
|
||||
end
|
||||
end
|
||||
if not hover then
|
||||
self.down = false
|
||||
end
|
||||
end
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
v:update(dt)
|
||||
end
|
||||
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousepressed(x, y, button)
|
||||
- desc: called when the player presses a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
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 delayamount = self.delayamount
|
||||
|
||||
if hover and button == 1 then
|
||||
self.down = true
|
||||
self.scrolldelay = time + delayamount + 0.5
|
||||
local baseparent = self:GetBaseParent()
|
||||
if baseparent and baseparent.type == "frame" then
|
||||
baseparent:MakeTop()
|
||||
end
|
||||
if self.bartype == "vertical" then
|
||||
if y > self.internals[1].y then
|
||||
bar:Scroll(bar.height)
|
||||
else
|
||||
bar:Scroll(-bar.height)
|
||||
end
|
||||
elseif self.bartype == "horizontal" then
|
||||
if x > bar.x then
|
||||
bar:Scroll(bar.width)
|
||||
else
|
||||
bar:Scroll(-bar.width)
|
||||
end
|
||||
end
|
||||
loveframes.downobject = self
|
||||
end
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
v:mousepressed(x, y, button)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousereleased(x, y, button)
|
||||
- desc: called when the player releases a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:mousereleased(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
local internals = self.internals
|
||||
|
||||
if button == 1 then
|
||||
self.down = false
|
||||
end
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
v:mousereleased(x, y, button)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetBarType()
|
||||
- desc: gets the object's bar type
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetBarType()
|
||||
|
||||
return self.bartype
|
||||
|
||||
end
|
||||
|
||||
---------- module end ----------
|
||||
end
|
358
loveframes/objects/internal/scrollable/scrollbar.lua
Normal file
358
loveframes/objects/internal/scrollable/scrollbar.lua
Normal file
@ -0,0 +1,358 @@
|
||||
--[[------------------------------------------------
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012-2014 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
return function(loveframes)
|
||||
---------- module start ----------
|
||||
|
||||
-- scrollbar class
|
||||
local newobject = loveframes.NewObject("scrollbar", "loveframes_object_scrollbar", true)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject: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
|
||||
|
||||
if self.bartype == "vertical" then
|
||||
self.width = self.parent.width
|
||||
self.height = 5
|
||||
elseif self.bartype == "horizontal" then
|
||||
self.width = 5
|
||||
self.height = self.parent.height
|
||||
end
|
||||
|
||||
-- apply template properties to the object
|
||||
loveframes.ApplyTemplatesToObject(self)
|
||||
self:SetDrawFunc()
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
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 basecols = {}
|
||||
local dragging = self.dragging
|
||||
|
||||
if bartype == "vertical" then
|
||||
self.width = self.parent.width
|
||||
elseif bartype == "horizontal" then
|
||||
self.height = self.parent.height
|
||||
end
|
||||
|
||||
if bartype == "vertical" then
|
||||
local parent = self.parent
|
||||
local listo = parent.parent.parent
|
||||
local height = parent.height * (listo.height/listo.itemheight)
|
||||
if height < 20 then
|
||||
self.height = 20
|
||||
else
|
||||
self.height = height
|
||||
end
|
||||
self.maxy = parent.y + (parent.height - self.height)
|
||||
self.x = parent.x + parent.width - self.width
|
||||
self.y = parent.y + self.staticy
|
||||
if dragging then
|
||||
if self.staticy ~= self.lasty then
|
||||
if listo.OnScroll then
|
||||
listo.OnScroll(listo)
|
||||
end
|
||||
self.lasty = self.staticy
|
||||
end
|
||||
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.extraheight * percent
|
||||
local autoscroll = self.autoscroll
|
||||
local lastheight = self.lastheight
|
||||
listo.offsety = 0 + extra
|
||||
if self.staticy > space then
|
||||
self.staticy = space
|
||||
listo.offsety = listo.extraheight
|
||||
end
|
||||
if self.staticy < 0 then
|
||||
self.staticy = 0
|
||||
listo.offsety = 0
|
||||
end
|
||||
if autoscroll then
|
||||
if listo.itemheight > lastheight then
|
||||
local type = listo.type
|
||||
self.lastheight = listo.itemheight
|
||||
if type == "textinput" then
|
||||
local indicatory = listo.indicatory
|
||||
local font = listo.font
|
||||
local theight = font:getHeight("a")
|
||||
local y = listo.y
|
||||
local height = listo.height
|
||||
local linecount = #listo.lines
|
||||
local parentheight = self.parent.height
|
||||
if (indicatory + theight) > (y + height) then
|
||||
self:Scroll(parentheight/linecount)
|
||||
end
|
||||
else
|
||||
local maxy = self.maxy
|
||||
self:Scroll(maxy)
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif bartype == "horizontal" then
|
||||
local parent = self.parent
|
||||
local listo = self.parent.parent.parent
|
||||
local width = self.parent.width * (listo.width/listo.itemwidth)
|
||||
if width < 20 then
|
||||
self.width = 20
|
||||
else
|
||||
self.width = width
|
||||
end
|
||||
self.maxx = parent.x + (parent.width) - self.width
|
||||
self.x = parent.x + self.staticx
|
||||
self.y = parent.y + self.staticy
|
||||
if dragging then
|
||||
if self.staticx ~= self.lastx then
|
||||
if listo.OnScroll then
|
||||
listo.OnScroll(listo)
|
||||
end
|
||||
self.lastx = self.staticx
|
||||
end
|
||||
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.extrawidth * percent
|
||||
local autoscroll = self.autoscroll
|
||||
local lastwidth = self.lastwidth
|
||||
listo.offsetx = 0 + extra
|
||||
if self.staticx > space then
|
||||
self.staticx = space
|
||||
listo.offsetx = listo.extrawidth
|
||||
end
|
||||
|
||||
if self.staticx < 0 then
|
||||
self.staticx = 0
|
||||
listo.offsetx = 0
|
||||
end
|
||||
if autoscroll then
|
||||
if listo.itemwidth > lastwidth then
|
||||
self.lastwidth = listo.itemwidth
|
||||
self:Scroll(self.maxx)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local update = self.Update
|
||||
if update then update(self, dt) end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousepressed(x, y, button)
|
||||
- desc: called when the player presses a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
local hover = self.hover
|
||||
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
if not hover then
|
||||
return
|
||||
end
|
||||
|
||||
local baseparent = self:GetBaseParent()
|
||||
|
||||
if baseparent.type == "frame" then
|
||||
baseparent:MakeTop()
|
||||
end
|
||||
|
||||
local dragging = self.dragging
|
||||
|
||||
if not dragging then
|
||||
if button == 1 then
|
||||
self.starty = self.staticy
|
||||
self.startx = self.staticx
|
||||
self.clickx = x
|
||||
self.clicky = y
|
||||
self.dragging = true
|
||||
loveframes.downobject = self
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousereleased(x, y, button)
|
||||
- desc: called when the player releases a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:mousereleased(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
if self.dragging then
|
||||
self.dragging = false
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetMaxX(x)
|
||||
- desc: sets the object's max x position
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:SetMaxX(x)
|
||||
|
||||
self.maxx = x
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetMaxY(y)
|
||||
- desc: sets the object's max y position
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:SetMaxY(y)
|
||||
|
||||
self.maxy = y
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: Scroll(amount)
|
||||
- desc: scrolls the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:Scroll(amount)
|
||||
|
||||
local bartype = self.bartype
|
||||
local listo = self.parent.parent.parent
|
||||
local onscroll = listo.OnScroll
|
||||
|
||||
if bartype == "vertical" then
|
||||
local newy = (self.y + amount)
|
||||
if newy > self.maxy then
|
||||
self.staticy = self.maxy - self.parent.y
|
||||
elseif newy < self.parent.y then
|
||||
self.staticy = 0
|
||||
else
|
||||
self.staticy = self.staticy + amount
|
||||
end
|
||||
elseif bartype == "horizontal" then
|
||||
local newx = (self.x + amount)
|
||||
if newx > self.maxx then
|
||||
self.staticx = self.maxx - self.parent.x
|
||||
elseif newx < self.parent.x then
|
||||
self.staticx = 0
|
||||
else
|
||||
self.staticx = self.staticx + amount
|
||||
end
|
||||
end
|
||||
|
||||
if onscroll then
|
||||
onscroll(listo)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: ScrollTo(position)
|
||||
- desc: scrolls the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:ScrollTo(position)
|
||||
|
||||
local bartype = self.bartype
|
||||
local listo = self.parent.parent.parent
|
||||
local onscroll = listo.OnScroll
|
||||
|
||||
if bartype == "vertical" then
|
||||
local maxRealPos = self.parent.height - self.height
|
||||
if position > 1 then
|
||||
self.staticy = maxRealPos
|
||||
elseif position < 0 then
|
||||
self.staticy = 0
|
||||
else
|
||||
self.staticy = position * maxRealPos
|
||||
end
|
||||
elseif bartype == "horizontal" then
|
||||
local maxRealPos = self.parent.width - self.width
|
||||
if position > 1 then
|
||||
self.staticx = maxRealPos
|
||||
elseif position < 0 then
|
||||
self.staticx = 0
|
||||
else
|
||||
self.staticx = position * maxRealPos
|
||||
end
|
||||
end
|
||||
|
||||
if onscroll then
|
||||
onscroll(listo)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: IsDragging()
|
||||
- desc: gets whether the object is being dragged or not
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:IsDragging()
|
||||
|
||||
return self.dragging
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetBarType()
|
||||
- desc: gets the object's bartype
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetBarType()
|
||||
|
||||
return self.bartype
|
||||
|
||||
end
|
||||
|
||||
---------- module end ----------
|
||||
end
|
192
loveframes/objects/internal/scrollable/scrollbody.lua
Normal file
192
loveframes/objects/internal/scrollable/scrollbody.lua
Normal file
@ -0,0 +1,192 @@
|
||||
--[[------------------------------------------------
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012-2014 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
return function(loveframes)
|
||||
---------- module start ----------
|
||||
|
||||
-- scrollbar class
|
||||
local newobject = loveframes.NewObject("scrollbody", "loveframes_object_scrollbody", true)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:initialize(parent, bartype)
|
||||
|
||||
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
|
||||
elseif self.bartype == "horizontal" then
|
||||
self.width = self.parent.width
|
||||
self.height = 16
|
||||
self.staticx = 0
|
||||
self.staticy = self.parent.height - self.height
|
||||
end
|
||||
|
||||
table.insert(self.internals, loveframes.objects["scrollarea"]:new(self, bartype))
|
||||
|
||||
local bar = self.internals[1].internals[1]
|
||||
|
||||
if self.bartype == "vertical" then
|
||||
local upbutton = loveframes.objects["scrollbutton"]:new("up")
|
||||
upbutton.staticx = 0 + self.width - upbutton.width
|
||||
upbutton.staticy = 0
|
||||
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
|
||||
local dtscrolling = self.parent.dtscrolling
|
||||
if dtscrolling then
|
||||
local dt = love.timer.getDelta()
|
||||
bar:Scroll(-self.parent.buttonscrollamount * dt)
|
||||
else
|
||||
bar:Scroll(-self.parent.buttonscrollamount)
|
||||
end
|
||||
end
|
||||
end
|
||||
local downbutton = loveframes.objects["scrollbutton"]:new("down")
|
||||
downbutton.parent = self
|
||||
downbutton.staticx = 0 + self.width - downbutton.width
|
||||
downbutton.staticy = 0 + self.height - downbutton.height
|
||||
downbutton.Update = function(object, dt)
|
||||
downbutton.staticx = 0 + self.width - downbutton.width
|
||||
downbutton.staticy = 0 + self.height - downbutton.height
|
||||
downbutton.x = downbutton.parent.x + downbutton.staticx
|
||||
downbutton.y = downbutton.parent.y + downbutton.staticy
|
||||
if object.down and object.hover then
|
||||
local dtscrolling = self.parent.dtscrolling
|
||||
if dtscrolling then
|
||||
local dt = love.timer.getDelta()
|
||||
bar:Scroll(self.parent.buttonscrollamount * dt)
|
||||
else
|
||||
bar:Scroll(self.parent.buttonscrollamount)
|
||||
end
|
||||
end
|
||||
end
|
||||
table.insert(self.internals, upbutton)
|
||||
table.insert(self.internals, downbutton)
|
||||
elseif self.bartype == "horizontal" then
|
||||
local leftbutton = loveframes.objects["scrollbutton"]:new("left")
|
||||
leftbutton.parent = self
|
||||
leftbutton.staticx = 0
|
||||
leftbutton.staticy = 0
|
||||
leftbutton.Update = function(object, dt)
|
||||
leftbutton.staticx = 0
|
||||
leftbutton.staticy = 0
|
||||
if object.down and object.hover then
|
||||
local dtscrolling = self.parent.dtscrolling
|
||||
if dtscrolling then
|
||||
local dt = love.timer.getDelta()
|
||||
bar:Scroll(-self.parent.buttonscrollamount * dt)
|
||||
else
|
||||
bar:Scroll(-self.parent.buttonscrollamount)
|
||||
end
|
||||
end
|
||||
end
|
||||
local rightbutton = loveframes.objects["scrollbutton"]:new("right")
|
||||
rightbutton.parent = self
|
||||
rightbutton.staticx = 0 + self.width - rightbutton.width
|
||||
rightbutton.staticy = 0
|
||||
rightbutton.Update = function(object, dt)
|
||||
rightbutton.staticx = 0 + self.width - rightbutton.width
|
||||
rightbutton.staticy = 0
|
||||
rightbutton.x = rightbutton.parent.x + rightbutton.staticx
|
||||
rightbutton.y = rightbutton.parent.y + rightbutton.staticy
|
||||
if object.down and object.hover then
|
||||
local dtscrolling = self.parent.dtscrolling
|
||||
if dtscrolling then
|
||||
local dt = love.timer.getDelta()
|
||||
bar:Scroll(self.parent.buttonscrollamount * dt)
|
||||
else
|
||||
bar:Scroll(self.parent.buttonscrollamount)
|
||||
end
|
||||
end
|
||||
end
|
||||
table.insert(self.internals, leftbutton)
|
||||
table.insert(self.internals, rightbutton)
|
||||
end
|
||||
|
||||
local parentstate = parent.state
|
||||
self:SetState(parentstate)
|
||||
|
||||
-- apply template properties to the object
|
||||
loveframes.ApplyTemplatesToObject(self)
|
||||
self:SetDrawFunc()
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if not visible then
|
||||
if not alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
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 parent ~= base then
|
||||
self.x = parent.x + self.staticx
|
||||
self.y = parent.y + self.staticy
|
||||
end
|
||||
|
||||
-- resize to parent
|
||||
if parent ~= base then
|
||||
if self.bartype == "vertical" then
|
||||
self.height = self.parent.height
|
||||
self.staticx = self.parent.width - self.width
|
||||
if parent.hbar then self.height = self.height - parent:GetHorizontalScrollBody().height end
|
||||
elseif self.bartype == "horizontal" then
|
||||
self.width = self.parent.width
|
||||
self.staticy = self.parent.height - self.height
|
||||
if parent.vbar then self.width = self.width - parent:GetVerticalScrollBody().width end
|
||||
end
|
||||
end
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
v:update(dt)
|
||||
end
|
||||
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetScrollBar()
|
||||
- desc: gets the object's scroll bar
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetScrollBar()
|
||||
|
||||
return self.internals[1].internals[1]
|
||||
|
||||
end
|
||||
|
||||
---------- module end ----------
|
||||
end
|
139
loveframes/objects/internal/scrollable/scrollbutton.lua
Normal file
139
loveframes/objects/internal/scrollable/scrollbutton.lua
Normal file
@ -0,0 +1,139 @@
|
||||
--[[------------------------------------------------
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012-2014 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
return function(loveframes)
|
||||
---------- module start ----------
|
||||
|
||||
-- scrollbutton clas
|
||||
local newobject = loveframes.NewObject("scrollbutton", "loveframes_object_scrollbutton", true)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:initialize(scrolltype)
|
||||
|
||||
self.type = "scrollbutton"
|
||||
self.scrolltype = scrolltype
|
||||
self.width = 16
|
||||
self.height = 16
|
||||
self.down = false
|
||||
self.internal = true
|
||||
self.OnClick = function() end
|
||||
|
||||
-- apply template properties to the object
|
||||
loveframes.ApplyTemplatesToObject(self)
|
||||
self:SetDrawFunc()
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if not visible then
|
||||
if not alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
local hover = self.hover
|
||||
local parent = self.parent
|
||||
local base = loveframes.base
|
||||
local update = self.Update
|
||||
|
||||
if not hover then
|
||||
self.down = false
|
||||
else
|
||||
if loveframes.downobject == self then
|
||||
self.down = true
|
||||
end
|
||||
end
|
||||
|
||||
if not self.down and loveframes.downobject == self then
|
||||
self.hover = true
|
||||
end
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if parent ~= base then
|
||||
self.x = parent.x + self.staticx
|
||||
self.y = parent.y + self.staticy
|
||||
end
|
||||
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousepressed(x, y, button)
|
||||
- desc: called when the player presses a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
|
||||
if hover and button == 1 then
|
||||
local baseparent = self:GetBaseParent()
|
||||
if baseparent.type == "frame" then
|
||||
baseparent:MakeTop()
|
||||
end
|
||||
self.down = true
|
||||
loveframes.downobject = self
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousereleased(x, y, button)
|
||||
- desc: called when the player releases a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:mousereleased(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
local down = self.down
|
||||
local onclick = self.OnClick
|
||||
|
||||
if hover and down then
|
||||
if button == 1 then
|
||||
onclick(x, y, self)
|
||||
end
|
||||
end
|
||||
|
||||
self.down = false
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetScrollType()
|
||||
- desc: gets the object's scroll type
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetScrollType()
|
||||
|
||||
return self.scrolltype
|
||||
|
||||
end
|
||||
|
||||
---------- module end ----------
|
||||
end
|
228
loveframes/objects/internal/sliderbutton.lua
Normal file
228
loveframes/objects/internal/sliderbutton.lua
Normal file
@ -0,0 +1,228 @@
|
||||
--[[------------------------------------------------
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012-2014 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
return function(loveframes)
|
||||
---------- module start ----------
|
||||
|
||||
-- sliderbutton class
|
||||
local newobject = loveframes.NewObject("sliderbutton", "loveframes_object_sliderbutton", true)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject: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
|
||||
|
||||
-- apply template properties to the object
|
||||
loveframes.ApplyTemplatesToObject(self)
|
||||
self:SetDrawFunc()
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
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 downobject = loveframes.downobject
|
||||
local parent = self.parent
|
||||
local slidetype = parent.slidetype
|
||||
local dragging = self.dragging
|
||||
local base = loveframes.base
|
||||
local update = self.Update
|
||||
|
||||
if not hover then
|
||||
self.down = false
|
||||
if downobject == self then
|
||||
self.hover = true
|
||||
end
|
||||
else
|
||||
if downobject == self then
|
||||
self.down = true
|
||||
end
|
||||
end
|
||||
|
||||
if not down and downobject == self then
|
||||
self.hover = true
|
||||
end
|
||||
|
||||
-- move to parent if there is a parent
|
||||
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 then
|
||||
-- calculations for horizontal sliders
|
||||
if slidetype == "horizontal" then
|
||||
self.staticx = self.startx + (x - self.clickx)
|
||||
progress = self.staticx/(self.parent.width - self.width)
|
||||
nvalue = self.parent.min + (self.parent.max - self.parent.min) * progress
|
||||
nvalue = loveframes.Round(nvalue, self.parent.decimals)
|
||||
-- calculations for vertical sliders
|
||||
elseif slidetype == "vertical" then
|
||||
self.staticy = self.starty + (y - self.clicky)
|
||||
local space = self.parent.height - self.height
|
||||
local remaining = (self.parent.height - self.height) - self.staticy
|
||||
local percent = remaining/space
|
||||
nvalue = self.parent.min + (self.parent.max - self.parent.min) * percent
|
||||
nvalue = loveframes.Round(nvalue, self.parent.decimals)
|
||||
end
|
||||
if nvalue > self.parent.max then
|
||||
nvalue = self.parent.max
|
||||
end
|
||||
if nvalue < self.parent.min then
|
||||
nvalue = self.parent.min
|
||||
end
|
||||
self.parent.value = nvalue
|
||||
if self.parent.value == -0 then
|
||||
self.parent.value = math.abs(self.parent.value)
|
||||
end
|
||||
if nvalue ~= pvalue and nvalue >= self.parent.min and nvalue <= self.parent.max then
|
||||
if self.parent.OnValueChanged then
|
||||
self.parent.OnValueChanged(self.parent, self.parent.value)
|
||||
end
|
||||
end
|
||||
loveframes.downobject = self
|
||||
end
|
||||
|
||||
if slidetype == "horizontal" then
|
||||
if (self.staticx + self.width) > self.parent.width then
|
||||
self.staticx = self.parent.width - self.width
|
||||
end
|
||||
if self.staticx < 0 then
|
||||
self.staticx = 0
|
||||
end
|
||||
end
|
||||
|
||||
if slidetype == "vertical" then
|
||||
if (self.staticy + self.height) > self.parent.height then
|
||||
self.staticy = self.parent.height - self.height
|
||||
end
|
||||
if self.staticy < 0 then
|
||||
self.staticy = 0
|
||||
end
|
||||
end
|
||||
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousepressed(x, y, button)
|
||||
- desc: called when the player presses a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
|
||||
if hover and button == 1 then
|
||||
local baseparent = self:GetBaseParent()
|
||||
if baseparent and baseparent.type == "frame" then
|
||||
baseparent:MakeTop()
|
||||
end
|
||||
self.down = true
|
||||
self.dragging = true
|
||||
self.startx = self.staticx
|
||||
self.clickx = x
|
||||
self.starty = self.staticy
|
||||
self.clicky = y
|
||||
loveframes.downobject = self
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousereleased(x, y, button)
|
||||
- desc: called when the player releases a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:mousereleased(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
local down = self.down
|
||||
local dragging = self.dragging
|
||||
|
||||
if dragging then
|
||||
local parent = self.parent
|
||||
local onrelease = parent.OnRelease
|
||||
if onrelease then
|
||||
onrelease(parent)
|
||||
end
|
||||
end
|
||||
|
||||
self.down = false
|
||||
self.dragging = false
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: MoveToX(x)
|
||||
- desc: moves the object to the specified x position
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:MoveToX(x)
|
||||
|
||||
self.staticx = x
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: MoveToY(y)
|
||||
- desc: moves the object to the specified y position
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:MoveToY(y)
|
||||
|
||||
self.staticy = y
|
||||
|
||||
end
|
||||
|
||||
---------- module end ----------
|
||||
end
|
205
loveframes/objects/internal/tabbutton.lua
Normal file
205
loveframes/objects/internal/tabbutton.lua
Normal file
@ -0,0 +1,205 @@
|
||||
--[[------------------------------------------------
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012-2014 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
return function(loveframes)
|
||||
---------- module start ----------
|
||||
|
||||
-- tabbutton class
|
||||
local newobject = loveframes.NewObject("tabbutton", "loveframes_object_tabbutton", true)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:initialize(parent, text, tabnumber, tip, image, onopened, onclosed)
|
||||
|
||||
self.type = "tabbutton"
|
||||
self.font = loveframes.smallfont
|
||||
self.text = text
|
||||
self.tabnumber = tabnumber
|
||||
self.parent = parent
|
||||
self.state = parent.state
|
||||
self.staticx = 0
|
||||
self.staticy = 0
|
||||
self.width = 50
|
||||
self.height = 25
|
||||
self.internal = true
|
||||
self.down = false
|
||||
self.image = nil
|
||||
self.OnOpened = nil
|
||||
self.OnClosed = nil
|
||||
|
||||
if tip then
|
||||
self.tooltip = loveframes.objects["tooltip"]:new(self, tip)
|
||||
self.tooltip:SetFollowCursor(false)
|
||||
self.tooltip:SetFollowObject(true)
|
||||
self.tooltip:SetOffsets(0, -(self.tooltip.internals[1]:GetHeight() + 12))
|
||||
end
|
||||
|
||||
if image then
|
||||
self:SetImage(image)
|
||||
end
|
||||
|
||||
if onopened then
|
||||
self.OnOpened = onopened
|
||||
end
|
||||
|
||||
if onclosed then
|
||||
self.OnClosed = onclosed
|
||||
end
|
||||
|
||||
-- apply template properties to the object
|
||||
loveframes.ApplyTemplatesToObject(self)
|
||||
|
||||
self:SetDrawFunc()
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject: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
|
||||
|
||||
self:CheckHover()
|
||||
self:SetClickBounds(parent.x, parent.y, parent.width, parent.height)
|
||||
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousepressed(x, y, button)
|
||||
- desc: called when the player presses a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
local internals = self.internals
|
||||
|
||||
if hover and button == 1 then
|
||||
local baseparent = self:GetBaseParent()
|
||||
if baseparent and baseparent.type == "frame" then
|
||||
baseparent:MakeTop()
|
||||
end
|
||||
self.down = true
|
||||
loveframes.downobject = self
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousereleased(x, y, button)
|
||||
- desc: called when the player releases a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:mousereleased(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
local parent = self.parent
|
||||
local tabnumber = self.tabnumber
|
||||
|
||||
if hover and button == 1 then
|
||||
if button == 1 then
|
||||
local tab = parent.tab
|
||||
local internals = parent.internals
|
||||
local onopened = self.OnOpened
|
||||
local prevtab = internals[tab]
|
||||
local onclosed = prevtab.OnClosed
|
||||
parent:SwitchToTab(tabnumber)
|
||||
if onopened then
|
||||
onopened(self)
|
||||
end
|
||||
if onclosed then
|
||||
onclosed(prevtab)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
self.down = false
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetText(text)
|
||||
- desc: sets the object's text
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:SetText(text)
|
||||
|
||||
self.text = text
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetText()
|
||||
- desc: gets the object's text
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetText()
|
||||
|
||||
return self.text
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetImage(image)
|
||||
- desc: adds an image to the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:SetImage(image)
|
||||
|
||||
if type(image) == "string" then
|
||||
self.image = love.graphics.newImage(image)
|
||||
self.image:setFilter("nearest", "nearest")
|
||||
else
|
||||
self.image = image
|
||||
end
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetImage()
|
||||
- desc: gets the object's image
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetImage()
|
||||
|
||||
return self.image
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetTabNumber()
|
||||
- desc: gets the object's tab number
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetTabNumber()
|
||||
|
||||
return self.tabnumber
|
||||
|
||||
end
|
||||
|
||||
---------- module end ----------
|
||||
end
|
353
loveframes/objects/internal/tooltip.lua
Normal file
353
loveframes/objects/internal/tooltip.lua
Normal file
@ -0,0 +1,353 @@
|
||||
--[[------------------------------------------------
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012-2014 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
return function(loveframes)
|
||||
---------- module start ----------
|
||||
|
||||
-- tooltip class
|
||||
local newobject = loveframes.NewObject("tooltip", "loveframes_object_tooltip", true)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:initialize(object, text)
|
||||
|
||||
self.type = "tooltip"
|
||||
self.parent = loveframes.base
|
||||
self.object = object or nil
|
||||
self.width = 0
|
||||
self.height = 0
|
||||
self.padding = 5
|
||||
self.xoffset = 10
|
||||
self.yoffset = -10
|
||||
self.internal = true
|
||||
self.followcursor = true
|
||||
self.followobject = false
|
||||
self.alwaysupdate = true
|
||||
self.internals = {}
|
||||
|
||||
-- create the object's text
|
||||
local textobject = loveframes.Create("text")
|
||||
textobject:Remove()
|
||||
textobject.parent = self
|
||||
textobject:SetText(text or "")
|
||||
textobject:SetPos(10000, 0) -- textobject interferes with hover detection
|
||||
table.insert(self.internals, textobject)
|
||||
|
||||
-- apply template properties to the object
|
||||
loveframes.ApplyTemplatesToObject(self)
|
||||
table.insert(loveframes.base.internals, self)
|
||||
|
||||
self:SetDrawFunc()
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:update(dt)
|
||||
|
||||
local state = loveframes.state
|
||||
local selfstate = self.state
|
||||
|
||||
if state ~= selfstate then
|
||||
return
|
||||
end
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
local internals = self.internals
|
||||
local textobject = internals[1]
|
||||
|
||||
if not visible then
|
||||
textobject:SetPos(10000, 0) -- textobject interferes with hover detection
|
||||
if not alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local padding = self.padding
|
||||
local object = self.object
|
||||
local draworder = self.draworder
|
||||
local update = self.Update
|
||||
|
||||
self.width = textobject.width + padding * 2
|
||||
self.height = textobject.height + padding * 2
|
||||
|
||||
if object then
|
||||
if object == loveframes.base then
|
||||
self:Remove()
|
||||
return
|
||||
end
|
||||
--local ovisible = object.visible
|
||||
local ohover = object.hover
|
||||
local ostate = object.state
|
||||
if ostate ~= state then
|
||||
self.visible = false
|
||||
return
|
||||
end
|
||||
self.visible = ohover
|
||||
if ohover then
|
||||
local top = self:IsTopInternal()
|
||||
local followcursor = self.followcursor
|
||||
local followobject = self.followobject
|
||||
local xoffset = self.xoffset
|
||||
local yoffset = self.yoffset
|
||||
if followcursor then
|
||||
local height = self.height
|
||||
local mx, my = love.mouse.getPosition()
|
||||
self.x = mx + xoffset
|
||||
self.y = my - height + yoffset
|
||||
elseif followobject then
|
||||
local ox = object.x
|
||||
local oy = object.y
|
||||
self.x = ox + xoffset
|
||||
self.y = oy + yoffset
|
||||
end
|
||||
if not top then
|
||||
self:MoveToTop()
|
||||
end
|
||||
textobject:SetPos(padding, padding)
|
||||
end
|
||||
end
|
||||
|
||||
--textobject:SetVisible(self.show)
|
||||
textobject:SetState(selfstate)
|
||||
textobject:update(dt)
|
||||
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetFollowCursor(bool)
|
||||
- desc: sets whether or not the tooltip should follow the
|
||||
cursor
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:SetFollowCursor(bool)
|
||||
|
||||
self.followcursor = bool
|
||||
return self
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetFollowCursor()
|
||||
- desc: gets whether or not the tooltip should follow the
|
||||
cursor
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetFollowCursor()
|
||||
|
||||
return self.followcursor
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetObject(object)
|
||||
- desc: sets the tooltip's object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:SetObject(object)
|
||||
|
||||
self.object = object
|
||||
self.x = object.x
|
||||
self.y = object.y
|
||||
|
||||
return self
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetObject()
|
||||
- desc: gets the tooltip's object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetObject()
|
||||
|
||||
return self.object
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetText(text)
|
||||
- desc: sets the tooltip's text
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:SetText(text)
|
||||
|
||||
local internals = self.internals
|
||||
local textobject = internals[1]
|
||||
|
||||
textobject:SetText(text)
|
||||
return self
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetText()
|
||||
- desc: gets the tooltip's text
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetText()
|
||||
|
||||
local internals = self.internals
|
||||
local textobject = internals[1]
|
||||
local text = textobject:GetText()
|
||||
|
||||
return text
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetTextMaxWidth(text)
|
||||
- desc: sets the tooltip's text max width
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:SetTextMaxWidth(width)
|
||||
|
||||
local internals = self.internals
|
||||
local textobject = internals[1]
|
||||
|
||||
textobject:SetMaxWidth(width)
|
||||
return self
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetOffsetX(xoffset)
|
||||
- desc: sets the tooltip's x offset
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:SetOffsetX(xoffset)
|
||||
|
||||
self.xoffset = xoffset
|
||||
return self
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetOffsetX()
|
||||
- desc: gets the tooltip's x offset
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetOffsetX()
|
||||
|
||||
return self.xoffset
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetOffsetY(yoffset)
|
||||
- desc: sets the tooltip's y offset
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:SetOffsetY(yoffset)
|
||||
|
||||
self.yoffset = yoffset
|
||||
return self
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetOffsetY()
|
||||
- desc: gets the tooltip's y offset
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetOffsetY()
|
||||
|
||||
return self.yoffset
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetOffsets(xoffset, yoffset)
|
||||
- desc: sets the tooltip's x and y offset
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:SetOffsets(xoffset, yoffset)
|
||||
|
||||
self.xoffset = xoffset
|
||||
self.yoffset = yoffset
|
||||
|
||||
return self
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetOffsets()
|
||||
- desc: gets the tooltip's x and y offset
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetOffsets()
|
||||
|
||||
return self.xoffset, self.yoffset
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetPadding(padding)
|
||||
- desc: sets the tooltip's padding
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:SetPadding(padding)
|
||||
|
||||
self.padding = padding
|
||||
return self
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetPadding()
|
||||
- desc: gets the tooltip's padding
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetPadding()
|
||||
|
||||
return self.padding
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetFont(font)
|
||||
- desc: sets the tooltip's font
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:SetFont(font)
|
||||
|
||||
local internals = self.internals
|
||||
local textobject = internals[1]
|
||||
|
||||
textobject:SetFont(font)
|
||||
return self
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetFont()
|
||||
- desc: gets the tooltip's font
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetFont()
|
||||
|
||||
local internals = self.internals
|
||||
local textobject = internals[1]
|
||||
|
||||
return textobject:GetFont()
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetFollowObject(bool)
|
||||
- desc: sets whether or not the tooltip should follow
|
||||
its assigned object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:SetFollowObject(bool)
|
||||
|
||||
self.followobject = bool
|
||||
return self
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetFollowObject()
|
||||
- desc: gets whether or not the tooltip should follow
|
||||
its assigned object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetFollowObject()
|
||||
|
||||
return self.followobject
|
||||
|
||||
end
|
||||
|
||||
---------- module end ----------
|
||||
end
|
296
loveframes/objects/internal/treenode.lua
Normal file
296
loveframes/objects/internal/treenode.lua
Normal file
@ -0,0 +1,296 @@
|
||||
--[[------------------------------------------------
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012-2014 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
return function(loveframes)
|
||||
---------- module start ----------
|
||||
|
||||
-- button object
|
||||
local newobject = loveframes.NewObject("treenode", "loveframes_object_treenode", true)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:initialize()
|
||||
|
||||
self.type = "treenode"
|
||||
self.text = "Node"
|
||||
self.width = 250
|
||||
self.height = 16
|
||||
self.level = 0
|
||||
self.leftpadding = 0
|
||||
self.lastclick = 0
|
||||
self.open = false
|
||||
self.internal = true
|
||||
self.internals = {}
|
||||
self.icon = nil
|
||||
self.OnOpen = nil
|
||||
self.OnClose = nil
|
||||
|
||||
self:SetDrawFunc()
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:update(dt)
|
||||
|
||||
local state = loveframes.state
|
||||
local selfstate = self.state
|
||||
|
||||
if state ~= selfstate then
|
||||
return
|
||||
end
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if not visible then
|
||||
if not alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
local parent = self.parent
|
||||
local base = loveframes.base
|
||||
local update = self.Update
|
||||
|
||||
local tree = self.tree
|
||||
self:SetClickBounds(tree.x, tree.y, tree.width, tree.height)
|
||||
|
||||
for k, v in ipairs(self.internals) do
|
||||
if v.type == "treenode" then
|
||||
if self.open then
|
||||
v.x = v.tree.x - v.tree.offsetx
|
||||
v.y = (v.tree.y + self.tree.itemheight) - v.tree.offsety
|
||||
if v.width > self.tree.itemwidth then
|
||||
self.tree.itemwidth = v.width
|
||||
end
|
||||
self.tree.itemheight = self.tree.itemheight + v.height
|
||||
v:update(dt)
|
||||
end
|
||||
else
|
||||
v:update(dt)
|
||||
end
|
||||
end
|
||||
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: draw()
|
||||
- desc: draws the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:draw()
|
||||
if loveframes.state ~= self.state then
|
||||
return
|
||||
end
|
||||
|
||||
if not self.visible then
|
||||
return
|
||||
end
|
||||
|
||||
-- set the object's draw order
|
||||
self:SetDrawOrder()
|
||||
|
||||
local drawfunc = self.Draw or self.drawfunc
|
||||
if drawfunc then
|
||||
drawfunc(self)
|
||||
end
|
||||
|
||||
local internals = self.internals
|
||||
if internals then
|
||||
for k, v in ipairs(internals) do
|
||||
if v.type == "treenode" then
|
||||
if self.open then
|
||||
v:draw()
|
||||
end
|
||||
else
|
||||
v:draw()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousepressed(x, y, button)
|
||||
- desc: called when the player presses a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:mousepressed(x, y, button)
|
||||
|
||||
local state = loveframes.state
|
||||
local selfstate = self.state
|
||||
|
||||
if state ~= selfstate then
|
||||
return
|
||||
end
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
for k, v in ipairs(self.internals) do
|
||||
v:mousepressed(x, y, button)
|
||||
end
|
||||
|
||||
if self.hover and button == 1 then
|
||||
local time = os.time()
|
||||
if self.lastclick + 0.40 > time then
|
||||
self.open = not self.open
|
||||
end
|
||||
self.lastclick = time
|
||||
local onselectnode = self.tree.OnSelectNode
|
||||
self.tree.selectednode = self
|
||||
if onselectnode then
|
||||
onselectnode(self.parent, self)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousereleased(x, y, button)
|
||||
- desc: called when the player releases a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:mousereleased(x, y, button)
|
||||
|
||||
local state = loveframes.state
|
||||
local selfstate = self.state
|
||||
|
||||
if state ~= selfstate then
|
||||
return
|
||||
end
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
for k, v in ipairs(self.internals) do
|
||||
v:mousereleased(x, y, button)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetIcon(icon)
|
||||
- desc: sets the object's icon
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:SetIcon(icon)
|
||||
|
||||
if type(icon) == "string" then
|
||||
self.icon = love.graphics.newImage(icon)
|
||||
self.icon:setFilter("nearest", "nearest")
|
||||
else
|
||||
self.icon = icon
|
||||
end
|
||||
|
||||
return self
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetIcon()
|
||||
- desc: gets the object's icon
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetIcon()
|
||||
|
||||
return self.icon
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetText(text)
|
||||
- desc: sets the object's text
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:SetText(text)
|
||||
|
||||
self.text = text
|
||||
return self
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetText()
|
||||
- desc: gets the object's text
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetText()
|
||||
|
||||
return self.text
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: AddNode(text)
|
||||
- desc: adds a new node to the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:AddNode(text)
|
||||
|
||||
if not self.internals[1] then
|
||||
local openbutton = loveframes.objects["treenodebutton"]:new()
|
||||
openbutton.parent = self
|
||||
openbutton.staticx = 2
|
||||
openbutton.staticy = 2
|
||||
table.insert(self.internals, openbutton)
|
||||
end
|
||||
|
||||
local node = loveframes.objects["treenode"]:new()
|
||||
node.parent = self
|
||||
node.tree = self.tree
|
||||
node.text = text
|
||||
node.level = self.level + 1
|
||||
table.insert(self.internals, node)
|
||||
return node
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: RemoveNode(id)
|
||||
- desc: removes a node from the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:RemoveNode(id)
|
||||
|
||||
id = id + 1
|
||||
for k, v in ipairs(self.internals) do
|
||||
if k == id then
|
||||
v:Remove()
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetOpen(bool)
|
||||
- desc: sets whether or not the object is open
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:SetOpen(bool)
|
||||
|
||||
self.open = bool
|
||||
return self
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetOpen()
|
||||
- desc: gets whether or not the object is open
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetOpen()
|
||||
|
||||
return self.open
|
||||
|
||||
end
|
||||
|
||||
---------- module end ----------
|
||||
end
|
108
loveframes/objects/internal/treenodebutton.lua
Normal file
108
loveframes/objects/internal/treenodebutton.lua
Normal file
@ -0,0 +1,108 @@
|
||||
--[[------------------------------------------------
|
||||
-- Love Frames - A GUI library for LOVE --
|
||||
-- Copyright (c) 2012-2014 Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
return function(loveframes)
|
||||
---------- module start ----------
|
||||
|
||||
-- button object
|
||||
local newobject = loveframes.NewObject("treenodebutton", "loveframes_object_treenodebutton", true)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:initialize()
|
||||
|
||||
self.type = "treenodebutton"
|
||||
self.width = 16
|
||||
self.height = 16
|
||||
self.internal = true
|
||||
|
||||
self:SetDrawFunc()
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:update(dt)
|
||||
|
||||
local state = loveframes.state
|
||||
local selfstate = self.state
|
||||
|
||||
if state ~= selfstate then
|
||||
return
|
||||
end
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if not visible then
|
||||
if not alwaysupdate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
local parent = self.parent
|
||||
local base = loveframes.base
|
||||
local update = self.Update
|
||||
|
||||
-- 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 update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousepressed(x, y, button)
|
||||
- desc: called when the player presses a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:mousepressed(x, y, button)
|
||||
|
||||
local state = loveframes.state
|
||||
local selfstate = self.state
|
||||
|
||||
if state ~= selfstate then
|
||||
return
|
||||
end
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
|
||||
if hover and button == 1 then
|
||||
local bool = not self.parent.open
|
||||
if bool then
|
||||
local onopen = self.parent.OnOpen
|
||||
if onopen then
|
||||
onopen(self.parent)
|
||||
end
|
||||
else
|
||||
local onclose = self.parent.OnClose
|
||||
if onclose then
|
||||
onclose(self.parent)
|
||||
end
|
||||
end
|
||||
self.parent:SetOpen(bool)
|
||||
print("!")
|
||||
print(self.parent.level)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
---------- module end ----------
|
||||
end
|
Reference in New Issue
Block a user