Pop.Box/pop/init.lua

82 lines
2.5 KiB
Lua
Raw Normal View History

2015-11-20 11:30:40 +00:00
local lf = love.filesystem
local lg = love.graphics
2015-11-18 03:27:06 +00:00
local pop = {}
2015-11-20 11:30:40 +00:00
local path = ... --NOTE Pop.Box must be required as its directory name (w SLASHES)!
2015-11-18 03:27:06 +00:00
-- elements are local
2015-11-20 11:30:40 +00:00
--TODO require these how skins are required
2015-11-18 03:27:06 +00:00
local box = require(path .. ".elements.box")
local text = require(path .. ".elements.text")
2015-11-20 11:30:40 +00:00
-- skins define how elements are drawn
pop.skins = {}
local skins = lf.getDirectoryItems(path .. "/skins") --NOTE Pop.Box must be required with SLASHES!
for _, v in ipairs(skins) do
local name = v:sub(1,-5)
pop.skins[name] = require(path .. "/skins/" .. name)
pop.skins[name].name = name
end
pop.currentSkin = "clearspace" --default skin
2015-11-18 03:27:06 +00:00
-- everything has one parent element (initialized at the end)
pop.parentElement = false
function pop.create(elementType, parent, ...)
if not parent then
parent = pop.parentElement
end
local newElement
if elementType == "box" then
newElement = box(pop, parent, ...)
elseif elementType == "text" then
newElement = text(pop, parent, ...)
else
error("Invalid element type: " .. elementType)
end
return newElement
end
-- pretty wrappers to call pop.element() instead of pop.create("element")
2015-11-20 11:30:40 +00:00
pop.box = function(...) return pop.create("box", ...) end
pop.text = function(...) return pop.create("text", ...) end
2015-11-18 03:27:06 +00:00
function pop.draw(element)
if not element then
element = pop.parentElement
end
element:draw()
2015-11-20 11:30:40 +00:00
for _, childElement in pairs(element.child) do
--pop.draw(childElement, element.x, element.y)
pop.draw(childElement)
end
2015-11-18 03:27:06 +00:00
end
-- TODO decide if we should track mouse movement
2015-11-20 11:30:40 +00:00
function pop.onMousePress(button, x, y) end
function pop.onMouseRelease(button, x, y) end
2015-11-18 03:27:06 +00:00
function pop.mousepressed(button, x, y)
2015-11-20 11:30:40 +00:00
--TODO find which element it belongs to and if that element has a callback set,
-- if it does, use that, else, use the global callback (defined above..as nil)
2015-11-18 03:27:06 +00:00
end
function pop.mousereleased(button, x, y)
2015-11-20 11:30:40 +00:00
--TODO find which element it belongs to and if that element has a callback set,
-- if it does, use that, else, use the global callback (defined above..as nil)
2015-11-18 03:27:06 +00:00
end
-- initialize the top element
2015-11-20 11:30:40 +00:00
pop.parentElement = box(pop, {child={}}) -- dummy object because it has no parent
--pop.parentElement:setSizeControl("specified") -- make it not try to update itself (TODO or based on outro, and custom code to check top parent against screen size)
--pop.parentElement:setSize(lg.getWidth(), lg.getHeight()) -- fill window size
2015-11-18 03:27:06 +00:00
--pop.parentElement:setVisible(false) -- uneeded since its clear...
return pop