Fixed bug #382
authorSam Lantinga <slouken@libsdl.org>
Fri, 06 Jul 2007 09:22:18 +0000
changeset 2152003c1b5b07da
parent 2151 1e0692271600
child 2153 760c1bd2d625
Fixed bug #382

Added horizontal scrolling support
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
     1.1 --- a/include/SDL_compat.h	Thu Jul 05 06:35:40 2007 +0000
     1.2 +++ b/include/SDL_compat.h	Fri Jul 06 09:22:18 2007 +0000
     1.3 @@ -63,6 +63,8 @@
     1.4  
     1.5  #define SDL_BUTTON_WHEELUP	4
     1.6  #define SDL_BUTTON_WHEELDOWN	5
     1.7 +#define SDL_BUTTON_WHEELLEFT	6
     1.8 +#define SDL_BUTTON_WHEELRIGHT	7
     1.9  
    1.10  #define SDL_DEFAULT_REPEAT_DELAY	500
    1.11  #define SDL_DEFAULT_REPEAT_INTERVAL	30
     2.1 --- a/include/SDL_events.h	Thu Jul 05 06:35:40 2007 +0000
     2.2 +++ b/include/SDL_events.h	Fri Jul 06 09:22:18 2007 +0000
     2.3 @@ -199,7 +199,8 @@
     2.4  {
     2.5      Uint8 type;             /**< SDL_MOUSEWHEEL */
     2.6      Uint8 which;            /**< The mouse device index */
     2.7 -    int motion;             /**< The direction and distance scrolled */
     2.8 +    int x;                  /**< The amount scrolled horizontally */
     2.9 +    int y;                  /**< The amount scrolled vertically */
    2.10      SDL_WindowID windowID;  /**< The window with mouse focus, if any */
    2.11  } SDL_MouseWheelEvent;
    2.12  
     3.1 --- a/src/SDL_compat.c	Thu Jul 05 06:35:40 2007 +0000
     3.2 +++ b/src/SDL_compat.c	Fri Jul 06 09:22:18 2007 +0000
     3.3 @@ -256,25 +256,42 @@
     3.4              SDL_GetMouseState(&x, &y);
     3.5              SDL_SelectMouse(selected);
     3.6  
     3.7 -            if (event->wheel.motion > 0) {
     3.8 -                button = SDL_BUTTON_WHEELUP;
     3.9 -            } else {
    3.10 -                button = SDL_BUTTON_WHEELDOWN;
    3.11 -            }
    3.12 -
    3.13              fake.button.which = event->wheel.windowID;
    3.14 -            fake.button.button = button;
    3.15              fake.button.x = x;
    3.16              fake.button.y = y;
    3.17              fake.button.windowID = event->wheel.windowID;
    3.18  
    3.19 -            fake.type = SDL_MOUSEBUTTONDOWN;
    3.20 -            fake.button.state = SDL_PRESSED;
    3.21 -            SDL_PushEvent(&fake);
    3.22 +            if (event->wheel.y) {
    3.23 +                if (event->wheel.y > 0) {
    3.24 +                    fake.button.button = SDL_BUTTON_WHEELUP;
    3.25 +                } else {
    3.26 +                    fake.button.button = SDL_BUTTON_WHEELDOWN;
    3.27 +                }
    3.28  
    3.29 -            fake.type = SDL_MOUSEBUTTONUP;
    3.30 -            fake.button.state = SDL_RELEASED;
    3.31 -            SDL_PushEvent(&fake);
    3.32 +                fake.type = SDL_MOUSEBUTTONDOWN;
    3.33 +                fake.button.state = SDL_PRESSED;
    3.34 +                SDL_PushEvent(&fake);
    3.35 +
    3.36 +                fake.type = SDL_MOUSEBUTTONUP;
    3.37 +                fake.button.state = SDL_RELEASED;
    3.38 +                SDL_PushEvent(&fake);
    3.39 +            }
    3.40 +            if (event->wheel.x) {
    3.41 +                if (event->wheel.y > 0) {
    3.42 +                    fake.button.button = SDL_BUTTON_WHEELLEFT;
    3.43 +                } else {
    3.44 +                    fake.button.button = SDL_BUTTON_WHEELRIGHT;
    3.45 +                }
    3.46 +
    3.47 +                fake.type = SDL_MOUSEBUTTONDOWN;
    3.48 +                fake.button.state = SDL_PRESSED;
    3.49 +                SDL_PushEvent(&fake);
    3.50 +
    3.51 +                fake.type = SDL_MOUSEBUTTONUP;
    3.52 +                fake.button.state = SDL_RELEASED;
    3.53 +                SDL_PushEvent(&fake);
    3.54 +            }
    3.55 +
    3.56              break;
    3.57          }
    3.58  
     4.1 --- a/src/events/SDL_mouse.c	Thu Jul 05 06:35:40 2007 +0000
     4.2 +++ b/src/events/SDL_mouse.c	Fri Jul 06 09:22:18 2007 +0000
     4.3 @@ -427,12 +427,12 @@
     4.4  }
     4.5  
     4.6  int
     4.7 -SDL_SendMouseWheel(int index, int motion)
     4.8 +SDL_SendMouseWheel(int index, int x, int y)
     4.9  {
    4.10      SDL_Mouse *mouse = SDL_GetMouse(index);
    4.11      int posted;
    4.12  
    4.13 -    if (!mouse || !motion) {
    4.14 +    if (!mouse || (!x && !y)) {
    4.15          return 0;
    4.16      }
    4.17  
    4.18 @@ -442,7 +442,8 @@
    4.19          SDL_Event event;
    4.20          event.type = SDL_MOUSEWHEEL;
    4.21          event.wheel.which = (Uint8) index;
    4.22 -        event.wheel.motion = motion;
    4.23 +        event.wheel.x = x;
    4.24 +        event.wheel.y = y;
    4.25          event.wheel.windowID = mouse->focus;
    4.26          posted = (SDL_PushEvent(&event) > 0);
    4.27      }
     5.1 --- a/src/events/SDL_mouse_c.h	Thu Jul 05 06:35:40 2007 +0000
     5.2 +++ b/src/events/SDL_mouse_c.h	Fri Jul 06 09:22:18 2007 +0000
     5.3 @@ -102,7 +102,7 @@
     5.4  extern int SDL_SendMouseButton(int index, Uint8 state, Uint8 button);
     5.5  
     5.6  /* Send a mouse wheel event for a mouse at an index */
     5.7 -extern int SDL_SendMouseWheel(int index, int motion);
     5.8 +extern int SDL_SendMouseWheel(int index, int x, int y);
     5.9  
    5.10  /* Shutdown the mouse subsystem */
    5.11  extern void SDL_MouseQuit(void);
     6.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Thu Jul 05 06:35:40 2007 +0000
     6.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Fri Jul 06 09:22:18 2007 +0000
     6.3 @@ -274,7 +274,7 @@
     6.4      int index;
     6.5  
     6.6      index = _data->videodata->mouse;
     6.7 -    SDL_SendMouseWheel(index, (int)([theEvent deltaY]+0.9f));
     6.8 +    SDL_SendMouseWheel(index, (int)([theEvent deltaX]+0.9f), (int)([theEvent deltaY]+0.9f));
     6.9  }
    6.10  
    6.11  @end
     7.1 --- a/src/video/win32/SDL_win32events.c	Thu Jul 05 06:35:40 2007 +0000
     7.2 +++ b/src/video/win32/SDL_win32events.c	Fri Jul 06 09:22:18 2007 +0000
     7.3 @@ -645,7 +645,7 @@
     7.4              int motion = (short) HIWORD(wParam);
     7.5  
     7.6              index = data->videodata->mouse;
     7.7 -            SDL_SendMouseWheel(index, motion);
     7.8 +            SDL_SendMouseWheel(index, 0, motion);
     7.9          }
    7.10          return (0);
    7.11