Fix mouse wheel events in fullscreen mode for OS X
authorJjgod Jiang <gzjjgod@gmail.com>
Fri, 21 Jan 2011 00:15:18 +0100
changeset 5057bdff53ed6c8b
parent 5056 8b7988f42fcb
child 5058 03db7d4b02b4
Fix mouse wheel events in fullscreen mode for OS X

With proposed patch by vernier.
src/video/cocoa/SDL_cocoaevents.m
src/video/cocoa/SDL_cocoamouse.h
src/video/cocoa/SDL_cocoamouse.m
src/video/cocoa/SDL_cocoawindow.m
     1.1 --- a/src/video/cocoa/SDL_cocoaevents.m	Thu Jan 20 16:05:59 2011 -0800
     1.2 +++ b/src/video/cocoa/SDL_cocoaevents.m	Fri Jan 21 00:15:18 2011 +0100
     1.3 @@ -201,6 +201,7 @@
     1.4          case NSLeftMouseDragged:
     1.5          case NSRightMouseDragged:
     1.6          case NSOtherMouseDragged: /* usually middle mouse dragged */
     1.7 +        case NSScrollWheel:
     1.8          case NSMouseMoved:
     1.9              Cocoa_HandleMouseEvent(_this, event);
    1.10              /* Pass through to NSApp to make sure everything stays in sync */
     2.1 --- a/src/video/cocoa/SDL_cocoamouse.h	Thu Jan 20 16:05:59 2011 -0800
     2.2 +++ b/src/video/cocoa/SDL_cocoamouse.h	Fri Jan 21 00:15:18 2011 +0100
     2.3 @@ -27,6 +27,7 @@
     2.4  extern void Cocoa_InitMouse(_THIS);
     2.5  extern void Cocoa_HandleMouseEvent(_THIS, NSEvent * event);
     2.6  extern void Cocoa_QuitMouse(_THIS);
     2.7 +extern void Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent * event);
     2.8  
     2.9  #endif /* _SDL_cocoamouse_h */
    2.10  
     3.1 --- a/src/video/cocoa/SDL_cocoamouse.m	Thu Jan 20 16:05:59 2011 -0800
     3.2 +++ b/src/video/cocoa/SDL_cocoamouse.m	Fri Jan 21 00:15:18 2011 +0100
     3.3 @@ -93,6 +93,9 @@
     3.4      case NSRightMouseUp:
     3.5          SDL_SendMouseButton(window, SDL_RELEASED, ConvertMouseButtonToSDL([event buttonNumber]));
     3.6          break;
     3.7 +    case NSScrollWheel:
     3.8 +        Cocoa_HandleMouseWheel(window, event);
     3.9 +        break;
    3.10      case NSLeftMouseDragged:
    3.11      case NSRightMouseDragged:
    3.12      case NSOtherMouseDragged: /* usually middle mouse dragged */
    3.13 @@ -109,4 +112,23 @@
    3.14  {
    3.15  }
    3.16  
    3.17 +void
    3.18 +Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event)
    3.19 +{
    3.20 +    float x = [event deltaX];
    3.21 +    float y = [event deltaY];
    3.22 +
    3.23 +    if (x > 0) {
    3.24 +        x += 0.9f;
    3.25 +    } else if (x < 0) {
    3.26 +        x -= 0.9f;
    3.27 +    }
    3.28 +    if (y > 0) {
    3.29 +        y += 0.9f;
    3.30 +    } else if (y < 0) {
    3.31 +        y -= 0.9f;
    3.32 +    }
    3.33 +    SDL_SendMouseWheel(window, (int)x, (int)y);
    3.34 +}
    3.35 +
    3.36  /* vi: set ts=4 sw=4 expandtab: */
     4.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Thu Jan 20 16:05:59 2011 -0800
     4.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Fri Jan 21 00:15:18 2011 +0100
     4.3 @@ -29,6 +29,7 @@
     4.4  #include "../../events/SDL_windowevents_c.h"
     4.5  #include "SDL_cocoavideo.h"
     4.6  #include "SDL_cocoashape.h"
     4.7 +#include "SDL_cocoamouse.h"
     4.8  
     4.9  static __inline__ void ConvertNSRect(NSRect *r)
    4.10  {
    4.11 @@ -260,20 +261,7 @@
    4.12  
    4.13  - (void)scrollWheel:(NSEvent *)theEvent
    4.14  {
    4.15 -    float x = [theEvent deltaX];
    4.16 -    float y = [theEvent deltaY];
    4.17 -
    4.18 -    if (x > 0) {
    4.19 -        x += 0.9f;
    4.20 -    } else if (x < 0) {
    4.21 -        x -= 0.9f;
    4.22 -    }
    4.23 -    if (y > 0) {
    4.24 -        y += 0.9f;
    4.25 -    } else if (y < 0) {
    4.26 -        y -= 0.9f;
    4.27 -    }
    4.28 -    SDL_SendMouseWheel(_data->window, (int)x, (int)y);
    4.29 +    Cocoa_HandleMouseWheel(_data->window, theEvent);
    4.30  }
    4.31  
    4.32  - (void)touchesBeganWithEvent:(NSEvent *) theEvent