Joe Krahn\'s input (dials) device implementation.

git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@636 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
fayjf 2005-06-22 21:37:26 +00:00
parent 2ded92b062
commit a84f4042f0
5 changed files with 45 additions and 24 deletions

View File

@ -27,6 +27,7 @@ lib@LIBRARY@_la_SOURCES = freeglut_callbacks.c \
freeglut_gamemode.c \ freeglut_gamemode.c \
freeglut_geometry.c \ freeglut_geometry.c \
freeglut_init.c \ freeglut_init.c \
freeglut_input_devices.c \
freeglut_joystick.c \ freeglut_joystick.c \
freeglut_main.c \ freeglut_main.c \
freeglut_menu.c \ freeglut_menu.c \

View File

@ -82,7 +82,8 @@ SFG_State fgState = { { -1, -1, GL_FALSE }, /* Position */
GLUT_ACTION_EXIT, /* ActionOnWindowClose */ GLUT_ACTION_EXIT, /* ActionOnWindowClose */
GLUT_EXEC_STATE_INIT, /* ExecState */ GLUT_EXEC_STATE_INIT, /* ExecState */
NULL, /* ProgramName */ NULL, /* ProgramName */
GL_FALSE /* JoysticksInitialised */ GL_FALSE, /* JoysticksInitialised */
GL_FALSE /* InputDevsInitialised */
}; };
@ -202,6 +203,9 @@ static void fghInitialize( const char* displayName )
#endif #endif
fgState.Initialised = GL_TRUE; 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 !TARGET_HOST_WINCE
if ( fgState.JoysticksInitialised ) if ( fgState.JoysticksInitialised )
fgJoystickClose( ); fgJoystickClose( );
if ( fgState.InputDevsInitialised )
fgInputDeviceClose( );
#endif /* !TARGET_HOST_WINCE */ #endif /* !TARGET_HOST_WINCE */
fgState.JoysticksInitialised = GL_FALSE; fgState.JoysticksInitialised = GL_FALSE;
fgState.InputDevsInitialised = GL_FALSE;
fgState.Initialised = GL_FALSE; fgState.Initialised = GL_FALSE;

View File

@ -244,6 +244,7 @@ struct tagSFG_State
fgExecutionState ExecState; /* Used for GLUT termination */ fgExecutionState ExecState; /* Used for GLUT termination */
char *ProgramName; /* Name of the invoking program */ char *ProgramName; /* Name of the invoking program */
GLboolean JoysticksInitialised; /* Only initialize if application calls for them */ 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 */ /* The structure used by display initialization in freeglut_init.c */
@ -772,6 +773,11 @@ int glutJoystickGetNumAxes( int ident );
int glutJoystickGetNumButtons( int ident ); int glutJoystickGetNumButtons( int ident );
int glutJoystickNotWorking( 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 */ /* Setting the cursor for a given window */
void fgSetCursor ( SFG_Window *window, int cursorID ); void fgSetCursor ( SFG_Window *window, int cursorID );

View File

@ -1581,15 +1581,14 @@ static void fghJoystickInit( int ident )
*/ */
void fgInitialiseJoysticks ( void ) void fgInitialiseJoysticks ( void )
{ {
/* Initialization courtesy of OpenGLUT -- do we want it? */ if( !fgState.JoysticksInitialised )
if( !fgState.JoysticksInitialised ) {
{ int ident ;
int ident ; for ( ident = 0; ident < MAX_NUM_JOYSTICKS; ident++ )
for ( ident = 0; ident < MAX_NUM_JOYSTICKS; ident++ ) fghJoystickInit( ident );
fghJoystickInit( ident );
fgState.JoysticksInitialised = GL_TRUE; fgState.JoysticksInitialised = GL_TRUE;
} }
} }
/* /*
@ -1680,21 +1679,21 @@ void fgJoystickPollWindow( SFG_Window* window )
*/ */
int fgJoystickDetect( void ) int fgJoystickDetect( void )
{ {
int ident; int ident;
fgInitialiseJoysticks (); 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;
if ( !fgJoystick )
return 0; 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;
} }
/* /*

View File

@ -540,14 +540,21 @@ int FGAPIENTRY glutDeviceGet( GLenum eWhat )
case GLUT_JOYSTICK_AXES: case GLUT_JOYSTICK_AXES:
return glutJoystickGetNumAxes ( 0 ); return glutJoystickGetNumAxes ( 0 );
case GLUT_HAS_SPACEBALL:
case GLUT_HAS_DIAL_AND_BUTTON_BOX: 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: case GLUT_HAS_TABLET:
return FALSE; return FALSE;
case GLUT_NUM_SPACEBALL_BUTTONS: case GLUT_NUM_SPACEBALL_BUTTONS:
case GLUT_NUM_BUTTON_BOX_BUTTONS:
case GLUT_NUM_DIALS:
case GLUT_NUM_TABLET_BUTTONS: case GLUT_NUM_TABLET_BUTTONS:
return 0; return 0;