( unsigned int, int, int, int ),
int pollInterval )
{
- if( !fgState.JoysticksInitialised )
- {
- fgJoystickInit( 0 );
- fgJoystickInit( 1 );
- fgState.JoysticksInitialised = GL_TRUE;
- }
+ fgInitialiseJoysticks ();
SET_CALLBACK( Joystick );
fgStructure.Window->State.JoystickPollRate = pollInterval;
void fgDestroyMenu( SFG_Menu* menu );
/* Joystick device management functions, defined in freeglut_joystick.c */
-void fgJoystickInit( int ident );
+int fgJoystickDetect( void );
+void fgInitialiseJoysticks( void );
void fgJoystickClose( void );
void fgJoystickPollWindow( SFG_Window* window );
+/* More joystick functions. Should these go into the API? */
+int glutJoystickGetNumAxes( int ident );
+int glutJoystickGetNumButtons( int ident );
+int glutJoystickNotWorking( int ident );
+
/*
* Helper function to enumerate through all registered windows
* and one to enumerate all of a window's subwindows...
* The static joystick structure pointer
*/
#define MAX_NUM_JOYSTICKS 2
-static int fgNumberOfJoysticks = 0;
static SFG_Joystick *fgJoystick [ MAX_NUM_JOYSTICKS ];
/*
* This function replaces the constructor method in the JS library.
*/
-void fgJoystickInit( int ident )
+static void fghJoystickInit( int ident )
{
if( ident >= MAX_NUM_JOYSTICKS )
fgError( "Too large a joystick number: %d", ident );
}
/*
+ * Try initializing all the joysticks (well, both of them)
+ */
+void fgInitialiseJoysticks ( void )
+{
+ /* Initialization courtesy of OpenGLUT -- do we want it? */
+ if( !fgState.JoysticksInitialised )
+ {
+ int ident ;
+ for ( ident = 0; ident < MAX_NUM_JOYSTICKS; ident++ )
+ fghJoystickInit( ident );
+
+ fgState.JoysticksInitialised = GL_TRUE;
+ }
+}
+
+/*
*
*/
void fgJoystickClose( void )
}
/*
- * PWO: These jsJoystick class methods have not been implemented.
+ * Implementation for glutDeviceGet(GLUT_HAS_JOYSTICK)
+ */
+int fgJoystickDetect( void )
+{
+ int ident;
+
+ fgInitialiseJoysticks ();
+
+ if ( !fgJoystick )
+ return 0;
+
+ if ( !fgState.JoysticksInitialised )
+ return 0;
+
+ for( ident=0; ident<MAX_NUM_JOYSTICKS; ident++ )
+ if( fgJoystick[ident] && !fgJoystick[ident]->error )
+ return 1;
+
+ return 0;
+}
+
+/*
+ * Joystick information functions
*/
int glutJoystickGetNumAxes( int ident )
{
return fgJoystick[ ident ]->num_axes;
}
+int glutJoystickGetNumButtons( int ident )
+{
+ return fgJoystick[ ident ]->num_buttons;
+}
int glutJoystickNotWorking( int ident )
{
return fgJoystick[ ident ]->error;
#endif
- case GLUT_JOYSTICK_POLL_RATE:
case GLUT_HAS_JOYSTICK:
+ return fgJoystickDetect ();
+
case GLUT_OWNS_JOYSTICK:
+ return fgState.JoysticksInitialised;
+
+ case GLUT_JOYSTICK_POLL_RATE:
+ return fgStructure.Window ? fgStructure.Window->State.JoystickPollRate : 0;
+
+ /* The following two are only for Joystick 0 but this is an improvement */
case GLUT_JOYSTICK_BUTTONS:
+ return glutJoystickGetNumButtons ( 0 );
+
case GLUT_JOYSTICK_AXES:
- /* XXX WARNING: THIS IS A BIG LIE! */
- return 0;
+ return glutJoystickGetNumAxes ( 0 );
case GLUT_HAS_SPACEBALL:
case GLUT_HAS_DIAL_AND_BUTTON_BOX: