Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Event::MouseWheelEvent::Delta bug  (Read 1909 times)

0 Members and 1 Guest are viewing this topic.

tymofey

  • Newbie
  • *
  • Posts: 7
    • View Profile
Event::MouseWheelEvent::Delta bug
« 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32502
    • View Profile
    • SFML's website
    • Email
Event::MouseWheelEvent::Delta bug
« Reply #1 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
Laurent Gomila - SFML developer