Notes
- This function provides DIP (device independent pixels) coordinates.
Canvas:onHover(x, y, buttons) event
This event is fired when the user moves the mouse pointer over the Canvas.
Parameters
x
The horizontal position of the mouse in the Canvas area.
y
The vertical position of the mouse in the Canvas area.
buttons
A table
which fields indicates if mouse buttons or special keys have been pressed during the move :
"left"
: true
if left mouse button is pressed, false
otherwise"right"
: true
if right mouse button is pressed, false
otherwise"middle"
: true
if middle mouse button is pressed, false
otherwise"control"
: true
if the CONTROL key is pressed, false
otherwise"shift"
: true
if the SHIFT mouse button is pressed, false
otherwiseReturn value
The event returns no value.Example
local ui = require "ui"
require "canvas"
-- create a fixed Window
local win = ui.Window("Canvas:onLeave() event sample", "fixed", 320, 200)
win:status("")
-- create a Canvas
local canvas = ui.Canvas(win, 0, 0, 100, 100)
canvas.cursor = "cross"
canvas.bgcolor = 0xFFA0A0FF
canvas:center()
function canvas:onHover(x, y, buttons)
local btn = ""
if buttons.left then btn = btn.." left" end
if buttons.right then btn = btn.." right" end
if buttons.middle then btn = btn.." middle" end
if buttons.shift then btn = btn.." shift" end
win:status("x : "..math.floor(x), "y : "..math.floor(y), "buttons : "..(btn == "" and "none" or btn))
end
ui.run(win):wait()