src/video/cocoa/SDL_cocoamouse.m
changeset 7114 02b2fe147478
parent 7113 7b4b596b3cfb
child 7158 ff52fba70795
equal deleted inserted replaced
7113:7b4b596b3cfb 7114:02b2fe147478
    22 
    22 
    23 #if SDL_VIDEO_DRIVER_COCOA
    23 #if SDL_VIDEO_DRIVER_COCOA
    24 
    24 
    25 #include "SDL_assert.h"
    25 #include "SDL_assert.h"
    26 #include "SDL_events.h"
    26 #include "SDL_events.h"
    27 #include "SDL_cocoavideo.h"
    27 #include "SDL_cocoamouse.h"
    28 
    28 
    29 #include "../../events/SDL_mouse_c.h"
    29 #include "../../events/SDL_mouse_c.h"
    30 
    30 
    31 
    31 
    32 static SDL_Cursor *
    32 static SDL_Cursor *
   191     CGPoint point;
   191     CGPoint point;
   192 
   192 
   193     point.x = (float)window->x + x;
   193     point.x = (float)window->x + x;
   194     point.y = (float)window->y + y;
   194     point.y = (float)window->y + y;
   195 
   195 
       
   196     {
       
   197         /* This makes Cocoa_HandleMouseEvent ignore this delta in the next
       
   198          * movement event.
       
   199          */
       
   200         SDL_MouseData *driverdata = (SDL_MouseData*)mouse->driverdata;
       
   201         NSPoint location =  [NSEvent mouseLocation];
       
   202         driverdata->deltaXOffset = location.x - point.x;
       
   203         driverdata->deltaYOffset = point.y - location.y;
       
   204     }
       
   205 
   196     /* According to the docs, this was deprecated in 10.6, but it's still
   206     /* According to the docs, this was deprecated in 10.6, but it's still
   197      * around. The substitute requires a CGEventSource, but I'm not entirely
   207      * around. The substitute requires a CGEventSource, but I'm not entirely
   198      * sure how we'd procure the right one for this event.
   208      * sure how we'd procure the right one for this event.
   199      */
   209      */
   200     CGSetLocalEventsSuppressionInterval(0.0);
   210     CGSetLocalEventsSuppressionInterval(0.0);
   226 void
   236 void
   227 Cocoa_InitMouse(_THIS)
   237 Cocoa_InitMouse(_THIS)
   228 {
   238 {
   229     SDL_Mouse *mouse = SDL_GetMouse();
   239     SDL_Mouse *mouse = SDL_GetMouse();
   230 
   240 
       
   241     mouse->driverdata = SDL_calloc(1, sizeof(SDL_MouseData));
       
   242 
   231     mouse->CreateCursor = Cocoa_CreateCursor;
   243     mouse->CreateCursor = Cocoa_CreateCursor;
   232     mouse->CreateSystemCursor = Cocoa_CreateSystemCursor;
   244     mouse->CreateSystemCursor = Cocoa_CreateSystemCursor;
   233     mouse->ShowCursor = Cocoa_ShowCursor;
   245     mouse->ShowCursor = Cocoa_ShowCursor;
   234     mouse->FreeCursor = Cocoa_FreeCursor;
   246     mouse->FreeCursor = Cocoa_FreeCursor;
   235     mouse->WarpMouse = Cocoa_WarpMouse;
   247     mouse->WarpMouse = Cocoa_WarpMouse;
   246     if (mouse->relative_mode &&
   258     if (mouse->relative_mode &&
   247         ([event type] == NSMouseMoved ||
   259         ([event type] == NSMouseMoved ||
   248          [event type] == NSLeftMouseDragged ||
   260          [event type] == NSLeftMouseDragged ||
   249          [event type] == NSRightMouseDragged ||
   261          [event type] == NSRightMouseDragged ||
   250          [event type] == NSOtherMouseDragged)) {
   262          [event type] == NSOtherMouseDragged)) {
   251         float x = [event deltaX];
   263         SDL_MouseData *driverdata = (SDL_MouseData*)mouse->driverdata;
   252         float y = [event deltaY];
   264         float x = [event deltaX] + driverdata->deltaXOffset;
       
   265         float y = [event deltaY] + driverdata->deltaYOffset;
       
   266         driverdata->deltaXOffset = driverdata->deltaYOffset = 0;
       
   267 
   253         SDL_SendMouseMotion(mouse->focus, mouse->mouseID, 1, (int)x, (int)y);
   268         SDL_SendMouseMotion(mouse->focus, mouse->mouseID, 1, (int)x, (int)y);
   254     }
   269     }
   255 }
   270 }
   256 
   271 
   257 void
   272 void
   276 }
   291 }
   277 
   292 
   278 void
   293 void
   279 Cocoa_QuitMouse(_THIS)
   294 Cocoa_QuitMouse(_THIS)
   280 {
   295 {
       
   296     SDL_Mouse *mouse = SDL_GetMouse();
       
   297     if (mouse) {
       
   298         SDL_free(mouse->driverdata);
       
   299     }
   281 }
   300 }
   282 
   301 
   283 #endif /* SDL_VIDEO_DRIVER_COCOA */
   302 #endif /* SDL_VIDEO_DRIVER_COCOA */
   284 
   303 
   285 /* vi: set ts=4 sw=4 expandtab: */
   304 /* vi: set ts=4 sw=4 expandtab: */