49 lines
1.1 KiB
Lua
49 lines
1.1 KiB
Lua
local util = require('util')
|
|
-- 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)
|
|
return true
|
|
end
|
|
|
|
return false
|
|
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 util.ipairs_rev(self[tname]) do
|
|
if v:mousepressed(x, y, button) then
|
|
return
|
|
end
|
|
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
|