garden/window.lua
2025-01-01 15:14:01 +09:00

46 lines
1.1 KiB
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)
for _, tname in ipairs(tnames) do
for i, v in pairs(self[tname]) do
local x, y = x - v.x, y - v.y
if 0 <= x and x <= v.width and 0 <= y and y <= v.height then
v:mousepressed(x, y, button)
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