2013-02-11 21:15:40 +00:00
|
|
|
--[[------------------------------------------------
|
|
|
|
-- Love Frames - A GUI library for LOVE --
|
2014-01-14 11:29:11 +00:00
|
|
|
-- Copyright (c) 2012-2014 Kenny Shields --
|
2013-02-11 21:15:40 +00:00
|
|
|
--]]------------------------------------------------
|
|
|
|
|
2013-05-05 23:51:20 +00:00
|
|
|
local path = ...
|
|
|
|
|
2013-02-11 21:15:40 +00:00
|
|
|
-- central library table
|
|
|
|
loveframes = {}
|
|
|
|
|
|
|
|
-- library info
|
2013-08-15 19:28:18 +00:00
|
|
|
loveframes.author = "Kenny Shields"
|
2014-05-17 23:02:03 +00:00
|
|
|
loveframes.version = "0.9.8.1"
|
2013-08-15 19:28:18 +00:00
|
|
|
loveframes.stage = "Alpha"
|
2013-02-11 21:15:40 +00:00
|
|
|
|
|
|
|
-- library configurations
|
|
|
|
loveframes.config = {}
|
2013-05-05 23:51:20 +00:00
|
|
|
loveframes.config["DIRECTORY"] = nil
|
2013-02-11 21:15:40 +00:00
|
|
|
loveframes.config["DEFAULTSKIN"] = "Blue"
|
|
|
|
loveframes.config["ACTIVESKIN"] = "Blue"
|
|
|
|
loveframes.config["INDEXSKINIMAGES"] = true
|
|
|
|
loveframes.config["DEBUG"] = false
|
|
|
|
|
|
|
|
-- misc library vars
|
|
|
|
loveframes.state = "none"
|
|
|
|
loveframes.drawcount = 0
|
2013-06-10 16:34:01 +00:00
|
|
|
loveframes.collisioncount = 0
|
2013-11-22 17:00:06 +00:00
|
|
|
loveframes.objectcount = 0
|
2013-02-11 21:15:40 +00:00
|
|
|
loveframes.hoverobject = false
|
|
|
|
loveframes.modalobject = false
|
|
|
|
loveframes.inputobject = false
|
2013-10-30 23:05:10 +00:00
|
|
|
loveframes.downobject = false
|
2014-01-08 00:06:03 +00:00
|
|
|
loveframes.resizeobject = false
|
2013-06-10 16:34:01 +00:00
|
|
|
loveframes.hover = false
|
2013-10-30 23:05:10 +00:00
|
|
|
loveframes.input_cursor_set = false
|
|
|
|
loveframes.prevcursor = nil
|
2013-02-11 21:15:40 +00:00
|
|
|
loveframes.basicfont = love.graphics.newFont(12)
|
|
|
|
loveframes.basicfontsmall = love.graphics.newFont(10)
|
|
|
|
loveframes.objects = {}
|
2013-11-22 17:00:06 +00:00
|
|
|
loveframes.collisions = {}
|
2013-02-11 21:15:40 +00:00
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: load()
|
|
|
|
- desc: loads the library
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function loveframes.load()
|
|
|
|
|
|
|
|
-- install directory of the library
|
2013-05-05 23:51:20 +00:00
|
|
|
local dir = loveframes.config["DIRECTORY"] or path
|
2013-02-11 21:15:40 +00:00
|
|
|
|
|
|
|
-- require the internal base libraries
|
2013-09-20 22:44:47 +00:00
|
|
|
loveframes.class = require(dir .. ".third-party.middleclass")
|
2014-01-14 11:05:40 +00:00
|
|
|
require(dir .. ".libraries.util")
|
|
|
|
require(dir .. ".libraries.skins")
|
|
|
|
require(dir .. ".libraries.templates")
|
|
|
|
require(dir .. ".libraries.debug")
|
2013-02-11 21:15:40 +00:00
|
|
|
|
|
|
|
-- replace all "." with "/" in the directory setting
|
2013-12-05 14:39:09 +00:00
|
|
|
dir = dir:gsub("\\", "/"):gsub("(%a)%.(%a)", "%1/%2")
|
2013-02-11 21:15:40 +00:00
|
|
|
loveframes.config["DIRECTORY"] = dir
|
|
|
|
|
|
|
|
-- create a list of gui objects, skins and templates
|
|
|
|
local objects = loveframes.util.GetDirectoryContents(dir .. "/objects")
|
|
|
|
local skins = loveframes.util.GetDirectoryContents(dir .. "/skins")
|
|
|
|
local templates = loveframes.util.GetDirectoryContents(dir .. "/templates")
|
|
|
|
|
|
|
|
-- 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.requirepath)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- loop through a list of all gui templates and require them
|
|
|
|
for k, v in ipairs(templates) do
|
|
|
|
if v.extension == "lua" then
|
|
|
|
require(v.requirepath)
|
|
|
|
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.requirepath)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- create the base gui object
|
|
|
|
local base = loveframes.objects["base"]
|
|
|
|
loveframes.base = base:new()
|
|
|
|
|
2014-04-03 22:55:46 +00:00
|
|
|
-- enable key repeat
|
|
|
|
love.keyboard.setKeyRepeat(true)
|
|
|
|
|
2013-02-11 21:15:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: update(deltatime)
|
|
|
|
- desc: updates all library objects
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function loveframes.update(dt)
|
|
|
|
|
|
|
|
local base = loveframes.base
|
2013-10-30 23:05:10 +00:00
|
|
|
local input_cursor_set = loveframes.input_cursor_set
|
2013-06-10 16:34:01 +00:00
|
|
|
|
|
|
|
loveframes.collisioncount = 0
|
2013-11-22 17:00:06 +00:00
|
|
|
loveframes.objectcount = 0
|
2013-06-10 16:34:01 +00:00
|
|
|
loveframes.hover = false
|
2013-10-30 23:05:10 +00:00
|
|
|
loveframes.hoverobject = false
|
2013-11-22 17:00:06 +00:00
|
|
|
|
|
|
|
local downobject = loveframes.downobject
|
|
|
|
if #loveframes.collisions > 0 then
|
|
|
|
local top = loveframes.collisions[#loveframes.collisions]
|
|
|
|
if not downobject then
|
|
|
|
loveframes.hoverobject = top
|
|
|
|
else
|
|
|
|
if downobject == top then
|
|
|
|
loveframes.hoverobject = top
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-04-03 22:55:46 +00:00
|
|
|
local hoverobject = loveframes.hoverobject
|
|
|
|
local arrow = love.mouse.getSystemCursor("arrow")
|
|
|
|
local curcursor = love.mouse.getCursor()
|
|
|
|
if hoverobject then
|
|
|
|
local ibeam = love.mouse.getSystemCursor("ibeam")
|
|
|
|
local mx, my = love.mouse.getPosition()
|
|
|
|
if hoverobject.type == "textinput" and not loveframes.resizeobject then
|
|
|
|
if curcursor ~= ibeam then
|
|
|
|
love.mouse.setCursor(ibeam)
|
|
|
|
end
|
|
|
|
elseif hoverobject.type == "frame" then
|
|
|
|
if not hoverobject.dragging and hoverobject.canresize then
|
|
|
|
if loveframes.util.BoundingBox(hoverobject.x, mx, hoverobject.y, my, 5, 1, 5, 1) then
|
|
|
|
local sizenwse = love.mouse.getSystemCursor("sizenwse")
|
|
|
|
if curcursor ~= sizenwse then
|
|
|
|
love.mouse.setCursor(sizenwse)
|
|
|
|
end
|
|
|
|
elseif loveframes.util.BoundingBox(hoverobject.x + hoverobject.width - 5, mx, hoverobject.y + hoverobject.height - 5, my, 5, 1, 5, 1) then
|
|
|
|
local sizenwse = love.mouse.getSystemCursor("sizenwse")
|
|
|
|
if curcursor ~= sizenwse then
|
|
|
|
love.mouse.setCursor(sizenwse)
|
|
|
|
end
|
|
|
|
elseif loveframes.util.BoundingBox(hoverobject.x + hoverobject.width - 5, mx, hoverobject.y, my, 5, 1, 5, 1) then
|
|
|
|
local sizenesw = love.mouse.getSystemCursor("sizenesw")
|
|
|
|
if curcursor ~= sizenesw then
|
|
|
|
love.mouse.setCursor(sizenesw)
|
|
|
|
end
|
|
|
|
elseif loveframes.util.BoundingBox(hoverobject.x, mx, hoverobject.y + hoverobject.height - 5, my, 5, 1, 5, 1) then
|
|
|
|
local sizenesw = love.mouse.getSystemCursor("sizenesw")
|
|
|
|
if curcursor ~= sizenesw then
|
|
|
|
love.mouse.setCursor(sizenesw)
|
|
|
|
end
|
|
|
|
elseif loveframes.util.BoundingBox(hoverobject.x + 5, mx, hoverobject.y, my, hoverobject.width - 10, 1, 2, 1) then
|
|
|
|
local sizens = love.mouse.getSystemCursor("sizens")
|
|
|
|
if curcursor ~= sizens then
|
|
|
|
love.mouse.setCursor(sizens)
|
|
|
|
end
|
|
|
|
elseif loveframes.util.BoundingBox(hoverobject.x + 5, mx, hoverobject.y + hoverobject.height - 2, my, hoverobject.width - 10, 1, 2, 1) then
|
|
|
|
local sizens = love.mouse.getSystemCursor("sizens")
|
|
|
|
if curcursor ~= sizens then
|
|
|
|
love.mouse.setCursor(sizens)
|
|
|
|
end
|
|
|
|
elseif loveframes.util.BoundingBox(hoverobject.x, mx, hoverobject.y + 5, my, 2, 1, hoverobject.height - 10, 1) then
|
|
|
|
local sizewe = love.mouse.getSystemCursor("sizewe")
|
|
|
|
if curcursor ~= sizewe then
|
|
|
|
love.mouse.setCursor(sizewe)
|
|
|
|
end
|
|
|
|
elseif loveframes.util.BoundingBox(hoverobject.x + hoverobject.width - 2, mx, hoverobject.y + 5, my, 2, 1, hoverobject.height - 10, 1) then
|
|
|
|
local sizewe = love.mouse.getSystemCursor("sizewe")
|
|
|
|
if curcursor ~= sizewe then
|
|
|
|
love.mouse.setCursor(sizewe)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if not loveframes.resizeobject then
|
|
|
|
local arrow = love.mouse.getSystemCursor("arrow")
|
|
|
|
if curcursor ~= arrow then
|
|
|
|
love.mouse.setCursor(arrow)
|
2014-01-08 00:21:22 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-04-03 22:55:46 +00:00
|
|
|
elseif hoverobject.type == "text" and hoverobject.linkcol and not loveframes.resizeobject then
|
|
|
|
local hand = love.mouse.getSystemCursor("hand")
|
|
|
|
if curcursor ~= hand then
|
|
|
|
love.mouse.setCursor(hand)
|
2013-10-30 23:05:10 +00:00
|
|
|
end
|
2014-04-03 22:55:46 +00:00
|
|
|
end
|
|
|
|
if curcursor ~= arrow then
|
|
|
|
if hoverobject.type ~= "textinput" and hoverobject.type ~= "frame" and not hoverobject.linkcol and not loveframes.resizeobject then
|
|
|
|
love.mouse.setCursor(arrow)
|
|
|
|
elseif hoverobject.type ~= "textinput" and curcursor == ibeam then
|
2014-01-08 00:21:22 +00:00
|
|
|
love.mouse.setCursor(arrow)
|
2013-10-30 23:05:10 +00:00
|
|
|
end
|
|
|
|
end
|
2014-04-03 22:55:46 +00:00
|
|
|
else
|
|
|
|
if curcursor ~= arrow and not loveframes.resizeobject then
|
|
|
|
love.mouse.setCursor(arrow)
|
|
|
|
end
|
2013-10-30 23:05:10 +00:00
|
|
|
end
|
2013-11-25 13:06:41 +00:00
|
|
|
|
|
|
|
loveframes.collisions = {}
|
|
|
|
base:update(dt)
|
2013-02-11 21:15:40 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: draw()
|
|
|
|
- desc: draws all library objects
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function loveframes.draw()
|
|
|
|
|
|
|
|
local base = loveframes.base
|
|
|
|
local r, g, b, a = love.graphics.getColor()
|
2013-03-23 19:50:44 +00:00
|
|
|
local font = love.graphics.getFont()
|
2013-02-11 21:15:40 +00:00
|
|
|
|
|
|
|
base:draw()
|
|
|
|
|
|
|
|
loveframes.drawcount = 0
|
|
|
|
loveframes.debug.draw()
|
|
|
|
|
|
|
|
love.graphics.setColor(r, g, b, a)
|
|
|
|
|
2013-03-23 19:50:44 +00:00
|
|
|
if font then
|
|
|
|
love.graphics.setFont(font)
|
|
|
|
end
|
|
|
|
|
2013-02-11 21:15:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: mousepressed(x, y, button)
|
|
|
|
- desc: called when the player presses a mouse button
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function loveframes.mousepressed(x, y, button)
|
|
|
|
|
|
|
|
local base = loveframes.base
|
|
|
|
base:mousepressed(x, y, button)
|
|
|
|
|
2013-12-26 18:30:35 +00:00
|
|
|
-- close open menus
|
|
|
|
local bchildren = base.children
|
|
|
|
local hoverobject = loveframes.hoverobject
|
|
|
|
for k, v in ipairs(bchildren) do
|
|
|
|
local otype = v.type
|
|
|
|
local visible = v.visible
|
|
|
|
if hoverobject then
|
|
|
|
local htype = hoverobject.type
|
|
|
|
if otype == "menu" and visible and htype ~= "menu" and htype ~= "menuoption" then
|
|
|
|
v:SetVisible(false)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if otype == "menu" and visible then
|
|
|
|
v:SetVisible(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-11 21:15:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: mousereleased(x, y, button)
|
|
|
|
- desc: called when the player releases a mouse button
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function loveframes.mousereleased(x, y, button)
|
|
|
|
|
|
|
|
local base = loveframes.base
|
|
|
|
base:mousereleased(x, y, button)
|
|
|
|
|
|
|
|
-- reset the hover object
|
|
|
|
if button == "l" then
|
2013-10-30 23:05:10 +00:00
|
|
|
loveframes.downobject = false
|
2013-02-11 21:15:40 +00:00
|
|
|
loveframes.selectedobject = false
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
2014-04-03 22:55:46 +00:00
|
|
|
- func: keypressed(key, isrepeat)
|
2013-02-11 21:15:40 +00:00
|
|
|
- desc: called when the player presses a key
|
|
|
|
--]]---------------------------------------------------------
|
2014-04-03 22:55:46 +00:00
|
|
|
function loveframes.keypressed(key, isrepeat)
|
2013-02-11 21:15:40 +00:00
|
|
|
|
|
|
|
local base = loveframes.base
|
2014-04-03 22:55:46 +00:00
|
|
|
base:keypressed(key, isrepeat)
|
2013-02-11 21:15:40 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: keyreleased(key)
|
|
|
|
- desc: called when the player releases a key
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function loveframes.keyreleased(key)
|
|
|
|
|
|
|
|
local base = loveframes.base
|
|
|
|
base:keyreleased(key)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2013-10-22 22:38:24 +00:00
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: textinput(text)
|
|
|
|
- desc: called when the user inputs text
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function loveframes.textinput(text)
|
|
|
|
|
|
|
|
local base = loveframes.base
|
|
|
|
base:textinput(text)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2013-02-11 21:15:40 +00:00
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: Create(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
|
|
|
|
|
|
|
|
local objects = loveframes.objects
|
|
|
|
local object = objects[data]
|
2013-11-22 17:00:06 +00:00
|
|
|
local objectcount = loveframes.objectcount
|
2013-02-11 21:15:40 +00:00
|
|
|
|
|
|
|
if not object then
|
|
|
|
loveframes.util.Error("Error creating object: Invalid object '" ..data.. "'.")
|
|
|
|
end
|
|
|
|
|
|
|
|
-- create the object
|
|
|
|
local newobject = object:new()
|
|
|
|
|
|
|
|
-- apply template properties to the object
|
|
|
|
loveframes.templates.ApplyToObject(newobject)
|
|
|
|
|
|
|
|
-- if the object is a tooltip, return it and go no further
|
|
|
|
if data == "tooltip" then
|
|
|
|
return newobject
|
|
|
|
end
|
|
|
|
|
|
|
|
-- remove the object if it is an internal
|
|
|
|
if newobject.internal then
|
|
|
|
newobject:Remove()
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
-- parent the new object by default to the base gui object
|
|
|
|
newobject.parent = loveframes.base
|
|
|
|
table.insert(loveframes.base.children, newobject)
|
|
|
|
|
|
|
|
-- if the parent argument is not nil, make that argument the object's new parent
|
|
|
|
if parent then
|
|
|
|
newobject:SetParent(parent)
|
|
|
|
end
|
|
|
|
|
2013-11-22 17:00:06 +00:00
|
|
|
loveframes.objectcount = objectcount + 1
|
|
|
|
|
2013-02-11 21:15:40 +00:00
|
|
|
-- return the object for further manipulation
|
|
|
|
return newobject
|
|
|
|
|
|
|
|
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
|
2013-08-12 13:48:51 +00:00
|
|
|
local validobjects = loveframes.objects
|
2013-02-11 21:15:40 +00:00
|
|
|
for k, v in pairs(t) do
|
|
|
|
-- current default object
|
2013-08-12 13:48:51 +00:00
|
|
|
local object = validobjects[v.type]:new()
|
2013-02-11 21:15:40 +00:00
|
|
|
-- 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
|
2013-06-10 16:34:01 +00:00
|
|
|
if child then
|
2013-02-11 21:15:40 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: NewObject(id, name, inherit_from_base)
|
|
|
|
- desc: creates a new object
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function loveframes.NewObject(id, name, inherit_from_base)
|
|
|
|
|
|
|
|
local objects = loveframes.objects
|
|
|
|
local object = false
|
|
|
|
|
|
|
|
if inherit_from_base then
|
|
|
|
local base = objects["base"]
|
2013-09-20 22:44:47 +00:00
|
|
|
object = loveframes.class(name, base)
|
2013-02-11 21:15:40 +00:00
|
|
|
objects[id] = object
|
|
|
|
else
|
2013-09-20 22:44:47 +00:00
|
|
|
object = loveframes.class(name)
|
2013-02-11 21:15:40 +00:00
|
|
|
objects[id] = object
|
|
|
|
end
|
|
|
|
|
|
|
|
return object
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetState(name)
|
|
|
|
- desc: sets the current state
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function loveframes.SetState(name)
|
|
|
|
|
|
|
|
loveframes.state = name
|
|
|
|
loveframes.base.state = name
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetState()
|
|
|
|
- desc: gets the current state
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function loveframes.GetState()
|
|
|
|
|
|
|
|
return loveframes.state
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
-- load the library
|
2013-12-05 14:39:09 +00:00
|
|
|
loveframes.load()
|