Nigel Stewart's Win32 window-sizing fix for game mode
authorJ.C. Jones <jc@insufficient.coffee>
Thu, 11 Dec 2003 18:53:06 +0000 (18:53 +0000)
committerJ.C. Jones <jc@insufficient.coffee>
Thu, 11 Dec 2003 18:53:06 +0000 (18:53 +0000)
git-svn-id: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@389 7f0cb862-5218-0410-a997-914c9d46530a

src/freeglut_gamemode.c
src/freeglut_main.c
src/freeglut_window.c

index 41b241b..b909655 100644 (file)
@@ -428,6 +428,8 @@ int FGAPIENTRY glutEnterGameMode( void )
         fgState.GameModeSize.X, fgState.GameModeSize.Y, GL_TRUE, GL_FALSE
     );
 
+    fgStructure.GameMode->State.IsGameMode = GL_TRUE;
+
 #if TARGET_HOST_UNIX_X11
 
     /* Move the window up to the topleft corner */
@@ -534,6 +536,8 @@ void FGAPIENTRY glutLeaveGameMode( void )
 {
     freeglut_return_if_fail( fgStructure.GameMode );
 
+    fgStructure.GameMode->State.IsGameMode = GL_FALSE;
+
     fgAddToWindowDestroyList( fgStructure.GameMode );
 
 #if TARGET_HOST_UNIX_X11
index 4a4d9c6..10266f8 100644 (file)
@@ -87,42 +87,49 @@ static void fghReshapeWindowByHandle ( SFG_WindowHandleType handle,
 #elif TARGET_HOST_WIN32
 
     {
-        RECT winRect;
-        int x, y;
+        RECT rect;
 
-        GetWindowRect( window->Window.Handle, &winRect );
-        x = winRect.left;
-        y = winRect.top;
+        /*
+         * For windowed mode, get the current position of the
+         * window and resize taking the size of the frame
+         * decorations into account.
+         */
+
+        GetWindowRect( window->Window.Handle, &rect );
+        rect.right  = rect.left + width;
+        rect.bottom = rect.top  + height;
 
         if ( window->Parent == NULL )
         {
-            /*
-             * Adjust the size of the window to allow for the size of the
-             * frame, if we are not a menu
-             */
-            if ( ! window->IsMenu )
+            if ( ! window->IsMenu && !window->State.IsGameMode )
             {
-                width += GetSystemMetrics( SM_CXSIZEFRAME ) * 2;
-                height += GetSystemMetrics( SM_CYSIZEFRAME ) * 2 +
-                    GetSystemMetrics( SM_CYCAPTION );
+                rect.right  += GetSystemMetrics( SM_CXSIZEFRAME ) * 2;
+                rect.bottom += GetSystemMetrics( SM_CYSIZEFRAME ) * 2 +
+                               GetSystemMetrics( SM_CYCAPTION );
             }
         }
         else
         {
-            GetWindowRect( window->Parent->Window.Handle,
-                           &winRect );
-            x -= winRect.left + GetSystemMetrics( SM_CXSIZEFRAME );
-            y -= winRect.top + GetSystemMetrics( SM_CYSIZEFRAME ) +
-                GetSystemMetrics( SM_CYCAPTION );
+            GetWindowRect( window->Parent->Window.Handle, &rect );
+            AdjustWindowRect ( &rect, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS |
+                                      WS_CLIPCHILDREN, FALSE );
         }
 
-        MoveWindow(
-            window->Window.Handle,
-            x,
-            y,
-            width,
-            height,
-            TRUE
+        /*
+         * SWP_NOACTIVATE      Do not activate the window
+         * SWP_NOOWNERZORDER   Do not change position in z-order
+         * SWP_NOSENDCHANGING  Supress WM_WINDOWPOSCHANGING message
+         * SWP_NOZORDER                Retains the current Z order (ignore 2nd param)
+         */
+
+        SetWindowPos( window->Window.Handle,
+                      HWND_TOP,
+                      rect.left,
+                      rect.top,
+                      rect.right  - rect.left,
+                      rect.bottom - rect.top,
+                      SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING |
+                      SWP_NOZORDER
         );
     }
 
index 07422f7..ca75807 100644 (file)
@@ -943,13 +943,39 @@ void FGAPIENTRY glutFullScreen( void )
         }
     }
 #elif TARGET_HOST_WIN32
-    MoveWindow(
-        fgStructure.Window->Window.Handle,
-        0, 0,
-        fgDisplay.ScreenWidth,
-        fgDisplay.ScreenHeight,
-        TRUE
-    );
+    {
+        RECT rect;
+
+        /* For fullscreen mode, force the top-left corner to 0,0
+         * and adjust the window rectangle so that the client area
+         * covers the whole screen.
+         */
+
+        rect.left   = 0;
+        rect.top    = 0;
+        rect.right  = fgDisplay.ScreenWidth;
+        rect.bottom = fgDisplay.ScreenHeight;
+
+        AdjustWindowRect ( &rect, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS |
+                                  WS_CLIPCHILDREN, FALSE );
+
+        /*
+         * SWP_NOACTIVATE      Do not activate the window
+         * SWP_NOOWNERZORDER   Do not change position in z-order
+         * SWP_NOSENDCHANGING  Supress WM_WINDOWPOSCHANGING message
+         * SWP_NOZORDER                Retains the current Z order (ignore 2nd param)
+         */
+
+        SetWindowPos( fgStructure.Window->Window.Handle,
+                      HWND_TOP,
+                      rect.left,
+                      rect.top,
+                      rect.right  - rect.left,
+                      rect.bottom - rect.top,
+                      SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING |
+                      SWP_NOZORDER
+                    );
+    }
 #endif
 }