X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Ffreeglut_callbacks.c;h=4f6ad86ce38772ebe2c2b379c9aa25f031bee7e8;hb=3c7c46e5846a39dde8be85c131e69cab1d8cb1ec;hp=9ce8cfb2f202c11d7fe4d0ba55d0af07265f07ec;hpb=d296a46a2dccdd99048541e1f8ca0ef010ac8545;p=freeglut diff --git a/src/freeglut_callbacks.c b/src/freeglut_callbacks.c index 9ce8cfb..4f6ad86 100644 --- a/src/freeglut_callbacks.c +++ b/src/freeglut_callbacks.c @@ -25,23 +25,21 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - #include #include "freeglut_internal.h" - /* -- INTERFACE FUNCTIONS -------------------------------------------------- */ /* * All of the callbacks setting methods can be generalized to this: */ -#define SET_CALLBACK(a) \ - 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 ) /* * Sets the Display callback for the current window @@ -133,11 +131,12 @@ static void fghVisibility( int status ) { int glut_status = GLUT_VISIBLE; - freeglut_return_if_fail( fgStructure.Window ); + FREEGLUT_INTERNAL_ERROR_EXIT_IF_NOT_INITIALISED ( "Visibility Callback" ); + 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 ) ) @@ -180,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; } /* @@ -256,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; } /* @@ -302,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 ); } @@ -311,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 ); } @@ -320,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 ); }