Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Tracking rectangles had some problems, it's easier to track things di…
Browse files Browse the repository at this point in the history
…rectly. (fixes bug 1149, 1147, 1146)
  • Loading branch information
slouken committed Feb 25, 2011
1 parent f3eb4da commit 3fd5968
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions src/video/cocoa/SDL_cocoawindow.m
Expand Up @@ -66,7 +66,6 @@ - (void)listen:(SDL_WindowData *)data
[window setAcceptsMouseMovedEvents:YES];

[view setNextResponder:self];
[view addTrackingRect:[view visibleRect] owner:self userData:nil assumeInside:NO];
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
[view setAcceptsTouchEvents:YES];
#endif
Expand Down Expand Up @@ -152,12 +151,20 @@ - (void)windowDidBecomeKey:(NSNotification *)aNotification
SDL_SetKeyboardFocus(window);

/* If we just gained focus we need the updated mouse position */
if (SDL_GetMouseFocus() == window) {
{
NSPoint point;
point = [NSEvent mouseLocation];
point = [_data->nswindow convertScreenToBase:point];
point.y = window->h - point.y;
SDL_SendMouseMotion(window, 0, (int)point.x, (int)point.y);
int x, y;

point = [_data->nswindow mouseLocationOutsideOfEventStream];
x = (int)point.x;
y = (int)(window->h - point.y);

if (x >= 0 && x < window->w && y >= 0 && y < window->h) {
if (SDL_GetMouseFocus() != window) {
[self mouseEntered:nil];
}
SDL_SendMouseMotion(window, 0, x, y);
}
}

/* Check to see if someone updated the clipboard */
Expand Down Expand Up @@ -288,20 +295,28 @@ - (void)mouseExited:(NSEvent *)theEvent
- (void)mouseMoved:(NSEvent *)theEvent
{
SDL_Window *window = _data->window;
NSPoint point;
int x, y;

#ifdef RELATIVE_MOTION
if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
return;
}
#endif

if (SDL_GetMouseFocus() == window) {
NSPoint point;

point = [theEvent locationInWindow];
point.y = window->h - point.y;
point = [theEvent locationInWindow];
x = (int)point.x;
y = (int)(window->h - point.y);

SDL_SendMouseMotion(window, 0, (int)point.x, (int)point.y);
if (x < 0 || x >= window->w || y < 0 || y >= window->h) {
if (SDL_GetMouseFocus() == window) {
[self mouseExited:theEvent];
}
} else {
if (SDL_GetMouseFocus() != window) {
[self mouseEntered:theEvent];
}
SDL_SendMouseMotion(window, 0, x, y);
}
}

Expand Down

0 comments on commit 3fd5968

Please sign in to comment.