Moving some Windows-specific code out of "freeglut_main.c" into the Windows-specific...
[freeglut] / src / mswin / freeglut_main_mswin.c
index e69de29..6a7fbc2 100644 (file)
@@ -0,0 +1,123 @@
+/*\r
+ * freeglut_main_mswin.c\r
+ *\r
+ * The Windows-specific mouse cursor related stuff.\r
+ *\r
+ * Copyright (c) 2012 Stephen J. Baker. All Rights Reserved.\r
+ * Written by John F. Fay, <fayjf@sourceforge.net>\r
+ * Creation date: Sat Jan 21, 2012\r
+ *\r
+ * Permission is hereby granted, free of charge, to any person obtaining a\r
+ * copy of this software and associated documentation files (the "Software"),\r
+ * to deal in the Software without restriction, including without limitation\r
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+ * and/or sell copies of the Software, and to permit persons to whom the\r
+ * Software is furnished to do so, subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included\r
+ * in all copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL\r
+ * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ */\r
+\r
+#include <GL/freeglut.h>\r
+#include "freeglut_internal_mswin.h"\r
+\r
+\r
+\r
+\r
+void fghPlatformReshapeWindow ( SFG_Window *window, int width, int height )\r
+{\r
+    RECT windowRect;\r
+\r
+    /*\r
+     * For windowed mode, get the current position of the\r
+     * window and resize taking the size of the frame\r
+     * decorations into account.\r
+     */\r
+\r
+    /* "GetWindowRect" returns the pixel coordinates of the outside of the window */\r
+    GetWindowRect( window->Window.Handle, &windowRect );\r
+\r
+    /* Create rect in FreeGLUT format, (X,Y) topleft outside window, WxH of client area */\r
+    windowRect.right    = windowRect.left+width;\r
+    windowRect.bottom   = windowRect.top+height;\r
+\r
+    if (window->Parent == NULL)\r
+        /* get the window rect from this to feed to SetWindowPos, correct for window decorations */\r
+        fghComputeWindowRectFromClientArea_QueryWindow(window,&windowRect,TRUE);\r
+    else\r
+    {\r
+        /* correct rect for position client area of parent window\r
+         * (SetWindowPos input for child windows is in coordinates\r
+         * relative to the parent's client area).\r
+         * Child windows don't have decoration, so no need to correct\r
+         * for them.\r
+         */\r
+        RECT parentRect;\r
+        parentRect = fghGetClientArea( window->Parent, FALSE );\r
+        windowRect.left   -= parentRect.left;\r
+        windowRect.right  -= parentRect.left;\r
+        windowRect.top    -= parentRect.top;\r
+        windowRect.bottom -= parentRect.top;\r
+    }\r
+    \r
+    /* Do the actual resizing */\r
+    SetWindowPos( window->Window.Handle,\r
+                  HWND_TOP,\r
+                  windowRect.left, windowRect.top,\r
+                  windowRect.right - windowRect.left,\r
+                  windowRect.bottom- windowRect.top,\r
+                  SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING |\r
+                  SWP_NOZORDER\r
+    );\r
+}\r
+\r
+\r
+void fghcbPlatformDisplayWindow ( SFG_Window *window )\r
+{\r
+    RedrawWindow(\r
+        window->Window.Handle, NULL, NULL,\r
+        RDW_NOERASE | RDW_INTERNALPAINT | RDW_INVALIDATE | RDW_UPDATENOW\r
+    );\r
+}\r
+\r
+\r
+void fghPlatformSleepForEvents( long msec )\r
+{\r
+    MsgWaitForMultipleObjects( 0, NULL, FALSE, msec, QS_ALLINPUT );\r
+}\r
+\r
+\r
+void fghProcessSingleEvent ( void )\r
+{\r
+    MSG stMsg;\r
+\r
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMainLoopEvent" );\r
+\r
+    while( PeekMessage( &stMsg, NULL, 0, 0, PM_NOREMOVE ) )\r
+    {\r
+        if( GetMessage( &stMsg, NULL, 0, 0 ) == 0 )\r
+        {\r
+            if( fgState.ActionOnWindowClose == GLUT_ACTION_EXIT )\r
+            {\r
+                fgDeinitialize( );\r
+                exit( 0 );\r
+            }\r
+            else if( fgState.ActionOnWindowClose == GLUT_ACTION_GLUTMAINLOOP_RETURNS )\r
+                fgState.ExecState = GLUT_EXEC_STATE_STOP;\r
+\r
+            return;\r
+        }\r
+\r
+        TranslateMessage( &stMsg );\r
+        DispatchMessage( &stMsg );\r
+    }\r
+}\r
+\r
+\r