Canvas:onMouseWheel(delta, buttons) event
This event is fired when the user rotates the mouse wheel while beeing over the Canvas.
Parameters
delta
A number
that indicates the distance the wheel is rotated, expressed in multiples or divisions of 120
.
A positive value indicates that the wheel was rotated forward, away from the user, a negative value indicates that the wheel was rotated backward, toward the user.
buttons
A table
which fields indicates if mouse buttons or special keys have been pressed during the mouse up event :
"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
otherwise
Return value
The event returns no value.Example
local ui = require "ui"
require "canvas"
local win = ui.Window("Canvas - onMouseWheel event example", "fixed", 320, 240)
local c = ui.Canvas(win)
c.align = "all"
local width = c.width/2
local height = c.height/2
local scale = 1
function c:onMouseWheel(delta)
scale = scale + 0.05*delta/120
end
function c:onPaint()
self:begin()
self:clear()
c:identity()
c:scale(scale, scale)
c:fillrect(width-35, height-35, width+35, height+35, 0xA569BDFF)
self:flip()
end
ui.run(win):wait()