43 lines
972 B
Lua
43 lines
972 B
Lua
-- function generator for window functions
|
|
|
|
local w = {}
|
|
|
|
function w.draw(f)
|
|
return function(self)
|
|
love.graphics.push()
|
|
love.graphics.translate(self.x, self.y)
|
|
f(self)
|
|
love.graphics.pop()
|
|
end
|
|
end
|
|
|
|
function w.mousepressed(f)
|
|
return function(self, x, y, button)
|
|
local x, y = x - self.x, y - self.y
|
|
|
|
if 0 <= x and x <= self.width and 0 <= y and y <= self.height then
|
|
f(self, x, y, button)
|
|
end
|
|
end
|
|
end
|
|
|
|
function w.propagate(tnames)
|
|
return function(self, x, y, button)
|
|
local x, y = x - self.x, y - self.y
|
|
|
|
for _, tname in ipairs(tnames) do
|
|
for i, v in pairs(self[tname]) do
|
|
v:mousepressed(x, y, button)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
function w.draw_border(width, height)
|
|
love.graphics.push('all')
|
|
love.graphics.setLineWidth(5)
|
|
love.graphics.rectangle('line', 0, 0, width, height, 5)
|
|
love.graphics.pop()
|
|
end
|
|
|
|
return w
|