changeset 2152:003c1b5b07da

Fixed bug #382 Added horizontal scrolling support
author Sam Lantinga <slouken@libsdl.org>
date Fri, 06 Jul 2007 09:22:18 +0000
parents 1e0692271600
children 760c1bd2d625
files include/SDL_compat.h include/SDL_events.h src/SDL_compat.c src/events/SDL_mouse.c src/events/SDL_mouse_c.h src/video/cocoa/SDL_cocoawindow.m src/video/win32/SDL_win32events.c
diffstat 7 files changed, 41 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/include/SDL_compat.h	Thu Jul 05 06:35:40 2007 +0000
+++ b/include/SDL_compat.h	Fri Jul 06 09:22:18 2007 +0000
@@ -63,6 +63,8 @@
 
 #define SDL_BUTTON_WHEELUP	4
 #define SDL_BUTTON_WHEELDOWN	5
+#define SDL_BUTTON_WHEELLEFT	6
+#define SDL_BUTTON_WHEELRIGHT	7
 
 #define SDL_DEFAULT_REPEAT_DELAY	500
 #define SDL_DEFAULT_REPEAT_INTERVAL	30
--- a/include/SDL_events.h	Thu Jul 05 06:35:40 2007 +0000
+++ b/include/SDL_events.h	Fri Jul 06 09:22:18 2007 +0000
@@ -199,7 +199,8 @@
 {
     Uint8 type;             /**< SDL_MOUSEWHEEL */
     Uint8 which;            /**< The mouse device index */
-    int motion;             /**< The direction and distance scrolled */
+    int x;                  /**< The amount scrolled horizontally */
+    int y;                  /**< The amount scrolled vertically */
     SDL_WindowID windowID;  /**< The window with mouse focus, if any */
 } SDL_MouseWheelEvent;
 
--- a/src/SDL_compat.c	Thu Jul 05 06:35:40 2007 +0000
+++ b/src/SDL_compat.c	Fri Jul 06 09:22:18 2007 +0000
@@ -256,25 +256,42 @@
             SDL_GetMouseState(&x, &y);
             SDL_SelectMouse(selected);
 
-            if (event->wheel.motion > 0) {
-                button = SDL_BUTTON_WHEELUP;
-            } else {
-                button = SDL_BUTTON_WHEELDOWN;
-            }
-
             fake.button.which = event->wheel.windowID;
-            fake.button.button = button;
             fake.button.x = x;
             fake.button.y = y;
             fake.button.windowID = event->wheel.windowID;
 
-            fake.type = SDL_MOUSEBUTTONDOWN;
-            fake.button.state = SDL_PRESSED;
-            SDL_PushEvent(&fake);
+            if (event->wheel.y) {
+                if (event->wheel.y > 0) {
+                    fake.button.button = SDL_BUTTON_WHEELUP;
+                } else {
+                    fake.button.button = SDL_BUTTON_WHEELDOWN;
+                }
+
+                fake.type = SDL_MOUSEBUTTONDOWN;
+                fake.button.state = SDL_PRESSED;
+                SDL_PushEvent(&fake);
 
-            fake.type = SDL_MOUSEBUTTONUP;
-            fake.button.state = SDL_RELEASED;
-            SDL_PushEvent(&fake);
+                fake.type = SDL_MOUSEBUTTONUP;
+                fake.button.state = SDL_RELEASED;
+                SDL_PushEvent(&fake);
+            }
+            if (event->wheel.x) {
+                if (event->wheel.y > 0) {
+                    fake.button.button = SDL_BUTTON_WHEELLEFT;
+                } else {
+                    fake.button.button = SDL_BUTTON_WHEELRIGHT;
+                }
+
+                fake.type = SDL_MOUSEBUTTONDOWN;
+                fake.button.state = SDL_PRESSED;
+                SDL_PushEvent(&fake);
+
+                fake.type = SDL_MOUSEBUTTONUP;
+                fake.button.state = SDL_RELEASED;
+                SDL_PushEvent(&fake);
+            }
+
             break;
         }
 
--- a/src/events/SDL_mouse.c	Thu Jul 05 06:35:40 2007 +0000
+++ b/src/events/SDL_mouse.c	Fri Jul 06 09:22:18 2007 +0000
@@ -427,12 +427,12 @@
 }
 
 int
-SDL_SendMouseWheel(int index, int motion)
+SDL_SendMouseWheel(int index, int x, int y)
 {
     SDL_Mouse *mouse = SDL_GetMouse(index);
     int posted;
 
-    if (!mouse || !motion) {
+    if (!mouse || (!x && !y)) {
         return 0;
     }
 
@@ -442,7 +442,8 @@
         SDL_Event event;
         event.type = SDL_MOUSEWHEEL;
         event.wheel.which = (Uint8) index;
-        event.wheel.motion = motion;
+        event.wheel.x = x;
+        event.wheel.y = y;
         event.wheel.windowID = mouse->focus;
         posted = (SDL_PushEvent(&event) > 0);
     }
--- a/src/events/SDL_mouse_c.h	Thu Jul 05 06:35:40 2007 +0000
+++ b/src/events/SDL_mouse_c.h	Fri Jul 06 09:22:18 2007 +0000
@@ -102,7 +102,7 @@
 extern int SDL_SendMouseButton(int index, Uint8 state, Uint8 button);
 
 /* Send a mouse wheel event for a mouse at an index */
-extern int SDL_SendMouseWheel(int index, int motion);
+extern int SDL_SendMouseWheel(int index, int x, int y);
 
 /* Shutdown the mouse subsystem */
 extern void SDL_MouseQuit(void);
--- a/src/video/cocoa/SDL_cocoawindow.m	Thu Jul 05 06:35:40 2007 +0000
+++ b/src/video/cocoa/SDL_cocoawindow.m	Fri Jul 06 09:22:18 2007 +0000
@@ -274,7 +274,7 @@
     int index;
 
     index = _data->videodata->mouse;
-    SDL_SendMouseWheel(index, (int)([theEvent deltaY]+0.9f));
+    SDL_SendMouseWheel(index, (int)([theEvent deltaX]+0.9f), (int)([theEvent deltaY]+0.9f));
 }
 
 @end
--- a/src/video/win32/SDL_win32events.c	Thu Jul 05 06:35:40 2007 +0000
+++ b/src/video/win32/SDL_win32events.c	Fri Jul 06 09:22:18 2007 +0000
@@ -645,7 +645,7 @@
             int motion = (short) HIWORD(wParam);
 
             index = data->videodata->mouse;
-            SDL_SendMouseWheel(index, motion);
+            SDL_SendMouseWheel(index, 0, motion);
         }
         return (0);