comparison src/video/win32/SDL_win32window.c @ 4486:237b1eb53e4d

Fixed fullscreen window position Fixed position calculation for centered windows
author Sam Lantinga <slouken@libsdl.org>
date Tue, 06 Jul 2010 08:22:36 -0700
parents 3e69e077cb95
children eff4e88cc1e8
comparison
equal deleted inserted replaced
4485:82d661ea0d5a 4486:237b1eb53e4d
182 int 182 int
183 WIN_CreateWindow(_THIS, SDL_Window * window) 183 WIN_CreateWindow(_THIS, SDL_Window * window)
184 { 184 {
185 SDL_VideoDisplay *display = window->display; 185 SDL_VideoDisplay *display = window->display;
186 HWND hwnd; 186 HWND hwnd;
187 HWND top;
188 RECT rect; 187 RECT rect;
189 SDL_Rect bounds; 188 SDL_Rect bounds;
190 DWORD style = (WS_CLIPSIBLINGS | WS_CLIPCHILDREN); 189 DWORD style = (WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
191 int x, y; 190 int x, y;
192 int w, h; 191 int w, h;
200 && !(window->flags & SDL_WINDOW_FULLSCREEN)) { 199 && !(window->flags & SDL_WINDOW_FULLSCREEN)) {
201 style |= (WS_THICKFRAME | WS_MAXIMIZEBOX); 200 style |= (WS_THICKFRAME | WS_MAXIMIZEBOX);
202 } 201 }
203 202
204 /* Figure out what the window area will be */ 203 /* Figure out what the window area will be */
205 if (window->flags & SDL_WINDOW_FULLSCREEN) {
206 top = HWND_TOPMOST;
207 } else {
208 top = HWND_NOTOPMOST;
209 }
210 rect.left = 0; 204 rect.left = 0;
211 rect.top = 0; 205 rect.top = 0;
212 rect.right = window->w; 206 rect.right = window->w;
213 rect.bottom = window->h; 207 rect.bottom = window->h;
214 AdjustWindowRectEx(&rect, style, FALSE, 0); 208 AdjustWindowRectEx(&rect, style, FALSE, 0);
215 w = (rect.right - rect.left); 209 w = (rect.right - rect.left);
216 h = (rect.bottom - rect.top); 210 h = (rect.bottom - rect.top);
217 211
218 WIN_GetDisplayBounds(_this, display, &bounds); 212 WIN_GetDisplayBounds(_this, display, &bounds);
213 if (window->flags & SDL_WINDOW_FULLSCREEN) {
214 /* The bounds when this window is visible is the fullscreen mode */
215 SDL_DisplayMode fullscreen_mode;
216 if (SDL_GetWindowDisplayMode(window, &fullscreen_mode) == 0) {
217 bounds.w = fullscreen_mode.w;
218 bounds.h = fullscreen_mode.h;
219 }
220 }
219 if ((window->flags & SDL_WINDOW_FULLSCREEN) 221 if ((window->flags & SDL_WINDOW_FULLSCREEN)
220 || window->x == SDL_WINDOWPOS_CENTERED) { 222 || window->x == SDL_WINDOWPOS_CENTERED) {
221 x = bounds.x + (bounds.w - window->w) / 2; 223 x = bounds.x + (bounds.w - w) / 2;
222 } else if (window->x == SDL_WINDOWPOS_UNDEFINED) { 224 } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
223 if (bounds.x == 0) { 225 if (bounds.x == 0) {
224 x = CW_USEDEFAULT; 226 x = CW_USEDEFAULT;
225 } else { 227 } else {
226 x = bounds.x; 228 x = bounds.x;
228 } else { 230 } else {
229 x = bounds.x + window->x + rect.left; 231 x = bounds.x + window->x + rect.left;
230 } 232 }
231 if ((window->flags & SDL_WINDOW_FULLSCREEN) 233 if ((window->flags & SDL_WINDOW_FULLSCREEN)
232 || window->y == SDL_WINDOWPOS_CENTERED) { 234 || window->y == SDL_WINDOWPOS_CENTERED) {
233 y = bounds.y + (bounds.h - window->h) / 2; 235 y = bounds.y + (bounds.h - h) / 2;
234 } else if (window->x == SDL_WINDOWPOS_UNDEFINED) { 236 } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
235 if (bounds.x == 0) { 237 if (bounds.x == 0) {
236 y = CW_USEDEFAULT; 238 y = CW_USEDEFAULT;
237 } else { 239 } else {
238 y = bounds.y; 240 y = bounds.y;
385 SDL_Rect bounds; 387 SDL_Rect bounds;
386 DWORD style; 388 DWORD style;
387 HWND top; 389 HWND top;
388 BOOL menu; 390 BOOL menu;
389 int x, y; 391 int x, y;
392 int w, h;
390 393
391 /* Figure out what the window area will be */ 394 /* Figure out what the window area will be */
392 if (window->flags & SDL_WINDOW_FULLSCREEN) { 395 if (window->flags & SDL_WINDOW_FULLSCREEN) {
393 top = HWND_TOPMOST; 396 top = HWND_TOPMOST;
394 } else { 397 } else {
403 menu = FALSE; 406 menu = FALSE;
404 #else 407 #else
405 menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL); 408 menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL);
406 #endif 409 #endif
407 AdjustWindowRectEx(&rect, style, menu, 0); 410 AdjustWindowRectEx(&rect, style, menu, 0);
411 w = (rect.right - rect.left);
412 h = (rect.bottom - rect.top);
408 413
409 WIN_GetDisplayBounds(_this, display, &bounds); 414 WIN_GetDisplayBounds(_this, display, &bounds);
415 if (window->flags & SDL_WINDOW_FULLSCREEN) {
416 /* The bounds when this window is visible is the fullscreen mode */
417 SDL_DisplayMode fullscreen_mode;
418 if (SDL_GetWindowDisplayMode(window, &fullscreen_mode) == 0) {
419 bounds.w = fullscreen_mode.w;
420 bounds.h = fullscreen_mode.h;
421 }
422 }
410 if ((window->flags & SDL_WINDOW_FULLSCREEN) 423 if ((window->flags & SDL_WINDOW_FULLSCREEN)
411 || window->x == SDL_WINDOWPOS_CENTERED) { 424 || window->x == SDL_WINDOWPOS_CENTERED) {
412 x = bounds.x + (bounds.w - window->w) / 2; 425 x = bounds.x + (bounds.w - w) / 2;
413 } else { 426 } else {
414 x = bounds.x + window->x + rect.left; 427 x = bounds.x + window->x + rect.left;
415 } 428 }
416 if ((window->flags & SDL_WINDOW_FULLSCREEN) 429 if ((window->flags & SDL_WINDOW_FULLSCREEN)
417 || window->y == SDL_WINDOWPOS_CENTERED) { 430 || window->y == SDL_WINDOWPOS_CENTERED) {
418 y = bounds.y + (bounds.h - window->h) / 2; 431 y = bounds.y + (bounds.h - h) / 2;
419 } else { 432 } else {
420 y = bounds.y + window->y + rect.top; 433 y = bounds.y + window->y + rect.top;
421 } 434 }
422 435
423 SetWindowPos(hwnd, top, x, y, 0, 0, (SWP_NOCOPYBITS | SWP_NOSIZE)); 436 SetWindowPos(hwnd, top, x, y, 0, 0, (SWP_NOCOPYBITS | SWP_NOSIZE));