4 * The callbacks setting methods.
6 * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
7 * Written by Pawel W. Olszta, <olszta@sourceforge.net>
8 * Creation date: Fri Dec 3 1999
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 #include <GL/freeglut.h>
29 #include "fg_internal.h"
31 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
37 /* Sets the global idle callback */
38 void FGAPIENTRY glutIdleFunc( FGCBIdle callback )
40 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutIdleFunc" );
41 fgState.IdleCallback = callback;
44 /* Creates a timer and sets its callback */
45 void FGAPIENTRY glutTimerFunc( unsigned int timeOut, FGCBTimer callback, int timerID )
47 SFG_Timer *timer, *node;
49 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutTimerFunc" );
51 if( (timer = fgState.FreeTimers.Last) )
53 fgListRemove( &fgState.FreeTimers, &timer->Node );
57 if( ! (timer = malloc(sizeof(SFG_Timer))) )
58 fgError( "Fatal error: "
59 "Memory allocation failure in glutTimerFunc()" );
62 timer->Callback = callback;
64 timer->TriggerTime = fgElapsedTime() + timeOut;
66 for( node = fgState.Timers.First; node; node = node->Node.Next )
68 if( node->TriggerTime > timer->TriggerTime )
72 fgListInsert( &fgState.Timers, &node->Node, &timer->Node );
75 /* Deprecated version of glutMenuStatusFunc callback setting method */
76 void FGAPIENTRY glutMenuStateFunc( FGCBMenuState callback )
78 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMenuStateFunc" );
79 fgState.MenuStateCallback = callback;
82 /* Sets the global menu status callback for the current window */
83 void FGAPIENTRY glutMenuStatusFunc( FGCBMenuStatus callback )
85 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMenuStatusFunc" );
86 fgState.MenuStatusCallback = callback;
91 * Menu specific callbacks.
93 /* Callback upon menu destruction */
94 void FGAPIENTRY glutMenuDestroyFunc( FGCBDestroy callback )
96 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMenuDestroyFunc" );
97 if( fgStructure.CurrentMenu )
98 fgStructure.CurrentMenu->Destroy = callback;
103 * All of the window-specific callbacks setting methods can be generalized to this:
105 #define SET_CALLBACK(a) \
108 if( fgStructure.CurrentWindow == NULL ) \
110 SET_WCB( ( *( fgStructure.CurrentWindow ) ), a, callback ); \
114 * Sets the Display callback for the current window
116 void FGAPIENTRY glutDisplayFunc( FGCBDisplay callback )
118 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutDisplayFunc" );
120 fgError( "Fatal error in program. NULL display callback not "
121 "permitted in GLUT 3.0+ or freeglut 2.0.1+" );
122 SET_CALLBACK( Display );
126 * Sets the Reshape callback for the current window
128 void FGAPIENTRY glutReshapeFunc( FGCBReshape callback )
130 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutReshapeFunc" );
131 SET_CALLBACK( Reshape );
135 * Sets the Keyboard callback for the current window
137 void FGAPIENTRY glutKeyboardFunc( FGCBKeyboard callback )
139 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutKeyboardFunc" );
140 SET_CALLBACK( Keyboard );
144 * Sets the keyboard key release callback for the current window
146 void FGAPIENTRY glutKeyboardUpFunc( FGCBKeyboardUp callback )
148 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutKeyboardUpFunc" );
149 SET_CALLBACK( KeyboardUp );
153 * Sets the Special callback for the current window
155 void FGAPIENTRY glutSpecialFunc( FGCBSpecial callback )
157 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSpecialFunc" );
158 SET_CALLBACK( Special );
162 * Sets the special key release callback for the current window
164 void FGAPIENTRY glutSpecialUpFunc( FGCBSpecialUp callback )
166 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSpecialUpFunc" );
167 SET_CALLBACK( SpecialUp );
171 * Sets the Visibility callback for the current window.
173 static void fghVisibility( int status )
175 int glut_status = GLUT_VISIBLE;
177 FREEGLUT_INTERNAL_ERROR_EXIT_IF_NOT_INITIALISED ( "Visibility Callback" );
178 freeglut_return_if_fail( fgStructure.CurrentWindow );
180 if( ( GLUT_HIDDEN == status ) || ( GLUT_FULLY_COVERED == status ) )
181 glut_status = GLUT_NOT_VISIBLE;
182 INVOKE_WCB( *( fgStructure.CurrentWindow ), Visibility, ( glut_status ) );
185 void FGAPIENTRY glutVisibilityFunc( FGCBVisibility callback )
187 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutVisibilityFunc" );
188 SET_CALLBACK( Visibility );
191 glutWindowStatusFunc( fghVisibility );
193 glutWindowStatusFunc( NULL );
197 * Sets the joystick callback and polling rate for the current window
199 void FGAPIENTRY glutJoystickFunc( FGCBJoystick callback, int pollInterval )
201 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutJoystickFunc" );
202 fgInitialiseJoysticks ();
204 if ( ( ( fgStructure.CurrentWindow->State.JoystickPollRate < 0 ) ||
205 !FETCH_WCB(*fgStructure.CurrentWindow,Joystick) ) && /* Joystick callback was disabled */
206 ( callback && ( pollInterval >= 0 ) ) ) /* but is now enabled */
207 ++fgState.NumActiveJoysticks;
208 else if ( ( ( fgStructure.CurrentWindow->State.JoystickPollRate >= 0 ) &&
209 FETCH_WCB(*fgStructure.CurrentWindow,Joystick) ) && /* Joystick callback was enabled */
210 ( !callback || ( pollInterval < 0 ) ) ) /* but is now disabled */
211 --fgState.NumActiveJoysticks;
213 SET_CALLBACK( Joystick );
214 fgStructure.CurrentWindow->State.JoystickPollRate = pollInterval;
216 fgStructure.CurrentWindow->State.JoystickLastPoll =
217 fgElapsedTime() - fgStructure.CurrentWindow->State.JoystickPollRate;
219 if( fgStructure.CurrentWindow->State.JoystickLastPoll < 0 )
220 fgStructure.CurrentWindow->State.JoystickLastPoll = 0;
224 * Sets the mouse callback for the current window
226 void FGAPIENTRY glutMouseFunc( FGCBMouse callback )
228 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMouseFunc" );
229 SET_CALLBACK( Mouse );
233 * Sets the mouse wheel callback for the current window
235 void FGAPIENTRY glutMouseWheelFunc( FGCBMouseWheel callback )
237 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMouseWheelFunc" );
238 SET_CALLBACK( MouseWheel );
242 * Sets the mouse motion callback for the current window (one or more buttons
245 void FGAPIENTRY glutMotionFunc( FGCBMotion callback )
247 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMotionFunc" );
248 SET_CALLBACK( Motion );
252 * Sets the passive mouse motion callback for the current window (no mouse
253 * buttons are pressed)
255 void FGAPIENTRY glutPassiveMotionFunc( FGCBPassive callback )
257 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPassiveMotionFunc" );
258 SET_CALLBACK( Passive );
262 * Window mouse entry/leave callback
264 void FGAPIENTRY glutEntryFunc( FGCBEntry callback )
266 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutEntryFunc" );
267 SET_CALLBACK( Entry );
271 * Window destruction callbacks
273 void FGAPIENTRY glutCloseFunc( FGCBDestroy callback )
275 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutCloseFunc" );
276 SET_CALLBACK( Destroy );
279 void FGAPIENTRY glutWMCloseFunc( FGCBDestroy callback )
281 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWMCloseFunc" );
282 glutCloseFunc( callback );
286 * Sets the overlay display callback for the current window
288 void FGAPIENTRY glutOverlayDisplayFunc( FGCBOverlayDisplay callback )
290 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutOverlayDisplayFunc" );
291 SET_CALLBACK( OverlayDisplay );
295 * Sets the window status callback for the current window
297 void FGAPIENTRY glutWindowStatusFunc( FGCBWindowStatus callback )
299 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWindowStatusFunc" );
300 SET_CALLBACK( WindowStatus );
304 * Sets the spaceball motion callback for the current window
306 void FGAPIENTRY glutSpaceballMotionFunc( FGCBSpaceMotion callback )
308 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSpaceballMotionFunc" );
309 fgInitialiseSpaceball();
311 SET_CALLBACK( SpaceMotion );
315 * Sets the spaceball rotate callback for the current window
317 void FGAPIENTRY glutSpaceballRotateFunc( FGCBSpaceRotation callback )
319 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSpaceballRotateFunc" );
320 fgInitialiseSpaceball();
322 SET_CALLBACK( SpaceRotation );
326 * Sets the spaceball button callback for the current window
328 void FGAPIENTRY glutSpaceballButtonFunc( FGCBSpaceButton callback )
330 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSpaceballButtonFunc" );
331 fgInitialiseSpaceball();
333 SET_CALLBACK( SpaceButton );
337 * Sets the button box callback for the current window
339 void FGAPIENTRY glutButtonBoxFunc( FGCBButtonBox callback )
341 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutButtonBoxFunc" );
342 SET_CALLBACK( ButtonBox );
346 * Sets the dials box callback for the current window
348 void FGAPIENTRY glutDialsFunc( FGCBDials callback )
350 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutDialsFunc" );
351 SET_CALLBACK( Dials );
355 * Sets the tablet motion callback for the current window
357 void FGAPIENTRY glutTabletMotionFunc( FGCBTabletMotion callback )
359 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutTabletMotionFunc" );
360 SET_CALLBACK( TabletMotion );
364 * Sets the tablet buttons callback for the current window
366 void FGAPIENTRY glutTabletButtonFunc( FGCBTabletButton callback )
368 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutTabletButtonFunc" );
369 SET_CALLBACK( TabletButton );
373 * Sets the multi-pointer entry callback for the current window
375 void FGAPIENTRY glutMultiEntryFunc( FGCBMultiEntry callback )
377 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMultiEntryFunc" );
378 SET_CALLBACK( MultiEntry );
382 * Sets the multi-pointer button callback for the current window
384 void FGAPIENTRY glutMultiButtonFunc( FGCBMultiButton callback )
386 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMultiButtonFunc" );
387 SET_CALLBACK( MultiButton );
391 * Sets the multi-pointer motion callback for the current window
393 void FGAPIENTRY glutMultiMotionFunc( FGCBMultiMotion callback )
395 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMultiMotionFunc" );
396 SET_CALLBACK( MultiMotion );
400 * Sets the multi-pointer passive motion callback for the current window
402 void FGAPIENTRY glutMultiPassiveFunc( FGCBMultiPassive callback )
404 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMultiPassiveFunc" );
405 SET_CALLBACK( MultiPassive );
409 * Sets the context reload callback for the current window
411 void FGAPIENTRY glutInitContextFunc( FGCBInitContext callback )
413 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutInitContextFunc" );
414 SET_CALLBACK( InitContext );
418 * Sets the pause callback for the current window
420 void FGAPIENTRY glutPauseFunc( FGCBPause callback )
422 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPauseFunc" );
423 SET_CALLBACK( Pause );
427 * Sets the resume callback for the current window
429 void FGAPIENTRY glutResumeFunc( FGCBResume callback )
431 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutResumeFunc" );
432 SET_CALLBACK( Resume );
435 /*** END OF FILE ***/