Fixed accumulating mouse wheel motion for the Microsoft Wireless Mouse 5000
authorSam Lantinga <slouken@libsdl.org>
Sun, 13 Oct 2013 19:59:40 -0700
changeset 7813 d8fb783475d5
parent 7812 c50a384be081
child 7814 5a057d8d685e
Fixed accumulating mouse wheel motion for the Microsoft Wireless Mouse 5000
src/video/windows/SDL_windowsevents.c
--- a/src/video/windows/SDL_windowsevents.c	Sun Oct 13 19:51:58 2013 -0700
+++ b/src/video/windows/SDL_windowsevents.c	Sun Oct 13 19:59:40 2013 -0700
@@ -466,10 +466,20 @@
 
     case WM_MOUSEWHEEL:
         {
-            /* FIXME: This may need to accumulate deltas up to WHEEL_DELTA */
-            short motion = GET_WHEEL_DELTA_WPARAM(wParam) / WHEEL_DELTA;
+            static short s_AccumulatedMotion;
 
-            SDL_SendMouseWheel(data->window, 0, 0, motion);
+            s_AccumulatedMotion += GET_WHEEL_DELTA_WPARAM(wParam);
+            if (s_AccumulatedMotion > 0) {
+                while (s_AccumulatedMotion >= WHEEL_DELTA) {
+                    SDL_SendMouseWheel(data->window, 0, 0, 1);
+                    s_AccumulatedMotion -= WHEEL_DELTA;
+                }
+            } else {
+                while (s_AccumulatedMotion <= -WHEEL_DELTA) {
+                    SDL_SendMouseWheel(data->window, 0, 0, -1);
+                    s_AccumulatedMotion += WHEEL_DELTA;
+                }
+            }
             break;
         }