changeset 3507:3712547eac4f

The window positions are relative to the origin of the windowing system (upper left of the primary display). Fixed the mouse positions for windowed mouse movement.
author Sam Lantinga <slouken@libsdl.org>
date Tue, 01 Dec 2009 12:08:34 +0000
parents e829b6098435
children a12068b6f44f
files src/video/cocoa/SDL_cocoawindow.m
diffstat 1 files changed, 12 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/video/cocoa/SDL_cocoawindow.m	Tue Dec 01 11:50:00 2009 +0000
+++ b/src/video/cocoa/SDL_cocoawindow.m	Tue Dec 01 12:08:34 2009 +0000
@@ -98,11 +98,10 @@
 - (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);
 }
 
@@ -245,11 +244,11 @@
         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);
         }
@@ -332,11 +331,10 @@
 
     /* 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;
     }
@@ -401,13 +399,13 @@
         || 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;
@@ -500,13 +498,13 @@
         || 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;