2022-08-23 17:44:16 +01:00
|
|
|
-- Simple immediate-mode buttons with (currently) just an onpress1 handler for
|
|
|
|
-- the left button.
|
|
|
|
-- If the handler returns true, it'll prevent any further processing of the
|
|
|
|
-- event.
|
2022-05-18 07:18:56 +01:00
|
|
|
|
2022-05-18 07:24:46 +01:00
|
|
|
Button_handlers = {}
|
2022-05-11 05:17:50 +01:00
|
|
|
|
|
|
|
-- draw button and queue up event handlers
|
|
|
|
function button(name, params)
|
|
|
|
love.graphics.setColor(params.color[1], params.color[2], params.color[3])
|
|
|
|
love.graphics.rectangle('fill', params.x,params.y, params.w,params.h, 5,5)
|
|
|
|
if params.icon then params.icon(params.x, params.y) end
|
2022-05-18 07:24:46 +01:00
|
|
|
table.insert(Button_handlers, params)
|
2022-05-11 05:17:50 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- process button event handlers
|
2022-05-18 07:18:56 +01:00
|
|
|
function propagate_to_button_handlers(x, y, mouse_button)
|
2022-05-18 07:24:46 +01:00
|
|
|
for _,ev in ipairs(Button_handlers) do
|
2022-05-11 05:17:50 +01:00
|
|
|
if x>ev.x and x<ev.x+ev.w and y>ev.y and y<ev.y+ev.h then
|
2022-08-23 17:37:38 +01:00
|
|
|
if ev.onpress1 and mouse_button == 1 then
|
2022-08-23 17:40:48 +01:00
|
|
|
return ev.onpress1()
|
2022-08-23 17:37:38 +01:00
|
|
|
end
|
2022-05-11 05:17:50 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|