mirror of
https://github.com/TangentFoxy/Pop.Box.git
synced 2024-12-15 12:44:20 +00:00
wip rewrite bare-bones / using ldoc
This commit is contained in:
parent
61f126cd62
commit
165ec05baf
@ -13,6 +13,10 @@ to make it easy to experiment with GUIs during development.
|
|||||||
|
|
||||||
Supports LÖVE versions 0.9.1 and higher.
|
Supports LÖVE versions 0.9.1 and higher.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
**Note**: Currently rewriting and redesigning Pop.Box. The following info is out of date until I finish:
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- Quickly set up and align GUI elements.
|
- Quickly set up and align GUI elements.
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
@ECHO OFF
|
|
||||||
REM Assumes you have Windows binaries in the project's root directory!
|
|
||||||
cd src
|
|
||||||
"%cd%\..\moonc.exe" -t ../lib .
|
|
||||||
cd ..
|
|
||||||
xcopy /S /Y "%cd%\lib\pop\*" "%cd%\demo\pop\*"
|
|
5
build.sh
5
build.sh
@ -1,5 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
cd src
|
|
||||||
moonc -t ../lib .
|
|
||||||
cd ..
|
|
||||||
cp -rf ./lib/pop/* ./demo/pop/
|
|
11
config.ld
Normal file
11
config.ld
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
file = {
|
||||||
|
"init.moon",
|
||||||
|
"util.moon",
|
||||||
|
}
|
||||||
|
|
||||||
|
project = "Pop.Box()"
|
||||||
|
description = "GUI library for LOVE, designed for ease of use"
|
||||||
|
title = "Documentation"
|
||||||
|
--package = "pop" --has to be same name as source directory
|
||||||
|
format = "markdown"
|
||||||
|
dir = "docs"
|
3
demo.bat
3
demo.bat
@ -1,3 +0,0 @@
|
|||||||
@ECHO OFF
|
|
||||||
REM "%cd%\build.bat"
|
|
||||||
"C:\Program Files\Love\LOVE.exe" "%cd%\demo"
|
|
@ -1,7 +0,0 @@
|
|||||||
function love.conf(t)
|
|
||||||
t.title = "Pop.Box demo/tests"
|
|
||||||
t.console = true
|
|
||||||
|
|
||||||
t.window.width = 960
|
|
||||||
t.window.height = 540
|
|
||||||
end
|
|
@ -1,344 +0,0 @@
|
|||||||
local inspect ={
|
|
||||||
_VERSION = 'inspect.lua 3.0.3',
|
|
||||||
_URL = 'http://github.com/kikito/inspect.lua',
|
|
||||||
_DESCRIPTION = 'human-readable representations of tables',
|
|
||||||
_LICENSE = [[
|
|
||||||
MIT LICENSE
|
|
||||||
|
|
||||||
Copyright (c) 2013 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.
|
|
||||||
]]
|
|
||||||
}
|
|
||||||
|
|
||||||
inspect.KEY = setmetatable({}, {__tostring = function() return 'inspect.KEY' end})
|
|
||||||
inspect.METATABLE = setmetatable({}, {__tostring = function() return 'inspect.METATABLE' end})
|
|
||||||
|
|
||||||
-- Apostrophizes the string if it has quotes, but not aphostrophes
|
|
||||||
-- Otherwise, it returns a regular quoted string
|
|
||||||
local function smartQuote(str)
|
|
||||||
if str:match('"') and not str:match("'") then
|
|
||||||
return "'" .. str .. "'"
|
|
||||||
end
|
|
||||||
return '"' .. str:gsub('"', '\\"') .. '"'
|
|
||||||
end
|
|
||||||
|
|
||||||
local controlCharsTranslation = {
|
|
||||||
["\a"] = "\\a", ["\b"] = "\\b", ["\f"] = "\\f", ["\n"] = "\\n",
|
|
||||||
["\r"] = "\\r", ["\t"] = "\\t", ["\v"] = "\\v"
|
|
||||||
}
|
|
||||||
|
|
||||||
local function escape(str)
|
|
||||||
local result = str:gsub("\\", "\\\\"):gsub("(%c)", controlCharsTranslation)
|
|
||||||
return result
|
|
||||||
end
|
|
||||||
|
|
||||||
local function isIdentifier(str)
|
|
||||||
return type(str) == 'string' and str:match( "^[_%a][_%a%d]*$" )
|
|
||||||
end
|
|
||||||
|
|
||||||
local function isSequenceKey(k, sequenceLength)
|
|
||||||
return type(k) == 'number'
|
|
||||||
and 1 <= k
|
|
||||||
and k <= sequenceLength
|
|
||||||
and math.floor(k) == k
|
|
||||||
end
|
|
||||||
|
|
||||||
local defaultTypeOrders = {
|
|
||||||
['number'] = 1, ['boolean'] = 2, ['string'] = 3, ['table'] = 4,
|
|
||||||
['function'] = 5, ['userdata'] = 6, ['thread'] = 7
|
|
||||||
}
|
|
||||||
|
|
||||||
local function sortKeys(a, b)
|
|
||||||
local ta, tb = type(a), type(b)
|
|
||||||
|
|
||||||
-- strings and numbers are sorted numerically/alphabetically
|
|
||||||
if ta == tb and (ta == 'string' or ta == 'number') then return a < b end
|
|
||||||
|
|
||||||
local dta, dtb = defaultTypeOrders[ta], defaultTypeOrders[tb]
|
|
||||||
-- Two default types are compared according to the defaultTypeOrders table
|
|
||||||
if dta and dtb then return defaultTypeOrders[ta] < defaultTypeOrders[tb]
|
|
||||||
elseif dta then return true -- default types before custom ones
|
|
||||||
elseif dtb then return false -- custom types after default ones
|
|
||||||
end
|
|
||||||
|
|
||||||
-- custom types are sorted out alphabetically
|
|
||||||
return ta < tb
|
|
||||||
end
|
|
||||||
|
|
||||||
-- For implementation reasons, the behavior of rawlen & # is "undefined" when
|
|
||||||
-- tables aren't pure sequences. So we implement our own # operator.
|
|
||||||
local function getSequenceLength(t)
|
|
||||||
local len = 1
|
|
||||||
local v = rawget(t,len)
|
|
||||||
while v ~= nil do
|
|
||||||
len = len + 1
|
|
||||||
v = rawget(t,len)
|
|
||||||
end
|
|
||||||
return len - 1
|
|
||||||
end
|
|
||||||
|
|
||||||
local function getNonSequentialKeys(t)
|
|
||||||
local keys = {}
|
|
||||||
local sequenceLength = getSequenceLength(t)
|
|
||||||
for k,_ in pairs(t) do
|
|
||||||
if not isSequenceKey(k, sequenceLength) then table.insert(keys, k) end
|
|
||||||
end
|
|
||||||
table.sort(keys, sortKeys)
|
|
||||||
return keys, sequenceLength
|
|
||||||
end
|
|
||||||
|
|
||||||
local function getToStringResultSafely(t, mt)
|
|
||||||
local __tostring = type(mt) == 'table' and rawget(mt, '__tostring')
|
|
||||||
local str, ok
|
|
||||||
if type(__tostring) == 'function' then
|
|
||||||
ok, str = pcall(__tostring, t)
|
|
||||||
str = ok and str or 'error: ' .. tostring(str)
|
|
||||||
end
|
|
||||||
if type(str) == 'string' and #str > 0 then return str end
|
|
||||||
end
|
|
||||||
|
|
||||||
local maxIdsMetaTable = {
|
|
||||||
__index = function(self, typeName)
|
|
||||||
rawset(self, typeName, 0)
|
|
||||||
return 0
|
|
||||||
end
|
|
||||||
}
|
|
||||||
|
|
||||||
local idsMetaTable = {
|
|
||||||
__index = function (self, typeName)
|
|
||||||
local col = {}
|
|
||||||
rawset(self, typeName, col)
|
|
||||||
return col
|
|
||||||
end
|
|
||||||
}
|
|
||||||
|
|
||||||
local function countTableAppearances(t, tableAppearances)
|
|
||||||
tableAppearances = tableAppearances or {}
|
|
||||||
|
|
||||||
if type(t) == 'table' then
|
|
||||||
if not tableAppearances[t] then
|
|
||||||
tableAppearances[t] = 1
|
|
||||||
for k,v in pairs(t) do
|
|
||||||
countTableAppearances(k, tableAppearances)
|
|
||||||
countTableAppearances(v, tableAppearances)
|
|
||||||
end
|
|
||||||
countTableAppearances(getmetatable(t), tableAppearances)
|
|
||||||
else
|
|
||||||
tableAppearances[t] = tableAppearances[t] + 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return tableAppearances
|
|
||||||
end
|
|
||||||
|
|
||||||
local copySequence = function(s)
|
|
||||||
local copy, len = {}, #s
|
|
||||||
for i=1, len do copy[i] = s[i] end
|
|
||||||
return copy, len
|
|
||||||
end
|
|
||||||
|
|
||||||
local function makePath(path, ...)
|
|
||||||
local keys = {...}
|
|
||||||
local newPath, len = copySequence(path)
|
|
||||||
for i=1, #keys do
|
|
||||||
newPath[len + i] = keys[i]
|
|
||||||
end
|
|
||||||
return newPath
|
|
||||||
end
|
|
||||||
|
|
||||||
local function processRecursive(process, item, path, visited)
|
|
||||||
|
|
||||||
if item == nil then return nil end
|
|
||||||
if visited[item] then return visited[item] end
|
|
||||||
|
|
||||||
local processed = process(item, path)
|
|
||||||
if type(processed) == 'table' then
|
|
||||||
local processedCopy = {}
|
|
||||||
visited[item] = processedCopy
|
|
||||||
local processedKey
|
|
||||||
|
|
||||||
for k,v in pairs(processed) do
|
|
||||||
processedKey = processRecursive(process, k, makePath(path, k, inspect.KEY), visited)
|
|
||||||
if processedKey ~= nil then
|
|
||||||
processedCopy[processedKey] = processRecursive(process, v, makePath(path, processedKey), visited)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local mt = processRecursive(process, getmetatable(processed), makePath(path, inspect.METATABLE), visited)
|
|
||||||
setmetatable(processedCopy, mt)
|
|
||||||
processed = processedCopy
|
|
||||||
end
|
|
||||||
return processed
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-------------------------------------------------------------------
|
|
||||||
|
|
||||||
local Inspector = {}
|
|
||||||
local Inspector_mt = {__index = Inspector}
|
|
||||||
|
|
||||||
function Inspector:puts(...)
|
|
||||||
local args = {...}
|
|
||||||
local buffer = self.buffer
|
|
||||||
local len = #buffer
|
|
||||||
for i=1, #args do
|
|
||||||
len = len + 1
|
|
||||||
buffer[len] = tostring(args[i])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function Inspector:down(f)
|
|
||||||
self.level = self.level + 1
|
|
||||||
f()
|
|
||||||
self.level = self.level - 1
|
|
||||||
end
|
|
||||||
|
|
||||||
function Inspector:tabify()
|
|
||||||
self:puts(self.newline, string.rep(self.indent, self.level))
|
|
||||||
end
|
|
||||||
|
|
||||||
function Inspector:alreadyVisited(v)
|
|
||||||
return self.ids[type(v)][v] ~= nil
|
|
||||||
end
|
|
||||||
|
|
||||||
function Inspector:getId(v)
|
|
||||||
local tv = type(v)
|
|
||||||
local id = self.ids[tv][v]
|
|
||||||
if not id then
|
|
||||||
id = self.maxIds[tv] + 1
|
|
||||||
self.maxIds[tv] = id
|
|
||||||
self.ids[tv][v] = id
|
|
||||||
end
|
|
||||||
return id
|
|
||||||
end
|
|
||||||
|
|
||||||
function Inspector:putKey(k)
|
|
||||||
if isIdentifier(k) then return self:puts(k) end
|
|
||||||
self:puts("[")
|
|
||||||
self:putValue(k)
|
|
||||||
self:puts("]")
|
|
||||||
end
|
|
||||||
|
|
||||||
function Inspector:putTable(t)
|
|
||||||
if t == inspect.KEY or t == inspect.METATABLE then
|
|
||||||
self:puts(tostring(t))
|
|
||||||
elseif self:alreadyVisited(t) then
|
|
||||||
self:puts('<table ', self:getId(t), '>')
|
|
||||||
elseif self.level >= self.depth then
|
|
||||||
self:puts('{...}')
|
|
||||||
else
|
|
||||||
if self.tableAppearances[t] > 1 then self:puts('<', self:getId(t), '>') end
|
|
||||||
|
|
||||||
local nonSequentialKeys, sequenceLength = getNonSequentialKeys(t)
|
|
||||||
local mt = getmetatable(t)
|
|
||||||
local toStringResult = getToStringResultSafely(t, mt)
|
|
||||||
|
|
||||||
self:puts('{')
|
|
||||||
self:down(function()
|
|
||||||
if toStringResult then
|
|
||||||
self:puts(' -- ', escape(toStringResult))
|
|
||||||
if sequenceLength >= 1 then self:tabify() end
|
|
||||||
end
|
|
||||||
|
|
||||||
local count = 0
|
|
||||||
for i=1, sequenceLength do
|
|
||||||
if count > 0 then self:puts(',') end
|
|
||||||
self:puts(' ')
|
|
||||||
self:putValue(t[i])
|
|
||||||
count = count + 1
|
|
||||||
end
|
|
||||||
|
|
||||||
for _,k in ipairs(nonSequentialKeys) do
|
|
||||||
if count > 0 then self:puts(',') end
|
|
||||||
self:tabify()
|
|
||||||
self:putKey(k)
|
|
||||||
self:puts(' = ')
|
|
||||||
self:putValue(t[k])
|
|
||||||
count = count + 1
|
|
||||||
end
|
|
||||||
|
|
||||||
if mt then
|
|
||||||
if count > 0 then self:puts(',') end
|
|
||||||
self:tabify()
|
|
||||||
self:puts('<metatable> = ')
|
|
||||||
self:putValue(mt)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
if #nonSequentialKeys > 0 or mt then -- result is multi-lined. Justify closing }
|
|
||||||
self:tabify()
|
|
||||||
elseif sequenceLength > 0 then -- array tables have one extra space before closing }
|
|
||||||
self:puts(' ')
|
|
||||||
end
|
|
||||||
|
|
||||||
self:puts('}')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function Inspector:putValue(v)
|
|
||||||
local tv = type(v)
|
|
||||||
|
|
||||||
if tv == 'string' then
|
|
||||||
self:puts(smartQuote(escape(v)))
|
|
||||||
elseif tv == 'number' or tv == 'boolean' or tv == 'nil' then
|
|
||||||
self:puts(tostring(v))
|
|
||||||
elseif tv == 'table' then
|
|
||||||
self:putTable(v)
|
|
||||||
else
|
|
||||||
self:puts('<',tv,' ',self:getId(v),'>')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-------------------------------------------------------------------
|
|
||||||
|
|
||||||
function inspect.inspect(root, options)
|
|
||||||
options = options or {}
|
|
||||||
|
|
||||||
local depth = options.depth or math.huge
|
|
||||||
local newline = options.newline or '\n'
|
|
||||||
local indent = options.indent or ' '
|
|
||||||
local process = options.process
|
|
||||||
|
|
||||||
if process then
|
|
||||||
root = processRecursive(process, root, {}, {})
|
|
||||||
end
|
|
||||||
|
|
||||||
local inspector = setmetatable({
|
|
||||||
depth = depth,
|
|
||||||
buffer = {},
|
|
||||||
level = 0,
|
|
||||||
ids = setmetatable({}, idsMetaTable),
|
|
||||||
maxIds = setmetatable({}, maxIdsMetaTable),
|
|
||||||
newline = newline,
|
|
||||||
indent = indent,
|
|
||||||
tableAppearances = countTableAppearances(root)
|
|
||||||
}, Inspector_mt)
|
|
||||||
|
|
||||||
inspector:putValue(root)
|
|
||||||
|
|
||||||
return table.concat(inspector.buffer)
|
|
||||||
end
|
|
||||||
|
|
||||||
setmetatable(inspect, { __call = function(_, ...) return inspect.inspect(...) end })
|
|
||||||
|
|
||||||
return inspect
|
|
||||||
|
|
@ -1,78 +0,0 @@
|
|||||||
local lg = love.graphics
|
|
||||||
local pop, inspect
|
|
||||||
|
|
||||||
local debugDraw = false
|
|
||||||
|
|
||||||
function love.load()
|
|
||||||
pop = require "pop"
|
|
||||||
|
|
||||||
w2 = pop.window(nil, "Window")
|
|
||||||
w2:move(100, 100)
|
|
||||||
w2:setWidth(500)
|
|
||||||
w2:move(-50, 80)
|
|
||||||
w2:setHeight(500)
|
|
||||||
w2:move(0, -175)
|
|
||||||
w2.title:align("center")
|
|
||||||
w2:position(0, 0)
|
|
||||||
w2:size(200, 120):position(90, 70)
|
|
||||||
w2:setClose(false)
|
|
||||||
local t2 = pop.text("Click here to toggle close\nbutton on this window."):setMargin(10):setColor(0,0,0)
|
|
||||||
t2.clicked = function()
|
|
||||||
w2:setClose(not w2:hasClose())
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
w2:addChild(t2)
|
|
||||||
end
|
|
||||||
|
|
||||||
function love.update(dt)
|
|
||||||
pop.update(dt)
|
|
||||||
end
|
|
||||||
|
|
||||||
function love.draw()
|
|
||||||
pop.draw()
|
|
||||||
|
|
||||||
if debugDraw then
|
|
||||||
pop.debugDraw()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function love.mousemoved(x, y, dx, dy)
|
|
||||||
pop.mousemoved(x, y, dx, dy)
|
|
||||||
end
|
|
||||||
|
|
||||||
function love.mousepressed(x, y, button)
|
|
||||||
pop.mousepressed(x, y, button)
|
|
||||||
end
|
|
||||||
|
|
||||||
function love.mousereleased(x, y, button)
|
|
||||||
pop.mousereleased(x, y, button)
|
|
||||||
end
|
|
||||||
|
|
||||||
function love.keypressed(key)
|
|
||||||
local handled = pop.keypressed(key)
|
|
||||||
|
|
||||||
if (key == "d") and (not handled) then
|
|
||||||
debugDraw = not debugDraw
|
|
||||||
end
|
|
||||||
|
|
||||||
if (key == "w") and (not handled) then
|
|
||||||
local w = pop.window()
|
|
||||||
w.title:align("center")
|
|
||||||
end
|
|
||||||
|
|
||||||
if (key == "p") and (not handled) then
|
|
||||||
pop.printElementStack()
|
|
||||||
end
|
|
||||||
|
|
||||||
if (key == "escape") and (not handled) then
|
|
||||||
love.event.quit()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function love.keyreleased(key)
|
|
||||||
pop.keyreleased(key)
|
|
||||||
end
|
|
||||||
|
|
||||||
function love.textinput(text)
|
|
||||||
pop.textinput(text)
|
|
||||||
end
|
|
143
demo/main.lua
143
demo/main.lua
@ -1,143 +0,0 @@
|
|||||||
local lg = love.graphics
|
|
||||||
local pop, inspect
|
|
||||||
|
|
||||||
local debugDraw = false
|
|
||||||
local videoFile = lg.newVideo("test.ogv") -- so we can loop playback
|
|
||||||
|
|
||||||
function love.load()
|
|
||||||
print(love.getVersion())
|
|
||||||
|
|
||||||
inspect = require "debug-lib/inspect"
|
|
||||||
pop = require "pop"
|
|
||||||
---[[
|
|
||||||
local c = pop.box():align("center", "center"):setSize(300, 300)
|
|
||||||
pop.box(c, {255, 0, 0, 255}):setSize(100, 50)
|
|
||||||
pop.box(c, {0, 255, 0, 255}):align("center"):setSize(100, 100)
|
|
||||||
pop.box(c, {0, 0, 255, 255}):align("right"):setSize(50, 100)
|
|
||||||
pop.box(c, {100, 100, 100, 255}):align("center", "center"):setSize(500, 100)
|
|
||||||
pop.box(c):align("center"):setSize(50, 500):move(0, -100)
|
|
||||||
pop.box(c, {255, 255, 0, 255}):align(false, "bottom"):setSize(100, 100)
|
|
||||||
pop.box(c, {255, 150, 0, 255}):align("center", "bottom"):setSize(100, 50)
|
|
||||||
pop.box(c, {0, 255, 255}):align("right", "bottom"):setSize(50, 100):move(-50)
|
|
||||||
pop.text(nil, "Here's some test text\n(with newlines)\nin the top left corner!")
|
|
||||||
pop.text(nil, "Here's some test text in the bottom right corner!"):align("right", "bottom")
|
|
||||||
pop.skin(pop.text("Here's easier-to-code test text in the center!"):align("center", "center", true)) -- 'true' means align to pixel!
|
|
||||||
w = pop.box(nil, {255, 255, 255, 255}):align(false, "bottom"):setSize(150, 150)
|
|
||||||
b = pop.box(w, {0, 0, 0, 255}):margin(5):setSize(100, 100)
|
|
||||||
--]]
|
|
||||||
|
|
||||||
--c:move(100)
|
|
||||||
pop.box({255, 0, 0, 255}):position(50, 500) -- testing streamlined_get_set extension & optional parents
|
|
||||||
--b:margin(2) -- testing streamlined_get_set extension
|
|
||||||
b:fill() -- testing fill!
|
|
||||||
|
|
||||||
w2 = pop.window(nil, "Window")
|
|
||||||
w2:move(100, 100)
|
|
||||||
w2:setWidth(500)
|
|
||||||
w2:move(-50, 80)
|
|
||||||
w2:setHeight(500)
|
|
||||||
w2:move(0, -175)
|
|
||||||
w2.title:align("center")
|
|
||||||
w2:position(0, 0)
|
|
||||||
w2:size(200, 120):position(90, 70)
|
|
||||||
w2:setClose(false)
|
|
||||||
local t2 = pop.text("Click here to toggle close\nbutton on this window."):setMargin(10):setColor(0,0,0)
|
|
||||||
t2.clicked = function()
|
|
||||||
w2:setClose(not w2:hasClose())
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
w2:addChild(t2)
|
|
||||||
|
|
||||||
local test = lg.newImage("test.png")
|
|
||||||
G = pop.element():align("right"):move(-2, 2)
|
|
||||||
a = pop.box(G, test):align("right")
|
|
||||||
b = pop.box(G, test):align("right"):move(-25):setWidth(40)
|
|
||||||
c = pop.box(G, test):align("right"):move(0, 25):setHeight(40)
|
|
||||||
|
|
||||||
print(a.horizontal, a.vertical)
|
|
||||||
print(b.horizontal, b.vertical)
|
|
||||||
print(c.horizontal, c.vertical)
|
|
||||||
|
|
||||||
local window = pop.window():align("center", "center"):setTitle("Welcome! This title is far too big!")
|
|
||||||
|
|
||||||
pop.window():setClose(false):setClose(true)
|
|
||||||
|
|
||||||
local video = pop.box():align("right", "bottom"):setBackground(videoFile):setSize(320/2, 240/2):move(-20, -20)
|
|
||||||
videoFile:play()
|
|
||||||
|
|
||||||
--TODO make debugDraw better
|
|
||||||
|
|
||||||
--[[
|
|
||||||
local all = pop.box()
|
|
||||||
for k,v in pairs(all) do
|
|
||||||
print(k, v)
|
|
||||||
end
|
|
||||||
print(all.__class.__name)
|
|
||||||
--]]
|
|
||||||
end
|
|
||||||
|
|
||||||
function love.update(dt)
|
|
||||||
pop.update(dt)
|
|
||||||
|
|
||||||
if not videoFile:isPlaying() then
|
|
||||||
videoFile:rewind()
|
|
||||||
videoFile:play() -- sometimes rewinding at the end of play fails to start a loop
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function love.draw()
|
|
||||||
pop.draw()
|
|
||||||
|
|
||||||
if debugDraw then
|
|
||||||
pop.debugDraw()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function love.mousemoved(x, y, dx, dy)
|
|
||||||
pop.mousemoved(x, y, dx, dy)
|
|
||||||
end
|
|
||||||
|
|
||||||
function love.mousepressed(x, y, button)
|
|
||||||
pop.mousepressed(x, y, button)
|
|
||||||
end
|
|
||||||
|
|
||||||
function love.mousereleased(x, y, button)
|
|
||||||
pop.mousereleased(x, y, button)
|
|
||||||
end
|
|
||||||
|
|
||||||
function love.keypressed(key)
|
|
||||||
local handled = pop.keypressed(key)
|
|
||||||
|
|
||||||
if (key == "d") and (not handled) then
|
|
||||||
debugDraw = not debugDraw
|
|
||||||
end
|
|
||||||
|
|
||||||
if (key == "w") and (not handled) then
|
|
||||||
local w = pop.window()
|
|
||||||
w.title:align("center")
|
|
||||||
end
|
|
||||||
|
|
||||||
if (key == "e") and (not handled) then
|
|
||||||
print("EVENTS:")
|
|
||||||
for k,v in pairs(pop.events) do
|
|
||||||
print(k, v)
|
|
||||||
end
|
|
||||||
print("END")
|
|
||||||
end
|
|
||||||
|
|
||||||
if (key == "p") and (not handled) then
|
|
||||||
pop.printElementTree()
|
|
||||||
end
|
|
||||||
|
|
||||||
if (key == "escape") and (not handled) then
|
|
||||||
love.event.quit()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function love.keyreleased(key)
|
|
||||||
pop.keyreleased(key)
|
|
||||||
end
|
|
||||||
|
|
||||||
function love.textinput(text)
|
|
||||||
pop.textinput(text)
|
|
||||||
end
|
|
@ -1,110 +0,0 @@
|
|||||||
local graphics
|
|
||||||
graphics = love.graphics
|
|
||||||
local sub, len
|
|
||||||
do
|
|
||||||
local _obj_0 = string
|
|
||||||
sub, len = _obj_0.sub, _obj_0.len
|
|
||||||
end
|
|
||||||
local path = sub(..., 1, len(...) - len("/box"))
|
|
||||||
local element = require(tostring(path) .. "/element")
|
|
||||||
local box
|
|
||||||
do
|
|
||||||
local _class_0
|
|
||||||
local _parent_0 = element
|
|
||||||
local _base_0 = {
|
|
||||||
draw = function(self)
|
|
||||||
if self.background then
|
|
||||||
if type(self.background) == "table" then
|
|
||||||
graphics.setColor(self.background)
|
|
||||||
graphics.rectangle("fill", self.x, self.y, self.w, self.h)
|
|
||||||
else
|
|
||||||
local w, h = self.background:getDimensions()
|
|
||||||
w = self.w / w
|
|
||||||
h = self.h / h
|
|
||||||
graphics.setColor(255, 255, 255, 255)
|
|
||||||
graphics.draw(self.background, self.x, self.y, 0, w, h)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
debugDraw = function(self)
|
|
||||||
graphics.setLineWidth(0.5)
|
|
||||||
graphics.setColor(0, 0, 0, 100)
|
|
||||||
graphics.rectangle("fill", self.x, self.y, self.w, self.h)
|
|
||||||
graphics.setColor(0, 0, 200, 200)
|
|
||||||
graphics.rectangle("line", self.x, self.y, self.w, self.h)
|
|
||||||
graphics.setColor(200, 200, 255, 255)
|
|
||||||
graphics.print("b", self.x, self.y)
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
setBackground = function(self, background)
|
|
||||||
self.background = background
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
getBackground = function(self)
|
|
||||||
return self.background
|
|
||||||
end,
|
|
||||||
setColor = function(self, r, g, b, a)
|
|
||||||
if a == nil then
|
|
||||||
a = 255
|
|
||||||
end
|
|
||||||
if type(r) == "table" then
|
|
||||||
self.background = r
|
|
||||||
else
|
|
||||||
self.background = {
|
|
||||||
r,
|
|
||||||
g,
|
|
||||||
b,
|
|
||||||
a
|
|
||||||
}
|
|
||||||
end
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
getColor = function(self)
|
|
||||||
if type(self.background) == "table" then
|
|
||||||
return unpack(self.background)
|
|
||||||
else
|
|
||||||
return error("Box \"" .. tostring(self) .. "\" doesn't have a color.")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
}
|
|
||||||
_base_0.__index = _base_0
|
|
||||||
setmetatable(_base_0, _parent_0.__base)
|
|
||||||
_class_0 = setmetatable({
|
|
||||||
__init = function(self, parent, background)
|
|
||||||
if background == nil then
|
|
||||||
background = false
|
|
||||||
end
|
|
||||||
_class_0.__parent.__init(self, parent)
|
|
||||||
self.w = 20
|
|
||||||
self.h = 20
|
|
||||||
self.background = background
|
|
||||||
end,
|
|
||||||
__base = _base_0,
|
|
||||||
__name = "box",
|
|
||||||
__parent = _parent_0
|
|
||||||
}, {
|
|
||||||
__index = function(cls, name)
|
|
||||||
local val = rawget(_base_0, name)
|
|
||||||
if val == nil then
|
|
||||||
local parent = rawget(cls, "__parent")
|
|
||||||
if parent then
|
|
||||||
return parent[name]
|
|
||||||
end
|
|
||||||
else
|
|
||||||
return val
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
__call = function(cls, ...)
|
|
||||||
local _self_0 = setmetatable({}, _base_0)
|
|
||||||
cls.__init(_self_0, ...)
|
|
||||||
return _self_0
|
|
||||||
end
|
|
||||||
})
|
|
||||||
_base_0.__class = _class_0
|
|
||||||
if _parent_0.__inherited then
|
|
||||||
_parent_0.__inherited(_parent_0, _class_0)
|
|
||||||
end
|
|
||||||
box = _class_0
|
|
||||||
return _class_0
|
|
||||||
end
|
|
@ -1,296 +0,0 @@
|
|||||||
local graphics
|
|
||||||
graphics = love.graphics
|
|
||||||
local floor
|
|
||||||
floor = math.floor
|
|
||||||
local insert, remove
|
|
||||||
do
|
|
||||||
local _obj_0 = table
|
|
||||||
insert, remove = _obj_0.insert, _obj_0.remove
|
|
||||||
end
|
|
||||||
local tonumber = tonumber
|
|
||||||
local element
|
|
||||||
do
|
|
||||||
local _class_0
|
|
||||||
local _base_0 = {
|
|
||||||
debugDraw = function(self)
|
|
||||||
graphics.setLineWidth(0.5)
|
|
||||||
graphics.setColor(0, 0, 0, 100)
|
|
||||||
graphics.rectangle("fill", self.x, self.y, self.w, self.h)
|
|
||||||
graphics.setColor(0, 200, 0, 200)
|
|
||||||
graphics.rectangle("line", self.x, self.y, self.w, self.h)
|
|
||||||
graphics.setColor(200, 255, 200, 255)
|
|
||||||
graphics.print("e", self.x, self.y)
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
addChild = function(self, child)
|
|
||||||
if child.parent then
|
|
||||||
child.parent:removeChild(child)
|
|
||||||
end
|
|
||||||
insert(self.child, child)
|
|
||||||
child.parent = self
|
|
||||||
child:align()
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
removeChild = function(self, child)
|
|
||||||
if tonumber(child) == child then
|
|
||||||
self.child[child].parent = false
|
|
||||||
return remove(self.child, child)
|
|
||||||
else
|
|
||||||
for k, v in ipairs(self.child) do
|
|
||||||
if v == child then
|
|
||||||
return remove(self.child, k)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return "Element \"" .. tostring(child) .. "\" is not a child of element \"" .. tostring(self) .. "\". Cannot remove it."
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
getChildren = function(self)
|
|
||||||
return self.child
|
|
||||||
end,
|
|
||||||
move = function(self, x, y)
|
|
||||||
if x then
|
|
||||||
self.x = self.x + x
|
|
||||||
end
|
|
||||||
if y then
|
|
||||||
self.y = self.y + y
|
|
||||||
end
|
|
||||||
for i = 1, #self.child do
|
|
||||||
if not (self.child[i].excludeMovement) then
|
|
||||||
self.child[i]:move(x, y)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
setPosition = function(self, x, y)
|
|
||||||
local oldX = self.x
|
|
||||||
local oldY = self.y
|
|
||||||
if x then
|
|
||||||
local _exp_0 = self.horizontal
|
|
||||||
if "left" == _exp_0 then
|
|
||||||
self.x = x
|
|
||||||
elseif "center" == _exp_0 then
|
|
||||||
self.x = x - self.w / 2
|
|
||||||
elseif "right" == _exp_0 then
|
|
||||||
self.x = x - self.w
|
|
||||||
end
|
|
||||||
else
|
|
||||||
x = oldX
|
|
||||||
end
|
|
||||||
if y then
|
|
||||||
local _exp_0 = self.vertical
|
|
||||||
if "top" == _exp_0 then
|
|
||||||
self.y = y
|
|
||||||
elseif "center" == _exp_0 then
|
|
||||||
self.y = y - self.h / 2
|
|
||||||
elseif "bottom" == _exp_0 then
|
|
||||||
self.y = y - self.h
|
|
||||||
end
|
|
||||||
else
|
|
||||||
y = oldY
|
|
||||||
end
|
|
||||||
for i = 1, #self.child do
|
|
||||||
self.child[i]:move(x - oldX, y - oldY)
|
|
||||||
end
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
getPosition = function(self)
|
|
||||||
local resultX = self.x
|
|
||||||
local resultY = self.y
|
|
||||||
local _exp_0 = self.horizontal
|
|
||||||
if "center" == _exp_0 then
|
|
||||||
resultX = resultX + (self.w / 2)
|
|
||||||
elseif "right" == _exp_0 then
|
|
||||||
resultY = resultY + self.w
|
|
||||||
end
|
|
||||||
local _exp_1 = self.vertical
|
|
||||||
if "center" == _exp_1 then
|
|
||||||
resultY = resultY + (self.h / 2)
|
|
||||||
elseif "bottom" == _exp_1 then
|
|
||||||
resultY = resultY + self.h
|
|
||||||
end
|
|
||||||
return resultX, resultY
|
|
||||||
end,
|
|
||||||
setSize = function(self, w, h)
|
|
||||||
if w then
|
|
||||||
local _exp_0 = self.horizontal
|
|
||||||
if "center" == _exp_0 then
|
|
||||||
self.x = self.x - ((w - self.w) / 2)
|
|
||||||
elseif "right" == _exp_0 then
|
|
||||||
self.x = self.x - (w - self.w)
|
|
||||||
end
|
|
||||||
self.w = w
|
|
||||||
end
|
|
||||||
if h then
|
|
||||||
local _exp_0 = self.vertical
|
|
||||||
if "center" == _exp_0 then
|
|
||||||
self.y = self.y - ((h - self.h) / 2)
|
|
||||||
elseif "bottom" == _exp_0 then
|
|
||||||
self.y = self.y - (h - self.h)
|
|
||||||
end
|
|
||||||
self.h = h
|
|
||||||
end
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
getSize = function(self)
|
|
||||||
return self.w, self.h
|
|
||||||
end,
|
|
||||||
setWidth = function(self, w)
|
|
||||||
local _exp_0 = self.horizontal
|
|
||||||
if "center" == _exp_0 then
|
|
||||||
self.x = self.x - ((w - self.w) / 2)
|
|
||||||
elseif "right" == _exp_0 then
|
|
||||||
self.x = self.x - (w - self.w)
|
|
||||||
end
|
|
||||||
self.w = w
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
getWidth = function(self)
|
|
||||||
return self.w
|
|
||||||
end,
|
|
||||||
setHeight = function(self, h)
|
|
||||||
local _exp_0 = self.vertical
|
|
||||||
if "center" == _exp_0 then
|
|
||||||
self.y = self.y - ((h - self.h) / 2)
|
|
||||||
elseif "bottom" == _exp_0 then
|
|
||||||
self.y = self.y - (h - self.h)
|
|
||||||
end
|
|
||||||
self.h = h
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
getHeight = function(self)
|
|
||||||
return self.h
|
|
||||||
end,
|
|
||||||
adjustSize = function(self, w, h)
|
|
||||||
local W, H = self:getSize()
|
|
||||||
if w then
|
|
||||||
W = W + w
|
|
||||||
end
|
|
||||||
if h then
|
|
||||||
H = H + h
|
|
||||||
end
|
|
||||||
self:setSize(W, H)
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
align = function(self, horizontal, vertical, toPixel)
|
|
||||||
if toPixel == nil then
|
|
||||||
toPixel = true
|
|
||||||
end
|
|
||||||
self:setAlignment(horizontal, vertical)
|
|
||||||
self.x = self.parent.x
|
|
||||||
self.y = self.parent.y
|
|
||||||
local _exp_0 = self.horizontal
|
|
||||||
if "left" == _exp_0 then
|
|
||||||
self.x = self.x + self.spacing
|
|
||||||
elseif "center" == _exp_0 then
|
|
||||||
self.x = self.x + ((self.parent.w - self.w) / 2)
|
|
||||||
elseif "right" == _exp_0 then
|
|
||||||
self.x = self.x + (self.parent.w - self.w - self.spacing)
|
|
||||||
end
|
|
||||||
local _exp_1 = self.vertical
|
|
||||||
if "top" == _exp_1 then
|
|
||||||
self.y = self.y + self.spacing
|
|
||||||
elseif "center" == _exp_1 then
|
|
||||||
self.y = self.y + ((self.parent.h - self.h) / 2)
|
|
||||||
elseif "bottom" == _exp_1 then
|
|
||||||
self.y = self.y + (self.parent.h - self.h - self.spacing)
|
|
||||||
end
|
|
||||||
if toPixel then
|
|
||||||
self.x = floor(self.x)
|
|
||||||
self.y = floor(self.y)
|
|
||||||
end
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
alignTo = function(self, element, horizontal, vertical, toPixel)
|
|
||||||
if toPixel == nil then
|
|
||||||
toPixel = true
|
|
||||||
end
|
|
||||||
local parent = self.parent
|
|
||||||
self.parent = element
|
|
||||||
self:align(horizontal, vertical, toPixel)
|
|
||||||
self.parent = parent
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
setAlignment = function(self, horizontal, vertical)
|
|
||||||
if horizontal then
|
|
||||||
self.horizontal = horizontal
|
|
||||||
end
|
|
||||||
if vertical then
|
|
||||||
self.vertical = vertical
|
|
||||||
end
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
getAlignment = function(self)
|
|
||||||
return self.horizontal, self.vertical
|
|
||||||
end,
|
|
||||||
setMargin = function(self, spacing)
|
|
||||||
self.spacing = spacing
|
|
||||||
self:align()
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
getMargin = function(self)
|
|
||||||
return self.spacing
|
|
||||||
end,
|
|
||||||
fill = function(self)
|
|
||||||
self.x = self.parent.x + self.spacing
|
|
||||||
self.y = self.parent.y + self.spacing
|
|
||||||
self.w = self.parent.w - self.spacing * 2
|
|
||||||
self.h = self.parent.h - self.spacing * 2
|
|
||||||
end,
|
|
||||||
delete = function(self)
|
|
||||||
for k, v in ipairs(self.child) do
|
|
||||||
v:delete()
|
|
||||||
end
|
|
||||||
self.parent:removeChild(self)
|
|
||||||
self = nil
|
|
||||||
return nil
|
|
||||||
end,
|
|
||||||
getVisibility = function(self)
|
|
||||||
return (not self.excludeDraw)
|
|
||||||
end,
|
|
||||||
setVisibility = function(self, isVisible)
|
|
||||||
self.excludeDraw = (not isVisible)
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
getStatic = function(self)
|
|
||||||
return self.excludeMovement
|
|
||||||
end,
|
|
||||||
setStatic = function(self, isStatic)
|
|
||||||
self.excludeMovement = isStatic
|
|
||||||
return self
|
|
||||||
end
|
|
||||||
}
|
|
||||||
_base_0.__index = _base_0
|
|
||||||
_class_0 = setmetatable({
|
|
||||||
__init = function(self, parent)
|
|
||||||
self.parent = parent
|
|
||||||
self.child = { }
|
|
||||||
self.w = 0
|
|
||||||
self.h = 0
|
|
||||||
self.spacing = 0
|
|
||||||
if parent then
|
|
||||||
self.x = parent.x
|
|
||||||
self.y = parent.y
|
|
||||||
else
|
|
||||||
self.x = 0
|
|
||||||
self.y = 0
|
|
||||||
end
|
|
||||||
self.horizontal = "left"
|
|
||||||
self.vertical = "top"
|
|
||||||
self.excludeDraw = false
|
|
||||||
self.excludeUpdate = false
|
|
||||||
self.excludeMovement = false
|
|
||||||
end,
|
|
||||||
__base = _base_0,
|
|
||||||
__name = "element"
|
|
||||||
}, {
|
|
||||||
__index = _base_0,
|
|
||||||
__call = function(cls, ...)
|
|
||||||
local _self_0 = setmetatable({}, _base_0)
|
|
||||||
cls.__init(_self_0, ...)
|
|
||||||
return _self_0
|
|
||||||
end
|
|
||||||
})
|
|
||||||
_base_0.__class = _class_0
|
|
||||||
element = _class_0
|
|
||||||
return _class_0
|
|
||||||
end
|
|
Binary file not shown.
Before Width: | Height: | Size: 303 B |
@ -1,154 +0,0 @@
|
|||||||
local graphics
|
|
||||||
graphics = love.graphics
|
|
||||||
local sub, len
|
|
||||||
do
|
|
||||||
local _obj_0 = string
|
|
||||||
sub, len = _obj_0.sub, _obj_0.len
|
|
||||||
end
|
|
||||||
local path = sub(..., 1, len(...) - len("/box"))
|
|
||||||
local element = require(tostring(path) .. "/element")
|
|
||||||
local text
|
|
||||||
do
|
|
||||||
local _class_0
|
|
||||||
local _parent_0 = element
|
|
||||||
local _base_0 = {
|
|
||||||
draw = function(self)
|
|
||||||
graphics.setColor(self.color)
|
|
||||||
graphics.setFont(self.font)
|
|
||||||
graphics.print(self.txt, self.x, self.y)
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
debugDraw = function(self)
|
|
||||||
graphics.setLineWidth(0.5)
|
|
||||||
graphics.setColor(0, 0, 0, 100)
|
|
||||||
graphics.rectangle("fill", self.x, self.y, self.w, self.h)
|
|
||||||
graphics.setColor(200, 0, 0, 200)
|
|
||||||
graphics.rectangle("line", self.x, self.y, self.w, self.h)
|
|
||||||
graphics.setColor(255, 200, 200, 255)
|
|
||||||
graphics.print("t", self.x, self.y)
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
setSize = function(self)
|
|
||||||
local w = self.font:getWidth(self.txt)
|
|
||||||
local h = self.font:getHeight() * (select(2, self.txt:gsub("\n", "\n")) + 1)
|
|
||||||
local _exp_0 = self.horizontal
|
|
||||||
if "center" == _exp_0 then
|
|
||||||
self.x = self.x - ((w - self.w) / 2)
|
|
||||||
elseif "right" == _exp_0 then
|
|
||||||
self.x = self.x - (w - self.w - self.spacing)
|
|
||||||
end
|
|
||||||
local _exp_1 = self.vertical
|
|
||||||
if "center" == _exp_1 then
|
|
||||||
self.y = self.y - ((h - self.h) / 2)
|
|
||||||
elseif "bottom" == _exp_1 then
|
|
||||||
self.y = self.y - (h - self.h - self.spacing)
|
|
||||||
end
|
|
||||||
self.w = w
|
|
||||||
self.h = h
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
setWidth = function(self)
|
|
||||||
self:setSize()
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
setHeight = function(self)
|
|
||||||
self:setSize()
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
setText = function(self, text)
|
|
||||||
if text == nil then
|
|
||||||
text = ""
|
|
||||||
end
|
|
||||||
self.txt = text
|
|
||||||
self:setSize()
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
getText = function(self)
|
|
||||||
return self.txt
|
|
||||||
end,
|
|
||||||
setFont = function(self, font)
|
|
||||||
self.font = font
|
|
||||||
self:setSize()
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
getFont = function(self)
|
|
||||||
return self.font
|
|
||||||
end,
|
|
||||||
setColor = function(self, r, g, b, a)
|
|
||||||
if a == nil then
|
|
||||||
a = 255
|
|
||||||
end
|
|
||||||
if type(r) == "table" then
|
|
||||||
self.color = r
|
|
||||||
else
|
|
||||||
self.color = {
|
|
||||||
r,
|
|
||||||
g,
|
|
||||||
b,
|
|
||||||
a
|
|
||||||
}
|
|
||||||
end
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
getColor = function(self)
|
|
||||||
return unpack(self.color)
|
|
||||||
end
|
|
||||||
}
|
|
||||||
_base_0.__index = _base_0
|
|
||||||
setmetatable(_base_0, _parent_0.__base)
|
|
||||||
_class_0 = setmetatable({
|
|
||||||
__init = function(self, parent, text, color)
|
|
||||||
if text == nil then
|
|
||||||
text = ""
|
|
||||||
end
|
|
||||||
if color == nil then
|
|
||||||
color = {
|
|
||||||
255,
|
|
||||||
255,
|
|
||||||
255,
|
|
||||||
255
|
|
||||||
}
|
|
||||||
end
|
|
||||||
_class_0.__parent.__init(self, parent)
|
|
||||||
self.font = graphics.newFont(14)
|
|
||||||
self:setText(text)
|
|
||||||
self.color = color
|
|
||||||
end,
|
|
||||||
__base = _base_0,
|
|
||||||
__name = "text",
|
|
||||||
__parent = _parent_0
|
|
||||||
}, {
|
|
||||||
__index = function(cls, name)
|
|
||||||
local val = rawget(_base_0, name)
|
|
||||||
if val == nil then
|
|
||||||
local parent = rawget(cls, "__parent")
|
|
||||||
if parent then
|
|
||||||
return parent[name]
|
|
||||||
end
|
|
||||||
else
|
|
||||||
return val
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
__call = function(cls, ...)
|
|
||||||
local _self_0 = setmetatable({}, _base_0)
|
|
||||||
cls.__init(_self_0, ...)
|
|
||||||
return _self_0
|
|
||||||
end
|
|
||||||
})
|
|
||||||
_base_0.__class = _class_0
|
|
||||||
local self = _class_0
|
|
||||||
self.wrap = function(pop)
|
|
||||||
return function(parent, ...)
|
|
||||||
if type(parent) == "string" then
|
|
||||||
return pop.create("text", nil, parent, ...)
|
|
||||||
else
|
|
||||||
return pop.create("text", parent, ...)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if _parent_0.__inherited then
|
|
||||||
_parent_0.__inherited(_parent_0, _class_0)
|
|
||||||
end
|
|
||||||
text = _class_0
|
|
||||||
return _class_0
|
|
||||||
end
|
|
@ -1,353 +0,0 @@
|
|||||||
local graphics, mouse
|
|
||||||
do
|
|
||||||
local _obj_0 = love
|
|
||||||
graphics, mouse = _obj_0.graphics, _obj_0.mouse
|
|
||||||
end
|
|
||||||
local insert, remove
|
|
||||||
do
|
|
||||||
local _obj_0 = table
|
|
||||||
insert, remove = _obj_0.insert, _obj_0.remove
|
|
||||||
end
|
|
||||||
local sub, len
|
|
||||||
do
|
|
||||||
local _obj_0 = string
|
|
||||||
sub, len = _obj_0.sub, _obj_0.len
|
|
||||||
end
|
|
||||||
local path = sub(..., 1, len(...) - len("/window"))
|
|
||||||
local element = require(tostring(path) .. "/element")
|
|
||||||
local box = require(tostring(path) .. "/box")
|
|
||||||
local text = require(tostring(path) .. "/text")
|
|
||||||
local closeImage = graphics.newImage(tostring(path) .. "/img/close.png")
|
|
||||||
local left = 1
|
|
||||||
local mousemoved_event = true
|
|
||||||
do
|
|
||||||
local major, minor, revision = love.getVersion()
|
|
||||||
if (major == 0) and (minor == 10) and ((revision == 0) or (revision == 1)) then
|
|
||||||
left = 1
|
|
||||||
elseif (major == 0) and (minor == 9) then
|
|
||||||
left = "l"
|
|
||||||
if revision == 1 then
|
|
||||||
mousemoved_event = false
|
|
||||||
end
|
|
||||||
else
|
|
||||||
print("elements/window: unrecognized LOVE version: " .. tostring(major) .. "." .. tostring(minor) .. "." .. tostring(revision))
|
|
||||||
print(" assuming LOVE version > 0.10.1 (there may be bugs)")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
local pop_ref = false
|
|
||||||
local window
|
|
||||||
do
|
|
||||||
local _class_0
|
|
||||||
local _parent_0 = element
|
|
||||||
local _base_0 = {
|
|
||||||
load = function(pop)
|
|
||||||
pop_ref = pop
|
|
||||||
end,
|
|
||||||
debugDraw = function(self)
|
|
||||||
graphics.setLineWidth(0.5)
|
|
||||||
graphics.setColor(0, 0, 0, 100)
|
|
||||||
graphics.rectangle("fill", self.x, self.y, self.w, self.h)
|
|
||||||
graphics.setColor(200, 0, 200, 200)
|
|
||||||
graphics.rectangle("line", self.x, self.y, self.w, self.h)
|
|
||||||
graphics.setColor(255, 200, 255, 255)
|
|
||||||
graphics.print("w", self.x, self.y)
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
addChild = function(self, child)
|
|
||||||
self.area:addChild(child)
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
removeChild = function(self, child)
|
|
||||||
local result = self.area:removeChild(child)
|
|
||||||
if result == self.area then
|
|
||||||
return self
|
|
||||||
elseif type(result) == "string" then
|
|
||||||
for k, v in ipairs(self.child) do
|
|
||||||
if v == child then
|
|
||||||
remove(self.child, k)
|
|
||||||
return self
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return "Element \"" .. tostring(child) .. "\" is not a child of window \"" .. tostring(self) .. "\". Cannot remove it."
|
|
||||||
else
|
|
||||||
return result
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
getChildren = function(self)
|
|
||||||
return self.area.child
|
|
||||||
end,
|
|
||||||
align = function(self, horizontal, vertical, toPixel)
|
|
||||||
_class_0.__parent.__base.align(self, horizontal, vertical, toPixel)
|
|
||||||
for i = 1, #self.child do
|
|
||||||
self.child[i]:align()
|
|
||||||
end
|
|
||||||
self.area:move(nil, self.head:getHeight())
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
setSize = function(self, w, h)
|
|
||||||
local x = 0
|
|
||||||
local y = 0
|
|
||||||
if w then
|
|
||||||
local _exp_0 = self.horizontal
|
|
||||||
if "center" == _exp_0 then
|
|
||||||
x = x - ((w - self.w) / 2)
|
|
||||||
elseif "right" == _exp_0 then
|
|
||||||
x = x - (w - self.w)
|
|
||||||
end
|
|
||||||
if self.close then
|
|
||||||
self.head:setWidth(w - self.head:getHeight())
|
|
||||||
else
|
|
||||||
self.head:setWidth(w)
|
|
||||||
end
|
|
||||||
self.area:setWidth(w)
|
|
||||||
self.w = w
|
|
||||||
self.x = self.x + x
|
|
||||||
self.title:align()
|
|
||||||
if self.close then
|
|
||||||
self.close:align()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if h then
|
|
||||||
h = h - self.head:getHeight()
|
|
||||||
local _exp_0 = self.vertical
|
|
||||||
if "center" == _exp_0 then
|
|
||||||
y = y - ((h - self.h) / 2)
|
|
||||||
elseif "right" == _exp_0 then
|
|
||||||
y = y - (h - self.h)
|
|
||||||
end
|
|
||||||
self.area:setHeight(h)
|
|
||||||
self.h = h + self.head:getHeight()
|
|
||||||
self.y = self.y + y
|
|
||||||
end
|
|
||||||
self.head:move(x, y)
|
|
||||||
self.area:move(x, y)
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
setWidth = function(self, w)
|
|
||||||
local x = 0
|
|
||||||
local _exp_0 = self.horizontal
|
|
||||||
if "center" == _exp_0 then
|
|
||||||
x = x - ((w - self.w) / 2)
|
|
||||||
elseif "right" == _exp_0 then
|
|
||||||
x = x - (w - self.w)
|
|
||||||
end
|
|
||||||
if self.close then
|
|
||||||
self.head:setWidth(w - self.head:getHeight())
|
|
||||||
else
|
|
||||||
self.head:setWidth(w)
|
|
||||||
end
|
|
||||||
self.area:setWidth(w)
|
|
||||||
self.w = w
|
|
||||||
self.x = self.x + x
|
|
||||||
self.title:align()
|
|
||||||
if self.close then
|
|
||||||
self.close:align()
|
|
||||||
end
|
|
||||||
self.head:move(x)
|
|
||||||
self.area:move(x)
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
setHeight = function(self, h)
|
|
||||||
local y = 0
|
|
||||||
h = h - self.head:getHeight()
|
|
||||||
local _exp_0 = self.vertical
|
|
||||||
if "center" == _exp_0 then
|
|
||||||
y = y - ((h - self.h) / 2)
|
|
||||||
elseif "right" == _exp_0 then
|
|
||||||
y = y - (h - self.h)
|
|
||||||
end
|
|
||||||
self.area:setHeight(h)
|
|
||||||
self.h = h + self.head:getHeight()
|
|
||||||
self.y = self.y + y
|
|
||||||
self.head:move(nil, y)
|
|
||||||
self.title:move(nil, y)
|
|
||||||
self.area:move(nil, y)
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
setTitle = function(self, title)
|
|
||||||
self.title:setText(title)
|
|
||||||
if self.titleOverflow == "trunicate" then
|
|
||||||
while self.title:getWidth() > self.head:getWidth() do
|
|
||||||
title = title:sub(1, -3)
|
|
||||||
self.title:setText(title .. "…")
|
|
||||||
end
|
|
||||||
elseif self.titleOverflow == "resize" then
|
|
||||||
if self.title:getWidth() > self.head:getWidth() then
|
|
||||||
self:setWidth(self.title:getWidth())
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
getTitle = function(self)
|
|
||||||
return self.title:getText()
|
|
||||||
end,
|
|
||||||
setTitleOverflow = function(self, method)
|
|
||||||
self.titleOverflow = method
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
getTitleOverflow = function(self)
|
|
||||||
return self.titleOverflow
|
|
||||||
end,
|
|
||||||
setClose = function(self, enabled)
|
|
||||||
if enabled then
|
|
||||||
self.close = box(self, closeImage)
|
|
||||||
self.close.clicked = function()
|
|
||||||
self:delete()
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
local height = self.head:getHeight()
|
|
||||||
self.close:align("right"):setSize(height, height)
|
|
||||||
self.head:setWidth(self.w - height)
|
|
||||||
self.title:align()
|
|
||||||
insert(self.child, self.close)
|
|
||||||
else
|
|
||||||
self.close:delete()
|
|
||||||
self.head:setWidth(self.w)
|
|
||||||
self.title:align()
|
|
||||||
self.close = false
|
|
||||||
end
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
hasClose = function(self)
|
|
||||||
if self.close then
|
|
||||||
return true
|
|
||||||
else
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
delete = function(self)
|
|
||||||
_class_0.__parent.__base.delete(self)
|
|
||||||
self.head = nil
|
|
||||||
self.title = nil
|
|
||||||
self.area = nil
|
|
||||||
self.close = nil
|
|
||||||
end
|
|
||||||
}
|
|
||||||
_base_0.__index = _base_0
|
|
||||||
setmetatable(_base_0, _parent_0.__base)
|
|
||||||
_class_0 = setmetatable({
|
|
||||||
__init = function(self, parent, title, tBackground, tColor, wBackground)
|
|
||||||
if title == nil then
|
|
||||||
title = "window"
|
|
||||||
end
|
|
||||||
if tBackground == nil then
|
|
||||||
tBackground = {
|
|
||||||
25,
|
|
||||||
180,
|
|
||||||
230,
|
|
||||||
255
|
|
||||||
}
|
|
||||||
end
|
|
||||||
if tColor == nil then
|
|
||||||
tColor = {
|
|
||||||
255,
|
|
||||||
255,
|
|
||||||
255,
|
|
||||||
255
|
|
||||||
}
|
|
||||||
end
|
|
||||||
if wBackground == nil then
|
|
||||||
wBackground = {
|
|
||||||
200,
|
|
||||||
200,
|
|
||||||
210,
|
|
||||||
255
|
|
||||||
}
|
|
||||||
end
|
|
||||||
_class_0.__parent.__init(self, parent)
|
|
||||||
self.head = box(self, tBackground)
|
|
||||||
self.title = text(self.head, title, tColor)
|
|
||||||
self.area = box(self, wBackground)
|
|
||||||
self.close = box(self, closeImage)
|
|
||||||
local height = self.title:getHeight()
|
|
||||||
self.head:setSize(self.w - height, height)
|
|
||||||
self.area:move(nil, height)
|
|
||||||
self.close:align("right"):setSize(height, height)
|
|
||||||
self:setSize(100, 80)
|
|
||||||
self.child = {
|
|
||||||
self.head,
|
|
||||||
self.title,
|
|
||||||
self.area,
|
|
||||||
self.close
|
|
||||||
}
|
|
||||||
self.titleOverflow = "trunicate"
|
|
||||||
self.area.mousepressed = function()
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
self.area.clicked = function()
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
self.close.clicked = function()
|
|
||||||
self:delete()
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
self.head.selected = false
|
|
||||||
if mousemoved_event then
|
|
||||||
self.head.mousemoved = function(self, x, y, dx, dy)
|
|
||||||
if self.selected then
|
|
||||||
self.parent:move(dx, dy)
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
self.head.mousepressed = function(self, x, y, button)
|
|
||||||
if button == left then
|
|
||||||
self.selected = true
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
else
|
|
||||||
self.head.mx = 0
|
|
||||||
self.head.my = 0
|
|
||||||
self.head.update = function(self)
|
|
||||||
local x, y = mouse.getPosition()
|
|
||||||
return self:setPosition(x - mx, y - my)
|
|
||||||
end
|
|
||||||
self.head.mousepressed = function(self, x, y, button)
|
|
||||||
if button == left then
|
|
||||||
self.selected = true
|
|
||||||
self.mx = x
|
|
||||||
self.my = y
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
self.head.mousereleased = function(self, x, y, button)
|
|
||||||
if button == left then
|
|
||||||
self.selected = false
|
|
||||||
pop_ref.focused = false
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
__base = _base_0,
|
|
||||||
__name = "window",
|
|
||||||
__parent = _parent_0
|
|
||||||
}, {
|
|
||||||
__index = function(cls, name)
|
|
||||||
local val = rawget(_base_0, name)
|
|
||||||
if val == nil then
|
|
||||||
local parent = rawget(cls, "__parent")
|
|
||||||
if parent then
|
|
||||||
return parent[name]
|
|
||||||
end
|
|
||||||
else
|
|
||||||
return val
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
__call = function(cls, ...)
|
|
||||||
local _self_0 = setmetatable({}, _base_0)
|
|
||||||
cls.__init(_self_0, ...)
|
|
||||||
return _self_0
|
|
||||||
end
|
|
||||||
})
|
|
||||||
_base_0.__class = _class_0
|
|
||||||
if _parent_0.__inherited then
|
|
||||||
_parent_0.__inherited(_parent_0, _class_0)
|
|
||||||
end
|
|
||||||
window = _class_0
|
|
||||||
return _class_0
|
|
||||||
end
|
|
@ -1,102 +0,0 @@
|
|||||||
local graphics
|
|
||||||
graphics = love.graphics
|
|
||||||
local sub, len
|
|
||||||
do
|
|
||||||
local _obj_0 = string
|
|
||||||
sub, len = _obj_0.sub, _obj_0.len
|
|
||||||
end
|
|
||||||
local path = sub(..., 1, len(...) - len("/extensions/streamlined_get_set"))
|
|
||||||
local element = require(tostring(path) .. "/elements/element")
|
|
||||||
local box = require(tostring(path) .. "/elements/box")
|
|
||||||
local text = require(tostring(path) .. "/elements/text")
|
|
||||||
element.__base.position = function(self, x, y)
|
|
||||||
if x or y then
|
|
||||||
return self:setPosition(x, y)
|
|
||||||
else
|
|
||||||
return self:getPosition()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
element.__base.size = function(self, w, h)
|
|
||||||
if w or h then
|
|
||||||
return self:setSize(w, h)
|
|
||||||
else
|
|
||||||
return self:getSize()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
element.__base.width = function(self, w)
|
|
||||||
if w then
|
|
||||||
return self:setWidth(w)
|
|
||||||
else
|
|
||||||
return self:getWidth()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
element.__base.height = function(self, h)
|
|
||||||
if h then
|
|
||||||
return self:setHeight(h)
|
|
||||||
else
|
|
||||||
return self:getHeight()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
element.__base.alignment = function(self, horizontal, vertical)
|
|
||||||
if horizontal or vertical then
|
|
||||||
return self:setAlignment(horizontal, vertical)
|
|
||||||
else
|
|
||||||
return self:getAlignment()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
element.__base.margin = function(self, m)
|
|
||||||
if m then
|
|
||||||
return self:setMargin(m)
|
|
||||||
else
|
|
||||||
return self:getMargin()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
element.__base.resize = element.__base.adjustSize
|
|
||||||
element.__base.visibility = function(self, v)
|
|
||||||
if v ~= nil then
|
|
||||||
return self:setVisibility(v)
|
|
||||||
else
|
|
||||||
return self:getVisibility()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
element.__base.show = function(self)
|
|
||||||
return self:setVisibility(true)
|
|
||||||
end
|
|
||||||
element.__base.hide = function(self)
|
|
||||||
return self:setVisibility(false)
|
|
||||||
end
|
|
||||||
element.__base.static = function(self, s)
|
|
||||||
if s ~= nil then
|
|
||||||
return self:setStatic(s)
|
|
||||||
else
|
|
||||||
return self:getStatic()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
box.__base.color = function(self, r, g, b, a)
|
|
||||||
if r or g or b or a then
|
|
||||||
return self:setColor(r, g, b, a)
|
|
||||||
else
|
|
||||||
return self:getColor()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
text.__base.text = function(self, text)
|
|
||||||
if text then
|
|
||||||
return self:setText(text)
|
|
||||||
else
|
|
||||||
return self:getText()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
text.__base.font = function(self, font)
|
|
||||||
if font then
|
|
||||||
return self:setFont(font)
|
|
||||||
else
|
|
||||||
return self:getFont()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
text.__base.color = function(self, r, g, b, a)
|
|
||||||
if r or g or b or a then
|
|
||||||
return self:setColor(r, g, b, a)
|
|
||||||
else
|
|
||||||
return self:getColor()
|
|
||||||
end
|
|
||||||
end
|
|
@ -1,291 +0,0 @@
|
|||||||
local pop = {
|
|
||||||
_VERSION = 'Pop.Box v0.0.0',
|
|
||||||
_DESCRIPTION = 'GUI library for LOVE, designed for ease of use',
|
|
||||||
_URL = 'http://github.com/Guard13007/Pop.Box',
|
|
||||||
_LICENSE = 'The MIT License (MIT)',
|
|
||||||
_AUTHOR = 'Paul Liverman III'
|
|
||||||
}
|
|
||||||
if not (love.getVersion) then
|
|
||||||
error("Pop.Box only supports LOVE versions >= 0.9.1")
|
|
||||||
end
|
|
||||||
local filesystem, graphics
|
|
||||||
do
|
|
||||||
local _obj_0 = love
|
|
||||||
filesystem, graphics = _obj_0.filesystem, _obj_0.graphics
|
|
||||||
end
|
|
||||||
local insert
|
|
||||||
insert = table.insert
|
|
||||||
local inheritsFromElement
|
|
||||||
inheritsFromElement = require(tostring(...) .. "/util").inheritsFromElement
|
|
||||||
local path = ...
|
|
||||||
pop.elements = { }
|
|
||||||
pop.skins = { }
|
|
||||||
pop.screen = false
|
|
||||||
pop.focused = false
|
|
||||||
pop.load = function()
|
|
||||||
local elements = filesystem.getDirectoryItems(tostring(path) .. "/elements")
|
|
||||||
for i = 1, #elements do
|
|
||||||
local _continue_0 = false
|
|
||||||
repeat
|
|
||||||
if not (elements[i]:sub(-4) == ".lua") then
|
|
||||||
_continue_0 = true
|
|
||||||
break
|
|
||||||
end
|
|
||||||
local name = elements[i]:sub(1, -5)
|
|
||||||
pop.elements[name] = require(tostring(path) .. "/elements/" .. tostring(name))
|
|
||||||
if pop.elements[name].load then
|
|
||||||
pop.elements[name].load(pop)
|
|
||||||
end
|
|
||||||
print("element loaded: \"" .. tostring(name) .. "\"")
|
|
||||||
if not (pop[name]) then
|
|
||||||
if pop.elements[name].wrap then
|
|
||||||
pop[name] = pop.elements[name].wrap(pop)
|
|
||||||
else
|
|
||||||
pop[name] = function(...)
|
|
||||||
return pop.create(name, ...)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
print("wrapper created: \"pop." .. tostring(name) .. "()\"")
|
|
||||||
end
|
|
||||||
_continue_0 = true
|
|
||||||
until true
|
|
||||||
if not _continue_0 then
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
local skins = filesystem.getDirectoryItems(tostring(path) .. "/skins")
|
|
||||||
for i = 1, #skins do
|
|
||||||
local _continue_0 = false
|
|
||||||
repeat
|
|
||||||
if not (skins[i]:sub(-4) == ".lua") then
|
|
||||||
_continue_0 = true
|
|
||||||
break
|
|
||||||
end
|
|
||||||
local name = skins[i]:sub(1, -5)
|
|
||||||
pop.skins[name] = require(tostring(path) .. "/skins/" .. tostring(name))
|
|
||||||
print("skin loaded: \"" .. tostring(name) .. "\"")
|
|
||||||
_continue_0 = true
|
|
||||||
until true
|
|
||||||
if not _continue_0 then
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
local extensions = filesystem.getDirectoryItems(tostring(path) .. "/extensions")
|
|
||||||
for i = 1, #extensions do
|
|
||||||
local _continue_0 = false
|
|
||||||
repeat
|
|
||||||
if not (extensions[i]:sub(-4) == ".lua") then
|
|
||||||
_continue_0 = true
|
|
||||||
break
|
|
||||||
end
|
|
||||||
local name = extensions[i]:sub(1, -5)
|
|
||||||
require(tostring(path) .. "/extensions/" .. tostring(name))
|
|
||||||
print("extension loaded: \"" .. tostring(name) .. "\"")
|
|
||||||
_continue_0 = true
|
|
||||||
until true
|
|
||||||
if not _continue_0 then
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
pop.screen = pop.create("element", false):setSize(graphics.getWidth(), graphics.getHeight())
|
|
||||||
return print("created \"pop.screen\"")
|
|
||||||
end
|
|
||||||
pop.create = function(element, parent, ...)
|
|
||||||
if parent == nil then
|
|
||||||
parent = pop.screen
|
|
||||||
end
|
|
||||||
if inheritsFromElement(parent) then
|
|
||||||
element = pop.elements[element](parent, ...)
|
|
||||||
insert(parent.child, element)
|
|
||||||
elseif parent == false then
|
|
||||||
element = pop.elements[element](false, ...)
|
|
||||||
else
|
|
||||||
element = pop.elements[element](pop.screen, parent, ...)
|
|
||||||
insert(pop.screen.child, element)
|
|
||||||
end
|
|
||||||
return element
|
|
||||||
end
|
|
||||||
pop.update = function(dt, element)
|
|
||||||
if element == nil then
|
|
||||||
element = pop.screen
|
|
||||||
end
|
|
||||||
if not (element.excludeUpdate) then
|
|
||||||
if element.update then
|
|
||||||
element:update(dt)
|
|
||||||
end
|
|
||||||
for i = 1, #element.child do
|
|
||||||
pop.update(dt, element.child[i])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
pop.draw = function(element)
|
|
||||||
if element == nil then
|
|
||||||
element = pop.screen
|
|
||||||
end
|
|
||||||
if not (element.excludeDraw) then
|
|
||||||
if element.draw then
|
|
||||||
element:draw()
|
|
||||||
end
|
|
||||||
for i = 1, #element.child do
|
|
||||||
pop.draw(element.child[i])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
pop.mousemoved = function(x, y, dx, dy)
|
|
||||||
if pop.focused and pop.focused.mousemoved then
|
|
||||||
return pop.focused:mousemoved(x, y, dx, dy)
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
pop.mousepressed = function(x, y, button, element)
|
|
||||||
if not (element) then
|
|
||||||
print("mousepressed", x, y, button)
|
|
||||||
element = pop.screen
|
|
||||||
end
|
|
||||||
local handled = false
|
|
||||||
if (x >= element.x) and (x <= element.x + element.w) and (y >= element.y) and (y <= element.y + element.h) then
|
|
||||||
for i = #element.child, 1, -1 do
|
|
||||||
do
|
|
||||||
handled = pop.mousepressed(x, y, button, element.child[i])
|
|
||||||
if handled then
|
|
||||||
return handled
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if not (handled) then
|
|
||||||
if element.mousepressed and (not element.excludeDraw) then
|
|
||||||
do
|
|
||||||
handled = element:mousepressed(x - element.x, y - element.y, button)
|
|
||||||
if handled then
|
|
||||||
pop.focused = element
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return handled
|
|
||||||
end
|
|
||||||
pop.mousereleased = function(x, y, button, element)
|
|
||||||
local clickedHandled = false
|
|
||||||
local mousereleasedHandled = false
|
|
||||||
if element then
|
|
||||||
if (x >= element.x) and (x <= element.x + element.w) and (y >= element.y) and (y <= element.y + element.h) then
|
|
||||||
for i = #element.child, 1, -1 do
|
|
||||||
clickedHandled, mousereleasedHandled = pop.mousereleased(x, y, button, element.child[i])
|
|
||||||
if clickedHandled or mousereleasedHandled then
|
|
||||||
return clickedHandled, mousereleasedHandled
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if not (clickedHandled or mousereleasedHandled) then
|
|
||||||
if element.clicked and (not element.excludeDraw) then
|
|
||||||
clickedHandled = element:clicked(x - element.x, y - element.y, button)
|
|
||||||
end
|
|
||||||
if element.mousereleased then
|
|
||||||
mousereleasedHandled = element:mousereleased(x - element.x, y - element.y, button)
|
|
||||||
end
|
|
||||||
if clickedHandled then
|
|
||||||
pop.focused = element
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
print("mousereleased", x, y, button)
|
|
||||||
pop.mousereleased(x, y, button, pop.screen)
|
|
||||||
end
|
|
||||||
return clickedHandled, mousereleasedHandled
|
|
||||||
end
|
|
||||||
pop.keypressed = function(key)
|
|
||||||
print("keypressed", key)
|
|
||||||
local element = pop.focused
|
|
||||||
if element and element.keypressed and (not element.excludeDraw) then
|
|
||||||
return element.keypressed(key)
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
pop.keyreleased = function(key)
|
|
||||||
print("keyreleased", key)
|
|
||||||
local element = pop.focused
|
|
||||||
if element and element.keyreleased then
|
|
||||||
return element.keyreleased(key)
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
pop.textinput = function(text)
|
|
||||||
print("textinput", text)
|
|
||||||
local element = pop.focused
|
|
||||||
if element and element.textinput and (not element.excludeDraw) then
|
|
||||||
return element.textinput(text)
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
pop.skin = function(element, skin, depth)
|
|
||||||
if element == nil then
|
|
||||||
element = pop.screen
|
|
||||||
end
|
|
||||||
if skin == nil then
|
|
||||||
skin = pop.skins.default
|
|
||||||
end
|
|
||||||
if element.background and skin.background then
|
|
||||||
element.background = skin.background
|
|
||||||
end
|
|
||||||
if element.color and skin.color then
|
|
||||||
element.color = skin.color
|
|
||||||
end
|
|
||||||
if element.font and skin.font then
|
|
||||||
element.font = skin.font
|
|
||||||
end
|
|
||||||
if not (depth or (depth == 0)) then
|
|
||||||
if depth == tonumber(depth) then
|
|
||||||
for i = 1, #element.child do
|
|
||||||
pop.skin(element.child[i], skin, depth - 1)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
for i = 1, #element.child do
|
|
||||||
pop.skin(element.child[i], skin, false)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
pop.debugDraw = function(element)
|
|
||||||
if element == nil then
|
|
||||||
element = pop.screen
|
|
||||||
end
|
|
||||||
if element.debugDraw then
|
|
||||||
element:debugDraw()
|
|
||||||
else
|
|
||||||
graphics.setLineWidth(1)
|
|
||||||
graphics.setLineColor(0, 0, 0, 100)
|
|
||||||
graphics.rectangle("fill", element.x, element.y, element.w, element.h)
|
|
||||||
graphics.setColor(150, 150, 150, 150)
|
|
||||||
graphics.rectangle("line", element.x, element.y, element.w, element.h)
|
|
||||||
graphics.setColor(200, 200, 200, 255)
|
|
||||||
graphics.print(".", element.x, element.y)
|
|
||||||
end
|
|
||||||
for i = 1, #element.child do
|
|
||||||
pop.debugDraw(element.child[i])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
pop.printElementTree = function(element, depth)
|
|
||||||
if element == nil then
|
|
||||||
element = pop.screen
|
|
||||||
end
|
|
||||||
if depth == nil then
|
|
||||||
depth = 0
|
|
||||||
end
|
|
||||||
local cls = element.__class.__name
|
|
||||||
if cls == "text" then
|
|
||||||
cls = cls .. " (\"" .. tostring(element:getText():gsub("\n", "\\n")) .. "\")"
|
|
||||||
elseif cls == "box" then
|
|
||||||
local bg = element:getBackground()
|
|
||||||
if type(bg) == "table" then
|
|
||||||
bg = tostring(bg[1]) .. ", " .. tostring(bg[2]) .. ", " .. tostring(bg[3]) .. ", " .. tostring(bg[4])
|
|
||||||
end
|
|
||||||
cls = cls .. " (" .. tostring(bg) .. ")"
|
|
||||||
end
|
|
||||||
print(string.rep("-", depth) .. " " .. tostring(cls))
|
|
||||||
for i = 1, #element.child do
|
|
||||||
pop.printElementStack(element.child[i], depth + 1)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
pop.load()
|
|
||||||
return pop
|
|
@ -1,17 +0,0 @@
|
|||||||
local graphics
|
|
||||||
graphics = love.graphics
|
|
||||||
return {
|
|
||||||
background = {
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
220
|
|
||||||
},
|
|
||||||
color = {
|
|
||||||
255,
|
|
||||||
255,
|
|
||||||
255,
|
|
||||||
250
|
|
||||||
},
|
|
||||||
font = graphics.newFont(14)
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
local inheritsFromElement
|
|
||||||
inheritsFromElement = function(object)
|
|
||||||
if object and object.__class then
|
|
||||||
local cls = object.__class
|
|
||||||
if cls.__name == "element" then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
while cls.__parent do
|
|
||||||
cls = cls.__parent
|
|
||||||
if cls.__name == "element" then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
return {
|
|
||||||
inheritsFromElement = inheritsFromElement
|
|
||||||
}
|
|
BIN
demo/test.ogv
BIN
demo/test.ogv
Binary file not shown.
BIN
demo/test.png
BIN
demo/test.png
Binary file not shown.
Before Width: | Height: | Size: 355 B |
@ -1,15 +0,0 @@
|
|||||||
# Supported Drawables
|
|
||||||
|
|
||||||
Pop.Box supports three [Drawables][1]: Canvas, Image, and Video.
|
|
||||||
|
|
||||||
**Note**: Video and Canvas support are untested.
|
|
||||||
|
|
||||||
Additionally, in the place of a Drawable, you can use `false` to not render
|
|
||||||
anything, or a table of color values. The color values should be in the format
|
|
||||||
LÖVE uses (`{red, green, blue, alpha}`, see [love.graphics.setColor][2]).
|
|
||||||
|
|
||||||
(The alpha value is optional, but not using an alpha is likely to mess up your
|
|
||||||
rendering if an alpha is used *anywhere else*.)
|
|
||||||
|
|
||||||
[1]: https://love2d.org/wiki/Drawable
|
|
||||||
[2]: https://love2d.org/wiki/love.graphics.setColor
|
|
@ -1,31 +0,0 @@
|
|||||||
# Elements
|
|
||||||
|
|
||||||
Elements are the core of Pop.Box.
|
|
||||||
|
|
||||||
Once `pop` has been required, you can create elements and interact with them.
|
|
||||||
Most elements can be created like this: `local box = pop.box(...)`
|
|
||||||
|
|
||||||
However, if an element's name clashes with a function name used in Pop.Box, you
|
|
||||||
will have to use `pop.create(type, ...)` where `type` is a string naming the
|
|
||||||
element type. (No standard elements do this.)
|
|
||||||
|
|
||||||
When creating an element, the first argument is its parent element. If the first
|
|
||||||
argument is not an element, it will be treated as the second argument. If it is
|
|
||||||
`false`, then an element with no parent will be created.
|
|
||||||
|
|
||||||
When no parent is specified, an element's parent is `pop.screen`, which is the
|
|
||||||
top-level element of Pop.Box. (This behavior can be modified by custom elements,
|
|
||||||
so check their documentation.)
|
|
||||||
|
|
||||||
## Available Elements
|
|
||||||
|
|
||||||
- [Element][1] (The base of all elements, and useful for alignment.)
|
|
||||||
- [Box][2] (A box, can be colored, or display a [supported Drawable][3].)
|
|
||||||
- [Text][4] (Plain text, no special features. Useful for basic labels and such.)
|
|
||||||
- [Window][5] (A movable window. Has a title and area for other elements.)
|
|
||||||
|
|
||||||
[1]: ./elements/element.md
|
|
||||||
[2]: ./elements/box.md
|
|
||||||
[3]: ./Drawables.md
|
|
||||||
[4]: ./elements/text.md
|
|
||||||
[5]: ./elements/window.md
|
|
@ -1,23 +0,0 @@
|
|||||||
# Excludes
|
|
||||||
|
|
||||||
Any element can have a few boolean values set to exclude it from normal
|
|
||||||
operations for movement, rendering, and updating. Simply set the appropriate
|
|
||||||
value to a true value.
|
|
||||||
|
|
||||||
Note that any element using one of these excludes its children as well.
|
|
||||||
|
|
||||||
- `excludeMovement` Excludes movement caused by a parent being moved.
|
|
||||||
- `excludeUpdate` Excludes an element from being updated (by `pop.update()`).
|
|
||||||
- `excludeDraw` Excludes being rendered (by `pop.draw()`).
|
|
||||||
|
|
||||||
**Note**: `excludeDraw` also excludes an element from accepting the following
|
|
||||||
events:
|
|
||||||
|
|
||||||
- `mousepressed`
|
|
||||||
- `clicked`
|
|
||||||
- `keypressed`
|
|
||||||
- `textinput`
|
|
||||||
|
|
||||||
The reason for this is that it wouldn't make sense for an invisible element to
|
|
||||||
be capturing input. However, some events are passed through in case an element
|
|
||||||
becomes invisible while processing input.
|
|
@ -1,14 +0,0 @@
|
|||||||
# Extensions
|
|
||||||
|
|
||||||
Extensions are simply a way for custom code to be run after loading elements and
|
|
||||||
skins. Simply place a `.lua` file in the `extensions` directory, and it will be
|
|
||||||
required.
|
|
||||||
|
|
||||||
## Standard Extensions
|
|
||||||
|
|
||||||
There is only one standard extension, which modifies element classes to add a
|
|
||||||
more convenient getter/setter method to most get/set methods. For example,
|
|
||||||
instead of `element:getSize()`, just call `element:size()`. Instead of
|
|
||||||
`element:setSize(w, h)`, call `element:size(w, h)`.
|
|
||||||
|
|
||||||
This is mostly for a demo of what can be possible, but also might be useful.
|
|
54
docs/Pop.md
54
docs/Pop.md
@ -1,54 +0,0 @@
|
|||||||
# Pop Module
|
|
||||||
|
|
||||||
This is the main module that allows you to access everything else in Pop.Box.
|
|
||||||
Simply require it (`local pop = require "pop"`) and define LÖVE callbacks for:
|
|
||||||
|
|
||||||
- `pop.update(dt)`
|
|
||||||
- `pop.draw()`
|
|
||||||
- `pop.mousemoved(x, y, dx, dy)` (when using LÖVE 0.10.0 or later)
|
|
||||||
- `pop.mousepressed(x, y, button)`
|
|
||||||
- `pop.mousereleased(x, y, button)`
|
|
||||||
- `pop.keypressed(key)`
|
|
||||||
- `pop.keyreleased(key)`
|
|
||||||
- `pop.textinput(text)`
|
|
||||||
|
|
||||||
Every callback returns `true`/`false` for whether or not the event was handled.
|
|
||||||
For example, using the `mousepressed` event handler:
|
|
||||||
|
|
||||||
```lua
|
|
||||||
function love.mousepressed(x, y, button)
|
|
||||||
local handled = pop.mousepressed(x, y, button)
|
|
||||||
if not handled then
|
|
||||||
-- do something useful
|
|
||||||
end
|
|
||||||
end
|
|
||||||
```
|
|
||||||
|
|
||||||
## Creating Elements
|
|
||||||
|
|
||||||
Once `pop` has been required, you can create [Elements][1] and interact with
|
|
||||||
them. Most elements can be created like this: `local box = pop.box(...)`
|
|
||||||
|
|
||||||
For more information, see the [Elements documentation][1].
|
|
||||||
|
|
||||||
## Skinning Elements
|
|
||||||
|
|
||||||
See the [Skins][2] documentation.
|
|
||||||
|
|
||||||
## Custom Elements/Skins/Extensions
|
|
||||||
|
|
||||||
Any `.lua` file placed in the `elements`, `skins`, and `extensions` directories
|
|
||||||
within the module will be loaded and available as appropriate. See the
|
|
||||||
documentation on each for how to make them:
|
|
||||||
|
|
||||||
- [Elements][1]
|
|
||||||
- [Skins][2]
|
|
||||||
- [Extensions][3]
|
|
||||||
|
|
||||||
Also of use, there is a separate set of docs about how Pop.Box works under the
|
|
||||||
surface: [Pop Module (dev)][4]
|
|
||||||
|
|
||||||
[1]: ./Elements.md
|
|
||||||
[2]: ./Skins.md
|
|
||||||
[3]: ./Extensions.md
|
|
||||||
[4]: ./dev/Pop.md
|
|
@ -1,37 +0,0 @@
|
|||||||
# Skins
|
|
||||||
|
|
||||||
**Note**: This system is mostly an after-thought right now, and will probably
|
|
||||||
be replaced with something else entirely.
|
|
||||||
|
|
||||||
Skins are simple tables containing information to style a variety of elements.
|
|
||||||
Use `pop.skin()` to apply a skin to an element and its children. Skins are
|
|
||||||
loaded from the `skins` directory.
|
|
||||||
|
|
||||||
**Note**: Skins are only applied on elements as-is. You can't change elements
|
|
||||||
added in the future by setting a skin, or change a skin to modify elements that
|
|
||||||
have had it applied. In the future, I might change this. (This skinning system
|
|
||||||
is basically a placeholder.)
|
|
||||||
|
|
||||||
Usage: `pop.skin(element, skin, depth)`
|
|
||||||
|
|
||||||
- `element` is the element to start with.
|
|
||||||
- `skin` is the skin (a table).
|
|
||||||
- `depth` is how many levels of children of the element should be skinned.
|
|
||||||
Defaults to skinning as many levels of children as there are.
|
|
||||||
|
|
||||||
Alternately, you can think of depth as a boolean for "don't recurse". By
|
|
||||||
setting it to `true`, you can stop skinning children. `false` (and default
|
|
||||||
behavior) will skin all levels of children.
|
|
||||||
|
|
||||||
## What's inside a skin
|
|
||||||
|
|
||||||
- `color` - A table of RGBA values (see [love.graphics.setColor][2]), used as a
|
|
||||||
foreground color (currently for `text` elements only).
|
|
||||||
- `background` - A [supported Drawable][4], used for backgrounds (currently
|
|
||||||
used on `box` elements only).
|
|
||||||
- `font` - A [Font][5].
|
|
||||||
|
|
||||||
[2]: https://love2d.org/wiki/love.graphics.setColor
|
|
||||||
[3]: ./Pop.md
|
|
||||||
[4]: ./Drawables.md
|
|
||||||
[5]: https://love2d.org/wiki/Font
|
|
@ -1,15 +0,0 @@
|
|||||||
# Pop Module (dev)
|
|
||||||
|
|
||||||
(This document focuses on the structure and code of Pop.Box, not how to use it.
|
|
||||||
See the [regular documentation][1] for that.)
|
|
||||||
|
|
||||||
TODO: Write me.
|
|
||||||
|
|
||||||
## Notes
|
|
||||||
|
|
||||||
- `pop.mousereleased()` Handling a click maybe should *not* check bounds.
|
|
||||||
Handling a mouse release should maybe *not* check for `excludeDraw`. If an
|
|
||||||
element was already selected and then went invisible, I'm probably breaking
|
|
||||||
things worse by doing this. This has been changed.
|
|
||||||
|
|
||||||
[1]: ../Pop.md
|
|
@ -1,4 +0,0 @@
|
|||||||
- `addChild()` Adds children to `@window` instead of itself. This may cause
|
|
||||||
issues with expectation vs result. A user expects when using `addChild()` that
|
|
||||||
an element will be a direct child of `window`, not that it will end up in a
|
|
||||||
sub-element.
|
|
@ -1,17 +0,0 @@
|
|||||||
# box
|
|
||||||
|
|
||||||
The box element is a rectangle that has a [supported Drawable][1] as its
|
|
||||||
background.
|
|
||||||
|
|
||||||
## Methods
|
|
||||||
|
|
||||||
- `setBackground(background)` Using a supported Drawable (see above), set the
|
|
||||||
background.
|
|
||||||
- `getBackground()` Returns the background in use.
|
|
||||||
- `setColor(red, green, blue, alpha)` Sets the background to the specified
|
|
||||||
color. `alpha` is optional and defaults to `255`. Alternately, pass a table of
|
|
||||||
color values (ex: `{red, green, blue, alpha}`).
|
|
||||||
- `getColor()` Returns red, green, blue, and alpha color values of background.
|
|
||||||
Errors if the background is not a color.
|
|
||||||
|
|
||||||
[1]: ../Drawables.md
|
|
@ -1,62 +0,0 @@
|
|||||||
# element
|
|
||||||
|
|
||||||
This is the base of all elements, and useful for alignment purposes. It is also
|
|
||||||
the element type used for `pop.screen` (the top-level element of Pop.Box). All
|
|
||||||
methods here are available on all other elements (any differences are noted on
|
|
||||||
their documentation pages).
|
|
||||||
|
|
||||||
## Alignment
|
|
||||||
|
|
||||||
All elements have a `horizontal` and `vertical` alignment property. These modify
|
|
||||||
how elements are aligned and how positions are handled. For example, an element
|
|
||||||
aligned to the top-right will return the position of the top-right corner when
|
|
||||||
calling `getPosition()`.
|
|
||||||
|
|
||||||
- `horizontal` can be `left`, `center`, or `right`. Defaults to `left`.
|
|
||||||
- `vertical` can be `top`, `center`, or `bottom`. Defaults to `top`.
|
|
||||||
|
|
||||||
## Methods
|
|
||||||
|
|
||||||
Every method that does not return a value returns the element itself, so that
|
|
||||||
you can chain method calls (ex: `box:setSize(100, 50):align("right")`).
|
|
||||||
|
|
||||||
- `addChild(child)` Adds a child element.
|
|
||||||
- `removeChild(child)` Removes child element by reference or index. If `child`
|
|
||||||
is a number, it will return the child at that index (after removing it).
|
|
||||||
- `getChildren()` Returns a numerically indexed table of child elements.
|
|
||||||
- `move(x, y)` Moves the element (and its children) by specified values.
|
|
||||||
Parameters optional. (Children can exclude being moved with their parent. See
|
|
||||||
[Excludes][1].)
|
|
||||||
- `setPosition(x, y)` Sets position of the element (and its children) based on
|
|
||||||
the alignment of the element. Parameters optional. (Children can exclude being
|
|
||||||
moved with their parent. See [Excludes][1].)
|
|
||||||
- `getPosition()` Returns x/y position of the element based on its alignment.
|
|
||||||
- `setSize(w, h)` Sets the width/height of the element, element keeps "in-place"
|
|
||||||
based on its alignment. (For example, a right-aligned element will grow to the
|
|
||||||
left.) Parameters optional.
|
|
||||||
- `getSize()` Returns the width/height of the element.
|
|
||||||
- `setWidth(w)` Sets the width of the element. Element stays "in-place" based on
|
|
||||||
its alignment.
|
|
||||||
- `getWidth()` Returns the width of the element.
|
|
||||||
- `setHeight(h)` Sets the height of the element. Element stays "in-place" based
|
|
||||||
on its alignment.
|
|
||||||
- `getHeight()` Returns the height of the element.
|
|
||||||
- `adjustSize(w, h)` Grows the element by a relative width/height. Element stays
|
|
||||||
"in-place" based on its alignment.
|
|
||||||
- `align(horizontal, vertical, toPixel)` Aligns the element based on its margin
|
|
||||||
and parent. `toPixel` is a boolean for pixel-perfect alignment, defaulting to
|
|
||||||
`true`. See above section about alignment for valid values of `horizontal` and
|
|
||||||
`vertical`. A parent element is required for this method.
|
|
||||||
- `alignTo(element, horizontal, vertical, toPixel)` Works just like `align()`,
|
|
||||||
except that alignment is based on a specific element instead of the parent.
|
|
||||||
Does not require a parent element.
|
|
||||||
- `setAlignment(horizontal, vertical)` Sets alignment values on the element
|
|
||||||
*without* moving the element.
|
|
||||||
- `getAlignment()` Returns the `horizontal` and `vertical` alignment of the
|
|
||||||
element.
|
|
||||||
- `setMargin(m)` Sets a margin to be used when aligning the element.
|
|
||||||
- `getMargin()` Returns the current margin value.
|
|
||||||
- `fill()` Resizes and aligns the element to fill its parent's area, with the
|
|
||||||
element's margin taken into account on all sides.
|
|
||||||
|
|
||||||
[1]: ../Excludes.md
|
|
@ -1,22 +0,0 @@
|
|||||||
# text
|
|
||||||
|
|
||||||
The text element is plain text in one color. Nothing special.
|
|
||||||
|
|
||||||
(**Note**: Other, more advanced text elements are planned, with support for
|
|
||||||
things like line-wrapping and custom coloring and formatting of text.)
|
|
||||||
|
|
||||||
## Methods
|
|
||||||
|
|
||||||
- `setSize()` Unlike other elements, a size cannot be set. If this is called, it
|
|
||||||
will fix the size of the text if it somehow was modified incorrectly.
|
|
||||||
- `setWidth()` Width cannot be set. If called, will fix the size of the text.
|
|
||||||
- `setHeight()` Height cannot be set. If called, will fix the size of the text.
|
|
||||||
- `setText(text)` Sets the text of the element. Will resize element to fit text.
|
|
||||||
Newlines are supported. Defaults to an empty string.
|
|
||||||
- `getText()` Returns the text of the element.
|
|
||||||
- `setFont()` Sets the font to be used on this element. Will resize to fit the
|
|
||||||
text and font.
|
|
||||||
- `setColor(red, green, blue, alpha)` Sets color of text. `alpha` is optional
|
|
||||||
and defaults to `255`. Alternately, pass a table of color values (ex: `{red,
|
|
||||||
green, blue, alpha}`).
|
|
||||||
- `getColor()` Returns red, green, blue, and alpha values of color.
|
|
@ -1,4 +0,0 @@
|
|||||||
# window
|
|
||||||
|
|
||||||
Documentation has not been written yet, as this element is still under heavy
|
|
||||||
development.
|
|
65
docs/index.html
Normal file
65
docs/index.html
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||||
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||||
|
<html>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||||
|
<head>
|
||||||
|
<title>Documentation</title>
|
||||||
|
<link rel="stylesheet" href="ldoc.css" type="text/css" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div id="container">
|
||||||
|
|
||||||
|
<div id="product">
|
||||||
|
<div id="product_logo"></div>
|
||||||
|
<div id="product_name"><big><b></b></big></div>
|
||||||
|
<div id="product_description"></div>
|
||||||
|
</div> <!-- id="product" -->
|
||||||
|
|
||||||
|
|
||||||
|
<div id="main">
|
||||||
|
|
||||||
|
|
||||||
|
<!-- Menu -->
|
||||||
|
|
||||||
|
<div id="navigation">
|
||||||
|
<br/>
|
||||||
|
<h1>Pop.Box()</h1>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<h2>Modules</h2>
|
||||||
|
<ul class="$(kind=='Topics' and '' or 'nowrap'">
|
||||||
|
<li><a href="modules/pop.html">pop</a></li>
|
||||||
|
<li><a href="modules/util.html">util</a></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="content">
|
||||||
|
|
||||||
|
|
||||||
|
<h2>GUI library for LOVE, designed for ease of use</h2>
|
||||||
|
|
||||||
|
<h2>Modules</h2>
|
||||||
|
<table class="module_list">
|
||||||
|
<tr>
|
||||||
|
<td class="name" nowrap><a href="modules/pop.html">pop</a></td>
|
||||||
|
<td class="summary">The Pop.Box GUI itself.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="name" nowrap><a href="modules/util.html">util</a></td>
|
||||||
|
<td class="summary">Utility functions, intended for internal use only.</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
</div> <!-- id="content" -->
|
||||||
|
</div> <!-- id="main" -->
|
||||||
|
<div id="about">
|
||||||
|
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
|
||||||
|
<i style="float:right;">Last updated 2016-06-20 22:28:27 </i>
|
||||||
|
</div> <!-- id="about" -->
|
||||||
|
</div> <!-- id="container" -->
|
||||||
|
</body>
|
||||||
|
</html>
|
304
docs/ldoc.css
Normal file
304
docs/ldoc.css
Normal file
@ -0,0 +1,304 @@
|
|||||||
|
/* BEGIN RESET
|
||||||
|
|
||||||
|
Copyright (c) 2010, Yahoo! Inc. All rights reserved.
|
||||||
|
Code licensed under the BSD License:
|
||||||
|
http://developer.yahoo.com/yui/license.html
|
||||||
|
version: 2.8.2r1
|
||||||
|
*/
|
||||||
|
html {
|
||||||
|
color: #000;
|
||||||
|
background: #FFF;
|
||||||
|
}
|
||||||
|
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,button,textarea,p,blockquote,th,td {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
table {
|
||||||
|
border-collapse: collapse;
|
||||||
|
border-spacing: 0;
|
||||||
|
}
|
||||||
|
fieldset,img {
|
||||||
|
border: 0;
|
||||||
|
}
|
||||||
|
address,caption,cite,code,dfn,em,strong,th,var,optgroup {
|
||||||
|
font-style: inherit;
|
||||||
|
font-weight: inherit;
|
||||||
|
}
|
||||||
|
del,ins {
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
li {
|
||||||
|
list-style: disc;
|
||||||
|
margin-left: 20px;
|
||||||
|
}
|
||||||
|
caption,th {
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
h1,h2,h3,h4,h5,h6 {
|
||||||
|
font-size: 100%;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
q:before,q:after {
|
||||||
|
content: '';
|
||||||
|
}
|
||||||
|
abbr,acronym {
|
||||||
|
border: 0;
|
||||||
|
font-variant: normal;
|
||||||
|
}
|
||||||
|
sup {
|
||||||
|
vertical-align: baseline;
|
||||||
|
}
|
||||||
|
sub {
|
||||||
|
vertical-align: baseline;
|
||||||
|
}
|
||||||
|
legend {
|
||||||
|
color: #000;
|
||||||
|
}
|
||||||
|
input,button,textarea,select,optgroup,option {
|
||||||
|
font-family: inherit;
|
||||||
|
font-size: inherit;
|
||||||
|
font-style: inherit;
|
||||||
|
font-weight: inherit;
|
||||||
|
}
|
||||||
|
input,button,textarea,select {*font-size:100%;
|
||||||
|
}
|
||||||
|
/* END RESET */
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin-left: 1em;
|
||||||
|
margin-right: 1em;
|
||||||
|
font-family: arial, helvetica, geneva, sans-serif;
|
||||||
|
background-color: #ffffff; margin: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
code, tt { font-family: monospace; font-size: 1.1em; }
|
||||||
|
span.parameter { font-family:monospace; }
|
||||||
|
span.parameter:after { content:":"; }
|
||||||
|
span.types:before { content:"("; }
|
||||||
|
span.types:after { content:")"; }
|
||||||
|
.type { font-weight: bold; font-style:italic }
|
||||||
|
|
||||||
|
body, p, td, th { font-size: .95em; line-height: 1.2em;}
|
||||||
|
|
||||||
|
p, ul { margin: 10px 0 0 0px;}
|
||||||
|
|
||||||
|
strong { font-weight: bold;}
|
||||||
|
|
||||||
|
em { font-style: italic;}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
font-size: 1.5em;
|
||||||
|
margin: 0 0 20px 0;
|
||||||
|
}
|
||||||
|
h2, h3, h4 { margin: 15px 0 10px 0; }
|
||||||
|
h2 { font-size: 1.25em; }
|
||||||
|
h3 { font-size: 1.15em; }
|
||||||
|
h4 { font-size: 1.06em; }
|
||||||
|
|
||||||
|
a:link { font-weight: bold; color: #004080; text-decoration: none; }
|
||||||
|
a:visited { font-weight: bold; color: #006699; text-decoration: none; }
|
||||||
|
a:link:hover { text-decoration: underline; }
|
||||||
|
|
||||||
|
hr {
|
||||||
|
color:#cccccc;
|
||||||
|
background: #00007f;
|
||||||
|
height: 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
blockquote { margin-left: 3em; }
|
||||||
|
|
||||||
|
ul { list-style-type: disc; }
|
||||||
|
|
||||||
|
p.name {
|
||||||
|
font-family: "Andale Mono", monospace;
|
||||||
|
padding-top: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre {
|
||||||
|
background-color: rgb(245, 245, 245);
|
||||||
|
border: 1px solid #C0C0C0; /* silver */
|
||||||
|
padding: 10px;
|
||||||
|
margin: 10px 0 10px 0;
|
||||||
|
overflow: auto;
|
||||||
|
font-family: "Andale Mono", monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre.example {
|
||||||
|
font-size: .85em;
|
||||||
|
}
|
||||||
|
|
||||||
|
table.index { border: 1px #00007f; }
|
||||||
|
table.index td { text-align: left; vertical-align: top; }
|
||||||
|
|
||||||
|
#container {
|
||||||
|
margin-left: 1em;
|
||||||
|
margin-right: 1em;
|
||||||
|
background-color: #f0f0f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#product {
|
||||||
|
text-align: center;
|
||||||
|
border-bottom: 1px solid #cccccc;
|
||||||
|
background-color: #ffffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
#product big {
|
||||||
|
font-size: 2em;
|
||||||
|
}
|
||||||
|
|
||||||
|
#main {
|
||||||
|
background-color: #f0f0f0;
|
||||||
|
border-left: 2px solid #cccccc;
|
||||||
|
}
|
||||||
|
|
||||||
|
#navigation {
|
||||||
|
float: left;
|
||||||
|
width: 14em;
|
||||||
|
vertical-align: top;
|
||||||
|
background-color: #f0f0f0;
|
||||||
|
overflow: visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
#navigation h2 {
|
||||||
|
background-color:#e7e7e7;
|
||||||
|
font-size:1.1em;
|
||||||
|
color:#000000;
|
||||||
|
text-align: left;
|
||||||
|
padding:0.2em;
|
||||||
|
border-top:1px solid #dddddd;
|
||||||
|
border-bottom:1px solid #dddddd;
|
||||||
|
}
|
||||||
|
|
||||||
|
#navigation ul
|
||||||
|
{
|
||||||
|
font-size:1em;
|
||||||
|
list-style-type: none;
|
||||||
|
margin: 1px 1px 10px 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#navigation li {
|
||||||
|
text-indent: -1em;
|
||||||
|
display: block;
|
||||||
|
margin: 3px 0px 0px 22px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#navigation li li a {
|
||||||
|
margin: 0px 3px 0px -1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
#content {
|
||||||
|
margin-left: 14em;
|
||||||
|
padding: 1em;
|
||||||
|
width: 700px;
|
||||||
|
border-left: 2px solid #cccccc;
|
||||||
|
border-right: 2px solid #cccccc;
|
||||||
|
background-color: #ffffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
#about {
|
||||||
|
clear: both;
|
||||||
|
padding: 5px;
|
||||||
|
border-top: 2px solid #cccccc;
|
||||||
|
background-color: #ffffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media print {
|
||||||
|
body {
|
||||||
|
font: 12pt "Times New Roman", "TimeNR", Times, serif;
|
||||||
|
}
|
||||||
|
a { font-weight: bold; color: #004080; text-decoration: underline; }
|
||||||
|
|
||||||
|
#main {
|
||||||
|
background-color: #ffffff;
|
||||||
|
border-left: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#container {
|
||||||
|
margin-left: 2%;
|
||||||
|
margin-right: 2%;
|
||||||
|
background-color: #ffffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
#content {
|
||||||
|
padding: 1em;
|
||||||
|
background-color: #ffffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
#navigation {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
pre.example {
|
||||||
|
font-family: "Andale Mono", monospace;
|
||||||
|
font-size: 10pt;
|
||||||
|
page-break-inside: avoid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
table.module_list {
|
||||||
|
border-width: 1px;
|
||||||
|
border-style: solid;
|
||||||
|
border-color: #cccccc;
|
||||||
|
border-collapse: collapse;
|
||||||
|
}
|
||||||
|
table.module_list td {
|
||||||
|
border-width: 1px;
|
||||||
|
padding: 3px;
|
||||||
|
border-style: solid;
|
||||||
|
border-color: #cccccc;
|
||||||
|
}
|
||||||
|
table.module_list td.name { background-color: #f0f0f0; min-width: 200px; }
|
||||||
|
table.module_list td.summary { width: 100%; }
|
||||||
|
|
||||||
|
|
||||||
|
table.function_list {
|
||||||
|
border-width: 1px;
|
||||||
|
border-style: solid;
|
||||||
|
border-color: #cccccc;
|
||||||
|
border-collapse: collapse;
|
||||||
|
}
|
||||||
|
table.function_list td {
|
||||||
|
border-width: 1px;
|
||||||
|
padding: 3px;
|
||||||
|
border-style: solid;
|
||||||
|
border-color: #cccccc;
|
||||||
|
}
|
||||||
|
table.function_list td.name { background-color: #f0f0f0; min-width: 200px; }
|
||||||
|
table.function_list td.summary { width: 100%; }
|
||||||
|
|
||||||
|
ul.nowrap {
|
||||||
|
overflow:auto;
|
||||||
|
white-space:nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
dl.table dt, dl.function dt {border-top: 1px solid #ccc; padding-top: 1em;}
|
||||||
|
dl.table dd, dl.function dd {padding-bottom: 1em; margin: 10px 0 0 20px;}
|
||||||
|
dl.table h3, dl.function h3 {font-size: .95em;}
|
||||||
|
|
||||||
|
/* stop sublists from having initial vertical space */
|
||||||
|
ul ul { margin-top: 0px; }
|
||||||
|
ol ul { margin-top: 0px; }
|
||||||
|
ol ol { margin-top: 0px; }
|
||||||
|
ul ol { margin-top: 0px; }
|
||||||
|
|
||||||
|
/* make the target distinct; helps when we're navigating to a function */
|
||||||
|
a:target + * {
|
||||||
|
background-color: #FF9;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* styles for prettification of source */
|
||||||
|
pre .comment { color: #558817; }
|
||||||
|
pre .constant { color: #a8660d; }
|
||||||
|
pre .escape { color: #844631; }
|
||||||
|
pre .keyword { color: #aa5050; font-weight: bold; }
|
||||||
|
pre .library { color: #0e7c6b; }
|
||||||
|
pre .marker { color: #512b1e; background: #fedc56; font-weight: bold; }
|
||||||
|
pre .string { color: #8080ff; }
|
||||||
|
pre .number { color: #f8660d; }
|
||||||
|
pre .operator { color: #2239a8; font-weight: bold; }
|
||||||
|
pre .preprocessor, pre .prepro { color: #a33243; }
|
||||||
|
pre .global { color: #800080; }
|
||||||
|
pre .user-keyword { color: #800080; }
|
||||||
|
pre .prompt { color: #558817; }
|
||||||
|
pre .url { color: #272fc2; text-decoration: underline; }
|
||||||
|
|
335
docs/modules/pop.html
Normal file
335
docs/modules/pop.html
Normal file
@ -0,0 +1,335 @@
|
|||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||||
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||||
|
<html>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||||
|
<head>
|
||||||
|
<title>Documentation</title>
|
||||||
|
<link rel="stylesheet" href="../ldoc.css" type="text/css" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div id="container">
|
||||||
|
|
||||||
|
<div id="product">
|
||||||
|
<div id="product_logo"></div>
|
||||||
|
<div id="product_name"><big><b></b></big></div>
|
||||||
|
<div id="product_description"></div>
|
||||||
|
</div> <!-- id="product" -->
|
||||||
|
|
||||||
|
|
||||||
|
<div id="main">
|
||||||
|
|
||||||
|
|
||||||
|
<!-- Menu -->
|
||||||
|
|
||||||
|
<div id="navigation">
|
||||||
|
<br/>
|
||||||
|
<h1>Pop.Box()</h1>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><a href="../index.html">Index</a></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h2>Contents</h2>
|
||||||
|
<ul>
|
||||||
|
<li><a href="#Functions">Functions</a></li>
|
||||||
|
<li><a href="#Tables">Tables</a></li>
|
||||||
|
<li><a href="#Issues">Issues</a></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
<h2>Modules</h2>
|
||||||
|
<ul class="$(kind=='Topics' and '' or 'nowrap'">
|
||||||
|
<li><strong>pop</strong></li>
|
||||||
|
<li><a href="../modules/util.html">util</a></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="content">
|
||||||
|
|
||||||
|
<h1>Module <code>pop</code></h1>
|
||||||
|
<p>The Pop.Box GUI itself.</p>
|
||||||
|
<p>
|
||||||
|
|
||||||
|
</p>
|
||||||
|
<h3>Info:</h3>
|
||||||
|
<ul>
|
||||||
|
<li><strong>Copyright</strong>: Paul Liverman III (2015-2016)</li>
|
||||||
|
<li><strong>Release</strong>: v0.0.0</li>
|
||||||
|
<li><strong>License</strong>: The MIT License (MIT)</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
<h2><a href="#Functions">Functions</a></h2>
|
||||||
|
<table class="function_list">
|
||||||
|
<tr>
|
||||||
|
<td class="name" nowrap><a href="#load">load ()</a></td>
|
||||||
|
<td class="summary">Loads elements, skins, extensions, and initializes <code>pop.screen</code>.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="name" nowrap><a href="#create">create (element, parent)</a></td>
|
||||||
|
<td class="summary">Creates an element.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="name" nowrap><a href="#update">update (dt, element)</a></td>
|
||||||
|
<td class="summary">Event handler for <code>love.update()</code> events.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="name" nowrap><a href="#draw">draw (element)</a></td>
|
||||||
|
<td class="summary">Event handler for <code>love.draw()</code> events.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="name" nowrap><a href="#mousemoved">mousemoved (x, y, dx, dy)</a></td>
|
||||||
|
<td class="summary">Event handler for <code>love.mousemoved()</code> events.</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<h2><a href="#Tables">Tables</a></h2>
|
||||||
|
<table class="function_list">
|
||||||
|
<tr>
|
||||||
|
<td class="name" nowrap><a href="#pop">pop</a></td>
|
||||||
|
<td class="summary">
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<h2><a href="#Issues">Issues</a></h2>
|
||||||
|
<table class="function_list">
|
||||||
|
<tr>
|
||||||
|
<td class="name" nowrap><a href="#pop-todo1">pop-todo1</a></td>
|
||||||
|
<td class="summary">Find out what happens if someone requires the <code>init.lua</code> / <code>init.moon</code> file instead of the directory, add an error message for this.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="name" nowrap><a href="#load-todo2">load-todo2</a></td>
|
||||||
|
<td class="summary">Determine if extensions should have a reference saved (and the possibility of a load function?)
|
||||||
|
require into pop.extensions by filename</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="name" nowrap><a href="#mousemoved-todo3">mousemoved-todo3</a></td>
|
||||||
|
<td class="summary">Implement a way for an element to attach itself to <code>love.mousemoved()</code> events?</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
|
||||||
|
<h2 class="section-header "><a name="Functions"></a>Functions</h2>
|
||||||
|
|
||||||
|
<dl class="function">
|
||||||
|
<dt>
|
||||||
|
<a name = "load"></a>
|
||||||
|
<strong>load ()</strong>
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
Loads elements, skins, extensions, and initializes <code>pop.screen</code>. <strong>IMPORTANT</strong>: Intended to only be called once, and is automatically called when you require Pop.Box.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<h3>See also:</h3>
|
||||||
|
<ul>
|
||||||
|
<a href="../modules/pop.html#">pop</a>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
</dd>
|
||||||
|
<dt>
|
||||||
|
<a name = "create"></a>
|
||||||
|
<strong>create (element, parent)</strong>
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
Creates an element.
|
||||||
|
|
||||||
|
|
||||||
|
<h3>Parameters:</h3>
|
||||||
|
<ul>
|
||||||
|
<li><span class="parameter">element</span>
|
||||||
|
A string naming the element class to use.
|
||||||
|
</li>
|
||||||
|
<li><span class="parameter">parent</span>
|
||||||
|
<em>Optional</em> The parent element. If <code>false</code>, an element is created with no parent. If <code>nil</code>, defaults to <code>pop.screen</code>.
|
||||||
|
(<strong>Note</strong>: An element with no parent will not be handled by Pop.Box's event handlers unless you handle it explicitly.)
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<h3>See also:</h3>
|
||||||
|
<ul>
|
||||||
|
<a href="../modules/pop.html#">pop</a>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
</dd>
|
||||||
|
<dt>
|
||||||
|
<a name = "update"></a>
|
||||||
|
<strong>update (dt, element)</strong>
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
Event handler for <code>love.update()</code> events.
|
||||||
|
|
||||||
|
|
||||||
|
<h3>Parameters:</h3>
|
||||||
|
<ul>
|
||||||
|
<li><span class="parameter">dt</span>
|
||||||
|
The amount of time passed since the last call to update, in seconds.
|
||||||
|
</li>
|
||||||
|
<li><span class="parameter">element</span>
|
||||||
|
<em>Optional</em> The element to update. Defaults to <code>pop.screen</code> (and loops through all its children).
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</dd>
|
||||||
|
<dt>
|
||||||
|
<a name = "draw"></a>
|
||||||
|
<strong>draw (element)</strong>
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
Event handler for <code>love.draw()</code> events.
|
||||||
|
|
||||||
|
|
||||||
|
<h3>Parameters:</h3>
|
||||||
|
<ul>
|
||||||
|
<li><span class="parameter">element</span>
|
||||||
|
<em>Optional</em> The element to draw. Defaults to <code>pop.screen</code> (and loops through all its children).
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</dd>
|
||||||
|
<dt>
|
||||||
|
<a name = "mousemoved"></a>
|
||||||
|
<strong>mousemoved (x, y, dx, dy)</strong>
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
Event handler for <code>love.mousemoved()</code> events. (*LÖVE >= 0.10.0*)
|
||||||
|
|
||||||
|
|
||||||
|
<h3>Parameters:</h3>
|
||||||
|
<ul>
|
||||||
|
<li><span class="parameter">x</span>
|
||||||
|
The x coordinate of the mouse.
|
||||||
|
</li>
|
||||||
|
<li><span class="parameter">y</span>
|
||||||
|
The y coordinate of the mouse.
|
||||||
|
</li>
|
||||||
|
<li><span class="parameter">dx</span>
|
||||||
|
The distance on the x axis the mouse was moved.
|
||||||
|
</li>
|
||||||
|
<li><span class="parameter">dy</span>
|
||||||
|
The distance on the y axis the mouse was moved.
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</dd>
|
||||||
|
</dl>
|
||||||
|
<h2 class="section-header "><a name="Tables"></a>Tables</h2>
|
||||||
|
|
||||||
|
<dl class="function">
|
||||||
|
<dt>
|
||||||
|
<a name = "pop"></a>
|
||||||
|
<strong>pop</strong>
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<h3>Fields:</h3>
|
||||||
|
<ul>
|
||||||
|
<li><span class="parameter">elements</span>
|
||||||
|
All GUI classes are stored here.
|
||||||
|
</li>
|
||||||
|
<li><span class="parameter">skins</span>
|
||||||
|
All skins are stored here.
|
||||||
|
</li>
|
||||||
|
<li><span class="parameter">screen</span>
|
||||||
|
The top level GUI element. Represents the game screen. Initialized in <code>pop.load()</code>
|
||||||
|
</li>
|
||||||
|
<li><span class="parameter">focused</span>
|
||||||
|
The currently focused GUI element (or false if none is focused).
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<h3>See also:</h3>
|
||||||
|
<ul>
|
||||||
|
<a href="../modules/pop.html#load">pop.load</a>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
</dd>
|
||||||
|
</dl>
|
||||||
|
<h2 class="section-header "><a name="Issues"></a>Issues</h2>
|
||||||
|
|
||||||
|
<dl class="function">
|
||||||
|
<dt>
|
||||||
|
<a name = "pop-todo1"></a>
|
||||||
|
<strong>pop-todo1</strong>
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
Find out what happens if someone requires the <code>init.lua</code> / <code>init.moon</code> file instead of the directory, add an error message for this.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</dd>
|
||||||
|
<dt>
|
||||||
|
<a name = "load-todo2"></a>
|
||||||
|
<strong>load-todo2</strong>
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
Determine if extensions should have a reference saved (and the possibility of a load function?)
|
||||||
|
require into pop.extensions by filename
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</dd>
|
||||||
|
<dt>
|
||||||
|
<a name = "mousemoved-todo3"></a>
|
||||||
|
<strong>mousemoved-todo3</strong>
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
Implement a way for an element to attach itself to <code>love.mousemoved()</code> events?
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</dd>
|
||||||
|
</dl>
|
||||||
|
|
||||||
|
|
||||||
|
</div> <!-- id="content" -->
|
||||||
|
</div> <!-- id="main" -->
|
||||||
|
<div id="about">
|
||||||
|
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
|
||||||
|
<i style="float:right;">Last updated 2016-06-20 22:28:27 </i>
|
||||||
|
</div> <!-- id="about" -->
|
||||||
|
</div> <!-- id="container" -->
|
||||||
|
</body>
|
||||||
|
</html>
|
119
docs/modules/util.html
Normal file
119
docs/modules/util.html
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||||
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||||
|
<html>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||||
|
<head>
|
||||||
|
<title>Documentation</title>
|
||||||
|
<link rel="stylesheet" href="../ldoc.css" type="text/css" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div id="container">
|
||||||
|
|
||||||
|
<div id="product">
|
||||||
|
<div id="product_logo"></div>
|
||||||
|
<div id="product_name"><big><b></b></big></div>
|
||||||
|
<div id="product_description"></div>
|
||||||
|
</div> <!-- id="product" -->
|
||||||
|
|
||||||
|
|
||||||
|
<div id="main">
|
||||||
|
|
||||||
|
|
||||||
|
<!-- Menu -->
|
||||||
|
|
||||||
|
<div id="navigation">
|
||||||
|
<br/>
|
||||||
|
<h1>Pop.Box()</h1>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><a href="../index.html">Index</a></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h2>Contents</h2>
|
||||||
|
<ul>
|
||||||
|
<li><a href="#Functions">Functions</a></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
<h2>Modules</h2>
|
||||||
|
<ul class="$(kind=='Topics' and '' or 'nowrap'">
|
||||||
|
<li><a href="../modules/pop.html">pop</a></li>
|
||||||
|
<li><strong>util</strong></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="content">
|
||||||
|
|
||||||
|
<h1>Module <code>util</code></h1>
|
||||||
|
<p>Utility functions, intended for internal use only.</p>
|
||||||
|
<p>
|
||||||
|
|
||||||
|
</p>
|
||||||
|
<h3>Info:</h3>
|
||||||
|
<ul>
|
||||||
|
<li><strong>Copyright</strong>: Paul Liverman III (2015-2016)</li>
|
||||||
|
<li><strong>Release</strong>: v0.0.0</li>
|
||||||
|
<li><strong>License</strong>: The MIT License (MIT)</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
<h2><a href="#Functions">Functions</a></h2>
|
||||||
|
<table class="function_list">
|
||||||
|
<tr>
|
||||||
|
<td class="name" nowrap><a href="#inheritsFromElement">inheritsFromElement (object)</a></td>
|
||||||
|
<td class="summary">
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
|
||||||
|
<h2 class="section-header "><a name="Functions"></a>Functions</h2>
|
||||||
|
|
||||||
|
<dl class="function">
|
||||||
|
<dt>
|
||||||
|
<a name = "inheritsFromElement"></a>
|
||||||
|
<strong>inheritsFromElement (object)</strong>
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<h3>Parameters:</h3>
|
||||||
|
<ul>
|
||||||
|
<li><span class="parameter">object</span>
|
||||||
|
A table (MoonScript object expected) to be checked for inheritence from the "element" element.
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h3>Returns:</h3>
|
||||||
|
<ol>
|
||||||
|
|
||||||
|
<code>true</code> / <code>false</code>: Is the table an object inherting from "element"?
|
||||||
|
</ol>
|
||||||
|
|
||||||
|
<h3>Raises:</h3>
|
||||||
|
Can error if the table has a similar structure to a MoonScript object without being the same structure.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</dd>
|
||||||
|
</dl>
|
||||||
|
|
||||||
|
|
||||||
|
</div> <!-- id="content" -->
|
||||||
|
</div> <!-- id="main" -->
|
||||||
|
<div id="about">
|
||||||
|
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
|
||||||
|
<i style="float:right;">Last updated 2016-06-20 22:28:27 </i>
|
||||||
|
</div> <!-- id="about" -->
|
||||||
|
</div> <!-- id="container" -->
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -1,34 +0,0 @@
|
|||||||
local lg = love.graphics
|
|
||||||
local pop, parts
|
|
||||||
|
|
||||||
-- pretend parts has been defined
|
|
||||||
|
|
||||||
function love.load()
|
|
||||||
pop = require "lib.pop"
|
|
||||||
local width4 = lg.getWidth()/4
|
|
||||||
local height2 = lg.getHeight()/2
|
|
||||||
local PartList = pop.scrollbox():setSize(width4, height2)--:setSizeControl(true) --defaults to true
|
|
||||||
local PartInfo = pop.scrollbox():setSize(width4, height2):move(nil, height2)
|
|
||||||
local CraftInfo = pop.box():setSize(width4, height2):move(lg.getWidth()*3/4)
|
|
||||||
local columns = math.floor(PartList:getWidth()/128)
|
|
||||||
local rows = math.floor(#parts/columns)
|
|
||||||
local grid = pop.grid(PartList, columns, rows)
|
|
||||||
for i = 1, #parts do
|
|
||||||
-- pretend that parts.gui is a box designed to fix in here properly
|
|
||||||
grid:add(parts[i].gui) -- pretend by default, adding something to a grid like this adds it to first available spot
|
|
||||||
-- also, grids auto-resize their children
|
|
||||||
end
|
|
||||||
PartList:add(grid) -- BULLSHIT ?!
|
|
||||||
end
|
|
||||||
|
|
||||||
-- parts.gui is something like this:
|
|
||||||
|
|
||||||
gui = pop.box(newImage()) -- assumes a box can take 'userdata' as first arg and know it is an image
|
|
||||||
gui.clicked = function(x, y, button)
|
|
||||||
-- don't care about x/y
|
|
||||||
if button == "l" then --left
|
|
||||||
selected = gui.partReference -- or something
|
|
||||||
elseif button == "r" then --right
|
|
||||||
displayPartInfo() -- something happens to display it in the proper spot
|
|
||||||
end
|
|
||||||
end
|
|
@ -1,3 +1,9 @@
|
|||||||
|
--- The Pop.Box GUI itself.
|
||||||
|
--- @module pop
|
||||||
|
--- @copyright Paul Liverman III (2015-2016)
|
||||||
|
--- @license The MIT License (MIT)
|
||||||
|
--- @release v0.0.0
|
||||||
|
|
||||||
pop = {
|
pop = {
|
||||||
_VERSION: 'Pop.Box v0.0.0'
|
_VERSION: 'Pop.Box v0.0.0'
|
||||||
_DESCRIPTION: 'GUI library for LOVE, designed for ease of use'
|
_DESCRIPTION: 'GUI library for LOVE, designed for ease of use'
|
||||||
@ -9,37 +15,53 @@ pop = {
|
|||||||
unless love.getVersion
|
unless love.getVersion
|
||||||
error "Pop.Box only supports LOVE versions >= 0.9.1"
|
error "Pop.Box only supports LOVE versions >= 0.9.1"
|
||||||
|
|
||||||
|
--- @todo Find out what happens if someone requires the `init.lua` / `init.moon` file instead of the directory, add an error message for this.
|
||||||
|
|
||||||
import filesystem, graphics from love
|
import filesystem, graphics from love
|
||||||
import insert from table
|
import insert from table
|
||||||
import inheritsFromElement from require "#{...}/util"
|
import inheritsFromElement from require "#{...}/util"
|
||||||
|
|
||||||
path = ...
|
path = ...
|
||||||
|
|
||||||
|
--- @table pop
|
||||||
|
--- @field elements All GUI classes are stored here.
|
||||||
|
--- @field skins All skins are stored here.
|
||||||
|
--- @field screen The top level GUI element. Represents the game screen. Initialized in `pop.load()`
|
||||||
|
--- @see pop.load
|
||||||
|
--- @field focused The currently focused GUI element (or false if none is focused).
|
||||||
|
|
||||||
pop.elements = {}
|
pop.elements = {}
|
||||||
pop.skins = {}
|
pop.skins = {}
|
||||||
|
pop.screen = false
|
||||||
pop.screen = false -- initialized in pop.load()
|
|
||||||
pop.focused = false
|
pop.focused = false
|
||||||
|
|
||||||
-- loads elements and skins, creates pop.screen (intended to only be called once at the beginning)
|
|
||||||
|
|
||||||
|
--- Loads elements, skins, extensions, and initializes `pop.screen`. **IMPORTANT**: Intended to only be called once, and is automatically called when you require Pop.Box.
|
||||||
|
--- @function load
|
||||||
|
--- @see pop
|
||||||
|
--- @todo @see Elements
|
||||||
|
--- @todo @see Skins
|
||||||
|
--- @todo @see Extensions
|
||||||
|
|
||||||
pop.load = ->
|
pop.load = ->
|
||||||
elements = filesystem.getDirectoryItems "#{path}/elements"
|
elements = filesystem.getDirectoryItems "#{path}/elements"
|
||||||
|
|
||||||
for i = 1, #elements
|
for i = 1, #elements
|
||||||
-- only attempt to load lua files
|
-- ignore non-Lua files
|
||||||
unless elements[i]\sub(-4) == ".lua"
|
unless elements[i]\sub(-4) == ".lua"
|
||||||
continue
|
continue
|
||||||
|
|
||||||
-- load into pop.elements table
|
-- require into pop.elements table by filename
|
||||||
name = elements[i]\sub 1, -5
|
name = elements[i]\sub 1, -5
|
||||||
pop.elements[name] = require "#{path}/elements/#{name}"
|
pop.elements[name] = require "#{path}/elements/#{name}"
|
||||||
|
|
||||||
|
-- call the element's load function if it exists
|
||||||
if pop.elements[name].load
|
if pop.elements[name].load
|
||||||
pop.elements[name].load pop
|
pop.elements[name].load pop
|
||||||
|
|
||||||
print "element loaded: \"#{name}\""
|
print "element loaded: \"#{name}\""
|
||||||
|
|
||||||
-- create pop.element() wrapper if possible
|
-- create "pop.element()" function wrapper if possible
|
||||||
unless pop[name]
|
unless pop[name]
|
||||||
if pop.elements[name].wrap
|
if pop.elements[name].wrap
|
||||||
pop[name] = pop.elements[name].wrap pop
|
pop[name] = pop.elements[name].wrap pop
|
||||||
@ -49,71 +71,127 @@ pop.load = ->
|
|||||||
|
|
||||||
print "wrapper created: \"pop.#{name}()\""
|
print "wrapper created: \"pop.#{name}()\""
|
||||||
|
|
||||||
-- works just like above, except no load calls or wrappers
|
|
||||||
skins = filesystem.getDirectoryItems "#{path}/skins"
|
|
||||||
|
|
||||||
|
skins = filesystem.getDirectoryItems "#{path}/skins"
|
||||||
for i = 1, #skins
|
for i = 1, #skins
|
||||||
|
-- ignore non-Lua files
|
||||||
unless skins[i]\sub(-4) == ".lua"
|
unless skins[i]\sub(-4) == ".lua"
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
-- require into pop.skins table by filename
|
||||||
name = skins[i]\sub 1, -5
|
name = skins[i]\sub 1, -5
|
||||||
pop.skins[name] = require "#{path}/skins/#{name}"
|
pop.skins[name] = require "#{path}/skins/#{name}"
|
||||||
|
|
||||||
|
-- call the skin's load function if it exists
|
||||||
|
if pop.skins[name].load
|
||||||
|
pop.skins[name].load pop
|
||||||
|
|
||||||
print "skin loaded: \"#{name}\""
|
print "skin loaded: \"#{name}\""
|
||||||
|
|
||||||
-- (again, similar) load extensions by just running them via require
|
|
||||||
extensions = filesystem.getDirectoryItems "#{path}/extensions"
|
|
||||||
|
|
||||||
|
extensions = filesystem.getDirectoryItems "#{path}/extensions"
|
||||||
for i = 1, #extensions
|
for i = 1, #extensions
|
||||||
|
-- ignore non-Lua files
|
||||||
unless extensions[i]\sub(-4) == ".lua"
|
unless extensions[i]\sub(-4) == ".lua"
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
--- @todo Determine if extensions should have a reference saved (and the possibility of a load function?)
|
||||||
|
-- require into pop.extensions by filename
|
||||||
name = extensions[i]\sub 1, -5
|
name = extensions[i]\sub 1, -5
|
||||||
require "#{path}/extensions/#{name}"
|
require "#{path}/extensions/#{name}"
|
||||||
|
|
||||||
print "extension loaded: \"#{name}\""
|
print "extension loaded: \"#{name}\""
|
||||||
|
|
||||||
-- GUI screen area
|
|
||||||
|
-- Initialize pop.screen (top element, GUI area)
|
||||||
pop.screen = pop.create("element", false)\setSize(graphics.getWidth!, graphics.getHeight!)
|
pop.screen = pop.create("element", false)\setSize(graphics.getWidth!, graphics.getHeight!)
|
||||||
print "created \"pop.screen\""
|
print "created \"pop.screen\""
|
||||||
|
|
||||||
-- creates an element (parent is an element, false, or nil (defaults to pop.screen))
|
|
||||||
|
|
||||||
|
--- Creates an element.
|
||||||
|
--- @function create
|
||||||
|
--- @param element A string naming the element class to use.
|
||||||
|
--- @param parent *Optional* The parent element. If `false`, an element is created with no parent. If `nil`, defaults to `pop.screen`.
|
||||||
|
--- (**Note**: An element with no parent will not be handled by Pop.Box's event handlers unless you handle it explicitly.)
|
||||||
|
--- @see pop
|
||||||
|
--- @todo @see Elements
|
||||||
|
|
||||||
pop.create = (element, parent=pop.screen, ...) ->
|
pop.create = (element, parent=pop.screen, ...) ->
|
||||||
-- if valid parent element
|
-- if valid parent element, use it
|
||||||
if inheritsFromElement parent
|
if inheritsFromElement parent
|
||||||
element = pop.elements[element](parent, ...)
|
element = pop.elements[element](parent, ...)
|
||||||
insert parent.child, element
|
insert parent.child, element
|
||||||
-- if explicitly no parent
|
insert parent.data.child, element.data
|
||||||
|
-- if explicitly no parent, just create the element
|
||||||
elseif parent == false
|
elseif parent == false
|
||||||
element = pop.elements[element](false, ...)
|
element = pop.elements[element](false, ...)
|
||||||
-- else use pop.screen, and "parent" is actually first argument
|
-- else use pop.screen (and "parent" is actually the first argument)
|
||||||
else
|
else
|
||||||
element = pop.elements[element](pop.screen, parent, ...)
|
element = pop.elements[element](pop.screen, parent, ...)
|
||||||
insert pop.screen.child, element
|
insert pop.screen.child, element
|
||||||
|
insert pop.screen.data.child, element.data
|
||||||
|
|
||||||
return element
|
return element
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
--- Event handler for `love.update()` events.
|
||||||
|
--- @function update
|
||||||
|
--- @param dt The amount of time passed since the last call to update, in seconds.
|
||||||
|
--- @param element *Optional* The element to update. Defaults to `pop.screen` (and loops through all its children).
|
||||||
|
--- @todo Define Elements and @see that documentation from here. Generic documentation, not specifically element!
|
||||||
|
|
||||||
pop.update = (dt, element=pop.screen) ->
|
pop.update = (dt, element=pop.screen) ->
|
||||||
unless element.excludeUpdate
|
-- data.update boolean controls an element and its children being updated
|
||||||
|
if element.data.update
|
||||||
if element.update
|
if element.update
|
||||||
element\update dt
|
element\update dt
|
||||||
for i = 1, #element.child
|
for i = 1, #element.child
|
||||||
pop.update dt, element.child[i]
|
pop.update dt, element.child[i]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
--- Event handler for `love.draw()` events.
|
||||||
|
--- @function draw
|
||||||
|
--- @param element *Optional* The element to draw. Defaults to `pop.screen` (and loops through all its children).
|
||||||
|
--- @todo @see Elements
|
||||||
|
|
||||||
pop.draw = (element=pop.screen) ->
|
pop.draw = (element=pop.screen) ->
|
||||||
unless element.excludeDraw
|
-- data.draw boolean controls an element and its children being drawn
|
||||||
|
if element.data.draw
|
||||||
if element.draw
|
if element.draw
|
||||||
element\draw!
|
element\draw!
|
||||||
for i = 1, #element.child
|
for i = 1, #element.child
|
||||||
pop.draw element.child[i]
|
pop.draw element.child[i]
|
||||||
|
|
||||||
--TODO implement a way for an element to attach itself to mousemoved events
|
|
||||||
|
|
||||||
|
--- Event handler for `love.mousemoved()` events. (*LÖVE >= 0.10.0*)
|
||||||
|
--- @function mousemoved
|
||||||
|
--- @param x The x coordinate of the mouse.
|
||||||
|
--- @param y The y coordinate of the mouse.
|
||||||
|
--- @param dx The distance on the x axis the mouse was moved.
|
||||||
|
--- @param dy The distance on the y axis the mouse was moved.
|
||||||
|
--- @return `true` / `false`: Was the event handled?
|
||||||
|
|
||||||
|
--- @todo Implement a way for an element to attach itself to `love.mousemoved()` events?
|
||||||
pop.mousemoved = (x, y, dx, dy) ->
|
pop.mousemoved = (x, y, dx, dy) ->
|
||||||
if pop.focused and pop.focused.mousemoved
|
if pop.focused and pop.focused.mousemoved
|
||||||
return pop.focused\mousemoved x, y, dx, dy
|
return pop.focused\mousemoved x, y, dx, dy
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
--- Event handler for `love.mousepressed()` events.
|
||||||
|
--- @function mousepressed
|
||||||
|
--- @param x The x coordinate of the mouse press.
|
||||||
|
--- @param y The y coordinate of the mouse press.
|
||||||
|
--- @param button The mouse button pressed.
|
||||||
|
--- @param element *Optional* The element to check for event handling. Defaults to `pop.screen` (and loops through all its children).
|
||||||
|
--- @return `true` / `false`: Was the event handled?
|
||||||
|
|
||||||
pop.mousepressed = (x, y, button, element) ->
|
pop.mousepressed = (x, y, button, element) ->
|
||||||
-- start at the screen, print that we received an event
|
-- start at the screen, print that we received an event
|
||||||
unless element
|
unless element
|
||||||
@ -123,23 +201,34 @@ pop.mousepressed = (x, y, button, element) ->
|
|||||||
-- have we handled the event?
|
-- have we handled the event?
|
||||||
handled = false
|
handled = false
|
||||||
|
|
||||||
-- if it was inside the current element..
|
-- if it is inside the current element..
|
||||||
if (x >= element.x) and (x <= element.x + element.w) and (y >= element.y) and (y <= element.y + element.h)
|
if (x >= element.data.x) and (x <= element.data.x + element.data.w) and (y >= element.data.y) and (y <= element.data.y + element.data.h)
|
||||||
-- check its child elements in reverse order, returning if something handles it
|
-- check its child elements in reverse order, returning if something handles it
|
||||||
for i = #element.child, 1, -1
|
for i = #element.child, 1, -1
|
||||||
if handled = pop.mousepressed x, y, button, element.child[i]
|
if handled = pop.mousepressed x, y, button, element.child[i]
|
||||||
return handled
|
return handled
|
||||||
|
|
||||||
-- if a child hasn't handled it yet
|
-- if a child hasn't handled it yet (note: this check doesn't seem neccessary)
|
||||||
unless handled
|
unless handled
|
||||||
-- if we can handle it and are visible, try to handle it, and set pop.focused
|
-- if we can handle it and are visible, try to handle it, and set pop.focused
|
||||||
if element.mousepressed and (not element.excludeDraw)
|
if element.mousepressed and element.data.draw
|
||||||
if handled = element\mousepressed x - element.x, y - element.y, button
|
if handled = element\mousepressed x - element.data.x, y - element.data.y, button
|
||||||
pop.focused = element
|
pop.focused = element
|
||||||
|
|
||||||
-- return whether or not we have handled the event
|
-- return whether or not we have handled the event
|
||||||
return handled
|
return handled
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
--- Event handler for `love.mousereleased()` events.
|
||||||
|
--- @function mousereleased
|
||||||
|
--- @param x The x coordinate of the mouse release.
|
||||||
|
--- @param y The y coordinate of the mouse release.
|
||||||
|
--- @param button The mouse button released.
|
||||||
|
--- @param element *Optional* The element to check for event handling. Defaults to `pop.screen` (and loops through all its children).
|
||||||
|
--- @return `true` / `false`: Was a click handled?
|
||||||
|
--- @return `true` / `false`: Was a mouse release handled?
|
||||||
|
|
||||||
pop.mousereleased = (x, y, button, element) ->
|
pop.mousereleased = (x, y, button, element) ->
|
||||||
-- we are trying to handle a clicked or mousereleased event
|
-- we are trying to handle a clicked or mousereleased event
|
||||||
clickedHandled = false
|
clickedHandled = false
|
||||||
@ -147,24 +236,26 @@ pop.mousereleased = (x, y, button, element) ->
|
|||||||
|
|
||||||
-- if we have an element, and are within its bounds
|
-- if we have an element, and are within its bounds
|
||||||
if element
|
if element
|
||||||
if (x >= element.x) and (x <= element.x + element.w) and (y >= element.y) and (y <= element.y + element.h)
|
if (x >= element.data.x) and (x <= element.data.x + element.data.w) and (y >= element.data.y) and (y <= element.data.y + element.data.h)
|
||||||
-- check its children in reverse for handling a clicked or mousereleased event
|
-- check its children in reverse for handling a clicked or mousereleased event
|
||||||
for i = #element.child, 1, -1
|
for i = #element.child, 1, -1
|
||||||
clickedHandled, mousereleasedHandled = pop.mousereleased x, y, button, element.child[i]
|
clickedHandled, mousereleasedHandled = pop.mousereleased x, y, button, element.child[i]
|
||||||
if clickedHandled or mousereleasedHandled
|
if clickedHandled or mousereleasedHandled
|
||||||
return clickedHandled, mousereleasedHandled
|
return clickedHandled, mousereleasedHandled
|
||||||
|
|
||||||
-- if that doesn't work, we try to handle it ourselves
|
-- if that doesn't work, we try to handle it ourselves (note: again, this check seems unneccessary)
|
||||||
unless clickedHandled or mousereleasedHandled
|
unless clickedHandled or mousereleasedHandled
|
||||||
-- clicked only happens on visible elements, mousereleased happens either way
|
-- clicked only happens on visible elements, mousereleased happens either way
|
||||||
if element.clicked and (not element.excludeDraw)
|
if element.clicked and element.data.draw
|
||||||
clickedHandled = element\clicked x - element.x, y - element.y, button
|
clickedHandled = element\clicked x - element.data.x, y - element.data.y, button
|
||||||
if element.mousereleased
|
if element.mousereleased
|
||||||
mousereleasedHandled = element\mousereleased x - element.x, y - element.y, button
|
mousereleasedHandled = element\mousereleased x - element.data.x, y - element.data.y, button
|
||||||
|
|
||||||
-- if we clicked, we're focused!
|
-- if we clicked, we're focused!
|
||||||
if clickedHandled
|
if clickedHandled
|
||||||
pop.focused = element
|
pop.focused = element
|
||||||
|
--- @todo Figure out how to bring a focused element to the front of view (aka the first element in its parent's children).
|
||||||
|
--- (If I do it right here, the for loop above may break! I need to test/figure this out.)
|
||||||
--NOTE this might cause an error in the above for loop!
|
--NOTE this might cause an error in the above for loop!
|
||||||
-- basically, move focused element to front of its parent's child
|
-- basically, move focused element to front of its parent's child
|
||||||
--element.parent\focusChild element
|
--element.parent\focusChild element
|
@ -1,110 +0,0 @@
|
|||||||
local graphics
|
|
||||||
graphics = love.graphics
|
|
||||||
local sub, len
|
|
||||||
do
|
|
||||||
local _obj_0 = string
|
|
||||||
sub, len = _obj_0.sub, _obj_0.len
|
|
||||||
end
|
|
||||||
local path = sub(..., 1, len(...) - len("/box"))
|
|
||||||
local element = require(tostring(path) .. "/element")
|
|
||||||
local box
|
|
||||||
do
|
|
||||||
local _class_0
|
|
||||||
local _parent_0 = element
|
|
||||||
local _base_0 = {
|
|
||||||
draw = function(self)
|
|
||||||
if self.background then
|
|
||||||
if type(self.background) == "table" then
|
|
||||||
graphics.setColor(self.background)
|
|
||||||
graphics.rectangle("fill", self.x, self.y, self.w, self.h)
|
|
||||||
else
|
|
||||||
local w, h = self.background:getDimensions()
|
|
||||||
w = self.w / w
|
|
||||||
h = self.h / h
|
|
||||||
graphics.setColor(255, 255, 255, 255)
|
|
||||||
graphics.draw(self.background, self.x, self.y, 0, w, h)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
debugDraw = function(self)
|
|
||||||
graphics.setLineWidth(0.5)
|
|
||||||
graphics.setColor(0, 0, 0, 100)
|
|
||||||
graphics.rectangle("fill", self.x, self.y, self.w, self.h)
|
|
||||||
graphics.setColor(0, 0, 200, 200)
|
|
||||||
graphics.rectangle("line", self.x, self.y, self.w, self.h)
|
|
||||||
graphics.setColor(200, 200, 255, 255)
|
|
||||||
graphics.print("b", self.x, self.y)
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
setBackground = function(self, background)
|
|
||||||
self.background = background
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
getBackground = function(self)
|
|
||||||
return self.background
|
|
||||||
end,
|
|
||||||
setColor = function(self, r, g, b, a)
|
|
||||||
if a == nil then
|
|
||||||
a = 255
|
|
||||||
end
|
|
||||||
if type(r) == "table" then
|
|
||||||
self.background = r
|
|
||||||
else
|
|
||||||
self.background = {
|
|
||||||
r,
|
|
||||||
g,
|
|
||||||
b,
|
|
||||||
a
|
|
||||||
}
|
|
||||||
end
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
getColor = function(self)
|
|
||||||
if type(self.background) == "table" then
|
|
||||||
return unpack(self.background)
|
|
||||||
else
|
|
||||||
return error("Box \"" .. tostring(self) .. "\" doesn't have a color.")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
}
|
|
||||||
_base_0.__index = _base_0
|
|
||||||
setmetatable(_base_0, _parent_0.__base)
|
|
||||||
_class_0 = setmetatable({
|
|
||||||
__init = function(self, parent, background)
|
|
||||||
if background == nil then
|
|
||||||
background = false
|
|
||||||
end
|
|
||||||
_class_0.__parent.__init(self, parent)
|
|
||||||
self.w = 20
|
|
||||||
self.h = 20
|
|
||||||
self.background = background
|
|
||||||
end,
|
|
||||||
__base = _base_0,
|
|
||||||
__name = "box",
|
|
||||||
__parent = _parent_0
|
|
||||||
}, {
|
|
||||||
__index = function(cls, name)
|
|
||||||
local val = rawget(_base_0, name)
|
|
||||||
if val == nil then
|
|
||||||
local parent = rawget(cls, "__parent")
|
|
||||||
if parent then
|
|
||||||
return parent[name]
|
|
||||||
end
|
|
||||||
else
|
|
||||||
return val
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
__call = function(cls, ...)
|
|
||||||
local _self_0 = setmetatable({}, _base_0)
|
|
||||||
cls.__init(_self_0, ...)
|
|
||||||
return _self_0
|
|
||||||
end
|
|
||||||
})
|
|
||||||
_base_0.__class = _class_0
|
|
||||||
if _parent_0.__inherited then
|
|
||||||
_parent_0.__inherited(_parent_0, _class_0)
|
|
||||||
end
|
|
||||||
box = _class_0
|
|
||||||
return _class_0
|
|
||||||
end
|
|
@ -1,296 +0,0 @@
|
|||||||
local graphics
|
|
||||||
graphics = love.graphics
|
|
||||||
local floor
|
|
||||||
floor = math.floor
|
|
||||||
local insert, remove
|
|
||||||
do
|
|
||||||
local _obj_0 = table
|
|
||||||
insert, remove = _obj_0.insert, _obj_0.remove
|
|
||||||
end
|
|
||||||
local tonumber = tonumber
|
|
||||||
local element
|
|
||||||
do
|
|
||||||
local _class_0
|
|
||||||
local _base_0 = {
|
|
||||||
debugDraw = function(self)
|
|
||||||
graphics.setLineWidth(0.5)
|
|
||||||
graphics.setColor(0, 0, 0, 100)
|
|
||||||
graphics.rectangle("fill", self.x, self.y, self.w, self.h)
|
|
||||||
graphics.setColor(0, 200, 0, 200)
|
|
||||||
graphics.rectangle("line", self.x, self.y, self.w, self.h)
|
|
||||||
graphics.setColor(200, 255, 200, 255)
|
|
||||||
graphics.print("e", self.x, self.y)
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
addChild = function(self, child)
|
|
||||||
if child.parent then
|
|
||||||
child.parent:removeChild(child)
|
|
||||||
end
|
|
||||||
insert(self.child, child)
|
|
||||||
child.parent = self
|
|
||||||
child:align()
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
removeChild = function(self, child)
|
|
||||||
if tonumber(child) == child then
|
|
||||||
self.child[child].parent = false
|
|
||||||
return remove(self.child, child)
|
|
||||||
else
|
|
||||||
for k, v in ipairs(self.child) do
|
|
||||||
if v == child then
|
|
||||||
return remove(self.child, k)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return "Element \"" .. tostring(child) .. "\" is not a child of element \"" .. tostring(self) .. "\". Cannot remove it."
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
getChildren = function(self)
|
|
||||||
return self.child
|
|
||||||
end,
|
|
||||||
move = function(self, x, y)
|
|
||||||
if x then
|
|
||||||
self.x = self.x + x
|
|
||||||
end
|
|
||||||
if y then
|
|
||||||
self.y = self.y + y
|
|
||||||
end
|
|
||||||
for i = 1, #self.child do
|
|
||||||
if not (self.child[i].excludeMovement) then
|
|
||||||
self.child[i]:move(x, y)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
setPosition = function(self, x, y)
|
|
||||||
local oldX = self.x
|
|
||||||
local oldY = self.y
|
|
||||||
if x then
|
|
||||||
local _exp_0 = self.horizontal
|
|
||||||
if "left" == _exp_0 then
|
|
||||||
self.x = x
|
|
||||||
elseif "center" == _exp_0 then
|
|
||||||
self.x = x - self.w / 2
|
|
||||||
elseif "right" == _exp_0 then
|
|
||||||
self.x = x - self.w
|
|
||||||
end
|
|
||||||
else
|
|
||||||
x = oldX
|
|
||||||
end
|
|
||||||
if y then
|
|
||||||
local _exp_0 = self.vertical
|
|
||||||
if "top" == _exp_0 then
|
|
||||||
self.y = y
|
|
||||||
elseif "center" == _exp_0 then
|
|
||||||
self.y = y - self.h / 2
|
|
||||||
elseif "bottom" == _exp_0 then
|
|
||||||
self.y = y - self.h
|
|
||||||
end
|
|
||||||
else
|
|
||||||
y = oldY
|
|
||||||
end
|
|
||||||
for i = 1, #self.child do
|
|
||||||
self.child[i]:move(x - oldX, y - oldY)
|
|
||||||
end
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
getPosition = function(self)
|
|
||||||
local resultX = self.x
|
|
||||||
local resultY = self.y
|
|
||||||
local _exp_0 = self.horizontal
|
|
||||||
if "center" == _exp_0 then
|
|
||||||
resultX = resultX + (self.w / 2)
|
|
||||||
elseif "right" == _exp_0 then
|
|
||||||
resultY = resultY + self.w
|
|
||||||
end
|
|
||||||
local _exp_1 = self.vertical
|
|
||||||
if "center" == _exp_1 then
|
|
||||||
resultY = resultY + (self.h / 2)
|
|
||||||
elseif "bottom" == _exp_1 then
|
|
||||||
resultY = resultY + self.h
|
|
||||||
end
|
|
||||||
return resultX, resultY
|
|
||||||
end,
|
|
||||||
setSize = function(self, w, h)
|
|
||||||
if w then
|
|
||||||
local _exp_0 = self.horizontal
|
|
||||||
if "center" == _exp_0 then
|
|
||||||
self.x = self.x - ((w - self.w) / 2)
|
|
||||||
elseif "right" == _exp_0 then
|
|
||||||
self.x = self.x - (w - self.w)
|
|
||||||
end
|
|
||||||
self.w = w
|
|
||||||
end
|
|
||||||
if h then
|
|
||||||
local _exp_0 = self.vertical
|
|
||||||
if "center" == _exp_0 then
|
|
||||||
self.y = self.y - ((h - self.h) / 2)
|
|
||||||
elseif "bottom" == _exp_0 then
|
|
||||||
self.y = self.y - (h - self.h)
|
|
||||||
end
|
|
||||||
self.h = h
|
|
||||||
end
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
getSize = function(self)
|
|
||||||
return self.w, self.h
|
|
||||||
end,
|
|
||||||
setWidth = function(self, w)
|
|
||||||
local _exp_0 = self.horizontal
|
|
||||||
if "center" == _exp_0 then
|
|
||||||
self.x = self.x - ((w - self.w) / 2)
|
|
||||||
elseif "right" == _exp_0 then
|
|
||||||
self.x = self.x - (w - self.w)
|
|
||||||
end
|
|
||||||
self.w = w
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
getWidth = function(self)
|
|
||||||
return self.w
|
|
||||||
end,
|
|
||||||
setHeight = function(self, h)
|
|
||||||
local _exp_0 = self.vertical
|
|
||||||
if "center" == _exp_0 then
|
|
||||||
self.y = self.y - ((h - self.h) / 2)
|
|
||||||
elseif "bottom" == _exp_0 then
|
|
||||||
self.y = self.y - (h - self.h)
|
|
||||||
end
|
|
||||||
self.h = h
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
getHeight = function(self)
|
|
||||||
return self.h
|
|
||||||
end,
|
|
||||||
adjustSize = function(self, w, h)
|
|
||||||
local W, H = self:getSize()
|
|
||||||
if w then
|
|
||||||
W = W + w
|
|
||||||
end
|
|
||||||
if h then
|
|
||||||
H = H + h
|
|
||||||
end
|
|
||||||
self:setSize(W, H)
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
align = function(self, horizontal, vertical, toPixel)
|
|
||||||
if toPixel == nil then
|
|
||||||
toPixel = true
|
|
||||||
end
|
|
||||||
self:setAlignment(horizontal, vertical)
|
|
||||||
self.x = self.parent.x
|
|
||||||
self.y = self.parent.y
|
|
||||||
local _exp_0 = self.horizontal
|
|
||||||
if "left" == _exp_0 then
|
|
||||||
self.x = self.x + self.spacing
|
|
||||||
elseif "center" == _exp_0 then
|
|
||||||
self.x = self.x + ((self.parent.w - self.w) / 2)
|
|
||||||
elseif "right" == _exp_0 then
|
|
||||||
self.x = self.x + (self.parent.w - self.w - self.spacing)
|
|
||||||
end
|
|
||||||
local _exp_1 = self.vertical
|
|
||||||
if "top" == _exp_1 then
|
|
||||||
self.y = self.y + self.spacing
|
|
||||||
elseif "center" == _exp_1 then
|
|
||||||
self.y = self.y + ((self.parent.h - self.h) / 2)
|
|
||||||
elseif "bottom" == _exp_1 then
|
|
||||||
self.y = self.y + (self.parent.h - self.h - self.spacing)
|
|
||||||
end
|
|
||||||
if toPixel then
|
|
||||||
self.x = floor(self.x)
|
|
||||||
self.y = floor(self.y)
|
|
||||||
end
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
alignTo = function(self, element, horizontal, vertical, toPixel)
|
|
||||||
if toPixel == nil then
|
|
||||||
toPixel = true
|
|
||||||
end
|
|
||||||
local parent = self.parent
|
|
||||||
self.parent = element
|
|
||||||
self:align(horizontal, vertical, toPixel)
|
|
||||||
self.parent = parent
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
setAlignment = function(self, horizontal, vertical)
|
|
||||||
if horizontal then
|
|
||||||
self.horizontal = horizontal
|
|
||||||
end
|
|
||||||
if vertical then
|
|
||||||
self.vertical = vertical
|
|
||||||
end
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
getAlignment = function(self)
|
|
||||||
return self.horizontal, self.vertical
|
|
||||||
end,
|
|
||||||
setMargin = function(self, spacing)
|
|
||||||
self.spacing = spacing
|
|
||||||
self:align()
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
getMargin = function(self)
|
|
||||||
return self.spacing
|
|
||||||
end,
|
|
||||||
fill = function(self)
|
|
||||||
self.x = self.parent.x + self.spacing
|
|
||||||
self.y = self.parent.y + self.spacing
|
|
||||||
self.w = self.parent.w - self.spacing * 2
|
|
||||||
self.h = self.parent.h - self.spacing * 2
|
|
||||||
end,
|
|
||||||
delete = function(self)
|
|
||||||
for k, v in ipairs(self.child) do
|
|
||||||
v:delete()
|
|
||||||
end
|
|
||||||
self.parent:removeChild(self)
|
|
||||||
self = nil
|
|
||||||
return nil
|
|
||||||
end,
|
|
||||||
getVisibility = function(self)
|
|
||||||
return (not self.excludeDraw)
|
|
||||||
end,
|
|
||||||
setVisibility = function(self, isVisible)
|
|
||||||
self.excludeDraw = (not isVisible)
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
getStatic = function(self)
|
|
||||||
return self.excludeMovement
|
|
||||||
end,
|
|
||||||
setStatic = function(self, isStatic)
|
|
||||||
self.excludeMovement = isStatic
|
|
||||||
return self
|
|
||||||
end
|
|
||||||
}
|
|
||||||
_base_0.__index = _base_0
|
|
||||||
_class_0 = setmetatable({
|
|
||||||
__init = function(self, parent)
|
|
||||||
self.parent = parent
|
|
||||||
self.child = { }
|
|
||||||
self.w = 0
|
|
||||||
self.h = 0
|
|
||||||
self.spacing = 0
|
|
||||||
if parent then
|
|
||||||
self.x = parent.x
|
|
||||||
self.y = parent.y
|
|
||||||
else
|
|
||||||
self.x = 0
|
|
||||||
self.y = 0
|
|
||||||
end
|
|
||||||
self.horizontal = "left"
|
|
||||||
self.vertical = "top"
|
|
||||||
self.excludeDraw = false
|
|
||||||
self.excludeUpdate = false
|
|
||||||
self.excludeMovement = false
|
|
||||||
end,
|
|
||||||
__base = _base_0,
|
|
||||||
__name = "element"
|
|
||||||
}, {
|
|
||||||
__index = _base_0,
|
|
||||||
__call = function(cls, ...)
|
|
||||||
local _self_0 = setmetatable({}, _base_0)
|
|
||||||
cls.__init(_self_0, ...)
|
|
||||||
return _self_0
|
|
||||||
end
|
|
||||||
})
|
|
||||||
_base_0.__class = _class_0
|
|
||||||
element = _class_0
|
|
||||||
return _class_0
|
|
||||||
end
|
|
Binary file not shown.
Before Width: | Height: | Size: 303 B |
@ -1,154 +0,0 @@
|
|||||||
local graphics
|
|
||||||
graphics = love.graphics
|
|
||||||
local sub, len
|
|
||||||
do
|
|
||||||
local _obj_0 = string
|
|
||||||
sub, len = _obj_0.sub, _obj_0.len
|
|
||||||
end
|
|
||||||
local path = sub(..., 1, len(...) - len("/box"))
|
|
||||||
local element = require(tostring(path) .. "/element")
|
|
||||||
local text
|
|
||||||
do
|
|
||||||
local _class_0
|
|
||||||
local _parent_0 = element
|
|
||||||
local _base_0 = {
|
|
||||||
draw = function(self)
|
|
||||||
graphics.setColor(self.color)
|
|
||||||
graphics.setFont(self.font)
|
|
||||||
graphics.print(self.txt, self.x, self.y)
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
debugDraw = function(self)
|
|
||||||
graphics.setLineWidth(0.5)
|
|
||||||
graphics.setColor(0, 0, 0, 100)
|
|
||||||
graphics.rectangle("fill", self.x, self.y, self.w, self.h)
|
|
||||||
graphics.setColor(200, 0, 0, 200)
|
|
||||||
graphics.rectangle("line", self.x, self.y, self.w, self.h)
|
|
||||||
graphics.setColor(255, 200, 200, 255)
|
|
||||||
graphics.print("t", self.x, self.y)
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
setSize = function(self)
|
|
||||||
local w = self.font:getWidth(self.txt)
|
|
||||||
local h = self.font:getHeight() * (select(2, self.txt:gsub("\n", "\n")) + 1)
|
|
||||||
local _exp_0 = self.horizontal
|
|
||||||
if "center" == _exp_0 then
|
|
||||||
self.x = self.x - ((w - self.w) / 2)
|
|
||||||
elseif "right" == _exp_0 then
|
|
||||||
self.x = self.x - (w - self.w - self.spacing)
|
|
||||||
end
|
|
||||||
local _exp_1 = self.vertical
|
|
||||||
if "center" == _exp_1 then
|
|
||||||
self.y = self.y - ((h - self.h) / 2)
|
|
||||||
elseif "bottom" == _exp_1 then
|
|
||||||
self.y = self.y - (h - self.h - self.spacing)
|
|
||||||
end
|
|
||||||
self.w = w
|
|
||||||
self.h = h
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
setWidth = function(self)
|
|
||||||
self:setSize()
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
setHeight = function(self)
|
|
||||||
self:setSize()
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
setText = function(self, text)
|
|
||||||
if text == nil then
|
|
||||||
text = ""
|
|
||||||
end
|
|
||||||
self.txt = text
|
|
||||||
self:setSize()
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
getText = function(self)
|
|
||||||
return self.txt
|
|
||||||
end,
|
|
||||||
setFont = function(self, font)
|
|
||||||
self.font = font
|
|
||||||
self:setSize()
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
getFont = function(self)
|
|
||||||
return self.font
|
|
||||||
end,
|
|
||||||
setColor = function(self, r, g, b, a)
|
|
||||||
if a == nil then
|
|
||||||
a = 255
|
|
||||||
end
|
|
||||||
if type(r) == "table" then
|
|
||||||
self.color = r
|
|
||||||
else
|
|
||||||
self.color = {
|
|
||||||
r,
|
|
||||||
g,
|
|
||||||
b,
|
|
||||||
a
|
|
||||||
}
|
|
||||||
end
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
getColor = function(self)
|
|
||||||
return unpack(self.color)
|
|
||||||
end
|
|
||||||
}
|
|
||||||
_base_0.__index = _base_0
|
|
||||||
setmetatable(_base_0, _parent_0.__base)
|
|
||||||
_class_0 = setmetatable({
|
|
||||||
__init = function(self, parent, text, color)
|
|
||||||
if text == nil then
|
|
||||||
text = ""
|
|
||||||
end
|
|
||||||
if color == nil then
|
|
||||||
color = {
|
|
||||||
255,
|
|
||||||
255,
|
|
||||||
255,
|
|
||||||
255
|
|
||||||
}
|
|
||||||
end
|
|
||||||
_class_0.__parent.__init(self, parent)
|
|
||||||
self.font = graphics.newFont(14)
|
|
||||||
self:setText(text)
|
|
||||||
self.color = color
|
|
||||||
end,
|
|
||||||
__base = _base_0,
|
|
||||||
__name = "text",
|
|
||||||
__parent = _parent_0
|
|
||||||
}, {
|
|
||||||
__index = function(cls, name)
|
|
||||||
local val = rawget(_base_0, name)
|
|
||||||
if val == nil then
|
|
||||||
local parent = rawget(cls, "__parent")
|
|
||||||
if parent then
|
|
||||||
return parent[name]
|
|
||||||
end
|
|
||||||
else
|
|
||||||
return val
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
__call = function(cls, ...)
|
|
||||||
local _self_0 = setmetatable({}, _base_0)
|
|
||||||
cls.__init(_self_0, ...)
|
|
||||||
return _self_0
|
|
||||||
end
|
|
||||||
})
|
|
||||||
_base_0.__class = _class_0
|
|
||||||
local self = _class_0
|
|
||||||
self.wrap = function(pop)
|
|
||||||
return function(parent, ...)
|
|
||||||
if type(parent) == "string" then
|
|
||||||
return pop.create("text", nil, parent, ...)
|
|
||||||
else
|
|
||||||
return pop.create("text", parent, ...)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if _parent_0.__inherited then
|
|
||||||
_parent_0.__inherited(_parent_0, _class_0)
|
|
||||||
end
|
|
||||||
text = _class_0
|
|
||||||
return _class_0
|
|
||||||
end
|
|
@ -1,353 +0,0 @@
|
|||||||
local graphics, mouse
|
|
||||||
do
|
|
||||||
local _obj_0 = love
|
|
||||||
graphics, mouse = _obj_0.graphics, _obj_0.mouse
|
|
||||||
end
|
|
||||||
local insert, remove
|
|
||||||
do
|
|
||||||
local _obj_0 = table
|
|
||||||
insert, remove = _obj_0.insert, _obj_0.remove
|
|
||||||
end
|
|
||||||
local sub, len
|
|
||||||
do
|
|
||||||
local _obj_0 = string
|
|
||||||
sub, len = _obj_0.sub, _obj_0.len
|
|
||||||
end
|
|
||||||
local path = sub(..., 1, len(...) - len("/window"))
|
|
||||||
local element = require(tostring(path) .. "/element")
|
|
||||||
local box = require(tostring(path) .. "/box")
|
|
||||||
local text = require(tostring(path) .. "/text")
|
|
||||||
local closeImage = graphics.newImage(tostring(path) .. "/img/close.png")
|
|
||||||
local left = 1
|
|
||||||
local mousemoved_event = true
|
|
||||||
do
|
|
||||||
local major, minor, revision = love.getVersion()
|
|
||||||
if (major == 0) and (minor == 10) and ((revision == 0) or (revision == 1)) then
|
|
||||||
left = 1
|
|
||||||
elseif (major == 0) and (minor == 9) then
|
|
||||||
left = "l"
|
|
||||||
if revision == 1 then
|
|
||||||
mousemoved_event = false
|
|
||||||
end
|
|
||||||
else
|
|
||||||
print("elements/window: unrecognized LOVE version: " .. tostring(major) .. "." .. tostring(minor) .. "." .. tostring(revision))
|
|
||||||
print(" assuming LOVE version > 0.10.1 (there may be bugs)")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
local pop_ref = false
|
|
||||||
local window
|
|
||||||
do
|
|
||||||
local _class_0
|
|
||||||
local _parent_0 = element
|
|
||||||
local _base_0 = {
|
|
||||||
load = function(pop)
|
|
||||||
pop_ref = pop
|
|
||||||
end,
|
|
||||||
debugDraw = function(self)
|
|
||||||
graphics.setLineWidth(0.5)
|
|
||||||
graphics.setColor(0, 0, 0, 100)
|
|
||||||
graphics.rectangle("fill", self.x, self.y, self.w, self.h)
|
|
||||||
graphics.setColor(200, 0, 200, 200)
|
|
||||||
graphics.rectangle("line", self.x, self.y, self.w, self.h)
|
|
||||||
graphics.setColor(255, 200, 255, 255)
|
|
||||||
graphics.print("w", self.x, self.y)
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
addChild = function(self, child)
|
|
||||||
self.area:addChild(child)
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
removeChild = function(self, child)
|
|
||||||
local result = self.area:removeChild(child)
|
|
||||||
if result == self.area then
|
|
||||||
return self
|
|
||||||
elseif type(result) == "string" then
|
|
||||||
for k, v in ipairs(self.child) do
|
|
||||||
if v == child then
|
|
||||||
remove(self.child, k)
|
|
||||||
return self
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return "Element \"" .. tostring(child) .. "\" is not a child of window \"" .. tostring(self) .. "\". Cannot remove it."
|
|
||||||
else
|
|
||||||
return result
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
getChildren = function(self)
|
|
||||||
return self.area.child
|
|
||||||
end,
|
|
||||||
align = function(self, horizontal, vertical, toPixel)
|
|
||||||
_class_0.__parent.__base.align(self, horizontal, vertical, toPixel)
|
|
||||||
for i = 1, #self.child do
|
|
||||||
self.child[i]:align()
|
|
||||||
end
|
|
||||||
self.area:move(nil, self.head:getHeight())
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
setSize = function(self, w, h)
|
|
||||||
local x = 0
|
|
||||||
local y = 0
|
|
||||||
if w then
|
|
||||||
local _exp_0 = self.horizontal
|
|
||||||
if "center" == _exp_0 then
|
|
||||||
x = x - ((w - self.w) / 2)
|
|
||||||
elseif "right" == _exp_0 then
|
|
||||||
x = x - (w - self.w)
|
|
||||||
end
|
|
||||||
if self.close then
|
|
||||||
self.head:setWidth(w - self.head:getHeight())
|
|
||||||
else
|
|
||||||
self.head:setWidth(w)
|
|
||||||
end
|
|
||||||
self.area:setWidth(w)
|
|
||||||
self.w = w
|
|
||||||
self.x = self.x + x
|
|
||||||
self.title:align()
|
|
||||||
if self.close then
|
|
||||||
self.close:align()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if h then
|
|
||||||
h = h - self.head:getHeight()
|
|
||||||
local _exp_0 = self.vertical
|
|
||||||
if "center" == _exp_0 then
|
|
||||||
y = y - ((h - self.h) / 2)
|
|
||||||
elseif "right" == _exp_0 then
|
|
||||||
y = y - (h - self.h)
|
|
||||||
end
|
|
||||||
self.area:setHeight(h)
|
|
||||||
self.h = h + self.head:getHeight()
|
|
||||||
self.y = self.y + y
|
|
||||||
end
|
|
||||||
self.head:move(x, y)
|
|
||||||
self.area:move(x, y)
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
setWidth = function(self, w)
|
|
||||||
local x = 0
|
|
||||||
local _exp_0 = self.horizontal
|
|
||||||
if "center" == _exp_0 then
|
|
||||||
x = x - ((w - self.w) / 2)
|
|
||||||
elseif "right" == _exp_0 then
|
|
||||||
x = x - (w - self.w)
|
|
||||||
end
|
|
||||||
if self.close then
|
|
||||||
self.head:setWidth(w - self.head:getHeight())
|
|
||||||
else
|
|
||||||
self.head:setWidth(w)
|
|
||||||
end
|
|
||||||
self.area:setWidth(w)
|
|
||||||
self.w = w
|
|
||||||
self.x = self.x + x
|
|
||||||
self.title:align()
|
|
||||||
if self.close then
|
|
||||||
self.close:align()
|
|
||||||
end
|
|
||||||
self.head:move(x)
|
|
||||||
self.area:move(x)
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
setHeight = function(self, h)
|
|
||||||
local y = 0
|
|
||||||
h = h - self.head:getHeight()
|
|
||||||
local _exp_0 = self.vertical
|
|
||||||
if "center" == _exp_0 then
|
|
||||||
y = y - ((h - self.h) / 2)
|
|
||||||
elseif "right" == _exp_0 then
|
|
||||||
y = y - (h - self.h)
|
|
||||||
end
|
|
||||||
self.area:setHeight(h)
|
|
||||||
self.h = h + self.head:getHeight()
|
|
||||||
self.y = self.y + y
|
|
||||||
self.head:move(nil, y)
|
|
||||||
self.title:move(nil, y)
|
|
||||||
self.area:move(nil, y)
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
setTitle = function(self, title)
|
|
||||||
self.title:setText(title)
|
|
||||||
if self.titleOverflow == "trunicate" then
|
|
||||||
while self.title:getWidth() > self.head:getWidth() do
|
|
||||||
title = title:sub(1, -3)
|
|
||||||
self.title:setText(title .. "…")
|
|
||||||
end
|
|
||||||
elseif self.titleOverflow == "resize" then
|
|
||||||
if self.title:getWidth() > self.head:getWidth() then
|
|
||||||
self:setWidth(self.title:getWidth())
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
getTitle = function(self)
|
|
||||||
return self.title:getText()
|
|
||||||
end,
|
|
||||||
setTitleOverflow = function(self, method)
|
|
||||||
self.titleOverflow = method
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
getTitleOverflow = function(self)
|
|
||||||
return self.titleOverflow
|
|
||||||
end,
|
|
||||||
setClose = function(self, enabled)
|
|
||||||
if enabled then
|
|
||||||
self.close = box(self, closeImage)
|
|
||||||
self.close.clicked = function()
|
|
||||||
self:delete()
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
local height = self.head:getHeight()
|
|
||||||
self.close:align("right"):setSize(height, height)
|
|
||||||
self.head:setWidth(self.w - height)
|
|
||||||
self.title:align()
|
|
||||||
insert(self.child, self.close)
|
|
||||||
else
|
|
||||||
self.close:delete()
|
|
||||||
self.head:setWidth(self.w)
|
|
||||||
self.title:align()
|
|
||||||
self.close = false
|
|
||||||
end
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
hasClose = function(self)
|
|
||||||
if self.close then
|
|
||||||
return true
|
|
||||||
else
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
delete = function(self)
|
|
||||||
_class_0.__parent.__base.delete(self)
|
|
||||||
self.head = nil
|
|
||||||
self.title = nil
|
|
||||||
self.area = nil
|
|
||||||
self.close = nil
|
|
||||||
end
|
|
||||||
}
|
|
||||||
_base_0.__index = _base_0
|
|
||||||
setmetatable(_base_0, _parent_0.__base)
|
|
||||||
_class_0 = setmetatable({
|
|
||||||
__init = function(self, parent, title, tBackground, tColor, wBackground)
|
|
||||||
if title == nil then
|
|
||||||
title = "window"
|
|
||||||
end
|
|
||||||
if tBackground == nil then
|
|
||||||
tBackground = {
|
|
||||||
25,
|
|
||||||
180,
|
|
||||||
230,
|
|
||||||
255
|
|
||||||
}
|
|
||||||
end
|
|
||||||
if tColor == nil then
|
|
||||||
tColor = {
|
|
||||||
255,
|
|
||||||
255,
|
|
||||||
255,
|
|
||||||
255
|
|
||||||
}
|
|
||||||
end
|
|
||||||
if wBackground == nil then
|
|
||||||
wBackground = {
|
|
||||||
200,
|
|
||||||
200,
|
|
||||||
210,
|
|
||||||
255
|
|
||||||
}
|
|
||||||
end
|
|
||||||
_class_0.__parent.__init(self, parent)
|
|
||||||
self.head = box(self, tBackground)
|
|
||||||
self.title = text(self.head, title, tColor)
|
|
||||||
self.area = box(self, wBackground)
|
|
||||||
self.close = box(self, closeImage)
|
|
||||||
local height = self.title:getHeight()
|
|
||||||
self.head:setSize(self.w - height, height)
|
|
||||||
self.area:move(nil, height)
|
|
||||||
self.close:align("right"):setSize(height, height)
|
|
||||||
self:setSize(100, 80)
|
|
||||||
self.child = {
|
|
||||||
self.head,
|
|
||||||
self.title,
|
|
||||||
self.area,
|
|
||||||
self.close
|
|
||||||
}
|
|
||||||
self.titleOverflow = "trunicate"
|
|
||||||
self.area.mousepressed = function()
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
self.area.clicked = function()
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
self.close.clicked = function()
|
|
||||||
self:delete()
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
self.head.selected = false
|
|
||||||
if mousemoved_event then
|
|
||||||
self.head.mousemoved = function(self, x, y, dx, dy)
|
|
||||||
if self.selected then
|
|
||||||
self.parent:move(dx, dy)
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
self.head.mousepressed = function(self, x, y, button)
|
|
||||||
if button == left then
|
|
||||||
self.selected = true
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
else
|
|
||||||
self.head.mx = 0
|
|
||||||
self.head.my = 0
|
|
||||||
self.head.update = function(self)
|
|
||||||
local x, y = mouse.getPosition()
|
|
||||||
return self:setPosition(x - mx, y - my)
|
|
||||||
end
|
|
||||||
self.head.mousepressed = function(self, x, y, button)
|
|
||||||
if button == left then
|
|
||||||
self.selected = true
|
|
||||||
self.mx = x
|
|
||||||
self.my = y
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
self.head.mousereleased = function(self, x, y, button)
|
|
||||||
if button == left then
|
|
||||||
self.selected = false
|
|
||||||
pop_ref.focused = false
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
__base = _base_0,
|
|
||||||
__name = "window",
|
|
||||||
__parent = _parent_0
|
|
||||||
}, {
|
|
||||||
__index = function(cls, name)
|
|
||||||
local val = rawget(_base_0, name)
|
|
||||||
if val == nil then
|
|
||||||
local parent = rawget(cls, "__parent")
|
|
||||||
if parent then
|
|
||||||
return parent[name]
|
|
||||||
end
|
|
||||||
else
|
|
||||||
return val
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
__call = function(cls, ...)
|
|
||||||
local _self_0 = setmetatable({}, _base_0)
|
|
||||||
cls.__init(_self_0, ...)
|
|
||||||
return _self_0
|
|
||||||
end
|
|
||||||
})
|
|
||||||
_base_0.__class = _class_0
|
|
||||||
if _parent_0.__inherited then
|
|
||||||
_parent_0.__inherited(_parent_0, _class_0)
|
|
||||||
end
|
|
||||||
window = _class_0
|
|
||||||
return _class_0
|
|
||||||
end
|
|
@ -1,102 +0,0 @@
|
|||||||
local graphics
|
|
||||||
graphics = love.graphics
|
|
||||||
local sub, len
|
|
||||||
do
|
|
||||||
local _obj_0 = string
|
|
||||||
sub, len = _obj_0.sub, _obj_0.len
|
|
||||||
end
|
|
||||||
local path = sub(..., 1, len(...) - len("/extensions/streamlined_get_set"))
|
|
||||||
local element = require(tostring(path) .. "/elements/element")
|
|
||||||
local box = require(tostring(path) .. "/elements/box")
|
|
||||||
local text = require(tostring(path) .. "/elements/text")
|
|
||||||
element.__base.position = function(self, x, y)
|
|
||||||
if x or y then
|
|
||||||
return self:setPosition(x, y)
|
|
||||||
else
|
|
||||||
return self:getPosition()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
element.__base.size = function(self, w, h)
|
|
||||||
if w or h then
|
|
||||||
return self:setSize(w, h)
|
|
||||||
else
|
|
||||||
return self:getSize()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
element.__base.width = function(self, w)
|
|
||||||
if w then
|
|
||||||
return self:setWidth(w)
|
|
||||||
else
|
|
||||||
return self:getWidth()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
element.__base.height = function(self, h)
|
|
||||||
if h then
|
|
||||||
return self:setHeight(h)
|
|
||||||
else
|
|
||||||
return self:getHeight()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
element.__base.alignment = function(self, horizontal, vertical)
|
|
||||||
if horizontal or vertical then
|
|
||||||
return self:setAlignment(horizontal, vertical)
|
|
||||||
else
|
|
||||||
return self:getAlignment()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
element.__base.margin = function(self, m)
|
|
||||||
if m then
|
|
||||||
return self:setMargin(m)
|
|
||||||
else
|
|
||||||
return self:getMargin()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
element.__base.resize = element.__base.adjustSize
|
|
||||||
element.__base.visibility = function(self, v)
|
|
||||||
if v ~= nil then
|
|
||||||
return self:setVisibility(v)
|
|
||||||
else
|
|
||||||
return self:getVisibility()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
element.__base.show = function(self)
|
|
||||||
return self:setVisibility(true)
|
|
||||||
end
|
|
||||||
element.__base.hide = function(self)
|
|
||||||
return self:setVisibility(false)
|
|
||||||
end
|
|
||||||
element.__base.static = function(self, s)
|
|
||||||
if s ~= nil then
|
|
||||||
return self:setStatic(s)
|
|
||||||
else
|
|
||||||
return self:getStatic()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
box.__base.color = function(self, r, g, b, a)
|
|
||||||
if r or g or b or a then
|
|
||||||
return self:setColor(r, g, b, a)
|
|
||||||
else
|
|
||||||
return self:getColor()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
text.__base.text = function(self, text)
|
|
||||||
if text then
|
|
||||||
return self:setText(text)
|
|
||||||
else
|
|
||||||
return self:getText()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
text.__base.font = function(self, font)
|
|
||||||
if font then
|
|
||||||
return self:setFont(font)
|
|
||||||
else
|
|
||||||
return self:getFont()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
text.__base.color = function(self, r, g, b, a)
|
|
||||||
if r or g or b or a then
|
|
||||||
return self:setColor(r, g, b, a)
|
|
||||||
else
|
|
||||||
return self:getColor()
|
|
||||||
end
|
|
||||||
end
|
|
291
lib/pop/init.lua
291
lib/pop/init.lua
@ -1,291 +0,0 @@
|
|||||||
local pop = {
|
|
||||||
_VERSION = 'Pop.Box v0.0.0',
|
|
||||||
_DESCRIPTION = 'GUI library for LOVE, designed for ease of use',
|
|
||||||
_URL = 'http://github.com/Guard13007/Pop.Box',
|
|
||||||
_LICENSE = 'The MIT License (MIT)',
|
|
||||||
_AUTHOR = 'Paul Liverman III'
|
|
||||||
}
|
|
||||||
if not (love.getVersion) then
|
|
||||||
error("Pop.Box only supports LOVE versions >= 0.9.1")
|
|
||||||
end
|
|
||||||
local filesystem, graphics
|
|
||||||
do
|
|
||||||
local _obj_0 = love
|
|
||||||
filesystem, graphics = _obj_0.filesystem, _obj_0.graphics
|
|
||||||
end
|
|
||||||
local insert
|
|
||||||
insert = table.insert
|
|
||||||
local inheritsFromElement
|
|
||||||
inheritsFromElement = require(tostring(...) .. "/util").inheritsFromElement
|
|
||||||
local path = ...
|
|
||||||
pop.elements = { }
|
|
||||||
pop.skins = { }
|
|
||||||
pop.screen = false
|
|
||||||
pop.focused = false
|
|
||||||
pop.load = function()
|
|
||||||
local elements = filesystem.getDirectoryItems(tostring(path) .. "/elements")
|
|
||||||
for i = 1, #elements do
|
|
||||||
local _continue_0 = false
|
|
||||||
repeat
|
|
||||||
if not (elements[i]:sub(-4) == ".lua") then
|
|
||||||
_continue_0 = true
|
|
||||||
break
|
|
||||||
end
|
|
||||||
local name = elements[i]:sub(1, -5)
|
|
||||||
pop.elements[name] = require(tostring(path) .. "/elements/" .. tostring(name))
|
|
||||||
if pop.elements[name].load then
|
|
||||||
pop.elements[name].load(pop)
|
|
||||||
end
|
|
||||||
print("element loaded: \"" .. tostring(name) .. "\"")
|
|
||||||
if not (pop[name]) then
|
|
||||||
if pop.elements[name].wrap then
|
|
||||||
pop[name] = pop.elements[name].wrap(pop)
|
|
||||||
else
|
|
||||||
pop[name] = function(...)
|
|
||||||
return pop.create(name, ...)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
print("wrapper created: \"pop." .. tostring(name) .. "()\"")
|
|
||||||
end
|
|
||||||
_continue_0 = true
|
|
||||||
until true
|
|
||||||
if not _continue_0 then
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
local skins = filesystem.getDirectoryItems(tostring(path) .. "/skins")
|
|
||||||
for i = 1, #skins do
|
|
||||||
local _continue_0 = false
|
|
||||||
repeat
|
|
||||||
if not (skins[i]:sub(-4) == ".lua") then
|
|
||||||
_continue_0 = true
|
|
||||||
break
|
|
||||||
end
|
|
||||||
local name = skins[i]:sub(1, -5)
|
|
||||||
pop.skins[name] = require(tostring(path) .. "/skins/" .. tostring(name))
|
|
||||||
print("skin loaded: \"" .. tostring(name) .. "\"")
|
|
||||||
_continue_0 = true
|
|
||||||
until true
|
|
||||||
if not _continue_0 then
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
local extensions = filesystem.getDirectoryItems(tostring(path) .. "/extensions")
|
|
||||||
for i = 1, #extensions do
|
|
||||||
local _continue_0 = false
|
|
||||||
repeat
|
|
||||||
if not (extensions[i]:sub(-4) == ".lua") then
|
|
||||||
_continue_0 = true
|
|
||||||
break
|
|
||||||
end
|
|
||||||
local name = extensions[i]:sub(1, -5)
|
|
||||||
require(tostring(path) .. "/extensions/" .. tostring(name))
|
|
||||||
print("extension loaded: \"" .. tostring(name) .. "\"")
|
|
||||||
_continue_0 = true
|
|
||||||
until true
|
|
||||||
if not _continue_0 then
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
pop.screen = pop.create("element", false):setSize(graphics.getWidth(), graphics.getHeight())
|
|
||||||
return print("created \"pop.screen\"")
|
|
||||||
end
|
|
||||||
pop.create = function(element, parent, ...)
|
|
||||||
if parent == nil then
|
|
||||||
parent = pop.screen
|
|
||||||
end
|
|
||||||
if inheritsFromElement(parent) then
|
|
||||||
element = pop.elements[element](parent, ...)
|
|
||||||
insert(parent.child, element)
|
|
||||||
elseif parent == false then
|
|
||||||
element = pop.elements[element](false, ...)
|
|
||||||
else
|
|
||||||
element = pop.elements[element](pop.screen, parent, ...)
|
|
||||||
insert(pop.screen.child, element)
|
|
||||||
end
|
|
||||||
return element
|
|
||||||
end
|
|
||||||
pop.update = function(dt, element)
|
|
||||||
if element == nil then
|
|
||||||
element = pop.screen
|
|
||||||
end
|
|
||||||
if not (element.excludeUpdate) then
|
|
||||||
if element.update then
|
|
||||||
element:update(dt)
|
|
||||||
end
|
|
||||||
for i = 1, #element.child do
|
|
||||||
pop.update(dt, element.child[i])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
pop.draw = function(element)
|
|
||||||
if element == nil then
|
|
||||||
element = pop.screen
|
|
||||||
end
|
|
||||||
if not (element.excludeDraw) then
|
|
||||||
if element.draw then
|
|
||||||
element:draw()
|
|
||||||
end
|
|
||||||
for i = 1, #element.child do
|
|
||||||
pop.draw(element.child[i])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
pop.mousemoved = function(x, y, dx, dy)
|
|
||||||
if pop.focused and pop.focused.mousemoved then
|
|
||||||
return pop.focused:mousemoved(x, y, dx, dy)
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
pop.mousepressed = function(x, y, button, element)
|
|
||||||
if not (element) then
|
|
||||||
print("mousepressed", x, y, button)
|
|
||||||
element = pop.screen
|
|
||||||
end
|
|
||||||
local handled = false
|
|
||||||
if (x >= element.x) and (x <= element.x + element.w) and (y >= element.y) and (y <= element.y + element.h) then
|
|
||||||
for i = #element.child, 1, -1 do
|
|
||||||
do
|
|
||||||
handled = pop.mousepressed(x, y, button, element.child[i])
|
|
||||||
if handled then
|
|
||||||
return handled
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if not (handled) then
|
|
||||||
if element.mousepressed and (not element.excludeDraw) then
|
|
||||||
do
|
|
||||||
handled = element:mousepressed(x - element.x, y - element.y, button)
|
|
||||||
if handled then
|
|
||||||
pop.focused = element
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return handled
|
|
||||||
end
|
|
||||||
pop.mousereleased = function(x, y, button, element)
|
|
||||||
local clickedHandled = false
|
|
||||||
local mousereleasedHandled = false
|
|
||||||
if element then
|
|
||||||
if (x >= element.x) and (x <= element.x + element.w) and (y >= element.y) and (y <= element.y + element.h) then
|
|
||||||
for i = #element.child, 1, -1 do
|
|
||||||
clickedHandled, mousereleasedHandled = pop.mousereleased(x, y, button, element.child[i])
|
|
||||||
if clickedHandled or mousereleasedHandled then
|
|
||||||
return clickedHandled, mousereleasedHandled
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if not (clickedHandled or mousereleasedHandled) then
|
|
||||||
if element.clicked and (not element.excludeDraw) then
|
|
||||||
clickedHandled = element:clicked(x - element.x, y - element.y, button)
|
|
||||||
end
|
|
||||||
if element.mousereleased then
|
|
||||||
mousereleasedHandled = element:mousereleased(x - element.x, y - element.y, button)
|
|
||||||
end
|
|
||||||
if clickedHandled then
|
|
||||||
pop.focused = element
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
print("mousereleased", x, y, button)
|
|
||||||
pop.mousereleased(x, y, button, pop.screen)
|
|
||||||
end
|
|
||||||
return clickedHandled, mousereleasedHandled
|
|
||||||
end
|
|
||||||
pop.keypressed = function(key)
|
|
||||||
print("keypressed", key)
|
|
||||||
local element = pop.focused
|
|
||||||
if element and element.keypressed and (not element.excludeDraw) then
|
|
||||||
return element.keypressed(key)
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
pop.keyreleased = function(key)
|
|
||||||
print("keyreleased", key)
|
|
||||||
local element = pop.focused
|
|
||||||
if element and element.keyreleased then
|
|
||||||
return element.keyreleased(key)
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
pop.textinput = function(text)
|
|
||||||
print("textinput", text)
|
|
||||||
local element = pop.focused
|
|
||||||
if element and element.textinput and (not element.excludeDraw) then
|
|
||||||
return element.textinput(text)
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
pop.skin = function(element, skin, depth)
|
|
||||||
if element == nil then
|
|
||||||
element = pop.screen
|
|
||||||
end
|
|
||||||
if skin == nil then
|
|
||||||
skin = pop.skins.default
|
|
||||||
end
|
|
||||||
if element.background and skin.background then
|
|
||||||
element.background = skin.background
|
|
||||||
end
|
|
||||||
if element.color and skin.color then
|
|
||||||
element.color = skin.color
|
|
||||||
end
|
|
||||||
if element.font and skin.font then
|
|
||||||
element.font = skin.font
|
|
||||||
end
|
|
||||||
if not (depth or (depth == 0)) then
|
|
||||||
if depth == tonumber(depth) then
|
|
||||||
for i = 1, #element.child do
|
|
||||||
pop.skin(element.child[i], skin, depth - 1)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
for i = 1, #element.child do
|
|
||||||
pop.skin(element.child[i], skin, false)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
pop.debugDraw = function(element)
|
|
||||||
if element == nil then
|
|
||||||
element = pop.screen
|
|
||||||
end
|
|
||||||
if element.debugDraw then
|
|
||||||
element:debugDraw()
|
|
||||||
else
|
|
||||||
graphics.setLineWidth(1)
|
|
||||||
graphics.setLineColor(0, 0, 0, 100)
|
|
||||||
graphics.rectangle("fill", element.x, element.y, element.w, element.h)
|
|
||||||
graphics.setColor(150, 150, 150, 150)
|
|
||||||
graphics.rectangle("line", element.x, element.y, element.w, element.h)
|
|
||||||
graphics.setColor(200, 200, 200, 255)
|
|
||||||
graphics.print(".", element.x, element.y)
|
|
||||||
end
|
|
||||||
for i = 1, #element.child do
|
|
||||||
pop.debugDraw(element.child[i])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
pop.printElementTree = function(element, depth)
|
|
||||||
if element == nil then
|
|
||||||
element = pop.screen
|
|
||||||
end
|
|
||||||
if depth == nil then
|
|
||||||
depth = 0
|
|
||||||
end
|
|
||||||
local cls = element.__class.__name
|
|
||||||
if cls == "text" then
|
|
||||||
cls = cls .. " (\"" .. tostring(element:getText():gsub("\n", "\\n")) .. "\")"
|
|
||||||
elseif cls == "box" then
|
|
||||||
local bg = element:getBackground()
|
|
||||||
if type(bg) == "table" then
|
|
||||||
bg = tostring(bg[1]) .. ", " .. tostring(bg[2]) .. ", " .. tostring(bg[3]) .. ", " .. tostring(bg[4])
|
|
||||||
end
|
|
||||||
cls = cls .. " (" .. tostring(bg) .. ")"
|
|
||||||
end
|
|
||||||
print(string.rep("-", depth) .. " " .. tostring(cls))
|
|
||||||
for i = 1, #element.child do
|
|
||||||
pop.printElementStack(element.child[i], depth + 1)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
pop.load()
|
|
||||||
return pop
|
|
@ -1,17 +0,0 @@
|
|||||||
local graphics
|
|
||||||
graphics = love.graphics
|
|
||||||
return {
|
|
||||||
background = {
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
220
|
|
||||||
},
|
|
||||||
color = {
|
|
||||||
255,
|
|
||||||
255,
|
|
||||||
255,
|
|
||||||
250
|
|
||||||
},
|
|
||||||
font = graphics.newFont(14)
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
local inheritsFromElement
|
|
||||||
inheritsFromElement = function(object)
|
|
||||||
if object and object.__class then
|
|
||||||
local cls = object.__class
|
|
||||||
if cls.__name == "element" then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
while cls.__parent do
|
|
||||||
cls = cls.__parent
|
|
||||||
if cls.__name == "element" then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
return {
|
|
||||||
inheritsFromElement = inheritsFromElement
|
|
||||||
}
|
|
@ -1,60 +0,0 @@
|
|||||||
import graphics from love
|
|
||||||
import sub, len from string
|
|
||||||
|
|
||||||
path = sub ..., 1, len(...) - len "/box"
|
|
||||||
element = require "#{path}/element"
|
|
||||||
|
|
||||||
class box extends element
|
|
||||||
new: (parent, background=false) =>
|
|
||||||
super parent
|
|
||||||
|
|
||||||
@w = 20
|
|
||||||
@h = 20
|
|
||||||
|
|
||||||
@background = background
|
|
||||||
|
|
||||||
draw: =>
|
|
||||||
if @background
|
|
||||||
if type(@background) == "table"
|
|
||||||
graphics.setColor @background
|
|
||||||
graphics.rectangle "fill", @x, @y, @w, @h
|
|
||||||
else
|
|
||||||
w, h = @background\getDimensions!
|
|
||||||
w = @w / w
|
|
||||||
h = @h / h
|
|
||||||
graphics.setColor 255, 255, 255, 255
|
|
||||||
graphics.draw @background, @x, @y, 0, w, h
|
|
||||||
|
|
||||||
return @
|
|
||||||
|
|
||||||
debugDraw: =>
|
|
||||||
graphics.setLineWidth 0.5
|
|
||||||
graphics.setColor 0, 0, 0, 100
|
|
||||||
graphics.rectangle "fill", @x, @y, @w, @h
|
|
||||||
graphics.setColor 0, 0, 200, 200
|
|
||||||
graphics.rectangle "line", @x, @y, @w, @h
|
|
||||||
graphics.setColor 200, 200, 255, 255
|
|
||||||
graphics.print "b", @x, @y
|
|
||||||
|
|
||||||
return @
|
|
||||||
|
|
||||||
setBackground: (background) =>
|
|
||||||
@background = background
|
|
||||||
return @
|
|
||||||
|
|
||||||
getBackground: =>
|
|
||||||
return @background
|
|
||||||
|
|
||||||
setColor: (r, g, b, a=255) =>
|
|
||||||
if type(r) == "table"
|
|
||||||
@background = r
|
|
||||||
else
|
|
||||||
@background = {r, g, b, a}
|
|
||||||
|
|
||||||
return @
|
|
||||||
|
|
||||||
getColor: =>
|
|
||||||
if type(@background) == "table"
|
|
||||||
return unpack @background
|
|
||||||
else
|
|
||||||
error "Box \"#{@}\" doesn't have a color." --might be a bad idea
|
|
@ -1,287 +0,0 @@
|
|||||||
import graphics from love
|
|
||||||
import floor from math
|
|
||||||
import insert, remove from table
|
|
||||||
tonumber = tonumber
|
|
||||||
|
|
||||||
class element
|
|
||||||
new: (parent) =>
|
|
||||||
@parent = parent
|
|
||||||
@child = {}
|
|
||||||
|
|
||||||
@w = 0
|
|
||||||
@h = 0
|
|
||||||
|
|
||||||
@spacing = 0
|
|
||||||
|
|
||||||
if parent
|
|
||||||
@x = parent.x
|
|
||||||
@y = parent.y
|
|
||||||
--@horizontal = parent.horizontal
|
|
||||||
--@vertical = parent.vertical
|
|
||||||
--@align!
|
|
||||||
else
|
|
||||||
@x = 0
|
|
||||||
@y = 0
|
|
||||||
--@horizontal = "left"
|
|
||||||
--@vertical = "top"
|
|
||||||
|
|
||||||
@horizontal = "left"
|
|
||||||
@vertical = "top"
|
|
||||||
|
|
||||||
@excludeDraw = false
|
|
||||||
@excludeUpdate = false
|
|
||||||
@excludeMovement = false
|
|
||||||
|
|
||||||
debugDraw: =>
|
|
||||||
graphics.setLineWidth 0.5
|
|
||||||
graphics.setColor 0, 0, 0, 100
|
|
||||||
graphics.rectangle "fill", @x, @y, @w, @h
|
|
||||||
graphics.setColor 0, 200, 0, 200
|
|
||||||
graphics.rectangle "line", @x, @y, @w, @h
|
|
||||||
graphics.setColor 200, 255, 200, 255
|
|
||||||
graphics.print "e", @x, @y
|
|
||||||
|
|
||||||
return @
|
|
||||||
|
|
||||||
addChild: (child) =>
|
|
||||||
-- make sure we don't duplicate references
|
|
||||||
if child.parent
|
|
||||||
child.parent\removeChild child
|
|
||||||
|
|
||||||
insert @child, child
|
|
||||||
child.parent = @
|
|
||||||
|
|
||||||
child\align! --NOTE not 100% sure if this is a good idea
|
|
||||||
|
|
||||||
return @
|
|
||||||
|
|
||||||
-- remove child by index OR by reference and return it
|
|
||||||
--NOTE API CHANGE HERE MIGHT'VE FUCKED A THING
|
|
||||||
removeChild: (child) =>
|
|
||||||
if tonumber(child) == child
|
|
||||||
-- remove indexed child, return it
|
|
||||||
@child[child].parent = false
|
|
||||||
return remove @child, child
|
|
||||||
else
|
|
||||||
for k,v in ipairs @child
|
|
||||||
if v == child
|
|
||||||
return remove @child, k
|
|
||||||
return "Element \"#{child}\" is not a child of element \"#{@}\". Cannot remove it."
|
|
||||||
|
|
||||||
getChildren: =>
|
|
||||||
return @child
|
|
||||||
|
|
||||||
--focusChild: (child) =>
|
|
||||||
-- insert @child, 1, @removeChild(child)
|
|
||||||
-- return @
|
|
||||||
|
|
||||||
move: (x, y) =>
|
|
||||||
if x
|
|
||||||
@x = @x + x
|
|
||||||
if y
|
|
||||||
@y = @y + y
|
|
||||||
|
|
||||||
for i = 1, #@child
|
|
||||||
unless @child[i].excludeMovement
|
|
||||||
@child[i]\move x, y
|
|
||||||
|
|
||||||
return @
|
|
||||||
|
|
||||||
setPosition: (x, y) =>
|
|
||||||
oldX = @x
|
|
||||||
oldY = @y
|
|
||||||
|
|
||||||
if x
|
|
||||||
switch @horizontal
|
|
||||||
when "left"
|
|
||||||
@x = x
|
|
||||||
when "center"
|
|
||||||
@x = x - @w/2
|
|
||||||
when "right"
|
|
||||||
@x = x - @w
|
|
||||||
else
|
|
||||||
x = oldX
|
|
||||||
|
|
||||||
if y
|
|
||||||
switch @vertical
|
|
||||||
when "top"
|
|
||||||
@y = y
|
|
||||||
when "center"
|
|
||||||
@y = y - @h/2
|
|
||||||
when "bottom"
|
|
||||||
@y = y - @h
|
|
||||||
else
|
|
||||||
y = oldY
|
|
||||||
|
|
||||||
for i = 1, #@child
|
|
||||||
@child[i]\move x - oldX, y - oldY
|
|
||||||
|
|
||||||
return @
|
|
||||||
|
|
||||||
getPosition: =>
|
|
||||||
resultX = @x
|
|
||||||
resultY = @y
|
|
||||||
|
|
||||||
switch @horizontal
|
|
||||||
when "center"
|
|
||||||
resultX += @w/2
|
|
||||||
when "right"
|
|
||||||
resultY += @w
|
|
||||||
|
|
||||||
switch @vertical
|
|
||||||
when "center"
|
|
||||||
resultY += @h/2
|
|
||||||
when "bottom"
|
|
||||||
resultY += @h
|
|
||||||
|
|
||||||
return resultX, resultY
|
|
||||||
|
|
||||||
setSize: (w, h) =>
|
|
||||||
if w
|
|
||||||
switch @horizontal
|
|
||||||
when "center"
|
|
||||||
@x -= (w - @w)/2
|
|
||||||
when "right"
|
|
||||||
@x -= w - @w
|
|
||||||
|
|
||||||
@w = w
|
|
||||||
|
|
||||||
if h
|
|
||||||
switch @vertical
|
|
||||||
when "center"
|
|
||||||
@y -= (h - @h)/2
|
|
||||||
when "bottom"
|
|
||||||
@y -= h - @h
|
|
||||||
|
|
||||||
@h = h
|
|
||||||
|
|
||||||
return @
|
|
||||||
|
|
||||||
getSize: =>
|
|
||||||
return @w, @h
|
|
||||||
|
|
||||||
setWidth: (w) =>
|
|
||||||
switch @horizontal
|
|
||||||
when "center"
|
|
||||||
@x -= (w - @w)/2
|
|
||||||
when "right"
|
|
||||||
@x -= w - @w
|
|
||||||
|
|
||||||
@w = w
|
|
||||||
|
|
||||||
return @
|
|
||||||
|
|
||||||
getWidth: =>
|
|
||||||
return @w
|
|
||||||
|
|
||||||
setHeight: (h) =>
|
|
||||||
switch @vertical
|
|
||||||
when "center"
|
|
||||||
@y -= (h - @h)/2
|
|
||||||
when "bottom"
|
|
||||||
@y -= h - @h
|
|
||||||
|
|
||||||
@h = h
|
|
||||||
|
|
||||||
return @
|
|
||||||
|
|
||||||
getHeight: =>
|
|
||||||
return @h
|
|
||||||
|
|
||||||
adjustSize: (w, h) =>
|
|
||||||
W, H = @getSize!
|
|
||||||
|
|
||||||
if w
|
|
||||||
W += w
|
|
||||||
if h
|
|
||||||
H += h
|
|
||||||
|
|
||||||
@setSize W, H
|
|
||||||
|
|
||||||
return @
|
|
||||||
|
|
||||||
--TODO note that align requires a parent!
|
|
||||||
align: (horizontal, vertical, toPixel=true) =>
|
|
||||||
@setAlignment horizontal, vertical
|
|
||||||
|
|
||||||
@x = @parent.x
|
|
||||||
@y = @parent.y
|
|
||||||
|
|
||||||
switch @horizontal
|
|
||||||
when "left"
|
|
||||||
@x += @spacing
|
|
||||||
when "center"
|
|
||||||
@x += (@parent.w - @w)/2
|
|
||||||
when "right"
|
|
||||||
@x += @parent.w - @w - @spacing
|
|
||||||
|
|
||||||
switch @vertical
|
|
||||||
when "top"
|
|
||||||
@y += @spacing
|
|
||||||
when "center"
|
|
||||||
@y += (@parent.h - @h)/2
|
|
||||||
when "bottom"
|
|
||||||
@y += @parent.h - @h - @spacing
|
|
||||||
|
|
||||||
if toPixel
|
|
||||||
@x = floor @x
|
|
||||||
@y = floor @y
|
|
||||||
|
|
||||||
return @
|
|
||||||
|
|
||||||
alignTo: (element, horizontal, vertical, toPixel=true) =>
|
|
||||||
parent = @parent
|
|
||||||
@parent = element
|
|
||||||
|
|
||||||
@align horizontal, vertical, toPixel
|
|
||||||
|
|
||||||
@parent = parent
|
|
||||||
|
|
||||||
return @
|
|
||||||
|
|
||||||
setAlignment: (horizontal, vertical) =>
|
|
||||||
if horizontal
|
|
||||||
@horizontal = horizontal
|
|
||||||
if vertical
|
|
||||||
@vertical = vertical
|
|
||||||
|
|
||||||
return @
|
|
||||||
|
|
||||||
getAlignment: =>
|
|
||||||
return @horizontal, @vertical
|
|
||||||
|
|
||||||
setMargin: (spacing) =>
|
|
||||||
@spacing = spacing
|
|
||||||
@align!
|
|
||||||
return @
|
|
||||||
|
|
||||||
getMargin: =>
|
|
||||||
return @spacing
|
|
||||||
|
|
||||||
fill: =>
|
|
||||||
@x = @parent.x + @spacing
|
|
||||||
@y = @parent.y + @spacing
|
|
||||||
@w = @parent.w - @spacing*2
|
|
||||||
@h = @parent.h - @spacing*2
|
|
||||||
|
|
||||||
delete: =>
|
|
||||||
for k,v in ipairs @child
|
|
||||||
v\delete!
|
|
||||||
|
|
||||||
@parent\removeChild @
|
|
||||||
@ = nil
|
|
||||||
return nil
|
|
||||||
|
|
||||||
getVisibility: =>
|
|
||||||
return (not @excludeDraw)
|
|
||||||
|
|
||||||
setVisibility: (isVisible) =>
|
|
||||||
@excludeDraw = (not isVisible)
|
|
||||||
return @
|
|
||||||
|
|
||||||
getStatic: =>
|
|
||||||
return @excludeMovement
|
|
||||||
|
|
||||||
setStatic: (isStatic) =>
|
|
||||||
@excludeMovement = isStatic
|
|
||||||
return @
|
|
Binary file not shown.
Before Width: | Height: | Size: 303 B |
@ -1,98 +0,0 @@
|
|||||||
import graphics from love
|
|
||||||
import sub, len from string
|
|
||||||
|
|
||||||
path = sub ..., 1, len(...) - len "/box"
|
|
||||||
element = require "#{path}/element"
|
|
||||||
|
|
||||||
class text extends element
|
|
||||||
-- this should be completely unneccessary, but I'm keeping it just in case (and moreso to remember how to do this)
|
|
||||||
@wrap = (pop) ->
|
|
||||||
return (parent, ...) ->
|
|
||||||
if type(parent) == "string"
|
|
||||||
return pop.create("text", nil, parent, ...)
|
|
||||||
else
|
|
||||||
return pop.create("text", parent, ...)
|
|
||||||
|
|
||||||
new: (parent, text="", color={255,255,255,255}) =>
|
|
||||||
super parent
|
|
||||||
|
|
||||||
@font = graphics.newFont 14
|
|
||||||
@setText text
|
|
||||||
@color = color
|
|
||||||
|
|
||||||
draw: =>
|
|
||||||
graphics.setColor @color
|
|
||||||
graphics.setFont @font
|
|
||||||
graphics.print @txt, @x, @y
|
|
||||||
|
|
||||||
return @
|
|
||||||
|
|
||||||
debugDraw: =>
|
|
||||||
graphics.setLineWidth 0.5
|
|
||||||
graphics.setColor 0, 0, 0, 100
|
|
||||||
graphics.rectangle "fill", @x, @y, @w, @h
|
|
||||||
graphics.setColor 200, 0, 0, 200
|
|
||||||
graphics.rectangle "line", @x, @y, @w, @h
|
|
||||||
graphics.setColor 255, 200, 200, 255
|
|
||||||
graphics.print "t", @x, @y
|
|
||||||
|
|
||||||
return @
|
|
||||||
|
|
||||||
-- unlike most elements, you cannot set a size for text elements
|
|
||||||
setSize: =>
|
|
||||||
w = @font\getWidth @txt
|
|
||||||
h = @font\getHeight! * (select(2, @txt\gsub("\n", "\n")) + 1) --hack to get height of multiple lines
|
|
||||||
|
|
||||||
switch @horizontal
|
|
||||||
when "center"
|
|
||||||
@x -= (w - @w)/2
|
|
||||||
when "right"
|
|
||||||
@x -= w - @w - @spacing
|
|
||||||
|
|
||||||
switch @vertical
|
|
||||||
when "center"
|
|
||||||
@y -= (h - @h)/2
|
|
||||||
when "bottom"
|
|
||||||
@y -= h - @h - @spacing
|
|
||||||
|
|
||||||
@w = w
|
|
||||||
@h = h
|
|
||||||
|
|
||||||
return @
|
|
||||||
|
|
||||||
-- cannot set width!
|
|
||||||
setWidth: =>
|
|
||||||
@setSize!
|
|
||||||
return @
|
|
||||||
|
|
||||||
-- cannot set height!
|
|
||||||
setHeight: =>
|
|
||||||
@setSize!
|
|
||||||
return @
|
|
||||||
|
|
||||||
setText: (text="") =>
|
|
||||||
@txt = text
|
|
||||||
@setSize!
|
|
||||||
return @
|
|
||||||
|
|
||||||
getText: =>
|
|
||||||
return @txt
|
|
||||||
|
|
||||||
setFont: (font) =>
|
|
||||||
@font = font
|
|
||||||
@setSize!
|
|
||||||
return @
|
|
||||||
|
|
||||||
getFont: =>
|
|
||||||
return @font
|
|
||||||
|
|
||||||
setColor: (r, g, b, a=255) =>
|
|
||||||
if type(r) == "table"
|
|
||||||
@color = r
|
|
||||||
else
|
|
||||||
@color = {r, g, b, a}
|
|
||||||
|
|
||||||
return @
|
|
||||||
|
|
||||||
getColor: =>
|
|
||||||
return unpack @color
|
|
@ -1,307 +0,0 @@
|
|||||||
import graphics, mouse from love
|
|
||||||
import insert, remove from table
|
|
||||||
import sub, len from string
|
|
||||||
|
|
||||||
path = sub ..., 1, len(...) - len "/window"
|
|
||||||
element = require "#{path}/element"
|
|
||||||
box = require "#{path}/box"
|
|
||||||
text = require "#{path}/text"
|
|
||||||
|
|
||||||
closeImage = graphics.newImage "#{path}/img/close.png"
|
|
||||||
|
|
||||||
-- version compatibility
|
|
||||||
left = 1 -- what is the left mouse button?
|
|
||||||
mousemoved_event = true -- is the mousemoved event available?
|
|
||||||
|
|
||||||
do
|
|
||||||
major, minor, revision = love.getVersion!
|
|
||||||
if (major == 0) and (minor == 10) and ((revision == 0) or (revision == 1))
|
|
||||||
left = 1 -- redundant, but whatever
|
|
||||||
elseif (major == 0) and (minor == 9)
|
|
||||||
left = "l"
|
|
||||||
if revision == 1
|
|
||||||
mousemoved_event = false
|
|
||||||
else
|
|
||||||
print "elements/window: unrecognized LOVE version: #{major}.#{minor}.#{revision}"
|
|
||||||
print " assuming LOVE version > 0.10.1 (there may be bugs)"
|
|
||||||
|
|
||||||
pop_ref = false -- reference to pop, loaded by pop.load!
|
|
||||||
|
|
||||||
class window extends element
|
|
||||||
load: (pop) ->
|
|
||||||
pop_ref = pop
|
|
||||||
|
|
||||||
new: (parent, title="window", tBackground={25, 180, 230, 255}, tColor={255, 255, 255, 255}, wBackground={200, 200, 210, 255}) =>
|
|
||||||
super parent
|
|
||||||
|
|
||||||
-- NOTE @title having @head as its parent might break things horribly
|
|
||||||
@head = box @, tBackground -- title box at top
|
|
||||||
@title = text @head, title, tColor -- text at top
|
|
||||||
@area = box @, wBackground -- main window area
|
|
||||||
@close = box @, closeImage -- close button
|
|
||||||
|
|
||||||
-- correct placement / sizes of elements
|
|
||||||
height = @title\getHeight!
|
|
||||||
@head\setSize @w - height, height
|
|
||||||
@area\move nil, height
|
|
||||||
@close\align("right")\setSize height, height
|
|
||||||
@setSize 100, 80
|
|
||||||
|
|
||||||
-- our child elements are still child elements
|
|
||||||
--TODO change title to be a child of head ?
|
|
||||||
@child = {
|
|
||||||
@head, @title, @area, @close
|
|
||||||
}
|
|
||||||
|
|
||||||
@titleOverflow = "trunicate" -- defaults to trunicating title to fit in window
|
|
||||||
|
|
||||||
-- window area steals mouse events to keep them from propagating under it
|
|
||||||
@area.mousepressed = ->
|
|
||||||
return true
|
|
||||||
@area.clicked = ->
|
|
||||||
return true
|
|
||||||
|
|
||||||
@close.clicked = ->
|
|
||||||
@delete!
|
|
||||||
return true
|
|
||||||
|
|
||||||
@head.selected = false -- whether or not the window title (and thus, the window) has been selected
|
|
||||||
|
|
||||||
if mousemoved_event
|
|
||||||
@head.mousemoved = (x, y, dx, dy) =>
|
|
||||||
if @selected
|
|
||||||
@parent\move dx, dy
|
|
||||||
return true
|
|
||||||
return false
|
|
||||||
|
|
||||||
@head.mousepressed = (x, y, button) =>
|
|
||||||
if button == left
|
|
||||||
@selected = true
|
|
||||||
return true
|
|
||||||
return false
|
|
||||||
|
|
||||||
else
|
|
||||||
@head.mx = 0 -- local mouse coordinates when selected
|
|
||||||
@head.my = 0
|
|
||||||
|
|
||||||
@head.update = =>
|
|
||||||
x, y = mouse.getPosition!
|
|
||||||
@setPosition x - mx, y - my
|
|
||||||
--return false -- why?
|
|
||||||
|
|
||||||
@head.mousepressed = (x, y, button) =>
|
|
||||||
if button == left
|
|
||||||
@selected = true
|
|
||||||
@mx = x
|
|
||||||
@my = y
|
|
||||||
return true
|
|
||||||
return false
|
|
||||||
|
|
||||||
@head.mousereleased = (x, y, button) =>
|
|
||||||
if button == left
|
|
||||||
@selected = false
|
|
||||||
pop_ref.focused = false -- clear our focus
|
|
||||||
return true
|
|
||||||
return false
|
|
||||||
|
|
||||||
--@head.focusChild = =>
|
|
||||||
-- @parent\focusChild @ -- nope
|
|
||||||
-- return @
|
|
||||||
|
|
||||||
debugDraw: =>
|
|
||||||
graphics.setLineWidth 0.5
|
|
||||||
graphics.setColor 0, 0, 0, 100
|
|
||||||
graphics.rectangle "fill", @x, @y, @w, @h
|
|
||||||
graphics.setColor 200, 0, 200, 200
|
|
||||||
graphics.rectangle "line", @x, @y, @w, @h
|
|
||||||
graphics.setColor 255, 200, 255, 255
|
|
||||||
graphics.print "w", @x, @y
|
|
||||||
|
|
||||||
return @
|
|
||||||
|
|
||||||
addChild: (child) =>
|
|
||||||
@area\addChild child
|
|
||||||
|
|
||||||
return @
|
|
||||||
|
|
||||||
-- pass through to window, but return us if window returns itself
|
|
||||||
removeChild: (child) =>
|
|
||||||
result = @area\removeChild child
|
|
||||||
if result == @area
|
|
||||||
return @
|
|
||||||
elseif type(result) == "string"
|
|
||||||
for k,v in ipairs @child
|
|
||||||
if v == child
|
|
||||||
remove @child, k
|
|
||||||
return @
|
|
||||||
return "Element \"#{child}\" is not a child of window \"#{@}\". Cannot remove it."
|
|
||||||
else
|
|
||||||
return result
|
|
||||||
|
|
||||||
getChildren: =>
|
|
||||||
return @area.child
|
|
||||||
|
|
||||||
--focusChild: =>
|
|
||||||
-- @parent\focusChild @
|
|
||||||
-- --NOTE might need to also actually focus the sub-element
|
|
||||||
-- return @
|
|
||||||
|
|
||||||
align: (horizontal, vertical, toPixel) =>
|
|
||||||
super horizontal, vertical, toPixel
|
|
||||||
|
|
||||||
for i = 1, #@child
|
|
||||||
@child[i]\align!
|
|
||||||
|
|
||||||
@area\move nil, @head\getHeight!
|
|
||||||
|
|
||||||
return @
|
|
||||||
|
|
||||||
setSize: (w, h) =>
|
|
||||||
x = 0
|
|
||||||
y = 0
|
|
||||||
|
|
||||||
if w
|
|
||||||
switch @horizontal
|
|
||||||
when "center"
|
|
||||||
x -= (w - @w)/2
|
|
||||||
when "right"
|
|
||||||
x -= w - @w
|
|
||||||
|
|
||||||
if @close
|
|
||||||
@head\setWidth w - @head\getHeight!
|
|
||||||
else
|
|
||||||
@head\setWidth w
|
|
||||||
|
|
||||||
@area\setWidth w
|
|
||||||
@w = w
|
|
||||||
@x += x
|
|
||||||
|
|
||||||
@title\align!
|
|
||||||
|
|
||||||
if @close
|
|
||||||
@close\align!
|
|
||||||
|
|
||||||
if h
|
|
||||||
h = h - @head\getHeight!
|
|
||||||
switch @vertical
|
|
||||||
when "center"
|
|
||||||
y -= (h - @h)/2
|
|
||||||
when "right"
|
|
||||||
y -= h - @h
|
|
||||||
|
|
||||||
@area\setHeight h
|
|
||||||
@h = h + @head\getHeight!
|
|
||||||
@y += y
|
|
||||||
|
|
||||||
@head\move x, y
|
|
||||||
--@title\move x, y
|
|
||||||
@area\move x, y
|
|
||||||
|
|
||||||
return @
|
|
||||||
|
|
||||||
setWidth: (w) =>
|
|
||||||
x = 0
|
|
||||||
|
|
||||||
switch @horizontal
|
|
||||||
when "center"
|
|
||||||
x -= (w - @w)/2
|
|
||||||
when "right"
|
|
||||||
x -= w - @w
|
|
||||||
|
|
||||||
if @close
|
|
||||||
@head\setWidth w - @head\getHeight!
|
|
||||||
else
|
|
||||||
@head\setWidth w
|
|
||||||
|
|
||||||
@area\setWidth w
|
|
||||||
@w = w
|
|
||||||
@x += x
|
|
||||||
|
|
||||||
@title\align!
|
|
||||||
|
|
||||||
if @close
|
|
||||||
@close\align!
|
|
||||||
|
|
||||||
@head\move x
|
|
||||||
--@title\move x
|
|
||||||
@area\move x
|
|
||||||
|
|
||||||
return @
|
|
||||||
|
|
||||||
setHeight: (h) =>
|
|
||||||
y = 0
|
|
||||||
|
|
||||||
h = h - @head\getHeight!
|
|
||||||
switch @vertical
|
|
||||||
when "center"
|
|
||||||
y -= (h - @h)/2
|
|
||||||
when "right"
|
|
||||||
y -= h - @h
|
|
||||||
|
|
||||||
@area\setHeight h
|
|
||||||
@h = h + @head\getHeight!
|
|
||||||
@y += y
|
|
||||||
|
|
||||||
@head\move nil, y
|
|
||||||
@title\move nil, y
|
|
||||||
@area\move nil, y
|
|
||||||
|
|
||||||
return @
|
|
||||||
|
|
||||||
setTitle: (title) =>
|
|
||||||
@title\setText title
|
|
||||||
|
|
||||||
if @titleOverflow == "trunicate"
|
|
||||||
while @title\getWidth! > @head\getWidth!
|
|
||||||
title = title\sub 1, -3
|
|
||||||
@title\setText title .. "…"
|
|
||||||
|
|
||||||
elseif @titleOverflow == "resize"
|
|
||||||
if @title\getWidth! > @head\getWidth!
|
|
||||||
@setWidth @title\getWidth!
|
|
||||||
|
|
||||||
return @
|
|
||||||
|
|
||||||
getTitle: =>
|
|
||||||
return @title\getText!
|
|
||||||
|
|
||||||
setTitleOverflow: (method) =>
|
|
||||||
@titleOverflow = method
|
|
||||||
|
|
||||||
return @
|
|
||||||
|
|
||||||
getTitleOverflow: =>
|
|
||||||
return @titleOverflow
|
|
||||||
|
|
||||||
setClose: (enabled) =>
|
|
||||||
if enabled
|
|
||||||
@close = box @, closeImage
|
|
||||||
@close.clicked = ->
|
|
||||||
@delete!
|
|
||||||
return true
|
|
||||||
height = @head\getHeight!
|
|
||||||
@close\align("right")\setSize height, height
|
|
||||||
@head\setWidth @w - height
|
|
||||||
@title\align!
|
|
||||||
insert @child, @close
|
|
||||||
else
|
|
||||||
@close\delete!
|
|
||||||
@head\setWidth @w
|
|
||||||
@title\align!
|
|
||||||
@close = false
|
|
||||||
|
|
||||||
return @
|
|
||||||
|
|
||||||
hasClose: =>
|
|
||||||
if @close
|
|
||||||
return true
|
|
||||||
else
|
|
||||||
return false
|
|
||||||
|
|
||||||
delete: =>
|
|
||||||
super!
|
|
||||||
@head = nil
|
|
||||||
@title = nil
|
|
||||||
@area = nil
|
|
||||||
@close = nil
|
|
||||||
return
|
|
@ -1,92 +0,0 @@
|
|||||||
-- adds methods to elements using a single function for get and set operations
|
|
||||||
-- ex: instead of getWidth() and setWidth(val), use width() and width(val)
|
|
||||||
|
|
||||||
import graphics from love
|
|
||||||
import sub, len from string
|
|
||||||
|
|
||||||
path = sub ..., 1, len(...) - len "/extensions/streamlined_get_set"
|
|
||||||
element = require "#{path}/elements/element"
|
|
||||||
box = require "#{path}/elements/box"
|
|
||||||
text = require "#{path}/elements/text"
|
|
||||||
|
|
||||||
element.__base.position = (x, y) =>
|
|
||||||
if x or y
|
|
||||||
return @setPosition x, y
|
|
||||||
else
|
|
||||||
return @getPosition!
|
|
||||||
|
|
||||||
element.__base.size = (w, h) =>
|
|
||||||
if w or h
|
|
||||||
return @setSize w, h
|
|
||||||
else
|
|
||||||
return @getSize!
|
|
||||||
|
|
||||||
element.__base.width = (w) =>
|
|
||||||
if w
|
|
||||||
return @setWidth w
|
|
||||||
else
|
|
||||||
return @getWidth!
|
|
||||||
|
|
||||||
element.__base.height = (h) =>
|
|
||||||
if h
|
|
||||||
return @setHeight h
|
|
||||||
else
|
|
||||||
return @getHeight!
|
|
||||||
|
|
||||||
element.__base.alignment = (horizontal, vertical) =>
|
|
||||||
if horizontal or vertical
|
|
||||||
return @setAlignment horizontal, vertical
|
|
||||||
else
|
|
||||||
return @getAlignment!
|
|
||||||
|
|
||||||
element.__base.margin = (m) =>
|
|
||||||
if m
|
|
||||||
return @setMargin m
|
|
||||||
else
|
|
||||||
return @getMargin!
|
|
||||||
|
|
||||||
element.__base.resize = element.__base.adjustSize
|
|
||||||
|
|
||||||
element.__base.visibility = (v) =>
|
|
||||||
if v != nil
|
|
||||||
return @setVisibility v
|
|
||||||
else
|
|
||||||
return @getVisibility!
|
|
||||||
|
|
||||||
element.__base.show = =>
|
|
||||||
return @setVisibility true
|
|
||||||
|
|
||||||
element.__base.hide = =>
|
|
||||||
return @setVisibility false
|
|
||||||
|
|
||||||
element.__base.static = (s) =>
|
|
||||||
if s != nil
|
|
||||||
return @setStatic s
|
|
||||||
else
|
|
||||||
return @getStatic!
|
|
||||||
|
|
||||||
-- box.__base.background -- can't be done!
|
|
||||||
|
|
||||||
box.__base.color = (r, g, b, a) =>
|
|
||||||
if r or g or b or a
|
|
||||||
return @setColor r, g, b, a
|
|
||||||
else
|
|
||||||
return @getColor!
|
|
||||||
|
|
||||||
text.__base.text = (text) =>
|
|
||||||
if text
|
|
||||||
return @setText text
|
|
||||||
else
|
|
||||||
return @getText!
|
|
||||||
|
|
||||||
text.__base.font = (font) =>
|
|
||||||
if font
|
|
||||||
return @setFont font
|
|
||||||
else
|
|
||||||
return @getFont!
|
|
||||||
|
|
||||||
text.__base.color = (r, g, b, a) =>
|
|
||||||
if r or g or b or a
|
|
||||||
return @setColor r, g, b, a
|
|
||||||
else
|
|
||||||
return @getColor!
|
|
@ -1,10 +0,0 @@
|
|||||||
-- Note that the "default" name is a bit of a misnomer, as this does not
|
|
||||||
-- specify the defaults used in Pop.Box elements (they define their own)
|
|
||||||
|
|
||||||
import graphics from love
|
|
||||||
|
|
||||||
return {
|
|
||||||
background: {0, 0, 0, 220}
|
|
||||||
color: {255, 255, 255, 250}
|
|
||||||
font: graphics.newFont 14
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
inheritsFromElement = (object) ->
|
|
||||||
if object and object.__class
|
|
||||||
cls = object.__class
|
|
||||||
|
|
||||||
if cls.__name == "element"
|
|
||||||
return true
|
|
||||||
|
|
||||||
while cls.__parent
|
|
||||||
cls = cls.__parent
|
|
||||||
if cls.__name == "element"
|
|
||||||
return true
|
|
||||||
|
|
||||||
return false
|
|
||||||
|
|
||||||
return {
|
|
||||||
:inheritsFromElement
|
|
||||||
}
|
|
27
util.moon
Normal file
27
util.moon
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
--- Utility functions, intended for internal use only.
|
||||||
|
--- @module util
|
||||||
|
--- @copyright Paul Liverman III (2015-2016)
|
||||||
|
--- @license The MIT License (MIT)
|
||||||
|
--- @release v0.0.0
|
||||||
|
|
||||||
|
--- @function inheritsFromElement
|
||||||
|
--- @param object A table (MoonScript object expected) to be checked for inheritence from the "element" element.
|
||||||
|
--- @return `true` / `false`: Is the table an object inherting from "element"?
|
||||||
|
--- @raise Can error if the table has a similar structure to a MoonScript object without being the same structure.
|
||||||
|
inheritsFromElement = (object) ->
|
||||||
|
if object and object.__class
|
||||||
|
cls = object.__class
|
||||||
|
|
||||||
|
if cls.__name == "element"
|
||||||
|
return true
|
||||||
|
|
||||||
|
while cls.__parent
|
||||||
|
cls = cls.__parent
|
||||||
|
if cls.__name == "element"
|
||||||
|
return true
|
||||||
|
|
||||||
|
return false
|
||||||
|
|
||||||
|
return {
|
||||||
|
:inheritsFromElement
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user