mirror of
https://github.com/TangentFoxy/Pop.Box.git
synced 2024-12-15 12:44:20 +00:00
another fix attempt, failed
This commit is contained in:
parent
79130fe3d6
commit
a5e3714af8
@ -1,4 +1,4 @@
|
|||||||
local pop = require("pop")()
|
local pop = require "pop"
|
||||||
|
|
||||||
local lg = love.graphics
|
local lg = love.graphics
|
||||||
|
|
||||||
@ -7,35 +7,35 @@ local testsRun = false
|
|||||||
local debugDrawEnabled = false
|
local debugDrawEnabled = false
|
||||||
|
|
||||||
function love.load()
|
function love.load()
|
||||||
pop:text(nil, "Press \"s\" to show objects for visual testing/demo.\nPress \"t\" to run tests.\nPress \"d\" to toggle debug draw."):move(2, 2)
|
pop.text(nil, "Press \"s\" to show objects for visual testing/demo.\nPress \"t\" to run tests.\nPress \"d\" to toggle debug draw."):move(2, 2)
|
||||||
--TODO correct the fact that the size is wrong here! (height doesn't take into account \n)
|
--TODO correct the fact that the size is wrong here! (height doesn't take into account \n)
|
||||||
--NOTE width? Is width calculated correctly when \n's exist? TEST THIS (also test tabs)
|
--NOTE width? Is width calculated correctly when \n's exist? TEST THIS (also test tabs)
|
||||||
pop:text(nil, "This is a test\ncollection of strings to see how width is determined.\nLooks like it takes width of widest line!"):move(30, 120)
|
pop.text(nil, "This is a test\ncollection of strings to see how width is determined.\nLooks like it takes width of widest line!"):move(30, 120)
|
||||||
pop:element():align("right", "bottom"):setSize(25, 25):move(-5, -5)
|
pop.element():align("right", "bottom"):setSize(25, 25):move(-5, -5)
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.update(dt)
|
function love.update(dt)
|
||||||
pop:update(dt)
|
pop.update(dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.draw()
|
function love.draw()
|
||||||
pop:draw()
|
pop.draw()
|
||||||
|
|
||||||
if debugDrawEnabled then
|
if debugDrawEnabled then
|
||||||
pop:debugDraw()
|
pop.debugDraw()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.textinput(text)
|
function love.textinput(text)
|
||||||
--pop:textinput(text)
|
pop.textinput(text)
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.mousepressed(button, x, y)
|
function love.mousepressed(button, x, y)
|
||||||
--pop:mousepressed(button, x, y)
|
pop.mousepressed(button, x, y)
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.mousereleased(button, x, y)
|
function love.mousereleased(button, x, y)
|
||||||
--pop:mousereleased(button, x, y)
|
pop.mousereleased(button, x, y)
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.keypressed(key)
|
function love.keypressed(key)
|
||||||
@ -44,19 +44,19 @@ function love.keypressed(key)
|
|||||||
else
|
else
|
||||||
if (key == "s") and (not visualTestsShown) then
|
if (key == "s") and (not visualTestsShown) then
|
||||||
-- old visual tests
|
-- old visual tests
|
||||||
local align = pop:box():align("center", "center"):setSize(200, 200)
|
local align = pop.box():align("center", "center"):setSize(200, 200)
|
||||||
pop:box(align):align("left", "top"):setSize(75, 10):setColor(255, 0, 255, 255)
|
pop.box(align):align("left", "top"):setSize(75, 10):setColor(255, 0, 255, 255)
|
||||||
pop:box(align):align("center", "top"):setColor(100, 100, 100)
|
pop.box(align):align("center", "top"):setColor(100, 100, 100)
|
||||||
pop:box(align, {0, 255, 0, 255}):setSize(20, 5):align("right", "top")
|
pop.box(align, {0, 255, 0, 255}):setSize(20, 5):align("right", "top")
|
||||||
pop:box(align):align("left", "center"):setColor(0, 0, 255)
|
pop.box(align):align("left", "center"):setColor(0, 0, 255)
|
||||||
pop:box(align):align("center", "center"):setSize(90, 90):setColor(255, 255, 255)
|
pop.box(align):align("center", "center"):setSize(90, 90):setColor(255, 255, 255)
|
||||||
pop:box(align):align("right", "center"):setColor(255, 0, 0)
|
pop.box(align):align("right", "center"):setColor(255, 0, 0)
|
||||||
pop:box(align):align("left", "bottom"):setColor(0, 255, 0):setSize(nil, 40)
|
pop.box(align):align("left", "bottom"):setColor(0, 255, 0):setSize(nil, 40)
|
||||||
pop:box(align):align("center", "bottom"):setColor(255, 255, 0)
|
pop.box(align):align("center", "bottom"):setColor(255, 255, 0)
|
||||||
pop:box(align):align("right", "bottom"):setColor(0, 255, 255):setSize(40, 40)
|
pop.box(align):align("right", "bottom"):setColor(0, 255, 255):setSize(40, 40)
|
||||||
--pop:box(nil, {255, 0, 0, 255}):align("left", "top"):setSize(50, 50) --TODO adjust z-height of elements
|
--pop.box(nil, {255, 0, 0, 255}):align("left", "top"):setSize(50, 50) --TODO adjust z-height of elements
|
||||||
pop:text(nil, "Hello World!"):align("center"):setText("Hey, I've been modified!")--:move(0, 18)
|
pop.text(nil, "Hello World!"):align("center"):setText("Hey, I've been modified!")--:move(0, 18)
|
||||||
pop:text(nil, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*()-=_+[]{}\\|:;\"',./<>?`~"):align("center", "bottom")
|
pop.text(nil, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*()-=_+[]{}\\|:;\"',./<>?`~"):align("center", "bottom")
|
||||||
|
|
||||||
visualTestsShown = true
|
visualTestsShown = true
|
||||||
elseif (key == "t") and (not testsRun) then
|
elseif (key == "t") and (not testsRun) then
|
||||||
@ -65,10 +65,10 @@ function love.keypressed(key)
|
|||||||
debugDrawEnabled = not debugDrawEnabled
|
debugDrawEnabled = not debugDrawEnabled
|
||||||
end
|
end
|
||||||
|
|
||||||
--pop:keypressed(key)
|
pop.keypressed(key)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.keyreleased(key)
|
function love.keyreleased(key)
|
||||||
--pop:keyreleased(key)
|
pop.keyreleased(key)
|
||||||
end
|
end
|
||||||
|
@ -6,59 +6,76 @@ end
|
|||||||
local insert
|
local insert
|
||||||
insert = table.insert
|
insert = table.insert
|
||||||
local path = ...
|
local path = ...
|
||||||
local Pop
|
local pop = { }
|
||||||
do
|
pop.elements = { }
|
||||||
local _class_0
|
pop.window = {
|
||||||
local _base_0 = {
|
child = { }
|
||||||
create = function(self, elementType, parent, ...)
|
}
|
||||||
if parent == nil then
|
pop.load = function()
|
||||||
parent = self.window
|
local elements = filesystem.getDirectoryItems(tostring(path) .. "/elements")
|
||||||
|
for i = 1, #elements do
|
||||||
|
local name = elements[i]:sub(1, -5)
|
||||||
|
pop.elements[name] = require(tostring(path) .. "/elements/" .. tostring(name))
|
||||||
|
print("loaded element: " .. tostring(name))
|
||||||
|
if not pop[name] then
|
||||||
|
pop[name] = function(...)
|
||||||
|
return pop.create(name, ...)
|
||||||
end
|
end
|
||||||
local newElement = self.elements[elementType](parent, ...)
|
print("wrapper created: " .. tostring(name) .. "()")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
pop.window = pop.create("element"):setSize(graphics.getWidth(), graphics.getHeight())
|
||||||
|
return print("created window")
|
||||||
|
end
|
||||||
|
pop.create = function(elementType, parent, ...)
|
||||||
|
if parent == nil then
|
||||||
|
parent = pop.window
|
||||||
|
end
|
||||||
|
local newElement = pop.elements[elementType](parent, ...)
|
||||||
insert(parent.child, newElement)
|
insert(parent.child, newElement)
|
||||||
return newElement
|
return newElement
|
||||||
end,
|
end
|
||||||
update = function(self, dt, element)
|
pop.update = function(dt, element)
|
||||||
if element == nil then
|
if element == nil then
|
||||||
element = self.window
|
element = pop.window
|
||||||
end
|
end
|
||||||
if not element.excludeUpdating then
|
if not element.excludeUpdating then
|
||||||
if element.update then
|
if element.update then
|
||||||
element:update(dt)
|
element:update(dt)
|
||||||
end
|
end
|
||||||
for i = 1, #element.child do
|
for i = 1, #element.child do
|
||||||
self:update(dt, element.child[i])
|
pop.update(dt, element.child[i])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end
|
||||||
draw = function(self, element)
|
pop.draw = function(element)
|
||||||
if element == nil then
|
if element == nil then
|
||||||
element = self.window
|
element = pop.window
|
||||||
end
|
end
|
||||||
if not element.excludeRendering then
|
if not element.excludeRendering then
|
||||||
if element.draw then
|
if element.draw then
|
||||||
local _
|
local _
|
||||||
do
|
do
|
||||||
local _base_1 = element
|
local _base_0 = element
|
||||||
local _fn_0 = _base_1.draw
|
local _fn_0 = _base_0.draw
|
||||||
_ = function(...)
|
_ = function(...)
|
||||||
return _fn_0(_base_1, ...)
|
return _fn_0(_base_0, ...)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for i = 1, #element.child do
|
for i = 1, #element.child do
|
||||||
self:draw(element.child[i])
|
pop.draw(element.child)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end
|
||||||
mousepressed = function(self, button, x, y, element)
|
pop.mousepressed = function(button, x, y, element)
|
||||||
if element == nil then
|
if element == nil then
|
||||||
element = self.window
|
element = pop.window
|
||||||
end
|
end
|
||||||
if (x >= element.x) and (x <= (element.x + element.w)) then
|
if (x >= element.x) and (x <= (element.x + element.w)) then
|
||||||
if (y >= element.y) and (y <= (element.y + element.h)) then
|
if (y >= element.y) and (y <= (element.y + element.h)) then
|
||||||
for i = 1, #element.child do
|
for i = 1, #element.child do
|
||||||
if self:mousepressed(button, x, y, element.child[i]) then
|
if pop.mousepressed(button, x, y, element.child[i]) then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -69,36 +86,22 @@ do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end
|
||||||
mousereleased = function(self, button, x, y, element)
|
pop.mousereleased = function(button, x, y, element)
|
||||||
if element == nil then
|
if element == nil then
|
||||||
element = self.window
|
element = pop.window
|
||||||
end
|
|
||||||
if (x >= element.x) and (x <= (element.x + element.w)) then
|
|
||||||
if (y >= element.y) and (y <= (element.y + element.h)) then
|
|
||||||
for i = 1, #element.child do
|
|
||||||
if self:mousereleased(button, x, y, element.child[i]) then
|
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if element.mousereleased then
|
pop.keypressed = function(key)
|
||||||
return element:mousereleased(button, x - element.x, y - element.y)
|
return print("pop.keypressed() is unimplemented.")
|
||||||
else
|
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
pop.keyreleased = function(key)
|
||||||
|
return print("pop.keyreleased() is unimplemented.")
|
||||||
end
|
end
|
||||||
|
pop.textinput = function(text)
|
||||||
|
return print("pop.textinput() is unimplemented.")
|
||||||
end
|
end
|
||||||
end,
|
pop.skin = function(element, skin, apply_to_children)
|
||||||
keypressed = function(self, key)
|
|
||||||
return error("Unimplemented.")
|
|
||||||
end,
|
|
||||||
keyreleased = function(self, key)
|
|
||||||
return error("Unimplemented.")
|
|
||||||
end,
|
|
||||||
textinput = function(self, text)
|
|
||||||
return error("Unimplemented.")
|
|
||||||
end,
|
|
||||||
skin = function(self, element, skin, apply_to_children)
|
|
||||||
if apply_to_children == nil then
|
if apply_to_children == nil then
|
||||||
apply_to_children = true
|
apply_to_children = true
|
||||||
end
|
end
|
||||||
@ -114,13 +117,13 @@ do
|
|||||||
end
|
end
|
||||||
if apply_to_children then
|
if apply_to_children then
|
||||||
for i = 1, #element.child do
|
for i = 1, #element.child do
|
||||||
self:skin(element.child[i], skin)
|
pop.skin(element.child[i], skin)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end
|
||||||
debugDraw = function(self, element)
|
pop.debugDraw = function(element)
|
||||||
if element == nil then
|
if element == nil then
|
||||||
element = self.window
|
element = pop.window
|
||||||
end
|
end
|
||||||
if element.debugDraw then
|
if element.debugDraw then
|
||||||
element:debugDraw()
|
element:debugDraw()
|
||||||
@ -134,43 +137,8 @@ do
|
|||||||
graphics.print(".", element.x, element.y)
|
graphics.print(".", element.x, element.y)
|
||||||
end
|
end
|
||||||
for i = 1, #element.child do
|
for i = 1, #element.child do
|
||||||
self:debugDraw(element.child[i])
|
pop.debugDraw(element.child[i])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
}
|
pop.load()
|
||||||
_base_0.__index = _base_0
|
return pop
|
||||||
_class_0 = setmetatable({
|
|
||||||
__init = function(self)
|
|
||||||
self.elements = { }
|
|
||||||
self.window = {
|
|
||||||
child = { }
|
|
||||||
}
|
|
||||||
local elements = filesystem.getDirectoryItems(tostring(path) .. "/elements")
|
|
||||||
for i = 1, #elements do
|
|
||||||
local name = elements[i]:sub(1, -5)
|
|
||||||
self.elements[name] = require(tostring(path) .. "/elements/" .. tostring(name))
|
|
||||||
print("loaded element: " .. tostring(name))
|
|
||||||
if not self[name] then
|
|
||||||
self[name] = function(self, ...)
|
|
||||||
return self:create(name, ...)
|
|
||||||
end
|
|
||||||
print("wrapper created: " .. tostring(name) .. "()")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
self.window = self:create("element", self.window):setSize(graphics.getWidth(), graphics.getHeight())
|
|
||||||
return print("created window")
|
|
||||||
end,
|
|
||||||
__base = _base_0,
|
|
||||||
__name = "Pop"
|
|
||||||
}, {
|
|
||||||
__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
|
|
||||||
Pop = _class_0
|
|
||||||
return _class_0
|
|
||||||
end
|
|
||||||
|
146
lib/pop/init.lua
146
lib/pop/init.lua
@ -6,59 +6,76 @@ end
|
|||||||
local insert
|
local insert
|
||||||
insert = table.insert
|
insert = table.insert
|
||||||
local path = ...
|
local path = ...
|
||||||
local Pop
|
local pop = { }
|
||||||
do
|
pop.elements = { }
|
||||||
local _class_0
|
pop.window = {
|
||||||
local _base_0 = {
|
child = { }
|
||||||
create = function(self, elementType, parent, ...)
|
}
|
||||||
if parent == nil then
|
pop.load = function()
|
||||||
parent = self.window
|
local elements = filesystem.getDirectoryItems(tostring(path) .. "/elements")
|
||||||
|
for i = 1, #elements do
|
||||||
|
local name = elements[i]:sub(1, -5)
|
||||||
|
pop.elements[name] = require(tostring(path) .. "/elements/" .. tostring(name))
|
||||||
|
print("loaded element: " .. tostring(name))
|
||||||
|
if not pop[name] then
|
||||||
|
pop[name] = function(...)
|
||||||
|
return pop.create(name, ...)
|
||||||
end
|
end
|
||||||
local newElement = self.elements[elementType](parent, ...)
|
print("wrapper created: " .. tostring(name) .. "()")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
pop.window = pop.create("element"):setSize(graphics.getWidth(), graphics.getHeight())
|
||||||
|
return print("created window")
|
||||||
|
end
|
||||||
|
pop.create = function(elementType, parent, ...)
|
||||||
|
if parent == nil then
|
||||||
|
parent = pop.window
|
||||||
|
end
|
||||||
|
local newElement = pop.elements[elementType](parent, ...)
|
||||||
insert(parent.child, newElement)
|
insert(parent.child, newElement)
|
||||||
return newElement
|
return newElement
|
||||||
end,
|
end
|
||||||
update = function(self, dt, element)
|
pop.update = function(dt, element)
|
||||||
if element == nil then
|
if element == nil then
|
||||||
element = self.window
|
element = pop.window
|
||||||
end
|
end
|
||||||
if not element.excludeUpdating then
|
if not element.excludeUpdating then
|
||||||
if element.update then
|
if element.update then
|
||||||
element:update(dt)
|
element:update(dt)
|
||||||
end
|
end
|
||||||
for i = 1, #element.child do
|
for i = 1, #element.child do
|
||||||
self:update(dt, element.child[i])
|
pop.update(dt, element.child[i])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end
|
||||||
draw = function(self, element)
|
pop.draw = function(element)
|
||||||
if element == nil then
|
if element == nil then
|
||||||
element = self.window
|
element = pop.window
|
||||||
end
|
end
|
||||||
if not element.excludeRendering then
|
if not element.excludeRendering then
|
||||||
if element.draw then
|
if element.draw then
|
||||||
local _
|
local _
|
||||||
do
|
do
|
||||||
local _base_1 = element
|
local _base_0 = element
|
||||||
local _fn_0 = _base_1.draw
|
local _fn_0 = _base_0.draw
|
||||||
_ = function(...)
|
_ = function(...)
|
||||||
return _fn_0(_base_1, ...)
|
return _fn_0(_base_0, ...)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for i = 1, #element.child do
|
for i = 1, #element.child do
|
||||||
self:draw(element.child[i])
|
pop.draw(element.child)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end
|
||||||
mousepressed = function(self, button, x, y, element)
|
pop.mousepressed = function(button, x, y, element)
|
||||||
if element == nil then
|
if element == nil then
|
||||||
element = self.window
|
element = pop.window
|
||||||
end
|
end
|
||||||
if (x >= element.x) and (x <= (element.x + element.w)) then
|
if (x >= element.x) and (x <= (element.x + element.w)) then
|
||||||
if (y >= element.y) and (y <= (element.y + element.h)) then
|
if (y >= element.y) and (y <= (element.y + element.h)) then
|
||||||
for i = 1, #element.child do
|
for i = 1, #element.child do
|
||||||
if self:mousepressed(button, x, y, element.child[i]) then
|
if pop.mousepressed(button, x, y, element.child[i]) then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -69,36 +86,22 @@ do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end
|
||||||
mousereleased = function(self, button, x, y, element)
|
pop.mousereleased = function(button, x, y, element)
|
||||||
if element == nil then
|
if element == nil then
|
||||||
element = self.window
|
element = pop.window
|
||||||
end
|
|
||||||
if (x >= element.x) and (x <= (element.x + element.w)) then
|
|
||||||
if (y >= element.y) and (y <= (element.y + element.h)) then
|
|
||||||
for i = 1, #element.child do
|
|
||||||
if self:mousereleased(button, x, y, element.child[i]) then
|
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if element.mousereleased then
|
pop.keypressed = function(key)
|
||||||
return element:mousereleased(button, x - element.x, y - element.y)
|
return print("pop.keypressed() is unimplemented.")
|
||||||
else
|
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
pop.keyreleased = function(key)
|
||||||
|
return print("pop.keyreleased() is unimplemented.")
|
||||||
end
|
end
|
||||||
|
pop.textinput = function(text)
|
||||||
|
return print("pop.textinput() is unimplemented.")
|
||||||
end
|
end
|
||||||
end,
|
pop.skin = function(element, skin, apply_to_children)
|
||||||
keypressed = function(self, key)
|
|
||||||
return error("Unimplemented.")
|
|
||||||
end,
|
|
||||||
keyreleased = function(self, key)
|
|
||||||
return error("Unimplemented.")
|
|
||||||
end,
|
|
||||||
textinput = function(self, text)
|
|
||||||
return error("Unimplemented.")
|
|
||||||
end,
|
|
||||||
skin = function(self, element, skin, apply_to_children)
|
|
||||||
if apply_to_children == nil then
|
if apply_to_children == nil then
|
||||||
apply_to_children = true
|
apply_to_children = true
|
||||||
end
|
end
|
||||||
@ -114,13 +117,13 @@ do
|
|||||||
end
|
end
|
||||||
if apply_to_children then
|
if apply_to_children then
|
||||||
for i = 1, #element.child do
|
for i = 1, #element.child do
|
||||||
self:skin(element.child[i], skin)
|
pop.skin(element.child[i], skin)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end
|
||||||
debugDraw = function(self, element)
|
pop.debugDraw = function(element)
|
||||||
if element == nil then
|
if element == nil then
|
||||||
element = self.window
|
element = pop.window
|
||||||
end
|
end
|
||||||
if element.debugDraw then
|
if element.debugDraw then
|
||||||
element:debugDraw()
|
element:debugDraw()
|
||||||
@ -134,43 +137,8 @@ do
|
|||||||
graphics.print(".", element.x, element.y)
|
graphics.print(".", element.x, element.y)
|
||||||
end
|
end
|
||||||
for i = 1, #element.child do
|
for i = 1, #element.child do
|
||||||
self:debugDraw(element.child[i])
|
pop.debugDraw(element.child[i])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
}
|
pop.load()
|
||||||
_base_0.__index = _base_0
|
return pop
|
||||||
_class_0 = setmetatable({
|
|
||||||
__init = function(self)
|
|
||||||
self.elements = { }
|
|
||||||
self.window = {
|
|
||||||
child = { }
|
|
||||||
}
|
|
||||||
local elements = filesystem.getDirectoryItems(tostring(path) .. "/elements")
|
|
||||||
for i = 1, #elements do
|
|
||||||
local name = elements[i]:sub(1, -5)
|
|
||||||
self.elements[name] = require(tostring(path) .. "/elements/" .. tostring(name))
|
|
||||||
print("loaded element: " .. tostring(name))
|
|
||||||
if not self[name] then
|
|
||||||
self[name] = function(self, ...)
|
|
||||||
return self:create(name, ...)
|
|
||||||
end
|
|
||||||
print("wrapper created: " .. tostring(name) .. "()")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
self.window = self:create("element", self.window):setSize(graphics.getWidth(), graphics.getHeight())
|
|
||||||
return print("created window")
|
|
||||||
end,
|
|
||||||
__base = _base_0,
|
|
||||||
__name = "Pop"
|
|
||||||
}, {
|
|
||||||
__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
|
|
||||||
Pop = _class_0
|
|
||||||
return _class_0
|
|
||||||
end
|
|
||||||
|
@ -3,56 +3,57 @@ import insert from table
|
|||||||
|
|
||||||
path = ...
|
path = ...
|
||||||
|
|
||||||
class Pop
|
pop = {}
|
||||||
new: =>
|
|
||||||
@elements = {}
|
|
||||||
@window = {child: {}}
|
|
||||||
--@focused = @window --TODO redo better
|
|
||||||
|
|
||||||
|
pop.elements = {}
|
||||||
|
pop.window = {child: {}} --placeholder to allow window creation without specialized code
|
||||||
|
--pop.focused = false
|
||||||
|
|
||||||
|
pop.load = ->
|
||||||
elements = filesystem.getDirectoryItems "#{path}/elements"
|
elements = filesystem.getDirectoryItems "#{path}/elements"
|
||||||
for i = 1, #elements
|
for i = 1, #elements
|
||||||
name = elements[i]\sub 1, -5
|
name = elements[i]\sub 1, -5
|
||||||
@elements[name] = require "#{path}/elements/#{name}"
|
pop.elements[name] = require "#{path}/elements/#{name}"
|
||||||
print "loaded element: #{name}"
|
print "loaded element: #{name}"
|
||||||
|
|
||||||
if not @[name]
|
if not pop[name]
|
||||||
@[name] = (...) => return @create(name, ...)
|
pop[name] = (...) -> return pop.create(name, ...)
|
||||||
print "wrapper created: #{name}()"
|
print "wrapper created: #{name}()"
|
||||||
|
|
||||||
@window = @create("element", @window)\setSize(graphics.getWidth!, graphics.getHeight!)
|
pop.window = pop.create("element")\setSize(graphics.getWidth!, graphics.getHeight!)
|
||||||
|
--pop.window.parent = pop.window --may be dangerous? infinite loop looking for the window?
|
||||||
|
--pop.window.parent = false --may be dangerous? attempting to index a boolean?
|
||||||
print "created window"
|
print "created window"
|
||||||
--@window.parent = @window
|
|
||||||
--@window.parent = false
|
|
||||||
|
|
||||||
create: (elementType, parent=@window, ...) =>
|
pop.create = (elementType, parent=pop.window, ...) ->
|
||||||
newElement = @elements[elementType](parent, ...)
|
newElement = pop.elements[elementType](parent, ...)
|
||||||
insert parent.child, newElement
|
insert parent.child, newElement
|
||||||
return newElement
|
return newElement
|
||||||
|
|
||||||
update: (dt, element=@window) =>
|
pop.update = (dt, element=pop.window) ->
|
||||||
if not element.excludeUpdating
|
if not element.excludeUpdating
|
||||||
if element.update
|
if element.update
|
||||||
element\update dt
|
element\update dt
|
||||||
|
|
||||||
for i = 1, #element.child
|
for i = 1, #element.child
|
||||||
@update dt, element.child[i]
|
pop.update dt, element.child[i]
|
||||||
|
|
||||||
draw: (element=@window) =>
|
pop.draw = (element=pop.window) ->
|
||||||
if not element.excludeRendering
|
if not element.excludeRendering
|
||||||
if element.draw
|
if element.draw
|
||||||
element\draw
|
element\draw
|
||||||
|
|
||||||
for i = 1, #element.child
|
for i = 1, #element.child
|
||||||
@draw element.child[i]
|
pop.draw element.child
|
||||||
|
|
||||||
mousepressed: (button, x, y, element=@window) =>
|
pop.mousepressed = (button, x, y, element=pop.window) ->
|
||||||
-- if within bounds of element, check its children
|
-- if within bounds, check children
|
||||||
-- if not handled by child, check if it can handle it
|
-- if not handled, check if we can handle it
|
||||||
-- abort loop with success if handled
|
-- abort with success if handled
|
||||||
if (x >= element.x) and (x <= (element.x + element.w))
|
if (x >= element.x) and (x <= (element.x + element.w))
|
||||||
if (y >= element.y) and (y <= (element.y + element.h))
|
if (y >= element.y) and (y <= (element.y + element.h))
|
||||||
for i = 1, #element.child
|
for i = 1, #element.child
|
||||||
if @mousepressed button, x, y, element.child[i]
|
if pop.mousepressed button, x, y, element.child[i]
|
||||||
return true
|
return true
|
||||||
|
|
||||||
if element.mousepressed
|
if element.mousepressed
|
||||||
@ -60,31 +61,20 @@ class Pop
|
|||||||
else
|
else
|
||||||
return false
|
return false
|
||||||
|
|
||||||
--TODO rewrite for multiple return values, mousereleased is the first val, click is the second!
|
--TODO multiple return values, mousereleased first, click second
|
||||||
mousereleased: (button, x, y, element=@window) =>
|
pop.mousereleased = (button, x, y, element=pop.window) ->
|
||||||
-- same as mousepressed, except an additional click is fired
|
-- same as mousepressed, except a click can be fired as well
|
||||||
-- (TODO fix, so you have to start and end the click on the same element)
|
|
||||||
if (x >= element.x) and (x <= (element.x + element.w))
|
|
||||||
if (y >= element.y) and (y <= (element.y + element.h))
|
|
||||||
for i = 1, #element.child
|
|
||||||
if @mousereleased button, x, y, element.child[i]
|
|
||||||
return true
|
|
||||||
|
|
||||||
if element.mousereleased
|
pop.keypressed = (key) ->
|
||||||
return element\mousereleased button, x - element.x, y - element.y
|
print "pop.keypressed() is unimplemented."
|
||||||
else
|
|
||||||
return false
|
|
||||||
|
|
||||||
keypressed: (key) =>
|
pop.keyreleased = (key) ->
|
||||||
error "Unimplemented."
|
print "pop.keyreleased() is unimplemented."
|
||||||
|
|
||||||
keyreleased: (key) =>
|
pop.textinput = (text) ->
|
||||||
error "Unimplemented."
|
print "pop.textinput() is unimplemented."
|
||||||
|
|
||||||
textinput: (text) =>
|
pop.skin = (element, skin, apply_to_children=true) ->
|
||||||
error "Unimplemented."
|
|
||||||
|
|
||||||
skin: (element, skin, apply_to_children=true) =>
|
|
||||||
element.margin = skin.margin
|
element.margin = skin.margin
|
||||||
|
|
||||||
if element.background
|
if element.background
|
||||||
@ -96,9 +86,9 @@ class Pop
|
|||||||
|
|
||||||
if apply_to_children
|
if apply_to_children
|
||||||
for i = 1, #element.child
|
for i = 1, #element.child
|
||||||
@skin element.child[i], skin
|
pop.skin element.child[i], skin
|
||||||
|
|
||||||
debugDraw: (element=@window) =>
|
pop.debugDraw = (element=pop.window) ->
|
||||||
if element.debugDraw
|
if element.debugDraw
|
||||||
element\debugDraw!
|
element\debugDraw!
|
||||||
else
|
else
|
||||||
@ -111,4 +101,8 @@ class Pop
|
|||||||
graphics.print ".", element.x, element.y
|
graphics.print ".", element.x, element.y
|
||||||
|
|
||||||
for i = 1, #element.child
|
for i = 1, #element.child
|
||||||
@debugDraw element.child[i]
|
pop.debugDraw element.child[i]
|
||||||
|
|
||||||
|
pop.load!
|
||||||
|
|
||||||
|
return pop
|
||||||
|
Loading…
Reference in New Issue
Block a user