2012-05-06 00:24:42 +00:00
|
|
|
--[[------------------------------------------------
|
2012-09-29 23:20:41 +00:00
|
|
|
-- Love Frames - A GUI library for LOVE --
|
2014-01-14 11:29:11 +00:00
|
|
|
-- Copyright (c) 2012-2014 Kenny Shields --
|
2012-05-06 00:24:42 +00:00
|
|
|
--]]------------------------------------------------
|
|
|
|
|
2013-11-25 13:06:41 +00:00
|
|
|
-- list object
|
2012-11-24 22:42:16 +00:00
|
|
|
local newobject = loveframes.NewObject("list", "loveframes_object_list", true)
|
2012-05-06 00:24:42 +00:00
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: initialize()
|
|
|
|
- desc: initializes the object
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:initialize()
|
2012-05-06 00:24:42 +00:00
|
|
|
|
2012-12-28 12:19:02 +00:00
|
|
|
self.type = "list"
|
|
|
|
self.display = "vertical"
|
|
|
|
self.width = 300
|
|
|
|
self.height = 150
|
|
|
|
self.clickx = 0
|
|
|
|
self.clicky = 0
|
|
|
|
self.padding = 0
|
|
|
|
self.spacing = 0
|
|
|
|
self.offsety = 0
|
|
|
|
self.offsetx = 0
|
|
|
|
self.extrawidth = 0
|
|
|
|
self.extraheight = 0
|
2013-06-10 16:34:01 +00:00
|
|
|
self.buttonscrollamount = 0.10
|
|
|
|
self.mousewheelscrollamount = 10
|
2012-12-28 12:19:02 +00:00
|
|
|
self.internal = false
|
|
|
|
self.hbar = false
|
|
|
|
self.vbar = false
|
|
|
|
self.autoscroll = false
|
2013-02-11 21:15:40 +00:00
|
|
|
self.horizontalstacking = false
|
2013-06-10 16:34:01 +00:00
|
|
|
self.dtscrolling = false
|
2012-12-28 12:19:02 +00:00
|
|
|
self.internals = {}
|
|
|
|
self.children = {}
|
|
|
|
self.OnScroll = nil
|
2012-05-06 00:24:42 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: update(deltatime)
|
|
|
|
- desc: updates the object
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:update(dt)
|
2012-05-06 00:24:42 +00:00
|
|
|
|
2013-02-11 21:15:40 +00:00
|
|
|
local state = loveframes.state
|
|
|
|
local selfstate = self.state
|
|
|
|
|
|
|
|
if state ~= selfstate then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2012-12-28 12:19:02 +00:00
|
|
|
local visible = self.visible
|
2012-09-02 00:56:32 +00:00
|
|
|
local alwaysupdate = self.alwaysupdate
|
2012-05-22 07:10:18 +00:00
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if not visible then
|
|
|
|
if not alwaysupdate then
|
2012-05-06 00:24:42 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-28 12:19:02 +00:00
|
|
|
local internals = self.internals
|
|
|
|
local children = self.children
|
|
|
|
local display = self.display
|
|
|
|
local parent = self.parent
|
2013-02-11 21:15:40 +00:00
|
|
|
local horizontalstacking = self.horizontalstacking
|
2012-12-28 12:19:02 +00:00
|
|
|
local base = loveframes.base
|
|
|
|
local update = self.Update
|
2012-05-22 07:10:18 +00:00
|
|
|
|
2012-05-06 00:24:42 +00:00
|
|
|
-- move to parent if there is a parent
|
2012-09-29 23:20:41 +00:00
|
|
|
if parent ~= base then
|
2012-05-06 00:24:42 +00:00
|
|
|
self.x = self.parent.x + self.staticx
|
|
|
|
self.y = self.parent.y + self.staticy
|
|
|
|
end
|
|
|
|
|
|
|
|
self:CheckHover()
|
|
|
|
|
2012-05-22 07:10:18 +00:00
|
|
|
for k, v in ipairs(internals) do
|
2012-05-06 00:24:42 +00:00
|
|
|
v:update(dt)
|
|
|
|
end
|
|
|
|
|
2013-02-11 21:15:40 +00:00
|
|
|
local x = self.x
|
|
|
|
local y = self.y
|
|
|
|
local width = self.width
|
|
|
|
local height = self.height
|
|
|
|
local offsetx = self.offsetx
|
|
|
|
local offsety = self.offsety
|
|
|
|
|
2012-05-22 07:10:18 +00:00
|
|
|
for k, v in ipairs(children) do
|
2014-01-20 22:20:08 +00:00
|
|
|
local col = loveframes.util.BoundingBox(x, v.x, y, v.y, width, v.width, height, v.height)
|
|
|
|
if col then
|
|
|
|
v:update(dt)
|
|
|
|
end
|
2013-02-11 21:15:40 +00:00
|
|
|
v:SetClickBounds(x, y, width, height)
|
|
|
|
v.x = (v.parent.x + v.staticx) - offsetx
|
|
|
|
v.y = (v.parent.y + v.staticy) - offsety
|
2012-05-22 07:10:18 +00:00
|
|
|
if display == "vertical" then
|
2012-05-06 00:24:42 +00:00
|
|
|
if v.lastheight ~= v.height then
|
|
|
|
self:CalculateSize()
|
|
|
|
self:RedoLayout()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if update then
|
|
|
|
update(self, dt)
|
2012-05-06 00:24:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: draw()
|
|
|
|
- desc: draws the object
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:draw()
|
2012-05-06 00:24:42 +00:00
|
|
|
|
2013-02-11 21:15:40 +00:00
|
|
|
local state = loveframes.state
|
|
|
|
local selfstate = self.state
|
|
|
|
|
|
|
|
if state ~= selfstate then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2012-05-22 07:10:18 +00:00
|
|
|
local visible = self.visible
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if not visible then
|
2012-05-06 00:24:42 +00:00
|
|
|
return
|
|
|
|
end
|
2012-09-02 00:56:32 +00:00
|
|
|
|
2013-02-11 21:15:40 +00:00
|
|
|
local x = self.x
|
|
|
|
local y = self.y
|
|
|
|
local width = self.width
|
|
|
|
local height = self.height
|
2013-08-12 13:48:51 +00:00
|
|
|
local stencilfunc = function() love.graphics.rectangle("fill", x, y, width, height) end
|
2012-12-28 12:19:02 +00:00
|
|
|
local internals = self.internals
|
|
|
|
local children = self.children
|
|
|
|
local skins = loveframes.skins.available
|
|
|
|
local skinindex = loveframes.config["ACTIVESKIN"]
|
|
|
|
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
|
|
|
local selfskin = self.skin
|
|
|
|
local skin = skins[selfskin] or skins[skinindex]
|
|
|
|
local drawfunc = skin.DrawList or skins[defaultskin].DrawList
|
|
|
|
local drawoverfunc = skin.DrawOverList or skins[defaultskin].DrawOverList
|
|
|
|
local draw = self.Draw
|
|
|
|
local drawcount = loveframes.drawcount
|
2012-09-29 23:20:41 +00:00
|
|
|
|
2012-10-22 14:19:02 +00:00
|
|
|
-- set the object's draw order
|
|
|
|
self:SetDrawOrder()
|
2014-01-20 22:20:08 +00:00
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if draw then
|
|
|
|
draw(self)
|
2012-05-06 00:24:42 +00:00
|
|
|
else
|
2012-09-02 00:56:32 +00:00
|
|
|
drawfunc(self)
|
2012-05-06 00:24:42 +00:00
|
|
|
end
|
|
|
|
|
2014-04-03 22:55:46 +00:00
|
|
|
love.graphics.setStencil(stencilfunc)
|
2012-05-06 00:24:42 +00:00
|
|
|
|
2012-05-22 07:10:18 +00:00
|
|
|
for k, v in ipairs(children) do
|
2013-02-11 21:15:40 +00:00
|
|
|
local col = loveframes.util.BoundingBox(x, v.x, y, v.y, width, v.width, height, v.height)
|
|
|
|
if col then
|
2012-05-06 00:24:42 +00:00
|
|
|
v:draw()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
love.graphics.setStencil()
|
|
|
|
|
2012-05-22 07:10:18 +00:00
|
|
|
for k, v in ipairs(internals) do
|
2012-05-06 00:24:42 +00:00
|
|
|
v:draw()
|
|
|
|
end
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if not draw then
|
|
|
|
drawoverfunc(self)
|
2012-05-06 00:24:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: mousepressed(x, y, button)
|
|
|
|
- desc: called when the player presses a mouse button
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:mousepressed(x, y, button)
|
2012-05-06 00:24:42 +00:00
|
|
|
|
2013-02-11 21:15:40 +00:00
|
|
|
local state = loveframes.state
|
|
|
|
local selfstate = self.state
|
|
|
|
|
|
|
|
if state ~= selfstate then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2012-05-22 07:10:18 +00:00
|
|
|
local visible = self.visible
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if not visible then
|
2012-05-06 00:24:42 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2012-12-28 12:19:02 +00:00
|
|
|
local toplist = self:IsTopList()
|
|
|
|
local hover = self.hover
|
|
|
|
local vbar = self.vbar
|
|
|
|
local hbar = self.hbar
|
2012-11-20 21:04:57 +00:00
|
|
|
local scrollamount = self.mousewheelscrollamount
|
2012-12-28 12:19:02 +00:00
|
|
|
local children = self.children
|
|
|
|
local internals = self.internals
|
2012-05-06 00:24:42 +00:00
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if hover and button == "l" then
|
2012-05-06 00:24:42 +00:00
|
|
|
local baseparent = self:GetBaseParent()
|
|
|
|
if baseparent and baseparent.type == "frame" then
|
|
|
|
baseparent:MakeTop()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if vbar or hbar then
|
|
|
|
if toplist then
|
2012-05-06 00:24:42 +00:00
|
|
|
local bar = self:GetScrollBar()
|
2013-02-11 21:15:40 +00:00
|
|
|
local dtscrolling = self.dtscrolling
|
|
|
|
if dtscrolling then
|
|
|
|
local dt = love.timer.getDelta()
|
|
|
|
if button == "wu" then
|
|
|
|
bar:Scroll(-scrollamount * dt)
|
|
|
|
elseif button == "wd" then
|
|
|
|
bar:Scroll(scrollamount * dt)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if button == "wu" then
|
|
|
|
bar:Scroll(-scrollamount)
|
|
|
|
elseif button == "wd" then
|
|
|
|
bar:Scroll(scrollamount)
|
|
|
|
end
|
2012-05-06 00:24:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-05-22 07:10:18 +00:00
|
|
|
for k, v in ipairs(internals) do
|
2012-05-06 00:24:42 +00:00
|
|
|
v:mousepressed(x, y, button)
|
|
|
|
end
|
|
|
|
|
2012-05-22 07:10:18 +00:00
|
|
|
for k, v in ipairs(children) do
|
2012-05-06 00:24:42 +00:00
|
|
|
v:mousepressed(x, y, button)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: AddItem(object)
|
|
|
|
- desc: adds an item to the object
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:AddItem(object)
|
2012-05-06 00:24:42 +00:00
|
|
|
|
2013-11-25 13:06:41 +00:00
|
|
|
local objtype = object.type
|
|
|
|
if objtype == "frame" then
|
2012-05-06 00:24:42 +00:00
|
|
|
return
|
|
|
|
end
|
2012-05-22 07:10:18 +00:00
|
|
|
|
|
|
|
local children = self.children
|
2013-06-24 15:11:02 +00:00
|
|
|
local state = self.state
|
2012-05-06 00:24:42 +00:00
|
|
|
|
2013-03-23 19:50:44 +00:00
|
|
|
-- remove the item object from its current parent and make its new parent the list object
|
2012-05-06 00:24:42 +00:00
|
|
|
object:Remove()
|
|
|
|
object.parent = self
|
2013-06-24 15:11:02 +00:00
|
|
|
object:SetState(state)
|
2012-05-06 00:24:42 +00:00
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
-- insert the item object into the list object's children table
|
2012-05-22 07:10:18 +00:00
|
|
|
table.insert(children, object)
|
2012-05-06 00:24:42 +00:00
|
|
|
|
2013-03-23 19:50:44 +00:00
|
|
|
-- resize the list and redo its layout
|
2012-05-06 00:24:42 +00:00
|
|
|
self:CalculateSize()
|
|
|
|
self:RedoLayout()
|
|
|
|
|
2014-02-11 12:34:07 +00:00
|
|
|
return self
|
|
|
|
|
2012-05-06 00:24:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
2013-02-11 21:15:40 +00:00
|
|
|
- func: RemoveItem(object or number)
|
2012-05-06 00:24:42 +00:00
|
|
|
- desc: removes an item from the object
|
|
|
|
--]]---------------------------------------------------------
|
2013-02-11 21:15:40 +00:00
|
|
|
function newobject:RemoveItem(data)
|
2012-05-06 00:24:42 +00:00
|
|
|
|
2013-02-11 21:15:40 +00:00
|
|
|
local dtype = type(data)
|
|
|
|
|
|
|
|
if dtype == "number" then
|
|
|
|
local children = self.children
|
|
|
|
local item = children[data]
|
|
|
|
if item then
|
|
|
|
item:Remove()
|
|
|
|
end
|
|
|
|
else
|
2013-03-05 19:46:01 +00:00
|
|
|
data:Remove()
|
2013-02-11 21:15:40 +00:00
|
|
|
end
|
2012-05-06 00:24:42 +00:00
|
|
|
|
2013-03-05 19:46:01 +00:00
|
|
|
self:CalculateSize()
|
|
|
|
self:RedoLayout()
|
|
|
|
|
2014-02-11 12:34:07 +00:00
|
|
|
return self
|
|
|
|
|
2012-05-06 00:24:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: CalculateSize()
|
|
|
|
- desc: calculates the size of the object's children
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:CalculateSize()
|
2012-05-06 00:24:42 +00:00
|
|
|
|
2012-12-28 12:19:02 +00:00
|
|
|
local numitems = #self.children
|
|
|
|
local height = self.height
|
|
|
|
local width = self.width
|
|
|
|
local padding = self.padding
|
|
|
|
local spacing = self.spacing
|
|
|
|
local itemheight = self.padding
|
|
|
|
local itemwidth = self.padding
|
|
|
|
local display = self.display
|
|
|
|
local vbar = self.vbar
|
|
|
|
local hbar = self.hbar
|
|
|
|
local internals = self.internals
|
|
|
|
local children = self.children
|
2013-02-11 21:15:40 +00:00
|
|
|
local horizontalstacking = self.horizontalstacking
|
2012-05-06 00:24:42 +00:00
|
|
|
|
|
|
|
if display == "vertical" then
|
2013-02-11 21:15:40 +00:00
|
|
|
if horizontalstacking then
|
|
|
|
local curwidth = 0
|
|
|
|
local maxwidth = width - padding * 2
|
|
|
|
local prevheight = 0
|
|
|
|
local scrollbar = self:GetScrollBar()
|
|
|
|
if scrollbar then
|
|
|
|
maxwidth = maxwidth - scrollbar.width
|
|
|
|
end
|
|
|
|
for k, v in ipairs(children) do
|
|
|
|
if v.height > prevheight then
|
|
|
|
prevheight = v.height
|
|
|
|
end
|
|
|
|
curwidth = curwidth + v.width + spacing
|
|
|
|
if children[k + 1] then
|
|
|
|
if curwidth + children[k + 1].width > maxwidth then
|
|
|
|
curwidth = padding
|
|
|
|
itemheight = itemheight + prevheight + spacing
|
|
|
|
prevheight = 0
|
|
|
|
end
|
|
|
|
else
|
|
|
|
itemheight = itemheight + prevheight + padding
|
|
|
|
end
|
|
|
|
end
|
|
|
|
self.itemheight = itemheight
|
|
|
|
else
|
|
|
|
for k, v in ipairs(children) do
|
|
|
|
itemheight = itemheight + v.height + spacing
|
|
|
|
end
|
|
|
|
self.itemheight = (itemheight - spacing) + padding
|
2012-05-06 00:24:42 +00:00
|
|
|
end
|
2012-05-22 07:10:18 +00:00
|
|
|
local itemheight = self.itemheight
|
|
|
|
if itemheight > height then
|
2012-09-29 23:20:41 +00:00
|
|
|
self.extraheight = itemheight - height
|
|
|
|
if not vbar then
|
2012-11-24 22:42:16 +00:00
|
|
|
local scrollbar = loveframes.objects["scrollbody"]:new(self, display)
|
2012-05-22 07:10:18 +00:00
|
|
|
table.insert(internals, scrollbar)
|
2012-05-06 00:24:42 +00:00
|
|
|
self.vbar = true
|
2012-05-16 10:36:01 +00:00
|
|
|
self:GetScrollBar().autoscroll = self.autoscroll
|
2012-05-06 00:24:42 +00:00
|
|
|
end
|
|
|
|
else
|
2012-09-29 23:20:41 +00:00
|
|
|
if vbar then
|
2012-05-22 07:10:18 +00:00
|
|
|
local bar = internals[1]
|
|
|
|
bar:Remove()
|
2012-05-06 00:24:42 +00:00
|
|
|
self.vbar = false
|
|
|
|
self.offsety = 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
elseif display == "horizontal" then
|
2012-05-22 07:10:18 +00:00
|
|
|
for k, v in ipairs(children) do
|
2012-05-06 00:24:42 +00:00
|
|
|
itemwidth = itemwidth + v.width + spacing
|
|
|
|
end
|
|
|
|
self.itemwidth = (itemwidth - spacing) + padding
|
2012-05-22 07:10:18 +00:00
|
|
|
local itemwidth = self.itemwidth
|
|
|
|
if itemwidth > width then
|
2012-09-29 23:20:41 +00:00
|
|
|
self.extrawidth = itemwidth - width
|
|
|
|
if not hbar then
|
2012-11-24 22:42:16 +00:00
|
|
|
local scrollbar = loveframes.objects["scrollbody"]:new(self, display)
|
2012-05-22 07:10:18 +00:00
|
|
|
table.insert(internals, scrollbar)
|
2012-05-06 00:24:42 +00:00
|
|
|
self.hbar = true
|
2012-05-16 10:36:01 +00:00
|
|
|
self:GetScrollBar().autoscroll = self.autoscroll
|
2012-05-06 00:24:42 +00:00
|
|
|
end
|
|
|
|
else
|
2012-09-29 23:20:41 +00:00
|
|
|
if hbar then
|
2012-05-22 07:10:18 +00:00
|
|
|
local bar = internals[1]
|
|
|
|
bar:Remove()
|
2012-05-06 00:24:42 +00:00
|
|
|
self.hbar = false
|
|
|
|
self.offsetx = 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-02-11 12:34:07 +00:00
|
|
|
return self
|
|
|
|
|
2012-05-06 00:24:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: RedoLayout()
|
2012-12-10 14:19:35 +00:00
|
|
|
- desc: used to redo the layout of the object
|
2012-05-06 00:24:42 +00:00
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:RedoLayout()
|
2012-05-06 00:24:42 +00:00
|
|
|
|
2013-02-11 21:15:40 +00:00
|
|
|
local width = self.width
|
|
|
|
local height = self.height
|
2012-12-10 14:19:35 +00:00
|
|
|
local children = self.children
|
2013-02-11 21:15:40 +00:00
|
|
|
local internals = self.internals
|
2012-12-28 12:19:02 +00:00
|
|
|
local padding = self.padding
|
|
|
|
local spacing = self.spacing
|
|
|
|
local starty = padding
|
|
|
|
local startx = padding
|
|
|
|
local vbar = self.vbar
|
|
|
|
local hbar = self.hbar
|
|
|
|
local display = self.display
|
2013-02-11 21:15:40 +00:00
|
|
|
local horizontalstacking = self.horizontalstacking
|
|
|
|
local scrollbody, scrollbodywidth, scrollbodyheight
|
|
|
|
|
|
|
|
if vbar or hbar then
|
|
|
|
scrollbody = internals[1]
|
|
|
|
scrollbodywidth = scrollbody.width
|
|
|
|
scrollbodyheight = scrollbody.height
|
|
|
|
end
|
2012-05-06 00:24:42 +00:00
|
|
|
|
|
|
|
if #children > 0 then
|
2013-02-11 21:15:40 +00:00
|
|
|
if display == "vertical" then
|
|
|
|
if horizontalstacking then
|
|
|
|
local curwidth = padding
|
|
|
|
local curheight = padding
|
|
|
|
local maxwidth = self.width - padding * 2
|
|
|
|
local prevheight = 0
|
|
|
|
local scrollbar = self:GetScrollBar()
|
|
|
|
if scrollbar then
|
|
|
|
maxwidth = maxwidth - scrollbar.width
|
|
|
|
end
|
|
|
|
for k, v in ipairs(children) do
|
|
|
|
local itemheight = v.height
|
|
|
|
v.lastheight = itemheight
|
|
|
|
v.staticx = curwidth
|
|
|
|
v.staticy = curheight
|
|
|
|
if v.height > prevheight then
|
|
|
|
prevheight = v.height
|
2012-05-06 00:24:42 +00:00
|
|
|
end
|
2013-02-11 21:15:40 +00:00
|
|
|
if children[k + 1] then
|
|
|
|
curwidth = curwidth + v.width + spacing
|
|
|
|
if curwidth + (children[k + 1].width) > maxwidth then
|
|
|
|
curwidth = padding
|
|
|
|
curheight = curheight + prevheight + spacing
|
|
|
|
prevheight = 0
|
|
|
|
end
|
2012-05-06 00:24:42 +00:00
|
|
|
end
|
2013-02-11 21:15:40 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
for k, v in ipairs(children) do
|
|
|
|
local itemwidth = v.width
|
|
|
|
local itemheight = v.height
|
|
|
|
local retainsize = v.retainsize
|
|
|
|
v.staticx = padding
|
|
|
|
v.staticy = starty
|
|
|
|
v.lastheight = itemheight
|
|
|
|
if vbar then
|
|
|
|
if itemwidth + padding > (width - scrollbodywidth) then
|
|
|
|
v:SetWidth((width - scrollbodywidth) - (padding * 2))
|
|
|
|
end
|
|
|
|
if not retainsize then
|
|
|
|
v:SetWidth((width - scrollbodywidth) - (padding * 2))
|
|
|
|
end
|
|
|
|
scrollbody.staticx = width - scrollbodywidth
|
|
|
|
scrollbody.height = height
|
|
|
|
else
|
|
|
|
if not retainsize then
|
|
|
|
v:SetWidth(width - (padding * 2))
|
|
|
|
end
|
2012-05-06 00:24:42 +00:00
|
|
|
end
|
2013-02-11 21:15:40 +00:00
|
|
|
starty = starty + itemheight
|
|
|
|
starty = starty + spacing
|
2012-05-06 00:24:42 +00:00
|
|
|
end
|
2013-02-11 21:15:40 +00:00
|
|
|
end
|
|
|
|
elseif display == "horizontal" then
|
|
|
|
for k, v in ipairs(children) do
|
|
|
|
local itemwidth = v.width
|
|
|
|
local itemheight = v.height
|
|
|
|
local retainsize = v.retainsize
|
2012-05-06 00:24:42 +00:00
|
|
|
v.staticx = startx
|
|
|
|
v.staticy = padding
|
2012-09-29 23:20:41 +00:00
|
|
|
if hbar then
|
2013-02-11 21:15:40 +00:00
|
|
|
if itemheight + padding > (height - scrollbodyheight) then
|
|
|
|
v:SetHeight((height - scrollbodyheight) - (padding * 2))
|
2012-05-06 00:24:42 +00:00
|
|
|
end
|
2013-02-11 21:15:40 +00:00
|
|
|
if not retainsize then
|
|
|
|
v:SetHeight((height - scrollbodyheight) - (padding * 2))
|
2012-05-06 00:24:42 +00:00
|
|
|
end
|
2013-02-11 21:15:40 +00:00
|
|
|
scrollbody.staticy = height - scrollbodyheight
|
|
|
|
scrollbody.width = width
|
2012-05-06 00:24:42 +00:00
|
|
|
else
|
2013-02-11 21:15:40 +00:00
|
|
|
if not retainsize then
|
|
|
|
v:SetHeight(height - (padding * 2))
|
2012-05-06 00:24:42 +00:00
|
|
|
end
|
|
|
|
end
|
2013-02-11 21:15:40 +00:00
|
|
|
startx = startx + itemwidth
|
2012-05-06 00:24:42 +00:00
|
|
|
startx = startx + spacing
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-02-11 12:34:07 +00:00
|
|
|
return self
|
|
|
|
|
2012-05-06 00:24:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetDisplayType(type)
|
|
|
|
- desc: sets the object's display type
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:SetDisplayType(type)
|
2012-05-06 00:24:42 +00:00
|
|
|
|
2012-12-28 12:19:02 +00:00
|
|
|
local children = self.children
|
2012-09-02 00:56:32 +00:00
|
|
|
local numchildren = #children
|
2012-05-22 07:10:18 +00:00
|
|
|
|
2012-12-28 12:19:02 +00:00
|
|
|
self.display = type
|
|
|
|
self.vbar = false
|
|
|
|
self.hbar = false
|
|
|
|
self.offsetx = 0
|
|
|
|
self.offsety = 0
|
2012-05-06 00:24:42 +00:00
|
|
|
self.internals = {}
|
|
|
|
|
2012-05-22 07:10:18 +00:00
|
|
|
if numchildren > 0 then
|
2012-05-06 00:24:42 +00:00
|
|
|
self:CalculateSize()
|
|
|
|
self:RedoLayout()
|
|
|
|
end
|
2014-02-11 12:34:07 +00:00
|
|
|
|
|
|
|
return self
|
2012-05-06 00:24:42 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetDisplayType()
|
|
|
|
- desc: gets the object's display type
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:GetDisplayType()
|
2012-05-06 00:24:42 +00:00
|
|
|
|
|
|
|
return self.display
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetPadding(amount)
|
|
|
|
- desc: sets the object's padding
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:SetPadding(amount)
|
2012-05-06 00:24:42 +00:00
|
|
|
|
2012-12-28 12:19:02 +00:00
|
|
|
local children = self.children
|
|
|
|
local numchildren = #children
|
2012-05-22 07:10:18 +00:00
|
|
|
|
2012-05-06 00:24:42 +00:00
|
|
|
self.padding = amount
|
|
|
|
|
2012-05-22 07:10:18 +00:00
|
|
|
if numchildren > 0 then
|
2012-05-06 00:24:42 +00:00
|
|
|
self:CalculateSize()
|
|
|
|
self:RedoLayout()
|
|
|
|
end
|
|
|
|
|
2014-02-11 12:34:07 +00:00
|
|
|
return self
|
|
|
|
|
2012-05-06 00:24:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetSpacing(amount)
|
|
|
|
- desc: sets the object's spacing
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:SetSpacing(amount)
|
2012-05-06 00:24:42 +00:00
|
|
|
|
2012-12-28 12:19:02 +00:00
|
|
|
local children = self.children
|
|
|
|
local numchildren = #children
|
2012-05-22 07:10:18 +00:00
|
|
|
|
2012-05-06 00:24:42 +00:00
|
|
|
self.spacing = amount
|
|
|
|
|
2012-05-22 07:10:18 +00:00
|
|
|
if numchildren > 0 then
|
2012-05-06 00:24:42 +00:00
|
|
|
self:CalculateSize()
|
|
|
|
self:RedoLayout()
|
|
|
|
end
|
|
|
|
|
2014-02-11 12:34:07 +00:00
|
|
|
return self
|
|
|
|
|
2012-05-06 00:24:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: Clear()
|
|
|
|
- desc: removes all of the object's children
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:Clear()
|
2012-05-06 00:24:42 +00:00
|
|
|
|
|
|
|
self.children = {}
|
|
|
|
self:CalculateSize()
|
|
|
|
self:RedoLayout()
|
2014-02-11 12:34:07 +00:00
|
|
|
|
|
|
|
return self
|
2012-05-06 00:24:42 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetWidth(width)
|
|
|
|
- desc: sets the object's width
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:SetWidth(width)
|
2012-05-06 00:24:42 +00:00
|
|
|
|
|
|
|
self.width = width
|
|
|
|
self:CalculateSize()
|
|
|
|
self:RedoLayout()
|
|
|
|
|
2014-02-11 12:34:07 +00:00
|
|
|
return self
|
|
|
|
|
2012-05-06 00:24:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetHeight(height)
|
|
|
|
- desc: sets the object's height
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:SetHeight(height)
|
2012-05-06 00:24:42 +00:00
|
|
|
|
|
|
|
self.height = height
|
|
|
|
self:CalculateSize()
|
|
|
|
self:RedoLayout()
|
|
|
|
|
2014-02-11 12:34:07 +00:00
|
|
|
return self
|
|
|
|
|
2012-05-06 00:24:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetSize()
|
|
|
|
- desc: gets the object's size
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:SetSize(width, height)
|
2012-05-06 00:24:42 +00:00
|
|
|
|
|
|
|
self.width = width
|
|
|
|
self.height = height
|
|
|
|
self:CalculateSize()
|
|
|
|
self:RedoLayout()
|
|
|
|
|
2014-02-11 12:34:07 +00:00
|
|
|
return self
|
|
|
|
|
2012-05-06 00:24:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetScrollBar()
|
|
|
|
- desc: gets the object's scroll bar
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:GetScrollBar()
|
2012-05-06 00:24:42 +00:00
|
|
|
|
2012-12-28 12:19:02 +00:00
|
|
|
local vbar = self.vbar
|
|
|
|
local hbar = self.hbar
|
2012-09-29 23:20:41 +00:00
|
|
|
local internals = self.internals
|
2012-05-13 03:57:27 +00:00
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if vbar or hbar then
|
|
|
|
local scrollbody = internals[1]
|
|
|
|
local scrollarea = scrollbody.internals[1]
|
2012-12-28 12:19:02 +00:00
|
|
|
local scrollbar = scrollarea.internals[1]
|
2012-05-13 03:57:27 +00:00
|
|
|
return scrollbar
|
|
|
|
else
|
|
|
|
return false
|
|
|
|
end
|
2012-05-06 00:24:42 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetAutoScroll(bool)
|
|
|
|
- desc: sets whether or not the list's scrollbar should
|
|
|
|
auto scroll to the bottom when a new object is
|
|
|
|
added to the list
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:SetAutoScroll(bool)
|
2012-05-06 00:24:42 +00:00
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
local scrollbar = self:GetScrollBar()
|
|
|
|
|
2012-05-06 00:24:42 +00:00
|
|
|
self.autoscroll = bool
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if scrollbar then
|
|
|
|
scrollbar.autoscroll = bool
|
2012-05-17 10:40:29 +00:00
|
|
|
end
|
|
|
|
|
2014-02-11 12:34:07 +00:00
|
|
|
return self
|
|
|
|
|
2012-11-20 21:04:57 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetButtonScrollAmount(speed)
|
|
|
|
- desc: sets the scroll amount of the object's scrollbar
|
|
|
|
buttons
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:SetButtonScrollAmount(amount)
|
2012-11-20 21:04:57 +00:00
|
|
|
|
|
|
|
self.buttonscrollamount = amount
|
2014-02-11 12:34:07 +00:00
|
|
|
return self
|
2012-11-20 21:04:57 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetButtonScrollAmount()
|
|
|
|
- desc: gets the scroll amount of the object's scrollbar
|
|
|
|
buttons
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:GetButtonScrollAmount()
|
2012-11-20 21:04:57 +00:00
|
|
|
|
|
|
|
return self.buttonscrollamount
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetMouseWheelScrollAmount(amount)
|
|
|
|
- desc: sets the scroll amount of the mouse wheel
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:SetMouseWheelScrollAmount(amount)
|
2012-11-20 21:04:57 +00:00
|
|
|
|
|
|
|
self.mousewheelscrollamount = amount
|
2014-02-11 12:34:07 +00:00
|
|
|
return self
|
2012-11-20 21:04:57 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetMouseWheelScrollAmount()
|
|
|
|
- desc: gets the scroll amount of the mouse wheel
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:GetButtonScrollAmount()
|
2012-11-20 21:04:57 +00:00
|
|
|
|
|
|
|
return self.mousewheelscrollamount
|
|
|
|
|
2013-02-11 21:15:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: EnableHorizontalStacking(bool)
|
|
|
|
- desc: enables or disables horizontal stacking
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:EnableHorizontalStacking(bool)
|
|
|
|
|
|
|
|
local children = self.children
|
|
|
|
local numchildren = #children
|
|
|
|
|
|
|
|
self.horizontalstacking = bool
|
|
|
|
|
|
|
|
if numchildren > 0 then
|
|
|
|
self:CalculateSize()
|
|
|
|
self:RedoLayout()
|
|
|
|
end
|
|
|
|
|
2014-02-11 12:34:07 +00:00
|
|
|
return self
|
|
|
|
|
2013-02-11 21:15:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetHorizontalStacking()
|
|
|
|
- desc: gets whether or not the object allows horizontal
|
|
|
|
stacking
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:GetHorizontalStacking()
|
|
|
|
|
|
|
|
return self.horizontalstacking
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetDTScrolling(bool)
|
|
|
|
- desc: sets whether or not the object should use delta
|
|
|
|
time when scrolling
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:SetDTScrolling(bool)
|
|
|
|
|
|
|
|
self.dtscrolling = bool
|
2014-02-11 12:34:07 +00:00
|
|
|
return self
|
2013-02-11 21:15:40 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetDTScrolling()
|
|
|
|
- desc: gets whether or not the object should use delta
|
|
|
|
time when scrolling
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:GetDTScrolling()
|
|
|
|
|
|
|
|
return self.dtscrolling
|
|
|
|
|
2012-05-06 00:24:42 +00:00
|
|
|
end
|