Implemented Cocoa mouse wheel events
authorSam Lantinga <slouken@libsdl.org>
Sat, 29 Jul 2006 22:42:48 +0000
changeset 1957c7803e4c21d3
parent 1956 ba0d62354872
child 1958 5fc6fb0fb605
Implemented Cocoa mouse wheel events
include/SDL_events.h
src/video/cocoa/SDL_cocoawindow.h
src/video/cocoa/SDL_cocoawindow.m
test/common.c
     1.1 --- a/include/SDL_events.h	Sat Jul 29 21:51:00 2006 +0000
     1.2 +++ b/include/SDL_events.h	Sat Jul 29 22:42:48 2006 +0000
     1.3 @@ -60,11 +60,11 @@
     1.4      SDL_WINDOWEVENT,            /**< Window state change */
     1.5      SDL_KEYDOWN,                /**< Keys pressed */
     1.6      SDL_KEYUP,                  /**< Keys released */
     1.7 -    SDL_TEXTINPUT,                              /**< Keyboard text input */
     1.8 +    SDL_TEXTINPUT,              /**< Keyboard text input */
     1.9      SDL_MOUSEMOTION,            /**< Mouse moved */
    1.10      SDL_MOUSEBUTTONDOWN,        /**< Mouse button pressed */
    1.11      SDL_MOUSEBUTTONUP,          /**< Mouse button released */
    1.12 -    SDL_MOUSEWHEEL,                             /**< Mouse wheel motion */
    1.13 +    SDL_MOUSEWHEEL,             /**< Mouse wheel motion */
    1.14      SDL_JOYAXISMOTION,          /**< Joystick axis motion */
    1.15      SDL_JOYBALLMOTION,          /**< Joystick trackball motion */
    1.16      SDL_JOYHATMOTION,           /**< Joystick hat position change */
     2.1 --- a/src/video/cocoa/SDL_cocoawindow.h	Sat Jul 29 21:51:00 2006 +0000
     2.2 +++ b/src/video/cocoa/SDL_cocoawindow.h	Sat Jul 29 22:42:48 2006 +0000
     2.3 @@ -54,6 +54,7 @@
     2.4  -(void) rightMouseUp:(NSEvent *) theEvent;
     2.5  -(void) otherMouseUp:(NSEvent *) theEvent;
     2.6  -(void) mouseMoved:(NSEvent *) theEvent;
     2.7 +-(void) mouseDragged:(NSEvent *) theEvent;
     2.8  -(void) scrollWheel:(NSEvent *) theEvent;
     2.9  -(void) keyDown:(NSEvent *) theEvent;
    2.10  -(void) keyUp:(NSEvent *) theEvent;
     3.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Sat Jul 29 21:51:00 2006 +0000
     3.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Sat Jul 29 22:42:48 2006 +0000
     3.3 @@ -208,26 +208,22 @@
     3.4      }
     3.5  
     3.6      point = [NSEvent mouseLocation];
     3.7 -    if (point.x < rect.origin.x ||
     3.8 -        point.x > (rect.origin.x + rect.size.width) ||
     3.9 -        point.y < rect.origin.y ||
    3.10 -        point.y > (rect.origin.y + rect.size.height)) {
    3.11 -        if (window->flags & SDL_WINDOW_MOUSE_FOCUS) {
    3.12 -            SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_LEAVE, 0, 0);
    3.13 -        }
    3.14 -    } else {
    3.15 -        if (!(window->flags & SDL_WINDOW_MOUSE_FOCUS)) {
    3.16 -            SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_ENTER, 0, 0);
    3.17 -        }
    3.18 -    }
    3.19      point.x = point.x - rect.origin.x;
    3.20      point.y = rect.size.height - (point.y - rect.origin.y);
    3.21      SDL_SendMouseMotion(index, 0, (int)point.x, (int)point.y);
    3.22  }
    3.23  
    3.24 +- (void)mouseDragged:(NSEvent *)theEvent
    3.25 +{
    3.26 +    [self mouseMoved:theEvent];
    3.27 +}
    3.28 +
    3.29  - (void)scrollWheel:(NSEvent *)theEvent
    3.30  {
    3.31 -fprintf(stderr, "scrollWheel\n");
    3.32 +    int index;
    3.33 +
    3.34 +    index = _data->videodata->mouse;
    3.35 +    SDL_SendMouseWheel(index, (int)([theEvent deltaY]+0.9f));
    3.36  }
    3.37  
    3.38  - (void)keyDown:(NSEvent *)theEvent
     4.1 --- a/test/common.c	Sat Jul 29 21:51:00 2006 +0000
     4.2 +++ b/test/common.c	Sat Jul 29 22:42:48 2006 +0000
     4.3 @@ -827,7 +827,7 @@
     4.4      case SDL_MOUSEWHEEL:
     4.5          fprintf(stderr, "Mouse %d: wheel scrolled %d in window %d",
     4.6                  event->wheel.which, event->wheel.motion,
     4.7 -                event->button.windowID);
     4.8 +                event->wheel.windowID);
     4.9          break;
    4.10      case SDL_JOYBALLMOTION:
    4.11          fprintf(stderr, "Joystick %d: ball %d moved by %d,%d",