Fixing the build after Diederick Niehorster's full screen fixes: they are only valid...
[freeglut] / src / freeglut_callbacks.c
index 2dd2232..a40f7da 100644 (file)
 /*
  * All of the callbacks setting methods can be generalized to this:
  */
-#define SET_CALLBACK(a)                                  \
-do                                                       \
-{                                                        \
-    if( fgStructure.Window == NULL )                     \
-        return;                                          \
-    SET_WCB( ( *( fgStructure.Window ) ), a, callback ); \
+#define SET_CALLBACK(a)                                         \
+do                                                              \
+{                                                               \
+    if( fgStructure.CurrentWindow == NULL )                     \
+        return;                                                 \
+    SET_WCB( ( *( fgStructure.CurrentWindow ) ), a, callback ); \
 } while( 0 )
 
 /*
@@ -132,11 +132,11 @@ static void fghVisibility( int status )
     int glut_status = GLUT_VISIBLE;
 
     FREEGLUT_INTERNAL_ERROR_EXIT_IF_NOT_INITIALISED ( "Visibility Callback" );
-    freeglut_return_if_fail( fgStructure.Window );
+    freeglut_return_if_fail( fgStructure.CurrentWindow );
 
     if( ( GLUT_HIDDEN == status )  || ( GLUT_FULLY_COVERED == status ) )
         glut_status = GLUT_NOT_VISIBLE;
-    INVOKE_WCB( *( fgStructure.Window ), Visibility, ( glut_status ) );
+    INVOKE_WCB( *( fgStructure.CurrentWindow ), Visibility, ( glut_status ) );
 }
 
 void FGAPIENTRY glutVisibilityFunc( void (* callback)( int ) )
@@ -179,14 +179,23 @@ void FGAPIENTRY glutJoystickFunc( void (* callback)
     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutJoystickFunc" );
     fgInitialiseJoysticks ();
 
+    if ( ( ( fgStructure.CurrentWindow->State.JoystickPollRate < 0 ) ||
+           !FETCH_WCB(*fgStructure.CurrentWindow,Joystick) ) &&  /* Joystick callback was disabled */
+         ( callback && ( pollInterval >= 0 ) ) )               /* but is now enabled */
+        ++fgState.NumActiveJoysticks;
+    else if ( ( ( fgStructure.CurrentWindow->State.JoystickPollRate >= 0 ) &&
+                FETCH_WCB(*fgStructure.CurrentWindow,Joystick) ) &&  /* Joystick callback was enabled */
+              ( !callback || ( pollInterval < 0 ) ) )              /* but is now disabled */
+        --fgState.NumActiveJoysticks;
+
     SET_CALLBACK( Joystick );
-    fgStructure.Window->State.JoystickPollRate = pollInterval;
+    fgStructure.CurrentWindow->State.JoystickPollRate = pollInterval;
 
-    fgStructure.Window->State.JoystickLastPoll =
-        fgElapsedTime() - fgStructure.Window->State.JoystickPollRate;
+    fgStructure.CurrentWindow->State.JoystickLastPoll =
+        fgElapsedTime() - fgStructure.CurrentWindow->State.JoystickPollRate;
 
-    if( fgStructure.Window->State.JoystickLastPoll < 0 )
-        fgStructure.Window->State.JoystickLastPoll = 0;
+    if( fgStructure.CurrentWindow->State.JoystickLastPoll < 0 )
+        fgStructure.CurrentWindow->State.JoystickLastPoll = 0;
 }
 
 /*
@@ -255,8 +264,8 @@ void FGAPIENTRY glutWMCloseFunc( void (* callback)( void ) )
 void FGAPIENTRY glutMenuDestroyFunc( void (* callback)( void ) )
 {
     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMenuDestroyFunc" );
-    if( fgStructure.Menu )
-        fgStructure.Menu->Destroy = callback;
+    if( fgStructure.CurrentMenu )
+        fgStructure.CurrentMenu->Destroy = callback;
 }
 
 /*
@@ -301,6 +310,8 @@ void FGAPIENTRY glutWindowStatusFunc( void (* callback)( int ) )
 void FGAPIENTRY glutSpaceballMotionFunc( void (* callback)( int, int, int ) )
 {
     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSpaceballMotionFunc" );
+    fgInitialiseSpaceball();
+
     SET_CALLBACK( SpaceMotion );
 }
 
@@ -310,6 +321,8 @@ void FGAPIENTRY glutSpaceballMotionFunc( void (* callback)( int, int, int ) )
 void FGAPIENTRY glutSpaceballRotateFunc( void (* callback)( int, int, int ) )
 {
     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSpaceballRotateFunc" );
+    fgInitialiseSpaceball();
+
     SET_CALLBACK( SpaceRotation );
 }
 
@@ -319,6 +332,8 @@ void FGAPIENTRY glutSpaceballRotateFunc( void (* callback)( int, int, int ) )
 void FGAPIENTRY glutSpaceballButtonFunc( void (* callback)( int, int ) )
 {
     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSpaceballButtonFunc" );
+    fgInitialiseSpaceball();
+
     SET_CALLBACK( SpaceButton );
 }
 
@@ -358,4 +373,40 @@ void FGAPIENTRY glutTabletButtonFunc( void (* callback)( int, int, int, int ) )
     SET_CALLBACK( TabletButton );
 }
 
+/*
+ * Sets the multi-pointer entry callback for the current window
+ */
+void FGAPIENTRY glutMultiEntryFunc( void (* callback)(int, int ) )
+{
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMultiEntryFunc" );
+    SET_CALLBACK( MultiEntry );
+}
+
+/*
+ * Sets the multi-pointer button callback for the current window
+ */
+void FGAPIENTRY glutMultiButtonFunc( void (* callback)(int, int, int, int, int ) )
+{
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMultiButtonFunc" );
+    SET_CALLBACK( MultiButton );
+}
+
+/*
+ * Sets the multi-pointer motion callback for the current window
+ */
+void FGAPIENTRY glutMultiMotionFunc( void (* callback)(int, int, int ) )
+{
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMultiMotionFunc" );
+    SET_CALLBACK( MultiMotion );
+}
+
+/*
+ * Sets the multi-pointer passive motion callback for the current window
+ */
+void FGAPIENTRY glutMultiPassiveFunc( void (* callback)(int, int, int ) )
+{
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMultiPassiveFunc" );
+    SET_CALLBACK( MultiPassive );
+}
+
 /*** END OF FILE ***/