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

Commit

Permalink
The window positions are relative to the origin of the windowing syst…
Browse files Browse the repository at this point in the history
…em (upper left of the primary display).

Fixed the mouse positions for windowed mouse movement.
  • Loading branch information
slouken committed Dec 1, 2009
1 parent 0983bec commit f287a2b
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/video/cocoa/SDL_cocoawindow.m
Expand Up @@ -98,11 +98,10 @@ - (void)windowDidExpose:(NSNotification *)aNotification
- (void)windowDidMove:(NSNotification *)aNotification
{
int x, y;
NSRect disp = CGDisplayBounds(_data->display);
NSRect rect = [_data->window contentRectForFrameRect:[_data->window frame]];
ConvertNSRect(&rect);
x = (int)rect.origin.x - disp.origin.x;
y = (int)rect.origin.y - disp.origin.y;
x = (int)rect.origin.x;
y = (int)rect.origin.y;
SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_MOVED, x, y);
}

Expand Down Expand Up @@ -245,11 +244,11 @@ - (void)mouseMoved:(NSEvent *)theEvent
point.x = point.x - rect.origin.x;
point.y = rect.size.height - point.y;
} else {
rect = [_data->window contentRectForFrameRect:[_data->window frame]];
point.y = rect.size.height - (point.y - rect.origin.y);
point.x -= window->x;
point.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - point.y - window->y;
}
if ( point.x < 0 || point.x >= rect.size.width ||
point.y < 0 || point.y >= rect.size.height ) {
if ( point.x < 0 || point.x >= window->w ||
point.y < 0 || point.y >= window->h ) {
if (mouse->focus != 0) {
SDL_SetMouseFocus(index, 0);
}
Expand Down Expand Up @@ -332,11 +331,10 @@ - (BOOL)canBecomeMainWindow

/* Fill in the SDL window with the window data */
{
NSRect disp = CGDisplayBounds(data->display);
NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
ConvertNSRect(&rect);
window->x = (int)rect.origin.x - disp.origin.x;
window->y = (int)rect.origin.y - disp.origin.y;
window->x = (int)rect.origin.x;
window->y = (int)rect.origin.y;
window->w = (int)rect.size.width;
window->h = (int)rect.size.height;
}
Expand Down Expand Up @@ -401,13 +399,13 @@ - (BOOL)canBecomeMainWindow
|| window->x == SDL_WINDOWPOS_CENTERED) {
rect.origin.x += (rect.size.width - window->w) / 2;
} else if (window->x != SDL_WINDOWPOS_UNDEFINED) {
rect.origin.x += window->x;
rect.origin.x = window->x;
}
if ((window->flags & SDL_WINDOW_FULLSCREEN)
|| window->y == SDL_WINDOWPOS_CENTERED) {
rect.origin.y += (rect.size.height - window->h) / 2;
} else if (window->x != SDL_WINDOWPOS_UNDEFINED) {
rect.origin.y += window->y;
rect.origin.y = window->y;
}
rect.size.width = window->w;
rect.size.height = window->h;
Expand Down Expand Up @@ -500,13 +498,13 @@ - (BOOL)canBecomeMainWindow
|| window->x == SDL_WINDOWPOS_CENTERED) {
rect.origin.x += (rect.size.width - window->w) / 2;
} else {
rect.origin.x += window->x;
rect.origin.x = window->x;
}
if ((window->flags & SDL_WINDOW_FULLSCREEN)
|| window->y == SDL_WINDOWPOS_CENTERED) {
rect.origin.y += (rect.size.height - window->h) / 2;
} else {
rect.origin.y += window->y;
rect.origin.y = window->y;
}
rect.size.width = window->w;
rect.size.height = window->h;
Expand Down

0 comments on commit f287a2b

Please sign in to comment.