From: John F. Fay Date: Wed, 22 Jun 2005 21:37:26 +0000 (+0000) Subject: Joe Krahn\'s input (dials) device implementation. X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=commitdiff_plain;h=09070646b28804f0a700bd10b6caf8d606712d2c;p=freeglut Joe Krahn\'s input (dials) device implementation. git-svn-id: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@636 7f0cb862-5218-0410-a997-914c9d46530a --- diff --git a/src/Makefile.am b/src/Makefile.am index 20077b2..93195de 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -27,6 +27,7 @@ lib@LIBRARY@_la_SOURCES = freeglut_callbacks.c \ freeglut_gamemode.c \ freeglut_geometry.c \ freeglut_init.c \ + freeglut_input_devices.c \ freeglut_joystick.c \ freeglut_main.c \ freeglut_menu.c \ diff --git a/src/freeglut_init.c b/src/freeglut_init.c index 078192c..13310f7 100644 --- a/src/freeglut_init.c +++ b/src/freeglut_init.c @@ -82,7 +82,8 @@ SFG_State fgState = { { -1, -1, GL_FALSE }, /* Position */ GLUT_ACTION_EXIT, /* ActionOnWindowClose */ GLUT_EXEC_STATE_INIT, /* ExecState */ NULL, /* ProgramName */ - GL_FALSE /* JoysticksInitialised */ + GL_FALSE, /* JoysticksInitialised */ + GL_FALSE /* InputDevsInitialised */ }; @@ -202,6 +203,9 @@ static void fghInitialize( const char* displayName ) #endif fgState.Initialised = GL_TRUE; + + /* InputDevice uses GlutTimerFunc(), so fgState.Initialised must be TRUE */ + fgInitialiseInputDevices(); } /* @@ -242,8 +246,12 @@ void fgDeinitialize( void ) #if !TARGET_HOST_WINCE if ( fgState.JoysticksInitialised ) fgJoystickClose( ); + + if ( fgState.InputDevsInitialised ) + fgInputDeviceClose( ); #endif /* !TARGET_HOST_WINCE */ fgState.JoysticksInitialised = GL_FALSE; + fgState.InputDevsInitialised = GL_FALSE; fgState.Initialised = GL_FALSE; diff --git a/src/freeglut_internal.h b/src/freeglut_internal.h index 10086ea..185f9a4 100644 --- a/src/freeglut_internal.h +++ b/src/freeglut_internal.h @@ -244,6 +244,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 */ + GLboolean InputDevsInitialised; /* Only initialize if application calls for them */ }; /* The structure used by display initialization in freeglut_init.c */ @@ -772,6 +773,11 @@ int glutJoystickGetNumAxes( int ident ); int glutJoystickGetNumButtons( int ident ); int glutJoystickNotWorking( int ident ); +/* InputDevice Init/Fini */ +int fgInputDeviceDetect( void ); +void fgInitialiseInputDevices( void ); +void fgInputDeviceClose( void ); + /* Setting the cursor for a given window */ void fgSetCursor ( SFG_Window *window, int cursorID ); diff --git a/src/freeglut_joystick.c b/src/freeglut_joystick.c index 7548a88..b6fcdbc 100644 --- a/src/freeglut_joystick.c +++ b/src/freeglut_joystick.c @@ -1581,15 +1581,14 @@ static void fghJoystickInit( int ident ) */ 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 ); + if( !fgState.JoysticksInitialised ) + { + int ident ; + for ( ident = 0; ident < MAX_NUM_JOYSTICKS; ident++ ) + fghJoystickInit( ident ); - fgState.JoysticksInitialised = GL_TRUE; - } + fgState.JoysticksInitialised = GL_TRUE; + } } /* @@ -1680,21 +1679,21 @@ void fgJoystickPollWindow( SFG_Window* window ) */ int fgJoystickDetect( void ) { - int ident; + int ident; - fgInitialiseJoysticks (); + fgInitialiseJoysticks (); - if ( !fgJoystick ) - return 0; + if ( !fgJoystick ) + return 0; - if ( !fgState.JoysticksInitialised ) - return 0; + if ( !fgState.JoysticksInitialised ) + return 0; - for( ident=0; identerror ) - return 1; + for( ident=0; identerror ) + return 1; - return 0; + return 0; } /* diff --git a/src/freeglut_state.c b/src/freeglut_state.c index 4968b47..e8d2120 100644 --- a/src/freeglut_state.c +++ b/src/freeglut_state.c @@ -540,14 +540,21 @@ int FGAPIENTRY glutDeviceGet( GLenum eWhat ) case GLUT_JOYSTICK_AXES: return glutJoystickGetNumAxes ( 0 ); - case GLUT_HAS_SPACEBALL: case GLUT_HAS_DIAL_AND_BUTTON_BOX: + return fgInputDeviceDetect (); + + case GLUT_NUM_DIALS: + if ( fgState.InputDevsInitialised ) return 8; + return 0; + + case GLUT_NUM_BUTTON_BOX_BUTTONS: + return 0; + + case GLUT_HAS_SPACEBALL: case GLUT_HAS_TABLET: return FALSE; case GLUT_NUM_SPACEBALL_BUTTONS: - case GLUT_NUM_BUTTON_BOX_BUTTONS: - case GLUT_NUM_DIALS: case GLUT_NUM_TABLET_BUTTONS: return 0;