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

1295
loveframes/objects/base.lua Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,298 @@
--[[------------------------------------------------
-- Love Frames - A GUI library for LOVE --
-- Copyright (c) 2012-2014 Kenny Shields --
--]]------------------------------------------------
return function(loveframes)
---------- module start ----------
-- button object
local newobject = loveframes.NewObject("button", "loveframes_object_button", true)
--[[---------------------------------------------------------
- func: initialize()
- desc: initializes the object
--]]---------------------------------------------------------
function newobject:initialize()
self.type = "button"
self.text = "Button"
self.width = 80
self.height = 25
self.internal = false
self.down = false
self.clickable = true
self.enabled = true
self.toggleable = false
self.toggle = false
self.OnClick = nil
self.groupIndex = 0
self.checked = false
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 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
if downobject == self then
self.hover = true
end
else
if downobject == self then
self.down = true
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
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 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 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
if self.groupIndex ~= 0 then
local baseparent = self.parent
if baseparent then
for k, v in ipairs(baseparent.children) do
if v.groupIndex then
if v.groupIndex == self.groupIndex then
v.checked = false
end
end
end
end
self.checked = true
end
if onclick then
onclick(self, x, y)
end
if self.toggleable then
local ontoggle = self.OnToggle
self.toggle = not self.toggle
if ontoggle then
ontoggle(self, self.toggle)
end
end
end
end
self.down = false
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: 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: SetClickable(bool)
- desc: sets whether the object can be clicked or not
--]]---------------------------------------------------------
function newobject:SetClickable(bool)
self.clickable = bool
return self
end
--[[---------------------------------------------------------
- func: GetClickable(bool)
- desc: gets whether the object can be clicked or not
--]]---------------------------------------------------------
function newobject:GetClickable()
return self.clickable
end
--[[---------------------------------------------------------
- func: SetClickable(bool)
- desc: sets whether or not the object is enabled
--]]---------------------------------------------------------
function newobject:SetEnabled(bool)
self.enabled = bool
return self
end
--[[---------------------------------------------------------
- func: GetEnabled()
- desc: gets whether or not the object is enabled
--]]---------------------------------------------------------
function newobject:GetEnabled()
return self.enabled
end
--[[---------------------------------------------------------
- func: GetDown()
- desc: gets whether or not the object is currently
being pressed
--]]---------------------------------------------------------
function newobject:GetDown()
return self.down
end
--[[---------------------------------------------------------
- func: SetToggleable(bool)
- desc: sets whether or not the object is toggleable
--]]---------------------------------------------------------
function newobject:SetToggleable(bool)
self.toggleable = bool
return self
end
--[[---------------------------------------------------------
- func: GetToggleable()
- desc: gets whether or not the object is toggleable
--]]---------------------------------------------------------
function newobject:GetToggleable()
return self.toggleable
end
---------- module end ----------
end

View File

@ -0,0 +1,429 @@
--[[------------------------------------------------
-- Love Frames - A GUI library for LOVE --
-- Copyright (c) 2012-2014 Kenny Shields --
--]]------------------------------------------------
return function(loveframes)
---------- module start ----------
-- checkbox object
local newobject = loveframes.NewObject("checkbox", "loveframes_object_checkbox", true)
--[[---------------------------------------------------------
- func: initialize()
- desc: initializes the object
--]]---------------------------------------------------------
function newobject:initialize()
self.type = "checkbox"
self.width = 0
self.height = 0
self.boxwidth = 16
self.boxheight = 16
self.font = loveframes.basicfont
self.checked = false
self.lastvalue = false
self.internal = false
self.down = true
self.enabled = true
self.internals = {}
self.OnChanged = nil
self.groupIndex = 0
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 internals = self.internals
local boxwidth = self.boxwidth
local boxheight = self.boxheight
local parent = self.parent
local base = loveframes.base
local update = self.Update
if not hover then
self.down = false
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 and parent.type ~= "list" then
self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy
end
if internals[1] then
self.width = boxwidth + 5 + internals[1].width
if internals[1].height == boxheight then
self.height = boxheight
else
if internals[1].height > boxheight then
self.height = internals[1].height
else
self.height = boxheight
end
end
else
self.width = boxwidth
self.height = boxheight
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 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 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 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 down = self.down
local enabled = self.enabled
local checked = self.checked
local onchanged = self.OnChanged
if hover and down and enabled and button == 1 then
if checked then
if self.groupIndex == 0 then self.checked = false end
else
if self.groupIndex ~= 0 then
local baseparent = self.parent
if baseparent then
for k, v in ipairs(baseparent.children) do
if v.groupIndex then
if v.groupIndex == self.groupIndex then
v.checked = false
end
end
end
end
end
self.checked = true
end
if onchanged then
onchanged(self, self.checked)
end
end
end
--[[---------------------------------------------------------
- func: SetText(text)
- desc: sets the object's text
--]]---------------------------------------------------------
function newobject:SetText(text)
local boxwidth = self.boxwidth
local boxheight = self.boxheight
if text ~= "" then
self.internals = {}
local textobject = loveframes.Create("text")
local skin = loveframes.GetActiveSkin()
if not skin then
skin = loveframes.config["DEFAULTSKIN"]
end
local directives = skin.directives
if directives then
local default_color = directives.checkbox_text_default_color
local default_shadowcolor = directives.checkbox_text_default_shadowcolor
local default_font = directives.checkbox_text_default_font
if default_color then
textobject.defaultcolor = default_color
end
if default_shadowcolor then
textobject.shadowcolor = default_shadowcolor
end
if default_font then
self.font = default_font
end
end
textobject:Remove()
textobject.parent = self
textobject.state = self.state
textobject.collide = false
textobject:SetFont(self.font)
textobject:SetText(text)
textobject.Update = function(object, dt)
if object.height > boxheight then
object:SetPos(boxwidth + 5, 0)
else
object:SetPos(boxwidth + 5, boxheight/2 - object.height/2)
end
end
table.insert(self.internals, textobject)
else
self.width = boxwidth
self.height = boxheight
self.internals = {}
end
return self
end
--[[---------------------------------------------------------
- func: GetText()
- desc: gets the object's text
--]]---------------------------------------------------------
function newobject:GetText()
local internals = self.internals
local text = internals[1]
if text then
return text.text
else
return false
end
end
--[[---------------------------------------------------------
- func: SetSize(width, height, r1, r2)
- desc: sets the object's size
--]]---------------------------------------------------------
function newobject:SetSize(width, height, r1, r2)
if r1 then
self.boxwidth = self.parent.width * width
else
self.boxwidth = width
end
if r2 then
self.boxheight = self.parent.height * height
else
self.boxheight = height
end
return self
end
--[[---------------------------------------------------------
- func: SetWidth(width, relative)
- desc: sets the object's width
--]]---------------------------------------------------------
function newobject:SetWidth(width, relative)
if relative then
self.boxwidth = self.parent.width * width
else
self.boxwidth = width
end
return self
end
--[[---------------------------------------------------------
- func: SetHeight(height, relative)
- desc: sets the object's height
--]]---------------------------------------------------------
function newobject:SetHeight(height, relative)
if relative then
self.boxheight = self.parent.height * height
else
self.boxheight = height
end
return self
end
--[[---------------------------------------------------------
- func: SetChecked(bool)
- desc: sets whether the object is checked or not
--]]---------------------------------------------------------
function newobject:SetChecked(bool)
local onchanged = self.OnChanged
self.checked = bool
if onchanged then
onchanged(self)
end
return self
end
--[[---------------------------------------------------------
- func: GetChecked()
- desc: gets whether the object is checked or not
--]]---------------------------------------------------------
function newobject:GetChecked()
return self.checked
end
--[[---------------------------------------------------------
- func: SetFont(font)
- desc: sets the font of the object's text
--]]---------------------------------------------------------
function newobject:SetFont(font)
local internals = self.internals
local text = internals[1]
self.font = font
if text then
text:SetFont(font)
end
return self
end
--[[---------------------------------------------------------
- func: newobject:GetFont()
- desc: gets the font of the object's text
--]]---------------------------------------------------------
function newobject:GetFont()
return self.font
end
--[[---------------------------------------------------------
- func: newobject:GetBoxHeight()
- desc: gets the object's box size
--]]---------------------------------------------------------
function newobject:GetBoxSize()
return self.boxwidth, self.boxheight
end
--[[---------------------------------------------------------
- func: newobject:GetBoxWidth()
- desc: gets the object's box width
--]]---------------------------------------------------------
function newobject:GetBoxWidth()
return self.boxwidth
end
--[[---------------------------------------------------------
- func: newobject:GetBoxHeight()
- desc: gets the object's box height
--]]---------------------------------------------------------
function newobject:GetBoxHeight()
return self.boxheight
end
--[[---------------------------------------------------------
- func: SetClickable(bool)
- desc: sets whether or not the object is enabled
--]]---------------------------------------------------------
function newobject:SetEnabled(bool)
self.enabled = bool
return self
end
--[[---------------------------------------------------------
- func: GetEnabled()
- desc: gets whether or not the object is enabled
--]]---------------------------------------------------------
function newobject:GetEnabled()
return self.enabled
end
---------- module end ----------
end

View File

@ -0,0 +1,328 @@
--[[------------------------------------------------
-- Love Frames - A GUI library for LOVE --
-- Copyright (c) 2012-2014 Kenny Shields --
--]]------------------------------------------------
return function(loveframes)
---------- module start ----------
-- collapsiblecategory object
local newobject = loveframes.NewObject("collapsiblecategory", "loveframes_object_collapsiblecategory", true)
--[[---------------------------------------------------------
- func: initialize()
- desc: initializes the object
--]]---------------------------------------------------------
function newobject:initialize()
self.type = "collapsiblecategory"
self.text = "Category"
self.width = 200
self.height = 25
self.closedheight = 25
self.padding = 5
self.internal = false
self.open = false
self.down = false
self.children = {}
self.OnOpenedClosed = nil
self: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 open = self.open
local children = self.children
local curobject = children[1]
local parent = self.parent
local base = loveframes.base
local update = self.Update
self:CheckHover()
-- move to parent if there is a parent
if parent ~= base and parent.type ~= "list" then
self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy
end
if open and curobject then
curobject:SetWidth(self.width - self.padding * 2)
curobject:update(dt)
elseif not open and curobject then
if curobject:GetVisible() then
curobject:SetVisible(false)
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 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 open = self.open
local children = self.children
local curobject = children[1]
if hover then
local col = loveframes.BoundingBox(self.x, x, self.y, y, self.width, 1, self.closedheight, 1)
if button == 1 and col then
local baseparent = self:GetBaseParent()
if baseparent and baseparent.type == "frame" then
baseparent:MakeTop()
end
self.down = true
loveframes.downobject = self
end
end
if open and curobject then
curobject: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 hover = self.hover
local down = self.down
local clickable = self.clickable
local enabled = self.enabled
local open = self.open
local col = loveframes.BoundingBox(self.x, x, self.y, y, self.width, 1, self.closedheight, 1)
local children = self.children
local curobject = children[1]
if hover and col and down and button == 1 then
if open then
self:SetOpen(false)
else
self:SetOpen(true)
end
self.down = false
end
if open and curobject then
curobject:mousereleased(x, y, button)
end
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: SetObject(object)
- desc: sets the category's object
--]]---------------------------------------------------------
function newobject:SetObject(object)
local children = self.children
local curobject = children[1]
if curobject then
curobject:Remove()
self.children = {}
end
object:Remove()
object.parent = self
object:SetState(self.state)
object:SetWidth(self.width - self.padding*2)
object:SetPos(self.padding, self.closedheight + self.padding)
table.insert(self.children, object)
return self
end
--[[---------------------------------------------------------
- func: SetObject(object)
- desc: sets the category's object
--]]---------------------------------------------------------
function newobject:GetObject()
local children = self.children
local curobject = children[1]
if curobject then
return curobject
else
return false
end
end
--[[---------------------------------------------------------
- func: SetSize(width, height, relative)
- desc: sets the object's size
--]]---------------------------------------------------------
function newobject:SetSize(width, height, relative)
if relative then
self.width = self.parent.width * width
else
self.width = width
end
return self
end
--[[---------------------------------------------------------
- func: SetHeight(height)
- desc: sets the object's height
--]]---------------------------------------------------------
function newobject:SetHeight(height)
return self
end
--[[---------------------------------------------------------
- func: SetClosedHeight(height)
- desc: sets the object's closed height
--]]---------------------------------------------------------
function newobject:SetClosedHeight(height)
self.closedheight = height
return self
end
--[[---------------------------------------------------------
- func: GetClosedHeight()
- desc: gets the object's closed height
--]]---------------------------------------------------------
function newobject:GetClosedHeight()
return self.closedheight
end
--[[---------------------------------------------------------
- func: SetOpen(bool)
- desc: sets whether the object is opened or closed
--]]---------------------------------------------------------
function newobject:SetOpen(bool)
local children = self.children
local curobject = children[1]
local closedheight = self.closedheight
local padding = self.padding
local onopenedclosed = self.OnOpenedClosed
self.open = bool
if not bool then
self.height = closedheight
if curobject then
local curobjectheight = curobject.height
curobject:SetVisible(false)
end
else
if curobject then
local curobjectheight = curobject.height
self.height = closedheight + padding * 2 + curobjectheight
curobject:SetVisible(true)
end
end
-- call the on opened closed callback if it exists
if onopenedclosed then
onopenedclosed(self)
end
return self
end
--[[---------------------------------------------------------
- func: GetOpen()
- desc: gets whether the object is opened or closed
--]]---------------------------------------------------------
function newobject:GetOpen()
return self.open
end
---------- module end ----------
end

View File

@ -0,0 +1,984 @@
--[[------------------------------------------------
-- Love Frames - A GUI library for LOVE --
-- Copyright (c) 2012-2014 Kenny Shields --
--]]------------------------------------------------
return function(loveframes)
---------- module start ----------
-- columnlist object
local newobject = loveframes.NewObject("columnlist", "loveframes_object_columnlist", true)
--[[---------------------------------------------------------
- func: initialize()
- desc: intializes the element
--]]---------------------------------------------------------
function newobject:initialize()
self.type = "columnlist"
self.width = 300
self.height = 100
self.defaultcolumnwidth = 100
self.columnheight = 16
self.buttonscrollamount = 200
self.mousewheelscrollamount = 1500
self.autoscroll = false
self.dtscrolling = true
self.internal = false
self.selectionenabled = true
self.multiselect = false
self.startadjustment = false
self.canresizecolumns = true
self.children = {}
self.internals = {}
self.resizecolumn = nil
self.OnRowClicked = nil
self.OnRowRightClicked = nil
self.OnRowSelected = nil
self.OnScroll = nil
local list = loveframes.objects["columnlistarea"]:new(self)
table.insert(self.internals, list)
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 parent = self.parent
local base = loveframes.base
local children = self.children
local internals = self.internals
local update = self.Update
self:CheckHover()
-- move to parent if there is a parent
if parent ~= base then
self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy
end
for k, v in ipairs(internals) do
v:update(dt)
end
for k, v in ipairs(children) do
v.columnid = k
v:update(dt)
end
self.startadjustment = false
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 vbody = self.internals[1]:GetVerticalScrollBody()
local hbody = self.internals[1]:GetHorizontalScrollBody()
local width = self.width
local height = self.height
if vbody then
width = width - vbody.width
end
if hbody then
height = height - hbody.height
end
local stencilfunc = function()
love.graphics.rectangle("fill", self.x, self.y, width, height)
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
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
v:draw()
end
end
local drawfunc = self.DrawOver or self.drawoverfunc
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 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 children = self.children
local internals = self.internals
if 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(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 children = self.children
local internals = self.internals
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: PositionColumns()
- desc: positions the object's columns
--]]---------------------------------------------------------
function newobject:PositionColumns()
local x = 0
for k, v in ipairs(self.children) do
v:SetPos(x, 0)
x = x + v.width
end
return self
end
--[[---------------------------------------------------------
- func: AddColumn(name)
- desc: gives the object a new column with the specified
name
--]]---------------------------------------------------------
function newobject:AddColumn(name)
local internals = self.internals
local list = internals[1]
local width = self.width
local height = self.height
loveframes.objects["columnlistheader"]:new(name, self)
self:PositionColumns()
list:SetSize(width, height)
list:SetPos(0, 0)
return self
end
--[[---------------------------------------------------------
- func: AddRow(...)
- desc: adds a row of data to the object's list
--]]---------------------------------------------------------
function newobject:AddRow(...)
local arg = {...}
local internals = self.internals
local list = internals[1]
list:AddRow(arg)
return self
end
--[[---------------------------------------------------------
- func: Getchildrenize()
- desc: gets the size of the object's children
--]]---------------------------------------------------------
function newobject:GetColumnSize()
local children = self.children
local numchildren = #self.children
if numchildren > 0 then
local column = self.children[1]
local colwidth = column.width
local colheight = column.height
return colwidth, colheight
else
return 0, 0
end
end
--[[---------------------------------------------------------
- func: SetSize(width, height, r1, r2)
- desc: sets the object's size
--]]---------------------------------------------------------
function newobject:SetSize(width, height, r1, r2)
local internals = self.internals
local list = internals[1]
if r1 then
self.width = self.parent.width * width
else
self.width = width
end
if r2 then
self.height = self.parent.height * height
else
self.height = height
end
self:PositionColumns()
list:SetSize(width, height)
list:SetPos(0, 0)
list:CalculateSize()
list:RedoLayout()
return self
end
--[[---------------------------------------------------------
- func: SetWidth(width, relative)
- desc: sets the object's width
--]]---------------------------------------------------------
function newobject:SetWidth(width, relative)
local internals = self.internals
local list = internals[1]
if relative then
self.width = self.parent.width * width
else
self.width = width
end
self:PositionColumns()
list:SetSize(width)
list:SetPos(0, 0)
list:CalculateSize()
list:RedoLayout()
return self
end
--[[---------------------------------------------------------
- func: SetHeight(height, relative)
- desc: sets the object's height
--]]---------------------------------------------------------
function newobject:SetHeight(height, relative)
local internals = self.internals
local list = internals[1]
if relative then
self.height = self.parent.height * height
else
self.height = height
end
self:PositionColumns()
list:SetSize(height)
list:SetPos(0, 0)
list:CalculateSize()
list:RedoLayout()
return self
end
--[[---------------------------------------------------------
- func: SetMaxColorIndex(num)
- desc: sets the object's max color index for
alternating row colors
--]]---------------------------------------------------------
function newobject:SetMaxColorIndex(num)
local internals = self.internals
local list = internals[1]
list.colorindexmax = num
return self
end
--[[---------------------------------------------------------
- func: Clear()
- desc: removes all items from the object's list
--]]---------------------------------------------------------
function newobject:Clear()
local internals = self.internals
local list = internals[1]
list:Clear()
return self
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
--]]---------------------------------------------------------
function newobject:SetAutoScroll(bool)
local internals = self.internals
local list = internals[1]
local scrollbar = list:GetScrollBar()
self.autoscroll = bool
if list then
if scrollbar then
scrollbar.autoscroll = bool
end
end
return self
end
--[[---------------------------------------------------------
- func: SetButtonScrollAmount(speed)
- desc: sets the scroll amount of the object's scrollbar
buttons
--]]---------------------------------------------------------
function newobject:SetButtonScrollAmount(amount)
self.buttonscrollamount = amount
self.internals[1].buttonscrollamount = amount
return self
end
--[[---------------------------------------------------------
- func: GetButtonScrollAmount()
- desc: gets the scroll amount of the object's scrollbar
buttons
--]]---------------------------------------------------------
function newobject:GetButtonScrollAmount()
return self.buttonscrollamount
end
--[[---------------------------------------------------------
- func: SetMouseWheelScrollAmount(amount)
- desc: sets the scroll amount of the mouse wheel
--]]---------------------------------------------------------
function newobject:SetMouseWheelScrollAmount(amount)
self.mousewheelscrollamount = amount
self.internals[1].mousewheelscrollamount = amount
return self
end
--[[---------------------------------------------------------
- func: GetMouseWheelScrollAmount()
- desc: gets the scroll amount of the mouse wheel
--]]---------------------------------------------------------
function newobject:GetButtonScrollAmount()
return self.mousewheelscrollamount
end
--[[---------------------------------------------------------
- func: SetColumnHeight(height)
- desc: sets the height of the object's columns
--]]---------------------------------------------------------
function newobject:SetColumnHeight(height)
local children = self.children
local internals = self.internals
local list = internals[1]
self.columnheight = height
for k, v in ipairs(children) do
v:SetHeight(height)
end
list:CalculateSize()
list:RedoLayout()
return self
end
--[[---------------------------------------------------------
- func: SetDTScrolling(bool)
- desc: sets whether or not the object should use delta
time when scrolling
--]]---------------------------------------------------------
function newobject:SetDTScrolling(bool)
self.dtscrolling = bool
self.internals[1].dtscrolling = bool
return self
end
--[[---------------------------------------------------------
- func: GetDTScrolling()
- desc: gets whether or not the object should use delta
time when scrolling
--]]---------------------------------------------------------
function newobject:GetDTScrolling()
return self.dtscrolling
end
--[[---------------------------------------------------------
- func: SelectRow(row, ctrl)
- desc: selects the specfied row in the object's list
of rows
--]]---------------------------------------------------------
function newobject:SelectRow(row, ctrl)
local selectionenabled = self.selectionenabled
if not selectionenabled then
return
end
local list = self.internals[1]
local children = list.children
local multiselect = self.multiselect
local onrowselected = self.OnRowSelected
for k, v in ipairs(children) do
if v == row then
if v.selected and ctrl then
v.selected = false
else
v.selected = true
if onrowselected then
onrowselected(self, row, row:GetColumnData())
end
end
elseif v ~= row then
if not (multiselect and ctrl) then
v.selected = false
end
end
end
return self
end
--[[---------------------------------------------------------
- func: DeselectRow(row)
- desc: deselects the specfied row in the object's list
of rows
--]]---------------------------------------------------------
function newobject:DeselectRow(row)
row.selected = false
return self
end
--[[---------------------------------------------------------
- func: GetSelectedRows()
- desc: gets the object's selected rows
--]]---------------------------------------------------------
function newobject:GetSelectedRows()
local rows = {}
local list = self.internals[1]
local children = list.children
for k, v in ipairs(children) do
if v.selected then
table.insert(rows, v)
end
end
return rows
end
--[[---------------------------------------------------------
- func: SetSelectionEnabled(bool)
- desc: sets whether or not the object's rows can be
selected
--]]---------------------------------------------------------
function newobject:SetSelectionEnabled(bool)
self.selectionenabled = bool
return self
end
--[[---------------------------------------------------------
- func: GetSelectionEnabled()
- desc: gets whether or not the object's rows can be
selected
--]]---------------------------------------------------------
function newobject:GetSelectionEnabled()
return self.selectionenabled
end
--[[---------------------------------------------------------
- func: SetMultiselectEnabled(bool)
- desc: sets whether or not the object can have more
than one row selected
--]]---------------------------------------------------------
function newobject:SetMultiselectEnabled(bool)
self.multiselect = bool
return self
end
--[[---------------------------------------------------------
- func: GetMultiselectEnabled()
- desc: gets whether or not the object can have more
than one row selected
--]]---------------------------------------------------------
function newobject:GetMultiselectEnabled()
return self.multiselect
end
--[[---------------------------------------------------------
- func: RemoveColumn(id)
- desc: removes a column
--]]---------------------------------------------------------
function newobject:RemoveColumn(id)
local children = self.children
for k, v in ipairs(children) do
if k == id then
v:Remove()
end
end
return self
end
--[[---------------------------------------------------------
- func: SetColumnName(id, name)
- desc: sets a column's name
--]]---------------------------------------------------------
function newobject:SetColumnName(id, name)
local children = self.children
for k, v in ipairs(children) do
if k == id then
v.name = name
end
end
return self
end
--[[---------------------------------------------------------
- func: GetColumnName(id)
- desc: gets a column's name
--]]---------------------------------------------------------
function newobject:GetColumnName(id)
local children = self.children
for k, v in ipairs(children) do
if k == id then
return v.name
end
end
return false
end
--[[---------------------------------------------------------
- func: SizeToChildren(max)
- desc: sizes the object to match the combined height
of its children
- note: Credit to retupmoc258, the original author of
this method. This version has a few slight
modifications.
--]]---------------------------------------------------------
function newobject:SizeToChildren(max)
local oldheight = self.height
local list = self.internals[1]
local listchildren = list.children
local children = self.children
local width = self.width
local buf = children[1].height
local h = listchildren[1].height
local c = #listchildren
local height = buf + h*c
if max then
height = math.min(max, oldheight)
end
self:SetSize(width, height)
self:PositionColumns()
return self
end
--[[---------------------------------------------------------
- func: RemoveRow(id)
- desc: removes a row from the object's list
--]]---------------------------------------------------------
function newobject:RemoveRow(id)
local list = self.internals[1]
local listchildren = list.children
local row = listchildren[id]
if row then
row:Remove()
end
list:CalculateSize()
list:RedoLayout()
return self
end
--[[---------------------------------------------------------
- func: SetCellText(text, rowid, columnid)
- desc: sets a cell's text
--]]---------------------------------------------------------
function newobject:SetCellText(text, rowid, columnid)
local list = self.internals[1]
local listchildren = list.children
local row = listchildren[rowid]
if row and row.columndata[columnid]then
row.columndata[columnid] = text
end
return self
end
--[[---------------------------------------------------------
- func: GetCellText(rowid, columnid)
- desc: gets a cell's text
--]]---------------------------------------------------------
function newobject:GetCellText(rowid, columnid)
local row = self.internals[1].children[rowid]
if row and row.columndata[columnid] then
return row.columndata[columnid]
else
return false
end
end
--[[---------------------------------------------------------
- func: SetRowColumnData(rowid, columndata)
- desc: sets the columndata of the specified row
--]]---------------------------------------------------------
function newobject:SetRowColumnData(rowid, columndata)
local list = self.internals[1]
local listchildren = list.children
local row = listchildren[rowid]
if row then
for k, v in ipairs(columndata) do
row.columndata[k] = tostring(v)
end
end
return self
end
--[[---------------------------------------------------------
- func: GetTotalColumnWidth()
- desc: gets the combined width of the object's columns
--]]---------------------------------------------------------
function newobject:GetTotalColumnWidth()
local width = 0
for k, v in ipairs(self.children) do
width = width + v.width
end
return width
end
--[[---------------------------------------------------------
- func: SetColumnWidth(id, width)
- desc: sets the width of the specified column
--]]---------------------------------------------------------
function newobject:SetColumnWidth(id, width)
local column = self.children[id]
if column then
column.width = width
local x = 0
for k, v in ipairs(self.children) do
v:SetPos(x)
x = x + v.width
end
self.internals[1]:CalculateSize()
self.internals[1]:RedoLayout()
end
return self
end
--[[---------------------------------------------------------
- func: GetColumnWidth(id)
- desc: gets the width of the specified column
--]]---------------------------------------------------------
function newobject:GetColumnWidth(id)
local column = self.children[id]
if column then
return column.width
end
return false
end
--[[---------------------------------------------------------
- func: ResizeColumns()
- desc: resizes the object's columns to fit within the
width of the object's list area
--]]---------------------------------------------------------
function newobject:ResizeColumns()
local children = self.children
local width = 0
local vbody = self.internals[1]:GetVerticalScrollBody()
if vbody then
width = (self:GetWidth() - vbody:GetWidth())/#children
else
width = self:GetWidth()/#children
end
for k, v in ipairs(children) do
v:SetWidth(width)
self:PositionColumns()
self.internals[1]:CalculateSize()
self.internals[1]:RedoLayout()
end
return self
end
--[[---------------------------------------------------------
- func: SetDefaultColumnWidth(width)
- desc: sets the object's default column width
--]]---------------------------------------------------------
function newobject:SetDefaultColumnWidth(width)
self.defaultcolumnwidth = width
return self
end
--[[---------------------------------------------------------
- func: GetDefaultColumnWidth()
- desc: gets the object's default column width
--]]---------------------------------------------------------
function newobject:GetDefaultColumnWidth()
return self.defaultcolumnwidth
end
--[[---------------------------------------------------------
- func: SetColumnResizeEnabled(bool)
- desc: sets whether or not the object's columns can
be resized
--]]---------------------------------------------------------
function newobject:SetColumnResizeEnabled(bool)
self.canresizecolumns = bool
return self
end
--[[---------------------------------------------------------
- func: GetColumnResizeEnabled()
- desc: gets whether or not the object's columns can
be resized
--]]---------------------------------------------------------
function newobject:GetColumnResizeEnabled()
return self.canresizecolumns
end
--[[---------------------------------------------------------
- func: SizeColumnToData(columnid)
- desc: sizes a column to the width of its largest data
string
--]]---------------------------------------------------------
function newobject:SizeColumnToData(columnid)
local column = self.children[columnid]
local list = self.internals[1]
local largest = 0
for k, v in ipairs(list.children) do
local width = v:GetFont():getWidth(self:GetCellText(k, columnid))
if width > largest then
largest = width + v.textx
end
end
if largest <= 0 then
largest = 10
end
self:SetColumnWidth(columnid, largest)
return self
end
--[[---------------------------------------------------------
- func: SetColumnOrder(curid, newid)
- desc: sets the order of the specified column
--]]---------------------------------------------------------
function newobject:SetColumnOrder(curid, newid)
local column = self.children[curid]
local totalcolumns = #self.children
if column and totalcolumns > 1 and newid <= totalcolumns and newid >= 1 then
column:Remove()
table.insert(self.children, newid, column)
self:PositionColumns()
end
return self
end
---------- module end ----------
end

303
loveframes/objects/form.lua Normal file
View File

@ -0,0 +1,303 @@
--[[------------------------------------------------
-- Love Frames - A GUI library for LOVE --
-- Copyright (c) 2012-2014 Kenny Shields --
--]]------------------------------------------------
return function(loveframes)
---------- module start ----------
-- form object
local newobject = loveframes.NewObject("form", "loveframes_object_form", true)
--[[---------------------------------------------------------
- func: initialize()
- desc: initializes the object
--]]---------------------------------------------------------
function newobject:initialize()
self.type = "form"
self.name = "Form"
self.layout = "vertical"
self.width = 200
self.height = 50
self.padding = 5
self.spacing = 5
self.topmargin = 12
self.internal = false
self.children = {}
self:SetDrawFunc()
end
--[[---------------------------------------------------------
- func: update(deltatime)
- desc: updates the element
--]]---------------------------------------------------------
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 children = self.children
local parent = self.parent
local base = loveframes.base
local update = self.Update
-- move to parent if there is a parent
if parent ~= base and parent.type ~= "list" then
self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy
end
self:CheckHover()
for k, v in ipairs(children) 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 state = loveframes.state
local selfstate = self.state
if state ~= selfstate then
return
end
local visible = self.visible
if not visible then
return
end
local children = self.children
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
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
local children = self.children
if not visible then
return
end
for k, v in ipairs(children) do
v:mousereleased(x, y, button)
end
end
--[[---------------------------------------------------------
- func: AddItem(object)
- desc: adds an item to the object
--]]---------------------------------------------------------
function newobject:AddItem(object)
local objtype = object.type
if objtype == "frame" then
return
end
local children = self.children
local state = self.state
object:Remove()
object.parent = self
object:SetState(state)
table.insert(children, object)
self:LayoutObjects()
return self
end
--[[---------------------------------------------------------
- func: RemoveItem(object or number)
- desc: removes an item from the object
--]]---------------------------------------------------------
function newobject:RemoveItem(data)
local dtype = type(data)
if dtype == "number" then
local children = self.children
local item = children[data]
if item then
item:Remove()
end
else
data:Remove()
end
self:LayoutObjects()
return self
end
--[[---------------------------------------------------------
- func: LayoutObjects()
- desc: positions the object's children and calculates
a new size for the object
--]]---------------------------------------------------------
function newobject:LayoutObjects()
local layout = self.layout
local padding = self.padding
local spacing = self.spacing
local topmargin = self.topmargin
local children = self.children
local width = padding * 2
local height = padding * 2 + topmargin
local x = padding
local y = padding + topmargin
if layout == "vertical" then
local largest_width = 0
for k, v in ipairs(children) do
v.staticx = x
v.staticy = y
y = y + v.height + spacing
height = height + v.height + spacing
if v.width > largest_width then
largest_width = v.width
end
end
height = height - spacing
self.width = width + largest_width
self.height = height
elseif layout == "horizontal" then
local largest_height = 0
for k, v in ipairs(children) do
v.staticx = x
v.staticy = y
x = x + v.width + spacing
width = width + v.width + spacing
if v.height > largest_height then
largest_height = v.height
end
end
width = width - spacing
self.width = width
self.height = height + largest_height
end
return self
end
--[[---------------------------------------------------------
- func: SetLayoutType(ltype)
- desc: sets the object's layout type
--]]---------------------------------------------------------
function newobject:SetLayoutType(ltype)
self.layout = ltype
return self
end
--[[---------------------------------------------------------
- func: GetLayoutType()
- desc: gets the object's layout type
--]]---------------------------------------------------------
function newobject:GetLayoutType()
return self.layout
end
--[[---------------------------------------------------------
- func: SetTopMargin(margin)
- desc: sets the margin between the top of the object
and its children
--]]---------------------------------------------------------
function newobject:SetTopMargin(margin)
self.topmargin = margin
return self
end
--[[---------------------------------------------------------
- func: GetTopMargin()
- desc: gets the margin between the top of the object
and its children
--]]---------------------------------------------------------
function newobject:GetTopMargin()
return self.topmargin
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

1111
loveframes/objects/frame.lua Normal file

File diff suppressed because it is too large Load Diff

358
loveframes/objects/grid.lua Normal file
View File

@ -0,0 +1,358 @@
--[[------------------------------------------------
-- Love Frames - A GUI library for LOVE --
-- Copyright (c) 2012-2014 Kenny Shields --
--]]------------------------------------------------
return function(loveframes)
---------- module start ----------
-- grid object
local newobject = loveframes.NewObject("grid", "loveframes_object_grid", true)
--[[---------------------------------------------------------
- func: initialize()
- desc: initializes the object
--]]---------------------------------------------------------
function newobject:initialize()
self.type = "grid"
self.width = 100
self.height = 100
self.prevwidth = 100
self.prevheight = 100
self.rows = 0
self.columns = 0
self.cellwidth = 25
self.cellheight = 25
self.cellpadding = 5
self.itemautosize = false
self.children = {}
self.OnSizeChanged = 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 children = self.children
local base = loveframes.base
-- 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
local cw = self.cellwidth + (self.cellpadding * 2)
local ch = self.cellheight + (self.cellpadding * 2)
local prevwidth = self.prevwidth
local prevheight = self.prevheight
self.width = (self.columns * self.cellwidth) + (self.columns * (self.cellpadding * 2))
self.height = (self.rows * self.cellheight) + (self.rows * (self.cellpadding * 2))
if self.width ~= prevwidth or self.height ~= prevheight then
local onsizechanged = self.OnSizeChanged
self.prevwidth = self.width
self.prevheight = self.height
if onsizechanged then
onsizechanged(self)
end
end
for k, v in ipairs(children) do
local x = 0 + ((cw * v.gridcolumn) - cw ) + (cw/2 - v.width/2)
local y = 0 + ((ch * v.gridrow) - ch) + (ch/2 - v.height/2)
v.staticx = x
v.staticy = y
v:update(dt)
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 state = loveframes.state
local selfstate = self.state
if state ~= selfstate then
return
end
local visible = self.visible
if not visible then
return
end
local children = self.children
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
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
local children = self.children
if not visible then
return
end
for k, v in ipairs(children) do
v:mousereleased(x, y, button)
end
end
--[[---------------------------------------------------------
- func: AddItem(object, row, column)
- desc: adds and item to the object
--]]---------------------------------------------------------
function newobject:AddItem(object, row, column)
local itemautosize = self.itemautosize
local children = self.children
object:Remove()
table.insert(children, object)
object.parent = self
object.gridrow = row
object.gridcolumn = column
if itemautosize then
local cw = self.cellwidth + (self.cellpadding * 2)
local ch = self.cellheight + (self.cellpadding * 2)
object.width = cw - (self.cellpadding * 2)
object.height = ch - (self.cellpadding * 2)
end
return self
end
--[[---------------------------------------------------------
- func: GetItem(row, column)
- desc: gets an item from the object at the specified
row and column
--]]---------------------------------------------------------
function newobject:GetItem(row, column)
local children = self.children
for k, v in ipairs(children) do
if v.gridrow == row and v.gridcolumn == column then
return v
end
end
return false
end
--[[---------------------------------------------------------
- func: SetItemAutoSize(bool)
- desc: sets whether or not the object should auto-size
its items
--]]---------------------------------------------------------
function newobject:SetItemAutoSize(bool)
self.itemautosize = bool
return self
end
--[[---------------------------------------------------------
- func: GetItemAutoSize()
- desc: gets whether or not the object should auto-size
its items
--]]---------------------------------------------------------
function newobject:GetItemAutoSize()
return self.itemautosize
end
--[[---------------------------------------------------------
- func: SetRows(rows)
- desc: sets the number of rows the object should have
--]]---------------------------------------------------------
function newobject:SetRows(rows)
self.rows = rows
return self
end
--[[---------------------------------------------------------
- func: SetRows(rows)
- desc: gets the number of rows the object has
--]]---------------------------------------------------------
function newobject:GetRows()
return self.rows
end
--[[---------------------------------------------------------
- func: SetColumns(columns)
- desc: sets the number of columns the object should
have
--]]---------------------------------------------------------
function newobject:SetColumns(columns)
self.columns = columns
return self
end
--[[---------------------------------------------------------
- func: GetColumns()
- desc: gets the number of columns the object has
--]]---------------------------------------------------------
function newobject:GetColumns()
return self.columns
end
--[[---------------------------------------------------------
- func: SetCellWidth(width)
- desc: sets the width of the object's cells
--]]---------------------------------------------------------
function newobject:SetCellWidth(width)
self.cellwidth = width
return self
end
--[[---------------------------------------------------------
- func: GetCellWidth()
- desc: gets the width of the object's cells
--]]---------------------------------------------------------
function newobject:GetCellWidth()
return self.cellwidth
end
--[[---------------------------------------------------------
- func: SetCellHeight(height)
- desc: sets the height of the object's cells
--]]---------------------------------------------------------
function newobject:SetCellHeight(height)
self.cellheight = height
return self
end
--[[---------------------------------------------------------
- func: GetCellHeight()
- desc: gets the height of the object's cells
--]]---------------------------------------------------------
function newobject:GetCellHeight()
return self.cellheight
end
--[[---------------------------------------------------------
- func: SetCellSize(width, height)
- desc: sets the size of the object's cells
--]]---------------------------------------------------------
function newobject:SetCellSize(width, height)
self.cellwidth = width
self.cellheight = height
return self
end
--[[---------------------------------------------------------
- func: GetCellSize()
- desc: gets the size of the object's cells
--]]---------------------------------------------------------
function newobject:GetCellSize()
return self.cellwidth, self.cellheight
end
--[[---------------------------------------------------------
- func: SetCellPadding(padding)
- desc: sets the padding of the object's cells
--]]---------------------------------------------------------
function newobject:SetCellPadding(padding)
self.cellpadding = padding
return self
end
--[[---------------------------------------------------------
- func: GetCellPadding
- desc: gets the padding of the object's cells
--]]---------------------------------------------------------
function newobject:GetCellPadding()
return self.cellpadding
end
---------- module end ----------
end

View File

@ -0,0 +1,385 @@
--[[------------------------------------------------
-- Love Frames - A GUI library for LOVE --
-- Copyright (c) 2012-2014 Kenny Shields --
--]]------------------------------------------------
return function(loveframes)
---------- module start ----------
-- image object
local newobject = loveframes.NewObject("image", "loveframes_object_image", true)
--[[---------------------------------------------------------
- func: initialize()
- desc: initializes the object
--]]---------------------------------------------------------
function newobject:initialize()
self.type = "image"
self.width = 0
self.height = 0
self.orientation = 0
self.scalex = 1
self.scaley = 1
self.offsetx = 0
self.offsety = 0
self.shearx = 0
self.sheary = 0
self.internal = false
self.image = nil
self.imagecolor = {1, 1, 1, 1}
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 parent = self.parent
local base = loveframes.base
local update = self.Update
self:CheckHover()
-- 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: SetImage(image)
- desc: sets the object's image
--]]---------------------------------------------------------
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
self.width = self.image:getWidth()
self.height = self.image:getHeight()
return self
end
--[[---------------------------------------------------------
- func: GetImage()
- desc: gets the object's image
--]]---------------------------------------------------------
function newobject:GetImage()
return self.image
end
--[[---------------------------------------------------------
- func: SetColor(r, g, b, a)
- desc: sets the object's color
--]]---------------------------------------------------------
function newobject:SetColor(r, g, b, a)
self.imagecolor = {r, g, b, a}
return self
end
--[[---------------------------------------------------------
- func: GetColor()
- desc: gets the object's color
--]]---------------------------------------------------------
function newobject:GetColor()
return unpack(self.imagecolor)
end
--[[---------------------------------------------------------
- func: SetOrientation(orientation)
- desc: sets the object's orientation
--]]---------------------------------------------------------
function newobject:SetOrientation(orientation)
self.orientation = orientation
return self
end
--[[---------------------------------------------------------
- func: GetOrientation()
- desc: gets the object's orientation
--]]---------------------------------------------------------
function newobject:GetOrientation()
return self.orientation
end
--[[---------------------------------------------------------
- func: SetScaleX(scalex)
- desc: sets the object's x scale
--]]---------------------------------------------------------
function newobject:SetScaleX(scalex)
self.scalex = scalex
return self
end
--[[---------------------------------------------------------
- func: GetScaleX()
- desc: gets the object's x scale
--]]---------------------------------------------------------
function newobject:GetScaleX()
return self.scalex
end
--[[---------------------------------------------------------
- func: SetScaleY(scaley)
- desc: sets the object's y scale
--]]---------------------------------------------------------
function newobject:SetScaleY(scaley)
self.scaley = scaley
return self
end
--[[---------------------------------------------------------
- func: GetScaleY()
- desc: gets the object's y scale
--]]---------------------------------------------------------
function newobject:GetScaleY()
return self.scaley
end
--[[---------------------------------------------------------
- func: SetScale(scalex, scaley)
- desc: sets the object's x and y scale
--]]---------------------------------------------------------
function newobject:SetScale(scalex, scaley)
self.scalex = scalex
self.scaley = scaley
return self
end
--[[---------------------------------------------------------
- func: GetScale()
- desc: gets the object's x and y scale
--]]---------------------------------------------------------
function newobject:GetScale()
return self.scalex, self.scaley
end
--[[---------------------------------------------------------
- func: SetOffsetX(x)
- desc: sets the object's x offset
--]]---------------------------------------------------------
function newobject:SetOffsetX(x)
self.offsetx = x
return self
end
--[[---------------------------------------------------------
- func: GetOffsetX()
- desc: gets the object's x offset
--]]---------------------------------------------------------
function newobject:GetOffsetX()
return self.offsetx
end
--[[---------------------------------------------------------
- func: SetOffsetY(y)
- desc: sets the object's y offset
--]]---------------------------------------------------------
function newobject:SetOffsetY(y)
self.offsety = y
return self
end
--[[---------------------------------------------------------
- func: GetOffsetY()
- desc: gets the object's y offset
--]]---------------------------------------------------------
function newobject:GetOffsetY()
return self.offsety
end
--[[---------------------------------------------------------
- func: SetOffset(x, y)
- desc: sets the object's x and y offset
--]]---------------------------------------------------------
function newobject:SetOffset(x, y)
self.offsetx = x
self.offsety = y
return self
end
--[[---------------------------------------------------------
- func: GetOffset()
- desc: gets the object's x and y offset
--]]---------------------------------------------------------
function newobject:GetOffset()
return self.offsetx, self.offsety
end
--[[---------------------------------------------------------
- func: SetShearX(shearx)
- desc: sets the object's x shear
--]]---------------------------------------------------------
function newobject:SetShearX(shearx)
self.shearx = shearx
return self
end
--[[---------------------------------------------------------
- func: GetShearX()
- desc: gets the object's x shear
--]]---------------------------------------------------------
function newobject:GetShearX()
return self.shearx
end
--[[---------------------------------------------------------
- func: SetShearY(sheary)
- desc: sets the object's y shear
--]]---------------------------------------------------------
function newobject:SetShearY(sheary)
self.sheary = sheary
return self
end
--[[---------------------------------------------------------
- func: GetShearY()
- desc: gets the object's y shear
--]]---------------------------------------------------------
function newobject:GetShearY()
return self.sheary
end
--[[---------------------------------------------------------
- func: SetShear(shearx, sheary)
- desc: sets the object's x and y shear
--]]---------------------------------------------------------
function newobject:SetShear(shearx, sheary)
self.shearx = shearx
self.sheary = sheary
return self
end
--[[---------------------------------------------------------
- func: GetShear()
- desc: gets the object's x and y shear
--]]---------------------------------------------------------
function newobject:GetShear()
return self.shearx, self.sheary
end
--[[---------------------------------------------------------
- func: GetImageSize()
- desc: gets the size of the object's image
--]]---------------------------------------------------------
function newobject:GetImageSize()
local image = self.image
if image then
return image:getWidth(), image:getHeight()
end
end
--[[---------------------------------------------------------
- func: GetImageWidth()
- desc: gets the width of the object's image
--]]---------------------------------------------------------
function newobject:GetImageWidth()
local image = self.image
if image then
return image:getWidth()
end
end
--[[---------------------------------------------------------
- func: GetImageWidth()
- desc: gets the height of the object's image
--]]---------------------------------------------------------
function newobject:GetImageHeight()
local image = self.image
if image then
return image:getHeight()
end
end
---------- module end ----------
end

View File

@ -0,0 +1,343 @@
--[[------------------------------------------------
-- Love Frames - A GUI library for LOVE --
-- Copyright (c) 2012-2014 Kenny Shields --
--]]------------------------------------------------
return function(loveframes)
---------- module start ----------
-- imagebutton object
local newobject = loveframes.NewObject("imagebutton", "loveframes_object_imagebutton", true)
--[[---------------------------------------------------------
- func: initialize()
- desc: initializes the object
--]]---------------------------------------------------------
function newobject:initialize()
self.type = "imagebutton"
self.text = "Image Button"
self.width = 50
self.height = 50
self.internal = false
self.down = false
self.clickable = true
self.enabled = true
self.image = nil
self.imagecolor = {1, 1, 1, 1}
self.OnClick = nil
self.groupIndex = 0
self.checked = false
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 downobject = loveframes.downobject
local down = self.down
local parent = self.parent
local base = loveframes.base
local update = self.Update
if not hover then
self.down = false
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 = 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 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 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 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
if self.groupIndex ~= 0 then
local baseparent = self.parent
if baseparent then
for k, v in ipairs(baseparent.children) do
if v.groupIndex then
if v.groupIndex == self.groupIndex then
v.checked = false
end
end
end
end
self.checked = true
end
if onclick then
onclick(self, x, y)
end
end
end
self.down = false
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: SetClickable(bool)
- desc: sets whether the object can be clicked or not
--]]---------------------------------------------------------
function newobject:SetClickable(bool)
self.clickable = bool
return self
end
--[[---------------------------------------------------------
- func: GetClickable(bool)
- desc: gets whether the object can be clicked or not
--]]---------------------------------------------------------
function newobject:GetClickable()
return self.clickable
end
--[[---------------------------------------------------------
- func: SetClickable(bool)
- desc: sets whether the object is enabled or not
--]]---------------------------------------------------------
function newobject:SetEnabled(bool)
self.enabled = bool
return self
end
--[[---------------------------------------------------------
- func: GetEnabled()
- desc: gets whether the object is enabled or not
--]]---------------------------------------------------------
function newobject:GetEnabled()
return self.enabled
end
--[[---------------------------------------------------------
- func: SetImage(image)
- desc: sets the object's image
--]]---------------------------------------------------------
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
return self
end
--[[---------------------------------------------------------
- func: GetImage()
- desc: gets whether the object is enabled or not
--]]---------------------------------------------------------
function newobject:GetImage()
return self.image
end
--[[---------------------------------------------------------
- func: SizeToImage()
- desc: makes the object the same size as its image
--]]---------------------------------------------------------
function newobject:SizeToImage()
local image = self.image
if image then
self.width = image:getWidth()
self.height = image:getHeight()
end
return self
end
--[[---------------------------------------------------------
- func: GetImageSize()
- desc: gets the size of the object's image
--]]---------------------------------------------------------
function newobject:GetImageSize()
local image = self.image
if image then
return image:getWidth(), image:getHeight()
end
end
--[[---------------------------------------------------------
- func: GetImageWidth()
- desc: gets the width of the object's image
--]]---------------------------------------------------------
function newobject:GetImageWidth()
local image = self.image
if image then
return image:getWidth()
end
end
--[[---------------------------------------------------------
- func: GetImageWidth()
- desc: gets the height of the object's image
--]]---------------------------------------------------------
function newobject:GetImageHeight()
local image = self.image
if image then
return image:getHeight()
end
end
--[[---------------------------------------------------------
- func: SetColor(r, g, b, a)
- desc: sets the object's color
--]]---------------------------------------------------------
function newobject:SetColor(r, g, b, a)
self.imagecolor = {r, g, b, a}
return self
end
--[[---------------------------------------------------------
- func: GetColor()
- desc: gets the object's color
--]]---------------------------------------------------------
function newobject:GetColor()
return unpack(self.imagecolor)
end
---------- module end ----------
end

View 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

View 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

View 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

View 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

View 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

View 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

View 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

View 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

View 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

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

View 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

View 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

View 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

View 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

View 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

807
loveframes/objects/list.lua Normal file
View File

@ -0,0 +1,807 @@
--[[------------------------------------------------
-- Love Frames - A GUI library for LOVE --
-- Copyright (c) 2012-2014 Kenny Shields --
--]]------------------------------------------------
return function(loveframes)
---------- module start ----------
-- list object
local newobject = loveframes.NewObject("list", "loveframes_object_list", true)
--[[---------------------------------------------------------
- func: initialize()
- desc: initializes the object
--]]---------------------------------------------------------
function newobject:initialize()
self.type = "list"
self.display = "vertical"
self.width = 300
self.height = 150
self.clickx = 0
self.clicky = 0
self.padding = 0
self.spacing = 0
self.offsety = 0
self.offsetx = 0
self.extrawidth = 0
self.extraheight = 0
self.buttonscrollamount = 0.10
self.mousewheelscrollamount = 10
self.internal = false
self.hbar = false
self.vbar = false
self.autoscroll = false
self.horizontalstacking = false
self.dtscrolling = false
self.internals = {}
self.children = {}
self.OnScroll = 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 internals = self.internals
local children = self.children
local display = self.display
local parent = self.parent
local horizontalstacking = self.horizontalstacking
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
for k, v in ipairs(internals) do
v:update(dt)
for _, p in pairs(self:GetParents()) do
v.x = v.x - (p.offsetx or 0)
v.y = v.y - (p.offsety or 0)
end
end
local x = self.x
local y = self.y
local width = self.width
local height = self.height
local offsetx = self.offsetx
local offsety = self.offsety
for k, v in ipairs(children) do
v:update(dt)
v:SetClickBounds(x, y, width, height)
v.x = (v.parent.x + v.staticx) - offsetx
v.y = (v.parent.y + v.staticy) - offsety
for _, p in pairs(self:GetParents()) do
v.x = v.x - (p.offsetx or 0)
v.y = v.y - (p.offsety or 0)
end
if display == "vertical" then
if v.lastheight ~= v.height then
self:CalculateSize()
self:RedoLayout()
end
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
local x = self.x
local y = self.y
local width = self.width
local height = self.height
local stencilfunc = function()
love.graphics.rectangle("fill", x, y, width, height)
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(children) do
local col = loveframes.BoundingBox(x, v.x, y, v.y, width, v.width, height, v.height)
if col then
v:draw()
end
end
end
love.graphics.setStencilTest()
local drawfunc = self.DrawOver or self.drawoverfunc
if drawfunc then
drawfunc(self)
end
local internals = self.internals
if internals then
for k, v in ipairs(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 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 children = self.children
local internals = self.internals
if 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(internals) do
v:mousepressed(x, y, button)
end
for k, v in ipairs(children) do
v:mousepressed(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 vbar = self.vbar
local hbar = self.hbar
local scrollamount = self.mousewheelscrollamount
if (vbar or hbar) and toplist then
local bar = self:GetScrollBar()
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)
local objtype = object.type
if objtype == "frame" then
return
end
local children = self.children
local state = self.state
-- remove the item object from its current parent and make its new parent the list object
object:Remove()
object.parent = self
object:SetState(state)
-- insert the item object into the list object's children table
table.insert(children, object)
-- resize the list and redo its layout
self:CalculateSize()
self:RedoLayout()
return self
end
--[[---------------------------------------------------------
- func: RemoveItem(object or number)
- desc: removes an item from the object
--]]---------------------------------------------------------
function newobject:RemoveItem(data)
local dtype = type(data)
if dtype == "number" then
local children = self.children
local item = children[data]
if item then
item:Remove()
end
else
data:Remove()
end
self:CalculateSize()
self:RedoLayout()
return self
end
--[[---------------------------------------------------------
- func: CalculateSize()
- desc: calculates the size of the object's children
--]]---------------------------------------------------------
function newobject:CalculateSize()
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
local horizontalstacking = self.horizontalstacking
if display == "vertical" then
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
end
local itemheight = self.itemheight
if itemheight > height then
self.extraheight = itemheight - height
if not vbar then
local scrollbar = loveframes.objects["scrollbody"]:new(self, display)
table.insert(internals, scrollbar)
self.vbar = true
self:GetScrollBar().autoscroll = self.autoscroll
end
else
if vbar then
local bar = internals[1]
bar:Remove()
self.vbar = false
self.offsety = 0
end
end
elseif display == "horizontal" then
for k, v in ipairs(children) do
itemwidth = itemwidth + v.width + spacing
end
self.itemwidth = (itemwidth - spacing) + padding
local itemwidth = self.itemwidth
if itemwidth > width then
self.extrawidth = itemwidth - width
if not hbar then
local scrollbar = loveframes.objects["scrollbody"]:new(self, display)
table.insert(internals, scrollbar)
self.hbar = true
self:GetScrollBar().autoscroll = self.autoscroll
end
else
if hbar then
local bar = internals[1]
bar:Remove()
self.hbar = false
self.offsetx = 0
end
end
end
return self
end
--[[---------------------------------------------------------
- func: RedoLayout()
- desc: used to redo the layout of the object
--]]---------------------------------------------------------
function newobject:RedoLayout()
local width = self.width
local height = self.height
local children = self.children
local internals = self.internals
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
local horizontalstacking = self.horizontalstacking
local scrollbody, scrollbodywidth, scrollbodyheight
if vbar or hbar then
scrollbody = internals[1]
scrollbodywidth = scrollbody.width
scrollbodyheight = scrollbody.height
end
if #children > 0 then
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
end
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
end
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
end
starty = starty + itemheight
starty = starty + spacing
end
end
elseif display == "horizontal" then
for k, v in ipairs(children) do
local itemwidth = v.width
local itemheight = v.height
local retainsize = v.retainsize
v.staticx = startx
v.staticy = padding
if hbar then
if itemheight + padding > (height - scrollbodyheight) then
v:SetHeight((height - scrollbodyheight) - (padding * 2))
end
if not retainsize then
v:SetHeight((height - scrollbodyheight) - (padding * 2))
end
scrollbody.staticy = height - scrollbodyheight
scrollbody.width = width
else
if not retainsize then
v:SetHeight(height - (padding * 2))
end
end
startx = startx + itemwidth
startx = startx + spacing
end
end
end
return self
end
--[[---------------------------------------------------------
- func: SetDisplayType(type)
- desc: sets the object's display type
--]]---------------------------------------------------------
function newobject:SetDisplayType(type)
local children = self.children
local numchildren = #children
self.display = type
self.vbar = false
self.hbar = false
self.offsetx = 0
self.offsety = 0
self.internals = {}
if numchildren > 0 then
self:CalculateSize()
self:RedoLayout()
end
return self
end
--[[---------------------------------------------------------
- func: GetDisplayType()
- desc: gets the object's display type
--]]---------------------------------------------------------
function newobject:GetDisplayType()
return self.display
end
--[[---------------------------------------------------------
- func: SetPadding(amount)
- desc: sets the object's padding
--]]---------------------------------------------------------
function newobject:SetPadding(amount)
local children = self.children
local numchildren = #children
self.padding = amount
if numchildren > 0 then
self:CalculateSize()
self:RedoLayout()
end
return self
end
--[[---------------------------------------------------------
- func: SetSpacing(amount)
- desc: sets the object's spacing
--]]---------------------------------------------------------
function newobject:SetSpacing(amount)
local children = self.children
local numchildren = #children
self.spacing = amount
if numchildren > 0 then
self:CalculateSize()
self:RedoLayout()
end
return self
end
--[[---------------------------------------------------------
- func: Clear()
- desc: removes all of the object's children
--]]---------------------------------------------------------
function newobject:Clear()
self.children = {}
self:CalculateSize()
self:RedoLayout()
return self
end
--[[---------------------------------------------------------
- func: SetWidth(width, relative)
- desc: sets the object's width
--]]---------------------------------------------------------
function newobject:SetWidth(width, relative)
if relative then
self.width = self.parent.width * width
else
self.width = width
end
self:CalculateSize()
self:RedoLayout()
return self
end
--[[---------------------------------------------------------
- func: SetHeight(height, relative)
- desc: sets the object's height
--]]---------------------------------------------------------
function newobject:SetHeight(height, relative)
if relative then
self.height = self.parent.height * height
else
self.height = height
end
self:CalculateSize()
self:RedoLayout()
return self
end
--[[---------------------------------------------------------
- func: SetSize(width, height, r1, r2)
- desc: sets the object's size
--]]---------------------------------------------------------
function newobject:SetSize(width, height, r1, r2)
if r1 then
self.width = self.parent.width * width
else
self.width = width
end
if r2 then
self.height = self.parent.height * height
else
self.height = height
end
self:CalculateSize()
self:RedoLayout()
return self
end
--[[---------------------------------------------------------
- func: GetScrollBar()
- desc: gets the object's scroll bar
--]]---------------------------------------------------------
function newobject:GetScrollBar()
local vbar = self.vbar
local hbar = self.hbar
local internals = self.internals
if vbar or hbar then
local scrollbody = internals[1]
local scrollarea = scrollbody.internals[1]
local scrollbar = scrollarea.internals[1]
return scrollbar
else
return false
end
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
--]]---------------------------------------------------------
function newobject:SetAutoScroll(bool)
local scrollbar = self:GetScrollBar()
self.autoscroll = bool
if scrollbar then
scrollbar.autoscroll = bool
end
return self
end
--[[---------------------------------------------------------
- func: GetAutoScroll()
- desc: gets whether or not the list's scrollbar should
auto scroll to the bottom when a new object is
added to the list
--]]---------------------------------------------------------
function newobject:GetAutoScroll()
return self.autoscroll
end
--[[---------------------------------------------------------
- func: SetButtonScrollAmount(speed)
- desc: sets the scroll amount of the object's scrollbar
buttons
--]]---------------------------------------------------------
function newobject:SetButtonScrollAmount(amount)
self.buttonscrollamount = amount
return self
end
--[[---------------------------------------------------------
- func: GetButtonScrollAmount()
- desc: gets the scroll amount of the object's scrollbar
buttons
--]]---------------------------------------------------------
function newobject:GetButtonScrollAmount()
return self.buttonscrollamount
end
--[[---------------------------------------------------------
- func: SetMouseWheelScrollAmount(amount)
- desc: sets the scroll amount of the mouse wheel
--]]---------------------------------------------------------
function newobject:SetMouseWheelScrollAmount(amount)
self.mousewheelscrollamount = amount
return self
end
--[[---------------------------------------------------------
- func: GetMouseWheelScrollAmount()
- desc: gets the scroll amount of the mouse wheel
--]]---------------------------------------------------------
function newobject:GetButtonScrollAmount()
return self.mousewheelscrollamount
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
return self
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
return self
end
--[[---------------------------------------------------------
- func: GetDTScrolling()
- desc: gets whether or not the object should use delta
time when scrolling
--]]---------------------------------------------------------
function newobject:GetDTScrolling()
return self.dtscrolling
end
---------- module end ----------
end

287
loveframes/objects/menu.lua Normal file
View File

@ -0,0 +1,287 @@
--[[------------------------------------------------
-- Love Frames - A GUI library for LOVE --
-- Copyright (c) 2012-2014 Kenny Shields --
--]]------------------------------------------------
return function(loveframes)
---------- module start ----------
-- menu object
local newobject = loveframes.NewObject("menu", "loveframes_object_menu", true)
--[[---------------------------------------------------------
- func: initialize()
- desc: initializes the object
--]]---------------------------------------------------------
function newobject:initialize(menu)
self.type = "menu"
self.width = 80
self.height = 25
self.largest_item_width = 0
self.largest_item_height = 0
self.is_sub_menu = false
self.internal = false
self.parentmenu = nil
self.options = {}
self.internals = {}
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 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
for k, v in ipairs(self.internals) do
local width = v.contentwidth
local height = v.contentheight
if width > self.largest_item_width then
self.largest_item_width = width
end
if height > self.largest_item_height then
self.largest_item_height = height
end
end
local y = 0
self.height = 0
for k, v in ipairs(self.internals) do
v:SetWidth(self.largest_item_width)
if v.option_type ~= "divider" then
v:SetHeight(self.largest_item_height)
else
v:SetHeight(5)
end
v:SetY(y)
self.height = self.height + v.height
y = y + v.height
v:update(dt)
end
self.width = self.largest_item_width
self.largest_item_width = 0
self.largest_item_height = 0
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 sx + width > screen_width then
self.x = screen_width - width
end
if sy + self.height > screen_height then
self.y = screen_height - self.height
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 internals = self.internals
for k, v in ipairs(internals) do
v:mousereleased(x, y, button)
end
end
--[[---------------------------------------------------------
- func: AddOption(text, icon, func)
- desc: adds an option to the object
--]]---------------------------------------------------------
function newobject:AddOption(text, icon, func)
local menuoption = loveframes.objects["menuoption"]:new(self)
menuoption:SetText(text)
menuoption:SetIcon(icon)
menuoption:SetFunction(func)
table.insert(self.internals, menuoption)
return self
end
--[[---------------------------------------------------------
- func: RemoveOption(id)
- desc: removes an option
--]]---------------------------------------------------------
function newobject:RemoveOption(id)
for k, v in ipairs(self.internals) do
if k == id then
table.remove(self.internals, k)
return
end
end
return self
end
--[[---------------------------------------------------------
- func: AddSubMenu(text, icon, menu)
- desc: adds a submenu to the object
--]]---------------------------------------------------------
function newobject:AddSubMenu(text, icon, menu)
local function activatorFunc(object)
if menu:GetVisible() then
local hoverobject = loveframes.hoverobject
if hoverobject ~= object and hoverobject:GetBaseParent() ~= menu then
menu:SetVisible(false)
end
else
menu:SetVisible(true)
menu:SetPos(object:GetX() + object:GetWidth(), object:GetY())
end
end
menu:SetVisible(false)
local menuoption = loveframes.objects["menuoption"]:new(self, "submenu_activator", menu)
menuoption:SetText(text)
menuoption:SetIcon(icon)
if menu then
menu.is_sub_menu = true
menu.parentmenu = self
end
table.insert(self.internals, menuoption)
return self
end
--[[---------------------------------------------------------
- func: AddDivider()
- desc: adds a divider to the object
--]]---------------------------------------------------------
function newobject:AddDivider()
local menuoption = loveframes.objects["menuoption"]:new(self, "divider")
table.insert(self.internals, menuoption)
return self
end
--[[---------------------------------------------------------
- func: GetBaseMenu(t)
- desc: gets the object's base menu
--]]---------------------------------------------------------
function newobject:GetBaseMenu(t)
local t = t or {}
if self.parentmenu then
table.insert(t, self.parentmenu)
self.parentmenu:GetBaseMenu(t)
else
return self
end
return t[#t]
end
--[[---------------------------------------------------------
- func: SetVisible(bool)
- desc: sets the object's visibility
--]]---------------------------------------------------------
function newobject:SetVisible(bool)
self.visible = bool
if not bool then
local internals = self.internals
for k, v in ipairs(internals) do
if v.menu then
v.activated = false
v.menu:SetVisible(bool)
end
end
end
return self
end
---------- module end ----------
end

View File

@ -0,0 +1,418 @@
--[[------------------------------------------------
-- Love Frames - A GUI library for LOVE --
-- Copyright (c) 2012-2014 Kenny Shields --
--]]------------------------------------------------
return function(loveframes)
---------- module start ----------
-- multichoice object
local newobject = loveframes.NewObject("multichoice", "loveframes_object_multichoice", true)
--[[---------------------------------------------------------
- func: initialize()
- desc: initializes the object
--]]---------------------------------------------------------
function newobject:initialize()
self.type = "multichoice"
self.choice = ""
self.text = "Select an option"
self.width = 200
self.height = 25
self.listpadding = 0
self.listspacing = 0
self.buttonscrollamount = 200
self.mousewheelscrollamount = 1500
self.sortfunc = function(a, b) return a < b end
self.haslist = false
self.dtscrolling = true
self.enabled = true
self.internal = false
self.choices = {}
self.listheight = 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
local parent = self.parent
local base = loveframes.base
local update = self.Update
self:CheckHover()
-- 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
local haslist = self.haslist
local enabled = self.enabled
if hover and not haslist and enabled and button == 1 then
local baseparent = self:GetBaseParent()
if baseparent and baseparent.type == "frame" then
baseparent:MakeTop()
end
self.haslist = true
self.list = loveframes.objects["multichoicelist"]:new(self)
self.list:SetState(self.state)
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 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: AddChoice(choice)
- desc: adds a choice to the current list of choices
--]]---------------------------------------------------------
function newobject:AddChoice(choice)
local choices = self.choices
table.insert(choices, choice)
return self
end
--[[---------------------------------------------------------
- func: RemoveChoice(choice)
- desc: removes the specified choice from the object's
list of choices
--]]---------------------------------------------------------
function newobject:RemoveChoice(choice)
local choices = self.choices
for k, v in ipairs(choices) do
if v == choice then
table.remove(choices, k)
break
end
end
return self
end
--[[---------------------------------------------------------
- func: SetChoice(choice)
- desc: sets the current choice
--]]---------------------------------------------------------
function newobject:SetChoice(choice)
self.choice = choice
return self
end
--[[---------------------------------------------------------
- func: SelectChoice(choice)
- desc: selects a choice
--]]---------------------------------------------------------
function newobject:SelectChoice(choice)
local onchoiceselected = self.OnChoiceSelected
self.choice = choice
if self.list then
self.list:Close()
end
if onchoiceselected then
onchoiceselected(self, choice)
end
return self
end
--[[---------------------------------------------------------
- func: SetListHeight(height)
- desc: sets the height of the list of choices
--]]---------------------------------------------------------
function newobject:SetListHeight(height)
self.listheight = height
return self
end
--[[---------------------------------------------------------
- func: SetPadding(padding)
- desc: sets the padding of the list of choices
--]]---------------------------------------------------------
function newobject:SetPadding(padding)
self.listpadding = padding
return self
end
--[[---------------------------------------------------------
- func: SetSpacing(spacing)
- desc: sets the spacing of the list of choices
--]]---------------------------------------------------------
function newobject:SetSpacing(spacing)
self.listspacing = spacing
return self
end
--[[---------------------------------------------------------
- func: GetValue()
- desc: gets the value (choice) of the object
--]]---------------------------------------------------------
function newobject:GetValue()
return self.choice
end
--[[---------------------------------------------------------
- func: GetChoice()
- desc: gets the current choice (same as get value)
--]]---------------------------------------------------------
function newobject:GetChoice()
return self.choice
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: SetButtonScrollAmount(speed)
- desc: sets the scroll amount of the object's scrollbar
buttons
--]]---------------------------------------------------------
function newobject:SetButtonScrollAmount(amount)
self.buttonscrollamount = amount
return self
end
--[[---------------------------------------------------------
- func: GetButtonScrollAmount()
- desc: gets the scroll amount of the object's scrollbar
buttons
--]]---------------------------------------------------------
function newobject:GetButtonScrollAmount()
return self.buttonscrollamount
end
--[[---------------------------------------------------------
- func: SetMouseWheelScrollAmount(amount)
- desc: sets the scroll amount of the mouse wheel
--]]---------------------------------------------------------
function newobject:SetMouseWheelScrollAmount(amount)
self.mousewheelscrollamount = amount
return self
end
--[[---------------------------------------------------------
- func: GetMouseWheelScrollAmount()
- desc: gets the scroll amount of the mouse wheel
--]]---------------------------------------------------------
function newobject:GetButtonScrollAmount()
return self.mousewheelscrollamount
end
--[[---------------------------------------------------------
- func: SetDTScrolling(bool)
- desc: sets whether or not the object should use delta
time when scrolling
--]]---------------------------------------------------------
function newobject:SetDTScrolling(bool)
self.dtscrolling = bool
return self
end
--[[---------------------------------------------------------
- func: GetDTScrolling()
- desc: gets whether or not the object should use delta
time when scrolling
--]]---------------------------------------------------------
function newobject:GetDTScrolling()
return self.dtscrolling
end
--[[---------------------------------------------------------
- func: Sort(func)
- desc: sorts the object's choices
--]]---------------------------------------------------------
function newobject:Sort(func)
local default = self.sortfunc
if func then
table.sort(self.choices, func)
else
table.sort(self.choices, default)
end
return self
end
--[[---------------------------------------------------------
- func: SetSortFunction(func)
- desc: sets the object's default sort function
--]]---------------------------------------------------------
function newobject:SetSortFunction(func)
self.sortfunc = func
return self
end
--[[---------------------------------------------------------
- func: GetSortFunction(func)
- desc: gets the object's default sort function
--]]---------------------------------------------------------
function newobject:GetSortFunction()
return self.sortfunc
end
--[[---------------------------------------------------------
- func: Clear()
- desc: removes all choices from the object's list
of choices
--]]---------------------------------------------------------
function newobject:Clear()
self.choices = {}
self.choice = ""
self.text = "Select an option"
return self
end
--[[---------------------------------------------------------
- func: SetClickable(bool)
- desc: sets whether or not the object is enabled
--]]---------------------------------------------------------
function newobject:SetEnabled(bool)
self.enabled = bool
return self
end
--[[---------------------------------------------------------
- func: GetEnabled()
- desc: gets whether or not the object is enabled
--]]---------------------------------------------------------
function newobject:GetEnabled()
return self.enabled
end
---------- module end ----------
end

View File

@ -0,0 +1,485 @@
--[[------------------------------------------------
-- Love Frames - A GUI library for LOVE --
-- Copyright (c) 2012-2014 Kenny Shields --
--]]------------------------------------------------
return function(loveframes)
---------- module start ----------
-- numberbox object
local newobject = loveframes.NewObject("numberbox", "loveframes_object_numberbox", true)
--[[---------------------------------------------------------
- func: initialize()
- desc: initializes the object
--]]---------------------------------------------------------
function newobject:initialize()
self.type = "numberbox"
self.width = 80
self.height = 20
self.value = 0
self.increaseamount = 1
self.decreaseamount = 1
self.min = -100
self.max = 100
self.delay = 0
self.decimals = 0
self.internal = false
self.canmodify = false
self.lastbuttonclicked = false
self.internals = {}
self.OnValueChanged = nil
local input = loveframes.objects["textinput"]:new()
input.parent = self
input:SetSize(50, 20)
input:SetUsable({"1", "2", "3", "4", "5", "6", "7", "8", "9", "0", ".", "-"})
input:SetTabReplacement("")
input:SetText(self.value)
input.OnTextChanged = function(object)
local value = self.value
local newvalue = tonumber(object.lines[1])
if not newvalue then
self.value = value
input:SetText(value)
return
end
self.value = newvalue
if self.value > self.max then
self.value = self.max
object:SetText(self.value)
end
if self.value < self.min then
self.value = self.min
object:SetText(self.value)
end
if value ~= self.value then
if self.OnValueChanged then
self.OnValueChanged(self, self.value)
end
end
end
input.Update = function(object)
object:SetSize(object.parent.width - 20, object.parent.height)
end
local increasebutton = loveframes.objects["button"]:new()
increasebutton.parent = self
increasebutton:SetWidth(21)
increasebutton:SetText("+")
increasebutton.OnClick = function()
local canmodify = self.canmodify
if not canmodify then
self:ModifyValue("add")
else
self.canmodify = false
end
end
increasebutton.Update = function(object)
local time = 0
time = love.timer.getTime()
local delay = self.delay
local down = object.down
local canmodify = self.canmodify
local lastbuttonclicked = self.lastbuttonclicked
object:SetPos(object.parent.width - 21, 0)
object:SetHeight(object.parent.height/2 + 1)
if down and not canmodify then
self:ModifyValue("add")
self.canmodify = true
self.delay = time + 0.80
self.lastbuttonclicked = object
elseif down and canmodify and delay < time then
self:ModifyValue("add")
self.delay = time + 0.02
elseif not down and canmodify and lastbuttonclicked == object then
self.canmodify = false
self.delay = time + 0.80
end
end
local decreasesbutton = loveframes.objects["button"]:new()
decreasesbutton.parent = self
decreasesbutton:SetWidth(21)
decreasesbutton:SetText("-")
decreasesbutton.OnClick = function()
local canmodify = self.canmodify
if not canmodify then
self:ModifyValue("subtract")
else
self.canmodify = false
end
end
decreasesbutton.Update = function(object)
local time = 0
time = love.timer.getTime()
local delay = self.delay
local down = object.down
local canmodify = self.canmodify
local lastbuttonclicked = self.lastbuttonclicked
object:SetPos(object.parent.width - 21, object.parent.height/2)
object:SetHeight(object.parent.height/2)
if down and not canmodify then
self:ModifyValue("subtract")
self.canmodify = true
self.delay = time + 0.80
self.lastbuttonclicked = object
elseif down and canmodify and delay < time then
self:ModifyValue("subtract")
self.delay = time + 0.02
elseif not down and canmodify and lastbuttonclicked == object then
self.canmodify = false
self.delay = time + 0.80
end
end
table.insert(self.internals, input)
table.insert(self.internals, increasebutton)
table.insert(self.internals, decreasesbutton)
self:SetDrawFunc()
end
--[[---------------------------------------------------------
- func: update(deltatime)
- desc: updates the element
--]]---------------------------------------------------------
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 internals = self.internals
local parent = self.parent
local base = loveframes.base
local update = self.Update
-- move to parent if there is a parent
if parent ~= base and parent.type ~= "list" then
self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy
end
self:CheckHover()
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 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 hover = self.hover
if 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(internals) do
v:mousepressed(x, y, button)
end
end
--[[---------------------------------------------------------
- func: SetValue(value)
- desc: sets the object's value
--]]---------------------------------------------------------
function newobject:SetValue(value)
local min = self.min
local curvalue = self.value
local value = tonumber(value) or min
local internals = self.internals
local input = internals[1]
local onvaluechanged = self.OnValueChanged
self.value = value
input:SetText(value)
if value ~= curvalue and onvaluechanged then
onvaluechanged(self, value)
end
return self
end
--[[---------------------------------------------------------
- func: GetValue()
- desc: gets the object's value
--]]---------------------------------------------------------
function newobject:GetValue()
return self.value
end
--[[---------------------------------------------------------
- func: SetIncreaseAmount(amount)
- desc: sets the object's increase amount
--]]---------------------------------------------------------
function newobject:SetIncreaseAmount(amount)
self.increaseamount = amount
return self
end
--[[---------------------------------------------------------
- func: GetIncreaseAmount()
- desc: gets the object's increase amount
--]]---------------------------------------------------------
function newobject:GetIncreaseAmount()
return self.increaseamount
end
--[[---------------------------------------------------------
- func: SetDecreaseAmount(amount)
- desc: sets the object's decrease amount
--]]---------------------------------------------------------
function newobject:SetDecreaseAmount(amount)
self.decreaseamount = amount
return self
end
--[[---------------------------------------------------------
- func: GetDecreaseAmount()
- desc: gets the object's decrease amount
--]]---------------------------------------------------------
function newobject:GetDecreaseAmount()
return self.decreaseamount
end
--[[---------------------------------------------------------
- func: SetMax(max)
- desc: sets the object's maximum value
--]]---------------------------------------------------------
function newobject:SetMax(max)
local internals = self.internals
local input = internals[1]
local onvaluechanged = self.OnValueChanged
self.max = max
if self.value > max then
self.value = max
input:SetValue(max)
if onvaluechanged then
onvaluechanged(self, max)
end
end
return self
end
--[[---------------------------------------------------------
- func: GetMax()
- desc: gets the object's maximum value
--]]---------------------------------------------------------
function newobject:GetMax()
return self.max
end
--[[---------------------------------------------------------
- func: SetMin(min)
- desc: sets the object's minimum value
--]]---------------------------------------------------------
function newobject:SetMin(min)
local internals = self.internals
local input = internals[1]
local onvaluechanged = self.OnValueChanged
self.min = min
if self.value < min then
self.value = min
input:SetValue(min)
if onvaluechanged then
onvaluechanged(self, min)
end
end
return self
end
--[[---------------------------------------------------------
- func: GetMin()
- desc: gets the object's minimum value
--]]---------------------------------------------------------
function newobject:GetMin()
return self.min
end
--[[---------------------------------------------------------
- func: SetMinMax()
- desc: sets the object's minimum and maximum values
--]]---------------------------------------------------------
function newobject:SetMinMax(min, max)
local internals = self.internals
local input = internals[1]
local onvaluechanged = self.OnValueChanged
self.min = min
self.max = max
if self.value > max then
self.value = max
input:SetValue(max)
if onvaluechanged then
onvaluechanged(self, max)
end
end
if self.value < min then
self.value = min
input:SetValue(min)
if onvaluechanged then
onvaluechanged(self, min)
end
end
return self
end
--[[---------------------------------------------------------
- func: GetMinMax()
- desc: gets the object's minimum and maximum values
--]]---------------------------------------------------------
function newobject:GetMinMax()
return self.min, self.max
end
--[[---------------------------------------------------------
- func: ModifyValue(type)
- desc: modifies the object's value
--]]---------------------------------------------------------
function newobject:ModifyValue(type)
local value = self.value
local internals = self.internals
local input = internals[1]
local decimals = self.decimals
local onvaluechanged = self.OnValueChanged
if not value then
return
end
if type == "add" then
local increaseamount = self.increaseamount
local max = self.max
self.value = value + increaseamount
if self.value > max then
self.value = max
end
self.value = loveframes.Round(self.value, decimals)
input:SetText(self.value)
if value ~= self.value then
if onvaluechanged then
onvaluechanged(self, self.value)
end
end
elseif type == "subtract" then
local decreaseamount = self.decreaseamount
local min = self.min
self.value = value - decreaseamount
if self.value < min then
self.value = min
end
self.value = loveframes.Round(self.value, decimals)
input:SetText(self.value)
if value ~= self.value then
if onvaluechanged then
onvaluechanged(self, self.value)
end
end
end
return self
end
--[[---------------------------------------------------------
- func: SetDecimals(decimals)
- desc: sets how many decimals the object's value
can have
--]]---------------------------------------------------------
function newobject:SetDecimals(decimals)
self.decimals = decimals
return self
end
--[[---------------------------------------------------------
- func: GetDecimals()
- desc: gets how many decimals the object's value
can have
--]]---------------------------------------------------------
function newobject:GetDecimals()
return self.decimals
end
---------- module end ----------
end

View File

@ -0,0 +1,134 @@
--[[------------------------------------------------
-- Love Frames - A GUI library for LOVE --
-- Copyright (c) 2012-2014 Kenny Shields --
--]]------------------------------------------------
return function(loveframes)
---------- module start ----------
-- panel object
local newobject = loveframes.NewObject("panel", "loveframes_object_panel", true)
--[[---------------------------------------------------------
- func: initialize()
- desc: initializes the object
--]]---------------------------------------------------------
function newobject:initialize()
self.type = "panel"
self.width = 200
self.height = 50
self.internal = false
self.children = {}
self:SetDrawFunc()
end
--[[---------------------------------------------------------
- func: update(deltatime)
- desc: updates the element
--]]---------------------------------------------------------
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 children = self.children
local parent = self.parent
local base = loveframes.base
local update = self.Update
-- move to parent if there is a parent
if parent ~= base and parent.type ~= "list" then
self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy
end
self:CheckHover()
for k, v in ipairs(children) 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 state = loveframes.state
local selfstate = self.state
if state ~= selfstate then
return
end
local visible = self.visible
if not visible then
return
end
local children = self.children
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
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
local children = self.children
if not visible then
return
end
for k, v in ipairs(children) do
v:mousereleased(x, y, button)
end
end
---------- module end ----------
end

View File

@ -0,0 +1,318 @@
--[[------------------------------------------------
-- Love Frames - A GUI library for LOVE --
-- Copyright (c) 2012-2014 Kenny Shields --
--]]------------------------------------------------
return function(loveframes)
---------- module start ----------
-- progressbar object
local newobject = loveframes.NewObject("progressbar", "loveframes_object_progressbar", true)
--[[---------------------------------------------------------
- func: initialize()
- desc: initializes the object
--]]---------------------------------------------------------
function newobject:initialize()
self.type = "progressbar"
self.text = ""
self.width = 100
self.height = 25
self.min = 0
self.max = 10
self.value = 0
self.barwidth = 0
self.lerprate = 1000
self.lerpvalue = 0
self.lerpto = 0
self.lerpfrom = 0
self.completed = false
self.lerp = false
self.internal = false
self.OnComplete = nil
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 lerp = self.lerp
local lerprate = self.lerprate
local lerpvalue = self.lerpvalue
local lerpto = self.lerpto
local lerpfrom = self.lerpfrom
local value = self.value
local completed = self.completed
local parent = self.parent
local base = loveframes.base
local update = self.Update
local oncomplete = self.OnComplete
self:CheckHover()
-- caclulate barwidth
if lerp then
if lerpfrom < lerpto then
if lerpvalue < lerpto then
self.lerpvalue = lerpvalue + lerprate*dt
elseif lerpvalue > lerpto then
self.lerpvalue = lerpto
end
elseif lerpfrom > lerpto then
if lerpvalue > lerpto then
self.lerpvalue = lerpvalue - lerprate*dt
elseif lerpvalue < lerpto then
self.lerpvalue = lerpto
end
elseif lerpfrom == lerpto then
self.lerpvalue = lerpto
end
self.barwidth = self.lerpvalue/self.max * self.width
-- min check
if self.lerpvalue < self.min then
self.lerpvalue = self.min
end
-- max check
if self.lerpvalue > self.max then
self.lerpvalue = self.max
end
else
self.barwidth = value/self.max * self.width
-- min max check
if value < self.min then
self.value = self.min
elseif value > self.max then
self.value = self.max
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
-- completion check
if not completed then
if self.value >= self.max then
self.completed = true
if oncomplete then
oncomplete(self)
end
end
end
if update then
update(self, dt)
end
end
--[[---------------------------------------------------------
- func: SetMax(max)
- desc: sets the object's maximum value
--]]---------------------------------------------------------
function newobject:SetMax(max)
self.max = max
return self
end
--[[---------------------------------------------------------
- func: GetMax()
- desc: gets the object's maximum value
--]]---------------------------------------------------------
function newobject:GetMax()
return self.max
end
--[[---------------------------------------------------------
- func: SetMin(min)
- desc: sets the object's minimum value
--]]---------------------------------------------------------
function newobject:SetMin(min)
self.min = min
return self
end
--[[---------------------------------------------------------
- func: GetMin()
- desc: gets the object's minimum value
--]]---------------------------------------------------------
function newobject:GetMin()
return self.min
end
--[[---------------------------------------------------------
- func: SetMinMax()
- desc: sets the object's minimum and maximum values
--]]---------------------------------------------------------
function newobject:SetMinMax(min, max)
self.min = min
self.max = max
return self
end
--[[---------------------------------------------------------
- func: GetMinMax()
- desc: gets the object's minimum and maximum values
--]]---------------------------------------------------------
function newobject:GetMinMax()
return self.min, self.max
end
--[[---------------------------------------------------------
- func: SetValue(value)
- desc: sets the object's value
--]]---------------------------------------------------------
function newobject:SetValue(value)
local lerp = self.lerp
if lerp then
self.lerpvalue = self.lerpvalue
self.lerpto = value
self.lerpfrom = self.lerpvalue
self.value = value
else
self.value = value
end
return self
end
--[[---------------------------------------------------------
- func: GetValue()
- desc: gets the object's value
--]]---------------------------------------------------------
function newobject:GetValue()
return self.value
end
--[[---------------------------------------------------------
- func: SetLerp(bool)
- desc: sets whether or not the object should lerp
when changing between values
--]]---------------------------------------------------------
function newobject:SetLerp(bool)
self.lerp = bool
self.lerpto = self:GetValue()
self.lerpvalue = self:GetValue()
return self
end
--[[---------------------------------------------------------
- func: GetLerp()
- desc: gets whether or not the object should lerp
when changing between values
--]]---------------------------------------------------------
function newobject:GetLerp()
return self.lerp
end
--[[---------------------------------------------------------
- func: SetLerpRate(rate)
- desc: sets the object's lerp rate
--]]---------------------------------------------------------
function newobject:SetLerpRate(rate)
self.lerprate = rate
return self
end
--[[---------------------------------------------------------
- func: GetLerpRate()
- desc: gets the object's lerp rate
--]]---------------------------------------------------------
function newobject:GetLerpRate()
return self.lerprate
end
--[[---------------------------------------------------------
- func: GetCompleted()
- desc: gets whether or not the object has reached its
maximum value
--]]---------------------------------------------------------
function newobject:GetCompleted()
return self.completed
end
--[[---------------------------------------------------------
- func: GetBarWidth()
- desc: gets the object's bar width
--]]---------------------------------------------------------
function newobject:GetBarWidth()
return self.barwidth
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
---------- module end ----------
end

View File

@ -0,0 +1,429 @@
--[[------------------------------------------------
-- Love Frames - A GUI library for LOVE --
-- Copyright (c) 2012-2014 Kenny Shields --
--]]------------------------------------------------
return function(loveframes)
---------- module start ----------
-- radiobutton object
local newobject = loveframes.NewObject("radiobutton", "loveframes_object_radiobutton", true)
--[[---------------------------------------------------------
- func: initialize()
- desc: initializes the object
--]]---------------------------------------------------------
function newobject:initialize()
self.type = "radiobutton"
self.width = 0
self.height = 0
self.boxwidth = 20
self.boxheight = 20
self.font = loveframes.basicfont
self.checked = false
self.lastvalue = false
self.internal = false
self.down = true
self.enabled = true
self.internals = {}
self.OnChanged = function () end
self.group = {}
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 internals = self.internals
local boxwidth = self.boxwidth
local boxheight = self.boxheight
local parent = self.parent
local base = loveframes.base
local update = self.Update
if not hover then
self.down = false
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 and parent.type ~= "list" then
self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy
end
if internals[1] then
self.width = boxwidth + 5 + internals[1].width
if internals[1].height == boxheight then
self.height = boxheight
else
if internals[1].height > boxheight then
self.height = internals[1].height
else
self.height = boxheight
end
end
else
self.width = boxwidth
self.height = boxheight
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 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 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)
if loveframes.state ~= self.state then
return
end
if not self.visible then
return
end
if self.hover and self.down and self.enabled and button == 1 then
if not self.checked then
-- a radio button can only be unchecked by checking another radio button
self:SetChecked(true)
end
end
end
--[[---------------------------------------------------------
- func: SetText(text)
- desc: sets the object's text
--]]---------------------------------------------------------
function newobject:SetText(text)
local boxwidth = self.boxwidth
local boxheight = self.boxheight
if text ~= "" then
self.internals = {}
local textobject = loveframes.Create("text")
local skin = loveframes.GetActiveSkin()
if not skin then
skin = loveframes.config["DEFAULTSKIN"]
end
local directives = skin.directives
if directives then
local default_color = directives.radiobutton_text_default_color
local default_shadowcolor = directives.radiobutton_text_default_shadowcolor
local default_font = directives.radiobutton_text_default_font
if default_color then
textobject.defaultcolor = default_color
end
if default_shadowcolor then
textobject.shadowcolor = default_shadowcolor
end
if default_font then
self.font = default_font
end
end
textobject:Remove()
textobject.parent = self
textobject.state = self.state
textobject.collide = false
textobject:SetFont(self.font)
textobject:SetText(text)
textobject.Update = function(object, dt)
if object.height > boxheight then
object:SetPos(boxwidth + 5, 0)
else
object:SetPos(boxwidth + 5, boxheight/2 - object.height/2)
end
end
table.insert(self.internals, textobject)
else
self.width = boxwidth
self.height = boxheight
self.internals = {}
end
return self
end
--[[---------------------------------------------------------
- func: GetText()
- desc: gets the object's text
--]]---------------------------------------------------------
function newobject:GetText()
local internals = self.internals
local text = internals[1]
if text then
return text.text
else
return false
end
end
--[[---------------------------------------------------------
- func: SetSize(width, height, r1, r2)
- desc: sets the object's size
--]]---------------------------------------------------------
function newobject:SetSize(width, height, r1, r2)
if r1 then
self.boxwidth = self.parent.width * width
else
self.boxwidth = width
end
if r2 then
self.boxheight = self.parent.height * height
else
self.boxheight = height
end
return self
end
--[[---------------------------------------------------------
- func: SetWidth(width, relative)
- desc: sets the object's width
--]]---------------------------------------------------------
function newobject:SetWidth(width, relative)
if relative then
self.boxwidth = self.parent.width * width
else
self.boxwidth = width
end
return self
end
--[[---------------------------------------------------------
- func: SetHeight(height, relative)
- desc: sets the object's height
--]]---------------------------------------------------------
function newobject:SetHeight(height, relative)
if relative then
self.boxheight = self.parent.height * height
else
self.boxheight = height
end
return self
end
--[[---------------------------------------------------------
- func: SetChecked(bool)
- desc: sets whether the object is checked or not
--]]---------------------------------------------------------
function newobject:SetChecked(checked)
if self.checked ~= checked then
self.checked = checked
self:OnChanged(checked)
end
if checked then
for _, button in pairs(self.group) do
if button ~= self and button.checked then
button:SetChecked(false)
end
end
end
return self
end
--[[---------------------------------------------------------
- func: GetChecked()
- desc: gets whether the object is checked or not
--]]---------------------------------------------------------
function newobject:GetChecked()
return self.checked
end
--[[---------------------------------------------------------
- func: SetGroup()
- desc: set the object's group. only one radio button in a
group is checked at a time.
--]]---------------------------------------------------------
function newobject:SetGroup(group)
self.group = group
self.group[self] = self
end
--[[---------------------------------------------------------
- func: GetGroup()
- desc: gets the object's group
--]]---------------------------------------------------------
function newobject:GetGroup(group)
return self.group
end
--[[---------------------------------------------------------
- func: SetFont(font)
- desc: sets the font of the object's text
--]]---------------------------------------------------------
function newobject:SetFont(font)
local internals = self.internals
local text = internals[1]
self.font = font
if text then
text:SetFont(font)
end
return self
end
--[[---------------------------------------------------------
- func: newobject:GetFont()
- desc: gets the font of the object's text
--]]---------------------------------------------------------
function newobject:GetFont()
return self.font
end
--[[---------------------------------------------------------
- func: newobject:GetBoxHeight()
- desc: gets the object's box size
--]]---------------------------------------------------------
function newobject:GetBoxSize()
return self.boxwidth, self.boxheight
end
--[[---------------------------------------------------------
- func: newobject:GetBoxWidth()
- desc: gets the object's box width
--]]---------------------------------------------------------
function newobject:GetBoxWidth()
return self.boxwidth
end
--[[---------------------------------------------------------
- func: newobject:GetBoxHeight()
- desc: gets the object's box height
--]]---------------------------------------------------------
function newobject:GetBoxHeight()
return self.boxheight
end
--[[---------------------------------------------------------
- func: SetClickable(bool)
- desc: sets whether or not the object is enabled
--]]---------------------------------------------------------
function newobject:SetEnabled(bool)
self.enabled = bool
return self
end
--[[---------------------------------------------------------
- func: GetEnabled()
- desc: gets whether or not the object is enabled
--]]---------------------------------------------------------
function newobject:GetEnabled()
return self.enabled
end
---------- module end ----------
end

View File

@ -0,0 +1,514 @@
--[[------------------------------------------------
-- Love Frames - A GUI library for LOVE --
-- Copyright (c) 2012-2014 Kenny Shields --
--]]------------------------------------------------
return function(loveframes)
---------- module start ----------
-- slider object
local newobject = loveframes.NewObject("slider", "loveframes_object_slider", true)
--[[---------------------------------------------------------
- func: initialize()
- desc: initializes the object
--]]---------------------------------------------------------
function newobject:initialize()
self.type = "slider"
self.text = "Slider"
self.slidetype = "horizontal"
self.width = 5
self.height = 5
self.max = 10
self.min = 0
self.value = 0
self.decimals = 5
self.scrollincrease = 1
self.scrolldecrease = 1
self.scrollable = true
self.enabled = true
self.internal = false
self.internals = {}
self.OnValueChanged = nil
self.OnRelease = nil
-- create the slider button
local sliderbutton = loveframes.objects["sliderbutton"]:new(self)
sliderbutton.state = self.state
table.insert(self.internals, sliderbutton)
-- set initial value to minimum
self:SetValue(self.min)
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 internals = self.internals
local sliderbutton = internals[1]
local parent = self.parent
local base = loveframes.base
local update = self.Update
self:CheckHover()
-- move to parent if there is a parent
if parent ~= base and parent.type ~= "list" then
self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy
end
if sliderbutton then
local slidetype = self.slidetype
local buttonwidth = sliderbutton.width
local buttonheight = sliderbutton.height
if slidetype == "horizontal" then
self.height = buttonheight
elseif slidetype == "vertical" then
self.width = buttonwidth
end
end
-- update internals
for k, v in ipairs(self.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 state = loveframes.state
local selfstate = self.state
if state ~= selfstate then
return
end
local visible = self.visible
if not visible then
return
end
local enabled = self.enabled
if not enabled then
return
end
local internals = self.internals
local hover = self.hover
local slidetype = self.slidetype
local scrollable = self.scrollable
if hover and button == 1 then
if slidetype == "horizontal" then
local xpos = x - self.x
local button = internals[1]
local baseparent = self:GetBaseParent()
if baseparent and baseparent.type == "frame" then
baseparent:MakeTop()
end
button:MoveToX(xpos)
button.down = true
button.dragging = true
button.startx = button.staticx
button.clickx = x
elseif slidetype == "vertical" then
local ypos = y - self.y
local button = internals[1]
local baseparent = self:GetBaseParent()
if baseparent and baseparent.type == "frame" then
baseparent:MakeTop()
end
button:MoveToY(ypos)
button.down = true
button.dragging = true
button.starty = button.staticy
button.clicky = y
end
elseif hover and scrollable and button == "wu" then
local value = self.value
local increase = self.scrollincrease
local newvalue = value + increase
self:SetValue(newvalue)
elseif hover and scrollable and button == "wd" then
local value = self.value
local decrease = self.scrolldecrease
local newvalue = value - decrease
self:SetValue(newvalue)
end
for k, v in ipairs(internals) do
v:mousepressed(x, y, button)
end
end
--[[---------------------------------------------------------
- func: SetValue(value)
- desc: sets the object's value
--]]---------------------------------------------------------
function newobject:SetValue(value)
if value > self.max then
return
end
if value < self.min then
return
end
local decimals = self.decimals
local newval = loveframes.Round(value, decimals)
local internals = self.internals
local onvaluechanged = self.OnValueChanged
-- set the new value
self.value = newval
-- slider button object
local sliderbutton = internals[1]
local slidetype = self.slidetype
local width = self.width
local height = self.height
local min = self.min
local max = self.max
-- move the slider button to the new position
if slidetype == "horizontal" then
local xpos = width * ((newval - min) / (max - min))
sliderbutton:MoveToX(xpos)
elseif slidetype == "vertical" then
local ypos = height - height * ((newval - min) / (max - min))
sliderbutton:MoveToY(ypos)
end
-- call OnValueChanged
if onvaluechanged then
onvaluechanged(self, newval)
end
return self
end
--[[---------------------------------------------------------
- func: GetValue()
- desc: gets the object's value
--]]---------------------------------------------------------
function newobject:GetValue()
return self.value
end
--[[---------------------------------------------------------
- func: SetMax(max)
- desc: sets the object's maximum value
--]]---------------------------------------------------------
function newobject:SetMax(max)
self.max = max
if self.value > self.max then
self.value = self.max
end
return self
end
--[[---------------------------------------------------------
- func: GetMax()
- desc: gets the object's maximum value
--]]---------------------------------------------------------
function newobject:GetMax()
return self.max
end
--[[---------------------------------------------------------
- func: SetMin(min)
- desc: sets the object's minimum value
--]]---------------------------------------------------------
function newobject:SetMin(min)
self.min = min
if self.value < self.min then
self.value = self.min
end
return self
end
--[[---------------------------------------------------------
- func: GetMin()
- desc: gets the object's minimum value
--]]---------------------------------------------------------
function newobject:GetMin()
return self.min
end
--[[---------------------------------------------------------
- func: SetMinMax()
- desc: sets the object's minimum and maximum values
--]]---------------------------------------------------------
function newobject:SetMinMax(min, max)
self.min = min
self.max = max
if self.value > self.max then
self.value = self.max
end
if self.value < self.min then
self.value = self.min
end
return self
end
--[[---------------------------------------------------------
- func: GetMinMax()
- desc: gets the object's minimum and maximum values
--]]---------------------------------------------------------
function newobject:GetMinMax()
return self.min, self.max
end
--[[---------------------------------------------------------
- func: SetText(name)
- desc: sets the objects's text
--]]---------------------------------------------------------
function newobject:SetText(text)
self.text = text
return self
end
--[[---------------------------------------------------------
- func: GetText()
- desc: gets the objects's text
--]]---------------------------------------------------------
function newobject:GetText()
return self.text
end
--[[---------------------------------------------------------
- func: SetDecimals(decimals)
- desc: sets how many decimals the object's value
can have
--]]---------------------------------------------------------
function newobject:SetDecimals(decimals)
self.decimals = decimals
return self
end
--[[---------------------------------------------------------
- func: GetDecimals()
- desc: gets how many decimals the object's value
can have
--]]---------------------------------------------------------
function newobject:GetDecimals()
return self.decimals
end
--[[---------------------------------------------------------
- func: SetButtonSize(width, height)
- desc: sets the objects's button size
--]]---------------------------------------------------------
function newobject:SetButtonSize(width, height)
local internals = self.internals
local sliderbutton = internals[1]
if sliderbutton then
sliderbutton.width = width
sliderbutton.height = height
end
return self
end
--[[---------------------------------------------------------
- func: GetButtonSize()
- desc: gets the objects's button size
--]]---------------------------------------------------------
function newobject:GetButtonSize()
local internals = self.internals
local sliderbutton = internals[1]
if sliderbutton then
return sliderbutton.width, sliderbutton.height
end
end
--[[---------------------------------------------------------
- func: SetSlideType(slidetype)
- desc: sets the objects's slide type
--]]---------------------------------------------------------
function newobject:SetSlideType(slidetype)
self.slidetype = slidetype
if slidetype == "vertical" then
self:SetValue(self.min)
end
return self
end
--[[---------------------------------------------------------
- func: GetSlideType()
- desc: gets the objects's slide type
--]]---------------------------------------------------------
function newobject:GetSlideType()
return self.slidetype
end
--[[---------------------------------------------------------
- func: SetScrollable(bool)
- desc: sets whether or not the object can be scrolled
via the mouse wheel
--]]---------------------------------------------------------
function newobject:SetScrollable(bool)
self.scrollable = bool
return self
end
--[[---------------------------------------------------------
- func: GetScrollable()
- desc: gets whether or not the object can be scrolled
via the mouse wheel
--]]---------------------------------------------------------
function newobject:GetScrollable()
return self.scrollable
end
--[[---------------------------------------------------------
- func: SetScrollIncrease(increase)
- desc: sets the amount to increase the object's value
by when scrolling with the mouse wheel
--]]---------------------------------------------------------
function newobject:SetScrollIncrease(increase)
self.scrollincrease = increase
return self
end
--[[---------------------------------------------------------
- func: GetScrollIncrease()
- desc: gets the amount to increase the object's value
by when scrolling with the mouse wheel
--]]---------------------------------------------------------
function newobject:GetScrollIncrease()
return self.scrollincrease
end
--[[---------------------------------------------------------
- func: SetScrollDecrease(decrease)
- desc: sets the amount to decrease the object's value
by when scrolling with the mouse wheel
--]]---------------------------------------------------------
function newobject:SetScrollDecrease(decrease)
self.scrolldecrease = decrease
return self
end
--[[---------------------------------------------------------
- func: GetScrollDecrease()
- desc: gets the amount to decrease the object's value
by when scrolling with the mouse wheel
--]]---------------------------------------------------------
function newobject:GetScrollDecrease()
return self.scrolldecrease
end
--[[---------------------------------------------------------
- func: SetEnabled(bool)
- desc: sets whether or not the object is enabled
--]]---------------------------------------------------------
function newobject:SetEnabled(bool)
self.enabled = bool
return self
end
--[[---------------------------------------------------------
- func: GetEnabled()
- desc: gets whether or not the object is enabled
--]]---------------------------------------------------------
function newobject:GetEnabled()
return self.enabled
end
---------- module end ----------
end

765
loveframes/objects/tabs.lua Normal file
View File

@ -0,0 +1,765 @@
--[[------------------------------------------------
-- Love Frames - A GUI library for LOVE --
-- Copyright (c) 2012-2014 Kenny Shields --
--]]------------------------------------------------
return function(loveframes)
---------- module start ----------
-- tabs object
local newobject = loveframes.NewObject("tabs", "loveframes_object_tabs", true)
--[[---------------------------------------------------------
- func: initialize()
- desc: initializes the object
--]]---------------------------------------------------------
function newobject:initialize()
self.type = "tabs"
self.width = 100
self.height = 50
self.clickx = 0
self.clicky = 0
self.offsetx = 0
self.tab = 1
self.tabnumber = 1
self.padding = 5
self.tabheight = 25
self.previoustabheight = 25
self.buttonscrollamount = 200
self.mousewheelscrollamount = 1500
self.buttonareax = 0
self.buttonareawidth = self.width
self.autosize = true
self.autobuttonareawidth = true
self.dtscrolling = true
self.internal = false
self.tooltipfont = loveframes.basicfontsmall
self.internals = {}
self.children = {}
self:AddScrollButtons()
self:SetDrawFunc()
end
--[[---------------------------------------------------------
- func: update(deltatime)
- desc: updates the element
--]]---------------------------------------------------------
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 x, y = love.mouse.getPosition()
local tabheight = self.tabheight
local padding = self.padding
local autosize = self.autosize
local autobuttonareawidth = self.autobuttonareawidth
local padding = self.padding
local children = self.children
local numchildren = #children
local internals = self.internals
local tab = self.tab
local parent = self.parent
local base = loveframes.base
local update = self.Update
-- move to parent if there is a parent
if parent ~= base then
self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy
end
self:CheckHover()
if numchildren > 0 and tab == 0 then
self.tab = 1
end
if autobuttonareawidth then
local width = self.width
self.buttonareawidth = width
end
local pos = 0
for k, v in ipairs(internals) do
v:update(dt)
if v.type == "tabbutton" then
v.x = (v.parent.x + v.staticx) + pos + self.offsetx + self.buttonareax
v.y = (v.parent.y + v.staticy)
pos = pos + v.width - 1
end
end
if #self.children > 0 then
self.children[self.tab]:update(dt)
self.children[self.tab]:SetPos(padding, tabheight + padding)
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 tabheight = self:GetHeightOfButtons()
local stencilfunc = function() love.graphics.rectangle("fill", x + self.buttonareax, y, self.buttonareawidth, height) 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 internals = self.internals
if internals then
for k, v in ipairs(internals) do
local col = loveframes.BoundingBox(x + self.buttonareax, v.x, self.y, v.y, self.buttonareawidth, v.width, tabheight, v.height)
if col or v.type == "scrollbutton" then
v:draw()
end
end
end
love.graphics.setStencilTest()
local children = self.children
if #children > 0 then
children[self.tab]:draw()
end
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 children = self.children
local internals = self.internals
local numchildren = #children
local numinternals = #internals
local tab = self.tab
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
for k, v in ipairs(internals) do
v:mousepressed(x, y, button)
end
if numchildren > 0 then
children[tab]: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
local children = self.children
local numchildren = #children
local tab = self.tab
local internals = self.internals
if not visible then
return
end
for k, v in ipairs(internals) do
v:mousereleased(x, y, button)
end
if numchildren > 0 then
children[tab]: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 internals = self.internals
local numinternals = #internals
if y < 0 then
local buttonheight = self:GetHeightOfButtons()
local col = loveframes.BoundingBox(self.x, x, self.y, y, self.width, 1, buttonheight, 1)
local visible = internals[numinternals - 1]:GetVisible()
if col and visible then
local scrollamount = -y * self.mousewheelscrollamount
local dtscrolling = self.dtscrolling
if dtscrolling then
local dt = love.timer.getDelta()
self.offsetx = self.offsetx + scrollamount * dt
else
self.offsetx = self.offsetx + scrollamount
end
if self.offsetx > 0 then
self.offsetx = 0
end
end
elseif y > 0 then
local buttonheight = self:GetHeightOfButtons()
local col = loveframes.BoundingBox(self.x, x, self.y, y, self.width, 1, buttonheight, 1)
local visible = internals[numinternals]:GetVisible()
if col and visible then
local bwidth = self:GetWidthOfButtons()
local scrollamount = y * self.mousewheelscrollamount
local dtscrolling = self.dtscrolling
if dtscrolling then
local dt = love.timer.getDelta()
self.offsetx = self.offsetx - scrollamount * dt
else
self.offsetx = self.offsetx - scrollamount
end
if ((self.offsetx + bwidth) + self.width) < self.width then
self.offsetx = -(bwidth + 10)
end
end
end
end
--[[---------------------------------------------------------
- func: AddTab(name, object, tip, image)
- desc: adds a new tab to the tab panel
--]]---------------------------------------------------------
function newobject:AddTab(name, object, tip, image, onopened, onclosed)
local padding = self.padding
local autosize = self.autosize
local retainsize = self.retainsize
local tabnumber = self.tabnumber
local tabheight = self.tabheight
local internals = self.internals
local state = self.state
object:Remove()
object.parent = self
object:SetState(state)
object.staticx = 0
object.staticy = 0
if tabnumber ~= 1 then
object.visible = false
end
local tab = loveframes.objects["tabbutton"]:new(self, name, tabnumber, tip, image, onopened, onclosed)
table.insert(self.children, object)
table.insert(self.internals, #self.internals - 1, tab)
self.tabnumber = tabnumber + 1
if autosize and not retainsize then
object:SetSize(self.width - padding * 2, (self.height - tabheight) - padding * 2)
end
return tab
end
--[[---------------------------------------------------------
- func: AddScrollButtons()
- desc: creates scroll buttons fot the tab panel
- note: for internal use only
--]]---------------------------------------------------------
function newobject:AddScrollButtons()
local internals = self.internals
local state = self.state
for k, v in ipairs(internals) do
if v.type == "scrollbutton" then
table.remove(internals, k)
end
end
local leftbutton = loveframes.objects["scrollbutton"]:new("left")
leftbutton.parent = self
leftbutton:SetPos(0, 0)
leftbutton:SetSize(15, 25)
leftbutton:SetAlwaysUpdate(true)
leftbutton.Update = function(object, dt)
object.staticx = 0
object.staticy = 0
if self.offsetx ~= 0 then
object.visible = true
else
object.visible = false
object.down = false
object.hover = false
end
if object.down then
if self.offsetx > 0 then
self.offsetx = 0
elseif self.offsetx ~= 0 then
local scrollamount = self.buttonscrollamount
local dtscrolling = self.dtscrolling
if dtscrolling then
local dt = love.timer.getDelta()
self.offsetx = self.offsetx + scrollamount * dt
else
self.offsetx = self.offsetx + scrollamount
end
end
end
end
local rightbutton = loveframes.objects["scrollbutton"]:new("right")
rightbutton.parent = self
rightbutton:SetPos(self.width - 15, 0)
rightbutton:SetSize(15, 25)
rightbutton:SetAlwaysUpdate(true)
rightbutton.Update = function(object, dt)
object.staticx = self.width - object.width
object.staticy = 0
local bwidth = self:GetWidthOfButtons()
if (self.offsetx + bwidth) - (self.buttonareax * 2 - 1) > self.width then
object.visible = true
else
object.visible = false
object.down = false
object.hover = false
end
if object.down then
if ((self.x + self.offsetx) + bwidth) ~= (self.x + self.width) then
local scrollamount = self.buttonscrollamount
local dtscrolling = self.dtscrolling
if dtscrolling then
local dt = love.timer.getDelta()
self.offsetx = self.offsetx - scrollamount * dt
else
self.offsetx = self.offsetx - scrollamount
end
end
end
end
leftbutton.state = state
rightbutton.state = state
table.insert(internals, leftbutton)
table.insert(internals, rightbutton)
end
--[[---------------------------------------------------------
- func: GetWidthOfButtons()
- desc: gets the total width of all of the tab buttons
--]]---------------------------------------------------------
function newobject:GetWidthOfButtons()
local width = 0
local internals = self.internals
for k, v in ipairs(internals) do
if v.type == "tabbutton" then
width = width + v.width
end
end
return width
end
--[[---------------------------------------------------------
- func: GetHeightOfButtons()
- desc: gets the height of one tab button
--]]---------------------------------------------------------
function newobject:GetHeightOfButtons()
return self.tabheight
end
--[[---------------------------------------------------------
- func: SwitchToTab(tabnumber)
- desc: makes the specified tab the active tab
--]]---------------------------------------------------------
function newobject:SwitchToTab(tabnumber)
local children = self.children
for k, v in ipairs(children) do
v.visible = false
end
self.tab = tabnumber
self.children[tabnumber].visible = true
return self
end
--[[---------------------------------------------------------
- func: SetScrollButtonSize(width, height)
- desc: sets the size of the scroll buttons
--]]---------------------------------------------------------
function newobject:SetScrollButtonSize(width, height)
local internals = self.internals
for k, v in ipairs(internals) do
if v.type == "scrollbutton" then
v:SetSize(width, height)
end
end
return self
end
--[[---------------------------------------------------------
- func: SetPadding(paddint)
- desc: sets the padding for the tab panel
--]]---------------------------------------------------------
function newobject:SetPadding(padding)
self.padding = padding
return self
end
--[[---------------------------------------------------------
- func: SetPadding(paddint)
- desc: gets the padding of the tab panel
--]]---------------------------------------------------------
function newobject:GetPadding()
return self.padding
end
--[[---------------------------------------------------------
- func: SetTabHeight(height)
- desc: sets the height of the tab buttons
--]]---------------------------------------------------------
function newobject:SetTabHeight(height)
local autosize = self.autosize
local padding = self.padding
local previoustabheight = self.previoustabheight
local children = self.children
local internals = self.internals
self.tabheight = height
local tabheight = self.tabheight
if tabheight ~= previoustabheight then
for k, v in ipairs(children) do
local retainsize = v.retainsize
if autosize and not retainsize then
v:SetSize(self.width - padding*2, (self.height - tabheight) - padding*2)
end
end
self.previoustabheight = tabheight
end
for k, v in ipairs(internals) do
if v.type == "tabbutton" then
v:SetHeight(self.tabheight)
end
end
return self
end
--[[---------------------------------------------------------
- func: SetToolTipFont(font)
- desc: sets the height of the tab buttons
--]]---------------------------------------------------------
function newobject:SetToolTipFont(font)
local internals = self.internals
for k, v in ipairs(internals) do
if v.type == "tabbutton" and v.tooltip then
v.tooltip:SetFont(font)
end
end
return self
end
--[[---------------------------------------------------------
- func: GetTabNumber()
- desc: gets the object's tab number
--]]---------------------------------------------------------
function newobject:GetTabNumber()
return self.tab
end
--[[---------------------------------------------------------
- func: RemoveTab(id)
- desc: removes a tab from the object
--]]---------------------------------------------------------
function newobject:RemoveTab(id)
local children = self.children
local internals = self.internals
local tab = children[id]
if tab then
tab:Remove()
end
for k, v in ipairs(internals) do
if v.type == "tabbutton" then
if v.tabnumber == id then
v:Remove()
end
end
end
local tabnumber = 1
for k, v in ipairs(internals) do
if v.type == "tabbutton" then
v.tabnumber = tabnumber
tabnumber = tabnumber + 1
end
end
self.tabnumber = tabnumber
return self
end
--[[---------------------------------------------------------
- func: SetButtonScrollAmount(speed)
- desc: sets the scroll amount of the object's scrollbar
buttons
--]]---------------------------------------------------------
function newobject:SetButtonScrollAmount(amount)
self.buttonscrollamount = amount
return self
end
--[[---------------------------------------------------------
- func: GetButtonScrollAmount()
- desc: gets the scroll amount of the object's scrollbar
buttons
--]]---------------------------------------------------------
function newobject:GetButtonScrollAmount()
return self.buttonscrollamount
end
--[[---------------------------------------------------------
- func: SetMouseWheelScrollAmount(amount)
- desc: sets the scroll amount of the mouse wheel
--]]---------------------------------------------------------
function newobject:SetMouseWheelScrollAmount(amount)
self.mousewheelscrollamount = amount
return self
end
--[[---------------------------------------------------------
- func: GetMouseWheelScrollAmount()
- desc: gets the scroll amount of the mouse wheel
--]]---------------------------------------------------------
function newobject:GetButtonScrollAmount()
return self.mousewheelscrollamount
end
--[[---------------------------------------------------------
- func: SetDTScrolling(bool)
- desc: sets whether or not the object should use delta
time when scrolling
--]]---------------------------------------------------------
function newobject:SetDTScrolling(bool)
self.dtscrolling = bool
return self
end
--[[---------------------------------------------------------
- func: GetDTScrolling()
- desc: gets whether or not the object should use delta
time when scrolling
--]]---------------------------------------------------------
function newobject:GetDTScrolling()
return self.dtscrolling
end
--[[---------------------------------------------------------
- func: SetTabObject(id, object)
- desc: sets the object of a tab
--]]---------------------------------------------------------
function newobject:SetTabObject(id, object)
local children = self.children
local internals = self.internals
local tab = children[id]
local state = self.state
if tab then
tab:Remove()
object:Remove()
object.parent = self
object:SetState(state)
object.staticx = 0
object.staticy = 0
children[id] = object
end
return self
end
--[[---------------------------------------------------------
- func: SetButtonAreaX(x)
- desc: sets the x position of the object's button area
--]]---------------------------------------------------------
function newobject:SetButtonAreaX(x)
self.buttonareax = x
return self
end
--[[---------------------------------------------------------
- func: GetButtonAreaX()
- desc: gets the x position of the object's button area
--]]---------------------------------------------------------
function newobject:GetButtonAreaX()
return self.buttonareax
end
--[[---------------------------------------------------------
- func: SetButtonAreaWidth(width)
- desc: sets the width of the object's button area
--]]---------------------------------------------------------
function newobject:SetButtonAreaWidth(width)
self.buttonareawidth = width
return self
end
--[[---------------------------------------------------------
- func: GetButtonAreaWidth()
- desc: gets the width of the object's button area
--]]---------------------------------------------------------
function newobject:GetButtonAreaWidth()
return self.buttonareawidth
end
--[[---------------------------------------------------------
- func: SetAutoButtonAreaWidth(bool)
- desc: sets whether or not the width of the object's
button area should be adjusted automatically
--]]---------------------------------------------------------
function newobject:SetAutoButtonAreaWidth(bool)
self.autobuttonareawidth = bool
return self
end
--[[---------------------------------------------------------
- func: GetAutoButtonAreaWidth()
- desc: gets whether or not the width of the object's
button area should be adjusted automatically
--]]---------------------------------------------------------
function newobject:GetAutoButtonAreaWidth()
return self.autobuttonareawidth
end
---------- module end ----------
end

802
loveframes/objects/text.lua Normal file
View File

@ -0,0 +1,802 @@
--[[------------------------------------------------
-- Love Frames - A GUI library for LOVE --
-- Copyright (c) 2012-2014 Kenny Shields --
--]]------------------------------------------------
--[[------------------------------------------------
-- note: the text wrapping of this object is
experimental and not final
--]]------------------------------------------------
return function(loveframes)
---------- module start ----------
-- text object
local newobject = loveframes.NewObject("text", "loveframes_object_text", true)
--[[---------------------------------------------------------
- func: initialize()
- desc: initializes the object
--]]---------------------------------------------------------
function newobject:initialize()
self.type = "text"
self.text = ""
self.font = loveframes.basicfont
self.width = 5
self.height = 5
self.maxw = 0
self.shadowxoffset = 1
self.shadowyoffset = 1
self.lines = 0
self.formattedtext = {}
self.original = {}
self.defaultcolor = {0, 0, 0, 1}
self.shadowcolor = {0, 0, 0, 1}
self.linkcolor = {0, .4, 1, 1}
self.linkhovercolor = {0, 0, 1, 1}
self.ignorenewlines = false
self.shadow = false
self.linkcol = false
self.internal = false
self.linksenabled = false
self.detectlinks = false
self.OnClickLink = nil
local skin = loveframes.GetActiveSkin()
if not skin then
skin = loveframes.config["DEFAULTSKIN"]
end
local directives = skin.directives
if directives then
local text_default_color = directives.text_default_color
local text_default_shadowcolor = directives.text_default_shadowcolor
local text_default_font = directives.text_default_font
if text_default_color then
self.defaultcolor = text_default_color
end
if text_default_shadowcolor then
self.shadowcolor = text_default_shadowcolor
end
if text_default_font then
self.font = text_default_font
end
end
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 parent = self.parent
local base = loveframes.base
local update = self.Update
self:CheckHover()
local hover = self.hover
local linksenabled = self.linksenabled
local linkcol = false
if hover and linksenabled and not loveframes.resizeobject then
local formattedtext = self.formattedtext
local x = self.x
local y = self.y
for k, v in ipairs(formattedtext) do
local link = v.link
if link then
local mx, my = love.mouse.getPosition()
local font = v.font
local linkx = v.x
local linky = v.y
local text = v.text
local twidth = font:getWidth(text)
local theight = font:getHeight()
local col = loveframes.BoundingBox(x + linkx, mx, y + linky, my, twidth, 1, theight, 1)
v.hover = false
if col then
v.hover = true
linkcol = true
end
end
end
self.linkcol = linkcol
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
local hover = self.hover
if hover and button == 1 then
local baseparent = self:GetBaseParent()
if baseparent and baseparent.type == "frame" then
baseparent:MakeTop()
end
local linksenabled = self.linksenabled
if linksenabled then
local formattedtext = self.formattedtext
local objx = self.x
local objy = self.y
for k, v in ipairs(formattedtext) do
local link = v.link
if link then
local linkx = v.x
local linky = v.y
local font = v.font
local text = v.text
local twidth = font:getWidth(text)
local theight = font:getHeight()
local col = loveframes.BoundingBox(objx + linkx, x, objy + linky, y, twidth, 1, theight, 1)
if col then
local onclicklink = self.OnClickLink
if onclicklink then
onclicklink(self, text)
end
end
end
end
end
end
end
--[[---------------------------------------------------------
- func: SetText(text)
- desc: sets the object's text
--]]---------------------------------------------------------
function newobject:SetText(t)
local dtype = type(t)
local maxw = self.maxw
local font = self.font
local defaultcolor = self.defaultcolor
local inserts = {}
local prevcolor = defaultcolor
local prevlinkcolor = self.linkcolor
local prevlinkhovercolor = self.linkhovercolor
local prevfont = font
local link = false
local tdata
self.text = ""
self.formattedtext = {}
if dtype == "string" then
tdata = {t}
self.original = {t}
elseif dtype == "number" then
tdata = {tostring(t)}
self.original = {tostring(t)}
elseif dtype == "table" then
tdata = t
self.original = t
else
return
end
for k, v in ipairs(tdata) do
dtype = type(v)
if dtype == "table" then
if v.color then
prevcolor = v.color
end
if v.linkcolor then
prevlinkcolor = v.linkcolor
end
if v.linkhovercolor then
prevlinkhovercolor = v.linkhovercolor
end
if v.font then
prevfont = v.font
end
if v.link then
link = true
else
link = false
end
elseif dtype == "number" then
table.insert(self.formattedtext, {
font = prevfont,
color = prevcolor,
linkcolor = prevlinkcolor,
linkhovercolor = prevlinkhovercolor,
link = link,
text = tostring(v)
})
elseif dtype == "string" then
if self.ignorenewlines then
v = loveframes.utf8.gsub(v, "\n", " ")
end
v = loveframes.utf8.gsub(v, string.char(9), " ")
v = loveframes.utf8.gsub(v, "\n", " \n ")
local parts = loveframes.SplitString(v, " ")
for i, j in ipairs(parts) do
table.insert(self.formattedtext, {
font = prevfont,
color = prevcolor,
linkcolor = prevlinkcolor,
linkhovercolor = prevlinkhovercolor,
link = link,
text = j
})
end
end
end
if maxw > 0 then
for k, v in ipairs(self.formattedtext) do
local data = v.text
local width = v.font:getWidth(data)
local curw = 0
local new = ""
local key = k
if width > maxw then
table.remove(self.formattedtext, k)
for n=1, loveframes.utf8.len(data) do
local item = loveframes.utf8.sub(data, n, n)
local itemw = v.font:getWidth(item)
if n ~= loveframes.utf8.len(data) then
if (curw + itemw) > maxw then
table.insert(inserts, {
key = key,
font = v.font,
color = v.color,
linkcolor = prevlinkcolor,
linkhovercolor = v.linkhovercolor,
link = v.link,
text = new
})
new = item
curw = 0 + itemw
key = key + 1
else
new = new .. item
curw = curw + itemw
end
else
new = new .. item
table.insert(inserts, {
key = key,
font = v.font,
color = v.color,
linkcolor = prevlinkcolor,
linkhovercolor = v.linkhovercolor,
link = v.link,
text = new
})
end
end
end
end
end
for k, v in ipairs(inserts) do
table.insert(self.formattedtext, v.key, {
font = v.font,
color = v.color,
linkcolor = prevlinkcolor,
linkhovercolor = v.linkhovercolor,
link = v.link,
text = v.text
})
end
local textdata = self.formattedtext
local maxw = self.maxw
local font = self.font
local twidth = 0
local drawx = 0
local drawy = 0
local lines = 1
local textwidth = 0
local lastwidth = 0
local totalwidth = 0
local x = self.x
local y = self.y
local prevtextwidth = 0
local prevtextheight = 0
local prevlargestheight = 0
local largestwidth = 0
local largestheight = 0
local initialwidth = 0
local detectlinks = self.detectlinks
for k, v in ipairs(textdata) do
local text = v.text
local color = v.color
if detectlinks then
if loveframes.utf8.len(text) > 7 and (loveframes.utf8.sub(text, 1, 7) == "http://" or loveframes.utf8.sub(text, 1, 8) == "https://") then
v.link = true
end
end
if type(text) == "string" then
self.text = self.text .. text
local width = v.font:getWidth(text)
local height = v.font:getHeight("a")
if height > largestheight then
largestheight = height
prevlargestheight = height
end
totalwidth = totalwidth + width
if maxw > 0 then
if k ~= 1 then
if string.byte(text) == 10 then
twidth = 0
drawx = 0
width = 0
drawy = drawy + largestheight
largestheight = 0
text = ""
lines = lines + 1
elseif (twidth + width) > maxw then
twidth = 0 + width
drawx = 0
drawy = drawy + largestheight
largestheight = 0
lines = lines + 1
else
twidth = twidth + width
drawx = drawx + prevtextwidth
end
else
twidth = twidth + width
end
prevtextwidth = width
prevtextheight = height
v.x = drawx
v.y = drawy
else
if string.byte(text) == 10 then
twidth = 0
drawx = 0
width = 0
drawy = drawy + largestheight
largestheight = 0
text = ""
lines = lines + 1
if lastwidth < textwidth then
lastwidth = textwidth
end
if largestwidth < textwidth then
largestwidth = textwidth
end
textwidth = 0
else
drawx = drawx + prevtextwidth
textwidth = textwidth + width
end
prevtextwidth = width
prevtextheight = height
v.x = drawx
v.y = drawy
end
end
end
self.lines = lines
if lastwidth == 0 then
textwidth = totalwidth
end
if textwidth < largestwidth then
textwidth = largestwidth
end
if maxw > 0 then
self.width = maxw
else
self.width = textwidth
end
self.height = drawy + prevlargestheight
return self
end
--[[---------------------------------------------------------
- func: GetText()
- desc: gets the object's text
--]]---------------------------------------------------------
function newobject:GetText()
return self.text
end
--[[---------------------------------------------------------
- func: GetFormattedText()
- desc: gets the object's formatted text
--]]---------------------------------------------------------
function newobject:GetFormattedText()
return self.formattedtext
end
--[[---------------------------------------------------------
- func: DrawText()
- desc: draws the object's text
--]]---------------------------------------------------------
function newobject:DrawText()
local textdata = self.formattedtext
local x = self.x
local y = self.y
local shadow = self.shadow
local shadowxoffset = self.shadowxoffset
local shadowyoffset = self.shadowyoffset
local shadowcolor = self.shadowcolor
local inlist, list = self:IsInList()
local printfunc = function(text, x, y)
love.graphics.print(text, math.floor(x + 0.5), math.floor(y + 0.5))
end
for k, v in ipairs(textdata) do
local textx = v.x
local texty = v.y
local text = v.text
local color = v.color
local font = v.font
local link = v.link
local theight = font:getHeight("a")
if inlist then
local listy = list.y
local listhieght = list.height
if (y + texty) <= (listy + listhieght) and y + ((texty + theight)) >= listy then
love.graphics.setFont(font)
if shadow then
love.graphics.setColor(unpack(shadowcolor))
printfunc(text, x + textx + shadowxoffset, y + texty + shadowyoffset)
end
if link then
local linkcolor = v.linkcolor
local linkhovercolor = v.linkhovercolor
local hover = v.hover
if hover then
love.graphics.setColor(linkhovercolor)
else
love.graphics.setColor(linkcolor)
end
else
love.graphics.setColor(unpack(color))
end
printfunc(text, x + textx, y + texty)
end
else
love.graphics.setFont(font)
if shadow then
love.graphics.setColor(unpack(shadowcolor))
printfunc(text, x + textx + shadowxoffset, y + texty + shadowyoffset)
end
if link then
local linkcolor = v.linkcolor
local linkhovercolor = v.linkhovercolor
local hover = v.hover
if hover then
love.graphics.setColor(linkhovercolor)
else
love.graphics.setColor(linkcolor)
end
else
love.graphics.setColor(unpack(color))
end
printfunc(text, x + textx, y + texty)
end
end
return self
end
--[[---------------------------------------------------------
- func: SetMaxWidth(width)
- desc: sets the object's maximum width
--]]---------------------------------------------------------
function newobject:SetMaxWidth(width)
local original = self.original
self.maxw = width
self:SetText(original)
return self
end
--[[---------------------------------------------------------
- func: GetMaxWidth()
- desc: gets the object's maximum width
--]]---------------------------------------------------------
function newobject:GetMaxWidth()
return self.maxw
end
--[[---------------------------------------------------------
- func: SetWidth(width, relative)
- desc: sets the object's width
--]]---------------------------------------------------------
function newobject:SetWidth(width, relative)
if relative then
self:SetMaxWidth(self.parent.width * width)
else
self:SetMaxWidth(width)
end
return self
end
--[[---------------------------------------------------------
- func: SetHeight()
- desc: sets the object's height
--]]---------------------------------------------------------
function newobject:SetHeight(height)
return
end
--[[---------------------------------------------------------
- func: SetSize(width, height, relative)
- desc: sets the object's size
--]]---------------------------------------------------------
function newobject:SetSize(width, height, relative)
if relative then
self:SetMaxWidth(self.parent.width * width)
else
self:SetMaxWidth(width)
end
return self
end
--[[---------------------------------------------------------
- func: SetFont(font)
- desc: sets the object's font
- note: font argument must be a font object
--]]---------------------------------------------------------
function newobject:SetFont(font)
local original = self.original
self.font = font
if original then
self:SetText(original)
end
return self
end
--[[---------------------------------------------------------
- func: GetFont()
- desc: gets the object's font
--]]---------------------------------------------------------
function newobject:GetFont()
return self.font
end
--[[---------------------------------------------------------
- func: GetLines()
- desc: gets the number of lines the object's text uses
--]]---------------------------------------------------------
function newobject:GetLines()
return self.lines
end
--[[---------------------------------------------------------
- func: SetIgnoreNewlines(bool)
- desc: sets whether the object should ignore \n or not
--]]---------------------------------------------------------
function newobject:SetIgnoreNewlines(bool)
self.ignorenewlines = bool
return self
end
--[[---------------------------------------------------------
- func: GetIgnoreNewlines()
- desc: gets whether the object should ignore \n or not
--]]---------------------------------------------------------
function newobject:GetIgnoreNewlines()
return self.ignorenewlines
end
--[[---------------------------------------------------------
- func: SetShadow(bool)
- desc: sets whether or not the object should draw a
shadow behind its text
--]]---------------------------------------------------------
function newobject:SetShadow(bool)
self.shadow = bool
return self
end
--[[---------------------------------------------------------
- func: GetShadow()
- desc: gets whether or not the object should draw a
shadow behind its text
--]]---------------------------------------------------------
function newobject:GetShadow()
return self.shadow
end
--[[---------------------------------------------------------
- func: SetShadowOffsets(offsetx, offsety)
- desc: sets the object's x and y shadow offsets
--]]---------------------------------------------------------
function newobject:SetShadowOffsets(offsetx, offsety)
self.shadowxoffset = offsetx
self.shadowyoffset = offsety
return self
end
--[[---------------------------------------------------------
- func: GetShadowOffsets()
- desc: gets the object's x and y shadow offsets
--]]---------------------------------------------------------
function newobject:GetShadowOffsets()
return self.shadowxoffset, self.shadowyoffset
end
--[[---------------------------------------------------------
- func: SetShadowColor(r, g, b, a)
- desc: sets the object's shadow color
--]]---------------------------------------------------------
function newobject:SetShadowColor(r, g, b, a)
self.shadowcolor = {r, g, b, a}
return self
end
--[[---------------------------------------------------------
- func: GetShadowColor()
- desc: gets the object's shadow color
--]]---------------------------------------------------------
function newobject:GetShadowColor()
return self.shadowcolor
end
--[[---------------------------------------------------------
- func: SetDefaultColor(r, g, b, a)
- desc: sets the object's default text color
--]]---------------------------------------------------------
function newobject:SetDefaultColor(r, g, b, a)
self.defaultcolor = {r, g, b, a}
return self
end
--[[---------------------------------------------------------
- func: GetDefaultColor()
- desc: gets whether or not the object should draw a
shadow behind its text
--]]---------------------------------------------------------
function newobject:GetDefaultColor()
return self.defaultcolor
end
--[[---------------------------------------------------------
- func: SetLinksEnabled(enabled)
- desc: sets whether or not the object should process
urls into clickable links
--]]---------------------------------------------------------
function newobject:SetLinksEnabled(enabled)
self.linksenabled = enabled
return self
end
--[[---------------------------------------------------------
- func: GetLinksEnabled()
- desc: gets whether or not the object should process
urls into clickable links
--]]---------------------------------------------------------
function newobject:GetLinksEnabled()
return self.linksenabled
end
--[[---------------------------------------------------------
- func: SetDetectLinks(detect)
- desc: sets whether or not the object should detect
links when processing new text
--]]---------------------------------------------------------
function newobject:SetDetectLinks(detect)
self.detectlinks = detect
return self
end
--[[---------------------------------------------------------
- func: GetDetectLinks()
- desc: gets whether or not the object should detect
links when processing new text
--]]---------------------------------------------------------
function newobject:GetDetectLinks()
return self.detectlinks
end
---------- module end ----------
end

File diff suppressed because it is too large Load Diff

342
loveframes/objects/tree.lua Normal file
View File

@ -0,0 +1,342 @@
--[[------------------------------------------------
-- Love Frames - A GUI library for LOVE --
-- Copyright (c) 2012-2014 Kenny Shields --
--]]------------------------------------------------
return function(loveframes)
---------- module start ----------
-- tree object
local newobject = loveframes.NewObject("tree", "loveframes_object_tree", true)
--[[---------------------------------------------------------
- func: initialize()
- desc: initializes the object
--]]---------------------------------------------------------
function newobject:initialize()
self.type = "tree"
self.width = 200
self.height = 200
self.offsetx = 0
self.offsety = 0
self.itemwidth = 0
self.itemheight = 0
self.extrawidth = 0
self.extraheight = 0
self.buttonscrollamount = 0.10
self.vbar = false
self.hbar = false
self.internal = false
self.selectednode = false
self.OnSelectNode = nil
self.children = {}
self.internals = {}
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
self.itemwidth = 0
self.itemheight = 0
for k, v in ipairs(self.children) do
v.x = (v.parent.x + v.staticx) - self.offsetx
v.y = (self.y + self.itemheight) - self.offsety
if v.width > self.itemwidth then
self.itemwidth = v.width
end
self.itemheight = self.itemheight + v.height
v:update(dt)
end
if self.vbar then
self.itemwidth = self.itemwidth + 16 + 5
end
self.extrawidth = self.itemwidth - self.width
self.extraheight = self.itemheight - self.height
if self.itemheight > self.height then
if not self.vbar then
local scrollbody = loveframes.objects["scrollbody"]:new(self, "vertical")
table.insert(self.internals, scrollbody)
self.vbar = true
if self.hbar then
local vbody = self:GetVerticalScrollBody()
local vbodyheight = vbody:GetHeight() - 15
local hbody = self:GetHorizontalScrollBody()
local hbodywidth = hbody:GetWidth() - 15
vbody:SetHeight(vbodyheight)
hbody:SetWidth(hbodywidth)
end
end
else
if self.vbar then
self:GetVerticalScrollBody():Remove()
self.vbar = false
self.offsety = 0
if self.hbar then
local hbody = self:GetHorizontalScrollBody()
local hbodywidth = hbody:GetWidth() - 15
hbody:SetWidth(hbodywidth)
end
end
end
if self.itemwidth > self.width then
if not self.hbar then
local scrollbody = loveframes.objects["scrollbody"]:new(self, "horizontal")
table.insert(self.internals, scrollbody)
self.hbar = true
if self.vbar then
local vbody = self:GetVerticalScrollBody()
local hbody = self:GetHorizontalScrollBody()
vbody:SetHeight(vbody:GetHeight() - 15)
hbody:SetWidth(hbody:GetWidth() - 15)
end
end
else
if self.hbar then
self:GetHorizontalScrollBody():Remove()
self.hbar = false
self.offsetx = 0
if self.vbar then
local vbody = self:GetVerticalScrollBody()
if vbody then
vbody:SetHeight(vbody:GetHeight() + 15)
end
end
end
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 stencilfunc
if self.vbar and not self.hbar then
stencilfunc = function() love.graphics.rectangle("fill", self.x, self.y, self.width - 16, self.height) end
elseif self.hbar and not self.vbar then
stencilfunc = function() love.graphics.rectangle("fill", self.x, self.y, self.width, self.height - 16) end
elseif self.vbar and self.hbar then
stencilfunc = function() love.graphics.rectangle("fill", self.x, self.y, self.width - 16, self.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
local children = self.children
if children then
for k, v in ipairs(children) do
v:draw()
end
end
love.graphics.setStencilTest()
local internals = self.internals
if internals then
for k, v in ipairs(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 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
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 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
for k, v in ipairs(self.children) do
v:mousereleased(x, y, button)
end
end
--[[---------------------------------------------------------
- func: AddNode(text)
- desc: adds a node to the object
--]]---------------------------------------------------------
function newobject:AddNode(text)
local node = loveframes.objects["treenode"]:new()
node.parent = self
node.tree = self
node.text = text
node.staticx = 0
node.staticy = self.itemheight
table.insert(self.children, node)
return node
end
--[[---------------------------------------------------------
- func: RemoveNode(id)
- desc: removes a node from the object
--]]---------------------------------------------------------
function newobject:RemoveNode(id)
for k, v in ipairs(self.children) do
if k == id then
v:Remove()
break
end
end
end
--[[---------------------------------------------------------
- func: GetVerticalScrollBody()
- desc: gets the object's vertical scroll body
--]]---------------------------------------------------------
function newobject:GetVerticalScrollBody()
local vbar = self.vbar
local internals = self.internals
local item = false
if vbar then
for k, v in ipairs(internals) do
if v.type == "scrollbody" and v.bartype == "vertical" then
item = v
end
end
end
return item
end
--[[---------------------------------------------------------
- func: GetHorizontalScrollBody()
- desc: gets the object's horizontal scroll body
--]]---------------------------------------------------------
function newobject:GetHorizontalScrollBody()
local hbar = self.hbar
local internals = self.internals
local item = false
if hbar then
for k, v in ipairs(internals) do
if v.type == "scrollbody" and v.bartype == "horizontal" then
item = v
end
end
end
return item
end
---------- module end ----------
end