whoops, forgot to re-build!

This commit is contained in:
Fox 2016-03-28 18:00:17 -07:00
parent 6571320310
commit b06ecde97b
6 changed files with 199 additions and 106 deletions

View File

@ -1,4 +1,5 @@
local lg = love.graphics
local graphics
graphics = love.graphics
return {
background = {
0,
@ -12,5 +13,5 @@ return {
255,
250
},
font = lg.newFont(14)
font = graphics.newFont(14)
}

View File

@ -16,8 +16,8 @@ do
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
graphics.setColor(self.background)
local w, h = self.background:getDimensions()
w = self.w / w
h = self.h / h
@ -47,12 +47,16 @@ do
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)

View File

@ -1,5 +1,7 @@
local graphics
graphics = love.graphics
local floor
floor = math.floor
local element
do
local _class_0
@ -15,10 +17,14 @@ do
return self
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
if not (self.child[i].excludeMovement) then
self.child[i]:move(x, y)
end
end
@ -27,6 +33,7 @@ do
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
@ -35,16 +42,23 @@ do
elseif "right" == _exp_0 then
self.x = x - self.w
end
local _exp_1 = self.vertical
if "top" == _exp_1 then
else
x = oldX
end
if y then
local _exp_0 = self.vertical
if "top" == _exp_0 then
self.y = y
elseif "center" == _exp_1 then
elseif "center" == _exp_0 then
self.y = y - self.h / 2
elseif "bottom" == _exp_1 then
elseif "bottom" == _exp_0 then
self.y = y - self.h
end
else
y = oldY
end
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)
end
end
@ -57,7 +71,7 @@ do
if "center" == _exp_0 then
resultX = resultX + (self.w / 2)
elseif "right" == _exp_0 then
resultX = resultX + self.w
resultY = resultY + self.w
end
local _exp_1 = self.vertical
if "center" == _exp_1 then
@ -102,7 +116,7 @@ do
self:setSize(W, H)
return self
end,
align = function(self, horizontal, vertical)
align = function(self, horizontal, vertical, toPixel)
self:setAlignment(horizontal, vertical)
self.x = self.parent.x
self.y = self.parent.y
@ -122,13 +136,17 @@ do
elseif "bottom" == _exp_1 then
self.y = self.y + (self.parent.h - self.h - self.margin)
end
if toPixel then
self.x = floor(self.x)
self.y = floor(self.y)
end
return self
end,
alignTo = function(self, element, horizontal, vertical)
local realParent = self.parent
local parent = self.parent
self.parent = element
self:align(horizontal, vertical)
self.parent = realParent
self.parent = parent
return self
end,
setAlignment = function(self, horizontal, vertical)
@ -139,6 +157,14 @@ do
self.vertical = vertical
end
return self
end,
setMargin = function(self, margin)
self.margin = margin
self:align()
return self
end,
getMargin = function(self)
return self.margin
end
}
_base_0.__index = _base_0
@ -146,8 +172,13 @@ do
__init = function(self, pop, parent)
self.parent = parent
self.child = { }
if parent then
self.x = parent.x or 0
self.y = parent.y or 0
else
self.x = 0
self.y = 0
end
self.w = 10
self.h = 10
self.horizontal = "left"

View File

@ -5,13 +5,22 @@ do
local _obj_0 = string
sub, len = _obj_0.sub, _obj_0.len
end
local path = sub(..., 1, len(...) - len("/text"))
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 = {
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)
graphics.setColor(self.color)
graphics.setFont(self.font)
@ -40,7 +49,7 @@ do
local _exp_1 = self.vertical
if "center" == _exp_1 then
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)
end
self.w = w
@ -70,12 +79,16 @@ do
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)

View File

@ -8,38 +8,71 @@ insert = table.insert
local path = ...
local pop = { }
pop.elements = { }
pop.window = {
child = { }
}
pop.skins = { }
pop.screen = 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))
print("loaded element: " .. tostring(name))
if not pop[name] then
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
print("wrapper created: " .. tostring(name) .. "()")
end
print("wrapper created: \"pop." .. tostring(name) .. "()\"")
end
_continue_0 = true
until true
if not _continue_0 then
break
end
end
pop.window = pop.create("element"):setSize(graphics.getWidth(), graphics.getHeight())
return print("created window")
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
pop.create = function(elementType, parent, ...)
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
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.window
parent = pop.screen
end
local newElement = pop.elements[elementType](parent, ...)
insert(parent.child, newElement)
return newElement
element = pop.elements[element](pop, parent, ...)
if parent then
insert(parent.child, element)
end
return element
end
pop.update = function(dt, element)
if element == nil then
element = pop.window
element = pop.screen
end
if not element.excludeUpdating then
if not (element.excludeUpdate) then
if element.update then
element:update(dt)
end
@ -50,86 +83,80 @@ pop.update = function(dt, element)
end
pop.draw = function(element)
if element == nil then
element = pop.window
element = pop.screen
end
if not element.excludeRendering then
if not (element.excludeDraw) then
if element.draw then
local _
do
local _base_0 = element
local _fn_0 = _base_0.draw
_ = function(...)
return _fn_0(_base_0, ...)
end
end
element:draw()
end
for i = 1, #element.child do
pop.draw(element.child)
pop.draw(element.child[i])
end
end
end
pop.mousepressed = function(button, x, y, element)
pop.mousepressed = function(x, y, button, element)
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
print("mousepressed", x, y, button, element)
return false
end
end
end
end
pop.mousereleased = function(button, x, y, element)
pop.mousereleased = function(x, y, button, element)
if element == nil then
element = pop.window
element = pop.screen
end
print("mousereleased", x, y, button, element)
return false
end
pop.keypressed = function(key)
return print("pop.keypressed() is unimplemented.")
print("keypressed", key)
return false
end
pop.keyreleased = function(key)
return print("pop.keyreleased() is unimplemented.")
print("keyreleased", key)
return false
end
pop.textinput = function(text)
return print("pop.textinput() is unimplemented.")
print("textinput", text)
return false
end
pop.skin = function(element, skin, apply_to_children)
if apply_to_children == nil then
apply_to_children = true
pop.skin = function(element, skin, depth)
if element == nil then
element = pop.screen
end
element.margin = skin.margin
if element.background then
if skin == nil then
skin = pop.skins.default
end
if element.background and skin.background then
element.background = skin.background
end
if element.color then
if element.color and skin.color then
element.color = skin.color
end
if element.font then
if element.font and skin.font then
element.font = skin.font
end
if apply_to_children then
if not (depth or (depth == 0)) then
if depth == tonumber(depth) then
for i = 1, #element.child do
pop.skin(element.child[i], skin)
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.window
element = pop.screen
end
if element.debugDraw then
element:debugDraw()
else
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.setColor(150, 150, 150, 150)
graphics.rectangle("line", element.x, element.y, element.w, element.h)

17
lib/pop/skins/default.lua Normal file
View 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)
}