src/video/cocoa/SDL_cocoamouse.m
changeset 5371 fc3d3d580777
parent 5262 b530ef003506
child 5376 183ec2d4485c
equal deleted inserted replaced
5370:cb219a294ebf 5371:fc3d3d580777
    47 }
    47 }
    48 
    48 
    49 void
    49 void
    50 Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
    50 Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
    51 {
    51 {
    52     int i;
    52     /* We're correctly using views even in fullscreen mode now */
    53     NSPoint point = { 0, 0 };
       
    54     SDL_Window *window;
       
    55     SDL_Window *focus = SDL_GetMouseFocus();
       
    56 
       
    57     /* See if there are any fullscreen windows that might handle this event */
       
    58     window = NULL;
       
    59     for (i = 0; i < _this->num_displays; ++i) {
       
    60         SDL_VideoDisplay *display = &_this->displays[i];
       
    61         SDL_Window *candidate = display->fullscreen_window;
       
    62 
       
    63         if (candidate) {
       
    64             SDL_Rect bounds;
       
    65 
       
    66             Cocoa_GetDisplayBounds(_this, display, &bounds);
       
    67             point = [NSEvent mouseLocation];
       
    68             point.x = point.x - bounds.x;
       
    69             point.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - point.y - bounds.y;
       
    70             if ((point.x >= 0 && point.x < candidate->w) &&
       
    71                 (point.y >= 0 && point.y < candidate->h)) {
       
    72                 /* This is it! */
       
    73                 window = candidate;
       
    74                 break;
       
    75             } else if (candidate == focus) {
       
    76                 SDL_SetMouseFocus(NULL);
       
    77             }
       
    78         }
       
    79     }
       
    80 
       
    81     if (!window) {
       
    82         return;
       
    83     }
       
    84 
       
    85     switch ([event type]) {
       
    86     case NSLeftMouseDown:
       
    87     case NSOtherMouseDown:
       
    88     case NSRightMouseDown:
       
    89         SDL_SendMouseButton(window, SDL_PRESSED, ConvertMouseButtonToSDL([event buttonNumber]));
       
    90         break;
       
    91     case NSLeftMouseUp:
       
    92     case NSOtherMouseUp:
       
    93     case NSRightMouseUp:
       
    94         SDL_SendMouseButton(window, SDL_RELEASED, ConvertMouseButtonToSDL([event buttonNumber]));
       
    95         break;
       
    96     case NSScrollWheel:
       
    97         Cocoa_HandleMouseWheel(window, event);
       
    98         break;
       
    99     case NSLeftMouseDragged:
       
   100     case NSRightMouseDragged:
       
   101     case NSOtherMouseDragged: /* usually middle mouse dragged */
       
   102     case NSMouseMoved:
       
   103         SDL_SendMouseMotion(window, 0, (int)point.x, (int)point.y);
       
   104         break;
       
   105     default: /* just to avoid compiler warnings */
       
   106         break;
       
   107     }
       
   108 }
    53 }
   109 
    54 
   110 void
    55 void
   111 Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event)
    56 Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event)
   112 {
    57 {