src/video/cocoa/SDL_cocoamouse.m
changeset 7114 02b2fe147478
parent 7113 7b4b596b3cfb
child 7158 ff52fba70795
     1.1 --- a/src/video/cocoa/SDL_cocoamouse.m	Thu Apr 25 18:40:22 2013 -0700
     1.2 +++ b/src/video/cocoa/SDL_cocoamouse.m	Thu Apr 25 18:40:29 2013 -0700
     1.3 @@ -24,7 +24,7 @@
     1.4  
     1.5  #include "SDL_assert.h"
     1.6  #include "SDL_events.h"
     1.7 -#include "SDL_cocoavideo.h"
     1.8 +#include "SDL_cocoamouse.h"
     1.9  
    1.10  #include "../../events/SDL_mouse_c.h"
    1.11  
    1.12 @@ -193,6 +193,16 @@
    1.13      point.x = (float)window->x + x;
    1.14      point.y = (float)window->y + y;
    1.15  
    1.16 +    {
    1.17 +        /* This makes Cocoa_HandleMouseEvent ignore this delta in the next
    1.18 +         * movement event.
    1.19 +         */
    1.20 +        SDL_MouseData *driverdata = (SDL_MouseData*)mouse->driverdata;
    1.21 +        NSPoint location =  [NSEvent mouseLocation];
    1.22 +        driverdata->deltaXOffset = location.x - point.x;
    1.23 +        driverdata->deltaYOffset = point.y - location.y;
    1.24 +    }
    1.25 +
    1.26      /* According to the docs, this was deprecated in 10.6, but it's still
    1.27       * around. The substitute requires a CGEventSource, but I'm not entirely
    1.28       * sure how we'd procure the right one for this event.
    1.29 @@ -228,6 +238,8 @@
    1.30  {
    1.31      SDL_Mouse *mouse = SDL_GetMouse();
    1.32  
    1.33 +    mouse->driverdata = SDL_calloc(1, sizeof(SDL_MouseData));
    1.34 +
    1.35      mouse->CreateCursor = Cocoa_CreateCursor;
    1.36      mouse->CreateSystemCursor = Cocoa_CreateSystemCursor;
    1.37      mouse->ShowCursor = Cocoa_ShowCursor;
    1.38 @@ -248,8 +260,11 @@
    1.39           [event type] == NSLeftMouseDragged ||
    1.40           [event type] == NSRightMouseDragged ||
    1.41           [event type] == NSOtherMouseDragged)) {
    1.42 -        float x = [event deltaX];
    1.43 -        float y = [event deltaY];
    1.44 +        SDL_MouseData *driverdata = (SDL_MouseData*)mouse->driverdata;
    1.45 +        float x = [event deltaX] + driverdata->deltaXOffset;
    1.46 +        float y = [event deltaY] + driverdata->deltaYOffset;
    1.47 +        driverdata->deltaXOffset = driverdata->deltaYOffset = 0;
    1.48 +
    1.49          SDL_SendMouseMotion(mouse->focus, mouse->mouseID, 1, (int)x, (int)y);
    1.50      }
    1.51  }
    1.52 @@ -278,6 +293,10 @@
    1.53  void
    1.54  Cocoa_QuitMouse(_THIS)
    1.55  {
    1.56 +    SDL_Mouse *mouse = SDL_GetMouse();
    1.57 +    if (mouse) {
    1.58 +        SDL_free(mouse->driverdata);
    1.59 +    }
    1.60  }
    1.61  
    1.62  #endif /* SDL_VIDEO_DRIVER_COCOA */