send zDelta to miniwindow scrollwheel handler callback
Posted by Fiendish on Sun 05 May 2019 12:02 AM — 7 posts, 27,350 views.
The delta is unsigned, so you still have to test the flag. Example code:
win = "test_" .. GetPluginID () -- get a unique name, ensure not empty if outside plugin
WindowCreate (win, 0, 0, 200, 200, miniwin.pos_center_all, 0, ColourNameToRGB("white")) -- create window
WindowShow (win, true) -- show it
WindowAddHotspot(win, "hs1",
10, 10, 100, 100, -- rectangle
"", -- mouseover
"", -- cancelmouseover
"", -- mousedown
"", -- cancelmousedown
"", -- mouseup
"Tooltip message", -- tooltip text
miniwin.cursor_hand, 0) -- hand cursor
function mousewheelhandler (flags, hotspotid)
local delta = bit.shr (flags, 16)
if bit.band (flags, miniwin.wheel_scroll_back) ~= 0 then
print (delta, "backwards")
else
print (delta, "forwards")
end -- if
end -- mousewheelhandler
WindowRectOp (win, miniwin.rect_frame, 10, 10, 100, 100, ColourNameToRGB("blue"))
WindowScrollwheelHandler(win, "hs1", "mousewheelhandler")
https://github.com/nickgammon/mushclient/commit/d2f7129
in my testing the delta amount was always 120
So how does the main body scroll with different velocities?
I just tested, and I'm getting something like:
6
42
78
1170
1674
1188
3138
2604
2220
2562
2100
1284
1044
846
666
510
144
366
282
216
288
96
30
90
54
36
24
6
12
6
6
So it appears to work.
Are you sure it does? If you scroll faster you get more “pulses”. Thus the window scrolls faster. Like, a bike speedometer measures the number of times the wheel turns, and the more pulses a second the faster it must be turning. However the interaction between the magnet and the sensor is binary, it doesn’t recall the time taken for the wheel to send one pulse. You recall the time by measuring the time between pulses.
Having said that, though, I am using Windows XP running under VirtualBox in Ubuntu. Maybe you will get different results with other versions of Windows, or if it is run natively.
It seems odd for Windows to return a number (delta) if it is always the same.
function ScrollMain(flags, hotspot_id)
local delta = bit.shr(flags, 16)
if bit.band (flags, miniwin.wheel_scroll_back) ~= 0 then
direction = 1 -- wheel scrolled down
else
direction = -1 -- wheel scrolled up
end
SetScroll(GetInfo(296) + delta*direction, GetInfo(120))
end