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

Commit

Permalink
Fixed fullscreen window position
Browse files Browse the repository at this point in the history
Fixed position calculation for centered windows
  • Loading branch information
slouken committed Jul 6, 2010
1 parent d3e1a5b commit d0c3a38
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions src/video/win32/SDL_win32window.c
Expand Up @@ -184,7 +184,6 @@ WIN_CreateWindow(_THIS, SDL_Window * window)
{
SDL_VideoDisplay *display = window->display;
HWND hwnd;
HWND top;
RECT rect;
SDL_Rect bounds;
DWORD style = (WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
Expand All @@ -202,11 +201,6 @@ WIN_CreateWindow(_THIS, SDL_Window * window)
}

/* Figure out what the window area will be */
if (window->flags & SDL_WINDOW_FULLSCREEN) {
top = HWND_TOPMOST;
} else {
top = HWND_NOTOPMOST;
}
rect.left = 0;
rect.top = 0;
rect.right = window->w;
Expand All @@ -216,9 +210,17 @@ WIN_CreateWindow(_THIS, SDL_Window * window)
h = (rect.bottom - rect.top);

WIN_GetDisplayBounds(_this, display, &bounds);
if (window->flags & SDL_WINDOW_FULLSCREEN) {
/* The bounds when this window is visible is the fullscreen mode */
SDL_DisplayMode fullscreen_mode;
if (SDL_GetWindowDisplayMode(window, &fullscreen_mode) == 0) {
bounds.w = fullscreen_mode.w;
bounds.h = fullscreen_mode.h;
}
}
if ((window->flags & SDL_WINDOW_FULLSCREEN)
|| window->x == SDL_WINDOWPOS_CENTERED) {
x = bounds.x + (bounds.w - window->w) / 2;
x = bounds.x + (bounds.w - w) / 2;
} else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
if (bounds.x == 0) {
x = CW_USEDEFAULT;
Expand All @@ -230,7 +232,7 @@ WIN_CreateWindow(_THIS, SDL_Window * window)
}
if ((window->flags & SDL_WINDOW_FULLSCREEN)
|| window->y == SDL_WINDOWPOS_CENTERED) {
y = bounds.y + (bounds.h - window->h) / 2;
y = bounds.y + (bounds.h - h) / 2;
} else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
if (bounds.x == 0) {
y = CW_USEDEFAULT;
Expand Down Expand Up @@ -387,6 +389,7 @@ WIN_SetWindowPosition(_THIS, SDL_Window * window)
HWND top;
BOOL menu;
int x, y;
int w, h;

/* Figure out what the window area will be */
if (window->flags & SDL_WINDOW_FULLSCREEN) {
Expand All @@ -405,17 +408,27 @@ WIN_SetWindowPosition(_THIS, SDL_Window * window)
menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL);
#endif
AdjustWindowRectEx(&rect, style, menu, 0);
w = (rect.right - rect.left);
h = (rect.bottom - rect.top);

WIN_GetDisplayBounds(_this, display, &bounds);
if (window->flags & SDL_WINDOW_FULLSCREEN) {
/* The bounds when this window is visible is the fullscreen mode */
SDL_DisplayMode fullscreen_mode;
if (SDL_GetWindowDisplayMode(window, &fullscreen_mode) == 0) {
bounds.w = fullscreen_mode.w;
bounds.h = fullscreen_mode.h;
}
}
if ((window->flags & SDL_WINDOW_FULLSCREEN)
|| window->x == SDL_WINDOWPOS_CENTERED) {
x = bounds.x + (bounds.w - window->w) / 2;
x = bounds.x + (bounds.w - w) / 2;
} else {
x = bounds.x + window->x + rect.left;
}
if ((window->flags & SDL_WINDOW_FULLSCREEN)
|| window->y == SDL_WINDOWPOS_CENTERED) {
y = bounds.y + (bounds.h - window->h) / 2;
y = bounds.y + (bounds.h - h) / 2;
} else {
y = bounds.y + window->y + rect.top;
}
Expand Down

0 comments on commit d0c3a38

Please sign in to comment.