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 "freeglut_internal.h"
31 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
34 * All of the callbacks setting methods can be generalized to this:
36 #define SET_CALLBACK(a) \
39 if( fgStructure.CurrentWindow == NULL ) \
41 SET_WCB( ( *( fgStructure.CurrentWindow ) ), a, callback ); \
45 * Sets the Display callback for the current window
47 void FGAPIENTRY glutDisplayFunc( void (* callback)( void ) )
49 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutDisplayFunc" );
51 fgError( "Fatal error in program. NULL display callback not "
52 "permitted in GLUT 3.0+ or freeglut 2.0.1+" );
53 SET_CALLBACK( Display );
57 * Sets the Reshape callback for the current window
59 void FGAPIENTRY glutReshapeFunc( void (* callback)( int, int ) )
61 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutReshapeFunc" );
62 SET_CALLBACK( Reshape );
66 * Sets the Keyboard callback for the current window
68 void FGAPIENTRY glutKeyboardFunc( void (* callback)
69 ( unsigned char, int, int ) )
71 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutKeyboardFunc" );
72 SET_CALLBACK( Keyboard );
76 * Sets the Special callback for the current window
78 void FGAPIENTRY glutSpecialFunc( void (* callback)( int, int, int ) )
80 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSpecialFunc" );
81 SET_CALLBACK( Special );
85 * Sets the global idle callback
87 void FGAPIENTRY glutIdleFunc( void (* callback)( void ) )
89 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutIdleFunc" );
90 fgState.IdleCallback = callback;
94 * Sets the Timer callback for the current window
96 void FGAPIENTRY glutTimerFunc( unsigned int timeOut, void (* callback)( int ),
99 SFG_Timer *timer, *node;
101 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutTimerFunc" );
103 if( (timer = fgState.FreeTimers.Last) )
105 fgListRemove( &fgState.FreeTimers, &timer->Node );
109 if( ! (timer = malloc(sizeof(SFG_Timer))) )
110 fgError( "Fatal error: "
111 "Memory allocation failure in glutTimerFunc()" );
114 timer->Callback = callback;
116 timer->TriggerTime = fgElapsedTime() + timeOut;
118 for( node = fgState.Timers.First; node; node = node->Node.Next )
120 if( node->TriggerTime > timer->TriggerTime )
124 fgListInsert( &fgState.Timers, &node->Node, &timer->Node );
128 * Sets the Visibility callback for the current window.
130 static void fghVisibility( int status )
132 int glut_status = GLUT_VISIBLE;
134 FREEGLUT_INTERNAL_ERROR_EXIT_IF_NOT_INITIALISED ( "Visibility Callback" );
135 freeglut_return_if_fail( fgStructure.CurrentWindow );
137 if( ( GLUT_HIDDEN == status ) || ( GLUT_FULLY_COVERED == status ) )
138 glut_status = GLUT_NOT_VISIBLE;
139 INVOKE_WCB( *( fgStructure.CurrentWindow ), Visibility, ( glut_status ) );
142 void FGAPIENTRY glutVisibilityFunc( void (* callback)( int ) )
144 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutVisibilityFunc" );
145 SET_CALLBACK( Visibility );
148 glutWindowStatusFunc( fghVisibility );
150 glutWindowStatusFunc( NULL );
154 * Sets the keyboard key release callback for the current window
156 void FGAPIENTRY glutKeyboardUpFunc( void (* callback)
157 ( unsigned char, int, int ) )
159 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutKeyboardUpFunc" );
160 SET_CALLBACK( KeyboardUp );
164 * Sets the special key release callback for the current window
166 void FGAPIENTRY glutSpecialUpFunc( void (* callback)( int, int, int ) )
168 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSpecialUpFunc" );
169 SET_CALLBACK( SpecialUp );
173 * Sets the joystick callback and polling rate for the current window
175 void FGAPIENTRY glutJoystickFunc( void (* callback)
176 ( unsigned int, int, int, int ),
179 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutJoystickFunc" );
180 fgInitialiseJoysticks ();
182 if ( ( ( fgStructure.CurrentWindow->State.JoystickPollRate < 0 ) ||
183 !FETCH_WCB(*fgStructure.CurrentWindow,Joystick) ) && /* Joystick callback was disabled */
184 ( callback && ( pollInterval >= 0 ) ) ) /* but is now enabled */
185 ++fgState.NumActiveJoysticks;
186 else if ( ( ( fgStructure.CurrentWindow->State.JoystickPollRate >= 0 ) &&
187 FETCH_WCB(*fgStructure.CurrentWindow,Joystick) ) && /* Joystick callback was enabled */
188 ( !callback || ( pollInterval < 0 ) ) ) /* but is now disabled */
189 --fgState.NumActiveJoysticks;
191 SET_CALLBACK( Joystick );
192 fgStructure.CurrentWindow->State.JoystickPollRate = pollInterval;
194 fgStructure.CurrentWindow->State.JoystickLastPoll =
195 fgElapsedTime() - fgStructure.CurrentWindow->State.JoystickPollRate;
197 if( fgStructure.CurrentWindow->State.JoystickLastPoll < 0 )
198 fgStructure.CurrentWindow->State.JoystickLastPoll = 0;
202 * Sets the mouse callback for the current window
204 void FGAPIENTRY glutMouseFunc( void (* callback)( int, int, int, int ) )
206 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMouseFunc" );
207 SET_CALLBACK( Mouse );
211 * Sets the mouse wheel callback for the current window
213 void FGAPIENTRY glutMouseWheelFunc( void (* callback)( int, int, int, int ) )
215 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMouseWheelFunc" );
216 SET_CALLBACK( MouseWheel );
220 * Sets the mouse motion callback for the current window (one or more buttons
223 void FGAPIENTRY glutMotionFunc( void (* callback)( int, int ) )
225 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMotionFunc" );
226 SET_CALLBACK( Motion );
230 * Sets the passive mouse motion callback for the current window (no mouse
231 * buttons are pressed)
233 void FGAPIENTRY glutPassiveMotionFunc( void (* callback)( int, int ) )
235 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPassiveMotionFunc" );
236 SET_CALLBACK( Passive );
240 * Window mouse entry/leave callback
242 void FGAPIENTRY glutEntryFunc( void (* callback)( int ) )
244 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutEntryFunc" );
245 SET_CALLBACK( Entry );
249 * Window destruction callbacks
251 void FGAPIENTRY glutCloseFunc( void (* callback)( void ) )
253 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutCloseFunc" );
254 SET_CALLBACK( Destroy );
257 void FGAPIENTRY glutWMCloseFunc( void (* callback)( void ) )
259 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWMCloseFunc" );
260 glutCloseFunc( callback );
263 /* A. Donev: Destruction callback for menus */
264 void FGAPIENTRY glutMenuDestroyFunc( void (* callback)( void ) )
266 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMenuDestroyFunc" );
267 if( fgStructure.CurrentMenu )
268 fgStructure.CurrentMenu->Destroy = callback;
272 * Deprecated version of glutMenuStatusFunc callback setting method
274 void FGAPIENTRY glutMenuStateFunc( void (* callback)( int ) )
276 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMenuStateFunc" );
277 fgState.MenuStateCallback = callback;
281 * Sets the global menu status callback for the current window
283 void FGAPIENTRY glutMenuStatusFunc( void (* callback)( int, int, int ) )
285 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMenuStatusFunc" );
286 fgState.MenuStatusCallback = callback;
290 * Sets the overlay display callback for the current window
292 void FGAPIENTRY glutOverlayDisplayFunc( void (* callback)( void ) )
294 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutOverlayDisplayFunc" );
295 SET_CALLBACK( OverlayDisplay );
299 * Sets the window status callback for the current window
301 void FGAPIENTRY glutWindowStatusFunc( void (* callback)( int ) )
303 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWindowStatusFunc" );
304 SET_CALLBACK( WindowStatus );
308 * Sets the spaceball motion callback for the current window
310 void FGAPIENTRY glutSpaceballMotionFunc( void (* callback)( int, int, int ) )
312 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSpaceballMotionFunc" );
313 fgInitialiseSpaceball();
315 SET_CALLBACK( SpaceMotion );
319 * Sets the spaceball rotate callback for the current window
321 void FGAPIENTRY glutSpaceballRotateFunc( void (* callback)( int, int, int ) )
323 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSpaceballRotateFunc" );
324 fgInitialiseSpaceball();
326 SET_CALLBACK( SpaceRotation );
330 * Sets the spaceball button callback for the current window
332 void FGAPIENTRY glutSpaceballButtonFunc( void (* callback)( int, int ) )
334 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSpaceballButtonFunc" );
335 fgInitialiseSpaceball();
337 SET_CALLBACK( SpaceButton );
341 * Sets the button box callback for the current window
343 void FGAPIENTRY glutButtonBoxFunc( void (* callback)( int, int ) )
345 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutButtonBoxFunc" );
346 SET_CALLBACK( ButtonBox );
350 * Sets the dials box callback for the current window
352 void FGAPIENTRY glutDialsFunc( void (* callback)( int, int ) )
354 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutDialsFunc" );
355 SET_CALLBACK( Dials );
359 * Sets the tablet motion callback for the current window
361 void FGAPIENTRY glutTabletMotionFunc( void (* callback)( int, int ) )
363 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutTabletMotionFunc" );
364 SET_CALLBACK( TabletMotion );
368 * Sets the tablet buttons callback for the current window
370 void FGAPIENTRY glutTabletButtonFunc( void (* callback)( int, int, int, int ) )
372 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutTabletButtonFunc" );
373 SET_CALLBACK( TabletButton );
377 * Sets the multi-pointer entry callback for the current window
379 void FGAPIENTRY glutMultiEntryFunc( void (* callback)(int, int ) )
381 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMultiEntryFunc" );
382 SET_CALLBACK( MultiEntry );
386 * Sets the multi-pointer button callback for the current window
388 void FGAPIENTRY glutMultiButtonFunc( void (* callback)(int, int, int, int, int ) )
390 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMultiButtonFunc" );
391 SET_CALLBACK( MultiButton );
395 * Sets the multi-pointer motion callback for the current window
397 void FGAPIENTRY glutMultiMotionFunc( void (* callback)(int, int, int ) )
399 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMultiMotionFunc" );
400 SET_CALLBACK( MultiMotion );
404 * Sets the multi-pointer passive motion callback for the current window
406 void FGAPIENTRY glutMultiPassiveFunc( void (* callback)(int, int, int ) )
408 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMultiPassiveFunc" );
409 SET_CALLBACK( MultiPassive );
412 /*** END OF FILE ***/