Initial commit

This commit is contained in:
Kenny Shields 2012-05-05 20:24:42 -04:00
commit 5fe9cdb806
44 changed files with 10424 additions and 0 deletions

575
debug.lua Normal file
View File

@ -0,0 +1,575 @@
--[[------------------------------------------------
-- LÖVE Frames --
-- By Nikolai Resokav --
--]]------------------------------------------------
loveframes.debug = {}
local font = love.graphics.newFont(10)
local loremipsum =
[[
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Proin dui enim, porta eget facilisis quis, laoreet sit amet urna.
Maecenas lobortis venenatis euismod.
Sed at diam sit amet odio feugiat pretium nec quis libero.
Quisque auctor semper imperdiet.
Maecenas risus eros, varius pharetra volutpat in, fermentum scelerisque lacus.
Proin lectus erat, luctus non facilisis vel, hendrerit vitae nisl.
Aliquam vulputate scelerisque odio id faucibus.
]]
function loveframes.debug.draw()
-- get the current debug setting
local debug = loveframes.config["DEBUG"]
-- do not draw anthing if debug is off
if debug == false then
return
end
local cols = loveframes.util.GetCollisions()
local numcols = #cols
local topcol = cols[numcols] or {type = none, children = {}, x = 0, y = 0, width = 0, height = 0}
local bchildren = #loveframes.base.children
local objects = loveframes.util.GetAllObjects()
-- font for debug text
love.graphics.setFont(font)
love.graphics.setLine(1, "smooth")
love.graphics.setColor(0, 0, 0, 255)
love.graphics.print("Library Information", 6, 6)
love.graphics.setColor(255, 0, 0, 255)
love.graphics.print("Library Information", 5, 5)
love.graphics.setColor(0, 0, 0, 255)
love.graphics.line(6, 21, 190, 21)
love.graphics.setColor(255, 255, 255, 255)
love.graphics.line(5, 20, 190, 20)
love.graphics.setColor(0, 0, 0, 255)
love.graphics.print("Author: " ..loveframes.info.author, 6, 26)
love.graphics.setColor(255, 255, 255, 255)
love.graphics.print("Author: " ..loveframes.info.author, 5, 25)
love.graphics.setColor(0, 0, 0, 255)
love.graphics.print("Version: " ..loveframes.info.version, 6, 36)
love.graphics.setColor(255, 255, 255, 255)
love.graphics.print("Version: " ..loveframes.info.version, 5, 35)
love.graphics.setColor(0, 0, 0, 255)
love.graphics.print("Stage: " ..loveframes.info.stage, 6, 46)
love.graphics.setColor(255, 255, 255, 255)
love.graphics.print("Stage: " ..loveframes.info.stage, 5, 45)
love.graphics.setColor(0, 0, 0, 255)
love.graphics.print("Base Directory: " ..loveframes.config["DIRECTORY"], 6, 56)
love.graphics.setColor(255, 255, 255, 255)
love.graphics.print("Base Directory: " ..loveframes.config["DIRECTORY"], 5, 55)
-- object information box
love.graphics.setColor(0, 0, 0, 255)
love.graphics.print("Object Information", 6, 81)
love.graphics.setColor(255, 0, 0, 255)
love.graphics.print("Object Information", 5, 80)
love.graphics.setColor(0, 0, 0, 255)
love.graphics.line(6, 96, 190, 96)
love.graphics.setColor(255, 255, 255, 255)
love.graphics.line(5, 95, 190, 95)
if numcols > 0 then
love.graphics.setColor(0, 0, 0, 255)
love.graphics.print("Type: " ..topcol.type, 6, 101)
love.graphics.setColor(255, 255, 255, 255)
love.graphics.print("Type: " ..topcol.type, 5, 100)
else
love.graphics.setColor(0, 0, 0, 255)
love.graphics.print("Type: none", 6, 101)
love.graphics.setColor(255, 255, 255, 255)
love.graphics.print("Type: none", 5, 100)
end
if topcol.children then
love.graphics.setColor(0, 0, 0, 255)
love.graphics.print("# of children: " .. #topcol.children, 6, 111)
love.graphics.setColor(255, 255, 255, 255)
love.graphics.print("# of children: " .. #topcol.children, 5, 110)
else
love.graphics.setColor(0, 0, 0, 255)
love.graphics.print("# of children: 0", 6, 111)
love.graphics.setColor(255, 255, 255, 255)
love.graphics.print("# of children: 0", 5, 110)
end
love.graphics.setColor(0, 0, 0, 255)
love.graphics.print("X: " ..topcol.x, 6, 121)
love.graphics.setColor(255, 255, 255, 255)
love.graphics.print("X: " ..topcol.x, 5, 120)
love.graphics.setColor(0, 0, 0, 255)
love.graphics.print("Y: " ..topcol.y, 6, 131)
love.graphics.setColor(255, 255, 255, 255)
love.graphics.print("Y: " ..topcol.y, 5, 130)
love.graphics.setColor(0, 0, 0, 255)
love.graphics.print("Width: " ..topcol.width, 6, 141)
love.graphics.setColor(255, 255, 255, 255)
love.graphics.print("Width: " ..topcol.width, 5, 140)
love.graphics.setColor(0, 0, 0, 255)
love.graphics.print("Height: " ..topcol.height, 6, 151)
love.graphics.setColor(255, 255, 255, 255)
love.graphics.print("Height: " ..topcol.height, 5, 150)
-- Miscellaneous box
love.graphics.setColor(0, 0, 0, 255)
love.graphics.print("Miscellaneous: ", 6, 191)
love.graphics.setColor(255, 0, 0, 255)
love.graphics.print("Miscellaneous", 5, 190)
love.graphics.setColor(0, 0, 0, 255)
love.graphics.line(6, 206, 190, 206)
love.graphics.setColor(255, 255, 255, 255)
love.graphics.line(5, 205, 190, 205)
love.graphics.setColor(0, 0, 0, 255)
love.graphics.print("LOVE Version: " ..love._version, 6, 211)
love.graphics.setColor(255, 255, 255, 255)
love.graphics.print("LOVE Version: " ..love._version, 5, 210)
love.graphics.setColor(0, 0, 0, 255)
love.graphics.print("FPS: " ..love.timer.getFPS(), 6, 221)
love.graphics.setColor(255, 255, 255, 255)
love.graphics.print("FPS: " ..love.timer.getFPS(), 5, 220)
love.graphics.setColor(0, 0, 0, 255)
love.graphics.print("Delta Time: " ..love.timer.getDelta(), 6, 231)
love.graphics.setColor(255, 255, 255, 255)
love.graphics.print("Delta Time: " ..love.timer.getDelta(), 5, 230)
love.graphics.setColor(0, 0, 0, 255)
love.graphics.print("Total Objects: " ..#objects, 6, 241)
love.graphics.setColor(255, 255, 255, 255)
love.graphics.print("Total Objects: " ..#objects, 5, 240)
-- outline the object that the mouse is hovering over
love.graphics.setColor(255, 204, 51, 255)
love.graphics.setLine(2, "smooth")
love.graphics.rectangle("line", topcol.x - 1, topcol.y - 1, topcol.width + 2, topcol.height + 2)
end
function loveframes.debug.ExamplesMenu()
------------------------------------
-- examples frame
------------------------------------
local examplesframe = loveframes.Create("frame")
examplesframe:SetName("Examples List")
examplesframe:SetSize(200, love.graphics.getHeight() - 265)
examplesframe:SetPos(5, 260)
------------------------------------
-- examples list
------------------------------------
local exampleslist = loveframes.Create("list", examplesframe)
exampleslist:SetSize(200, exampleslist:GetParent():GetHeight() - 25)
exampleslist:SetPos(0, 25)
exampleslist:SetPadding(5)
exampleslist:SetSpacing(5)
exampleslist:SetDisplayType("vertical")
------------------------------------
-- button example
------------------------------------
local buttonexample = loveframes.Create("button")
buttonexample:SetText("Button")
buttonexample.OnClick = function(object1, x, y)
local frame1 = loveframes.Create("frame")
frame1:SetName("Button")
frame1:Center()
local button1 = loveframes.Create("button", frame1)
button1:SetWidth(200)
button1:SetText("Button")
button1:Center()
button1.OnClick = function(object2, x, y)
object2:SetText("You clicked the button!")
end
button1.OnMouseEnter = function(object2)
object2:SetText("The mouse entered the button.")
end
button1.OnMouseExit = function(object2)
object2:SetText("The mouse exited the button.")
end
end
exampleslist:AddItem(buttonexample)
------------------------------------
-- checkbox example
------------------------------------
local checkboxexample = loveframes.Create("button")
checkboxexample:SetText("Checkbox")
checkboxexample.OnClick = function(object1, x, y)
local frame1 = loveframes.Create("frame")
frame1:SetName("Checkbox")
frame1:Center()
local checkbox1 = loveframes.Create("checkbox", frame1)
checkbox1:SetText("Checkbox 1")
checkbox1:SetPos(5, 30)
--checkbox1:SetFont(love.graphics.newFont(50))
checkbox1.OnChanged = function(object2)
end
local checkbox2 = loveframes.Create("checkbox", frame1)
checkbox2:SetText("Checkbox 2")
checkbox2:SetPos(5, 60)
checkbox2.OnChanged = function(object3)
end
end
exampleslist:AddItem(checkboxexample)
------------------------------------
-- collapsible category example
------------------------------------
local collapsiblecategoryexample = loveframes.Create("button")
collapsiblecategoryexample:SetText("Collapsible Category")
collapsiblecategoryexample.OnClick = function(object1, x, y)
local frame1 = loveframes.Create("frame")
frame1:SetName("Collapsible Category")
frame1:SetSize(500, 300)
frame1:Center()
local panel1 = loveframes.Create("panel")
local collapsiblecategory1 = loveframes.Create("collapsiblecategory", frame1)
collapsiblecategory1:SetPos(5, 30)
collapsiblecategory1:SetSize(490, 265)
collapsiblecategory1:SetText("Category 1")
collapsiblecategory1:SetObject(panel1)
end
exampleslist:AddItem(collapsiblecategoryexample)
------------------------------------
-- cloumnlist example
------------------------------------
local cloumnlistexample = loveframes.Create("button")
cloumnlistexample:SetText("Column List")
cloumnlistexample.OnClick = function(object1, x, y)
local frame1 = loveframes.Create("frame")
frame1:SetName("Column List")
frame1:SetSize(500, 300)
frame1:Center()
local list1 = loveframes.Create("columnlist", frame1)
list1:SetPos(5, 30)
list1:SetSize(490, 265)
list1:AddColumn("Column 1")
list1:AddColumn("Column 2")
list1:AddColumn("Column 3")
list1:AddColumn("Column 4")
list1.OnRowClicked = function(parent, row, rowdata)
print(unpack(rowdata))
end
for i=1, 20 do
list1:AddRow("Row " ..i.. ", column 1", "Row " ..i.. ", column 2", "Row " ..i.. ", column 3", "Row " ..i.. ", column 4")
end
end
exampleslist:AddItem(cloumnlistexample)
------------------------------------
-- frame example
------------------------------------
local frameexample = loveframes.Create("button")
frameexample:SetText("Frame")
frameexample.OnClick = function(object1, x, y)
local frame1 = loveframes.Create("frame")
frame1:SetName("Frame")
frame1:Center()
local text1 = loveframes.Create("text", frame1)
text1:SetText("This is an example frame.")
text1.Update = function(object2, dt)
object2:Center()
end
end
exampleslist:AddItem(frameexample)
------------------------------------
-- image example
------------------------------------
local imageexample = loveframes.Create("button")
imageexample:SetText("Image")
imageexample.OnClick = function(object1, x, y)
local frame1 = loveframes.Create("frame")
frame1:SetName("Image")
frame1:SetSize(138, 163)
frame1:Center()
local image1 = loveframes.Create("image", frame1)
image1:SetImage("resources/images/carlsagan.png")
image1:SetPos(5, 30)
end
exampleslist:AddItem(imageexample)
------------------------------------
-- list example
------------------------------------
local listexample = loveframes.Create("button")
listexample:SetText("List")
listexample.OnClick = function(object1, x, y)
local frame1 = loveframes.Create("frame")
frame1:SetName("List")
frame1:SetSize(500, 455)
frame1:Center()
local list1 = loveframes.Create("list", frame1)
list1:SetPos(5, 30)
list1:SetSize(490, 300)
local panel1 = loveframes.Create("panel", frame1)
panel1:SetPos(5, 335)
panel1:SetSize(490, 115)
local slider1 = loveframes.Create("slider", panel1)
slider1:SetPos(5, 5)
slider1:SetWidth(480)
slider1:SetMinMax(0, 100)
slider1:SetText("Padding")
slider1:SetDecimals(0)
slider1.OnValueChanged = function(object2, value)
list1:SetPadding(value)
end
local slider2 = loveframes.Create("slider", panel1)
slider2:SetPos(5, 45)
slider2:SetWidth(480)
slider2:SetMinMax(0, 100)
slider2:SetText("Spacing")
slider2:SetDecimals(0)
slider2.OnValueChanged = function(object2, value)
list1:SetSpacing(value)
end
local button1 = loveframes.Create("button", panel1)
button1:SetPos(5, 85)
button1:SetSize(480, 25)
button1:SetText("Change List Type")
button1.OnClick = function(object2, x, y)
if list1:GetDisplayType() == "vertical" then
list1:SetDisplayType("horizontal")
else
list1:SetDisplayType("vertical")
end
end
for i=1, 50 do
local button2 = loveframes.Create("button")
button2:SetText(i)
list1:AddItem(button2)
end
end
exampleslist:AddItem(listexample)
------------------------------------
-- multichoice example
------------------------------------
local multichoiceexample = loveframes.Create("button")
multichoiceexample:SetText("Multichoice")
multichoiceexample.OnClick = function(object1, x, y)
local frame1 = loveframes.Create("frame")
frame1:SetName("Multichoice")
frame1:SetSize(210, 60)
frame1:Center()
local multichoice1 = loveframes.Create("multichoice", frame1)
multichoice1:SetPos(5, 30)
for i=1, 20 do
multichoice1:AddChoice(i)
end
end
exampleslist:AddItem(multichoiceexample)
------------------------------------
-- panel example
------------------------------------
local panelexample = loveframes.Create("button")
panelexample:SetText("Panel")
panelexample.OnClick = function(object1, x, y)
local frame1 = loveframes.Create("frame")
frame1:SetName("Panel")
frame1:SetSize(210, 85)
frame1:Center()
local panel1 = loveframes.Create("panel", frame1)
panel1:SetPos(5, 30)
end
exampleslist:AddItem(panelexample)
------------------------------------
-- progressbar example
------------------------------------
local progressbarexample = loveframes.Create("button")
progressbarexample:SetText("Progress Bar")
progressbarexample.OnClick = function(object1, x, y)
local frame1 = loveframes.Create("frame")
frame1:SetName("Progress Bar")
frame1:SetSize(500, 160)
frame1:Center()
local progressbar1 = loveframes.Create("progressbar", frame1)
progressbar1:SetPos(5, 30)
progressbar1:SetWidth(490)
progressbar1:SetLerpRate(1)
local button1 = loveframes.Create("button", frame1)
button1:SetPos(5, 60)
button1:SetWidth(490)
button1:SetText("Change bar value")
button1.OnClick = function(object2, x, y)
progressbar1:SetValue(math.random(progressbar1:GetMin(), progressbar1:GetMax()))
end
local button2 = loveframes.Create("button", frame1)
button2:SetPos(5, 90)
button2:SetWidth(490)
button2:SetText("Toggle bar lerp")
button2.OnClick = function(object2, x, y)
if progressbar1:GetLerp() == true then
progressbar1:SetLerp(false)
else
progressbar1:SetLerp(true)
end
end
local slider1 = loveframes.Create("slider", frame1)
slider1:SetPos(5, 120)
slider1:SetWidth(490)
slider1:SetText("Progressbar lerp rate")
slider1:SetMinMax(1, 50)
slider1.OnValueChanged = function(object2, value)
progressbar1:SetLerpRate(value)
end
end
exampleslist:AddItem(progressbarexample)
------------------------------------
-- slider example
------------------------------------
local sliderexample = loveframes.Create("button")
sliderexample:SetText("Slider")
sliderexample.OnClick = function(object1, x, y)
local frame1 = loveframes.Create("frame")
frame1:SetName("Slider")
frame1:SetSize(300, 100)
frame1:Center()
local slider1 = loveframes.Create("slider", frame1)
slider1:SetPos(5, 30)
slider1:SetSize(290, 500)
slider1:SetMinMax(0, 100)
end
exampleslist:AddItem(sliderexample)
------------------------------------
-- tabs example
------------------------------------
local tabsexample = loveframes.Create("button")
tabsexample:SetText("Tabs")
tabsexample.OnClick = function(object1, x, y)
local frame1 = loveframes.Create("frame")
frame1:SetName("Tabs")
frame1:SetSize(500, 300)
frame1:Center()
local tabs1 = loveframes.Create("tabs", frame1)
tabs1:SetPos(5, 30)
tabs1:SetSize(490, 265)
for i=1, 20 do
local text1 = loveframes.Create("text")
text1:SetText("Tab " ..i)
tabs1:AddTab("Tab " ..i, text1, "Tab " ..i)
end
end
exampleslist:AddItem(tabsexample)
------------------------------------
-- text example
------------------------------------
local textexample = loveframes.Create("button")
textexample:SetText("Text")
textexample.OnClick = function(object1, x, y)
local frame1 = loveframes.Create("frame")
frame1:SetName("Text")
frame1:SetSize(500, 300)
frame1:Center()
local list1 = loveframes.Create("list", frame1)
list1:SetPos(5, 30)
list1:SetSize(490, 265)
list1:SetPadding(5)
list1:SetSpacing(5)
for i=1, 20 do
local text1 = loveframes.Create("text")
text1:SetText(loremipsum)
--text1:SetColor({math.random(1, 255), math.random(1, 255), math.random(1, 255), 255})
list1:AddItem(text1)
end
end
exampleslist:AddItem(textexample)
------------------------------------
-- text input example
------------------------------------
local textinputexample = loveframes.Create("button")
textinputexample:SetText("Text Input")
textinputexample.OnClick = function(object1, x, y)
local frame1 = loveframes.Create("frame")
frame1:SetName("Text Input")
frame1:SetSize(500, 60)
frame1:Center()
local textinput1 = loveframes.Create("textinput", frame1)
textinput1:SetPos(5, 30)
textinput1:SetWidth(490)
end
exampleslist:AddItem(textinputexample)
end

6
graphics.lua Normal file
View File

@ -0,0 +1,6 @@
--[[------------------------------------------------
-- LÖVE Frames --
-- By Nikolai Resokav --
--]]------------------------------------------------
loveframes.graphics = {}

244
init.lua Normal file
View File

@ -0,0 +1,244 @@
--[[------------------------------------------------
-- LÖVE Frames --
-- By Nikolai Resokav --
--]]------------------------------------------------
-- central library table
loveframes = {}
-- library info
loveframes.info = {}
loveframes.info.author = "Nikolai Resokav"
loveframes.info.version = "0.9"
loveframes.info.stage = "Alpha"
-- library configurations
loveframes.config = {}
loveframes.config["DIRECTORY"] = "libraries/loveframes"
loveframes.config["DEFAULTSKIN"] = "Default"
loveframes.config["ACTIVESKIN"] = "Default"
loveframes.config["INDEXSKINIMAGES"] = true
loveframes.config["DEBUG"] = false
-- drawcount
loveframes.drawcount = 0
--[[---------------------------------------------------------
- func: load()
- desc: loads the library
--]]---------------------------------------------------------
function loveframes.load()
-- install directory of the library
local dir = loveframes.config["DIRECTORY"]
-- require the internal base libraries
require(dir .. "/third-party/middleclass/middleclass")
require(dir .. "/util")
require(dir .. "/skins")
require(dir .. "/templates")
require(dir .. "/debug")
-- create a list of gui objects and skins
local objects = loveframes.util.GetDirContents(dir .. "/objects")
local skins = loveframes.util.GetDirContents(dir .. "/skins")
-- loop through a list of all gui objects and require them
for k, v in ipairs(objects) do
if v.extension == "lua" then
require(v.path .. "/" ..v.name)
end
end
-- loop through a list of all gui skins and require them
for k, v in ipairs(skins) do
if v.extension == "lua" then
require(v.path .. "/" ..v.name)
end
end
-- create the base gui object
loveframes.base = base:new()
end
--[[---------------------------------------------------------
- func: update(deltatime)
- desc: updates all library objects
--]]---------------------------------------------------------
function loveframes.update(dt)
local object = loveframes.base
object:update(dt)
end
--[[---------------------------------------------------------
- func: draw()
- desc: draws all library objects
--]]---------------------------------------------------------
function loveframes.draw()
local object = loveframes.base
-- set the drawcount to zero
loveframes.drawcount = 0
-- draw the base object
object:draw()
-- draw the debug library
loveframes.debug.draw()
end
--[[---------------------------------------------------------
- func: mousepressed(x, y, button)
- desc: called when the player presses a mouse button
--]]---------------------------------------------------------
function loveframes.mousepressed(x, y, button)
local object = loveframes.base
object:mousepressed(x, y, button)
end
--[[---------------------------------------------------------
- func: mousereleased(x, y, button)
- desc: called when the player releases a mouse button
--]]---------------------------------------------------------
function loveframes.mousereleased(x, y, button)
local object = loveframes.base
object:mousereleased(x, y, button)
end
--[[---------------------------------------------------------
- func: keypressed(key)
- desc: called when the player presses a key
--]]---------------------------------------------------------
function loveframes.keypressed(key, unicode)
local object = loveframes.base
object:keypressed(key, unicode)
end
--[[---------------------------------------------------------
- func: keyreleased(key)
- desc: called when the player releases a key
--]]---------------------------------------------------------
function loveframes.keyreleased(key)
local object = loveframes.base
object:keyreleased(key)
end
--[[---------------------------------------------------------
- func: New(type, parent)
- desc: creates a new object or multiple new objects
(based on the method used) and returns said
object or objects for further manipulation
--]]---------------------------------------------------------
function loveframes.Create(data, parent)
if type(data) == "string" then
-- create the new object
local object = _G[data]:new()
if object.internal == true then
if object.type == "tooltip" then
object = tooltip:new()
else
return
end
end
-- parent the new object by default to the base gui object
object.parent = loveframes.base
table.insert(loveframes.base.children, object)
-- if the parent argument is not nil, make that argument the object's new parent
if parent ~= nil then
object:SetParent(parent)
end
-- return the object for further manipulation
return object
elseif type(data) == "table" then
-- table for creation of multiple objects
local objects = {}
-- this function reads a table that contains a layout of object properties and then
-- creates objects based on those properties
local function CreateObjects(t, o, c)
local child = c or false
for k, v in pairs(t) do
-- current default object
local object = _G[v.type]:new()
-- indert the object into the table of objects being created
table.insert(objects, object)
-- parent the new object by default to the base gui object
object.parent = loveframes.base
table.insert(loveframes.base.children, object)
if o then
object:SetParent(o)
end
-- loop through the current layout table and assign the properties found
-- to the current object
for i, j in pairs(v) do
if i ~= "children" and i ~= "func" then
if child == true then
if i == "x" then
object["staticx"] = j
elseif i == "y" then
object["staticy"] = j
else
object[i] = j
end
else
object[i] = j
end
elseif i == "children" then
CreateObjects(j, object, true)
end
end
if v.func then
v.func(object)
end
end
end
-- create the objects
CreateObjects(data)
return objects
end
end
-- load the library
loveframes.load()

470
license.html Normal file
View File

@ -0,0 +1,470 @@
<html>
<body>
<div style="width: 800px; padding: 0px; margin: auto; font-family: Arial; border: 1px solid #000000;">
<div style="padding: 5px; border-bottom: 1px solid #000000; text-align: center; background-color: #C80000; color: #FFFFFF;">
<h3>License for Löve Frames By Nikolai Resokav</h3>
</div>
<div style="padding: 10px; border-bottom: 1px solid #000000;">
Löve Frames is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) license.
Below is the entire legal code for the license. For more information on this license, please visit this web page:
<a href="http://creativecommons.org/licenses/by-sa/3.0/" style="text-decoration: none;">Licence URL</a>
</div>
<div style="padding: 10px;">
<h3><em>License</em></h3>
<p>THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS
OF THIS CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR
"LICENSE"). THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER
APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS
AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS
PROHIBITED.</p>
<p>BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU
ACCEPT AND AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE.
TO THE EXTENT THIS LICENSE MAY BE CONSIDERED TO BE A
CONTRACT, THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED HERE
IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND
CONDITIONS.</p>
<p><strong>1. Definitions</strong></p>
<ol type="a">
<li><strong>"Adaptation"</strong> means a work based upon
the Work, or upon the Work and other pre-existing works,
such as a translation, adaptation, derivative work,
arrangement of music or other alterations of a literary
or artistic work, or phonogram or performance and
includes cinematographic adaptations or any other form in
which the Work may be recast, transformed, or adapted
including in any form recognizably derived from the
original, except that a work that constitutes a
Collection will not be considered an Adaptation for the
purpose of this License. For the avoidance of doubt,
where the Work is a musical work, performance or
phonogram, the synchronization of the Work in
timed-relation with a moving image ("synching") will be
considered an Adaptation for the purpose of this
License.</li>
<li><strong>"Collection"</strong> means a collection of
literary or artistic works, such as encyclopedias and
anthologies, or performances, phonograms or broadcasts,
or other works or subject matter other than works listed
in Section 1(f) below, which, by reason of the selection
and arrangement of their contents, constitute
intellectual creations, in which the Work is included in
its entirety in unmodified form along with one or more
other contributions, each constituting separate and
independent works in themselves, which together are
assembled into a collective whole. A work that
constitutes a Collection will not be considered an
Adaptation (as defined below) for the purposes of this
License.</li>
<li><strong>"Creative Commons Compatible
License"</strong> means a license that is listed at
http://creativecommons.org/compatiblelicenses that has
been approved by Creative Commons as being essentially
equivalent to this License, including, at a minimum,
because that license: (i) contains terms that have the
same purpose, meaning and effect as the License Elements
of this License; and, (ii) explicitly permits the
relicensing of adaptations of works made available under
that license under this License or a Creative Commons
jurisdiction license with the same License Elements as
this License.</li>
<li><strong>"Distribute"</strong> means to make available
to the public the original and copies of the Work or
Adaptation, as appropriate, through sale or other
transfer of ownership.</li>
<li><strong>"License Elements"</strong> means the
following high-level license attributes as selected by
Licensor and indicated in the title of this License:
Attribution, ShareAlike.</li>
<li><strong>"Licensor"</strong> means the individual,
individuals, entity or entities that offer(s) the Work
under the terms of this License.</li>
<li><strong>"Original Author"</strong> means, in the case
of a literary or artistic work, the individual,
individuals, entity or entities who created the Work or
if no individual or entity can be identified, the
publisher; and in addition (i) in the case of a
performance the actors, singers, musicians, dancers, and
other persons who act, sing, deliver, declaim, play in,
interpret or otherwise perform literary or artistic works
or expressions of folklore; (ii) in the case of a
phonogram the producer being the person or legal entity
who first fixes the sounds of a performance or other
sounds; and, (iii) in the case of broadcasts, the
organization that transmits the broadcast.</li>
<li><strong>"Work"</strong> means the literary and/or
artistic work offered under the terms of this License
including without limitation any production in the
literary, scientific and artistic domain, whatever may be
the mode or form of its expression including digital
form, such as a book, pamphlet and other writing; a
lecture, address, sermon or other work of the same
nature; a dramatic or dramatico-musical work; a
choreographic work or entertainment in dumb show; a
musical composition with or without words; a
cinematographic work to which are assimilated works
expressed by a process analogous to cinematography; a
work of drawing, painting, architecture, sculpture,
engraving or lithography; a photographic work to which
are assimilated works expressed by a process analogous to
photography; a work of applied art; an illustration, map,
plan, sketch or three-dimensional work relative to
geography, topography, architecture or science; a
performance; a broadcast; a phonogram; a compilation of
data to the extent it is protected as a copyrightable
work; or a work performed by a variety or circus
performer to the extent it is not otherwise considered a
literary or artistic work.</li>
<li><strong>"You"</strong> means an individual or entity
exercising rights under this License who has not
previously violated the terms of this License with
respect to the Work, or who has received express
permission from the Licensor to exercise rights under
this License despite a previous violation.</li>
<li><strong>"Publicly Perform"</strong> means to perform
public recitations of the Work and to communicate to the
public those public recitations, by any means or process,
including by wire or wireless means or public digital
performances; to make available to the public Works in
such a way that members of the public may access these
Works from a place and at a place individually chosen by
them; to perform the Work to the public by any means or
process and the communication to the public of the
performances of the Work, including by public digital
performance; to broadcast and rebroadcast the Work by any
means including signs, sounds or images.</li>
<li><strong>"Reproduce"</strong> means to make copies of
the Work by any means including without limitation by
sound or visual recordings and the right of fixation and
reproducing fixations of the Work, including storage of a
protected performance or phonogram in digital form or
other electronic medium.</li>
</ol>
<p><strong>2. Fair Dealing Rights.</strong> Nothing in this
License is intended to reduce, limit, or restrict any uses
free from copyright or rights arising from limitations or
exceptions that are provided for in connection with the
copyright protection under copyright law or other
applicable laws.</p>
<p><strong>3. License Grant.</strong> Subject to the terms
and conditions of this License, Licensor hereby grants You
a worldwide, royalty-free, non-exclusive, perpetual (for
the duration of the applicable copyright) license to
exercise the rights in the Work as stated below:</p>
<ol type="a">
<li>to Reproduce the Work, to incorporate the Work into
one or more Collections, and to Reproduce the Work as
incorporated in the Collections;</li>
<li>to create and Reproduce Adaptations provided that any
such Adaptation, including any translation in any medium,
takes reasonable steps to clearly label, demarcate or
otherwise identify that changes were made to the original
Work. For example, a translation could be marked "The
original work was translated from English to Spanish," or
a modification could indicate "The original work has been
modified.";</li>
<li>to Distribute and Publicly Perform the Work including
as incorporated in Collections; and,</li>
<li>to Distribute and Publicly Perform Adaptations.</li>
<li>
<p>For the avoidance of doubt:</p>
<ol type="i">
<li><strong>Non-waivable Compulsory License
Schemes</strong>. In those jurisdictions in which the
right to collect royalties through any statutory or
compulsory licensing scheme cannot be waived, the
Licensor reserves the exclusive right to collect such
royalties for any exercise by You of the rights
granted under this License;</li>
<li><strong>Waivable Compulsory License
Schemes</strong>. In those jurisdictions in which the
right to collect royalties through any statutory or
compulsory licensing scheme can be waived, the
Licensor waives the exclusive right to collect such
royalties for any exercise by You of the rights
granted under this License; and,</li>
<li><strong>Voluntary License Schemes</strong>. The
Licensor waives the right to collect royalties,
whether individually or, in the event that the
Licensor is a member of a collecting society that
administers voluntary licensing schemes, via that
society, from any exercise by You of the rights
granted under this License.</li>
</ol>
</li>
</ol>
<p>The above rights may be exercised in all media and
formats whether now known or hereafter devised. The above
rights include the right to make such modifications as are
technically necessary to exercise the rights in other media
and formats. Subject to Section 8(f), all rights not
expressly granted by Licensor are hereby reserved.</p>
<p><strong>4. Restrictions.</strong> The license granted in
Section 3 above is expressly made subject to and limited by
the following restrictions:</p>
<ol type="a">
<li>You may Distribute or Publicly Perform the Work only
under the terms of this License. You must include a copy
of, or the Uniform Resource Identifier (URI) for, this
License with every copy of the Work You Distribute or
Publicly Perform. You may not offer or impose any terms
on the Work that restrict the terms of this License or
the ability of the recipient of the Work to exercise the
rights granted to that recipient under the terms of the
License. You may not sublicense the Work. You must keep
intact all notices that refer to this License and to the
disclaimer of warranties with every copy of the Work You
Distribute or Publicly Perform. When You Distribute or
Publicly Perform the Work, You may not impose any
effective technological measures on the Work that
restrict the ability of a recipient of the Work from You
to exercise the rights granted to that recipient under
the terms of the License. This Section 4(a) applies to
the Work as incorporated in a Collection, but this does
not require the Collection apart from the Work itself to
be made subject to the terms of this License. If You
create a Collection, upon notice from any Licensor You
must, to the extent practicable, remove from the
Collection any credit as required by Section 4(c), as
requested. If You create an Adaptation, upon notice from
any Licensor You must, to the extent practicable, remove
from the Adaptation any credit as required by Section
4(c), as requested.</li>
<li>You may Distribute or Publicly Perform an Adaptation
only under the terms of: (i) this License; (ii) a later
version of this License with the same License Elements as
this License; (iii) a Creative Commons jurisdiction
license (either this or a later license version) that
contains the same License Elements as this License (e.g.,
Attribution-ShareAlike 3.0 US)); (iv) a Creative Commons
Compatible License. If you license the Adaptation under
one of the licenses mentioned in (iv), you must comply
with the terms of that license. If you license the
Adaptation under the terms of any of the licenses
mentioned in (i), (ii) or (iii) (the "Applicable
License"), you must comply with the terms of the
Applicable License generally and the following
provisions: (I) You must include a copy of, or the URI
for, the Applicable License with every copy of each
Adaptation You Distribute or Publicly Perform; (II) You
may not offer or impose any terms on the Adaptation that
restrict the terms of the Applicable License or the
ability of the recipient of the Adaptation to exercise
the rights granted to that recipient under the terms of
the Applicable License; (III) You must keep intact all
notices that refer to the Applicable License and to the
disclaimer of warranties with every copy of the Work as
included in the Adaptation You Distribute or Publicly
Perform; (IV) when You Distribute or Publicly Perform the
Adaptation, You may not impose any effective
technological measures on the Adaptation that restrict
the ability of a recipient of the Adaptation from You to
exercise the rights granted to that recipient under the
terms of the Applicable License. This Section 4(b)
applies to the Adaptation as incorporated in a
Collection, but this does not require the Collection
apart from the Adaptation itself to be made subject to
the terms of the Applicable License.</li>
<li>If You Distribute, or Publicly Perform the Work or
any Adaptations or Collections, You must, unless a
request has been made pursuant to Section 4(a), keep
intact all copyright notices for the Work and provide,
reasonable to the medium or means You are utilizing: (i)
the name of the Original Author (or pseudonym, if
applicable) if supplied, and/or if the Original Author
and/or Licensor designate another party or parties (e.g.,
a sponsor institute, publishing entity, journal) for
attribution ("Attribution Parties") in Licensor's
copyright notice, terms of service or by other reasonable
means, the name of such party or parties; (ii) the title
of the Work if supplied; (iii) to the extent reasonably
practicable, the URI, if any, that Licensor specifies to
be associated with the Work, unless such URI does not
refer to the copyright notice or licensing information
for the Work; and (iv) , consistent with Ssection 3(b),
in the case of an Adaptation, a credit identifying the
use of the Work in the Adaptation (e.g., "French
translation of the Work by Original Author," or
"Screenplay based on original Work by Original Author").
The credit required by this Section 4(c) may be
implemented in any reasonable manner; provided, however,
that in the case of a Adaptation or Collection, at a
minimum such credit will appear, if a credit for all
contributing authors of the Adaptation or Collection
appears, then as part of these credits and in a manner at
least as prominent as the credits for the other
contributing authors. For the avoidance of doubt, You may
only use the credit required by this Section for the
purpose of attribution in the manner set out above and,
by exercising Your rights under this License, You may not
implicitly or explicitly assert or imply any connection
with, sponsorship or endorsement by the Original Author,
Licensor and/or Attribution Parties, as appropriate, of
You or Your use of the Work, without the separate,
express prior written permission of the Original Author,
Licensor and/or Attribution Parties.</li>
<li>Except as otherwise agreed in writing by the Licensor
or as may be otherwise permitted by applicable law, if
You Reproduce, Distribute or Publicly Perform the Work
either by itself or as part of any Adaptations or
Collections, You must not distort, mutilate, modify or
take other derogatory action in relation to the Work
which would be prejudicial to the Original Author's honor
or reputation. Licensor agrees that in those
jurisdictions (e.g. Japan), in which any exercise of the
right granted in Section 3(b) of this License (the right
to make Adaptations) would be deemed to be a distortion,
mutilation, modification or other derogatory action
prejudicial to the Original Author's honor and
reputation, the Licensor will waive or not assert, as
appropriate, this Section, to the fullest extent
permitted by the applicable national law, to enable You
to reasonably exercise Your right under Section 3(b) of
this License (right to make Adaptations) but not
otherwise.</li>
</ol>
<p><strong>5. Representations, Warranties and
Disclaimer</strong></p>
<p>UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN
WRITING, LICENSOR OFFERS THE WORK AS-IS AND MAKES NO
REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE
WORK, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, INCLUDING,
WITHOUT LIMITATION, WARRANTIES OF TITLE, MERCHANTIBILITY,
FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE
ABSENCE OF LATENT OR OTHER DEFECTS, ACCURACY, OR THE
PRESENCE OF ABSENCE OF ERRORS, WHETHER OR NOT DISCOVERABLE.
SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED
WARRANTIES, SO SUCH EXCLUSION MAY NOT APPLY TO YOU.</p>
<p><strong>6. Limitation on Liability.</strong> EXCEPT TO
THE EXTENT REQUIRED BY APPLICABLE LAW, IN NO EVENT WILL
LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY
SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY
DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK,
EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.</p>
<p><strong>7. Termination</strong></p>
<ol type="a">
<li>This License and the rights granted hereunder will
terminate automatically upon any breach by You of the
terms of this License. Individuals or entities who have
received Adaptations or Collections from You under this
License, however, will not have their licenses terminated
provided such individuals or entities remain in full
compliance with those licenses. Sections 1, 2, 5, 6, 7,
and 8 will survive any termination of this License.</li>
<li>Subject to the above terms and conditions, the
license granted here is perpetual (for the duration of
the applicable copyright in the Work). Notwithstanding
the above, Licensor reserves the right to release the
Work under different license terms or to stop
distributing the Work at any time; provided, however that
any such election will not serve to withdraw this License
(or any other license that has been, or is required to
be, granted under the terms of this License), and this
License will continue in full force and effect unless
terminated as stated above.</li>
</ol>
<p><strong>8. Miscellaneous</strong></p>
<ol type="a">
<li>Each time You Distribute or Publicly Perform the Work
or a Collection, the Licensor offers to the recipient a
license to the Work on the same terms and conditions as
the license granted to You under this License.</li>
<li>Each time You Distribute or Publicly Perform an
Adaptation, Licensor offers to the recipient a license to
the original Work on the same terms and conditions as the
license granted to You under this License.</li>
<li>If any provision of this License is invalid or
unenforceable under applicable law, it shall not affect
the validity or enforceability of the remainder of the
terms of this License, and without further action by the
parties to this agreement, such provision shall be
reformed to the minimum extent necessary to make such
provision valid and enforceable.</li>
<li>No term or provision of this License shall be deemed
waived and no breach consented to unless such waiver or
consent shall be in writing and signed by the party to be
charged with such waiver or consent.</li>
<li>This License constitutes the entire agreement between
the parties with respect to the Work licensed here. There
are no understandings, agreements or representations with
respect to the Work not specified here. Licensor shall
not be bound by any additional provisions that may appear
in any communication from You. This License may not be
modified without the mutual written agreement of the
Licensor and You.</li>
<li>The rights granted under, and the subject matter
referenced, in this License were drafted utilizing the
terminology of the Berne Convention for the Protection of
Literary and Artistic Works (as amended on September 28,
1979), the Rome Convention of 1961, the WIPO Copyright
Treaty of 1996, the WIPO Performances and Phonograms
Treaty of 1996 and the Universal Copyright Convention (as
revised on July 24, 1971). These rights and subject
matter take effect in the relevant jurisdiction in which
the License terms are sought to be enforced according to
the corresponding provisions of the implementation of
those treaty provisions in the applicable national law.
If the standard suite of rights granted under applicable
copyright law includes additional rights not granted
under this License, such additional rights are deemed to
be included in the License; this License is not intended
to restrict the license of any rights under applicable
law.</li>
</ol>
</div>
</div>
</body>
<html>

768
objects/base.lua Normal file
View File

@ -0,0 +1,768 @@
--[[------------------------------------------------
-- LÖVE Frames --
-- By Nikolai Resokav --
--]]------------------------------------------------
-- base object
base = class("base")
base:include(loveframes.templates.default)
--[[---------------------------------------------------------
- func: initialize()
- desc: intializes the element
--]]---------------------------------------------------------
function base:initialize()
-- width and height of the window
local w, h = love.graphics.getWidth(), love.graphics.getHeight()
self.type = "base"
self.width = w
self.height = h
self.internal = true
self.children = {}
end
--[[---------------------------------------------------------
- func: update(deltatime)
- desc: updates the object
--]]---------------------------------------------------------
function base:update(dt)
for k, v in ipairs(self.children) do
v:update(dt)
end
end
--[[---------------------------------------------------------
- func: draw()
- desc: draws the object
--]]---------------------------------------------------------
function base:draw()
loveframes.drawcount = loveframes.drawcount + 1
self.draworder = loveframes.drawcount
for k, v in ipairs(self.children) do
v:draw()
end
end
--[[---------------------------------------------------------
- func: mousepressed(x, y, button)
- desc: called when the player presses a mouse button
--]]---------------------------------------------------------
function base:mousepressed(x, y, button)
if self.children then
for k, v in ipairs(self.children) do
v:mousepressed(x, y, button)
end
end
end
--[[---------------------------------------------------------
- func: mousereleased(x, y, button)
- desc: called when the player releases a mouse button
--]]---------------------------------------------------------
function base:mousereleased(x, y, button)
if self.children then
for k, v in ipairs(self.children) do
v:mousereleased(x, y, button)
end
end
end
--[[---------------------------------------------------------
- func: keypressed(key)
- desc: called when the player presses a key
--]]---------------------------------------------------------
function base:keypressed(key, unicode)
if self.children then
for k, v in ipairs(self.children) do
v:keypressed(key, unicode)
end
end
end
--[[---------------------------------------------------------
- func: keyreleased(key)
- desc: called when the player releases a key
--]]---------------------------------------------------------
function base:keyreleased(key)
if self.children then
for k, v in ipairs(self.children) do
v:keyreleased(key)
end
end
end
--[[---------------------------------------------------------
- func: SetPos(x, y)
- desc: sets the object's position
--]]---------------------------------------------------------
function base:SetPos(x, y)
local parent = self.parent
if parent == loveframes.base then
self.x = x
self.y = y
else
self.staticx = x
self.staticy = y
end
end
--[[---------------------------------------------------------
- func: SetX(x)
- desc: sets the object's x position
--]]---------------------------------------------------------
function base:SetX(x)
local parent = self.parent
if parent == loveframes.base then
self.x = x
else
self.staticx = x
end
end
--[[---------------------------------------------------------
- func: SetY(y)
- desc: sets the object's y position
--]]---------------------------------------------------------
function base:SetY(y)
local parent = self.parent
if parent == loveframes.base then
self.y = y
else
self.staticy = y
end
end
--[[---------------------------------------------------------
- func: GetPos()
- desc: gets the object's position
--]]---------------------------------------------------------
function base:GetPos()
return self.x, self.y
end
--[[---------------------------------------------------------
- func: GetX()
- desc: gets the object's x position
--]]---------------------------------------------------------
function base:GetX()
return self.x
end
--[[---------------------------------------------------------
- func: GetY()
- desc: gets the object's y position
--]]---------------------------------------------------------
function base:GetY()
return self.y
end
--[[---------------------------------------------------------
- func: GetStaticPos()
- desc: gets the object's static position
--]]---------------------------------------------------------
function base:GetStaticPos()
return self.staticx, self.staticy
end
--[[---------------------------------------------------------
- func: GetStaticX()
- desc: gets the object's static x position
--]]---------------------------------------------------------
function base:GetStaticX()
return self.staticx
end
--[[---------------------------------------------------------
- func: GetStaticY()
- desc: gets the object's static y position
--]]---------------------------------------------------------
function base:GetStaticY()
return self.staticy
end
--[[---------------------------------------------------------
- func: Center()
- desc: centers the object in the game window or in
it's parent if it has one
--]]---------------------------------------------------------
function base:Center()
local parent = self.parent
if parent == loveframes.base then
local width = love.graphics.getWidth()
local height = love.graphics.getHeight()
self.x = width/2 - self.width/2
self.y = height/2 - self.height/2
else
local width = parent.width
local height = parent.height
self.staticx = width/2 - self.width/2
self.staticy = height/2 - self.height/2
end
end
--[[---------------------------------------------------------
- func: SetSize(width, height)
- desc: sets the object's size
--]]---------------------------------------------------------
function base:SetSize(width, height)
self.width = width
self.height = height
end
--[[---------------------------------------------------------
- func: SetWidth(width)
- desc: sets the object's width
--]]---------------------------------------------------------
function base:SetWidth(width)
self.width = width
end
--[[---------------------------------------------------------
- func: SetHeight(height)
- desc: sets the object's height
--]]---------------------------------------------------------
function base:SetHeight(height)
self.height = height
end
--[[---------------------------------------------------------
- func: GetSize()
- desc: gets the object's size
--]]---------------------------------------------------------
function base:GetSize()
return self.width, self.height
end
--[[---------------------------------------------------------
- func: GetWidth()
- desc: gets the object's width
--]]---------------------------------------------------------
function base:GetWidth()
return self.width
end
--[[---------------------------------------------------------
- func: GetHeight()
- desc: gets the object's height
--]]---------------------------------------------------------
function base:GetHeight()
return self.height
end
--[[---------------------------------------------------------
- func: SetVisible(bool)
- desc: sets the object's visibility
--]]---------------------------------------------------------
function base:SetVisible(bool)
local children = self.children
local internals = self.internals
self.visible = bool
if children then
for k, v in ipairs(children) do
v:SetVisible(bool)
end
end
if internals then
for k, v in ipairs(internals) do
v:SetVisible(bool)
end
end
end
--[[---------------------------------------------------------
- func: GetVisible()
- desc: gets the object's visibility
--]]---------------------------------------------------------
function base:GetVisible()
return self.visible
end
--[[---------------------------------------------------------
- func: SetParent(parent)
- desc: sets the object's parent
--]]---------------------------------------------------------
function base:SetParent(parent)
local tparent = parent
local cparent = self.parent
local ptype = tparent.type
local stype = self.type
if ptype ~= "frame" and ptype ~= "panel" and ptype ~= "list" then
return
end
if stype == "frame" then
return
end
self:Remove()
self.parent = tparent
table.insert(tparent.children, self)
end
--[[---------------------------------------------------------
- func: GetParent()
- desc: gets the object's parent
--]]---------------------------------------------------------
function base:GetParent()
local parent = self.parent
return parent
end
--[[---------------------------------------------------------
- func: Remove()
- desc: removes the object
--]]---------------------------------------------------------
function base:Remove()
if self.parent.internals then
for k, v in ipairs(self.parent.internals) do
if v == self then
table.remove(self.parent.internals, k)
end
end
end
for k, v in ipairs(self.parent.children) do
if v == self then
table.remove(self.parent.children, k)
end
end
end
--[[---------------------------------------------------------
- func: SetClickBounds(x, y, width, height)
- desc: sets a boundary box for the object's collision
detection
--]]---------------------------------------------------------
function base:SetClickBounds(x, y, width, height)
self.clickbounds = {x = x, y = y, width = width, height = height}
if self.internals then
for k, v in ipairs(self.internals) do
v:SetClickBounds(x, y, width, height)
end
end
if self.children then
for k, v in ipairs(self.children) do
v:SetClickBounds(x, y, width, height)
end
end
end
--[[---------------------------------------------------------
- func: GetClickBounds()
- desc: gets the boundary box for the object's collision
detection
--]]---------------------------------------------------------
function base:GetClickBounds()
return self.clickbounds
end
--[[---------------------------------------------------------
- func: RemoveClickBounds()
- desc: removes the collision detection boundary for the
object
--]]---------------------------------------------------------
function base:RemoveClickBounds()
self.clickbounds = nil
if self.internals then
for k, v in ipairs(self.internals) do
v:RemoveClickBounds()
end
end
if self.children then
for k, v in ipairs(self.children) do
v:RemoveClickBounds()
end
end
end
--[[---------------------------------------------------------
- func: InClickBounds()
- desc: checks if the mouse is inside the object's
collision detection boundaries
--]]---------------------------------------------------------
function base:InClickBounds()
local x, y = love.mouse.getPosition()
local bounds = self.clickbounds
if bounds then
local col = loveframes.util.BoundingBox(x, bounds.x, y, bounds.y, 1, bounds.width, 1, bounds.height)
return col
else
return false
end
end
--[[---------------------------------------------------------
- func: IsTopCollision()
- desc: checks if the object the top most object in a
collision table
--]]---------------------------------------------------------
function base:IsTopCollision()
local cols = loveframes.util.GetCollisions()
local draworder = self.draworder
local top = true
-- loop through the object's parent's children
for k, v in ipairs(cols) do
if v.draworder > draworder then
top = false
end
end
return top
end
--[[---------------------------------------------------------
- func: GetBaseParent(object, t)
- desc: finds the object's base parent
--]]---------------------------------------------------------
function base:GetBaseParent(t)
local t = t or {}
local parent
if self.parent ~= loveframes.base then
table.insert(t, self.parent)
self.parent:GetBaseParent(t)
end
return t[#t]
end
--[[---------------------------------------------------------
- func: CheckHover()
- desc: checks to see if the object should be in a
hover state
--]]---------------------------------------------------------
function base:CheckHover()
local x, y = love.mouse.getPosition()
local selfcol = loveframes.util.BoundingBox(x, self.x, y, self.y, 1, self.width, 1, self.height)
-- is the mouse inside the object?
if selfcol == true then
local top = self:IsTopCollision()
if top == true then
self.hover = true
else
self.hover = false
end
if self.clickbounds then
if self:InClickBounds() == false then
self.hover = false
end
end
else
self.hover = false
end
-- this chunk of code handles mouse enter and exit
if self.hover == true then
if self.calledmousefunc == false then
if self.OnMouseEnter ~= nil then
self.OnMouseEnter(self)
self.calledmousefunc = true
else
self.calledmousefunc = true
end
end
else
if self.calledmousefunc == true then
if self.OnMouseExit ~= nil then
self.OnMouseExit(self)
self.calledmousefunc = false
else
self.calledmousefunc = false
end
end
end
end
--[[---------------------------------------------------------
- func: GetHover()
- desc: return if the object is in a hover state or not
--]]---------------------------------------------------------
function base:GetHover()
return self.hover
end
--[[---------------------------------------------------------
- func: GetChildren()
- desc: returns the object's children
--]]---------------------------------------------------------
function base:GetChildren()
if self.children then
return self.children
end
end
--[[---------------------------------------------------------
- func: IsTopList()
- desc: returns true if the object is the top most list
object or false if not
--]]---------------------------------------------------------
function base:IsTopList()
local cols = loveframes.util.GetCollisions()
local children = self:GetChildren()
local order = self.draworder
local top = true
local found = false
local function IsChild(object)
for k, v in ipairs(children) do
if v == object then
return true
end
end
return false
end
for k, v in ipairs(cols) do
if v == self then
found = true
else
if v.draworder > order then
if IsChild(v) ~= true then
top = false
break
end
end
end
end
if found == false then
top = false
end
return top
end
--[[---------------------------------------------------------
- func: IsTopChild()
- desc: returns true if the object is the top most child
in it's parent's children table or false if not
--]]---------------------------------------------------------
function base:IsTopChild()
local children = self.parent.children
local num = #children
if children[num] == self then
return true
else
return false
end
end
--[[---------------------------------------------------------
- func: MoveToTop()
- desc: moves the object to the top of it's parent's
children table
--]]---------------------------------------------------------
function base:MoveToTop()
self:Remove()
table.insert(self.parent.children, self)
end
--[[---------------------------------------------------------
- func: SetSkin(name)
- desc: sets the object's skin
--]]---------------------------------------------------------
function base:SetSkin(name)
self.skin = name
if self.children then
for k, v in ipairs(self.children) do
v:SetSkin(name)
end
end
if self.internals then
for k, v in ipairs(self.internals) do
v:SetSkin(name)
end
end
end
--[[---------------------------------------------------------
- func: GetSkin(name)
- desc: gets the object's skin
--]]---------------------------------------------------------
function base:GetSkin(name)
return self.skin
end
--[[---------------------------------------------------------
- func: SetAlwaysUpdate(bool)
- desc: sets the object's skin
--]]---------------------------------------------------------
function base:SetAlwaysUpdate(bool)
self.alwaysupdate = bool
end
--[[---------------------------------------------------------
- func: GetAlwaysUpdate()
- desc: gets whether or not the object will always update
--]]---------------------------------------------------------
function base:GetAlwaysUpdate()
return self.alwaysupdate
end
--[[---------------------------------------------------------
- func: SetRetainSize(bool)
- desc: sets whether or not the object should retain it's
size when another object tries to resize it
--]]---------------------------------------------------------
function base:SetRetainSize(bool)
self.retainsize = bool
end
--[[---------------------------------------------------------
- func: GetRetainSize()
- desc: gets whether or not the object should retain it's
size when another object tries to resize it
--]]---------------------------------------------------------
function base:GetRetainSize()
return self.retainsize
end

189
objects/button.lua Normal file
View File

@ -0,0 +1,189 @@
--[[------------------------------------------------
-- LÖVE Frames --
-- By Nikolai Resokav --
--]]------------------------------------------------
-- button clas
button = class("button", base)
button:include(loveframes.templates.default)
--[[---------------------------------------------------------
- func: initialize()
- desc: initializes the object
--]]---------------------------------------------------------
function button:initialize()
self.type = "button"
self.text = "Button"
self.width = 80
self.height = 25
self.internal = false
self.hover = false
self.down = false
self.clickable = true
self.enabled = true
self.OnClick = nil
end
--[[---------------------------------------------------------
- func: update(deltatime)
- desc: updates the object
--]]---------------------------------------------------------
function button:update(dt)
if self.visible == false then
if self.alwaysupdate == false then
return
end
end
self:CheckHover()
-- move to parent if there is a parent
if self.parent ~= loveframes.base then
self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy
end
if self.Update then
self.Update(self, dt)
end
end
--[[---------------------------------------------------------
- func: draw()
- desc: draws the object
--]]---------------------------------------------------------
function button:draw()
if self.visible == false then
return
end
loveframes.drawcount = loveframes.drawcount + 1
self.draworder = loveframes.drawcount
-- skin variables
local index = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
if self.Draw ~= nil then
self.Draw(self)
else
skin.DrawButton(self)
end
end
--[[---------------------------------------------------------
- func: mousepressed(x, y, button)
- desc: called when the player presses a mouse button
--]]---------------------------------------------------------
function button:mousepressed(x, y, button)
if self.visible == false then
return
end
if self.hover == true and button == "l" then
local baseparent = self:GetBaseParent()
if baseparent and baseparent.type == "frame" then
baseparent:MakeTop()
end
self.down = true
end
end
--[[---------------------------------------------------------
- func: mousereleased(x, y, button)
- desc: called when the player releases a mouse button
--]]---------------------------------------------------------
function button:mousereleased(x, y, button)
if self.visible == false then
return
end
local hover = self.hover
local down = self.down
local clickable = self.clickable
local enabled = self.enabled
if hover == true and down == true and button == "l" and clickable == true then
if enabled == true then
self.OnClick(self, x, y)
end
end
self.down = false
end
--[[---------------------------------------------------------
- func: SetText(text)
- desc: sets the object's text
--]]---------------------------------------------------------
function button:SetText(text)
self.text = text
end
--[[---------------------------------------------------------
- func: GetText()
- desc: gets the object's text
--]]---------------------------------------------------------
function button:GetText()
return self.text
end
--[[---------------------------------------------------------
- func: SetClickable(bool)
- desc: sets whether the object can be clicked or not
--]]---------------------------------------------------------
function button:SetClickable(bool)
self.clickable = bool
end
--[[---------------------------------------------------------
- func: GetClickable(bool)
- desc: gets whether the object can be clicked or not
--]]---------------------------------------------------------
function button:GetClickable()
return self.clickable
end
--[[---------------------------------------------------------
- func: SetClickable(bool)
- desc: sets whether the object is enabled or not
--]]---------------------------------------------------------
function button:SetEnabled(bool)
self.enabled = bool
end
--[[---------------------------------------------------------
- func: GetEnabled()
- desc: gets whether the object is enabled or not
--]]---------------------------------------------------------
function button:GetEnabled()
return self.enabled
end

281
objects/checkbox.lua Normal file
View File

@ -0,0 +1,281 @@
--[[------------------------------------------------
-- LÖVE Frames --
-- By Nikolai Resokav --
--]]------------------------------------------------
-- button clas
checkbox = class("checkbox", base)
checkbox:include(loveframes.templates.default)
--[[---------------------------------------------------------
- func: initialize()
- desc: initializes the object
--]]---------------------------------------------------------
function checkbox:initialize()
self.type = "checkbox"
self.width = 0
self.height = 0
self.boxwidth = 20
self.boxheight = 20
self.font = love.graphics.newFont(12)
self.checked = false
self.lastvalue = false
self.internal = false
self.internals = {}
self.OnChanged = nil
end
--[[---------------------------------------------------------
- func: update(deltatime)
- desc: updates the object
--]]---------------------------------------------------------
function checkbox:update(dt)
if self.visible == false then
if self.alwaysupdate == false then
return
end
end
self:CheckHover()
-- move to parent if there is a parent
if self.parent ~= loveframes.base then
self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy
end
if self.internals[1] then
self.width = self.boxwidth + 5 + self.internals[1].width
if self.internals[1].height == self.boxheight then
self.height = self.boxheight
else
if self.internals[1].height > self.boxheight then
self.height = self.internals[1].height
else
self.height = self.boxheight
end
end
else
self.width = self.boxwidth
self.height = self.boxheight
end
for k, v in ipairs(self.internals) do
v:update(dt)
end
if self.Update then
self.Update(self, dt)
end
end
--[[---------------------------------------------------------
- func: draw()
- desc: draws the object
--]]---------------------------------------------------------
function checkbox:draw()
if self.visible == false then
return
end
loveframes.drawcount = loveframes.drawcount + 1
self.draworder = loveframes.drawcount
-- skin variables
local index = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
if self.Draw ~= nil then
self.Draw(self)
else
skin.DrawCheckBox(self)
end
for k, v in ipairs(self.internals) do
v:draw()
end
end
--[[---------------------------------------------------------
- func: mousepressed(x, y, button)
- desc: called when the player presses a mouse button
--]]---------------------------------------------------------
function checkbox:mousepressed(x, y, button)
if self.visible == false then
return
end
if self.hover == true and button == "l" 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 checkbox:mousereleased(x, y, button)
if self.visible == false then
return
end
local hover = self.hover
local checked = self.checked
if hover == true and button == "l" then
if checked == true then
self.checked = false
else
self.checked = true
end
if self.OnChanged then
self.OnChanged(self)
end
end
end
--[[---------------------------------------------------------
- func: SetText(text)
- desc: sets the object's text
--]]---------------------------------------------------------
function checkbox:SetText(text)
if text ~= "" then
self.internals = {}
local textobject = loveframes.Create("text")
textobject:Remove()
textobject.parent = self
textobject.collide = false
textobject:SetFont(self.font)
textobject:SetText(text)
textobject.Update = function(object, dt)
if object.height > self.boxheight then
object:SetPos(self.boxwidth + 5, 0)
else
object:SetPos(self.boxwidth + 5, self.boxheight/2 - object.height/2)
end
end
table.insert(self.internals, textobject)
else
self.width = self.boxwidth
self.height = self.boxheight
self.internals = {}
end
end
--[[---------------------------------------------------------
- func: GetText()
- desc: gets the object's text
--]]---------------------------------------------------------
function checkbox:GetText()
if self.internals[1] then
return self.internals[1].text
else
return false
end
end
--[[---------------------------------------------------------
- func: SetSize(width, height)
- desc: sets the object's size
--]]---------------------------------------------------------
function checkbox:SetSize(width, height)
self.boxwidth = width
self.boxheight = height
end
--[[---------------------------------------------------------
- func: SetWidth(width)
- desc: sets the object's width
--]]---------------------------------------------------------
function checkbox:SetWidth(width)
self.boxwidth = width
end
--[[---------------------------------------------------------
- func: SetHeight(height)
- desc: sets the object's height
--]]---------------------------------------------------------
function checkbox:SetHeight(height)
self.boxheight = height
end
--[[---------------------------------------------------------
- func: SetChecked(bool)
- desc: sets whether the object is checked or not
--]]---------------------------------------------------------
function checkbox:SetChecked(bool)
self.checked = bool
if self.OnChanged then
self.OnChanged(self)
end
end
--[[---------------------------------------------------------
- func: GetChecked()
- desc: gets whether the object is checked or not
--]]---------------------------------------------------------
function checkbox:GetChecked()
return self.checked
end
--[[---------------------------------------------------------
- func: SetFont(font)
- desc: sets the font of the object's text
--]]---------------------------------------------------------
function checkbox:SetFont(font)
self.font = font
if self.internals[1] then
self.internals[1]:SetFont(font)
end
end

View File

@ -0,0 +1,298 @@
--[[------------------------------------------------
-- LÖVE Frames --
-- By Nikolai Resokav --
--]]------------------------------------------------
-- button clas
collapsiblecategory = class("collapsiblecategory", base)
collapsiblecategory:include(loveframes.templates.default)
--[[---------------------------------------------------------
- func: initialize()
- desc: initializes the object
--]]---------------------------------------------------------
function collapsiblecategory: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.children = {}
self.OnOpenedClosed = nil
end
--[[---------------------------------------------------------
- func: update(deltatime)
- desc: updates the object
--]]---------------------------------------------------------
function collapsiblecategory:update(dt)
if self.visible == false then
if self.alwaysupdate == false then
return
end
end
self:CheckHover()
-- move to parent if there is a parent
if self.parent ~= loveframes.base then
self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy
end
if self.open == true then
for k, v in ipairs(self.children) do
v:update(dt)
v:SetWidth(self.width - self.padding*2)
v.y = (v.parent.y + v.staticy)
v.x = (v.parent.x + v.staticx)
end
end
if self.Update then
self.Update(self, dt)
end
end
--[[---------------------------------------------------------
- func: draw()
- desc: draws the object
--]]---------------------------------------------------------
function collapsiblecategory:draw()
if self.visible == false then
return
end
loveframes.drawcount = loveframes.drawcount + 1
self.draworder = loveframes.drawcount
-- skin variables
local index = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
if self.Draw ~= nil then
self.Draw(self)
else
skin.DrawCollapsibleCategory(self)
end
if self.open == true then
for k, v in ipairs(self.children) do
v:draw()
end
end
end
--[[---------------------------------------------------------
- func: mousepressed(x, y, button)
- desc: called when the player presses a mouse button
--]]---------------------------------------------------------
function collapsiblecategory:mousepressed(x, y, button)
if self.visible == false then
return
end
if self.hover == true then
local col = loveframes.util.BoundingBox(self.x, x, self.y, y, self.width, 1, self.closedheight, 1)
if button == "l" and col == true then
local baseparent = self:GetBaseParent()
if baseparent and baseparent.type == "frame" then
baseparent:MakeTop()
end
end
end
if self.open == true then
for k, v in ipairs(self.children) do
v:mousepressed(x, y, button)
end
end
end
--[[---------------------------------------------------------
- func: mousereleased(x, y, button)
- desc: called when the player releases a mouse button
--]]---------------------------------------------------------
function collapsiblecategory:mousereleased(x, y, button)
if self.visible == false 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.util.BoundingBox(self.x, x, self.y, y, self.width, 1, self.closedheight, 1)
if hover == true and button == "l" and col == true then
if open == true then
self:SetOpen(false)
else
self:SetOpen(true)
end
end
if self.open == true then
for k, v in ipairs(self.children) do
v:mousereleased(x, y, button)
end
end
end
--[[---------------------------------------------------------
- func: SetText(text)
- desc: sets the object's text
--]]---------------------------------------------------------
function collapsiblecategory:SetText(text)
self.text = text
end
--[[---------------------------------------------------------
- func: GetText()
- desc: gets the object's text
--]]---------------------------------------------------------
function collapsiblecategory:GetText()
return self.text
end
--[[---------------------------------------------------------
- func: SetObject(object)
- desc: sets the category's object
--]]---------------------------------------------------------
function collapsiblecategory:SetObject(object)
if self.children[1] then
self.children[1]:Remove()
self.children = {}
end
object:Remove()
object.parent = self
object:SetWidth(self.width - self.padding*2)
object:SetPos(self.padding, self.closedheight + self.padding)
table.insert(self.children, object)
end
--[[---------------------------------------------------------
- func: SetObject(object)
- desc: sets the category's object
--]]---------------------------------------------------------
function collapsiblecategory:GetObject()
if self.children[1] then
return self.children[1]
else
return false
end
end
--[[---------------------------------------------------------
- func: SetSize(width, height)
- desc: sets the object's size
--]]---------------------------------------------------------
function collapsiblecategory:SetSize(width, height)
self.width = width
end
--[[---------------------------------------------------------
- func: SetHeight(height)
- desc: sets the object's height
--]]---------------------------------------------------------
function collapsiblecategory:SetHeight(height)
return
end
--[[---------------------------------------------------------
- func: SetClosedHeight(height)
- desc: sets the object's closed height
--]]---------------------------------------------------------
function collapsiblecategory:SetClosedHeight(height)
self.closedheight = height
end
--[[---------------------------------------------------------
- func: GetClosedHeight()
- desc: gets the object's closed height
--]]---------------------------------------------------------
function collapsiblecategory:GetClosedHeight()
return self.closedheight
end
--[[---------------------------------------------------------
- func: SetOpen(bool)
- desc: sets whether the object is opened or closed
--]]---------------------------------------------------------
function collapsiblecategory:SetOpen(bool)
self.open = bool
if bool == false then
self.height = self.closedheight
if self.children[1] then
self.children[1]:SetVisible(false)
end
else
self.height = self.closedheight + self.padding*2 + self.children[1].height
if self.children[1] then
self.children[1]:SetVisible(true)
end
end
if self.OnOpenedClosed then
self.OnOpenedClosed(self)
end
end
--[[---------------------------------------------------------
- func: GetOpen()
- desc: gets whether the object is opened or closed
--]]---------------------------------------------------------
function collapsiblecategory:GetOpen()
return self.opened
end

291
objects/columnlist.lua Normal file
View File

@ -0,0 +1,291 @@
--[[------------------------------------------------
-- LÖVE Frames --
-- By Nikolai Resokav --
--]]------------------------------------------------
-- columnlist object
columnlist = class("columnlist", base)
columnlist:include(loveframes.templates.default)
--[[---------------------------------------------------------
- func: initialize()
- desc: intializes the element
--]]---------------------------------------------------------
function columnlist:initialize()
self.type = "columnlist"
self.width = 300
self.height = 100
self.internal = false
self.children = {}
self.internals = {}
self.OnRowClicked = nil
self.OnScroll = nil
local list = columnlistarea:new(self)
table.insert(self.internals, list)
end
--[[---------------------------------------------------------
- func: update(deltatime)
- desc: updates the object
--]]---------------------------------------------------------
function columnlist:update(dt)
if self.visible == false then
if self.alwaysupdate == false then
return
end
end
self:CheckHover()
-- move to parent if there is a parent
if self.parent ~= loveframes.base then
self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy
end
for k, v in ipairs(self.children) do
v:update(dt)
end
for k, v in ipairs(self.internals) do
v:update(dt)
end
if self.Update then
self.Update(self, dt)
end
end
--[[---------------------------------------------------------
- func: draw()
- desc: draws the object
--]]---------------------------------------------------------
function columnlist:draw()
if self.visible == false then
return
end
loveframes.drawcount = loveframes.drawcount + 1
self.draworder = loveframes.drawcount
-- skin variables
local index = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
if self.Draw ~= nil then
self.Draw(self)
else
skin.DrawColumnList(self)
end
for k, v in ipairs(self.internals) do
v:draw()
end
for k, v in ipairs(self.children) do
v:draw()
end
end
--[[---------------------------------------------------------
- func: mousepressed(x, y, button)
- desc: called when the player presses a mouse button
--]]---------------------------------------------------------
function columnlist:mousepressed(x, y, button)
if self.hover == true and button == "l" 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 columnlist:mousereleased(x, y, button)
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: keypressed(key)
- desc: called when the player presses a key
--]]---------------------------------------------------------
function columnlist:keypressed(key, unicode)
for k, v in ipairs(self.internals) do
v:keypressed(key, unicode)
end
for k, v in ipairs(self.children) do
v:keypressed(key, unicode)
end
end
--[[---------------------------------------------------------
- func: keyreleased(key)
- desc: called when the player releases a key
--]]---------------------------------------------------------
function columnlist:keyreleased(key)
for k, v in ipairs(self.internals) do
v:keyreleased(key)
end
for k, v in ipairs(self.children) do
v:keyreleased(key)
end
end
--[[---------------------------------------------------------
- func: Adjustchildren()
- desc: adjusts the width of the object's children
--]]---------------------------------------------------------
function columnlist:AdjustColumns()
local width = self.width
local bar = self.internals[1].bar
if bar == true then
width = width - 16
end
local children = self.children
local numchildren = #children
local columnwidth = width/numchildren
local x = 0
for k, v in ipairs(children) do
if bar == true then
v:SetWidth(columnwidth)
else
v:SetWidth(columnwidth)
end
v:SetPos(x, 0)
x = x + columnwidth
end
end
--[[---------------------------------------------------------
- func: AddColumn(name)
- desc: gives the object a new column with the specified
name
--]]---------------------------------------------------------
function columnlist:AddColumn(name)
columnlistheader:new(name, self)
self:AdjustColumns()
self.internals[1]:SetSize(self.width, self.height)
self.internals[1]:SetPos(0, 0)
end
--[[---------------------------------------------------------
- func: AddRow(...)
- desc: adds a row of data to the object's list
--]]---------------------------------------------------------
function columnlist:AddRow(...)
self.internals[1]:AddRow(arg)
end
--[[---------------------------------------------------------
- func: Getchildrenize()
- desc: gets the size of the object's children
--]]---------------------------------------------------------
function columnlist:GetColumnSize()
if #self.children > 0 then
return self.children[1].width, self.children[1].height
else
return 0, 0
end
end
--[[---------------------------------------------------------
- func: SetSize(width, height)
- desc: sets the object's size
--]]---------------------------------------------------------
function columnlist:SetSize(width, height)
self.width = width
self.height = height
self.internals[1]:SetSize(width, height)
self.internals[1]:SetPos(0, 0)
end
--[[---------------------------------------------------------
- func: SetWidth(width)
- desc: sets the object's width
--]]---------------------------------------------------------
function columnlist:SetWidth(width)
self.width = width
self.internals[1]:SetSize(width)
self.internals[1]:SetPos(0, 0)
end
--[[---------------------------------------------------------
- func: SetHeight(height)
- desc: sets the object's height
--]]---------------------------------------------------------
function columnlist:SetHeight(height)
self.height = height
self.internals[1]:SetSize(height)
self.internals[1]:SetPos(0, 0)
end
--[[---------------------------------------------------------
- func: SetMaxColorIndex(num)
- desc: sets the object's max color index for
alternating row colors
--]]---------------------------------------------------------
function columnlist:SetMaxColorIndex(num)
self.internals[1].colorindexmax = num
end

318
objects/frame.lua Normal file
View File

@ -0,0 +1,318 @@
--[[------------------------------------------------
-- LÖVE Frames --
-- By Nikolai Resokav --
--]]------------------------------------------------
-- frame class
frame = class("frame", base)
frame:include(loveframes.templates.default)
--[[---------------------------------------------------------
- func: initialize()
- desc: initializes the object
--]]---------------------------------------------------------
function frame:initialize()
self.type = "frame"
self.name = "Frame"
self.width = 300
self.height = 150
self.clickx = 0
self.clicky = 0
self.internal = false
self.draggable = true
self.screenlocked = false
self.dragging = false
self.internals = {}
self.children = {}
self.OnClose = nil
local close = closebutton:new()
close.parent = self
close:SetSize(16, 16)
close.OnClick = function()
self:Remove()
if self.OnClose then
self.OnClose(self)
end
end
table.insert(self.internals, close)
end
--[[---------------------------------------------------------
- func: update(deltatime)
- desc: updates the element
--]]---------------------------------------------------------
function frame:update(dt)
local x, y = love.mouse.getPosition()
local showclose = self.showclose
local close = self.internals[1]
if self.visible == false then
if self.alwaysupdate == false then
return
end
end
close:SetPos(self.width - 22, 4)
self:CheckHover()
-- dragging check
if self.dragging == true then
self.x = x - self.clickx
self.y = y - self.clicky
end
-- if screenlocked then keep within screen
if self.screenlocked == true then
local width = love.graphics.getWidth()
local height = love.graphics.getHeight()
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
end
for k, v in ipairs(self.internals) do
v:update(dt)
end
for k, v in ipairs(self.children) do
v:update(dt)
end
if self.Update then
self.Update(self, dt)
end
end
--[[---------------------------------------------------------
- func: draw()
- desc: draws the object
--]]---------------------------------------------------------
function frame:draw()
if self.visible == false then
return
end
-- skin variables
local index = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
loveframes.drawcount = loveframes.drawcount + 1
self.draworder = loveframes.drawcount
if self.Draw ~= nil then
self.Draw(self)
else
skin.DrawFrame(self)
end
for k, v in ipairs(self.internals) do
v:draw()
end
-- loop through the object's children and draw them
for k, v in ipairs(self.children) do
v:draw()
end
end
--[[---------------------------------------------------------
- func: mousepressed(x, y, button)
- desc: called when the player presses a mouse button
--]]---------------------------------------------------------
function frame:mousepressed(x, y, button)
local width = self.width
local height = self.height
local selfcol = loveframes.util.BoundingBox(x, self.x, y, self.y, 1, self.width, 1, self.height)
if self.visible == false then
return
end
if selfcol == true then
local top = self:IsTopCollision()
-- initiate dragging if not currently dragging
if self.dragging == false and top == true and button == "l" then
if y < self.y + 25 and self.draggable == true then
self.clickx = x - self.x
self.clicky = y - self.y
self.dragging = true
end
end
if top == true and button == "l" then
self: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 frame:mousereleased(x, y, button)
if self.visible == false then
return
end
-- exit the dragging state
if self.dragging == true then
self.dragging = false
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: SetName(name)
- desc: sets the frame's name
--]]---------------------------------------------------------
function frame:SetName(name)
self.name = name
end
--[[---------------------------------------------------------
- func: GetName()
- desc: gets the frame's name
--]]---------------------------------------------------------
function frame:GetName()
return self.name
end
--[[---------------------------------------------------------
- func: SetDraggable(true/false)
- desc: sets whether the frame can be dragged or not
--]]---------------------------------------------------------
function frame:SetDraggable(bool)
self.draggable = bool
end
--[[---------------------------------------------------------
- func: GetDraggable()
- desc: gets whether the frame can be dragged ot not
--]]---------------------------------------------------------
function frame:GetDraggable()
return self.draggable
end
--[[---------------------------------------------------------
- func: SetScreenLocked(bool)
- desc: sets whether the frame can be moved passed the
boundaries of the window or not
--]]---------------------------------------------------------
function frame:SetScreenLocked(bool)
self.screenlocked = bool
end
--[[---------------------------------------------------------
- func: GetScreenLocked()
- desc: gets whether the frame can be moved passed the
boundaries of window or not
--]]---------------------------------------------------------
function frame:GetScreenLocked()
return self.screenlocked
end
--[[---------------------------------------------------------
- func: ShowCloseButton(bool)
- desc: sets whether the close button should be drawn
--]]---------------------------------------------------------
function frame:ShowCloseButton(bool)
local close = self.internals[1]
close.visible = bool
end
--[[---------------------------------------------------------
- func: MakeTop()
- desc: makes the object the top object in the drawing
order
--]]---------------------------------------------------------
function frame:MakeTop()
local x, y = love.mouse.getPosition()
local children = loveframes.base.children
local numchildren = #children
local key = 0
if numchildren == 1 then
return
end
if children[numchildren] == self then
return
end
-- make this the top element
for k, v in ipairs(children) do
if v == self then
table.remove(loveframes.base.children, k)
table.insert(loveframes.base.children, self)
key = k
break
end
end
loveframes.base.children[key]:mousepressed(x, y, "l")
end

112
objects/image.lua Normal file
View File

@ -0,0 +1,112 @@
--[[------------------------------------------------
-- LÖVE Frames --
-- By Nikolai Resokav --
--]]------------------------------------------------
-- progress bar class
image = class("image", base)
image:include(loveframes.templates.default)
--[[---------------------------------------------------------
- func: initialize()
- desc: initializes the object
--]]---------------------------------------------------------
function image:initialize()
self.type = "image"
self.width = 0
self.height = 0
self.internal = false
self.image = nil
self.imagecolor = nil
end
--[[---------------------------------------------------------
- func: update(deltatime)
- desc: updates the object
--]]---------------------------------------------------------
function image:update(dt)
if self.visible == false then
if self.alwaysupdate == false then
return
end
end
-- move to parent if there is a parent
if self.parent ~= nil then
self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy
end
if self.Update then
self.Update(self, dt)
end
end
--[[---------------------------------------------------------
- func: draw()
- desc: draws the object
--]]---------------------------------------------------------
function image:draw()
if self.visible == false then
return
end
-- skin variables
local index = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
loveframes.drawcount = loveframes.drawcount + 1
self.draworder = loveframes.drawcount
if self.Draw ~= nil then
self.Draw(self)
else
skin.DrawImage(self)
end
local image = self.image
local color = self.imagecolor
if color then
love.graphics.setColor(unpack(color))
love.graphics.draw(image)
else
love.graphics.setColor(255, 255, 255, 255)
love.graphics.draw(image, self.x, self.y)
end
end
--[[---------------------------------------------------------
- func: SetImage(image)
- desc: sets the object's image
--]]---------------------------------------------------------
function image:SetImage(image)
if type(image) == "string" then
self.image = love.graphics.newImage(image)
else
self.image = image
end
self.width = self.image:getWidth()
self.height = self.image:getHeight()
end
--[[---------------------------------------------------------
- func: SetColor(table)
- desc: sets the object's color
--]]---------------------------------------------------------
function image:SetColor(t)
self.imagecolor = t
end

View File

@ -0,0 +1,122 @@
--[[------------------------------------------------
-- LÖVE Frames --
-- By Nikolai Resokav --
--]]------------------------------------------------
-- closebutton clas
closebutton = class("closebutton", base)
closebutton:include(loveframes.templates.default)
--[[---------------------------------------------------------
- func: initialize()
- desc: initializes the object
--]]---------------------------------------------------------
function closebutton:initialize()
self.type = "closebutton"
self.width = 80
self.height = 25
self.internal = true
self.hover = false
self.down = false
self.OnClick = function() end
end
--[[---------------------------------------------------------
- func: update(deltatime)
- desc: updates the object
--]]---------------------------------------------------------
function closebutton:update(dt)
if self.visible == false then
if self.alwaysupdate == false then
return
end
end
self:CheckHover()
-- move to parent if there is a parent
if self.parent ~= loveframes.base then
self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy
end
if self.Update then
self.Update(self, dt)
end
end
--[[---------------------------------------------------------
- func: draw()
- desc: draws the object
--]]---------------------------------------------------------
function closebutton:draw()
if self.visible == false then
return
end
loveframes.drawcount = loveframes.drawcount + 1
self.draworder = loveframes.drawcount
-- skin variables
local index = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
if self.Draw ~= nil then
self.Draw(self)
else
skin.DrawCloseButton(self)
end
end
--[[---------------------------------------------------------
- func: mousepressed(x, y, button)
- desc: called when the player presses a mouse button
--]]---------------------------------------------------------
function closebutton:mousepressed(x, y, button)
if self.visible == false then
return
end
if self.hover == true and button == "l" then
local baseparent = self:GetBaseParent()
if baseparent and baseparent.type == "frame" then
baseparent:MakeTop()
end
self.down = true
end
end
--[[---------------------------------------------------------
- func: mousereleased(x, y, button)
- desc: called when the player releases a mouse button
--]]---------------------------------------------------------
function closebutton:mousereleased(x, y, button)
if self.visible == false then
return
end
if self.hover == true and self.down == true then
if button == "l" then
self.OnClick(x, y, self)
end
end
self.down = false
end

View File

@ -0,0 +1,343 @@
--[[------------------------------------------------
-- LÖVE Frames --
-- By Nikolai Resokav --
--]]------------------------------------------------
-- columnlistarea object
columnlistarea = class("columnlistarea", base)
columnlistarea:include(loveframes.templates.default)
--[[---------------------------------------------------------
- func: initialize()
- desc: intializes the element
--]]---------------------------------------------------------
function columnlistarea:initialize(parent)
self.type = "columnlistarea"
self.parent = parent
self.width = 80
self.height = 25
self.clickx = 0
self.clicky = 0
self.offsety = 0
self.offsetx = 0
self.extra = 0
self.rowcolorindex = 1
self.rowcolorindexmax = 2
self.bar = false
self.internal = true
self.internals = {}
self.children = {}
end
--[[---------------------------------------------------------
- func: update(deltatime)
- desc: updates the object
--]]---------------------------------------------------------
function columnlistarea:update(dt)
if self.visible == false then
if self.alwaysupdate == false then
return
end
end
local cwidth, cheight = self.parent:GetColumnSize()
self:CheckHover()
-- move to parent if there is a parent
if self.parent ~= loveframes.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
v:update(dt)
end
for k, v in ipairs(self.children) do
v:update(dt)
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
if self.Update then
self.Update(self, dt)
end
end
--[[---------------------------------------------------------
- func: draw()
- desc: draws the object
--]]---------------------------------------------------------
function columnlistarea:draw()
if self.visible == false then
return
end
loveframes.drawcount = loveframes.drawcount + 1
self.draworder = loveframes.drawcount
-- skin variables
local index = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
if self.Draw ~= nil then
self.Draw(self)
else
skin.DrawColumnListArea(self)
end
for k, v in ipairs(self.internals) do
v:draw()
end
local stencilfunc = function() love.graphics.rectangle("fill", self.x, self.y, self.width, self.height) end
local stencil = love.graphics.newStencil(stencilfunc)
love.graphics.setStencil(stencil)
for k, v in ipairs(self.children) do
local col = loveframes.util.BoundingBox(self.x, v.x, self.y, v.y, self.width, v.width, self.height, v.height)
if col == true then
v:draw()
end
end
love.graphics.setStencil()
if self.Draw == nil then
skin.DrawColumnListArea(self)
end
end
--[[---------------------------------------------------------
- func: mousepressed(x, y, button)
- desc: called when the player presses a mouse button
--]]---------------------------------------------------------
function columnlistarea:mousepressed(x, y, button)
local toplist = self:IsTopList()
if self.hover == true and button == "l" then
local baseparent = self:GetBaseParent()
if baseparent and baseparent.type == "frame" then
baseparent:MakeTop()
end
end
if self.bar == true then
if toplist == true then
local bar = self:GetScrollBar()
if button == "wu" then
bar:Scroll(-5)
elseif button == "wd" then
bar:Scroll(5)
end
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 columnlistarea:mousereleased(x, y, button)
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: keypressed(key)
- desc: called when the player presses a key
--]]---------------------------------------------------------
function columnlistarea:keypressed(key, unicode)
for k, v in ipairs(self.internals) do
v:keypressed(key, unicode)
end
for k, v in ipairs(self.children) do
v:keypressed(key, unicode)
end
end
--[[---------------------------------------------------------
- func: keyreleased(key)
- desc: called when the player releases a key
--]]---------------------------------------------------------
function columnlistarea:keyreleased(key)
for k, v in ipairs(self.internals) do
v:keyreleased(key)
end
for k, v in ipairs(self.children) do
v:keyreleased(key)
end
end
--[[---------------------------------------------------------
- func: CalculateSize()
- desc: calculates the size of the object's children
--]]---------------------------------------------------------
function columnlistarea:CalculateSize()
local iw, ih = self.parent:GetColumnSize()
local numitems = #self.children
local height = self.height
local width = self.width
local itemheight = ih
local itemwidth = 0
local bar = self.bar
for k, v in ipairs(self.children) do
itemheight = itemheight + v.height
end
self.itemheight = itemheight
if self.itemheight > height then
self.extra = self.itemheight - height
if bar == false then
table.insert(self.internals, scrollbody:new(self, "vertical"))
self.bar = true
end
else
if bar == true then
self.internals[1]:Remove()
self.bar = false
self.offsety = 0
end
end
end
--[[---------------------------------------------------------
- func: RedoLayout()
- desc: used to redo the layour of the object
--]]---------------------------------------------------------
function columnlistarea:RedoLayout()
local children = self.children
local starty = 0
local startx = 0
local bar = self.bar
local display = self.display
if #children > 0 then
for k, v in ipairs(children) do
local height = v.height
v.staticx = startx
v.staticy = starty
if bar == true then
v:SetWidth(self.width - self.internals[1].width)
self.internals[1].staticx = self.width - self.internals[1].width
self.internals[1].height = self.height
else
v:SetWidth(self.width)
end
starty = starty + v.height
v.lastheight = v.height
end
end
end
function columnlistarea:AddRow(data)
local row = columnlistrow:new(self, data)
local colorindex = self.rowcolorindex
local colorindexmax = self.rowcolorindexmax
if colorindex == colorindexmax then
self.rowcolorindex = 1
else
self.rowcolorindex = colorindex + 1
end
table.insert(self.children, row)
self:CalculateSize()
self:RedoLayout()
self.parent:AdjustColumns()
end
--[[---------------------------------------------------------
- func: GetScrollBar()
- desc: gets the object's scroll bar
--]]---------------------------------------------------------
function columnlistarea:GetScrollBar()
return self.internals[1].internals[1].internals[1]
end
--[[---------------------------------------------------------
- func: Sort()
- desc: sorts the object's children
--]]---------------------------------------------------------
function columnlistarea:Sort(column, desc)
table.sort(self.children, function(a, b)
if desc then
return a.columndata[column] < b.columndata[column]
else
return a.columndata[column] > b.columndata[column]
end
end)
self:CalculateSize()
self:RedoLayout()
end

View File

@ -0,0 +1,147 @@
--[[------------------------------------------------
-- LÖVE Frames --
-- By Nikolai Resokav --
--]]------------------------------------------------
-- columnlistrow object
columnlistrow = class("columnlistrow", base)
columnlistrow:include(loveframes.templates.default)
--[[---------------------------------------------------------
- func: initialize()
- desc: intializes the element
--]]---------------------------------------------------------
function columnlistrow:initialize(parent, data)
self.type = "columnlistrow"
self.parent = parent
self.colorindex = self.parent.rowcolorindex
self.font = love.graphics.newFont(12)
self.width = 80
self.height = 25
self.internal = true
self.columndata = data
end
--[[---------------------------------------------------------
- func: update(deltatime)
- desc: updates the object
--]]---------------------------------------------------------
function columnlistrow:update(dt)
if self.visible == false then
if self.alwaysupdate == false then
return
end
end
self:CheckHover()
-- move to parent if there is a parent
if self.parent ~= loveframes.base then
self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy
end
if self.Update then
self.Update(self, dt)
end
end
--[[---------------------------------------------------------
- func: draw()
- desc: draws the object
--]]---------------------------------------------------------
function columnlistrow:draw()
if self.visible == false then
return
end
loveframes.drawcount = loveframes.drawcount + 1
self.draworder = loveframes.drawcount
-- skin variables
local index = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
if self.Draw ~= nil then
self.Draw(self)
else
skin.DrawColumnListRow(self)
end
end
--[[---------------------------------------------------------
- func: mousepressed(x, y, button)
- desc: called when the player presses a mouse button
--]]---------------------------------------------------------
function columnlistrow:mousepressed(x, y, button)
if self.visible == false then
return
end
if self.hover == true and button == "l" 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 columnlistrow:mousereleased(x, y, button)
if self.visible == false then
return
end
if self.hover == true and button == "l" then
local parent1 = self:GetParent()
local parent2 = parent1:GetParent()
if parent2.OnRowClicked then
parent2.OnRowClicked(parent2, self, self.columndata)
end
end
end
--[[---------------------------------------------------------
- func: keypressed(key)
- desc: called when the player presses a key
--]]---------------------------------------------------------
function columnlistrow:keypressed(key, unicode)
if self.visible == false then
return
end
end
--[[---------------------------------------------------------
- func: keyreleased(key)
- desc: called when the player releases a key
--]]---------------------------------------------------------
function columnlistrow:keyreleased(key)
if self.visible == false then
return
end
end

View File

@ -0,0 +1,162 @@
--[[------------------------------------------------
-- LÖVE Frames --
-- By Nikolai Resokav --
--]]------------------------------------------------
-- columnlistheader object
columnlistheader = class("columnlistheader", base)
columnlistheader:include(loveframes.templates.default)
--[[---------------------------------------------------------
- func: initialize()
- desc: intializes the element
--]]---------------------------------------------------------
function columnlistheader:initialize(name, parent)
self.type = "columnlistheader"
self.parent = parent
self.name = name
self.width = 80
self.height = 16
self.hover = false
self.down = false
self.clickable = true
self.enabled = true
self.descending = true
self.internal = true
table.insert(parent.children, self)
local key = 0
for k, v in ipairs(self.parent.children) do
if v == self then
key = k
end
end
self.OnClick = function()
if self.descending == true then
self.descending = false
else
self.descending = true
end
self.parent.internals[1]:Sort(key, self.descending)
end
end
--[[---------------------------------------------------------
- func: update(deltatime)
- desc: updates the object
--]]---------------------------------------------------------
function columnlistheader:update(dt)
if self.visible == false then
if self.alwaysupdate == false then
return
end
end
self:CheckHover()
-- move to parent if there is a parent
if self.parent ~= loveframes.base then
self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy
end
if self.Update then
self.Update(self, dt)
end
end
--[[---------------------------------------------------------
- func: draw()
- desc: draws the object
--]]---------------------------------------------------------
function columnlistheader:draw()
if self.visible == false then
return
end
loveframes.drawcount = loveframes.drawcount + 1
self.draworder = loveframes.drawcount
-- skin variables
local index = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
if self.Draw ~= nil then
self.Draw(self)
else
skin.DrawColumnListHeader(self)
end
end
--[[---------------------------------------------------------
- func: mousepressed(x, y, button)
- desc: called when the player presses a mouse button
--]]---------------------------------------------------------
function columnlistheader:mousepressed(x, y, button)
if self.hover == true and button == "l" then
local baseparent = self:GetBaseParent()
if baseparent and baseparent.type == "frame" and button == "l" then
baseparent:MakeTop()
end
self.down = true
end
end
--[[---------------------------------------------------------
- func: mousereleased(x, y, button)
- desc: called when the player releases a mouse button
--]]---------------------------------------------------------
function columnlistheader:mousereleased(x, y, button)
if self.visible == false then
return
end
local hover = self.hover
local down = self.down
local clickable = self.clickable
local enabled = self.enabled
if hover == true and down == true and button == "l" and clickable == true then
if enabled == true then
self.OnClick(self, x, y)
end
end
self.down = false
end
--[[---------------------------------------------------------
- func: keypressed(key)
- desc: called when the player presses a key
--]]---------------------------------------------------------
function columnlistheader:keypressed(key, unicode)
end
--[[---------------------------------------------------------
- func: keyreleased(key)
- desc: called when the player releases a key
--]]---------------------------------------------------------
function columnlistheader:keyreleased(key)
end

View File

@ -0,0 +1,360 @@
--[[------------------------------------------------
-- LÖVE Frames --
-- By Nikolai Resokav --
--]]------------------------------------------------
-- multichoicelist class
multichoicelist = class("multichoicelist", base)
multichoicelist:include(loveframes.templates.default)
--[[---------------------------------------------------------
- func: initialize()
- desc: initializes the object
--]]---------------------------------------------------------
function multichoicelist:initialize(object)
self.type = "multichoice-list"
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.offsety = 0
self.offsetx = 0
self.extra = 0
self.canremove = false
self.internal = true
self.vbar = false
self.children = {}
self.internals = {}
for k, v in ipairs(object.choices) do
local row = multichoicerow:new()
row:SetText(v)
self:AddItem(row)
end
table.insert(loveframes.base.children, self)
end
--[[---------------------------------------------------------
- func: update(deltatime)
- desc: updates the object
--]]---------------------------------------------------------
function multichoicelist:update(dt)
if self.visible == false then
if self.alwaysupdate == false then
return
end
end
local width = love.graphics.getWidth()
local height = love.graphics.getHeight()
local x, y = love.mouse.getPosition()
local selfcol = loveframes.util.BoundingBox(x, self.x, y, self.y, 1, self.width, 1, self.height)
-- move to parent if there is a parent
if self.parent ~= loveframes.base then
self.x = self.parent.x + self.staticx
self.y = self.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(self.internals) do
v:update(dt)
end
for k, v in ipairs(self.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 loveframes.base.children[#loveframes.base.children] ~= self then
-- self:Remove()
-- table.insert(loveframes.base.children, self)
--end
if self.Update then
self.Update(self, dt)
end
end
--[[---------------------------------------------------------
- func: draw()
- desc: draws the object
--]]---------------------------------------------------------
function multichoicelist:draw()
loveframes.drawcount = loveframes.drawcount + 1
self.draworder = loveframes.drawcount
-- skin variables
local index = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
if self.Draw ~= nil then
self.Draw(self)
else
skin.DrawMultiChoiceList(self)
end
for k, v in ipairs(self.internals) do
v:draw()
end
love.graphics.setScissor(self.x, self.y, self.width, self.height)
for k, v in ipairs(self.children) do
local col = loveframes.util.BoundingBox(self.x, v.x, self.y, v.y, self.width, v.width, self.height, v.height)
if col == true then
v:draw()
end
end
love.graphics.setScissor()
skin.DrawOverMultiChoiceList(self)
end
--[[---------------------------------------------------------
- func: mousepressed(x, y, button)
- desc: called when the player presses a mouse button
--]]---------------------------------------------------------
function multichoicelist:mousepressed(x, y, button)
if self.visible == false then
return
end
local selfcol = loveframes.util.BoundingBox(x, self.x, y, self.y, 1, self.width, 1, self.height)
local toplist = self:IsTopList()
if selfcol == false and button == "l" and self.canremove == true then
self:Close()
end
if self.vbar == true and toplist == true then
if button == "wu" then
self.internals[1].internals[1].internals[1]:Scroll(-5)
elseif button == "wd" then
self.internals[1].internals[1].internals[1]:Scroll(5)
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 multichoicelist:mousereleased(x, y, button)
if self.visible == false then
return
end
self.canremove = true
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: AddItem(object)
- desc: adds an item to the object
--]]---------------------------------------------------------
function multichoicelist:AddItem(object)
if object.type ~= "multichoice-row" 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 multichoicelist:RemoveItem(object)
for k, v in ipairs(self.children) do
if v == object then
table.remove(self.children, k)
end
end
self:CalculateSize()
self:RedoLayout()
end
--[[---------------------------------------------------------
- func: CalculateSize()
- desc: calculates the size of the object's children
--]]---------------------------------------------------------
function multichoicelist: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
for k, v in ipairs(self.children) do
itemheight = itemheight + v.height + spacing
end
self.itemheight = (itemheight - spacing) + padding
if self.itemheight > height then
self.extra = self.itemheight - height
if vbar == false then
local scroll = scrollbody:new(self, "vertical")
table.insert(self.internals, scroll)
self.vbar = true
end
else
if vbar == true 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 multichoicelist: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 == true 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 multichoicelist:SetPadding(amount)
self.padding = amount
end
--[[---------------------------------------------------------
- func: SetSpacing(amount)
- desc: sets the object's spacing
--]]---------------------------------------------------------
function multichoicelist:SetSpacing(amount)
self.spacing = amount
end
function multichoicelist:Close()
self:Remove()
self.list.haslist = false
end

View File

@ -0,0 +1,114 @@
--[[------------------------------------------------
-- LÖVE Frames --
-- By Nikolai Resokav --
--]]------------------------------------------------
-- multichoicerow class
multichoicerow = class("multichoicerow", base)
multichoicerow:include(loveframes.templates.default)
--[[---------------------------------------------------------
- func: initialize()
- desc: initializes the object
--]]---------------------------------------------------------
function multichoicerow:initialize()
self.type = "multichoice-row"
self.text = ""
self.width = 50
self.height = 25
self.hover = false
self.internal = true
self.down = false
self.canclick = false
self.OnClick = nil
end
--[[---------------------------------------------------------
- func: update(deltatime)
- desc: updates the object
--]]---------------------------------------------------------
function multichoicerow:update(dt)
if self.visible == false then
if self.alwaysupdate == false then
return
end
end
self:CheckHover()
-- move to parent if there is a parent
if self.parent ~= loveframes.base then
self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy
end
if self.Update then
self.Update(self, dt)
end
end
--[[---------------------------------------------------------
- func: draw()
- desc: draws the object
--]]---------------------------------------------------------
function multichoicerow:draw()
loveframes.drawcount = loveframes.drawcount + 1
self.draworder = loveframes.drawcount
-- skin variables
local index = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
if self.Draw ~= nil then
self.Draw(self)
else
skin.DrawMultiChoiceRow(self)
end
end
--[[---------------------------------------------------------
- func: mousepressed(x, y, button)
- desc: called when the player presses a mouse button
--]]---------------------------------------------------------
function multichoicerow:mousepressed(x, y, button)
if self.visible == false then
return
end
self.down = true
end
--[[---------------------------------------------------------
- func: mousereleased(x, y, button)
- desc: called when the player releases a mouse button
--]]---------------------------------------------------------
function multichoicerow:mousereleased(x, y, button)
if self.visible == false then
return
end
if self.hover == true and self.down == true and self.canclick == true and button == "l" then
self.parent.list:SelectChoice(self.text)
end
self.down = false
self.canclick = true
end
function multichoicerow:SetText(text)
self.text = text
end

View File

@ -0,0 +1,168 @@
--[[------------------------------------------------
-- LÖVE Frames --
-- By Nikolai Resokav --
--]]------------------------------------------------
-- scrollbar class
scrollarea = class("scrollarea", base)
function scrollarea: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, scrollbar:new(self, bartype))
end
function scrollarea:update(dt)
if self.visible == false then
if self.alwaysupdate == false then
return
end
end
-- move to parent if there is a parent
if self.parent ~= loveframes.base then
self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy
end
self:CheckHover()
if self.parent.internals[2] then
if self.bartype == "vertical" then
self.staticx = 0
self.staticy = self.parent.internals[2].height - 1
self.width = self.parent.width
self.height = self.parent.height - self.parent.internals[2].height*2 + 2
elseif self.bartype == "horizontal" then
self.staticx = self.parent.internals[2].width - 1
self.staticy = 0
self.width = self.parent.width - self.parent.internals[2].width*2 + 2
self.height = self.parent.height
end
end
local time = love.timer.getTime()
local x, y = love.mouse.getPosition()
local listo = self.parent.parent
if self.down == true then
if self.scrolldelay < time then
self.scrolldelay = time + self.delayamount
if listo.display == "vertical" then
if y > self.internals[1].y then
self.internals[1]:Scroll(self.internals[1].height)
else
self.internals[1]:Scroll(-self.internals[1].height)
end
elseif listo.display == "horizontal" then
if x > self.internals[1].x then
self.internals[1]:Scroll(self.internals[1].width)
else
self.internals[1]:Scroll(-self.internals[1].width)
end
end
end
if self.hover == false then
self.down = false
end
end
for k, v in ipairs(self.internals) do
v:update(dt)
end
if self.Update then
self.Update(self, dt)
end
end
function scrollarea:draw()
if self.visible == false then
return
end
-- skin variables
local index = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
loveframes.drawcount = loveframes.drawcount + 1
self.draworder = loveframes.drawcount
if self.Draw ~= nil then
self.Draw(self)
else
skin.DrawScrollArea(self)
end
for k, v in ipairs(self.internals) do
v:draw()
end
end
function scrollarea:mousepressed(x, y, button)
if self.visible == false then
return
end
local listo = self.parent.parent
local time = love.timer.getTime()
if self.hover == true and button == "l" then
self.down = true
self.scrolldelay = time + self.delayamount + 0.5
if listo.display == "vertical" then
if y > self.internals[1].y then
self.internals[1]:Scroll(self.internals[1].height)
else
self.internals[1]:Scroll(-self.internals[1].height)
end
elseif listo.display == "horizontal" then
if x > self.internals[1].x then
self.internals[1]:Scroll(self.internals[1].width)
else
self.internals[1]:Scroll(-self.internals[1].width)
end
end
end
for k, v in ipairs(self.internals) do
v:mousepressed(x, y, button)
end
end
function scrollarea:mousereleased(x, y, button)
if self.visible == false then
return
end
if button == "l" then
self.down = false
end
for k, v in ipairs(self.internals) do
v:mousereleased(x, y, button)
end
end

View File

@ -0,0 +1,283 @@
--[[------------------------------------------------
-- LÖVE Frames --
-- By Nikolai Resokav --
--]]------------------------------------------------
-- scrollbar class
scrollbar = class("scrollbar", base)
function scrollbar: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
end
function scrollbar:update(dt)
local x, y = love.mouse.getPosition()
local bartype = self.bartype
local cols, basecols = {}, {}
if self.visible == false then
if self.alwaysupdate == false then
return
end
end
self:CheckHover()
if self.bartype == "vertical" then
self.width = self.parent.width
elseif self.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 self.dragging == true 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.extra * percent
listo.offsety = 0 + extra
if self.staticy > space then
self.staticy = space
listo.offsety = listo.extra
end
if self.staticy < 0 then
self.staticy = 0
listo.offsety = 0
end
if self.autoscroll == true then
if listo.itemheight ~= self.lastheight then
self.lastheight = listo.itemheight
self:Scroll(self.maxy)
end
end
elseif bartype == "horizontal" then
self.lastwidth = self.width
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 self.dragging == true 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.extra * percent
listo.offsetx = 0 + extra
if self.staticx > space then
self.staticx = space
listo.offsetx = listo.extra
end
if self.staticx < 0 then
self.staticx = 0
listo.offsetx = 0
end
if self.autoscroll == true then
if self.width ~= self.lastwidth then
self.width = self.width
self:Scroll(self.maxx)
end
end
end
if self.Update then
self.Update(self, dt)
end
end
function scrollbar:draw()
if self.visible == false then
return
end
-- skin variables
local index = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
loveframes.drawcount = loveframes.drawcount + 1
self.draworder = loveframes.drawcount
if self.Draw ~= nil then
self.Draw(self)
else
skin.DrawScrollBar(self)
end
end
function scrollbar:mousepressed(x, y, button)
if self.visible == false then
return
end
if self.hover == false then
return
end
local baseparent = self:GetBaseParent()
if baseparent.type == "frame" then
baseparent:MakeTop()
end
if self.dragging == false then
if button == "l" then
self.starty = self.staticy
self.startx = self.staticx
self.clickx = x
self.clicky = y
self.dragging = true
end
end
end
function scrollbar:mousereleased(x, y, button)
if self.visible == false then
return
end
if self.dragging == true then
self.dragging = false
end
end
function scrollbar:SetMaxX(x)
self.maxx = x
end
function scrollbar:SetMaxY(y)
self.maxy = y
end
function scrollbar:Scroll(amount)
local bartype = self.bartype
local listo = self.parent.parent.parent
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 listo.OnScroll then
listo.OnScroll(listo)
end
end

View File

@ -0,0 +1,164 @@
--[[------------------------------------------------
-- LÖVE Frames --
-- By Nikolai Resokav --
--]]------------------------------------------------
-- scrollbar class
scrollbody = class("scrollbody", base)
function scrollbody:initialize(parent, bartype)
self.type = "scroll-body"
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, scrollarea:new(self, bartype))
local bar = self.internals[1].internals[1]
if self.bartype == "vertical" then
local upbutton = scrollbutton:new("up")
upbutton.parent = self
upbutton.Update = function(object, dt)
upbutton.staticx = 0 + self.width - upbutton.width
upbutton.staticy = 0
if object.down == true and object.hover == true then
bar:Scroll(-0.10)
end
end
local downbutton = scrollbutton:new("down")
downbutton.parent = self
downbutton.Update = function(object, dt)
downbutton.staticx = 0 + self.width - downbutton.width
downbutton.staticy = 0 + self.height - downbutton.height
if object.down == true and object.hover == true then
bar:Scroll(0.10)
end
end
table.insert(self.internals, upbutton)
table.insert(self.internals, downbutton)
elseif self.bartype == "horizontal" then
local leftbutton = scrollbutton:new("left")
leftbutton.parent = self
leftbutton.Update = function(object, dt)
leftbutton.staticx = 0
leftbutton.staticy = 0
if object.down == true and object.hover == true then
bar:Scroll(-0.10)
end
end
local rightbutton = scrollbutton:new("right")
rightbutton.parent = self
rightbutton.Update = function(object, dt)
rightbutton.staticx = 0 + self.width - rightbutton.width
rightbutton.staticy = 0
if object.down == true and object.hover == true then
bar:Scroll(0.10)
end
end
table.insert(self.internals, leftbutton)
table.insert(self.internals, rightbutton)
end
end
function scrollbody:update(dt)
if self.visible == false then
if self.alwaysupdate == false then
return
end
end
-- move to parent if there is a parent
if self.parent ~= loveframes.base then
self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy
end
self:CheckHover()
for k, v in ipairs(self.internals) do
v:update(dt)
end
if self.Update then
self.Update(self, dt)
end
end
function scrollbody:draw()
if self.visible == false then
return
end
-- skin variables
local index = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
loveframes.drawcount = loveframes.drawcount + 1
self.draworder = loveframes.drawcount
if self.Draw ~= nil then
self.Draw(self)
else
skin.DrawScrollBody(self)
end
for k, v in ipairs(self.internals) do
v:draw()
end
end
function scrollbody:mousepressed(x, y, button)
if self.visible == false then
return
end
for k, v in ipairs(self.internals) do
v:mousepressed(x, y, button)
end
end
function scrollbody:mousereleased(x, y, button)
if self.visible == false then
return
end
for k, v in ipairs(self.internals) do
v:mousereleased(x, y, button)
end
end

View File

@ -0,0 +1,134 @@
--[[------------------------------------------------
-- LÖVE Frames --
-- By Nikolai Resokav --
--]]------------------------------------------------
-- scrollbutton clas
scrollbutton = class("scrollbutton", base)
scrollbutton:include(loveframes.templates.default)
--[[---------------------------------------------------------
- func: initialize()
- desc: initializes the object
--]]---------------------------------------------------------
function scrollbutton:initialize(scrolltype)
self.type = "scrollbutton"
self.scrolltype = scrolltype
self.width = 16
self.height = 16
self.down = false
self.internal = true
self.OnClick = function() end
end
--[[---------------------------------------------------------
- func: update(deltatime)
- desc: updates the object
--]]---------------------------------------------------------
function scrollbutton:update(dt)
if self.visible == false then
if self.alwaysupdate == false then
return
end
end
self:CheckHover()
-- move to parent if there is a parent
if self.parent ~= loveframes.base then
self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy
end
if self.Update then
self.Update(self, dt)
end
end
--[[---------------------------------------------------------
- func: draw()
- desc: draws the object
--]]---------------------------------------------------------
function scrollbutton:draw()
if self.visible == false then
return
end
loveframes.drawcount = loveframes.drawcount + 1
self.draworder = loveframes.drawcount
-- skin variables
local index = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
if self.Draw ~= nil then
self.Draw(self)
else
skin.DrawScrollButton(self)
end
end
--[[---------------------------------------------------------
- func: mousepressed(x, y, scrollbutton)
- desc: called when the player presses a mouse button
--]]---------------------------------------------------------
function scrollbutton:mousepressed(x, y, scrollbutton)
if self.visible == false then
return
end
if self.hover == true then
local baseparent = self:GetBaseParent()
if baseparent.type == "frame" then
baseparent:MakeTop()
end
self.down = true
end
end
--[[---------------------------------------------------------
- func: mousereleased(x, y, scrollbutton)
- desc: called when the player releases a mouse button
--]]---------------------------------------------------------
function scrollbutton:mousereleased(x, y, scrollbutton)
if self.visible == false then
return
end
if self.hover == true and self.down == true then
if scrollbutton == "l" then
self.OnClick(x, y, self)
end
end
self.down = false
end
--[[---------------------------------------------------------
- func: SetText(text)
- desc: sets the object's text
--]]---------------------------------------------------------
function scrollbutton:SetText(text)
return
end

View File

@ -0,0 +1,155 @@
--[[------------------------------------------------
-- LÖVE Frames --
-- By Nikolai Resokav --
--]]------------------------------------------------
-- closebutton clas
sliderbutton = class("sliderbutton", base)
sliderbutton:include(loveframes.templates.default)
--[[---------------------------------------------------------
- func: initialize()
- desc: initializes the object
--]]---------------------------------------------------------
function sliderbutton:initialize(parent)
self.type = "sliderbutton"
self.width = 10
self.height = 20
self.staticx = 0
self.staticy = 0
self.startx = 0
self.clickx = 0
self.intervals = true
self.internal = true
self.down = false
self.dragging = false
self.parent = parent
self:SetY(self.parent.ycenter - self.height/2)
end
--[[---------------------------------------------------------
- func: update(deltatime)
- desc: updates the object
--]]---------------------------------------------------------
function sliderbutton:update(dt)
if self.visible == false then
if self.alwaysupdate == false then
return
end
end
local x, y = love.mouse.getPosition()
local intervals = self.intervals
self:CheckHover()
-- move to parent if there is a parent
if self.parent ~= loveframes.base then
self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy
end
if self.dragging == true then
self.staticx = self.startx + (x - self.clickx)
end
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
local progress = loveframes.util.Round(self.staticx/(self.parent.width - self.width), 5)
local nvalue = self.parent.min + (self.parent.max - self.parent.min) * progress
local pvalue = self.parent.value
if nvalue ~= pvalue then
self.parent.value = loveframes.util.Round(nvalue, self.parent.decimals)
self.parent.OnValueChanged(self.parent, self.parent.value)
end
if self.Update then
self.Update(self, dt)
end
end
--[[---------------------------------------------------------
- func: draw()
- desc: draws the object
--]]---------------------------------------------------------
function sliderbutton:draw()
if self.visible == false then
return
end
loveframes.drawcount = loveframes.drawcount + 1
self.draworder = loveframes.drawcount
-- skin variables
local index = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
if self.Draw ~= nil then
self.Draw(self)
else
skin.DrawSliderButton(self)
end
end
--[[---------------------------------------------------------
- func: mousepressed(x, y, button)
- desc: called when the player presses a mouse button
--]]---------------------------------------------------------
function sliderbutton:mousepressed(x, y, button)
if self.visible == false then
return
end
if self.hover == true and button == "l" 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
end
end
--[[---------------------------------------------------------
- func: mousereleased(x, y, button)
- desc: called when the player releases a mouse button
--]]---------------------------------------------------------
function sliderbutton:mousereleased(x, y, button)
if self.visible == false then
return
end
self.down = false
self.dragging = false
end
function sliderbutton:MoveToX(x)
self.staticx = x
end

View File

@ -0,0 +1,171 @@
--[[------------------------------------------------
-- LÖVE Frames --
-- By Nikolai Resokav --
--]]------------------------------------------------
-- tabbutton clas
tabbutton = class("tabbutton", base)
tabbutton:include(loveframes.templates.default)
--[[---------------------------------------------------------
- func: initialize()
- desc: initializes the object
--]]---------------------------------------------------------
function tabbutton:initialize(parent, text, tabnumber, tip, image)
self.type = "tabbutton"
self.text = text
self.tabnumber = tabnumber
self.parent = parent
self.staticx = 0
self.staticy = 0
self.width = 50
self.height = 25
self.internal = true
self.down = false
self.image = nil
if tip then
local tooltip = tooltip:new(self, tip)
tooltip:SetFollowCursor(false)
end
if image then
self:SetImage(image)
end
end
--[[---------------------------------------------------------
- func: update(deltatime)
- desc: updates the object
--]]---------------------------------------------------------
function tabbutton:update(dt)
if self.visible == false then
if self.alwaysupdate == false then
return
end
end
self:CheckHover()
self:SetClickBounds(self.parent.x, self.parent.y, self.parent.width, self.parent.height)
-- move to parent if there is a parent
if self.parent ~= loveframes.base then
self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy
end
if self.Update then
self.Update(self, dt)
end
end
--[[---------------------------------------------------------
- func: draw()
- desc: draws the object
--]]---------------------------------------------------------
function tabbutton:draw()
if self.visible == false then
return
end
loveframes.drawcount = loveframes.drawcount + 1
self.draworder = loveframes.drawcount
-- skin variables
local index = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
if self.Draw ~= nil then
self.Draw(self)
else
skin.DrawTabButton(self)
end
local font = love.graphics.getFont()
local width = font:getWidth(self.text)
local image = self.image
if image then
local imagewidth = image:getWidth()
self.width = imagewidth + 15 + width
else
self.width = 10 + width
end
end
--[[---------------------------------------------------------
- func: mousepressed(x, y, button)
- desc: called when the player presses a mouse button
--]]---------------------------------------------------------
function tabbutton:mousepressed(x, y, button)
if self.visible == false then
return
end
if self.hover == true and button == "l" then
local baseparent = self:GetBaseParent()
if baseparent and baseparent.type == "frame" then
baseparent:MakeTop()
end
self.down = true
end
end
--[[---------------------------------------------------------
- func: mousereleased(x, y, button)
- desc: called when the player releases a mouse button
--]]---------------------------------------------------------
function tabbutton:mousereleased(x, y, button)
if self.visible == false then
return
end
local pinternals = self.parent.internals
if self.hover == true and self.down == true then
if button == "l" then
self.parent:SwitchToTab(self.tabnumber)
end
end
self.down = false
end
--[[---------------------------------------------------------
- func: SetText(text)
- desc: sets the object's text
--]]---------------------------------------------------------
function tabbutton:SetText(text)
self.text = text
end
--[[---------------------------------------------------------
- func: SetImage(image)
- desc: adds an image to the object
--]]---------------------------------------------------------
function tabbutton:SetImage(image)
self.image = image
end

View File

@ -0,0 +1,231 @@
--[[------------------------------------------------
-- LÖVE Frames --
-- By Nikolai Resokav --
--]]------------------------------------------------
-- tooltip clas
tooltip = class("tooltip", base)
tooltip:include(loveframes.templates.default)
--[[---------------------------------------------------------
- func: initialize()
- desc: initializes the object
--]]---------------------------------------------------------
function tooltip:initialize(object, text, width)
local width = width or 0
self.type = "tooltip"
self.parent = loveframes.base
self.object = object or nil
self.width = width or 0
self.height = 0
self.padding = 5
self.xoffset = 0
self.yoffset = 0
self.internal = true
self.show = false
self.followcursor = true
self.alwaysupdate = true
self.text = loveframes.Create("text")
self.text:Remove()
self.text.parent = self
self.text:SetText(text or "")
self.text:SetWidth(width or 0)
self.text:SetPos(0, 0)
table.insert(loveframes.base.children, self)
end
--[[---------------------------------------------------------
- func: update(deltatime)
- desc: updates the object
--]]---------------------------------------------------------
function tooltip:update(dt)
if self.visible == false then
if self.alwaysupdate == false then
return
end
end
self.width = self.text.width + self.padding*2
self.height = self.text.height + self.padding*2
local object = self.object
local draworder = self.draworder
if object then
local hover = object.hover
local odraworder = object.draworder
self.show = object.hover
self.visible = self.show
local show = self.show
if show == true then
if self.followcursor == true then
local x, y = love.mouse.getPosition()
local top = self:IsTopChild()
self.x = x + self.xoffset
self.y = y - self.height + self.yoffset
else
self.x = object.x + self.xoffset
self.y = object.y - self.height + self.yoffset
end
if top == false then
self:MoveToTop()
end
self.text:SetPos(self.padding, self.padding)
end
if odraworder > draworder then
self:Remove()
table.insert(loveframes.base.children, self)
end
end
self.text:update(dt)
if self.Update then
self.Update(self, dt)
end
end
--[[---------------------------------------------------------
- func: draw()
- desc: draws the object
--]]---------------------------------------------------------
function tooltip:draw()
if self.visible == false then
return
end
loveframes.drawcount = loveframes.drawcount + 1
self.draworder = loveframes.drawcount
-- skin variables
local index = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
if self.show == true then
if self.Draw ~= nil then
self.Draw(self)
else
skin.DrawToolTip(self)
end
self.text:draw()
end
end
--[[---------------------------------------------------------
- func: mousepressed(x, y, button)
- desc: called when the player presses a mouse button
--]]---------------------------------------------------------
function tooltip:mousepressed(x, y, button)
if self.visible == false then
return
end
end
--[[---------------------------------------------------------
- func: mousereleased(x, y, button)
- desc: called when the player releases a mouse button
--]]---------------------------------------------------------
function tooltip:mousereleased(x, y, button)
if self.visible == false then
return
end
end
--[[---------------------------------------------------------
- func: SetFollowCursor(bool)
- desc: sets whether or not the tooltip should follow the
cursor
--]]---------------------------------------------------------
function tooltip:SetFollowCursor(bool)
self.followcursor = bool
end
--[[---------------------------------------------------------
- func: SetObject(object)
- desc: sets the tooltip's object
--]]---------------------------------------------------------
function tooltip:SetObject(object)
self.object = object
end
--[[---------------------------------------------------------
- func: SetText(text)
- desc: sets the tooltip's text
--]]---------------------------------------------------------
function tooltip:SetText(text)
self.text:SetText(text)
end
--[[---------------------------------------------------------
- func: SetTextMaxWidth(text)
- desc: sets the tooltip's text max width
--]]---------------------------------------------------------
function tooltip:SetTextMaxWidth(width)
self.text:SetMaxWidth(width)
end
--[[---------------------------------------------------------
- func: SetOffsets(xoffset, yoffset)
- desc: sets the tooltip's x and y offset
--]]---------------------------------------------------------
function tooltip:SetOffsets(xoffset, yoffset)
self.xoffset = xoffset
self.yoffset = yoffset
end
--[[---------------------------------------------------------
- func: SetPadding(padding)
- desc: sets the tooltip's padding
--]]---------------------------------------------------------
function tooltip:SetPadding(padding)
self.padding = padding
end
--[[---------------------------------------------------------
- func: SetFont(font)
- desc: sets the tooltip's font
--]]---------------------------------------------------------
function tooltip:SetFont(font)
self.text:SetFont(font)
end

518
objects/list.lua Normal file
View File

@ -0,0 +1,518 @@
--[[------------------------------------------------
-- LÖVE Frames --
-- By Nikolai Resokav --
--]]------------------------------------------------
-- list class
list = class("list", base)
list:include(loveframes.templates.default)
--[[---------------------------------------------------------
- func: initialize()
- desc: initializes the object
--]]---------------------------------------------------------
function list: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.extra = 0
self.internal = false
self.hbar = false
self.vbar = false
self.autoscroll = false
self.internals = {}
self.children = {}
self.OnScroll = nil
end
--[[---------------------------------------------------------
- func: update(deltatime)
- desc: updates the object
--]]---------------------------------------------------------
function list:update(dt)
if self.visible == false then
if self.alwaysupdate == false then
return
end
end
-- move to parent if there is a parent
if self.parent ~= loveframes.base then
self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy
end
self:CheckHover()
for k, v in ipairs(self.internals) do
v:update(dt)
end
for k, v in ipairs(self.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
if self.display == "vertical" then
if v.lastheight ~= v.height then
self:CalculateSize()
self:RedoLayout()
end
end
end
if self.Update then
self.Update(self, dt)
end
end
--[[---------------------------------------------------------
- func: draw()
- desc: draws the object
--]]---------------------------------------------------------
function list:draw()
if self.visible == false then
return
end
loveframes.drawcount = loveframes.drawcount + 1
self.draworder = loveframes.drawcount
-- skin variables
local index = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
if self.Draw ~= nil then
self.Draw(self)
else
skin.DrawList(self)
end
local stencilfunc = function() love.graphics.rectangle("fill", self.x, self.y, self.width, self.height) end
local stencil = love.graphics.newStencil(stencilfunc)
love.graphics.setStencil(stencil)
for k, v in ipairs(self.children) do
local col = loveframes.util.BoundingBox(self.x, v.x, self.y, v.y, self.width, v.width, self.height, v.height)
if col == true then
v:draw()
end
end
love.graphics.setStencil()
for k, v in ipairs(self.internals) do
v:draw()
end
if self.Draw == nil then
skin.DrawOverList(self)
end
end
--[[---------------------------------------------------------
- func: mousepressed(x, y, button)
- desc: called when the player presses a mouse button
--]]---------------------------------------------------------
function list:mousepressed(x, y, button)
if self.visible == false then
return
end
local toplist = self:IsTopList()
if self.hover == true and button == "l" then
local baseparent = self:GetBaseParent()
if baseparent and baseparent.type == "frame" then
baseparent:MakeTop()
end
end
if self.vbar == true or self.hbar == true then
if toplist == true then
local bar = self:GetScrollBar()
if button == "wu" then
bar:Scroll(-5)
elseif button == "wd" then
bar:Scroll(5)
end
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 list:mousereleased(x, y, button)
if self.visible == false 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: AddItem(object)
- desc: adds an item to the object
--]]---------------------------------------------------------
function list:AddItem(object)
if object.type == "frame" then
return
end
object:Remove()
object.parent = self
table.insert(self.children, object)
self:CalculateSize()
self:RedoLayout()
end
--[[---------------------------------------------------------
- func: RemoveItem(object)
- desc: removes an item from the object
--]]---------------------------------------------------------
function list:RemoveItem(object)
object:Remove()
self:CalculateSize()
self:RedoLayout()
end
--[[---------------------------------------------------------
- func: CalculateSize()
- desc: calculates the size of the object's children
--]]---------------------------------------------------------
function list: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
if display == "vertical" then
for k, v in ipairs(self.children) do
itemheight = itemheight + v.height + spacing
end
self.itemheight = (itemheight - spacing) + padding
if self.itemheight > height then
self.extra = self.itemheight - height
if vbar == false then
table.insert(self.internals, scrollbody:new(self, display))
self:GetScrollBar().autoscroll = self.autoscroll
self.vbar = true
end
else
if vbar == true then
self.internals[1]:Remove()
self.vbar = false
self.offsety = 0
end
end
elseif display == "horizontal" then
for k, v in ipairs(self.children) do
itemwidth = itemwidth + v.width + spacing
end
self.itemwidth = (itemwidth - spacing) + padding
if self.itemwidth > width then
self.extra = self.itemwidth - width
if hbar == false then
table.insert(self.internals, scrollbody:new(self, display))
self:GetScrollBar().autoscroll = self.autoscroll
self.hbar = true
end
else
if hbar == true then
self.internals[1]:Remove()
self.hbar = false
self.offsetx = 0
end
end
end
end
--[[---------------------------------------------------------
- func: RedoLayout()
- desc: used to redo the layour of the object
--]]---------------------------------------------------------
function list:RedoLayout()
local children = self.children
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
if #children > 0 then
for k, v in ipairs(children) do
if display == "vertical" then
local height = v.height
v.staticx = padding
v.staticy = starty
v.lastheight = v.height
if vbar == true then
if v.width + padding > (self.width - self.internals[1].width) then
v:SetWidth((self.width - self.internals[1].width) - padding*2)
end
if v.retainsize == false then
v:SetWidth((self.width - self.internals[1].width) - padding*2)
end
self.internals[1].staticx = self.width - self.internals[1].width
self.internals[1].height = self.height
else
if v.retainsize == false then
v:SetWidth(self.width - padding*2)
end
end
starty = starty + v.height
starty = starty + spacing
elseif display == "horizontal" then
v.staticx = startx
v.staticy = padding
if hbar == true then
if v.height + padding > (self.height - self.internals[1].height) then
v:SetHeight((self.height - self.internals[1].height) - padding*2)
end
if v.retainsize == false then
v:SetHeight((self.height - self.internals[1].height) - padding*2)
end
self.internals[1].staticy = self.height - self.internals[1].height
self.internals[1].width = self.width
else
if v.retainsize == false then
v:SetHeight(self.height - padding*2)
end
end
startx = startx + v.width
startx = startx + spacing
end
end
end
end
--[[---------------------------------------------------------
- func: SetDisplayType(type)
- desc: sets the object's display type
--]]---------------------------------------------------------
function list:SetDisplayType(type)
self.display = type
self.internals = {}
self.vbar = false
self.hbar = false
self.offsetx = 0
self.offsety = 0
if #self.children > 0 then
self:CalculateSize()
self:RedoLayout()
end
end
--[[---------------------------------------------------------
- func: GetDisplayType()
- desc: gets the object's display type
--]]---------------------------------------------------------
function list:GetDisplayType()
return self.display
end
--[[---------------------------------------------------------
- func: SetPadding(amount)
- desc: sets the object's padding
--]]---------------------------------------------------------
function list:SetPadding(amount)
self.padding = amount
if #self.children > 0 then
self:CalculateSize()
self:RedoLayout()
end
end
--[[---------------------------------------------------------
- func: SetSpacing(amount)
- desc: sets the object's spacing
--]]---------------------------------------------------------
function list:SetSpacing(amount)
self.spacing = amount
if #self.children > 0 then
self:CalculateSize()
self:RedoLayout()
end
end
--[[---------------------------------------------------------
- func: Clear()
- desc: removes all of the object's children
--]]---------------------------------------------------------
function list:Clear()
self.children = {}
self:CalculateSize()
self:RedoLayout()
end
--[[---------------------------------------------------------
- func: SetWidth(width)
- desc: sets the object's width
--]]---------------------------------------------------------
function list:SetWidth(width)
self.width = width
self:CalculateSize()
self:RedoLayout()
end
--[[---------------------------------------------------------
- func: SetHeight(height)
- desc: sets the object's height
--]]---------------------------------------------------------
function list:SetHeight(height)
self.height = height
self:CalculateSize()
self:RedoLayout()
end
--[[---------------------------------------------------------
- func: GetSize()
- desc: gets the object's size
--]]---------------------------------------------------------
function list:SetSize(width, height)
self.width = width
self.height = height
self:CalculateSize()
self:RedoLayout()
end
--[[---------------------------------------------------------
- func: GetScrollBar()
- desc: gets the object's scroll bar
--]]---------------------------------------------------------
function list:GetScrollBar()
return self.internals[1].internals[1].internals[1]
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 list:SetAutoScroll(bool)
self.autoscroll = bool
end

204
objects/multichoice.lua Normal file
View File

@ -0,0 +1,204 @@
--[[------------------------------------------------
-- LÖVE Frames --
-- By Nikolai Resokav --
--]]------------------------------------------------
-- progress bar class
multichoice = class("multichoice", base)
multichoice:include(loveframes.templates.default)
--[[---------------------------------------------------------
- func: initialize()
- desc: initializes the object
--]]---------------------------------------------------------
function multichoice:initialize()
self.type = "multichoice"
self.choice = ""
self.text = "Select an option"
self.width = 200
self.height = 25
self.listpadding = 0
self.listspacing = 0
self.listheight = nil
self.haslist = false
self.internal = false
self.choices = {}
end
--[[---------------------------------------------------------
- func: update(deltatime)
- desc: updates the object
--]]---------------------------------------------------------
function multichoice:update(dt)
if self.visible == false then
if self.alwaysupdate == false then
return
end
end
self:CheckHover()
-- move to parent if there is a parent
if self.parent ~= nil then
self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy
end
if self.Update then
self.Update(self, dt)
end
end
--[[---------------------------------------------------------
- func: draw()
- desc: draws the object
--]]---------------------------------------------------------
function multichoice:draw()
if self.visible == false then
return
end
-- skin variables
local index = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
loveframes.drawcount = loveframes.drawcount + 1
self.draworder = loveframes.drawcount
if self.Draw ~= nil then
self.Draw(self)
else
skin.DrawMultiChoice(self)
end
end
--[[---------------------------------------------------------
- func: mousepressed(x, y, button)
- desc: called when the player presses a mouse button
--]]---------------------------------------------------------
function multichoice:mousepressed(x, y, button)
if self.visible == false then
return
end
if self.hover == true and self.haslist == false and button == "l" then
local baseparent = self:GetBaseParent()
if baseparent and baseparent.type == "frame" then
baseparent:MakeTop()
end
self.haslist = true
self.list = multichoicelist:new(self)
end
end
--[[---------------------------------------------------------
- func: mousereleased(x, y, button)
- desc: called when the player releases a mouse button
--]]---------------------------------------------------------
function multichoice:mousereleased(x, y, button)
if self.visible == false then
return
end
end
--[[---------------------------------------------------------
- func: AddChoice(choice)
- desc: adds a choice to the current list of choices
--]]---------------------------------------------------------
function multichoice:AddChoice(choice)
table.insert(self.choices, choice)
end
--[[---------------------------------------------------------
- func: SetChoice(choice)
- desc: sets the current choice
--]]---------------------------------------------------------
function multichoice:SetChoice(choice)
self.choice = choice
end
--[[---------------------------------------------------------
- func: SelectChoice(choice)
- desc: selects a choice
--]]---------------------------------------------------------
function multichoice:SelectChoice(choice)
self.choice = choice
self.list:Close()
if self.OnChoiceSelected then
self.OnChoiceSelected(self, choice)
end
end
--[[---------------------------------------------------------
- func: SetListHeight(height)
- desc: sets the height of the list of choices
--]]---------------------------------------------------------
function multichoice:SetListHeight(height)
self.listheight = height
end
--[[---------------------------------------------------------
- func: SetPadding(padding)
- desc: sets the padding of the list of choices
--]]---------------------------------------------------------
function multichoice:SetPadding(padding)
self.listpadding = padding
end
--[[---------------------------------------------------------
- func: SetSpacing(spacing)
- desc: sets the spacing of the list of choices
--]]---------------------------------------------------------
function multichoice:SetSpacing(spacing)
self.listspacing = spacing
end
--[[---------------------------------------------------------
- func: GetValue()
- desc: gets the value (choice) of the object
--]]---------------------------------------------------------
function multichoice:GetValue()
return self.choice
end
--[[---------------------------------------------------------
- func: GetChoice()
- desc: gets the current choice (same as get value)
--]]---------------------------------------------------------
function multichoice:GetChoice()
return self.choice
end

126
objects/panel.lua Normal file
View File

@ -0,0 +1,126 @@
--[[------------------------------------------------
-- LÖVE Frames --
-- By Nikolai Resokav --
--]]------------------------------------------------
-- panel class
panel = class("panel", base)
panel:include(loveframes.templates.default)
--[[---------------------------------------------------------
- func: initialize()
- desc: initializes the object
--]]---------------------------------------------------------
function panel:initialize()
self.type = "panel"
self.width = 200
self.height = 50
self.internal = false
self.children = {}
end
--[[---------------------------------------------------------
- func: update(deltatime)
- desc: updates the element
--]]---------------------------------------------------------
function panel:update(dt)
if self.visible == false then
if self.alwaysupdate == false then
return
end
end
-- move to parent if there is a parent
if self.parent ~= loveframes.base and self.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(self.children) do
v:update(dt)
end
if self.Update then
self.Update(self, dt)
end
end
--[[---------------------------------------------------------
- func: draw()
- desc: draws the object
--]]---------------------------------------------------------
function panel:draw()
if self.visible == false then
return
end
-- skin variables
local index = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
loveframes.drawcount = loveframes.drawcount + 1
self.draworder = loveframes.drawcount
if self.Draw ~= nil then
self.Draw(self)
else
skin.DrawPanel(self)
end
-- loop through the object's children and draw them
for k, v in ipairs(self.children) do
v:draw()
end
end
--[[---------------------------------------------------------
- func: mousepressed(x, y, button)
- desc: called when the player presses a mouse button
--]]---------------------------------------------------------
function panel:mousepressed(x, y, button)
if self.visible == false then
return
end
if self.hover == true and button == "l" then
local baseparent = self:GetBaseParent()
if baseparent and baseparent.type == "frame" then
baseparent:MakeTop()
end
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 panel:mousereleased(x, y, button)
if self.visible == false then
return
end
for k, v in ipairs(self.children) do
v:mousereleased(x, y, button)
end
end

279
objects/progressbar.lua Normal file
View File

@ -0,0 +1,279 @@
--[[------------------------------------------------
-- LÖVE Frames --
-- By Nikolai Resokav --
--]]------------------------------------------------
-- progress bar class
progressbar = class("progressbar", base)
progressbar:include(loveframes.templates.default)
--[[---------------------------------------------------------
- func: initialize()
- desc: initializes the object
--]]---------------------------------------------------------
function progressbar:initialize()
self.type = "progressbar"
self.width = 100
self.height = 25
self.min = 0
self.max = 10
self.value = 0
self.progress = 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
end
--[[---------------------------------------------------------
- func: update(deltatime)
- desc: updates the object
--]]---------------------------------------------------------
function progressbar:update(dt)
if self.visible == false then
if self.alwaysupdate == false 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
self:CheckHover()
-- caclulate progress
if lerp == true 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.progress = 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.progress = self.value/self.max * self.width
-- min check
if self.value < self.min then
self.value = self.min
end
-- max check
if self.value > self.max then
self.value = self.max
end
end
-- move to parent if there is a parent
if self.parent ~= nil then
self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy
end
-- completion check
if self.completed == false then
if self.value >= self.max then
self.completed = true
if self.OnComplete then
self.OnComplete(self)
end
end
end
if self.Update then
self.Update(self, dt)
end
end
--[[---------------------------------------------------------
- func: draw()
- desc: draws the object
--]]---------------------------------------------------------
function progressbar:draw()
if self.visible == false then
return
end
-- skin variables
local index = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
loveframes.drawcount = loveframes.drawcount + 1
self.draworder = loveframes.drawcount
if self.Draw ~= nil then
self.Draw(self)
else
skin.DrawProgressBar(self)
end
end
--[[---------------------------------------------------------
- func: SetMax(max)
- desc: sets the object's maximum value
--]]---------------------------------------------------------
function progressbar:SetMax(max)
self.max = max
end
--[[---------------------------------------------------------
- func: GetMax()
- desc: gets the object's maximum value
--]]---------------------------------------------------------
function progressbar:GetMax()
return self.max
end
--[[---------------------------------------------------------
- func: SetMin(min)
- desc: sets the object's minimum value
--]]---------------------------------------------------------
function progressbar:SetMin(min)
self.min = min
end
--[[---------------------------------------------------------
- func: GetMin()
- desc: gets the object's minimum value
--]]---------------------------------------------------------
function progressbar:GetMin()
return self.min
end
--[[---------------------------------------------------------
- func: SetMinMax()
- desc: sets the object's minimum and maximum values
--]]---------------------------------------------------------
function progressbar:SetMinMax(min, max)
self.min = min
self.max = max
end
--[[---------------------------------------------------------
- func: GetMinMax()
- desc: gets the object's minimum and maximum values
--]]---------------------------------------------------------
function progressbar:GetMinMax()
return self.min, self.max
end
--[[---------------------------------------------------------
- func: SetValue(value)
- desc: sets the object's value
--]]---------------------------------------------------------
function progressbar:SetValue(value)
local lerp = self.lerp
if lerp == true then
self.lerpvalue = self.lerpvalue
self.lerpto = value
self.lerpfrom = self.lerpvalue
self.value = value
else
self.value = value
end
end
--[[---------------------------------------------------------
- func: GetValue()
- desc: gets the object's value
--]]---------------------------------------------------------
function progressbar:GetValue()
return self.value
end
--[[---------------------------------------------------------
- func: SetLerp(bool)
- desc: sets whether or not the object should lerp
when changing between values
--]]---------------------------------------------------------
function progressbar:SetLerp(bool)
self.lerp = bool
self.lerpto = self:GetValue()
self.lerpvalue = self:GetValue()
end
--[[---------------------------------------------------------
- func: GetLerp()
- desc: gets whether or not the object should lerp
when changing between values
--]]---------------------------------------------------------
function progressbar:GetLerp()
return self.lerp
end
--[[---------------------------------------------------------
- func: SetLerpRate(rate)
- desc: sets the object's lerp rate
--]]---------------------------------------------------------
function progressbar:SetLerpRate(rate)
self.lerprate = rate
end
--[[---------------------------------------------------------
- func: GetLerpRate()
- desc: gets the object's lerp rate
--]]---------------------------------------------------------
function progressbar:GetLerpRate()
return self.lerprate
end

308
objects/slider.lua Normal file
View File

@ -0,0 +1,308 @@
--[[------------------------------------------------
-- LÖVE Frames --
-- By Nikolai Resokav --
--]]------------------------------------------------
-- text clas
slider = class("slider", base)
slider:include(loveframes.templates.default)
--[[---------------------------------------------------------
- func: initialize()
- desc: initializes the object
--]]---------------------------------------------------------
function slider:initialize()
self.type = "slider"
self.text = "Slider"
self.width = 200
self.height = 35
self.max = 10
self.min = 0
self.value = 0
self.ycenter = 25
self.decimals = 5
self.internal = false
self.internals = {}
self.OnValueChanged = nil
-- create the slider button
table.insert(self.internals, sliderbutton:new(self))
-- set initial value to minimum
self:SetValue(self.min)
end
--[[---------------------------------------------------------
- func: update(deltatime)
- desc: updates the object
--]]---------------------------------------------------------
function slider:update(dt)
if self.visible == false then
if self.alwaysupdate == false then
return
end
end
self:CheckHover()
-- move to parent if there is a parent
if self.parent ~= loveframes.base then
self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy
end
-- update internals
for k, v in ipairs(self.internals) do
v:update(dt)
end
if self.Update then
self.Update(self, dt)
end
end
--[[---------------------------------------------------------
- func: draw()
- desc: draws the object
--]]---------------------------------------------------------
function slider:draw()
if self.visible == false then
return
end
loveframes.drawcount = loveframes.drawcount + 1
self.draworder = loveframes.drawcount
-- skin variables
local index = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
if self.Draw ~= nil then
self.Draw(self)
else
skin.DrawSlider(self)
end
-- draw internals
for k, v in ipairs(self.internals) do
v:draw()
end
end
--[[---------------------------------------------------------
- func: mousepressed(x, y, button)
- desc: called when the player presses a mouse button
--]]---------------------------------------------------------
function slider:mousepressed(x, y, button)
if self.visible == false then
return
end
if self.hover == true and button == "l" then
local xpos = x - self.x
local button = self.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
end
for k, v in ipairs(self.internals) do
v:mousepressed(x, y, button)
end
end
--[[---------------------------------------------------------
- func: mousereleased(x, y, button)
- desc: called when the player releases a mouse button
--]]---------------------------------------------------------
function slider:mousereleased(x, y, button)
if self.visible == false then
return
end
for k, v in ipairs(self.internals) do
v:mousereleased(x, y, button)
end
end
--[[---------------------------------------------------------
- func: SetValue(value)
- desc: sets the object's value
--]]---------------------------------------------------------
function slider:SetValue(value)
if value > self.max then
return
end
if value < self.min then
return
end
local decimals = self.decimals
local newval = loveframes.util.Round(value, decimals)
-- set the new value
self.value = newval
-- slider button object
local button = self.internals[1]
-- new position for the slider button
local xpos = self.width * (( newval - self.min ) / (self.max - self.min))
-- move the slider button to the new position
button:MoveToX(xpos)
-- call OnValueChanged
if self.OnValueChanged then
self.OnValueChanged(self)
end
end
--[[---------------------------------------------------------
- func: GetValue()
- desc: gets the object's value
--]]---------------------------------------------------------
function slider:GetValue()
return self.value
end
--[[---------------------------------------------------------
- func: SetMax(max)
- desc: sets the object's maximum value
--]]---------------------------------------------------------
function slider:SetMax(max)
self.max = max
end
--[[---------------------------------------------------------
- func: GetMax()
- desc: gets the object's maximum value
--]]---------------------------------------------------------
function slider:GetMax()
return self.max
end
--[[---------------------------------------------------------
- func: SetMin(min)
- desc: sets the object's minimum value
--]]---------------------------------------------------------
function slider:SetMin(min)
self.min = min
end
--[[---------------------------------------------------------
- func: GetMin()
- desc: gets the object's minimum value
--]]---------------------------------------------------------
function slider:GetMin()
return self.min
end
--[[---------------------------------------------------------
- func: SetMinMax()
- desc: sets the object's minimum and maximum values
--]]---------------------------------------------------------
function slider:SetMinMax(min, max)
self.min = min
self.max = max
end
--[[---------------------------------------------------------
- func: GetMinMax()
- desc: gets the object's minimum and maximum values
--]]---------------------------------------------------------
function slider:GetMinMax()
return self.min, self.max
end
--[[---------------------------------------------------------
- func: SetButtonYCenter(y)
- desc: sets the object's y center for it's slider
button
--]]---------------------------------------------------------
function slider:SetButtonYCenter(y)
self.ycenter = y
end
--[[---------------------------------------------------------
- func: GetButtonYCenter()
- desc: get's the object's y center of it's slider
button
--]]---------------------------------------------------------
function slider:GetButtonYCenter()
return self.ycenter
end
--[[---------------------------------------------------------
- func: SetText(name)
- desc: sets the objects's text
--]]---------------------------------------------------------
function slider:SetText(text)
self.text = text
end
--[[---------------------------------------------------------
- func: GetText()
- desc: gets the objects's text
--]]---------------------------------------------------------
function slider:GetText()
return self.text
end
--[[---------------------------------------------------------
- func: SetDecimals(decimals)
- desc: sets the objects's decimals
--]]---------------------------------------------------------
function slider:SetDecimals(decimals)
self.decimals = decimals
end

372
objects/tabs.lua Normal file
View File

@ -0,0 +1,372 @@
--[[------------------------------------------------
-- LÖVE Frames --
-- By Nikolai Resokav --
--]]------------------------------------------------
-- tabs class
tabs = class("tabpanel", base)
tabs:include(loveframes.templates.default)
--[[---------------------------------------------------------
- func: initialize()
- desc: initializes the object
--]]---------------------------------------------------------
function tabs: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.autosize = true
self.internal = false
self.tabs = {}
self.internals = {}
self.children = {}
end
--[[---------------------------------------------------------
- func: update(deltatime)
- desc: updates the element
--]]---------------------------------------------------------
function tabs:update(dt)
local x, y = love.mouse.getPosition()
local tabheight = self.tabheight
local padding = self.padding
local autosize = self.autosize
local tabheight = self.tabheight
local padding = self.padding
local autosize = self.autosize
if self.visible == false then
if self.alwaysupdate == false then
return
end
end
-- move to parent if there is a parent
if self.parent ~= loveframes.base then
self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy
end
self:CheckHover()
if #self.children > 0 and self.tab == 0 then
self.tab = 1
end
local pos = 0
for k, v in ipairs(self.internals) do
v:update(dt)
if v.type == "tabbutton" then
v.y = (v.parent.y + v.staticy)
v.x = (v.parent.x + v.staticx) + pos + self.offsetx
pos = pos + v.width - 1
end
end
for k, v in ipairs(self.children) do
v:update(dt)
v:SetPos(padding, tabheight + padding)
end
if self.Update then
self.Update(self, dt)
end
end
--[[---------------------------------------------------------
- func: draw()
- desc: draws the object
--]]---------------------------------------------------------
function tabs:draw()
if self.visible == false then
return
end
loveframes.drawcount = loveframes.drawcount + 1
self.draworder = loveframes.drawcount
-- skin variables
local index = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
if self.Draw ~= nil then
self.Draw(self)
else
skin.DrawTabPanel(self)
end
local tabheight = self:GetHeightOfButtons()
local stencilfunc = function() love.graphics.rectangle("fill", self.x, self.y, self.width, tabheight) end
local stencil = love.graphics.newStencil(stencilfunc)
love.graphics.setStencil(stencil)
for k, v in ipairs(self.internals) do
v:draw()
end
love.graphics.setStencil()
if #self.children > 0 then
self.children[self.tab]:draw()
end
end
--[[---------------------------------------------------------
- func: mousepressed(x, y, button)
- desc: called when the player presses a mouse button
--]]---------------------------------------------------------
function tabs:mousepressed(x, y, button)
if self.visible == false then
return
end
if self.hover == true and button == "l" 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
if #self.children > 0 then
self.children[self.tab]:mousepressed(x, y, button)
end
end
--[[---------------------------------------------------------
- func: mousereleased(x, y, button)
- desc: called when the player releases a mouse button
--]]---------------------------------------------------------
function tabs:mousereleased(x, y, button)
if self.visible == false then
return
end
for k, v in ipairs(self.internals) do
v:mousereleased(x, y, button)
end
if #self.children > 0 then
self.children[self.tab]:mousereleased(x, y, button)
end
end
--[[---------------------------------------------------------
- func: AddTab(name, object, tip, image)
- desc: adds a new tab to the tab panel
--]]---------------------------------------------------------
function tabs:AddTab(name, object, tip, image)
local tabheight = self.tabheight
local padding = self.padding
local autosize = self.autosize
object:Remove()
object.parent = self
object.staticx = 0
object.staticy = 0
object:SetWidth(self.width - 10)
object:SetHeight(self.height - 35)
table.insert(self.children, object)
self.internals[self.tabnumber] = tabbutton:new(self, name, self.tabnumber, tip, image)
self.internals[self.tabnumber].height = self.tabheight
self.tabnumber = self.tabnumber + 1
for k, v in ipairs(self.internals) do
self:SwitchToTab(k)
break
end
self:AddScrollButtons()
if autosize == true and object.retainsize == false then
object:SetSize(self.width - padding*2, (self.height - tabheight) - padding*2)
end
end
--[[---------------------------------------------------------
- func: AddScrollButtons()
- desc: creates scroll buttons fot the tab panel
- note: for internal use only
--]]---------------------------------------------------------
function tabs:AddScrollButtons()
for k, v in ipairs(self.internals) do
if v.type == "scrollbutton" then
table.remove(self.internals, k)
end
end
local leftbutton = scrollbutton:new("left")
leftbutton.parent = self
leftbutton:SetPos(0, 0)
leftbutton:SetSize(15, 25)
leftbutton:SetAlwaysUpdate(true)
leftbutton.Update = function(object, dt)
if self.offsetx ~= 0 then
object.visible = true
else
object.visible = false
object.down = false
object.hover = false
end
if object.down == true then
if self.offsetx ~= 0 then
self.offsetx = self.offsetx + 1
end
end
end
local rightbutton = scrollbutton:new("right")
rightbutton.parent = self
rightbutton:SetPos(self.width - 15, 0)
rightbutton:SetSize(15, 25)
rightbutton:SetAlwaysUpdate(true)
rightbutton.Update = function(object, dt)
local bwidth = self:GetWidthOfButtons()
if (self.offsetx + bwidth) > self.width then
object.visible = true
else
object.visible = false
object.down = false
object.hover = false
end
if object.down == true then
if ((self.x + self.offsetx) + bwidth) ~= (self.x + self.width) then
self.offsetx = self.offsetx - 1
end
end
end
table.insert(self.internals, leftbutton)
table.insert(self.internals, rightbutton)
end
--[[---------------------------------------------------------
- func: GetWidthOfButtons()
- desc: gets the total width of all of the tab buttons
--]]---------------------------------------------------------
function tabs:GetWidthOfButtons()
local width = 0
for k, v in ipairs(self.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 tabs:GetHeightOfButtons()
return self.tabheight
end
--[[---------------------------------------------------------
- func: SwitchToTab(tabnumber)
- desc: makes the specified tab the active tab
--]]---------------------------------------------------------
function tabs:SwitchToTab(tabnumber)
for k, v in ipairs(self.children) do
v.visible = false
end
self.tab = tabnumber
self.children[self.tab].visible = true
end
--[[---------------------------------------------------------
- func: SetScrollButtonSize(width, height)
- desc: sets the size of the scroll buttons
--]]---------------------------------------------------------
function tabs:SetScrollButtonSize(width, height)
for k, v in ipairs(self.internals) do
if v.type == "scrollbutton" then
v:SetSize(width, height)
end
end
end
--[[---------------------------------------------------------
- func: SetPadding(paddint)
- desc: sets the padding for the tab panel
--]]---------------------------------------------------------
function tabs:SetPadding(padding)
self.padding = padding
end
--[[---------------------------------------------------------
- func: SetPadding(paddint)
- desc: gets the padding of the tab panel
--]]---------------------------------------------------------
function tabs:GetPadding()
return self.padding
end
--[[---------------------------------------------------------
- func: SetTabHeight(height)
- desc: sets the height of the tab buttons
--]]---------------------------------------------------------
function tabs:SetTabHeight(height)
self.tabheight = height
for k, v in ipairs(self.internals) do
if v.type == "tabbutton" then
v:SetHeight(self.tabheight)
end
end
end

351
objects/text.lua Normal file
View File

@ -0,0 +1,351 @@
--[[------------------------------------------------
-- LÖVE Frames --
-- By Nikolai Resokav --
--]]------------------------------------------------
--[[------------------------------------------------
-- note: the text wrapping of this object is
experimental and not final
--]]------------------------------------------------
-- text class
text = class("text", base)
text:include(loveframes.templates.default)
--[[---------------------------------------------------------
- func: initialize()
- desc: initializes the object
--]]---------------------------------------------------------
function text:initialize()
self.type = "text"
self.text = ""
self.font = love.graphics.newFont(12)
self.width = 0
self.height = 0
self.maxw = 0
self.lines = 1
self.text = {}
self.original = {}
self.internal = false
end
--[[---------------------------------------------------------
- func: update(deltatime)
- desc: updates the object
--]]---------------------------------------------------------
function text:update(dt)
if self.visible == false then
if self.alwaysupdate == false then
return
end
end
self:CheckHover()
-- move to parent if there is a parent
if self.parent ~= loveframes.base then
self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy
end
if self.Update then
self.Update(self, dt)
end
end
--[[---------------------------------------------------------
- func: draw()
- desc: draws the object
--]]---------------------------------------------------------
function text:draw()
if self.visible == false then
return
end
loveframes.drawcount = loveframes.drawcount + 1
self.draworder = loveframes.drawcount
-- skin variables
local index = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
if self.Draw ~= nil then
self.Draw(self)
else
skin.DrawText(self)
end
self:DrawText()
end
--[[---------------------------------------------------------
- func: SetText(text)
- desc: sets the object's text
--]]---------------------------------------------------------
function text:SetText(t)
local dtype = type(t)
local maxw = self.maxw
local font = self.font
local inserts = {}
local tdata, prevcolor
self.text = {}
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
local dtype = type(v)
if k == 1 and dtype ~= "table" then
prevcolor = {0, 0, 0, 255}
end
if dtype == "table" then
prevcolor = v
elseif dtype == "string" then
v = v:gsub(string.char(9), " ")
v = v:gsub("\n", "")
local parts = loveframes.util.SplitSring(v, " ")
for i, j in ipairs(parts) do
table.insert(self.text, {color = prevcolor, text = j})
end
end
end
if maxw > 0 then
for k, v in ipairs(self.text) do
local data = v.text
local width = font:getWidth(data)
local curw = 0
local new = ""
local key = k
if width > maxw then
table.remove(self.text, k)
for n=1, #data do
local item = data:sub(n, n)
local itemw = font:getWidth(item)
if n ~= #data then
if (curw + itemw) > maxw then
table.insert(inserts, {key = key, color = v.color, 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, color = v.color, text = new})
end
end
end
end
end
for k, v in ipairs(inserts) do
table.insert(self.text, v.key, {color = v.color, text = v.text})
end
end
--[[---------------------------------------------------------
- func: GetText()
- desc: gets the object's text
--]]---------------------------------------------------------
function text:GetText()
return self.text
end
--[[---------------------------------------------------------
- func: Format()
- desc: formats the text
--]]---------------------------------------------------------
function text:DrawText()
local textdata = self.text
local maxw = self.maxw
local font = self.font
local height = font:getHeight("a")
local twidth = 0
local drawx = 0
local drawy = 0
local lines = 0
local totalwidth = 0
local prevtextwidth
for k, v in ipairs(textdata) do
if type(v.text) == "string" then
local width = font:getWidth(v.text)
totalwidth = totalwidth + width
if maxw > 0 then
if k ~= 1 then
if (twidth + width) > maxw then
twidth = 0 + width
drawx = 0
drawy = drawy + height
else
twidth = twidth + width
drawx = drawx + prevtextwidth
end
else
twidth = twidth + width
end
prevtextwidth = width
love.graphics.setFont(font)
love.graphics.setColor(unpack(v.color))
love.graphics.print(v.text, self.x + drawx, self.y + drawy)
else
if k ~= 1 then
drawx = drawx + prevtextwidth
end
prevtextwidth = width
love.graphics.setFont(font)
love.graphics.setColor(unpack(v.color))
love.graphics.print(v.text, self.x + drawx, self.y)
end
end
end
if maxw > 0 then
self.width = maxw
else
self.width = totalwidth
end
self.height = drawy + height
end
--[[---------------------------------------------------------
- func: SetMaxWidth(width)
- desc: sets the object's maximum width
--]]---------------------------------------------------------
function text:SetMaxWidth(width)
self.maxw = width
self:SetText(self.original)
end
--[[---------------------------------------------------------
- func: GetMaxWidth()
- desc: gets the object's maximum width
--]]---------------------------------------------------------
function text:GetMaxWidth()
return self.maxw
end
--[[---------------------------------------------------------
- func: SetWidth(width)
- desc: sets the object's width
--]]---------------------------------------------------------
function text:SetWidth(width)
self:SetMaxWidth(width)
end
--[[---------------------------------------------------------
- func: SetHeight()
- desc: sets the object's height
--]]---------------------------------------------------------
function text:SetHeight(height)
return
end
--[[---------------------------------------------------------
- func: SetSize()
- desc: sets the object's size
--]]---------------------------------------------------------
function text:SetSize(width, height)
self:SetMaxWidth(width)
end
--[[---------------------------------------------------------
- func: SetFont(font)
- desc: sets the object's font
- note: font argument must be a font object
--]]---------------------------------------------------------
function text:SetFont(font)
self.font = font
if self.original then
self:SetText(self.original)
end
end
--[[---------------------------------------------------------
- func: GetFont()
- desc: gets the object's font
--]]---------------------------------------------------------
function text:GetFont()
return self.font
end

482
objects/textinput.lua Normal file
View File

@ -0,0 +1,482 @@
--[[------------------------------------------------
-- LÖVE Frames --
-- By Nikolai Resokav --
--]]------------------------------------------------
-- textinput clas
textinput = class("textinput", base)
textinput:include(loveframes.templates.default)
--[[---------------------------------------------------------
- func: initialize()
- desc: initializes the object
--]]---------------------------------------------------------
function textinput:initialize()
self.type = "textinput"
self.text = ""
self.keydown = "none"
self.font = love.graphics.newFont(12)
self.textcolor = {0, 0, 0, 255}
self.width = 200
self.height = 25
self.delay = 0
self.xoffset = 0
self.blink = 0
self.blinknum = 0
self.blinkx = 0
self.blinky = 0
self.textx = 0
self.texty = 0
self.textxoffset = 0
self.textyoffset = 0
self.unicode = 0
self.showblink = true
self.focus = false
self.internal = false
self.OnEnter = nil
self.OnTextEntered = nil
end
--[[---------------------------------------------------------
- func: update(deltatime)
- desc: updates the object
--]]---------------------------------------------------------
function textinput:update(dt)
if self.visible == false then
if self.alwaysupdate == false then
return
end
end
local time = love.timer.getTime()
self:CheckHover()
-- move to parent if there is a parent
if self.parent ~= loveframes.base then
self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy
end
if self.keydown ~= "none" then
if time > self.delay then
self:RunKey(self.keydown, self.unicode)
self.delay = time + 0.02
end
end
self:PositionText()
self:RunBlink()
if self.Update then
self.Update(self, dt)
end
end
--[[---------------------------------------------------------
- func: draw()
- desc: draws the object
--]]---------------------------------------------------------
function textinput:draw()
if self.visible == false then
return
end
loveframes.drawcount = loveframes.drawcount + 1
self.draworder = loveframes.drawcount
-- skin variables
local index = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
local stencilfunc = function() love.graphics.rectangle("fill", self.x, self.y, self.width, self.height) end
local stencil = love.graphics.newStencil(stencilfunc)
love.graphics.setStencil(stencil)
if self.Draw ~= nil then
self.Draw(self)
else
skin.DrawTextInput(self)
end
love.graphics.setFont(self.font)
love.graphics.setColor(unpack(self.textcolor))
love.graphics.print(self.text, self.textx, self.texty)
love.graphics.setStencil()
end
--[[---------------------------------------------------------
- func: mousepressed(x, y, button)
- desc: called when the player presses a mouse button
--]]---------------------------------------------------------
function textinput:mousepressed(x, y, button)
if self.visible == false then
return
end
if button ~= "l" then
return
end
if self.hover == true then
local baseparent = self:GetBaseParent()
if baseparent and baseparent.type == "frame" then
baseparent:MakeTop()
end
self.focus = true
else
self.focus = false
end
self:GetTextCollisions(x, y)
end
--[[---------------------------------------------------------
- func: mousereleased(x, y, button)
- desc: called when the player releases a mouse button
--]]---------------------------------------------------------
function textinput:mousereleased(x, y, button)
if self.visible == false then
return
end
if button ~= "l" then
return
end
end
--[[---------------------------------------------------------
- func: keypressed(key)
- desc: called when the player presses a key
--]]---------------------------------------------------------
function textinput:keypressed(key, unicode)
if self.visible == false then
return
end
self.delay = love.timer.getTime() + 0.80
self.keydown = key
self:RunKey(key, unicode)
end
--[[---------------------------------------------------------
- func: keyreleased(key)
- desc: called when the player releases a key
--]]---------------------------------------------------------
function textinput:keyreleased(key)
if self.visible == false then
return
end
self.keydown = "none"
end
--[[---------------------------------------------------------
- func: RunKey(key, unicode)
- desc: runs a key event on the object
--]]---------------------------------------------------------
function textinput:RunKey(key, unicode)
local text = self.text
local ckey = ""
local font = self.font
local swidth = self.width
local twidth = font:getWidth(self.text)
local textxoffset = self.textxoffset
self.unicode = unicode
if self.visible == false then
return
end
if self.focus == false then
return
end
if key == "left" then
self:MoveBlinker(-1)
if self.blinkx <= self.x and self.blinknum ~= 0 then
local width = self.font:getWidth(self.text:sub(self.blinknum, self.blinknum + 1))
self.xoffset = self.xoffset + width
elseif self.blinknum == 0 and self.xoffset ~= 0 then
self.xoffset = 0
end
elseif key == "right" then
self:MoveBlinker(1)
if self.blinkx >= self.x + self.width and self.blinknum ~= #self.text then
local width = self.font:getWidth(self.text:sub(self.blinknum, self.blinknum))
self.xoffset = self.xoffset - width
elseif self.blinknum == #self.text and self.xoffset ~= ((0 - font:getWidth(self.text)) + self.width) then
self.xoffset = ((0 - font:getWidth(self.text)) + self.width)
end
end
-- key input checking system
if key == "backspace" then
if text ~= "" then
self.text = self:RemoveFromeText(self.blinknum)
self:MoveBlinker(-1)
end
elseif key == "return" then
if self.OnEnter ~= nil then
self.OnEnter(self, self.text)
end
else
if unicode > 31 and unicode < 127 then
ckey = string.char(unicode)
if self.blinknum ~= 0 and self.blinknum ~= #self.text then
self.text = self:AddIntoText(unicode, self.blinknum)
self:MoveBlinker(1)
else
self.text = text .. ckey
self:MoveBlinker(1)
end
if self.OnTextEntered then
self.OnTextEntered(self, ckey)
end
end
end
if key == "backspace" then
local cwidth = font:getWidth(self.text:sub(#self.text))
if self.xoffset ~= 0 then
self.xoffset = self.xoffset + cwidth
end
else
local cwidth = font:getWidth(ckey)
-- swidth - 1 is for the "-" character
if (twidth + textxoffset) >= (swidth - 1) then
self.xoffset = self.xoffset - cwidth
end
end
end
--[[---------------------------------------------------------
- func: MoveBlinker(num, exact)
- desc: moves the object's blinker
--]]---------------------------------------------------------
function textinput:MoveBlinker(num, exact)
if exact == nil or false then
self.blinknum = self.blinknum + num
else
self.blinknum = num
end
if self.blinknum > #self.text then
self.blinknum = #self.text
elseif self.blinknum < 0 then
self.blinknum = 0
end
self.showblink = true
end
--[[---------------------------------------------------------
- func: RunBlink()
- desc: runs a blink on the object's blinker
--]]---------------------------------------------------------
function textinput:RunBlink()
local time = love.timer.getTime()
if self.xoffset > 0 then
self.xoffset = 0
end
if self.blink < time then
if self.showblink == true then
self.showblink = false
else
self.showblink = true
end
self.blink = time + 0.50
end
local width = 0
for i=1, self.blinknum do
width = width + self.font:getWidth(self.text:sub(i, i))
end
self.blinkx = self.textx + width
self.blinky = self.texty
end
--[[---------------------------------------------------------
- func: AddIntoText(t, p)
- desc: adds text into the object's text a given
position
--]]---------------------------------------------------------
function textinput:AddIntoText(t, p)
local s = self.text
local part1 = s:sub(1, p)
local part2 = s:sub(p + 1)
local new = part1 .. string.char(t) .. part2
return new
--print(part1, part2)
end
--[[---------------------------------------------------------
- func: RemoveFromeText(p)
- desc: removes text from the object's text a given
position
--]]---------------------------------------------------------
function textinput:RemoveFromeText(p)
if self.blinknum ~= 0 then
local s = self.text
local part1 = s:sub(1, p - 1)
local part2 = s:sub(p + 1)
local new = part1 .. part2
return new
end
return self.text
end
--[[---------------------------------------------------------
- func: GetTextCollisions(x, y)
- desc: gets text collisions with the mouse
--]]---------------------------------------------------------
function textinput:GetTextCollisions(x, y)
local font = self.font
local text = self.text
local xpos = 0
for i=1, #text do
local width = font:getWidth(text:sub(i, i))
local height = font:getHeight(text:sub(i, i))
local tx = self.textx + xpos
local ty = self.texty
local col = loveframes.util.BoundingBox(tx, x, ty, y, width, 1, height, 1)
xpos = xpos + width
if col == true then
self:MoveBlinker(i - 1, true)
break
end
end
end
--[[---------------------------------------------------------
- func: PositionText()
- desc: positions the object's text
--]]---------------------------------------------------------
function textinput:PositionText()
self.textx = self.x + self.xoffset + self.textxoffset
self.texty = self.y + self.textyoffset
end
--[[---------------------------------------------------------
- func: SetTextOffsetX(num)
- desc: sets the object's text x offset
--]]---------------------------------------------------------
function textinput:SetTextOffsetX(num)
self.textxoffset = num
end
--[[---------------------------------------------------------
- func: SetTextOffsetY(num)
- desc: sets the object's text y offset
--]]---------------------------------------------------------
function textinput:SetTextOffsetY(num)
self.textyoffset = num
end
--[[---------------------------------------------------------
- func: SetFont(font)
- desc: sets the object's font
--]]---------------------------------------------------------
function textinput:SetFont(font)
self.font = font
end
--[[---------------------------------------------------------
- func: SetTextColor(color)
- desc: sets the object's text color
--]]---------------------------------------------------------
function textinput:SetTextColor(color)
self.textcolor = color
end
--[[---------------------------------------------------------
- func: SetFocus(focus)
- desc: sets the object's focus
--]]---------------------------------------------------------
function textinput:SetFocus(focus)
self.focus = focus
end
--[[---------------------------------------------------------
- func: GetFocus
- desc: gets the object's focus
--]]---------------------------------------------------------
function textinput:GetFocus()
return self.focus
end
--[[---------------------------------------------------------
- func: GetBlinkerVisibility
- desc: gets the object's blinker visibility
--]]---------------------------------------------------------
function textinput:GetBlinkerVisibility()
return self.showblink
end

18
readme.md Normal file
View File

@ -0,0 +1,18 @@
# Löve Frames
## Information
For information on installation and usage, please visit the wiki.
## License
Löve Frames is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) license.
For more information on this license, please read license.html or visit this web page: http://creativecommons.org/licenses/by-sa/3.0/
## Credits
Created by Nikolai Resokav
**Third Party Stuff**
- middleclass: kikito

52
skins.lua Normal file
View File

@ -0,0 +1,52 @@
--[[------------------------------------------------
-- LÖVE Frames --
-- By Nikolai Resokav --
--]]------------------------------------------------
loveframes.skins = {}
loveframes.skins.available = {}
function loveframes.skins.Register(skin)
local name = skin.name
local author = skin.author
local version = skin.version
local namecheck = loveframes.skins.available[name]
local dir = loveframes.config["DIRECTORY"] .. "/skins/" ..name
local dircheck = love.filesystem.isDirectory(dir)
local images = loveframes.util.GetDirContents(dir .. "/images")
local indeximages = loveframes.config["INDEXSKINIMAGES"]
if name == "" or name == nil then
error("Could not register skin: Invalid or missing name data.")
end
if author == "" or author == nil then
error("Could not register skin: Invalid or missing author data.")
end
if version == "" or version == nil then
error("Could not register skin: Invalid or missing version data.")
end
if namecheck ~= nil then
error("Could not register skin: A skin with the name '" ..name.. "' already exists.")
end
if dircheck == false then
error("Could not register skin: Could not find a directory for skin '" ..name.. "'.")
end
loveframes.skins.available[name] = skin
loveframes.skins.available[name].dir = dir
loveframes.skins.available[name].images = {}
if #images > 0 and indeximages == true then
for k, v in ipairs(images) do
loveframes.skins.available[name].images[v.name .. "." .. v.extension] = love.graphics.newImage(v.fullpath)
end
end
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 180 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 188 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 188 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 252 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 231 B

1181
skins/Default/skin.lua Normal file

File diff suppressed because it is too large Load Diff

31
templates.lua Normal file
View File

@ -0,0 +1,31 @@
--[[------------------------------------------------
-- LÖVE Frames --
-- By Nikolai Resokav --
--]]------------------------------------------------
-- templates
loveframes.templates = {}
-- default template
loveframes.templates.default =
{
x = 0,
y = 0,
width = 5,
height = 5,
staticx = 5,
staticy = 5,
draworder = 0,
internal = false,
visible = true,
hover = false,
alwaysupdate = false,
retainsize = false,
calledmousefunc = false,
skin = nil,
clickbounds = nil,
Draw = nil,
Update = nil,
OnMouseEnter = nil,
OnMouseExit = nil,
}

139
third-party/middleclass/middleclass.lua vendored Normal file
View File

@ -0,0 +1,139 @@
-- middleclass.lua - v2.0 (2011-09)
-- Copyright (c) 2011 Enrique García Cota
-- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-- Based on YaciCode, from Julien Patte and LuaObject, from Sebastien Rocca-Serra
local _classes = setmetatable({}, {__mode = "k"})
local function _setClassDictionariesMetatables(klass)
local dict = klass.__instanceDict
dict.__index = dict
local super = klass.super
if super then
local superStatic = super.static
setmetatable(dict, super.__instanceDict)
setmetatable(klass.static, { __index = function(_,k) return dict[k] or superStatic[k] end })
else
setmetatable(klass.static, { __index = function(_,k) return dict[k] end })
end
end
local function _setClassMetatable(klass)
setmetatable(klass, {
__tostring = function() return "class " .. klass.name end,
__index = klass.static,
__newindex = klass.__instanceDict,
__call = function(self, ...) return self:new(...) end
})
end
local function _createClass(name, super)
local klass = { name = name, super = super, static = {}, __mixins = {}, __instanceDict={} }
klass.subclasses = setmetatable({}, {__mode = "k"})
_setClassDictionariesMetatables(klass)
_setClassMetatable(klass)
_classes[klass] = true
return klass
end
local function _createLookupMetamethod(klass, name)
return function(...)
local method = klass.super[name]
assert( type(method)=='function', tostring(klass) .. " doesn't implement metamethod '" .. name .. "'" )
return method(...)
end
end
local function _setClassMetamethods(klass)
for _,m in ipairs(klass.__metamethods) do
klass[m]= _createLookupMetamethod(klass, m)
end
end
local function _setDefaultInitializeMethod(klass, super)
klass.initialize = function(instance, ...)
return super.initialize(instance, ...)
end
end
local function _includeMixin(klass, mixin)
assert(type(mixin)=='table', "mixin must be a table")
for name,method in pairs(mixin) do
if name ~= "included" and name ~= "static" then klass[name] = method end
end
if mixin.static then
for name,method in pairs(mixin.static) do
klass.static[name] = method
end
end
if type(mixin.included)=="function" then mixin:included(klass) end
klass.__mixins[mixin] = true
end
Object = _createClass("Object", nil)
Object.static.__metamethods = { '__add', '__call', '__concat', '__div', '__le', '__lt',
'__mod', '__mul', '__pow', '__sub', '__tostring', '__unm' }
function Object.static:allocate()
assert(_classes[self], "Make sure that you are using 'Class:allocate' instead of 'Class.allocate'")
return setmetatable({ class = self }, self.__instanceDict)
end
function Object.static:new(...)
local instance = self:allocate()
instance:initialize(...)
return instance
end
function Object.static:subclass(name)
assert(_classes[self], "Make sure that you are using 'Class:subclass' instead of 'Class.subclass'")
assert(type(name) == "string", "You must provide a name(string) for your class")
local subclass = _createClass(name, self)
_setClassMetamethods(subclass)
_setDefaultInitializeMethod(subclass, self)
self.subclasses[subclass] = true
self:subclassed(subclass)
return subclass
end
function Object.static:subclassed(other) end
function Object.static:include( ... )
assert(_classes[self], "Make sure you that you are using 'Class:include' instead of 'Class.include'")
for _,mixin in ipairs({...}) do _includeMixin(self, mixin) end
return self
end
function Object:initialize() end
function Object:__tostring() return "instance of " .. tostring(self.class) end
function class(name, super, ...)
super = super or Object
return super:subclass(name, ...)
end
function instanceOf(aClass, obj)
if not _classes[aClass] or type(obj) ~= 'table' or not _classes[obj.class] then return false end
if obj.class == aClass then return true end
return subclassOf(aClass, obj.class)
end
function subclassOf(other, aClass)
if not _classes[aClass] or not _classes[other] or aClass.super == nil then return false end
return aClass.super == other or subclassOf(other, aClass.super)
end
function includes(mixin, aClass)
if not _classes[aClass] then return false end
if aClass.__mixins[mixin] then return true end
return includes(mixin, aClass.super)
end

257
util.lua Normal file
View File

@ -0,0 +1,257 @@
--[[------------------------------------------------
-- LÖVE Frames --
-- By Nikolai Resokav --
--]]------------------------------------------------
-- util library
loveframes.util = {}
function loveframes.util.GetActiveSkin()
local index = loveframes.config["ACTIVESKIN"]
local skin = loveframes.skins.available[index]
return skin
end
--[[---------------------------------------------------------
- func: BoundingBox(x1, x2, y1, y2, w1, w2, h1, h2)
- desc: checks for a collision between two boxes
- note: i take no credit for this function
--]]---------------------------------------------------------
function loveframes.util.BoundingBox(x1, x2, y1, y2, w1, w2, h1, h2)
if x1 > x2 + w2 - 1 or y1 > y2 + h2 - 1 or x2 > x1 + w1 - 1 or y2 > y1 + h1 - 1 then
return false
else
return true
end
end
--[[---------------------------------------------------------
- func: loveframes.util.GetCollisions(object, table)
- desc: gets all objects colliding with the mouse
--]]---------------------------------------------------------
function loveframes.util.GetCollisions(object, t)
local x, y = love.mouse.getPosition()
local object = object or loveframes.base
local t = t or {}
-- add the current object if colliding
if object.visible == true then
local col = loveframes.util.BoundingBox(x, object.x, y, object.y, 1, object.width, 1, object.height)
if col == true and object.collide ~= false then
if object.clickbounds then
local clickcol = loveframes.util.BoundingBox(x, object.clickbounds.x, y, object.clickbounds.y, 1, object.clickbounds.width, 1, object.clickbounds.height)
if clickcol == true then
table.insert(t, object)
end
else
table.insert(t, object)
end
end
end
-- check for internals
if object.internals then
for k, v in ipairs(object.internals) do
if v.visible == true then
loveframes.util.GetCollisions(v, t)
end
end
end
-- check for children
if object.children then
for k, v in ipairs(object.children) do
if v.visible == true then
loveframes.util.GetCollisions(v, t)
end
end
end
return t
end
--[[---------------------------------------------------------
- func: loveframes.util.GetAllObjects(object, table)
- desc: gets all active objects
--]]---------------------------------------------------------
function loveframes.util.GetAllObjects(object, t)
local object = object or loveframes.base
local t = t or {}
table.insert(t, object)
if object.internals then
for k, v in ipairs(object.internals) do
loveframes.util.GetAllObjects(v, t)
end
end
if object.children then
for k, v in ipairs(object.children) do
loveframes.util.GetAllObjects(v, t)
end
end
return t
end
--[[---------------------------------------------------------
- func: GetDirContents(directory, table)
- desc: gets the contents of a directory and all of
it's subdirectories
--]]---------------------------------------------------------
function loveframes.util.GetDirContents(dir, t)
local dir = dir
local t = t or {}
local files = love.filesystem.enumerate(dir)
local dirs = {}
-- local function to restore a string to it's original state after being split
local function restore(t)
local s = ""
t[#t] = nil
for k, v in ipairs(t) do
if k ~= #t then
s = s .. v .. "."
else
s = s .. v
end
end
return s
end
for k, v in ipairs(files) do
local isdir = love.filesystem.isDirectory(dir.. "/" ..v)
if isdir == true then
table.insert(dirs, dir.. "/" ..v)
else
local parts = loveframes.util.SplitSring(v, "([.])")
local extension = parts[#parts]
local name = restore(parts)
table.insert(t, {path = dir, fullpath = dir.. "/" ..v, name = name, extension = extension})
end
end
if #dirs > 0 then
for k, v in ipairs(dirs) do
t = loveframes.util.GetDirContents(v, t)
end
end
return t
end
--[[---------------------------------------------------------
- func: Round(val, decimal)
- desc: rounds a number based on the decimal limit
- note: i take no credit for this function
--]]---------------------------------------------------------
function loveframes.util.Round(val, decimal)
if (decimal) then
return math.floor( (val * 10^decimal) + 0.5) / (10^decimal)
else
return math.floor(val+0.5)
end
end
--[[---------------------------------------------------------
- func: Split(string, pattern)
- desc: splits a string into a table based on a given pattern
- note: i take no credit for this function
--]]---------------------------------------------------------
function loveframes.util.SplitSring(str, pat)
local t = {} -- NOTE: use {n = 0} in Lua-5.0
if pat == " " then
local fpat = "(.-)" .. pat
local last_end = 1
local s, e, cap = str:find(fpat, 1)
while s do
if s ~= #str then
cap = cap .. " "
end
if s ~= 1 or cap ~= "" then
table.insert(t,cap)
end
last_end = e+1
s, e, cap = str:find(fpat, last_end)
end
if last_end <= #str then
cap = str:sub(last_end)
table.insert(t, cap)
end
else
local fpat = "(.-)" .. pat
local last_end = 1
local s, e, cap = str:find(fpat, 1)
while s do
if s ~= 1 or cap ~= "" then
table.insert(t,cap)
end
last_end = e+1
s, e, cap = str:find(fpat, last_end)
end
if last_end <= #str then
cap = str:sub(last_end)
table.insert(t, cap)
end
end
return t
end
--[[---------------------------------------------------------
- func: Trim(string)
- desc: trims spaces off of the beginning and end of
a string
- note: i take no credit for this function
--]]---------------------------------------------------------
function loveframes.util.TrimString(s)
return (s:gsub("^%s*(.-)%s*$", "%1"))
end
--[[---------------------------------------------------------
- func: RemoveAll()
- desc: removes all gui elements
--]]---------------------------------------------------------
function loveframes.util.RemoveAll()
loveframes.base.children = {}
end