changeset 5057:bdff53ed6c8b

Fix mouse wheel events in fullscreen mode for OS X With proposed patch by vernier.
author Jjgod Jiang <gzjjgod@gmail.com>
date Fri, 21 Jan 2011 00:15:18 +0100
parents 8b7988f42fcb
children 03db7d4b02b4
files src/video/cocoa/SDL_cocoaevents.m src/video/cocoa/SDL_cocoamouse.h src/video/cocoa/SDL_cocoamouse.m src/video/cocoa/SDL_cocoawindow.m
diffstat 4 files changed, 26 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/video/cocoa/SDL_cocoaevents.m	Thu Jan 20 16:05:59 2011 -0800
+++ b/src/video/cocoa/SDL_cocoaevents.m	Fri Jan 21 00:15:18 2011 +0100
@@ -201,6 +201,7 @@
         case NSLeftMouseDragged:
         case NSRightMouseDragged:
         case NSOtherMouseDragged: /* usually middle mouse dragged */
+        case NSScrollWheel:
         case NSMouseMoved:
             Cocoa_HandleMouseEvent(_this, event);
             /* Pass through to NSApp to make sure everything stays in sync */
--- a/src/video/cocoa/SDL_cocoamouse.h	Thu Jan 20 16:05:59 2011 -0800
+++ b/src/video/cocoa/SDL_cocoamouse.h	Fri Jan 21 00:15:18 2011 +0100
@@ -27,6 +27,7 @@
 extern void Cocoa_InitMouse(_THIS);
 extern void Cocoa_HandleMouseEvent(_THIS, NSEvent * event);
 extern void Cocoa_QuitMouse(_THIS);
+extern void Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent * event);
 
 #endif /* _SDL_cocoamouse_h */
 
--- a/src/video/cocoa/SDL_cocoamouse.m	Thu Jan 20 16:05:59 2011 -0800
+++ b/src/video/cocoa/SDL_cocoamouse.m	Fri Jan 21 00:15:18 2011 +0100
@@ -93,6 +93,9 @@
     case NSRightMouseUp:
         SDL_SendMouseButton(window, SDL_RELEASED, ConvertMouseButtonToSDL([event buttonNumber]));
         break;
+    case NSScrollWheel:
+        Cocoa_HandleMouseWheel(window, event);
+        break;
     case NSLeftMouseDragged:
     case NSRightMouseDragged:
     case NSOtherMouseDragged: /* usually middle mouse dragged */
@@ -109,4 +112,23 @@
 {
 }
 
+void
+Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event)
+{
+    float x = [event deltaX];
+    float y = [event deltaY];
+
+    if (x > 0) {
+        x += 0.9f;
+    } else if (x < 0) {
+        x -= 0.9f;
+    }
+    if (y > 0) {
+        y += 0.9f;
+    } else if (y < 0) {
+        y -= 0.9f;
+    }
+    SDL_SendMouseWheel(window, (int)x, (int)y);
+}
+
 /* vi: set ts=4 sw=4 expandtab: */
--- a/src/video/cocoa/SDL_cocoawindow.m	Thu Jan 20 16:05:59 2011 -0800
+++ b/src/video/cocoa/SDL_cocoawindow.m	Fri Jan 21 00:15:18 2011 +0100
@@ -29,6 +29,7 @@
 #include "../../events/SDL_windowevents_c.h"
 #include "SDL_cocoavideo.h"
 #include "SDL_cocoashape.h"
+#include "SDL_cocoamouse.h"
 
 static __inline__ void ConvertNSRect(NSRect *r)
 {
@@ -260,20 +261,7 @@
 
 - (void)scrollWheel:(NSEvent *)theEvent
 {
-    float x = [theEvent deltaX];
-    float y = [theEvent deltaY];
-
-    if (x > 0) {
-        x += 0.9f;
-    } else if (x < 0) {
-        x -= 0.9f;
-    }
-    if (y > 0) {
-        y += 0.9f;
-    } else if (y < 0) {
-        y -= 0.9f;
-    }
-    SDL_SendMouseWheel(_data->window, (int)x, (int)y);
+    Cocoa_HandleMouseWheel(_data->window, theEvent);
 }
 
 - (void)touchesBeganWithEvent:(NSEvent *) theEvent