Fixed fullscreen window position
authorSam Lantinga
Tue, 06 Jul 2010 08:22:36 -0700
changeset 47490fa503d49cb4
parent 4748 d1ce08e2697f
child 4750 22aa6a631d34
Fixed fullscreen window position
Fixed position calculation for centered windows
src/video/win32/SDL_win32window.c
     1.1 --- a/src/video/win32/SDL_win32window.c	Tue Jul 06 03:27:22 2010 -0400
     1.2 +++ b/src/video/win32/SDL_win32window.c	Tue Jul 06 08:22:36 2010 -0700
     1.3 @@ -186,7 +186,6 @@
     1.4  {
     1.5      SDL_VideoDisplay *display = window->display;
     1.6      HWND hwnd;
     1.7 -    HWND top;
     1.8      RECT rect;
     1.9      SDL_Rect bounds;
    1.10      DWORD style = (WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
    1.11 @@ -204,11 +203,6 @@
    1.12      }
    1.13  
    1.14      /* Figure out what the window area will be */
    1.15 -    if (window->flags & SDL_WINDOW_FULLSCREEN) {
    1.16 -        top = HWND_TOPMOST;
    1.17 -    } else {
    1.18 -        top = HWND_NOTOPMOST;
    1.19 -    }
    1.20      rect.left = 0;
    1.21      rect.top = 0;
    1.22      rect.right = window->w;
    1.23 @@ -218,9 +212,17 @@
    1.24      h = (rect.bottom - rect.top);
    1.25  
    1.26      WIN_GetDisplayBounds(_this, display, &bounds);
    1.27 +    if (window->flags & SDL_WINDOW_FULLSCREEN) {
    1.28 +        /* The bounds when this window is visible is the fullscreen mode */
    1.29 +        SDL_DisplayMode fullscreen_mode;
    1.30 +        if (SDL_GetWindowDisplayMode(window, &fullscreen_mode) == 0) {
    1.31 +            bounds.w = fullscreen_mode.w;
    1.32 +            bounds.h = fullscreen_mode.h;
    1.33 +        }
    1.34 +    }
    1.35      if ((window->flags & SDL_WINDOW_FULLSCREEN)
    1.36          || window->x == SDL_WINDOWPOS_CENTERED) {
    1.37 -        x = bounds.x + (bounds.w - window->w) / 2;
    1.38 +        x = bounds.x + (bounds.w - w) / 2;
    1.39      } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
    1.40          if (bounds.x == 0) {
    1.41              x = CW_USEDEFAULT;
    1.42 @@ -232,7 +234,7 @@
    1.43      }
    1.44      if ((window->flags & SDL_WINDOW_FULLSCREEN)
    1.45          || window->y == SDL_WINDOWPOS_CENTERED) {
    1.46 -        y = bounds.y + (bounds.h - window->h) / 2;
    1.47 +        y = bounds.y + (bounds.h - h) / 2;
    1.48      } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
    1.49          if (bounds.x == 0) {
    1.50              y = CW_USEDEFAULT;
    1.51 @@ -389,6 +391,7 @@
    1.52      HWND top;
    1.53      BOOL menu;
    1.54      int x, y;
    1.55 +    int w, h;
    1.56  
    1.57      /* Figure out what the window area will be */
    1.58      if (window->flags & SDL_WINDOW_FULLSCREEN) {
    1.59 @@ -407,17 +410,27 @@
    1.60      menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL);
    1.61  #endif
    1.62      AdjustWindowRectEx(&rect, style, menu, 0);
    1.63 +    w = (rect.right - rect.left);
    1.64 +    h = (rect.bottom - rect.top);
    1.65  
    1.66      WIN_GetDisplayBounds(_this, display, &bounds);
    1.67 +    if (window->flags & SDL_WINDOW_FULLSCREEN) {
    1.68 +        /* The bounds when this window is visible is the fullscreen mode */
    1.69 +        SDL_DisplayMode fullscreen_mode;
    1.70 +        if (SDL_GetWindowDisplayMode(window, &fullscreen_mode) == 0) {
    1.71 +            bounds.w = fullscreen_mode.w;
    1.72 +            bounds.h = fullscreen_mode.h;
    1.73 +        }
    1.74 +    }
    1.75      if ((window->flags & SDL_WINDOW_FULLSCREEN)
    1.76          || window->x == SDL_WINDOWPOS_CENTERED) {
    1.77 -        x = bounds.x + (bounds.w - window->w) / 2;
    1.78 +        x = bounds.x + (bounds.w - w) / 2;
    1.79      } else {
    1.80          x = bounds.x + window->x + rect.left;
    1.81      }
    1.82      if ((window->flags & SDL_WINDOW_FULLSCREEN)
    1.83          || window->y == SDL_WINDOWPOS_CENTERED) {
    1.84 -        y = bounds.y + (bounds.h - window->h) / 2;
    1.85 +        y = bounds.y + (bounds.h - h) / 2;
    1.86      } else {
    1.87          y = bounds.y + window->y + rect.top;
    1.88      }