cc-utilities/gfx/event.lua
2024-10-08 16:59:32 +02:00

27 lines
636 B
Lua

local Event = {}
function Event.isClickEvent(evt)
return evt[1] == "monitor_touch" or evt[1] == "mouse_click"
end
function Event.getClickParams(evt)
return evt[3], evt[4], evt[2]
end
function Event.repositionEvent(evt, dX, dY)
if Event.isClickEvent(evt) then
return evt[1], evt[2], evt[3] + dX, evt[4] + dY
else
return evt
end
end
function Event.containsClick(element, evt, dX, dY)
local x, y = Event.getClickParams(evt)
x = x + (dX or 0)
y = y + (dY or 0)
local eX, eY = element:getPos()
return x >= eX and x < (eX + element:getWidth()) and y >= eY and y < (eY + element:getHeight())
end
return Event