2016-02-25 00:25:54 +00:00
|
|
|
local graphics
|
|
|
|
graphics = love.graphics
|
2016-03-29 01:00:17 +00:00
|
|
|
local floor
|
|
|
|
floor = math.floor
|
2016-04-17 06:58:17 +00:00
|
|
|
local insert, remove
|
|
|
|
do
|
|
|
|
local _obj_0 = table
|
|
|
|
insert, remove = _obj_0.insert, _obj_0.remove
|
|
|
|
end
|
|
|
|
local tonumber = tonumber
|
2016-02-25 00:25:54 +00:00
|
|
|
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,
|
2016-04-01 01:59:16 +00:00
|
|
|
addChild = function(self, child)
|
2016-04-17 06:58:17 +00:00
|
|
|
if child.parent then
|
|
|
|
child.parent:removeChild(child)
|
|
|
|
end
|
|
|
|
insert(self.child, child)
|
2016-04-01 01:59:16 +00:00
|
|
|
child.parent = self
|
|
|
|
return self
|
|
|
|
end,
|
2016-04-17 06:58:17 +00:00
|
|
|
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
|
|
|
|
remove(self.child, k)
|
|
|
|
return self
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return error("Element \"" .. tostring(child) .. "\" is not a child of element \"" .. tostring(self) .. "\". Cannot remove it.")
|
|
|
|
end
|
|
|
|
end,
|
2016-04-03 19:11:27 +00:00
|
|
|
getChildren = function(self)
|
|
|
|
return self.child
|
|
|
|
end,
|
2016-02-25 00:25:54 +00:00
|
|
|
move = function(self, x, y)
|
2016-03-29 01:00:17 +00:00
|
|
|
if x then
|
|
|
|
self.x = self.x + x
|
|
|
|
end
|
|
|
|
if y then
|
|
|
|
self.y = self.y + y
|
|
|
|
end
|
2016-02-25 00:25:54 +00:00
|
|
|
for i = 1, #self.child do
|
2016-03-29 01:00:17 +00:00
|
|
|
if not (self.child[i].excludeMovement) then
|
2016-02-25 00:25:54 +00:00
|
|
|
self.child[i]:move(x, y)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return self
|
|
|
|
end,
|
|
|
|
setPosition = function(self, x, y)
|
|
|
|
local oldX = self.x
|
|
|
|
local oldY = self.y
|
2016-03-29 01:00:17 +00:00
|
|
|
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
|
2016-02-25 00:25:54 +00:00
|
|
|
end
|
2016-03-29 01:00:17 +00:00
|
|
|
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
|
2016-02-25 00:25:54 +00:00
|
|
|
end
|
|
|
|
for i = 1, #self.child do
|
2016-04-17 06:58:17 +00:00
|
|
|
self.child[i]:move(x - oldX, y - oldY)
|
2016-02-25 00:25:54 +00:00
|
|
|
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
|
2016-03-29 01:00:17 +00:00
|
|
|
resultY = resultY + self.w
|
2016-02-25 00:25:54 +00:00
|
|
|
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,
|
2016-03-30 21:01:15 +00:00
|
|
|
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,
|
2016-02-25 00:25:54 +00:00
|
|
|
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,
|
2016-03-29 01:00:17 +00:00
|
|
|
align = function(self, horizontal, vertical, toPixel)
|
2016-04-17 06:58:17 +00:00
|
|
|
if toPixel == nil then
|
|
|
|
toPixel = true
|
|
|
|
end
|
2016-02-25 00:25:54 +00:00
|
|
|
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.margin
|
|
|
|
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.margin)
|
|
|
|
end
|
|
|
|
local _exp_1 = self.vertical
|
|
|
|
if "top" == _exp_1 then
|
|
|
|
self.y = self.y + self.margin
|
|
|
|
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.margin)
|
|
|
|
end
|
2016-04-17 06:58:17 +00:00
|
|
|
if toPixel then
|
2016-03-29 01:00:17 +00:00
|
|
|
self.x = floor(self.x)
|
|
|
|
self.y = floor(self.y)
|
|
|
|
end
|
2016-02-25 00:25:54 +00:00
|
|
|
return self
|
|
|
|
end,
|
2016-04-17 06:58:17 +00:00
|
|
|
alignTo = function(self, element, horizontal, vertical, toPixel)
|
|
|
|
if toPixel == nil then
|
|
|
|
toPixel = true
|
|
|
|
end
|
2016-03-29 01:00:17 +00:00
|
|
|
local parent = self.parent
|
2016-02-25 00:25:54 +00:00
|
|
|
self.parent = element
|
2016-04-17 06:58:17 +00:00
|
|
|
self:align(horizontal, vertical, toPixel)
|
2016-03-29 01:00:17 +00:00
|
|
|
self.parent = parent
|
2016-02-25 00:25:54 +00:00
|
|
|
return self
|
|
|
|
end,
|
|
|
|
setAlignment = function(self, horizontal, vertical)
|
|
|
|
if horizontal then
|
|
|
|
self.horizontal = horizontal
|
|
|
|
end
|
|
|
|
if vertical then
|
|
|
|
self.vertical = vertical
|
|
|
|
end
|
|
|
|
return self
|
2016-03-29 01:00:17 +00:00
|
|
|
end,
|
2016-04-03 07:47:07 +00:00
|
|
|
getAlignment = function(self)
|
|
|
|
return self.horizontal, self.vertical
|
|
|
|
end,
|
2016-03-29 01:00:17 +00:00
|
|
|
setMargin = function(self, margin)
|
|
|
|
self.margin = margin
|
|
|
|
self:align()
|
|
|
|
return self
|
|
|
|
end,
|
|
|
|
getMargin = function(self)
|
|
|
|
return self.margin
|
2016-04-02 03:45:43 +00:00
|
|
|
end,
|
|
|
|
fill = function(self)
|
|
|
|
self.x = self.parent.x + self.margin
|
|
|
|
self.y = self.parent.y + self.margin
|
|
|
|
self.w = self.parent.w - self.margin * 2
|
|
|
|
self.h = self.parent.h - self.margin * 2
|
2016-04-17 07:40:48 +00:00
|
|
|
end,
|
|
|
|
delete = function(self)
|
|
|
|
for k, v in ipairs(self.child) do
|
|
|
|
v:delete()
|
|
|
|
end
|
|
|
|
return self.parent:removeChild(self)
|
2016-02-25 00:25:54 +00:00
|
|
|
end
|
|
|
|
}
|
|
|
|
_base_0.__index = _base_0
|
|
|
|
_class_0 = setmetatable({
|
2016-04-03 06:33:18 +00:00
|
|
|
__init = function(self, parent)
|
2016-02-25 00:25:54 +00:00
|
|
|
self.parent = parent
|
|
|
|
self.child = { }
|
2016-03-30 21:38:46 +00:00
|
|
|
self.w = 0
|
|
|
|
self.h = 0
|
|
|
|
self.margin = 0
|
2016-03-29 01:00:17 +00:00
|
|
|
if parent then
|
2016-03-30 21:38:46 +00:00
|
|
|
self.x = parent.x
|
|
|
|
self.y = parent.y
|
2016-03-29 01:00:17 +00:00
|
|
|
else
|
|
|
|
self.x = 0
|
|
|
|
self.y = 0
|
|
|
|
end
|
2016-02-25 00:25:54 +00:00
|
|
|
self.horizontal = "left"
|
|
|
|
self.vertical = "top"
|
|
|
|
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
|