mirror of
https://github.com/TangentFoxy/Pop.Box.git
synced 2024-12-15 12:44:20 +00:00
whoops, forgot to re-build!
This commit is contained in:
parent
6571320310
commit
b06ecde97b
@ -1,4 +1,5 @@
|
|||||||
local lg = love.graphics
|
local graphics
|
||||||
|
graphics = love.graphics
|
||||||
return {
|
return {
|
||||||
background = {
|
background = {
|
||||||
0,
|
0,
|
||||||
@ -12,5 +13,5 @@ return {
|
|||||||
255,
|
255,
|
||||||
250
|
250
|
||||||
},
|
},
|
||||||
font = lg.newFont(14)
|
font = graphics.newFont(14)
|
||||||
}
|
}
|
||||||
|
@ -16,8 +16,8 @@ do
|
|||||||
if self.background then
|
if self.background then
|
||||||
if type(self.background) == "table" then
|
if type(self.background) == "table" then
|
||||||
graphics.setColor(self.background)
|
graphics.setColor(self.background)
|
||||||
|
graphics.rectangle("fill", self.x, self.y, self.w, self.h)
|
||||||
else
|
else
|
||||||
graphics.setColor(self.background)
|
|
||||||
local w, h = self.background:getDimensions()
|
local w, h = self.background:getDimensions()
|
||||||
w = self.w / w
|
w = self.w / w
|
||||||
h = self.h / h
|
h = self.h / h
|
||||||
@ -47,12 +47,16 @@ do
|
|||||||
if a == nil then
|
if a == nil then
|
||||||
a = 255
|
a = 255
|
||||||
end
|
end
|
||||||
self.background = {
|
if type(r) == "table" then
|
||||||
r,
|
self.background = r
|
||||||
g,
|
else
|
||||||
b,
|
self.background = {
|
||||||
a
|
r,
|
||||||
}
|
g,
|
||||||
|
b,
|
||||||
|
a
|
||||||
|
}
|
||||||
|
end
|
||||||
return self
|
return self
|
||||||
end,
|
end,
|
||||||
getColor = function(self)
|
getColor = function(self)
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
local graphics
|
local graphics
|
||||||
graphics = love.graphics
|
graphics = love.graphics
|
||||||
|
local floor
|
||||||
|
floor = math.floor
|
||||||
local element
|
local element
|
||||||
do
|
do
|
||||||
local _class_0
|
local _class_0
|
||||||
@ -15,10 +17,14 @@ do
|
|||||||
return self
|
return self
|
||||||
end,
|
end,
|
||||||
move = function(self, x, y)
|
move = function(self, x, y)
|
||||||
self.x = self.x + x
|
if x then
|
||||||
self.y = self.y + y
|
self.x = self.x + x
|
||||||
|
end
|
||||||
|
if y then
|
||||||
|
self.y = self.y + y
|
||||||
|
end
|
||||||
for i = 1, #self.child do
|
for i = 1, #self.child do
|
||||||
if not self.child[i].excludeMovement then
|
if not (self.child[i].excludeMovement) then
|
||||||
self.child[i]:move(x, y)
|
self.child[i]:move(x, y)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -27,24 +33,32 @@ do
|
|||||||
setPosition = function(self, x, y)
|
setPosition = function(self, x, y)
|
||||||
local oldX = self.x
|
local oldX = self.x
|
||||||
local oldY = self.y
|
local oldY = self.y
|
||||||
local _exp_0 = self.horizontal
|
if x then
|
||||||
if "left" == _exp_0 then
|
local _exp_0 = self.horizontal
|
||||||
self.x = x
|
if "left" == _exp_0 then
|
||||||
elseif "center" == _exp_0 then
|
self.x = x
|
||||||
self.x = x - self.w / 2
|
elseif "center" == _exp_0 then
|
||||||
elseif "right" == _exp_0 then
|
self.x = x - self.w / 2
|
||||||
self.x = x - self.w
|
elseif "right" == _exp_0 then
|
||||||
|
self.x = x - self.w
|
||||||
|
end
|
||||||
|
else
|
||||||
|
x = oldX
|
||||||
end
|
end
|
||||||
local _exp_1 = self.vertical
|
if y then
|
||||||
if "top" == _exp_1 then
|
local _exp_0 = self.vertical
|
||||||
self.y = y
|
if "top" == _exp_0 then
|
||||||
elseif "center" == _exp_1 then
|
self.y = y
|
||||||
self.y = y - self.h / 2
|
elseif "center" == _exp_0 then
|
||||||
elseif "bottom" == _exp_1 then
|
self.y = y - self.h / 2
|
||||||
self.y = y - self.h
|
elseif "bottom" == _exp_0 then
|
||||||
|
self.y = y - self.h
|
||||||
|
end
|
||||||
|
else
|
||||||
|
y = oldY
|
||||||
end
|
end
|
||||||
for i = 1, #self.child do
|
for i = 1, #self.child do
|
||||||
if not self.child[i].excludeMovement then
|
if not (self.child[i].excludeMovement) then
|
||||||
self.child[i]:move(x - oldX, y - oldY)
|
self.child[i]:move(x - oldX, y - oldY)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -57,7 +71,7 @@ do
|
|||||||
if "center" == _exp_0 then
|
if "center" == _exp_0 then
|
||||||
resultX = resultX + (self.w / 2)
|
resultX = resultX + (self.w / 2)
|
||||||
elseif "right" == _exp_0 then
|
elseif "right" == _exp_0 then
|
||||||
resultX = resultX + self.w
|
resultY = resultY + self.w
|
||||||
end
|
end
|
||||||
local _exp_1 = self.vertical
|
local _exp_1 = self.vertical
|
||||||
if "center" == _exp_1 then
|
if "center" == _exp_1 then
|
||||||
@ -102,7 +116,7 @@ do
|
|||||||
self:setSize(W, H)
|
self:setSize(W, H)
|
||||||
return self
|
return self
|
||||||
end,
|
end,
|
||||||
align = function(self, horizontal, vertical)
|
align = function(self, horizontal, vertical, toPixel)
|
||||||
self:setAlignment(horizontal, vertical)
|
self:setAlignment(horizontal, vertical)
|
||||||
self.x = self.parent.x
|
self.x = self.parent.x
|
||||||
self.y = self.parent.y
|
self.y = self.parent.y
|
||||||
@ -122,13 +136,17 @@ do
|
|||||||
elseif "bottom" == _exp_1 then
|
elseif "bottom" == _exp_1 then
|
||||||
self.y = self.y + (self.parent.h - self.h - self.margin)
|
self.y = self.y + (self.parent.h - self.h - self.margin)
|
||||||
end
|
end
|
||||||
|
if toPixel then
|
||||||
|
self.x = floor(self.x)
|
||||||
|
self.y = floor(self.y)
|
||||||
|
end
|
||||||
return self
|
return self
|
||||||
end,
|
end,
|
||||||
alignTo = function(self, element, horizontal, vertical)
|
alignTo = function(self, element, horizontal, vertical)
|
||||||
local realParent = self.parent
|
local parent = self.parent
|
||||||
self.parent = element
|
self.parent = element
|
||||||
self:align(horizontal, vertical)
|
self:align(horizontal, vertical)
|
||||||
self.parent = realParent
|
self.parent = parent
|
||||||
return self
|
return self
|
||||||
end,
|
end,
|
||||||
setAlignment = function(self, horizontal, vertical)
|
setAlignment = function(self, horizontal, vertical)
|
||||||
@ -139,6 +157,14 @@ do
|
|||||||
self.vertical = vertical
|
self.vertical = vertical
|
||||||
end
|
end
|
||||||
return self
|
return self
|
||||||
|
end,
|
||||||
|
setMargin = function(self, margin)
|
||||||
|
self.margin = margin
|
||||||
|
self:align()
|
||||||
|
return self
|
||||||
|
end,
|
||||||
|
getMargin = function(self)
|
||||||
|
return self.margin
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
_base_0.__index = _base_0
|
_base_0.__index = _base_0
|
||||||
@ -146,8 +172,13 @@ do
|
|||||||
__init = function(self, pop, parent)
|
__init = function(self, pop, parent)
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.child = { }
|
self.child = { }
|
||||||
self.x = parent.x or 0
|
if parent then
|
||||||
self.y = parent.y or 0
|
self.x = parent.x or 0
|
||||||
|
self.y = parent.y or 0
|
||||||
|
else
|
||||||
|
self.x = 0
|
||||||
|
self.y = 0
|
||||||
|
end
|
||||||
self.w = 10
|
self.w = 10
|
||||||
self.h = 10
|
self.h = 10
|
||||||
self.horizontal = "left"
|
self.horizontal = "left"
|
||||||
|
@ -5,13 +5,22 @@ do
|
|||||||
local _obj_0 = string
|
local _obj_0 = string
|
||||||
sub, len = _obj_0.sub, _obj_0.len
|
sub, len = _obj_0.sub, _obj_0.len
|
||||||
end
|
end
|
||||||
local path = sub(..., 1, len(...) - len("/text"))
|
local path = sub(..., 1, len(...) - len("/box"))
|
||||||
local element = require(tostring(path) .. "/element")
|
local element = require(tostring(path) .. "/element")
|
||||||
local text
|
local text
|
||||||
do
|
do
|
||||||
local _class_0
|
local _class_0
|
||||||
local _parent_0 = element
|
local _parent_0 = element
|
||||||
local _base_0 = {
|
local _base_0 = {
|
||||||
|
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,
|
||||||
draw = function(self)
|
draw = function(self)
|
||||||
graphics.setColor(self.color)
|
graphics.setColor(self.color)
|
||||||
graphics.setFont(self.font)
|
graphics.setFont(self.font)
|
||||||
@ -40,7 +49,7 @@ do
|
|||||||
local _exp_1 = self.vertical
|
local _exp_1 = self.vertical
|
||||||
if "center" == _exp_1 then
|
if "center" == _exp_1 then
|
||||||
self.y = self.y - ((h - self.h) / 2)
|
self.y = self.y - ((h - self.h) / 2)
|
||||||
elseif "right" == _exp_1 then
|
elseif "bottom" == _exp_1 then
|
||||||
self.y = self.y - (h - self.h - self.margin)
|
self.y = self.y - (h - self.h - self.margin)
|
||||||
end
|
end
|
||||||
self.w = w
|
self.w = w
|
||||||
@ -70,12 +79,16 @@ do
|
|||||||
if a == nil then
|
if a == nil then
|
||||||
a = 255
|
a = 255
|
||||||
end
|
end
|
||||||
self.color = {
|
if type(r) == "table" then
|
||||||
r,
|
self.color = r
|
||||||
g,
|
else
|
||||||
b,
|
self.color = {
|
||||||
a
|
r,
|
||||||
}
|
g,
|
||||||
|
b,
|
||||||
|
a
|
||||||
|
}
|
||||||
|
end
|
||||||
return self
|
return self
|
||||||
end,
|
end,
|
||||||
getColor = function(self)
|
getColor = function(self)
|
||||||
|
157
lib/pop/init.lua
157
lib/pop/init.lua
@ -8,38 +8,71 @@ insert = table.insert
|
|||||||
local path = ...
|
local path = ...
|
||||||
local pop = { }
|
local pop = { }
|
||||||
pop.elements = { }
|
pop.elements = { }
|
||||||
pop.window = {
|
pop.skins = { }
|
||||||
child = { }
|
pop.screen = false
|
||||||
}
|
|
||||||
pop.load = function()
|
pop.load = function()
|
||||||
local elements = filesystem.getDirectoryItems(tostring(path) .. "/elements")
|
local elements = filesystem.getDirectoryItems(tostring(path) .. "/elements")
|
||||||
for i = 1, #elements do
|
for i = 1, #elements do
|
||||||
local name = elements[i]:sub(1, -5)
|
local _continue_0 = false
|
||||||
pop.elements[name] = require(tostring(path) .. "/elements/" .. tostring(name))
|
repeat
|
||||||
print("loaded element: " .. tostring(name))
|
if not (elements[i]:sub(-4) == ".lua") then
|
||||||
if not pop[name] then
|
_continue_0 = true
|
||||||
pop[name] = function(...)
|
break
|
||||||
return pop.create(name, ...)
|
|
||||||
end
|
end
|
||||||
print("wrapper created: " .. tostring(name) .. "()")
|
local name = elements[i]:sub(1, -5)
|
||||||
|
pop.elements[name] = require(tostring(path) .. "/elements/" .. tostring(name))
|
||||||
|
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
|
||||||
end
|
end
|
||||||
pop.window = pop.create("element"):setSize(graphics.getWidth(), graphics.getHeight())
|
local skins = filesystem.getDirectoryItems(tostring(path) .. "/skins")
|
||||||
return print("created window")
|
for i = 1, #skins do
|
||||||
end
|
local _continue_0 = false
|
||||||
pop.create = function(elementType, parent, ...)
|
repeat
|
||||||
if parent == nil then
|
if not (skins[i]:sub(-4) == ".lua") then
|
||||||
parent = pop.window
|
_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
|
end
|
||||||
local newElement = pop.elements[elementType](parent, ...)
|
pop.screen = pop.create("element", false):setSize(graphics.getWidth(), graphics.getHeight())
|
||||||
insert(parent.child, newElement)
|
return print("created \"pop.screen\"")
|
||||||
return newElement
|
end
|
||||||
|
pop.create = function(element, parent, ...)
|
||||||
|
if parent == nil then
|
||||||
|
parent = pop.screen
|
||||||
|
end
|
||||||
|
element = pop.elements[element](pop, parent, ...)
|
||||||
|
if parent then
|
||||||
|
insert(parent.child, element)
|
||||||
|
end
|
||||||
|
return element
|
||||||
end
|
end
|
||||||
pop.update = function(dt, element)
|
pop.update = function(dt, element)
|
||||||
if element == nil then
|
if element == nil then
|
||||||
element = pop.window
|
element = pop.screen
|
||||||
end
|
end
|
||||||
if not element.excludeUpdating then
|
if not (element.excludeUpdate) then
|
||||||
if element.update then
|
if element.update then
|
||||||
element:update(dt)
|
element:update(dt)
|
||||||
end
|
end
|
||||||
@ -50,86 +83,80 @@ pop.update = function(dt, element)
|
|||||||
end
|
end
|
||||||
pop.draw = function(element)
|
pop.draw = function(element)
|
||||||
if element == nil then
|
if element == nil then
|
||||||
element = pop.window
|
element = pop.screen
|
||||||
end
|
end
|
||||||
if not element.excludeRendering then
|
if not (element.excludeDraw) then
|
||||||
if element.draw then
|
if element.draw then
|
||||||
local _
|
element:draw()
|
||||||
do
|
|
||||||
local _base_0 = element
|
|
||||||
local _fn_0 = _base_0.draw
|
|
||||||
_ = function(...)
|
|
||||||
return _fn_0(_base_0, ...)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
for i = 1, #element.child do
|
for i = 1, #element.child do
|
||||||
pop.draw(element.child)
|
pop.draw(element.child[i])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
pop.mousepressed = function(button, x, y, element)
|
pop.mousepressed = function(x, y, button, element)
|
||||||
if element == nil then
|
if element == nil then
|
||||||
element = pop.window
|
element = pop.screen
|
||||||
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 pop.mousepressed(button, x, y, element.child[i]) then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if element.mousepressed then
|
|
||||||
return element:mousepressed(button, x - element.x, y - element.y)
|
|
||||||
else
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
print("mousepressed", x, y, button, element)
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
pop.mousereleased = function(button, x, y, element)
|
pop.mousereleased = function(x, y, button, element)
|
||||||
if element == nil then
|
if element == nil then
|
||||||
element = pop.window
|
element = pop.screen
|
||||||
end
|
end
|
||||||
|
print("mousereleased", x, y, button, element)
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
pop.keypressed = function(key)
|
pop.keypressed = function(key)
|
||||||
return print("pop.keypressed() is unimplemented.")
|
print("keypressed", key)
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
pop.keyreleased = function(key)
|
pop.keyreleased = function(key)
|
||||||
return print("pop.keyreleased() is unimplemented.")
|
print("keyreleased", key)
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
pop.textinput = function(text)
|
pop.textinput = function(text)
|
||||||
return print("pop.textinput() is unimplemented.")
|
print("textinput", text)
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
pop.skin = function(element, skin, apply_to_children)
|
pop.skin = function(element, skin, depth)
|
||||||
if apply_to_children == nil then
|
if element == nil then
|
||||||
apply_to_children = true
|
element = pop.screen
|
||||||
end
|
end
|
||||||
element.margin = skin.margin
|
if skin == nil then
|
||||||
if element.background then
|
skin = pop.skins.default
|
||||||
|
end
|
||||||
|
if element.background and skin.background then
|
||||||
element.background = skin.background
|
element.background = skin.background
|
||||||
end
|
end
|
||||||
if element.color then
|
if element.color and skin.color then
|
||||||
element.color = skin.color
|
element.color = skin.color
|
||||||
end
|
end
|
||||||
if element.font then
|
if element.font and skin.font then
|
||||||
element.font = skin.font
|
element.font = skin.font
|
||||||
end
|
end
|
||||||
if apply_to_children then
|
if not (depth or (depth == 0)) then
|
||||||
for i = 1, #element.child do
|
if depth == tonumber(depth) then
|
||||||
pop.skin(element.child[i], skin)
|
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
|
end
|
||||||
end
|
end
|
||||||
pop.debugDraw = function(element)
|
pop.debugDraw = function(element)
|
||||||
if element == nil then
|
if element == nil then
|
||||||
element = pop.window
|
element = pop.screen
|
||||||
end
|
end
|
||||||
if element.debugDraw then
|
if element.debugDraw then
|
||||||
element:debugDraw()
|
element:debugDraw()
|
||||||
else
|
else
|
||||||
graphics.setLineWidth(1)
|
graphics.setLineWidth(1)
|
||||||
graphics.setColor(0, 0, 0, 100)
|
graphics.setLineColor(0, 0, 0, 100)
|
||||||
graphics.rectangle("fill", element.x, element.y, element.w, element.h)
|
graphics.rectangle("fill", element.x, element.y, element.w, element.h)
|
||||||
graphics.setColor(150, 150, 150, 150)
|
graphics.setColor(150, 150, 150, 150)
|
||||||
graphics.rectangle("line", element.x, element.y, element.w, element.h)
|
graphics.rectangle("line", element.x, element.y, element.w, element.h)
|
||||||
|
17
lib/pop/skins/default.lua
Normal file
17
lib/pop/skins/default.lua
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
local graphics
|
||||||
|
graphics = love.graphics
|
||||||
|
return {
|
||||||
|
background = {
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
220
|
||||||
|
},
|
||||||
|
color = {
|
||||||
|
255,
|
||||||
|
255,
|
||||||
|
255,
|
||||||
|
250
|
||||||
|
},
|
||||||
|
font = graphics.newFont(14)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user