The window position is display relative, at least for now...
authorSam Lantinga <slouken@libsdl.org>
Sun, 06 Dec 2009 08:39:01 +0000
changeset 3530e96be66e3673
parent 3529 09155ec3e291
child 3531 61b7f5821576
The window position is display relative, at least for now...
src/video/cocoa/SDL_cocoawindow.m
src/video/win32/SDL_win32window.c
     1.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Sun Dec 06 08:16:23 2009 +0000
     1.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Sun Dec 06 08:39:01 2009 +0000
     1.3 @@ -298,7 +298,8 @@
     1.4  {
     1.5      NSAutoreleasePool *pool;
     1.6      SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
     1.7 -    SDL_DisplayData *displaydata = (SDL_DisplayData *) SDL_GetDisplayFromWindow(window)->driverdata;
     1.8 +    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
     1.9 +    SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
    1.10      SDL_WindowData *data;
    1.11  
    1.12      /* Allocate the window data */
    1.13 @@ -321,10 +322,12 @@
    1.14  
    1.15      /* Fill in the SDL window with the window data */
    1.16      {
    1.17 +        SDL_Rect bounds;
    1.18          NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
    1.19          ConvertNSRect(&rect);
    1.20 -        window->x = (int)rect.origin.x;
    1.21 -        window->y = (int)rect.origin.y;
    1.22 +        Cocoa_GetDisplayBounds(_this, display, &bounds);
    1.23 +        window->x = (int)rect.origin.x - bounds.x;
    1.24 +        window->y = (int)rect.origin.y - bounds.y;
    1.25          window->w = (int)rect.size.width;
    1.26          window->h = (int)rect.size.height;
    1.27      }
    1.28 @@ -392,7 +395,7 @@
    1.29      } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
    1.30          rect.origin.x = bounds.x;
    1.31      } else {
    1.32 -        rect.origin.x = window->x;
    1.33 +        rect.origin.x = bounds.x + window->x;
    1.34      }
    1.35      if ((window->flags & SDL_WINDOW_FULLSCREEN)
    1.36          || window->y == SDL_WINDOWPOS_CENTERED) {
    1.37 @@ -400,7 +403,7 @@
    1.38      } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
    1.39          rect.origin.y = bounds.y;
    1.40      } else {
    1.41 -        rect.origin.y = window->y;
    1.42 +        rect.origin.y = bounds.y + window->y;
    1.43      }
    1.44      rect.size.width = window->w;
    1.45      rect.size.height = window->h;
    1.46 @@ -496,13 +499,13 @@
    1.47          || window->x == SDL_WINDOWPOS_CENTERED) {
    1.48          rect.origin.x = bounds.x + (bounds.w - window->w) / 2;
    1.49      } else {
    1.50 -        rect.origin.x = window->x;
    1.51 +        rect.origin.x = bounds.x + window->x;
    1.52      }
    1.53      if ((window->flags & SDL_WINDOW_FULLSCREEN)
    1.54          || window->y == SDL_WINDOWPOS_CENTERED) {
    1.55          rect.origin.y = bounds.y + (bounds.h - window->h) / 2;
    1.56      } else {
    1.57 -        rect.origin.y = window->y;
    1.58 +        rect.origin.y = bounds.y + window->y;
    1.59      }
    1.60      rect.size.width = window->w;
    1.61      rect.size.height = window->h;
     2.1 --- a/src/video/win32/SDL_win32window.c	Sun Dec 06 08:16:23 2009 +0000
     2.2 +++ b/src/video/win32/SDL_win32window.c	Sun Dec 06 08:39:01 2009 +0000
     2.3 @@ -86,6 +86,7 @@
     2.4  SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, SDL_bool created)
     2.5  {
     2.6      SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
     2.7 +    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
     2.8      SDL_WindowData *data;
     2.9  
    2.10      /* Allocate the window data */
    2.11 @@ -123,8 +124,10 @@
    2.12          point.x = 0;
    2.13          point.y = 0;
    2.14          if (ClientToScreen(hwnd, &point)) {
    2.15 -            window->x = point.x;
    2.16 -            window->y = point.y;
    2.17 +            SDL_Rect bounds;
    2.18 +            WIN_GetDisplayBounds(_this, display, &bounds);
    2.19 +            window->x = point.x - bounds.x;
    2.20 +            window->y = point.y - bounds.y;
    2.21          }
    2.22      }
    2.23      {
    2.24 @@ -232,7 +235,7 @@
    2.25              x = bounds.x;
    2.26          }
    2.27      } else {
    2.28 -        x = window->x + rect.left;
    2.29 +        x = bounds.x + window->x + rect.left;
    2.30      }
    2.31      if ((window->flags & SDL_WINDOW_FULLSCREEN)
    2.32          || window->y == SDL_WINDOWPOS_CENTERED) {
    2.33 @@ -244,7 +247,7 @@
    2.34              y = bounds.y;
    2.35          }
    2.36      } else {
    2.37 -        y = window->y + rect.top;
    2.38 +        y = bounds.y + window->y + rect.top;
    2.39      }
    2.40  
    2.41      hwnd =
    2.42 @@ -459,13 +462,13 @@
    2.43          || window->x == SDL_WINDOWPOS_CENTERED) {
    2.44          x = bounds.x + (bounds.w - window->w) / 2;
    2.45      } else {
    2.46 -        x = window->x + rect.left;
    2.47 +        x = bounds.x + window->x + rect.left;
    2.48      }
    2.49      if ((window->flags & SDL_WINDOW_FULLSCREEN)
    2.50          || window->y == SDL_WINDOWPOS_CENTERED) {
    2.51          y = bounds.y + (bounds.h - window->h) / 2;
    2.52      } else {
    2.53 -        y = window->y + rect.top;
    2.54 +        y = bounds.y + window->y + rect.top;
    2.55      }
    2.56  
    2.57      SetWindowPos(hwnd, top, x, y, 0, 0, (SWP_NOCOPYBITS | SWP_NOSIZE));