SFML community forums

General => General discussions => Topic started by: nwp on December 28, 2013, 11:26:56 pm

Title: Bugreport: Scrollwheel does not work properly under Windows
Post by: nwp on December 28, 2013, 11:26:56 pm
Somehow I did not find the bug report subforum, sorry for that.

Under Windows the translation from WM_MOUSEWHEEL to sf::Event::MouseWheelMoved in SFML/Window/Win32/WindowImplWin32.cpp:603 is wrong for SFML 2.1. The WM_MOUSEWHEEL goes in WHEEL_DELTA units, which is 120. The line says
Quote
event.mouseWheel.delta = static_cast<Int16>(HIWORD(wParam)) / 120;
The Windows documentation states
Quote
The delta was set to 120 to allow Microsoft or other vendors to build finer-resolution wheels (a freely-rotating wheel with no notches) to send more messages per rotation, but with a smaller value in each message.
I have one of those mice (mouses?). If I scroll 1 notch, HIWORD(wParam) will be 112. It is then rounded down to 0 when it is divided by 120. Consequently in SFML I get lots of sf::Event::MouseWheelMoved with event.mouseWheel.delta equaling 0. When scrolling very fast so Windows reports scrolldistances bigger than 112 it sort of works.
Quick workaround:
Change the offending line to
Quote
event.mouseWheel.delta = static_cast<Int16>((HIWORD(wParam)) + 60) / 120;
That way at least the scrolling sort of works.
Real solution:
Change the type of event.mouseWheel.delta to float and the line to
Quote
event.mouseWheel.delta = (HIWORD(wParam)) / 120.f;

For extra style points change the magic number 120 to the Windows defined macro WHEEL_DELTA.

PS: How come the forum supports marquee and glow text, but no C++-code tags?

Edit: My recommended quick workaround only works for scrolling up, which is insufficient. New workaround:
event.mouseWheel.delta = (static_cast<Int16>(HIWORD(wParam)) * 3 / 2) / WHEEL_DELTA;
But its still a bad hack.
Title: Re: Bugreport: Scrollwheel does not work properly under Windows
Post by: eXpl0it3r on December 28, 2013, 11:39:07 pm
PS: How come the forum supports marquee and glow text, but no C++-code tags?
There is, you just shouldn't look for a button, but instead use the drop down menu on the right side or simply write [ code=cpp ]My Code[ /code ]. ;)

Which mouse of yours has such issues?
Title: Re: Bugreport: Scrollwheel does not work properly under Windows
Post by: nwp on December 28, 2013, 11:49:43 pm
Hmm, somehow I missed the Code dropdown thingie.

Which mouse of yours has such issues?
It says Microsoft Wireless Mobile Mouse 1000 Model 1452 on the back. I do not think this is a mouse issue though, its just a disagreement between windows and SFML how mousewheels work.
Title: Re: Bugreport: Scrollwheel does not work properly under Windows
Post by: eXpl0it3r on December 29, 2013, 12:46:02 am
Looks like this is already a known issue: #95 (https://github.com/SFML/SFML/issues/95)

I do not think this is a mouse issue though, its just a disagreement between windows and SFML how mousewheels work.
Yeah just wanted to get some model, so if anyone has a similar mouse, they could test it as well.
Title: Re: Bugreport: Scrollwheel does not work properly under Windows
Post by: Mario on December 29, 2013, 02:41:52 pm
Seems to work fine with my Logitech G700 on the latest master, no matter whether the wheel notches are enabled or not I always get at least -1 or +1.