changeset 1957:c7803e4c21d3

Implemented Cocoa mouse wheel events
author Sam Lantinga <slouken@libsdl.org>
date Sat, 29 Jul 2006 22:42:48 +0000
parents ba0d62354872
children 5fc6fb0fb605
files include/SDL_events.h src/video/cocoa/SDL_cocoawindow.h src/video/cocoa/SDL_cocoawindow.m test/common.c
diffstat 4 files changed, 13 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/include/SDL_events.h	Sat Jul 29 21:51:00 2006 +0000
+++ b/include/SDL_events.h	Sat Jul 29 22:42:48 2006 +0000
@@ -60,11 +60,11 @@
     SDL_WINDOWEVENT,            /**< Window state change */
     SDL_KEYDOWN,                /**< Keys pressed */
     SDL_KEYUP,                  /**< Keys released */
-    SDL_TEXTINPUT,                              /**< Keyboard text input */
+    SDL_TEXTINPUT,              /**< Keyboard text input */
     SDL_MOUSEMOTION,            /**< Mouse moved */
     SDL_MOUSEBUTTONDOWN,        /**< Mouse button pressed */
     SDL_MOUSEBUTTONUP,          /**< Mouse button released */
-    SDL_MOUSEWHEEL,                             /**< Mouse wheel motion */
+    SDL_MOUSEWHEEL,             /**< Mouse wheel motion */
     SDL_JOYAXISMOTION,          /**< Joystick axis motion */
     SDL_JOYBALLMOTION,          /**< Joystick trackball motion */
     SDL_JOYHATMOTION,           /**< Joystick hat position change */
--- a/src/video/cocoa/SDL_cocoawindow.h	Sat Jul 29 21:51:00 2006 +0000
+++ b/src/video/cocoa/SDL_cocoawindow.h	Sat Jul 29 22:42:48 2006 +0000
@@ -54,6 +54,7 @@
 -(void) rightMouseUp:(NSEvent *) theEvent;
 -(void) otherMouseUp:(NSEvent *) theEvent;
 -(void) mouseMoved:(NSEvent *) theEvent;
+-(void) mouseDragged:(NSEvent *) theEvent;
 -(void) scrollWheel:(NSEvent *) theEvent;
 -(void) keyDown:(NSEvent *) theEvent;
 -(void) keyUp:(NSEvent *) theEvent;
--- a/src/video/cocoa/SDL_cocoawindow.m	Sat Jul 29 21:51:00 2006 +0000
+++ b/src/video/cocoa/SDL_cocoawindow.m	Sat Jul 29 22:42:48 2006 +0000
@@ -208,26 +208,22 @@
     }
 
     point = [NSEvent mouseLocation];
-    if (point.x < rect.origin.x ||
-        point.x > (rect.origin.x + rect.size.width) ||
-        point.y < rect.origin.y ||
-        point.y > (rect.origin.y + rect.size.height)) {
-        if (window->flags & SDL_WINDOW_MOUSE_FOCUS) {
-            SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_LEAVE, 0, 0);
-        }
-    } else {
-        if (!(window->flags & SDL_WINDOW_MOUSE_FOCUS)) {
-            SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_ENTER, 0, 0);
-        }
-    }
     point.x = point.x - rect.origin.x;
     point.y = rect.size.height - (point.y - rect.origin.y);
     SDL_SendMouseMotion(index, 0, (int)point.x, (int)point.y);
 }
 
+- (void)mouseDragged:(NSEvent *)theEvent
+{
+    [self mouseMoved:theEvent];
+}
+
 - (void)scrollWheel:(NSEvent *)theEvent
 {
-fprintf(stderr, "scrollWheel\n");
+    int index;
+
+    index = _data->videodata->mouse;
+    SDL_SendMouseWheel(index, (int)([theEvent deltaY]+0.9f));
 }
 
 - (void)keyDown:(NSEvent *)theEvent
--- a/test/common.c	Sat Jul 29 21:51:00 2006 +0000
+++ b/test/common.c	Sat Jul 29 22:42:48 2006 +0000
@@ -827,7 +827,7 @@
     case SDL_MOUSEWHEEL:
         fprintf(stderr, "Mouse %d: wheel scrolled %d in window %d",
                 event->wheel.which, event->wheel.motion,
-                event->button.windowID);
+                event->wheel.windowID);
         break;
     case SDL_JOYBALLMOTION:
         fprintf(stderr, "Joystick %d: ball %d moved by %d,%d",