Tracking rectangles had some problems, it's easier to track things directly. (fixes bug 1149, 1147, 1146)
authorSam Lantinga <slouken@libsdl.org>
Thu, 24 Feb 2011 18:11:29 -0800
changeset 5396109b7c071f70
parent 5395 f0e399961f3a
child 5397 88ff1f463134
Tracking rectangles had some problems, it's easier to track things directly. (fixes bug 1149, 1147, 1146)
src/video/cocoa/SDL_cocoawindow.m
     1.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Thu Feb 24 17:52:47 2011 -0800
     1.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Thu Feb 24 18:11:29 2011 -0800
     1.3 @@ -66,7 +66,6 @@
     1.4      [window setAcceptsMouseMovedEvents:YES];
     1.5  
     1.6      [view setNextResponder:self];
     1.7 -    [view addTrackingRect:[view visibleRect] owner:self userData:nil assumeInside:NO];
     1.8  #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
     1.9      [view setAcceptsTouchEvents:YES];
    1.10  #endif
    1.11 @@ -152,12 +151,20 @@
    1.12      SDL_SetKeyboardFocus(window);
    1.13  
    1.14      /* If we just gained focus we need the updated mouse position */
    1.15 -    if (SDL_GetMouseFocus() == window) {
    1.16 +    {
    1.17          NSPoint point;
    1.18 -        point = [NSEvent mouseLocation];
    1.19 -        point = [_data->nswindow convertScreenToBase:point];
    1.20 -        point.y = window->h - point.y;
    1.21 -        SDL_SendMouseMotion(window, 0, (int)point.x, (int)point.y);
    1.22 +        int x, y;
    1.23 +
    1.24 +        point = [_data->nswindow mouseLocationOutsideOfEventStream];
    1.25 +        x = (int)point.x;
    1.26 +        y = (int)(window->h - point.y);
    1.27 +
    1.28 +        if (x >= 0 && x < window->w && y >= 0 && y < window->h) {
    1.29 +            if (SDL_GetMouseFocus() != window) {
    1.30 +                [self mouseEntered:nil];
    1.31 +            }
    1.32 +            SDL_SendMouseMotion(window, 0, x, y);
    1.33 +        }
    1.34      }
    1.35  
    1.36      /* Check to see if someone updated the clipboard */
    1.37 @@ -288,6 +295,8 @@
    1.38  - (void)mouseMoved:(NSEvent *)theEvent
    1.39  {
    1.40      SDL_Window *window = _data->window;
    1.41 +    NSPoint point;
    1.42 +    int x, y;
    1.43  
    1.44  #ifdef RELATIVE_MOTION
    1.45      if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
    1.46 @@ -295,13 +304,19 @@
    1.47      }
    1.48  #endif
    1.49  
    1.50 -    if (SDL_GetMouseFocus() == window) {
    1.51 -        NSPoint point;
    1.52 +    point = [theEvent locationInWindow];
    1.53 +    x = (int)point.x;
    1.54 +    y = (int)(window->h - point.y);
    1.55  
    1.56 -        point = [theEvent locationInWindow];
    1.57 -        point.y = window->h - point.y;
    1.58 -
    1.59 -        SDL_SendMouseMotion(window, 0, (int)point.x, (int)point.y);
    1.60 +    if (x < 0 || x >= window->w || y < 0 || y >= window->h) {
    1.61 +        if (SDL_GetMouseFocus() == window) {
    1.62 +            [self mouseExited:theEvent];
    1.63 +        }
    1.64 +    } else {
    1.65 +        if (SDL_GetMouseFocus() != window) {
    1.66 +            [self mouseEntered:theEvent];
    1.67 +        }
    1.68 +        SDL_SendMouseMotion(window, 0, x, y);
    1.69      }
    1.70  }
    1.71