2016-02-25 00:25:54 +00:00
|
|
|
local graphics
|
|
|
|
graphics = love.graphics
|
|
|
|
local sub, len
|
|
|
|
do
|
|
|
|
local _obj_0 = string
|
|
|
|
sub, len = _obj_0.sub, _obj_0.len
|
|
|
|
end
|
2016-03-29 01:00:17 +00:00
|
|
|
local path = sub(..., 1, len(...) - len("/box"))
|
2016-02-25 00:25:54 +00:00
|
|
|
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)
|
2016-04-04 19:47:02 +00:00
|
|
|
graphics.print(self.txt, self.x, self.y)
|
2016-02-25 00:25:54 +00:00
|
|
|
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)
|
2016-04-04 19:47:02 +00:00
|
|
|
local w = self.font:getWidth(self.txt)
|
|
|
|
local h = self.font:getHeight() * (select(2, self.txt:gsub("\n", "\n")) + 1)
|
2016-02-25 00:25:54 +00:00
|
|
|
local _exp_0 = self.horizontal
|
|
|
|
if "center" == _exp_0 then
|
|
|
|
self.x = self.x - ((w - self.w) / 2)
|
|
|
|
elseif "right" == _exp_0 then
|
2016-04-27 19:03:24 +00:00
|
|
|
self.x = self.x - (w - self.w - self.spacing)
|
2016-02-25 00:25:54 +00:00
|
|
|
end
|
|
|
|
local _exp_1 = self.vertical
|
|
|
|
if "center" == _exp_1 then
|
|
|
|
self.y = self.y - ((h - self.h) / 2)
|
2016-03-29 01:00:17 +00:00
|
|
|
elseif "bottom" == _exp_1 then
|
2016-04-27 19:03:24 +00:00
|
|
|
self.y = self.y - (h - self.h - self.spacing)
|
2016-02-25 00:25:54 +00:00
|
|
|
end
|
|
|
|
self.w = w
|
|
|
|
self.h = h
|
|
|
|
return self
|
|
|
|
end,
|
2016-03-30 21:01:15 +00:00
|
|
|
setWidth = function(self)
|
|
|
|
self:setSize()
|
|
|
|
return self
|
|
|
|
end,
|
|
|
|
setHeight = function(self)
|
|
|
|
self:setSize()
|
|
|
|
return self
|
|
|
|
end,
|
2016-02-25 00:25:54 +00:00
|
|
|
setText = function(self, text)
|
|
|
|
if text == nil then
|
|
|
|
text = ""
|
|
|
|
end
|
2016-04-04 19:47:02 +00:00
|
|
|
self.txt = text
|
2016-02-25 00:25:54 +00:00
|
|
|
self:setSize()
|
|
|
|
return self
|
|
|
|
end,
|
|
|
|
getText = function(self)
|
2016-04-04 19:47:02 +00:00
|
|
|
return self.txt
|
2016-02-25 00:25:54 +00:00
|
|
|
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
|
2016-03-29 01:00:17 +00:00
|
|
|
if type(r) == "table" then
|
|
|
|
self.color = r
|
|
|
|
else
|
|
|
|
self.color = {
|
|
|
|
r,
|
|
|
|
g,
|
|
|
|
b,
|
|
|
|
a
|
|
|
|
}
|
|
|
|
end
|
2016-02-25 00:25:54 +00:00
|
|
|
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({
|
2016-04-03 06:33:18 +00:00
|
|
|
__init = function(self, parent, text, color)
|
2016-02-25 00:25:54 +00:00
|
|
|
if text == nil then
|
|
|
|
text = ""
|
|
|
|
end
|
|
|
|
if color == nil then
|
|
|
|
color = {
|
|
|
|
255,
|
|
|
|
255,
|
|
|
|
255,
|
|
|
|
255
|
|
|
|
}
|
|
|
|
end
|
2016-04-03 06:33:18 +00:00
|
|
|
_class_0.__parent.__init(self, parent)
|
2016-02-25 00:25:54 +00:00
|
|
|
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
|
2016-04-04 19:47:02 +00:00
|
|
|
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
|
2016-02-25 00:25:54 +00:00
|
|
|
if _parent_0.__inherited then
|
|
|
|
_parent_0.__inherited(_parent_0, _class_0)
|
|
|
|
end
|
|
|
|
text = _class_0
|
|
|
|
return _class_0
|
|
|
|
end
|