2013-02-11 21:15:40 +00:00
|
|
|
--[[------------------------------------------------
|
|
|
|
-- Love Frames - A GUI library for LOVE --
|
2014-01-14 11:29:11 +00:00
|
|
|
-- Copyright (c) 2012-2014 Kenny Shields --
|
2013-02-11 21:15:40 +00:00
|
|
|
--]]------------------------------------------------
|
|
|
|
|
2014-10-23 22:36:16 +00:00
|
|
|
-- get the current require path
|
|
|
|
local path = string.sub(..., 1, string.len(...) - string.len(".objects.internal.scrollable.scrollbody"))
|
|
|
|
local loveframes = require(path .. ".libraries.common")
|
|
|
|
|
2013-02-11 21:15:40 +00:00
|
|
|
-- 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")
|
2014-01-25 03:17:48 +00:00
|
|
|
upbutton.staticx = 0 + self.width - upbutton.width
|
|
|
|
upbutton.staticy = 0
|
2013-02-11 21:15:40 +00:00
|
|
|
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
|
2014-01-25 03:17:48 +00:00
|
|
|
downbutton.staticx = 0 + self.width - downbutton.width
|
|
|
|
downbutton.staticy = 0 + self.height - downbutton.height
|
2013-02-11 21:15:40 +00:00
|
|
|
downbutton.Update = function(object, dt)
|
|
|
|
downbutton.staticx = 0 + self.width - downbutton.width
|
|
|
|
downbutton.staticy = 0 + self.height - downbutton.height
|
2014-09-20 18:07:09 +00:00
|
|
|
downbutton.x = downbutton.parent.x + downbutton.staticx
|
|
|
|
downbutton.y = downbutton.parent.y + downbutton.staticy
|
2013-02-11 21:15:40 +00:00
|
|
|
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
|
2014-01-25 03:17:48 +00:00
|
|
|
leftbutton.staticx = 0
|
|
|
|
leftbutton.staticy = 0
|
2013-02-11 21:15:40 +00:00
|
|
|
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
|
2014-01-25 03:17:48 +00:00
|
|
|
rightbutton.staticx = 0 + self.width - rightbutton.width
|
|
|
|
rightbutton.staticy = 0
|
2013-02-11 21:15:40 +00:00
|
|
|
rightbutton.Update = function(object, dt)
|
|
|
|
rightbutton.staticx = 0 + self.width - rightbutton.width
|
|
|
|
rightbutton.staticy = 0
|
2014-09-20 18:07:09 +00:00
|
|
|
rightbutton.x = rightbutton.parent.x + rightbutton.staticx
|
|
|
|
rightbutton.y = rightbutton.parent.y + rightbutton.staticy
|
2013-02-11 21:15:40 +00:00
|
|
|
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
|
|
|
|
|
2013-06-24 15:11:02 +00:00
|
|
|
local parentstate = parent.state
|
|
|
|
self:SetState(parentstate)
|
2013-02-11 21:15:40 +00:00
|
|
|
|
|
|
|
-- apply template properties to the object
|
|
|
|
loveframes.templates.ApplyToObject(self)
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2014-08-16 18:35:26 +00:00
|
|
|
self:CheckHover()
|
|
|
|
|
2013-02-11 21:15:40 +00:00
|
|
|
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
|
|
|
|
|
2014-10-25 14:25:31 +00:00
|
|
|
-- resize to parent
|
|
|
|
if parent ~= base then
|
|
|
|
if self.bartype == "vertical" then
|
|
|
|
self.height = self.parent.height
|
|
|
|
self.staticx = self.parent.width - self.width
|
2014-10-25 18:58:36 +00:00
|
|
|
if parent.hbar then self.height = self.height - parent:GetHorizontalScrollBody().height end
|
2014-10-25 14:25:31 +00:00
|
|
|
elseif self.bartype == "horizontal" then
|
|
|
|
self.width = self.parent.width
|
|
|
|
self.staticy = self.parent.height - self.height
|
2014-10-25 18:58:36 +00:00
|
|
|
if parent.vbar then self.width = self.width - parent:GetVerticalScrollBody().width end
|
2014-10-25 14:25:31 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-09-20 18:03:08 +00:00
|
|
|
for k, v in ipairs(internals) do
|
|
|
|
v:update(dt)
|
|
|
|
end
|
|
|
|
|
2013-02-11 21:15:40 +00:00
|
|
|
if update then
|
|
|
|
update(self, dt)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: draw()
|
|
|
|
- desc: draws the object
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:draw()
|
|
|
|
|
|
|
|
local visible = self.visible
|
|
|
|
|
|
|
|
if not visible then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local skins = loveframes.skins.available
|
|
|
|
local skinindex = loveframes.config["ACTIVESKIN"]
|
|
|
|
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
|
|
|
local selfskin = self.skin
|
|
|
|
local skin = skins[selfskin] or skins[skinindex]
|
|
|
|
local drawfunc = skin.DrawScrollBody or skins[defaultskin].DrawScrollBody
|
|
|
|
local draw = self.Draw
|
|
|
|
local drawcount = loveframes.drawcount
|
|
|
|
local internals = self.internals
|
|
|
|
|
|
|
|
-- set the object's draw order
|
|
|
|
self:SetDrawOrder()
|
|
|
|
|
|
|
|
if draw then
|
|
|
|
draw(self)
|
|
|
|
else
|
|
|
|
drawfunc(self)
|
|
|
|
end
|
|
|
|
|
|
|
|
for k, v in ipairs(internals) do
|
|
|
|
v:draw()
|
|
|
|
end
|
|
|
|
|
2014-08-23 19:51:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetScrollBar()
|
|
|
|
- desc: gets the object's scroll bar
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:GetScrollBar()
|
|
|
|
|
|
|
|
return self.internals[1].internals[1]
|
|
|
|
|
2014-11-09 21:24:10 +00:00
|
|
|
end
|