comparison src/video/windib/SDL_dibvideo.c @ 833:31fa08b36380

Added support for SDL_VIDEO_WINDOW_POS and SDL_VIDEO_CENTERED on Windows
author Sam Lantinga <slouken@libsdl.org>
date Mon, 16 Feb 2004 21:09:24 +0000
parents ed57c876700d
children f72cc0c7305f
comparison
equal deleted inserted replaced
832:f003714db2f4 833:31fa08b36380
461 int binfo_size; 461 int binfo_size;
462 BITMAPINFO *binfo; 462 BITMAPINFO *binfo;
463 HDC hdc; 463 HDC hdc;
464 RECT bounds; 464 RECT bounds;
465 int x, y; 465 int x, y;
466 BOOL was_visible;
467 Uint32 Rmask, Gmask, Bmask; 466 Uint32 Rmask, Gmask, Bmask;
468
469 /* See whether or not we should center the window */
470 was_visible = IsWindowVisible(SDL_Window);
471 467
472 /* Clean up any GL context that may be hanging around */ 468 /* Clean up any GL context that may be hanging around */
473 if ( current->flags & SDL_OPENGL ) { 469 if ( current->flags & SDL_OPENGL ) {
474 WIN_GL_ShutDown(this); 470 WIN_GL_ShutDown(this);
475 } 471 }
597 if (IsZoomed(SDL_Window)) style |= WS_MAXIMIZE; 593 if (IsZoomed(SDL_Window)) style |= WS_MAXIMIZE;
598 #endif 594 #endif
599 } 595 }
600 596
601 /* DJM: Don't piss of anyone who has setup his own window */ 597 /* DJM: Don't piss of anyone who has setup his own window */
602 if (!SDL_windowid) 598 if ( SDL_windowid == NULL )
603 SetWindowLong(SDL_Window, GWL_STYLE, style); 599 SetWindowLong(SDL_Window, GWL_STYLE, style);
604 600
605 /* Delete the old bitmap if necessary */ 601 /* Delete the old bitmap if necessary */
606 if ( screen_bmp != NULL ) { 602 if ( screen_bmp != NULL ) {
607 DeleteObject(screen_bmp); 603 DeleteObject(screen_bmp);
676 672
677 /* Resize the window */ 673 /* Resize the window */
678 if ( SDL_windowid == NULL ) { 674 if ( SDL_windowid == NULL ) {
679 HWND top; 675 HWND top;
680 UINT swp_flags; 676 UINT swp_flags;
677 const char *window = getenv("SDL_VIDEO_WINDOW_POS");
678 const char *center = getenv("SDL_VIDEO_CENTERED");
679
680 if ( !SDL_windowX && !SDL_windowY ) {
681 if ( window ) {
682 if ( sscanf(window, "%d,%d", &x, &y) == 2 ) {
683 SDL_windowX = x;
684 SDL_windowY = y;
685 }
686 if ( strcmp(window, "center") == 0 ) {
687 center = window;
688 window = NULL;
689 }
690 }
691 }
692 swp_flags = (SWP_NOCOPYBITS | SWP_SHOWWINDOW);
681 693
682 SDL_resizing = 1; 694 SDL_resizing = 1;
683 bounds.left = 0; 695 bounds.left = SDL_windowX;
684 bounds.top = 0; 696 bounds.top = SDL_windowY;
685 bounds.right = video->w; 697 bounds.right = SDL_windowX+video->w;
686 bounds.bottom = video->h; 698 bounds.bottom = SDL_windowY+video->h;
687 AdjustWindowRectEx(&bounds, GetWindowLong(SDL_Window, GWL_STYLE), FALSE, 0); 699 AdjustWindowRectEx(&bounds, GetWindowLong(SDL_Window, GWL_STYLE), FALSE, 0);
688 width = bounds.right-bounds.left; 700 width = bounds.right-bounds.left;
689 height = bounds.bottom-bounds.top; 701 height = bounds.bottom-bounds.top;
690 x = (GetSystemMetrics(SM_CXSCREEN)-width)/2; 702 if ( (flags & SDL_FULLSCREEN) ) {
691 y = (GetSystemMetrics(SM_CYSCREEN)-height)/2; 703 x = (GetSystemMetrics(SM_CXSCREEN)-width)/2;
704 y = (GetSystemMetrics(SM_CYSCREEN)-height)/2;
705 } else if ( SDL_windowX || SDL_windowY || window ) {
706 x = bounds.left;
707 y = bounds.top;
708 } else if ( center ) {
709 x = (GetSystemMetrics(SM_CXSCREEN)-width)/2;
710 y = (GetSystemMetrics(SM_CYSCREEN)-height)/2;
711 } else {
712 x = y = -1;
713 swp_flags |= SWP_NOMOVE;
714 }
692 if ( y < 0 ) { /* Cover up title bar for more client area */ 715 if ( y < 0 ) { /* Cover up title bar for more client area */
693 y -= GetSystemMetrics(SM_CYCAPTION)/2; 716 y -= GetSystemMetrics(SM_CYCAPTION)/2;
694 }
695 swp_flags = (SWP_NOCOPYBITS | SWP_FRAMECHANGED | SWP_SHOWWINDOW);
696 if ( was_visible && !(flags & SDL_FULLSCREEN) ) {
697 swp_flags |= SWP_NOMOVE;
698 } 717 }
699 if ( flags & SDL_FULLSCREEN ) { 718 if ( flags & SDL_FULLSCREEN ) {
700 top = HWND_TOPMOST; 719 top = HWND_TOPMOST;
701 } else { 720 } else {
702 top = HWND_NOTOPMOST; 721 top = HWND_NOTOPMOST;