2016-04-17 07:29:27 +00:00
|
|
|
local graphics, mouse
|
|
|
|
do
|
|
|
|
local _obj_0 = love
|
|
|
|
graphics, mouse = _obj_0.graphics, _obj_0.mouse
|
|
|
|
end
|
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
|
2016-03-30 21:01:15 +00:00
|
|
|
local sub, len
|
|
|
|
do
|
|
|
|
local _obj_0 = string
|
|
|
|
sub, len = _obj_0.sub, _obj_0.len
|
|
|
|
end
|
|
|
|
local path = sub(..., 1, len(...) - len("/window"))
|
|
|
|
local element = require(tostring(path) .. "/element")
|
|
|
|
local box = require(tostring(path) .. "/box")
|
|
|
|
local text = require(tostring(path) .. "/text")
|
2016-04-18 03:52:39 +00:00
|
|
|
local closeImage = graphics.newImage(tostring(path) .. "/img/close.png")
|
2016-04-02 03:45:43 +00:00
|
|
|
local left = 1
|
2016-04-02 06:31:05 +00:00
|
|
|
local mousemoved_event = true
|
2016-04-02 03:45:43 +00:00
|
|
|
do
|
|
|
|
local major, minor, revision = love.getVersion()
|
|
|
|
if (major == 0) and (minor == 10) and ((revision == 0) or (revision == 1)) then
|
|
|
|
left = 1
|
2016-04-03 07:22:49 +00:00
|
|
|
elseif (major == 0) and (minor == 9) then
|
2016-04-02 03:45:43 +00:00
|
|
|
left = "l"
|
|
|
|
if revision == 1 then
|
2016-04-02 06:31:05 +00:00
|
|
|
mousemoved_event = false
|
2016-04-02 03:45:43 +00:00
|
|
|
end
|
|
|
|
else
|
2016-04-17 06:58:17 +00:00
|
|
|
print("elements/window: unrecognized LOVE version: " .. tostring(major) .. "." .. tostring(minor) .. "." .. tostring(revision))
|
|
|
|
print(" assuming LOVE version > 0.10.1 (there may be bugs)")
|
2016-04-02 03:45:43 +00:00
|
|
|
end
|
|
|
|
end
|
2016-04-03 07:27:15 +00:00
|
|
|
local pop_ref = false
|
2016-03-30 21:01:15 +00:00
|
|
|
local window
|
|
|
|
do
|
|
|
|
local _class_0
|
|
|
|
local _parent_0 = element
|
|
|
|
local _base_0 = {
|
2016-04-03 07:27:15 +00:00
|
|
|
load = function(pop)
|
2016-04-03 06:33:18 +00:00
|
|
|
pop_ref = pop
|
|
|
|
end,
|
2016-03-30 21:01:15 +00:00
|
|
|
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, 200, 200)
|
|
|
|
graphics.rectangle("line", self.x, self.y, self.w, self.h)
|
|
|
|
graphics.setColor(255, 200, 255, 255)
|
|
|
|
graphics.print("w", self.x, self.y)
|
|
|
|
return self
|
|
|
|
end,
|
2016-04-03 19:11:27 +00:00
|
|
|
addChild = function(self, child)
|
2016-04-17 06:58:17 +00:00
|
|
|
self.window:addChild(child)
|
2016-04-03 19:11:27 +00:00
|
|
|
return self
|
|
|
|
end,
|
2016-04-17 06:58:17 +00:00
|
|
|
removeChild = function(self, child)
|
|
|
|
local result = self.window:removeChild(child)
|
|
|
|
if result == self.window then
|
|
|
|
return self
|
2016-04-18 03:37:55 +00:00
|
|
|
elseif type(result) == "string" then
|
|
|
|
for k, v in ipairs(self.child) do
|
|
|
|
if v == child then
|
|
|
|
remove(self.child, k)
|
|
|
|
return self
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return "Element \"" .. tostring(child) .. "\" is not a child of window \"" .. tostring(self) .. "\". Cannot remove it."
|
2016-04-17 06:58:17 +00:00
|
|
|
else
|
|
|
|
return result
|
|
|
|
end
|
|
|
|
end,
|
2016-04-03 19:11:27 +00:00
|
|
|
getChildren = function(self)
|
|
|
|
return self.window.child
|
|
|
|
end,
|
2016-04-04 19:47:02 +00:00
|
|
|
align = function(self, horizontal, vertical, toPixel)
|
|
|
|
_class_0.__parent.__base.align(self, horizontal, vertical, toPixel)
|
|
|
|
for i = 1, #self.child do
|
|
|
|
self.child[i]:align()
|
|
|
|
end
|
|
|
|
self.window:move(nil, self.head:getHeight())
|
|
|
|
return self
|
|
|
|
end,
|
2016-03-30 21:01:15 +00:00
|
|
|
setSize = function(self, w, h)
|
|
|
|
local x = 0
|
|
|
|
local y = 0
|
|
|
|
if w then
|
|
|
|
local _exp_0 = self.horizontal
|
|
|
|
if "center" == _exp_0 then
|
|
|
|
x = x - ((w - self.w) / 2)
|
|
|
|
elseif "right" == _exp_0 then
|
|
|
|
x = x - (w - self.w)
|
|
|
|
end
|
2016-04-18 03:37:55 +00:00
|
|
|
if self.close then
|
|
|
|
self.head:setWidth(w - self.head:getHeight())
|
|
|
|
else
|
|
|
|
self.head:setWidth(w)
|
|
|
|
end
|
2016-03-30 21:01:15 +00:00
|
|
|
self.window:setWidth(w)
|
|
|
|
self.w = w
|
|
|
|
self.x = self.x + x
|
2016-04-03 07:47:07 +00:00
|
|
|
self.title:align()
|
2016-04-18 03:37:55 +00:00
|
|
|
if self.close then
|
|
|
|
self.close:align()
|
|
|
|
end
|
2016-03-30 21:01:15 +00:00
|
|
|
end
|
|
|
|
if h then
|
|
|
|
h = h - self.head:getHeight()
|
|
|
|
local _exp_0 = self.vertical
|
|
|
|
if "center" == _exp_0 then
|
|
|
|
y = y - ((h - self.h) / 2)
|
|
|
|
elseif "right" == _exp_0 then
|
|
|
|
y = y - (h - self.h)
|
|
|
|
end
|
|
|
|
self.window:setHeight(h)
|
|
|
|
self.h = h + self.head:getHeight()
|
|
|
|
self.y = self.y + y
|
|
|
|
end
|
|
|
|
self.head:move(x, y)
|
|
|
|
self.window:move(x, y)
|
|
|
|
return self
|
|
|
|
end,
|
|
|
|
setWidth = function(self, w)
|
|
|
|
local x = 0
|
|
|
|
local _exp_0 = self.horizontal
|
|
|
|
if "center" == _exp_0 then
|
|
|
|
x = x - ((w - self.w) / 2)
|
|
|
|
elseif "right" == _exp_0 then
|
|
|
|
x = x - (w - self.w)
|
|
|
|
end
|
2016-04-18 03:37:55 +00:00
|
|
|
if self.close then
|
|
|
|
self.head:setWidth(w - self.head:getHeight())
|
|
|
|
else
|
|
|
|
self.head:setWidth(w)
|
|
|
|
end
|
2016-03-30 21:01:15 +00:00
|
|
|
self.window:setWidth(w)
|
|
|
|
self.w = w
|
|
|
|
self.x = self.x + x
|
2016-04-03 07:47:07 +00:00
|
|
|
self.title:align()
|
2016-04-18 03:37:55 +00:00
|
|
|
if self.close then
|
|
|
|
self.close:align()
|
|
|
|
end
|
2016-03-30 21:01:15 +00:00
|
|
|
self.head:move(x)
|
|
|
|
self.window:move(x)
|
|
|
|
return self
|
|
|
|
end,
|
|
|
|
setHeight = function(self, h)
|
|
|
|
local y = 0
|
|
|
|
h = h - self.head:getHeight()
|
|
|
|
local _exp_0 = self.vertical
|
|
|
|
if "center" == _exp_0 then
|
|
|
|
y = y - ((h - self.h) / 2)
|
|
|
|
elseif "right" == _exp_0 then
|
|
|
|
y = y - (h - self.h)
|
|
|
|
end
|
|
|
|
self.window:setHeight(h)
|
|
|
|
self.h = h + self.head:getHeight()
|
|
|
|
self.y = self.y + y
|
2016-04-03 07:47:07 +00:00
|
|
|
self.head:move(nil, y)
|
|
|
|
self.title:move(nil, y)
|
|
|
|
self.window:move(nil, y)
|
2016-03-30 21:01:15 +00:00
|
|
|
return self
|
2016-04-03 19:11:27 +00:00
|
|
|
end,
|
|
|
|
setTitle = function(self, title)
|
|
|
|
self.title:setText(title)
|
2016-04-18 03:37:55 +00:00
|
|
|
if self.titleOverflow == "trunicate" then
|
|
|
|
while self.title:getWidth() > self.head:getWidth() do
|
|
|
|
title = title:sub(1, -3)
|
|
|
|
self.title:setText(title .. "…")
|
|
|
|
end
|
|
|
|
elseif self.titleOverflow == "resize" then
|
|
|
|
if self.title:getWidth() > self.head:getWidth() then
|
|
|
|
self:setWidth(self.title:getWidth())
|
|
|
|
end
|
|
|
|
end
|
2016-04-03 19:11:27 +00:00
|
|
|
return self
|
2016-04-17 07:29:27 +00:00
|
|
|
end,
|
|
|
|
getTitle = function(self)
|
|
|
|
return self.title:getText()
|
2016-04-18 03:37:55 +00:00
|
|
|
end,
|
|
|
|
setTitleOverflow = function(self, method)
|
|
|
|
self.titleOverflow = method
|
|
|
|
return self
|
|
|
|
end,
|
|
|
|
getTitleOverflow = function(self)
|
|
|
|
return self.titleOverflow
|
|
|
|
end,
|
|
|
|
setClose = function(self, enabled)
|
|
|
|
if enabled then
|
|
|
|
self.close = box(self, closeImage)
|
2016-04-18 03:52:39 +00:00
|
|
|
self.close.clicked = function()
|
|
|
|
self:delete()
|
|
|
|
return true
|
|
|
|
end
|
2016-04-18 03:37:55 +00:00
|
|
|
local height = self.head:getHeight()
|
|
|
|
self.close:align("right"):setSize(height, height)
|
|
|
|
self.head:setWidth(self.w - height)
|
|
|
|
self.title:align()
|
|
|
|
insert(self.child, self.close)
|
|
|
|
else
|
|
|
|
self.close:delete()
|
|
|
|
self.head:setWidth(self.w)
|
|
|
|
self.title:align()
|
|
|
|
self.close = false
|
|
|
|
end
|
|
|
|
return self
|
|
|
|
end,
|
|
|
|
hasClose = function(self)
|
|
|
|
if self.close then
|
|
|
|
return true
|
|
|
|
else
|
|
|
|
return false
|
|
|
|
end
|
2016-03-30 21:01:15 +00:00
|
|
|
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, title, tBackground, tColor, wBackground)
|
2016-03-30 21:01:15 +00:00
|
|
|
if title == nil then
|
|
|
|
title = "window"
|
|
|
|
end
|
|
|
|
if tBackground == nil then
|
|
|
|
tBackground = {
|
|
|
|
25,
|
|
|
|
180,
|
|
|
|
230,
|
|
|
|
255
|
|
|
|
}
|
|
|
|
end
|
2016-04-02 03:45:43 +00:00
|
|
|
if tColor == nil then
|
|
|
|
tColor = {
|
|
|
|
255,
|
|
|
|
255,
|
|
|
|
255,
|
|
|
|
255
|
|
|
|
}
|
|
|
|
end
|
|
|
|
if wBackground == nil then
|
|
|
|
wBackground = {
|
|
|
|
200,
|
|
|
|
200,
|
|
|
|
210,
|
|
|
|
255
|
|
|
|
}
|
|
|
|
end
|
2016-04-03 06:33:18 +00:00
|
|
|
_class_0.__parent.__init(self, parent)
|
2016-03-30 21:01:15 +00:00
|
|
|
self.head = box(self, tBackground)
|
2016-04-18 03:52:39 +00:00
|
|
|
self.title = text(self.head, title, tColor)
|
2016-04-02 03:45:43 +00:00
|
|
|
self.window = box(self, wBackground)
|
2016-04-18 03:37:55 +00:00
|
|
|
self.close = box(self, closeImage)
|
2016-03-30 21:01:15 +00:00
|
|
|
local height = self.title:getHeight()
|
2016-04-18 03:37:55 +00:00
|
|
|
self.head:setSize(self.w - height, height)
|
2016-03-30 21:01:15 +00:00
|
|
|
self.window:move(nil, height)
|
2016-04-18 03:37:55 +00:00
|
|
|
self.close:align("right"):setSize(height, height)
|
2016-03-30 21:01:15 +00:00
|
|
|
self:setSize(100, 80)
|
|
|
|
self.child = {
|
|
|
|
self.head,
|
|
|
|
self.title,
|
2016-04-18 03:37:55 +00:00
|
|
|
self.window,
|
|
|
|
self.close
|
2016-03-30 21:01:15 +00:00
|
|
|
}
|
2016-04-18 03:37:55 +00:00
|
|
|
self.titleOverflow = "trunicate"
|
2016-04-18 04:57:32 +00:00
|
|
|
self.window.mousepressed = function()
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
self.window.clicked = function()
|
|
|
|
return true
|
|
|
|
end
|
2016-04-18 03:37:55 +00:00
|
|
|
self.close.clicked = function()
|
|
|
|
self:delete()
|
|
|
|
return true
|
|
|
|
end
|
2016-04-02 06:31:05 +00:00
|
|
|
self.head.selected = false
|
|
|
|
if mousemoved_event then
|
|
|
|
self.head.mousemoved = function(self, x, y, dx, dy)
|
|
|
|
if self.selected then
|
2016-04-17 08:27:06 +00:00
|
|
|
self.parent:move(dx, dy)
|
2016-04-02 06:31:05 +00:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
self.head.mousepressed = function(self, x, y, button)
|
|
|
|
if button == left then
|
|
|
|
self.selected = true
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
else
|
|
|
|
self.head.mx = 0
|
|
|
|
self.head.my = 0
|
|
|
|
self.head.update = function(self)
|
2016-04-17 07:29:27 +00:00
|
|
|
local x, y = mouse.getPosition()
|
|
|
|
return self:setPosition(x - mx, y - my)
|
2016-04-02 06:31:05 +00:00
|
|
|
end
|
|
|
|
self.head.mousepressed = function(self, x, y, button)
|
|
|
|
if button == left then
|
|
|
|
self.selected = true
|
|
|
|
self.mx = x
|
|
|
|
self.my = y
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
2016-04-17 07:29:27 +00:00
|
|
|
self.head.mousereleased = function(self, x, y, button)
|
|
|
|
if button == left then
|
|
|
|
self.selected = false
|
|
|
|
pop_ref.focused = false
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
2016-03-30 21:01:15 +00:00
|
|
|
end,
|
|
|
|
__base = _base_0,
|
|
|
|
__name = "window",
|
|
|
|
__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
|
|
|
|
if _parent_0.__inherited then
|
|
|
|
_parent_0.__inherited(_parent_0, _class_0)
|
|
|
|
end
|
|
|
|
window = _class_0
|
|
|
|
return _class_0
|
|
|
|
end
|