src/video/cocoa/SDL_cocoamouse.m
changeset 8951 692ba71b9c04
parent 8928 f60f16d29e37
child 8952 4bb098814ec4
equal deleted inserted replaced
8950:66b11e777d54 8951:692ba71b9c04
   280     /* our Cocoa event code already tracks the mouse outside the window,
   280     /* our Cocoa event code already tracks the mouse outside the window,
   281         so all we have to do here is say "okay" and do what we always do. */
   281         so all we have to do here is say "okay" and do what we always do. */
   282     return 0;
   282     return 0;
   283 }
   283 }
   284 
   284 
       
   285 static Uint32
       
   286 Cocoa_GetAbsoluteMouseState(int *x, int *y)
       
   287 {
       
   288     const NSUInteger cocoaButtons = [NSEvent pressedMouseButtons];
       
   289     const NSPoint cocoaLocation = [NSEvent mouseLocation];
       
   290     Uint32 retval = 0;
       
   291 
       
   292     for (NSScreen *screen in [NSScreen screens]) {
       
   293         NSRect frame = [screen frame];
       
   294         if (NSPointInRect(cocoaLocation, frame)) {
       
   295             *x = (int) cocoaLocation.x;
       
   296             *y = (int) ((frame.origin.y + frame.size.height) - cocoaLocation.y);
       
   297             break;
       
   298         }
       
   299     }
       
   300 
       
   301     retval |= (cocoaButtons & (1 << 0)) ? SDL_BUTTON_LMASK : 0;
       
   302     retval |= (cocoaButtons & (1 << 1)) ? SDL_BUTTON_RMASK : 0;
       
   303     retval |= (cocoaButtons & (1 << 2)) ? SDL_BUTTON_MMASK : 0;
       
   304     retval |= (cocoaButtons & (1 << 3)) ? SDL_BUTTON_X1MASK : 0;
       
   305     retval |= (cocoaButtons & (1 << 4)) ? SDL_BUTTON_X2MASK : 0;
       
   306 
       
   307     return retval;
       
   308 }
       
   309 
   285 void
   310 void
   286 Cocoa_InitMouse(_THIS)
   311 Cocoa_InitMouse(_THIS)
   287 {
   312 {
   288     SDL_Mouse *mouse = SDL_GetMouse();
   313     SDL_Mouse *mouse = SDL_GetMouse();
   289 
   314 
   294     mouse->ShowCursor = Cocoa_ShowCursor;
   319     mouse->ShowCursor = Cocoa_ShowCursor;
   295     mouse->FreeCursor = Cocoa_FreeCursor;
   320     mouse->FreeCursor = Cocoa_FreeCursor;
   296     mouse->WarpMouse = Cocoa_WarpMouse;
   321     mouse->WarpMouse = Cocoa_WarpMouse;
   297     mouse->SetRelativeMouseMode = Cocoa_SetRelativeMouseMode;
   322     mouse->SetRelativeMouseMode = Cocoa_SetRelativeMouseMode;
   298     mouse->CaptureMouse = Cocoa_CaptureMouse;
   323     mouse->CaptureMouse = Cocoa_CaptureMouse;
       
   324     mouse->GetAbsoluteMouseState = Cocoa_GetAbsoluteMouseState;
   299 
   325 
   300     SDL_SetDefaultCursor(Cocoa_CreateDefaultCursor());
   326     SDL_SetDefaultCursor(Cocoa_CreateDefaultCursor());
   301 
   327 
   302     Cocoa_InitMouseEventTap(mouse->driverdata);
   328     Cocoa_InitMouseEventTap(mouse->driverdata);
   303 
   329