src/video/cocoa/SDL_cocoawindow.m
changeset 5396 109b7c071f70
parent 5388 6e586f65f8ef
child 5398 83816c8a2b58
equal deleted inserted replaced
5395:f0e399961f3a 5396:109b7c071f70
    64 
    64 
    65     [window setNextResponder:self];
    65     [window setNextResponder:self];
    66     [window setAcceptsMouseMovedEvents:YES];
    66     [window setAcceptsMouseMovedEvents:YES];
    67 
    67 
    68     [view setNextResponder:self];
    68     [view setNextResponder:self];
    69     [view addTrackingRect:[view visibleRect] owner:self userData:nil assumeInside:NO];
       
    70 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
    69 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
    71     [view setAcceptsTouchEvents:YES];
    70     [view setAcceptsTouchEvents:YES];
    72 #endif
    71 #endif
    73 }
    72 }
    74 
    73 
   150 
   149 
   151     /* We're going to get keyboard events, since we're key. */
   150     /* We're going to get keyboard events, since we're key. */
   152     SDL_SetKeyboardFocus(window);
   151     SDL_SetKeyboardFocus(window);
   153 
   152 
   154     /* If we just gained focus we need the updated mouse position */
   153     /* If we just gained focus we need the updated mouse position */
   155     if (SDL_GetMouseFocus() == window) {
   154     {
   156         NSPoint point;
   155         NSPoint point;
   157         point = [NSEvent mouseLocation];
   156         int x, y;
   158         point = [_data->nswindow convertScreenToBase:point];
   157 
   159         point.y = window->h - point.y;
   158         point = [_data->nswindow mouseLocationOutsideOfEventStream];
   160         SDL_SendMouseMotion(window, 0, (int)point.x, (int)point.y);
   159         x = (int)point.x;
       
   160         y = (int)(window->h - point.y);
       
   161 
       
   162         if (x >= 0 && x < window->w && y >= 0 && y < window->h) {
       
   163             if (SDL_GetMouseFocus() != window) {
       
   164                 [self mouseEntered:nil];
       
   165             }
       
   166             SDL_SendMouseMotion(window, 0, x, y);
       
   167         }
   161     }
   168     }
   162 
   169 
   163     /* Check to see if someone updated the clipboard */
   170     /* Check to see if someone updated the clipboard */
   164     Cocoa_CheckClipboardUpdate(_data->videodata);
   171     Cocoa_CheckClipboardUpdate(_data->videodata);
   165 }
   172 }
   286 }
   293 }
   287 
   294 
   288 - (void)mouseMoved:(NSEvent *)theEvent
   295 - (void)mouseMoved:(NSEvent *)theEvent
   289 {
   296 {
   290     SDL_Window *window = _data->window;
   297     SDL_Window *window = _data->window;
       
   298     NSPoint point;
       
   299     int x, y;
   291 
   300 
   292 #ifdef RELATIVE_MOTION
   301 #ifdef RELATIVE_MOTION
   293     if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
   302     if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
   294         return;
   303         return;
   295     }
   304     }
   296 #endif
   305 #endif
   297 
   306 
   298     if (SDL_GetMouseFocus() == window) {
   307     point = [theEvent locationInWindow];
   299         NSPoint point;
   308     x = (int)point.x;
   300 
   309     y = (int)(window->h - point.y);
   301         point = [theEvent locationInWindow];
   310 
   302         point.y = window->h - point.y;
   311     if (x < 0 || x >= window->w || y < 0 || y >= window->h) {
   303 
   312         if (SDL_GetMouseFocus() == window) {
   304         SDL_SendMouseMotion(window, 0, (int)point.x, (int)point.y);
   313             [self mouseExited:theEvent];
       
   314         }
       
   315     } else {
       
   316         if (SDL_GetMouseFocus() != window) {
       
   317             [self mouseEntered:theEvent];
       
   318         }
       
   319         SDL_SendMouseMotion(window, 0, x, y);
   305     }
   320     }
   306 }
   321 }
   307 
   322 
   308 - (void)mouseDragged:(NSEvent *)theEvent
   323 - (void)mouseDragged:(NSEvent *)theEvent
   309 {
   324 {