comparison src/video/win32/SDL_win32window.c @ 4749:0fa503d49cb4

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 0c39b36dd104
children 436183eb30c8
comparison
equal deleted inserted replaced
4748:d1ce08e2697f 4749:0fa503d49cb4
184 int 184 int
185 WIN_CreateWindow(_THIS, SDL_Window * window) 185 WIN_CreateWindow(_THIS, SDL_Window * window)
186 { 186 {
187 SDL_VideoDisplay *display = window->display; 187 SDL_VideoDisplay *display = window->display;
188 HWND hwnd; 188 HWND hwnd;
189 HWND top;
190 RECT rect; 189 RECT rect;
191 SDL_Rect bounds; 190 SDL_Rect bounds;
192 DWORD style = (WS_CLIPSIBLINGS | WS_CLIPCHILDREN); 191 DWORD style = (WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
193 int x, y; 192 int x, y;
194 int w, h; 193 int w, h;
202 && !(window->flags & SDL_WINDOW_FULLSCREEN)) { 201 && !(window->flags & SDL_WINDOW_FULLSCREEN)) {
203 style |= (WS_THICKFRAME | WS_MAXIMIZEBOX); 202 style |= (WS_THICKFRAME | WS_MAXIMIZEBOX);
204 } 203 }
205 204
206 /* Figure out what the window area will be */ 205 /* Figure out what the window area will be */
207 if (window->flags & SDL_WINDOW_FULLSCREEN) {
208 top = HWND_TOPMOST;
209 } else {
210 top = HWND_NOTOPMOST;
211 }
212 rect.left = 0; 206 rect.left = 0;
213 rect.top = 0; 207 rect.top = 0;
214 rect.right = window->w; 208 rect.right = window->w;
215 rect.bottom = window->h; 209 rect.bottom = window->h;
216 AdjustWindowRectEx(&rect, style, FALSE, 0); 210 AdjustWindowRectEx(&rect, style, FALSE, 0);
217 w = (rect.right - rect.left); 211 w = (rect.right - rect.left);
218 h = (rect.bottom - rect.top); 212 h = (rect.bottom - rect.top);
219 213
220 WIN_GetDisplayBounds(_this, display, &bounds); 214 WIN_GetDisplayBounds(_this, display, &bounds);
215 if (window->flags & SDL_WINDOW_FULLSCREEN) {
216 /* The bounds when this window is visible is the fullscreen mode */
217 SDL_DisplayMode fullscreen_mode;
218 if (SDL_GetWindowDisplayMode(window, &fullscreen_mode) == 0) {
219 bounds.w = fullscreen_mode.w;
220 bounds.h = fullscreen_mode.h;
221 }
222 }
221 if ((window->flags & SDL_WINDOW_FULLSCREEN) 223 if ((window->flags & SDL_WINDOW_FULLSCREEN)
222 || window->x == SDL_WINDOWPOS_CENTERED) { 224 || window->x == SDL_WINDOWPOS_CENTERED) {
223 x = bounds.x + (bounds.w - window->w) / 2; 225 x = bounds.x + (bounds.w - w) / 2;
224 } else if (window->x == SDL_WINDOWPOS_UNDEFINED) { 226 } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
225 if (bounds.x == 0) { 227 if (bounds.x == 0) {
226 x = CW_USEDEFAULT; 228 x = CW_USEDEFAULT;
227 } else { 229 } else {
228 x = bounds.x; 230 x = bounds.x;
230 } else { 232 } else {
231 x = bounds.x + window->x + rect.left; 233 x = bounds.x + window->x + rect.left;
232 } 234 }
233 if ((window->flags & SDL_WINDOW_FULLSCREEN) 235 if ((window->flags & SDL_WINDOW_FULLSCREEN)
234 || window->y == SDL_WINDOWPOS_CENTERED) { 236 || window->y == SDL_WINDOWPOS_CENTERED) {
235 y = bounds.y + (bounds.h - window->h) / 2; 237 y = bounds.y + (bounds.h - h) / 2;
236 } else if (window->x == SDL_WINDOWPOS_UNDEFINED) { 238 } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
237 if (bounds.x == 0) { 239 if (bounds.x == 0) {
238 y = CW_USEDEFAULT; 240 y = CW_USEDEFAULT;
239 } else { 241 } else {
240 y = bounds.y; 242 y = bounds.y;
387 SDL_Rect bounds; 389 SDL_Rect bounds;
388 DWORD style; 390 DWORD style;
389 HWND top; 391 HWND top;
390 BOOL menu; 392 BOOL menu;
391 int x, y; 393 int x, y;
394 int w, h;
392 395
393 /* Figure out what the window area will be */ 396 /* Figure out what the window area will be */
394 if (window->flags & SDL_WINDOW_FULLSCREEN) { 397 if (window->flags & SDL_WINDOW_FULLSCREEN) {
395 top = HWND_TOPMOST; 398 top = HWND_TOPMOST;
396 } else { 399 } else {
405 menu = FALSE; 408 menu = FALSE;
406 #else 409 #else
407 menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL); 410 menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL);
408 #endif 411 #endif
409 AdjustWindowRectEx(&rect, style, menu, 0); 412 AdjustWindowRectEx(&rect, style, menu, 0);
413 w = (rect.right - rect.left);
414 h = (rect.bottom - rect.top);
410 415
411 WIN_GetDisplayBounds(_this, display, &bounds); 416 WIN_GetDisplayBounds(_this, display, &bounds);
417 if (window->flags & SDL_WINDOW_FULLSCREEN) {
418 /* The bounds when this window is visible is the fullscreen mode */
419 SDL_DisplayMode fullscreen_mode;
420 if (SDL_GetWindowDisplayMode(window, &fullscreen_mode) == 0) {
421 bounds.w = fullscreen_mode.w;
422 bounds.h = fullscreen_mode.h;
423 }
424 }
412 if ((window->flags & SDL_WINDOW_FULLSCREEN) 425 if ((window->flags & SDL_WINDOW_FULLSCREEN)
413 || window->x == SDL_WINDOWPOS_CENTERED) { 426 || window->x == SDL_WINDOWPOS_CENTERED) {
414 x = bounds.x + (bounds.w - window->w) / 2; 427 x = bounds.x + (bounds.w - w) / 2;
415 } else { 428 } else {
416 x = bounds.x + window->x + rect.left; 429 x = bounds.x + window->x + rect.left;
417 } 430 }
418 if ((window->flags & SDL_WINDOW_FULLSCREEN) 431 if ((window->flags & SDL_WINDOW_FULLSCREEN)
419 || window->y == SDL_WINDOWPOS_CENTERED) { 432 || window->y == SDL_WINDOWPOS_CENTERED) {
420 y = bounds.y + (bounds.h - window->h) / 2; 433 y = bounds.y + (bounds.h - h) / 2;
421 } else { 434 } else {
422 y = bounds.y + window->y + rect.top; 435 y = bounds.y + window->y + rect.top;
423 } 436 }
424 437
425 SetWindowPos(hwnd, top, x, y, 0, 0, (SWP_NOCOPYBITS | SWP_NOSIZE)); 438 SetWindowPos(hwnd, top, x, y, 0, 0, (SWP_NOCOPYBITS | SWP_NOSIZE));