comparison src/video/win32/SDL_win32window.c @ 3528:59ff7a2beb57

Added an API function to query geometry of multiple monitors: SDL_GetDisplayBounds() Implemented multi-monitor window positions on Windows
author Sam Lantinga <slouken@libsdl.org>
date Sun, 06 Dec 2009 08:03:38 +0000
parents 413672b09bb3
children e96be66e3673
comparison
equal deleted inserted replaced
3527:444cb12cadb6 3528:59ff7a2beb57
183 183
184 int 184 int
185 WIN_CreateWindow(_THIS, SDL_Window * window) 185 WIN_CreateWindow(_THIS, SDL_Window * window)
186 { 186 {
187 SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata; 187 SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
188 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
188 RAWINPUTDEVICE Rid; 189 RAWINPUTDEVICE Rid;
189 AXIS TabX, TabY; 190 AXIS TabX, TabY;
190 LOGCONTEXTA lc; 191 LOGCONTEXTA lc;
191 HWND hwnd; 192 HWND hwnd;
192 HWND top; 193 HWND top;
193 RECT rect; 194 RECT rect;
195 SDL_Rect bounds;
194 DWORD style = (WS_CLIPSIBLINGS | WS_CLIPCHILDREN); 196 DWORD style = (WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
195 int x, y; 197 int x, y;
196 int w, h; 198 int w, h;
197 199
198 if (window->flags & (SDL_WINDOW_BORDERLESS | SDL_WINDOW_FULLSCREEN)) { 200 if (window->flags & (SDL_WINDOW_BORDERLESS | SDL_WINDOW_FULLSCREEN)) {
217 rect.bottom = window->h; 219 rect.bottom = window->h;
218 AdjustWindowRectEx(&rect, style, FALSE, 0); 220 AdjustWindowRectEx(&rect, style, FALSE, 0);
219 w = (rect.right - rect.left); 221 w = (rect.right - rect.left);
220 h = (rect.bottom - rect.top); 222 h = (rect.bottom - rect.top);
221 223
224 WIN_GetDisplayBounds(_this, display, &bounds);
222 if ((window->flags & SDL_WINDOW_FULLSCREEN) 225 if ((window->flags & SDL_WINDOW_FULLSCREEN)
223 || window->x == SDL_WINDOWPOS_CENTERED) { 226 || window->x == SDL_WINDOWPOS_CENTERED) {
224 x = (GetSystemMetrics(SM_CXSCREEN) - w) / 2; 227 x = bounds.x + (bounds.w - window->w) / 2;
225 } else if (window->x == SDL_WINDOWPOS_UNDEFINED) { 228 } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
226 x = CW_USEDEFAULT; 229 if (bounds.x == 0) {
230 x = CW_USEDEFAULT;
231 } else {
232 x = bounds.x;
233 }
227 } else { 234 } else {
228 x = window->x + rect.left; 235 x = window->x + rect.left;
229 } 236 }
230 if ((window->flags & SDL_WINDOW_FULLSCREEN) 237 if ((window->flags & SDL_WINDOW_FULLSCREEN)
231 || window->y == SDL_WINDOWPOS_CENTERED) { 238 || window->y == SDL_WINDOWPOS_CENTERED) {
232 y = (GetSystemMetrics(SM_CYSCREEN) - h) / 2; 239 y = bounds.y + (bounds.h - window->h) / 2;
233 } else if (window->y == SDL_WINDOWPOS_UNDEFINED) { 240 } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
234 y = CW_USEDEFAULT; 241 if (bounds.x == 0) {
242 y = CW_USEDEFAULT;
243 } else {
244 y = bounds.y;
245 }
235 } else { 246 } else {
236 y = window->y + rect.top; 247 y = window->y + rect.top;
237 } 248 }
238 249
239 hwnd = 250 hwnd =
414 } 425 }
415 426
416 void 427 void
417 WIN_SetWindowPosition(_THIS, SDL_Window * window) 428 WIN_SetWindowPosition(_THIS, SDL_Window * window)
418 { 429 {
430 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
419 HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd; 431 HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
420 RECT rect; 432 RECT rect;
433 SDL_Rect bounds;
421 DWORD style; 434 DWORD style;
422 HWND top; 435 HWND top;
423 BOOL menu; 436 BOOL menu;
424 int x, y; 437 int x, y;
425 438
439 #else 452 #else
440 menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL); 453 menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL);
441 #endif 454 #endif
442 AdjustWindowRectEx(&rect, style, menu, 0); 455 AdjustWindowRectEx(&rect, style, menu, 0);
443 456
457 WIN_GetDisplayBounds(_this, display, &bounds);
444 if ((window->flags & SDL_WINDOW_FULLSCREEN) 458 if ((window->flags & SDL_WINDOW_FULLSCREEN)
445 || window->x == SDL_WINDOWPOS_CENTERED) { 459 || window->x == SDL_WINDOWPOS_CENTERED) {
446 x = (GetSystemMetrics(SM_CXSCREEN) - window->w) / 2; 460 x = bounds.x + (bounds.w - window->w) / 2;
447 } else { 461 } else {
448 x = window->x + rect.left; 462 x = window->x + rect.left;
449 } 463 }
450 if ((window->flags & SDL_WINDOW_FULLSCREEN) 464 if ((window->flags & SDL_WINDOW_FULLSCREEN)
451 || window->y == SDL_WINDOWPOS_CENTERED) { 465 || window->y == SDL_WINDOWPOS_CENTERED) {
452 y = (GetSystemMetrics(SM_CYSCREEN) - window->h) / 2; 466 y = bounds.y + (bounds.h - window->h) / 2;
453 } else { 467 } else {
454 y = window->y + rect.top; 468 y = window->y + rect.top;
455 } 469 }
456 470
457 SetWindowPos(hwnd, top, x, y, 0, 0, (SWP_NOCOPYBITS | SWP_NOSIZE)); 471 SetWindowPos(hwnd, top, x, y, 0, 0, (SWP_NOCOPYBITS | SWP_NOSIZE));