From 5b5823eeb59625f213957a105bf0cb65620e1dcd Mon Sep 17 00:00:00 2001 From: Edward Rudd Date: Sun, 23 Nov 2014 21:09:54 -0500 Subject: [PATCH] add in support for passing down the "natural" (or flipped) scrolling direction in the MouseWheelEvent event --- include/SDL_events.h | 1 + include/SDL_mouse.h | 9 +++++++++ src/core/linux/SDL_evdev.c | 4 ++-- src/events/SDL_mouse.c | 3 ++- src/events/SDL_mouse_c.h | 2 +- src/main/haiku/SDL_BApp.h | 2 +- src/video/cocoa/SDL_cocoamouse.m | 9 ++++++++- src/video/mir/SDL_mirevents.c | 2 +- src/video/nacl/SDL_naclevents.c | 2 +- src/video/wayland/SDL_waylandevents.c | 2 +- src/video/windows/SDL_windowsevents.c | 8 ++++---- src/video/winrt/SDL_winrtpointerinput.cpp | 2 +- src/video/x11/SDL_x11events.c | 2 +- 13 files changed, 33 insertions(+), 15 deletions(-) diff --git a/include/SDL_events.h b/include/SDL_events.h index f5136424e18f6..09ab9c2f2a562 100644 --- a/include/SDL_events.h +++ b/include/SDL_events.h @@ -260,6 +260,7 @@ typedef struct SDL_MouseWheelEvent Uint32 which; /**< The mouse instance id, or SDL_TOUCH_MOUSEID */ Sint32 x; /**< The amount scrolled horizontally, positive to the right and negative to the left */ Sint32 y; /**< The amount scrolled vertically, positive away from the user and negative toward the user */ + Uint32 direction; /**< Set to one of the SDL_MOUSEWHEEL_* defines. When FLIPPED the values in X and Y will be opposite. Multiply by -1 to change them back */ } SDL_MouseWheelEvent; /** diff --git a/include/SDL_mouse.h b/include/SDL_mouse.h index e71a0c9e5bd31..dd084279055d5 100644 --- a/include/SDL_mouse.h +++ b/include/SDL_mouse.h @@ -60,6 +60,15 @@ typedef enum SDL_NUM_SYSTEM_CURSORS } SDL_SystemCursor; +/** + * \brief Scroll direction types for the Scroll event + */ +typedef enum +{ + SDL_MOUSEWHEEL_NORMAL, /**< The scroll direction is normal */ + SDL_MOUSEWHEEL_FLIPPED /**< The scroll direction is flipped / natural */ +} SDL_MouseWheelDirection; + /* Function prototypes */ /** diff --git a/src/core/linux/SDL_evdev.c b/src/core/linux/SDL_evdev.c index c4a7d05ce2fd3..1f4c31657e484 100644 --- a/src/core/linux/SDL_evdev.c +++ b/src/core/linux/SDL_evdev.c @@ -681,10 +681,10 @@ SDL_EVDEV_Poll(void) SDL_SendMouseMotion(mouse->focus, mouse->mouseID, SDL_TRUE, 0, events[i].value); break; case REL_WHEEL: - SDL_SendMouseWheel(mouse->focus, mouse->mouseID, 0, events[i].value); + SDL_SendMouseWheel(mouse->focus, mouse->mouseID, 0, events[i].value, SDL_MOUSEWHEEL_NORMAL); break; case REL_HWHEEL: - SDL_SendMouseWheel(mouse->focus, mouse->mouseID, events[i].value, 0); + SDL_SendMouseWheel(mouse->focus, mouse->mouseID, events[i].value, 0, SDL_MOUSEWHEEL_NORMAL); break; default: break; diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c index 21fb87771c512..32eb0f902adb8 100644 --- a/src/events/SDL_mouse.c +++ b/src/events/SDL_mouse.c @@ -397,7 +397,7 @@ SDL_SendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8 } int -SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, int x, int y) +SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, int x, int y, SDL_MouseWheelDirection direction) { SDL_Mouse *mouse = SDL_GetMouse(); int posted; @@ -419,6 +419,7 @@ SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, int x, int y) event.wheel.which = mouseID; event.wheel.x = x; event.wheel.y = y; + event.wheel.direction = (Uint32)direction; posted = (SDL_PushEvent(&event) > 0); } return posted; diff --git a/src/events/SDL_mouse_c.h b/src/events/SDL_mouse_c.h index df95e1e526c83..56c061a56abc2 100644 --- a/src/events/SDL_mouse_c.h +++ b/src/events/SDL_mouse_c.h @@ -120,7 +120,7 @@ extern int SDL_SendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int rel extern int SDL_SendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8 button); /* Send a mouse wheel event */ -extern int SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, int x, int y); +extern int SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, int x, int y, SDL_MouseWheelDirection direction); /* Shutdown the mouse subsystem */ extern void SDL_MouseQuit(void); diff --git a/src/main/haiku/SDL_BApp.h b/src/main/haiku/SDL_BApp.h index 1e4a0f5501b4b..9eece54406d44 100644 --- a/src/main/haiku/SDL_BApp.h +++ b/src/main/haiku/SDL_BApp.h @@ -254,7 +254,7 @@ class SDL_BApp : public BApplication { return; } win = GetSDLWindow(winID); - SDL_SendMouseWheel(win, 0, xTicks, yTicks); + SDL_SendMouseWheel(win, 0, xTicks, yTicks, SDL_MOUSEWHEEL_NORMAL); } void _HandleKey(BMessage *msg) { diff --git a/src/video/cocoa/SDL_cocoamouse.m b/src/video/cocoa/SDL_cocoamouse.m index 8b933c27ddecb..c5d60f78d0c7d 100644 --- a/src/video/cocoa/SDL_cocoamouse.m +++ b/src/video/cocoa/SDL_cocoamouse.m @@ -399,6 +399,13 @@ + (NSCursor *)invisibleCursor float x = -[event deltaX]; float y = [event deltaY]; + SDL_MouseWheelDirection direction = SDL_MOUSEWHEEL_NORMAL; + + if ([event respondsToSelector:@selector(isDirectionInvertedFromDevice)]) { + if ([event isDirectionInvertedFromDevice] == YES) { + direction = SDL_MOUSEWHEEL_FLIPPED; + } + } if (x > 0) { x += 0.9f; @@ -410,7 +417,7 @@ + (NSCursor *)invisibleCursor } else if (y < 0) { y -= 0.9f; } - SDL_SendMouseWheel(window, mouse->mouseID, (int)x, (int)y); + SDL_SendMouseWheel(window, mouse->mouseID, (int)x, (int)y, direction); } void diff --git a/src/video/mir/SDL_mirevents.c b/src/video/mir/SDL_mirevents.c index b5829c7c792a8..76870d5a42edc 100644 --- a/src/video/mir/SDL_mirevents.c +++ b/src/video/mir/SDL_mirevents.c @@ -137,7 +137,7 @@ HandleTouchMotion(int device_id, int source_id, float x, float y, float pressure static void HandleMouseScroll(SDL_Window* sdl_window, int hscroll, int vscroll) { - SDL_SendMouseWheel(sdl_window, 0, hscroll, vscroll); + SDL_SendMouseWheel(sdl_window, 0, hscroll, vscroll, SDL_MOUSEWHEEL_NORMAL); } static void diff --git a/src/video/nacl/SDL_naclevents.c b/src/video/nacl/SDL_naclevents.c index 5a4449a49429d..3204a6b1dca8a 100644 --- a/src/video/nacl/SDL_naclevents.c +++ b/src/video/nacl/SDL_naclevents.c @@ -357,7 +357,7 @@ void NACL_PumpEvents(_THIS) { case PP_INPUTEVENT_TYPE_WHEEL: /* FIXME: GetTicks provides high resolution scroll events */ fp = driverdata->ppb_wheel_input_event->GetDelta(event); - SDL_SendMouseWheel(mouse->focus, mouse->mouseID, (int) fp.x, (int) fp.y); + SDL_SendMouseWheel(mouse->focus, mouse->mouseID, (int) fp.x, (int) fp.y, SDL_MOUSEWHEEL_NORMAL); break; case PP_INPUTEVENT_TYPE_MOUSEENTER: diff --git a/src/video/wayland/SDL_waylandevents.c b/src/video/wayland/SDL_waylandevents.c index cb729001e861c..e3c9782f6e581 100644 --- a/src/video/wayland/SDL_waylandevents.c +++ b/src/video/wayland/SDL_waylandevents.c @@ -184,7 +184,7 @@ pointer_handle_axis(void *data, struct wl_pointer *pointer, return; } - SDL_SendMouseWheel(window->sdlwindow, 0, x, y); + SDL_SendMouseWheel(window->sdlwindow, 0, x, y, SDL_MOUSEWHEEL_NORMAL); } } diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c index 28801d2fc34ba..9f2eff3f70dcf 100644 --- a/src/video/windows/SDL_windowsevents.c +++ b/src/video/windows/SDL_windowsevents.c @@ -498,12 +498,12 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) s_AccumulatedMotion += GET_WHEEL_DELTA_WPARAM(wParam); if (s_AccumulatedMotion > 0) { while (s_AccumulatedMotion >= WHEEL_DELTA) { - SDL_SendMouseWheel(data->window, 0, 0, 1); + SDL_SendMouseWheel(data->window, 0, 0, 1, SDL_MOUSEWHEEL_NORMAL); s_AccumulatedMotion -= WHEEL_DELTA; } } else { while (s_AccumulatedMotion <= -WHEEL_DELTA) { - SDL_SendMouseWheel(data->window, 0, 0, -1); + SDL_SendMouseWheel(data->window, 0, 0, -1, SDL_MOUSEWHEEL_NORMAL); s_AccumulatedMotion += WHEEL_DELTA; } } @@ -517,12 +517,12 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) s_AccumulatedMotion += GET_WHEEL_DELTA_WPARAM(wParam); if (s_AccumulatedMotion > 0) { while (s_AccumulatedMotion >= WHEEL_DELTA) { - SDL_SendMouseWheel(data->window, 0, 1, 0); + SDL_SendMouseWheel(data->window, 0, 1, 0, SDL_MOUSEWHEEL_NORMAL); s_AccumulatedMotion -= WHEEL_DELTA; } } else { while (s_AccumulatedMotion <= -WHEEL_DELTA) { - SDL_SendMouseWheel(data->window, 0, -1, 0); + SDL_SendMouseWheel(data->window, 0, -1, 0, SDL_MOUSEWHEEL_NORMAL); s_AccumulatedMotion += WHEEL_DELTA; } } diff --git a/src/video/winrt/SDL_winrtpointerinput.cpp b/src/video/winrt/SDL_winrtpointerinput.cpp index b811cb0089a07..da20cc3c9a16c 100644 --- a/src/video/winrt/SDL_winrtpointerinput.cpp +++ b/src/video/winrt/SDL_winrtpointerinput.cpp @@ -315,7 +315,7 @@ WINRT_ProcessPointerWheelChangedEvent(SDL_Window *window, Windows::UI::Input::Po // FIXME: This may need to accumulate deltas up to WHEEL_DELTA short motion = pointerPoint->Properties->MouseWheelDelta / WHEEL_DELTA; - SDL_SendMouseWheel(window, 0, 0, motion); + SDL_SendMouseWheel(window, 0, 0, motion, SDL_MOUSEWHEEL_NORMAL); } void diff --git a/src/video/x11/SDL_x11events.c b/src/video/x11/SDL_x11events.c index 0703447b03449..645c7741d3d13 100644 --- a/src/video/x11/SDL_x11events.c +++ b/src/video/x11/SDL_x11events.c @@ -990,7 +990,7 @@ X11_DispatchEvent(_THIS) case ButtonPress:{ int ticks = 0; if (X11_IsWheelEvent(display,&xevent,&ticks)) { - SDL_SendMouseWheel(data->window, 0, 0, ticks); + SDL_SendMouseWheel(data->window, 0, 0, ticks, SDL_MOUSEWHEEL_NORMAL); } else { if(xevent.xbutton.button == Button1) { if (ProcessHitTest(_this, data, &xevent)) {