src/video/cocoa/SDL_cocoamouse.m
changeset 8951 692ba71b9c04
parent 8928 f60f16d29e37
child 8952 4bb098814ec4
     1.1 --- a/src/video/cocoa/SDL_cocoamouse.m	Wed Jun 11 00:12:19 2014 -0400
     1.2 +++ b/src/video/cocoa/SDL_cocoamouse.m	Wed Jun 11 00:40:19 2014 -0400
     1.3 @@ -282,6 +282,31 @@
     1.4      return 0;
     1.5  }
     1.6  
     1.7 +static Uint32
     1.8 +Cocoa_GetAbsoluteMouseState(int *x, int *y)
     1.9 +{
    1.10 +    const NSUInteger cocoaButtons = [NSEvent pressedMouseButtons];
    1.11 +    const NSPoint cocoaLocation = [NSEvent mouseLocation];
    1.12 +    Uint32 retval = 0;
    1.13 +
    1.14 +    for (NSScreen *screen in [NSScreen screens]) {
    1.15 +        NSRect frame = [screen frame];
    1.16 +        if (NSPointInRect(cocoaLocation, frame)) {
    1.17 +            *x = (int) cocoaLocation.x;
    1.18 +            *y = (int) ((frame.origin.y + frame.size.height) - cocoaLocation.y);
    1.19 +            break;
    1.20 +        }
    1.21 +    }
    1.22 +
    1.23 +    retval |= (cocoaButtons & (1 << 0)) ? SDL_BUTTON_LMASK : 0;
    1.24 +    retval |= (cocoaButtons & (1 << 1)) ? SDL_BUTTON_RMASK : 0;
    1.25 +    retval |= (cocoaButtons & (1 << 2)) ? SDL_BUTTON_MMASK : 0;
    1.26 +    retval |= (cocoaButtons & (1 << 3)) ? SDL_BUTTON_X1MASK : 0;
    1.27 +    retval |= (cocoaButtons & (1 << 4)) ? SDL_BUTTON_X2MASK : 0;
    1.28 +
    1.29 +    return retval;
    1.30 +}
    1.31 +
    1.32  void
    1.33  Cocoa_InitMouse(_THIS)
    1.34  {
    1.35 @@ -296,6 +321,7 @@
    1.36      mouse->WarpMouse = Cocoa_WarpMouse;
    1.37      mouse->SetRelativeMouseMode = Cocoa_SetRelativeMouseMode;
    1.38      mouse->CaptureMouse = Cocoa_CaptureMouse;
    1.39 +    mouse->GetAbsoluteMouseState = Cocoa_GetAbsoluteMouseState;
    1.40  
    1.41      SDL_SetDefaultCursor(Cocoa_CreateDefaultCursor());
    1.42