X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Ffreeglut_joystick.c;h=185ef1bf35f21e4fc5b8c7444c50116d89715223;hb=9dac5d0710b760ba04ebb6bbe9ee61041232c700;hp=a61a708a787518b484d8ef932d72038a56a6a0db;hpb=41e63805080267e9dbd100d30deac6ba0b34678e;p=freeglut diff --git a/src/freeglut_joystick.c b/src/freeglut_joystick.c index a61a708..185ef1b 100644 --- a/src/freeglut_joystick.c +++ b/src/freeglut_joystick.c @@ -450,7 +450,6 @@ static void fghJoystickAddHatElement ( SFG_Joystick* joy, CFDictionaryRef hat ); * The static joystick structure pointer */ #define MAX_NUM_JOYSTICKS 2 -static int fgNumberOfJoysticks = 0; static SFG_Joystick *fgJoystick [ MAX_NUM_JOYSTICKS ]; @@ -1528,7 +1527,7 @@ static void fghJoystickOpen( SFG_Joystick* joy ) /* * 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 ); @@ -1639,6 +1638,22 @@ void fgJoystickInit( int 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 ) @@ -1722,12 +1737,38 @@ void fgJoystickPollWindow( SFG_Window* window ) } /* - * 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; identerror ) + 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;