joystick updates from John Fay
authorBrian Paul <brianp@vmware.com>
Fri, 10 Sep 2004 15:51:10 +0000 (15:51 +0000)
committerBrian Paul <brianp@vmware.com>
Fri, 10 Sep 2004 15:51:10 +0000 (15:51 +0000)
git-svn-id: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@513 7f0cb862-5218-0410-a997-914c9d46530a

src/freeglut_callbacks.c
src/freeglut_init.c
src/freeglut_internal.h
src/freeglut_main.c

index d7c998a..3e19c3e 100644 (file)
@@ -171,6 +171,13 @@ void FGAPIENTRY glutJoystickFunc( void (* callback)
                                   ( unsigned int, int, int, int ),
                                   int pollInterval )
 {
+    if( !fgState.JoysticksInitialised )
+    {
+        fgJoystickInit( 0 );
+        fgJoystickInit( 1 );
+        fgState.JoysticksInitialised = GL_TRUE;
+    }
+
     SET_CALLBACK( Joystick );
     fgStructure.Window->State.JoystickPollRate = pollInterval;
 
index 33a80f8..57df74e 100644 (file)
@@ -85,7 +85,8 @@ SFG_State fgState = { { -1, -1, GL_FALSE },  /* Position */
                       72,                     /* GameModeRefresh */
                       GLUT_ACTION_EXIT,       /* ActionOnWindowClose */
                       GLUT_EXEC_STATE_INIT,   /* ExecState */
-                      NULL                    /* ProgramName */
+                      NULL,                   /* ProgramName */
+                      GL_FALSE                /* JoysticksInitialised */
 };
 
 
@@ -201,11 +202,6 @@ void fgInitialize( const char* displayName )
 
 #endif
 
-#if !TARGET_HOST_WINCE
-    fgJoystickInit( 0 );
-    fgJoystickInit( 1 );
-#endif /* !TARGET_HOST_WINCE */
-
     fgState.Initialised = GL_TRUE;
 }
 
@@ -247,8 +243,10 @@ void fgDeinitialize( void )
     }
 
 #if !TARGET_HOST_WINCE
-    fgJoystickClose( );
+    if ( fgState.JoysticksInitialised )
+        fgJoystickClose( );
 #endif /* !TARGET_HOST_WINCE */
+    fgState.JoysticksInitialised = GL_FALSE;
 
     fgState.Initialised = GL_FALSE;
 
index 2e199be..1603df7 100644 (file)
@@ -167,7 +167,7 @@ struct tagSFG_XYUse
 typedef struct tagSFG_Time SFG_Time;
 struct tagSFG_Time
 {
-#ifdef WIN32
+#if TARGET_HOST_WIN32 || TARGET_HOST_WINCE
     DWORD Value;
 #else
     struct timeval  Value;
@@ -229,6 +229,7 @@ struct tagSFG_State
 
     fgExecutionState ExecState;           /* Used for GLUT termination       */
     char            *ProgramName;         /* Name of the invoking program    */
+    GLboolean        JoysticksInitialised;  /* Only initialize if application calls for them */
 };
 
 /* The structure used by display initialization in freeglut_init.c */
index 2e22721..5ad233c 100644 (file)
@@ -103,7 +103,8 @@ static void fghReshapeWindowByHandle ( SFG_WindowHandleType handle,
 
 #if !TARGET_HOST_WINCE
     {
-        RECT rect;
+        RECT winRect;
+        int x, y, w, h;
 
         /*
          * For windowed mode, get the current position of the
@@ -111,24 +112,29 @@ static void fghReshapeWindowByHandle ( SFG_WindowHandleType handle,
          * decorations into account.
          */
 
-        GetWindowRect( window->Window.Handle, &rect );
-        rect.right  = rect.left + width;
-        rect.bottom = rect.top  + height;
+        /* "GetWindowRect" returns the pixel coordinates of the outside of the window */
+        GetWindowRect( window->Window.Handle, &winRect );
+        x = winRect.left;
+        y = winRect.top;
+        w = width;
+        h = height;
 
         if ( window->Parent == NULL )
         {
             if ( ! window->IsMenu && !window->State.IsGameMode )
             {
-                rect.right  += GetSystemMetrics( SM_CXSIZEFRAME ) * 2;
-                rect.bottom += GetSystemMetrics( SM_CYSIZEFRAME ) * 2 +
-                               GetSystemMetrics( SM_CYCAPTION );
+                w += GetSystemMetrics( SM_CXSIZEFRAME ) * 2;
+                h += GetSystemMetrics( SM_CYSIZEFRAME ) * 2 +
+                     GetSystemMetrics( SM_CYCAPTION );
             }
         }
         else
         {
-            GetWindowRect( window->Parent->Window.Handle, &rect );
-            AdjustWindowRect ( &rect, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS |
-                                      WS_CLIPCHILDREN, FALSE );
+            RECT parentRect;
+            GetWindowRect( window->Parent->Window.Handle, &parentRect );
+            x -= parentRect.left + GetSystemMetrics( SM_CXSIZEFRAME ) * 2;
+            y -= parentRect.top  + GetSystemMetrics( SM_CYSIZEFRAME ) * 2 +
+                                   GetSystemMetrics( SM_CYCAPTION );
         }
 
         /*
@@ -140,10 +146,7 @@ static void fghReshapeWindowByHandle ( SFG_WindowHandleType handle,
 
         SetWindowPos( window->Window.Handle,
                       HWND_TOP,
-                      rect.left,
-                      rect.top,
-                      rect.right  - rect.left,
-                      rect.bottom - rect.top,
+                      x, y, w, h,
                       SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING |
                       SWP_NOZORDER
         );