39 lines
934 B
Lua
39 lines
934 B
Lua
local Event = {}
|
|
|
|
function Event.isKeyEvent(evt, key)
|
|
return evt[1] == "key" and (key == nil or evt[2] == key)
|
|
end
|
|
|
|
function Event.getKeyParams(evt)
|
|
return evt[2], evt[3]
|
|
end
|
|
|
|
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.toElementLocalPosition(evt, element)
|
|
return {Event.repositionEvent(evt, 1 - element:getX(), 1 - element:getY())}
|
|
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 |