Added time controls and nice clock face

This commit is contained in:
2024-04-11 21:42:11 -06:00
parent a8df373f93
commit f3da84db34
107 changed files with 25454 additions and 49 deletions

View 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

View 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

View 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

View 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