add in support for passing down the "natural" (or flipped) scrolling direction in the MouseWheelEvent event
authorEdward Rudd <urkle@outoforder.cc>
Sun, 23 Nov 2014 21:09:54 -0500
changeset 92576f41196c2d6b
parent 9256 9c45fc8605d9
child 9258 95c3682d0b95
add in support for passing down the "natural" (or flipped) scrolling direction in the MouseWheelEvent event
include/SDL_events.h
include/SDL_mouse.h
src/core/linux/SDL_evdev.c
src/events/SDL_mouse.c
src/events/SDL_mouse_c.h
src/main/haiku/SDL_BApp.h
src/video/cocoa/SDL_cocoamouse.m
src/video/mir/SDL_mirevents.c
src/video/nacl/SDL_naclevents.c
src/video/wayland/SDL_waylandevents.c
src/video/windows/SDL_windowsevents.c
src/video/winrt/SDL_winrtpointerinput.cpp
src/video/x11/SDL_x11events.c
     1.1 --- a/include/SDL_events.h	Wed Dec 03 10:55:23 2014 -0500
     1.2 +++ b/include/SDL_events.h	Sun Nov 23 21:09:54 2014 -0500
     1.3 @@ -260,6 +260,7 @@
     1.4      Uint32 which;       /**< The mouse instance id, or SDL_TOUCH_MOUSEID */
     1.5      Sint32 x;           /**< The amount scrolled horizontally, positive to the right and negative to the left */
     1.6      Sint32 y;           /**< The amount scrolled vertically, positive away from the user and negative toward the user */
     1.7 +    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 */
     1.8  } SDL_MouseWheelEvent;
     1.9  
    1.10  /**
     2.1 --- a/include/SDL_mouse.h	Wed Dec 03 10:55:23 2014 -0500
     2.2 +++ b/include/SDL_mouse.h	Sun Nov 23 21:09:54 2014 -0500
     2.3 @@ -60,6 +60,15 @@
     2.4      SDL_NUM_SYSTEM_CURSORS
     2.5  } SDL_SystemCursor;
     2.6  
     2.7 +/**
     2.8 + * \brief Scroll direction types for the Scroll event
     2.9 + */
    2.10 +typedef enum
    2.11 +{
    2.12 +    SDL_MOUSEWHEEL_NORMAL,    /**< The scroll direction is normal */
    2.13 +    SDL_MOUSEWHEEL_FLIPPED    /**< The scroll direction is flipped / natural */
    2.14 +} SDL_MouseWheelDirection;
    2.15 +
    2.16  /* Function prototypes */
    2.17  
    2.18  /**
     3.1 --- a/src/core/linux/SDL_evdev.c	Wed Dec 03 10:55:23 2014 -0500
     3.2 +++ b/src/core/linux/SDL_evdev.c	Sun Nov 23 21:09:54 2014 -0500
     3.3 @@ -681,10 +681,10 @@
     3.4                          SDL_SendMouseMotion(mouse->focus, mouse->mouseID, SDL_TRUE, 0, events[i].value);
     3.5                          break;
     3.6                      case REL_WHEEL:
     3.7 -                        SDL_SendMouseWheel(mouse->focus, mouse->mouseID, 0, events[i].value);
     3.8 +                        SDL_SendMouseWheel(mouse->focus, mouse->mouseID, 0, events[i].value, SDL_MOUSEWHEEL_NORMAL);
     3.9                          break;
    3.10                      case REL_HWHEEL:
    3.11 -                        SDL_SendMouseWheel(mouse->focus, mouse->mouseID, events[i].value, 0);
    3.12 +                        SDL_SendMouseWheel(mouse->focus, mouse->mouseID, events[i].value, 0, SDL_MOUSEWHEEL_NORMAL);
    3.13                          break;
    3.14                      default:
    3.15                          break;
     4.1 --- a/src/events/SDL_mouse.c	Wed Dec 03 10:55:23 2014 -0500
     4.2 +++ b/src/events/SDL_mouse.c	Sun Nov 23 21:09:54 2014 -0500
     4.3 @@ -397,7 +397,7 @@
     4.4  }
     4.5  
     4.6  int
     4.7 -SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, int x, int y)
     4.8 +SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, int x, int y, SDL_MouseWheelDirection direction)
     4.9  {
    4.10      SDL_Mouse *mouse = SDL_GetMouse();
    4.11      int posted;
    4.12 @@ -419,6 +419,7 @@
    4.13          event.wheel.which = mouseID;
    4.14          event.wheel.x = x;
    4.15          event.wheel.y = y;
    4.16 +        event.wheel.direction = (Uint32)direction;
    4.17          posted = (SDL_PushEvent(&event) > 0);
    4.18      }
    4.19      return posted;
     5.1 --- a/src/events/SDL_mouse_c.h	Wed Dec 03 10:55:23 2014 -0500
     5.2 +++ b/src/events/SDL_mouse_c.h	Sun Nov 23 21:09:54 2014 -0500
     5.3 @@ -120,7 +120,7 @@
     5.4  extern int SDL_SendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8 button);
     5.5  
     5.6  /* Send a mouse wheel event */
     5.7 -extern int SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, int x, int y);
     5.8 +extern int SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, int x, int y, SDL_MouseWheelDirection direction);
     5.9  
    5.10  /* Shutdown the mouse subsystem */
    5.11  extern void SDL_MouseQuit(void);
     6.1 --- a/src/main/haiku/SDL_BApp.h	Wed Dec 03 10:55:23 2014 -0500
     6.2 +++ b/src/main/haiku/SDL_BApp.h	Sun Nov 23 21:09:54 2014 -0500
     6.3 @@ -254,7 +254,7 @@
     6.4              return;
     6.5          }
     6.6          win = GetSDLWindow(winID);
     6.7 -        SDL_SendMouseWheel(win, 0, xTicks, yTicks);
     6.8 +        SDL_SendMouseWheel(win, 0, xTicks, yTicks, SDL_MOUSEWHEEL_NORMAL);
     6.9      }
    6.10  
    6.11      void _HandleKey(BMessage *msg) {
     7.1 --- a/src/video/cocoa/SDL_cocoamouse.m	Wed Dec 03 10:55:23 2014 -0500
     7.2 +++ b/src/video/cocoa/SDL_cocoamouse.m	Sun Nov 23 21:09:54 2014 -0500
     7.3 @@ -399,6 +399,13 @@
     7.4  
     7.5      float x = -[event deltaX];
     7.6      float y = [event deltaY];
     7.7 +    SDL_MouseWheelDirection direction = SDL_MOUSEWHEEL_NORMAL;
     7.8 +
     7.9 +    if ([event respondsToSelector:@selector(isDirectionInvertedFromDevice)]) {
    7.10 +        if ([event isDirectionInvertedFromDevice] == YES) {
    7.11 +            direction = SDL_MOUSEWHEEL_FLIPPED;
    7.12 +        }
    7.13 +    }
    7.14  
    7.15      if (x > 0) {
    7.16          x += 0.9f;
    7.17 @@ -410,7 +417,7 @@
    7.18      } else if (y < 0) {
    7.19          y -= 0.9f;
    7.20      }
    7.21 -    SDL_SendMouseWheel(window, mouse->mouseID, (int)x, (int)y);
    7.22 +    SDL_SendMouseWheel(window, mouse->mouseID, (int)x, (int)y, direction);
    7.23  }
    7.24  
    7.25  void
     8.1 --- a/src/video/mir/SDL_mirevents.c	Wed Dec 03 10:55:23 2014 -0500
     8.2 +++ b/src/video/mir/SDL_mirevents.c	Sun Nov 23 21:09:54 2014 -0500
     8.3 @@ -137,7 +137,7 @@
     8.4  static void
     8.5  HandleMouseScroll(SDL_Window* sdl_window, int hscroll, int vscroll)
     8.6  {
     8.7 -    SDL_SendMouseWheel(sdl_window, 0, hscroll, vscroll);
     8.8 +    SDL_SendMouseWheel(sdl_window, 0, hscroll, vscroll, SDL_MOUSEWHEEL_NORMAL);
     8.9  }
    8.10  
    8.11  static void
     9.1 --- a/src/video/nacl/SDL_naclevents.c	Wed Dec 03 10:55:23 2014 -0500
     9.2 +++ b/src/video/nacl/SDL_naclevents.c	Sun Nov 23 21:09:54 2014 -0500
     9.3 @@ -357,7 +357,7 @@
     9.4                      case PP_INPUTEVENT_TYPE_WHEEL:
     9.5                          /* FIXME: GetTicks provides high resolution scroll events */
     9.6                          fp = driverdata->ppb_wheel_input_event->GetDelta(event);
     9.7 -                        SDL_SendMouseWheel(mouse->focus, mouse->mouseID, (int) fp.x, (int) fp.y);
     9.8 +                        SDL_SendMouseWheel(mouse->focus, mouse->mouseID, (int) fp.x, (int) fp.y, SDL_MOUSEWHEEL_NORMAL);
     9.9                          break;
    9.10                          
    9.11                      case PP_INPUTEVENT_TYPE_MOUSEENTER:
    10.1 --- a/src/video/wayland/SDL_waylandevents.c	Wed Dec 03 10:55:23 2014 -0500
    10.2 +++ b/src/video/wayland/SDL_waylandevents.c	Sun Nov 23 21:09:54 2014 -0500
    10.3 @@ -184,7 +184,7 @@
    10.4                  return;
    10.5          }
    10.6  
    10.7 -        SDL_SendMouseWheel(window->sdlwindow, 0, x, y);
    10.8 +        SDL_SendMouseWheel(window->sdlwindow, 0, x, y, SDL_MOUSEWHEEL_NORMAL);
    10.9      }
   10.10  }
   10.11  
    11.1 --- a/src/video/windows/SDL_windowsevents.c	Wed Dec 03 10:55:23 2014 -0500
    11.2 +++ b/src/video/windows/SDL_windowsevents.c	Sun Nov 23 21:09:54 2014 -0500
    11.3 @@ -498,12 +498,12 @@
    11.4              s_AccumulatedMotion += GET_WHEEL_DELTA_WPARAM(wParam);
    11.5              if (s_AccumulatedMotion > 0) {
    11.6                  while (s_AccumulatedMotion >= WHEEL_DELTA) {
    11.7 -                    SDL_SendMouseWheel(data->window, 0, 0, 1);
    11.8 +                    SDL_SendMouseWheel(data->window, 0, 0, 1, SDL_MOUSEWHEEL_NORMAL);
    11.9                      s_AccumulatedMotion -= WHEEL_DELTA;
   11.10                  }
   11.11              } else {
   11.12                  while (s_AccumulatedMotion <= -WHEEL_DELTA) {
   11.13 -                    SDL_SendMouseWheel(data->window, 0, 0, -1);
   11.14 +                    SDL_SendMouseWheel(data->window, 0, 0, -1, SDL_MOUSEWHEEL_NORMAL);
   11.15                      s_AccumulatedMotion += WHEEL_DELTA;
   11.16                  }
   11.17              }
   11.18 @@ -517,12 +517,12 @@
   11.19              s_AccumulatedMotion += GET_WHEEL_DELTA_WPARAM(wParam);
   11.20              if (s_AccumulatedMotion > 0) {
   11.21                  while (s_AccumulatedMotion >= WHEEL_DELTA) {
   11.22 -                    SDL_SendMouseWheel(data->window, 0, 1, 0);
   11.23 +                    SDL_SendMouseWheel(data->window, 0, 1, 0, SDL_MOUSEWHEEL_NORMAL);
   11.24                      s_AccumulatedMotion -= WHEEL_DELTA;
   11.25                  }
   11.26              } else {
   11.27                  while (s_AccumulatedMotion <= -WHEEL_DELTA) {
   11.28 -                    SDL_SendMouseWheel(data->window, 0, -1, 0);
   11.29 +                    SDL_SendMouseWheel(data->window, 0, -1, 0, SDL_MOUSEWHEEL_NORMAL);
   11.30                      s_AccumulatedMotion += WHEEL_DELTA;
   11.31                  }
   11.32              }
    12.1 --- a/src/video/winrt/SDL_winrtpointerinput.cpp	Wed Dec 03 10:55:23 2014 -0500
    12.2 +++ b/src/video/winrt/SDL_winrtpointerinput.cpp	Sun Nov 23 21:09:54 2014 -0500
    12.3 @@ -315,7 +315,7 @@
    12.4  
    12.5      // FIXME: This may need to accumulate deltas up to WHEEL_DELTA
    12.6      short motion = pointerPoint->Properties->MouseWheelDelta / WHEEL_DELTA;
    12.7 -    SDL_SendMouseWheel(window, 0, 0, motion);
    12.8 +    SDL_SendMouseWheel(window, 0, 0, motion, SDL_MOUSEWHEEL_NORMAL);
    12.9  }
   12.10  
   12.11  void
    13.1 --- a/src/video/x11/SDL_x11events.c	Wed Dec 03 10:55:23 2014 -0500
    13.2 +++ b/src/video/x11/SDL_x11events.c	Sun Nov 23 21:09:54 2014 -0500
    13.3 @@ -990,7 +990,7 @@
    13.4      case ButtonPress:{
    13.5              int ticks = 0;
    13.6              if (X11_IsWheelEvent(display,&xevent,&ticks)) {
    13.7 -                SDL_SendMouseWheel(data->window, 0, 0, ticks);
    13.8 +                SDL_SendMouseWheel(data->window, 0, 0, ticks, SDL_MOUSEWHEEL_NORMAL);
    13.9              } else {
   13.10                  if(xevent.xbutton.button == Button1) {
   13.11                      if (ProcessHitTest(_this, data, &xevent)) {