send zDelta to miniwindow scrollwheel handler callback

Posted by Fiendish on Sun 05 May 2019 12:02 AM — 7 posts, 27,350 views.

USA Global Moderator #0
Right now wheel callbacks get only a boolean flag field indicating whether the wheel was spun up or down. I propose sending the full zDelta-derived number of lines value (as used for scrolling the main output) in addition. Native interface elements scroll differently for fast and slow spins, but miniwindows can't.
Amended on Sun 05 May 2019 12:05 AM by Fiendish
Australia Forum Administrator #1
OK, I added the delta to the high-order 16 bits of the flags (for minimum compatibility disruption) however in my testing the delta amount was always 120.

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
Amended on Sun 05 May 2019 10:02 PM by Nick Gammon
USA Global Moderator #2
Quote:
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:

Quote:

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.
Amended on Sun 05 May 2019 10:23 PM by Fiendish
Australia Forum Administrator #3

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.

Australia Forum Administrator #4
Looks like my second theory is correct. You are getting better results than I did. :)
USA Global Moderator #5
In macOS+Wine it appears to work, though I'm technically using a touchpad and not using a mouse. That may have something to do with it.
Amended on Sun 05 May 2019 10:27 PM by Fiendish
USA Global Moderator #6
Somewhat humorously, using this wheel handler results in much more touchpad-friendly output scrolling than the default, I guess because it doesn't lock to whole line increments which are more difficult to hit without wheel clicks.


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