Cleans up AdjustWindowEx calls
This commit is contained in:
Sam Lantinga 2017-09-06 07:29:34 -07:00
parent 20c5bc9135
commit fa0eeff7f5
1 changed files with 36 additions and 51 deletions

View File

@ -80,15 +80,42 @@ GetWindowStyle(SDL_Window * window)
return style; return style;
} }
static void
WIN_AdjustWindowRectWithStyle( SDL_Window * window, DWORD style, BOOL menu, int * x, int * y, int * width, int * height )
{
RECT rect;
rect.left = 0;
rect.top = 0;
rect.right = window->w;
rect.bottom = window->h;
AdjustWindowRectEx( &rect, style, menu, 0 );
*x = window->x + rect.left;
*y = window->y + rect.top;
*width = (rect.right - rect.left);
*height = (rect.bottom - rect.top);
}
static void
WIN_AdjustWindowRect( SDL_Window * window, int * x, int * y, int * width, int * height )
{
SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
HWND hwnd = data->hwnd;
DWORD style;
BOOL menu;
style = GetWindowLong( hwnd, GWL_STYLE );
menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu( hwnd ) != NULL);
WIN_AdjustWindowRectWithStyle( window, style, menu, x, y, width, height );
}
static void static void
WIN_SetWindowPositionInternal(_THIS, SDL_Window * window, UINT flags) WIN_SetWindowPositionInternal(_THIS, SDL_Window * window, UINT flags)
{ {
SDL_WindowData *data = (SDL_WindowData *)window->driverdata; SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
HWND hwnd = data->hwnd; HWND hwnd = data->hwnd;
RECT rect;
DWORD style;
HWND top; HWND top;
BOOL menu;
int x, y; int x, y;
int w, h; int w, h;
@ -98,17 +125,8 @@ WIN_SetWindowPositionInternal(_THIS, SDL_Window * window, UINT flags)
} else { } else {
top = HWND_NOTOPMOST; top = HWND_NOTOPMOST;
} }
style = GetWindowLong(hwnd, GWL_STYLE);
rect.left = 0; WIN_AdjustWindowRect( window, &x, &y, &w, &h );
rect.top = 0;
rect.right = window->w;
rect.bottom = window->h;
menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL);
AdjustWindowRectEx(&rect, style, menu, 0);
w = (rect.right - rect.left);
h = (rect.bottom - rect.top);
x = window->x + rect.left;
y = window->y + rect.top;
data->expected_resize = SDL_TRUE; data->expected_resize = SDL_TRUE;
SetWindowPos(hwnd, top, x, y, w, h, flags); SetWindowPos(hwnd, top, x, y, w, h, flags);
@ -170,25 +188,11 @@ SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, HWND parent, SDL_bool cre
int h = rect.bottom; int h = rect.bottom;
if ((window->w && window->w != w) || (window->h && window->h != h)) { if ((window->w && window->w != w) || (window->h && window->h != h)) {
/* We tried to create a window larger than the desktop and Windows didn't allow it. Override! */ /* We tried to create a window larger than the desktop and Windows didn't allow it. Override! */
RECT rect;
DWORD style;
BOOL menu;
int x, y; int x, y;
int w, h; int w, h;
/* Figure out what the window area will be */ /* Figure out what the window area will be */
style = GetWindowLong(hwnd, GWL_STYLE); WIN_AdjustWindowRect( window, &x, &y, &w, &h );
rect.left = 0;
rect.top = 0;
rect.right = window->w;
rect.bottom = window->h;
menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL);
AdjustWindowRectEx(&rect, style, menu, 0);
w = (rect.right - rect.left);
h = (rect.bottom - rect.top);
x = window->x + rect.left;
y = window->y + rect.top;
SetWindowPos(hwnd, HWND_NOTOPMOST, x, y, w, h, SWP_NOCOPYBITS | SWP_NOZORDER | SWP_NOACTIVATE); SetWindowPos(hwnd, HWND_NOTOPMOST, x, y, w, h, SWP_NOCOPYBITS | SWP_NOZORDER | SWP_NOACTIVATE);
} else { } else {
window->w = w; window->w = w;
@ -272,7 +276,6 @@ int
WIN_CreateWindow(_THIS, SDL_Window * window) WIN_CreateWindow(_THIS, SDL_Window * window)
{ {
HWND hwnd, parent = NULL; HWND hwnd, parent = NULL;
RECT rect;
DWORD style = STYLE_BASIC; DWORD style = STYLE_BASIC;
int x, y; int x, y;
int w, h; int w, h;
@ -284,15 +287,7 @@ WIN_CreateWindow(_THIS, SDL_Window * window)
style |= GetWindowStyle(window); style |= GetWindowStyle(window);
/* Figure out what the window area will be */ /* Figure out what the window area will be */
rect.left = window->x; WIN_AdjustWindowRectWithStyle( window, style, FALSE, &x, &y, &w, &h );
rect.top = window->y;
rect.right = window->x + window->w;
rect.bottom = window->y + window->h;
AdjustWindowRectEx(&rect, style, FALSE, 0);
x = rect.left;
y = rect.top;
w = (rect.right - rect.left);
h = (rect.bottom - rect.top);
hwnd = hwnd =
CreateWindow(SDL_Appname, TEXT(""), style, x, y, w, h, parent, NULL, CreateWindow(SDL_Appname, TEXT(""), style, x, y, w, h, parent, NULL,
@ -556,11 +551,9 @@ WIN_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display,
{ {
SDL_WindowData *data = (SDL_WindowData *) window->driverdata; SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
HWND hwnd = data->hwnd; HWND hwnd = data->hwnd;
RECT rect;
SDL_Rect bounds; SDL_Rect bounds;
DWORD style; DWORD style;
HWND top; HWND top;
BOOL menu;
int x, y; int x, y;
int w, h; int w, h;
@ -600,16 +593,8 @@ WIN_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display,
style |= WS_MAXIMIZE; style |= WS_MAXIMIZE;
data->windowed_mode_was_maximized = SDL_FALSE; data->windowed_mode_was_maximized = SDL_FALSE;
} }
rect.left = 0;
rect.top = 0; WIN_AdjustWindowRect( window, &x, &y, &w, &h );
rect.right = window->windowed.w;
rect.bottom = window->windowed.h;
menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL);
AdjustWindowRectEx(&rect, style, menu, 0);
w = (rect.right - rect.left);
h = (rect.bottom - rect.top);
x = window->windowed.x + rect.left;
y = window->windowed.y + rect.top;
} }
SetWindowLong(hwnd, GWL_STYLE, style); SetWindowLong(hwnd, GWL_STYLE, style);
data->expected_resize = SDL_TRUE; data->expected_resize = SDL_TRUE;