SFML community forums

Help => Window => Topic started by: tymofey on September 11, 2011, 09:38:08 am

Title: Event::MouseWheelEvent::Delta bug
Post by: tymofey on September 11, 2011, 09:38:08 am
Under windows/sfml2 i enountered a problem where  Event::MouseWheelEvent::Delta is almost allways zero, you need to scroll the wheel REALLY fast to obtain some other sensible value. After taking a look at the ProcessEvent function in /src/SFML/Window/Win32/WindowImplWin32.cpp, i found this:
Code: [Select]

        // Mouse wheel event
        case WM_MOUSEWHEEL :
        {
            // Mouse position is in screen coordinates, convert it to window coordinates
            POINT position;
            position.x = static_cast<Int16>(LOWORD(lParam));
            position.y = static_cast<Int16>(HIWORD(lParam));
            ScreenToClient(myHandle, &position);

            Event event;
            event.Type = Event::MouseWheelMoved;
            event.MouseWheel.Delta = static_cast<Int16>(HIWORD(wParam)) / 120;
            event.MouseButton.X    = position.x;
            event.MouseButton.Y    = position.y;
            PushEvent(event);
            break;
        }


Now, after carefully reading http://msdn.microsoft.com/en-us/library/ms645617(v=vs.85).aspx, the following was noticed:
Quote
The high-order word indicates the distance the wheel is rotated, expressed in multiples or divisions of WHEEL_DELTA, which is 120.

so it becomes appearent that
Code: [Select]
event.MouseWheel.Delta = static_cast<Int16>(HIWORD(wParam)) / 120;
sets Delta to zero whenever the absolute value of HIWORD(wParam) is less than 120, which happens to be quite often.

After taking a look at the Linux implementation:
Code: [Select]
event.MouseWheel.Delta = windowEvent.xbutton.button == Button4 ? 1 : -1; which can return only 1 or -1 i believe the windows one should be changed to something like
Code: [Select]
event.MouseWheel.Delta = static_cast<Int16>(HIWORD(wParam)) > 0 ? 1 : -1;
as well, or make Delta a float to allow fractional values.
Title: Event::MouseWheelEvent::Delta bug
Post by: Laurent on September 11, 2011, 10:39:31 am
Thanks, I've created a new issue in the task tracker:
https://github.com/SFML/SFML/issues/95