From 0b869de08df37c50dff44ccb73aaa9542f9a98ad Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 6 Jul 2007 09:22:18 +0000 Subject: [PATCH] Fixed bug #382 Added horizontal scrolling support --- include/SDL_compat.h | 2 ++ include/SDL_events.h | 3 ++- src/SDL_compat.c | 43 +++++++++++++++++++++---------- src/events/SDL_mouse.c | 7 ++--- src/events/SDL_mouse_c.h | 2 +- src/video/cocoa/SDL_cocoawindow.m | 2 +- src/video/win32/SDL_win32events.c | 2 +- 7 files changed, 41 insertions(+), 20 deletions(-) diff --git a/include/SDL_compat.h b/include/SDL_compat.h index bac3ca225..2ee673b79 100644 --- a/include/SDL_compat.h +++ b/include/SDL_compat.h @@ -63,6 +63,8 @@ extern "C" { #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 diff --git a/include/SDL_events.h b/include/SDL_events.h index ae6612e9d..f06a8ba3b 100644 --- a/include/SDL_events.h +++ b/include/SDL_events.h @@ -199,7 +199,8 @@ typedef struct SDL_MouseWheelEvent { 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; diff --git a/src/SDL_compat.c b/src/SDL_compat.c index 937e9e104..83838d205 100644 --- a/src/SDL_compat.c +++ b/src/SDL_compat.c @@ -256,25 +256,42 @@ SDL_CompatEventFilter(void *userdata, SDL_Event * event) 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); + } + 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); + } - fake.type = SDL_MOUSEBUTTONUP; - fake.button.state = SDL_RELEASED; - SDL_PushEvent(&fake); break; } diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c index c66e80ecb..b2579dc0f 100644 --- a/src/events/SDL_mouse.c +++ b/src/events/SDL_mouse.c @@ -427,12 +427,12 @@ SDL_SendMouseButton(int index, Uint8 state, Uint8 button) } 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_SendMouseWheel(int index, int motion) 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); } diff --git a/src/events/SDL_mouse_c.h b/src/events/SDL_mouse_c.h index 4bc60835f..530e38106 100644 --- a/src/events/SDL_mouse_c.h +++ b/src/events/SDL_mouse_c.h @@ -102,7 +102,7 @@ extern int SDL_SendMouseMotion(int index, int relative, int x, int y); 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); diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m index e8034e630..30e94240e 100644 --- a/src/video/cocoa/SDL_cocoawindow.m +++ b/src/video/cocoa/SDL_cocoawindow.m @@ -274,7 +274,7 @@ - (void)scrollWheel:(NSEvent *)theEvent 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 diff --git a/src/video/win32/SDL_win32events.c b/src/video/win32/SDL_win32events.c index 05d32fbdd..948dd1a65 100644 --- a/src/video/win32/SDL_win32events.c +++ b/src/video/win32/SDL_win32events.c @@ -645,7 +645,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) int motion = (short) HIWORD(wParam); index = data->videodata->mouse; - SDL_SendMouseWheel(index, motion); + SDL_SendMouseWheel(index, 0, motion); } return (0);