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 SET_CALLBACK( Joystick );
183 fgStructure.CurrentWindow->State.JoystickPollRate = pollInterval;
185 fgStructure.CurrentWindow->State.JoystickLastPoll =
186 fgElapsedTime() - fgStructure.CurrentWindow->State.JoystickPollRate;
188 if( fgStructure.CurrentWindow->State.JoystickLastPoll < 0 )
189 fgStructure.CurrentWindow->State.JoystickLastPoll = 0;
193 * Sets the mouse callback for the current window
195 void FGAPIENTRY glutMouseFunc( void (* callback)( int, int, int, int ) )
197 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMouseFunc" );
198 SET_CALLBACK( Mouse );
202 * Sets the mouse wheel callback for the current window
204 void FGAPIENTRY glutMouseWheelFunc( void (* callback)( int, int, int, int ) )
206 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMouseWheelFunc" );
207 SET_CALLBACK( MouseWheel );
211 * Sets the mouse motion callback for the current window (one or more buttons
214 void FGAPIENTRY glutMotionFunc( void (* callback)( int, int ) )
216 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMotionFunc" );
217 SET_CALLBACK( Motion );
221 * Sets the passive mouse motion callback for the current window (no mouse
222 * buttons are pressed)
224 void FGAPIENTRY glutPassiveMotionFunc( void (* callback)( int, int ) )
226 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPassiveMotionFunc" );
227 SET_CALLBACK( Passive );
231 * Window mouse entry/leave callback
233 void FGAPIENTRY glutEntryFunc( void (* callback)( int ) )
235 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutEntryFunc" );
236 SET_CALLBACK( Entry );
240 * Window destruction callbacks
242 void FGAPIENTRY glutCloseFunc( void (* callback)( void ) )
244 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutCloseFunc" );
245 SET_CALLBACK( Destroy );
248 void FGAPIENTRY glutWMCloseFunc( void (* callback)( void ) )
250 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWMCloseFunc" );
251 glutCloseFunc( callback );
254 /* A. Donev: Destruction callback for menus */
255 void FGAPIENTRY glutMenuDestroyFunc( void (* callback)( void ) )
257 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMenuDestroyFunc" );
258 if( fgStructure.CurrentMenu )
259 fgStructure.CurrentMenu->Destroy = callback;
263 * Deprecated version of glutMenuStatusFunc callback setting method
265 void FGAPIENTRY glutMenuStateFunc( void (* callback)( int ) )
267 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMenuStateFunc" );
268 fgState.MenuStateCallback = callback;
272 * Sets the global menu status callback for the current window
274 void FGAPIENTRY glutMenuStatusFunc( void (* callback)( int, int, int ) )
276 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMenuStatusFunc" );
277 fgState.MenuStatusCallback = callback;
281 * Sets the overlay display callback for the current window
283 void FGAPIENTRY glutOverlayDisplayFunc( void (* callback)( void ) )
285 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutOverlayDisplayFunc" );
286 SET_CALLBACK( OverlayDisplay );
290 * Sets the window status callback for the current window
292 void FGAPIENTRY glutWindowStatusFunc( void (* callback)( int ) )
294 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWindowStatusFunc" );
295 SET_CALLBACK( WindowStatus );
299 * Sets the spaceball motion callback for the current window
301 void FGAPIENTRY glutSpaceballMotionFunc( void (* callback)( int, int, int ) )
303 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSpaceballMotionFunc" );
304 SET_CALLBACK( SpaceMotion );
308 * Sets the spaceball rotate callback for the current window
310 void FGAPIENTRY glutSpaceballRotateFunc( void (* callback)( int, int, int ) )
312 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSpaceballRotateFunc" );
313 SET_CALLBACK( SpaceRotation );
317 * Sets the spaceball button callback for the current window
319 void FGAPIENTRY glutSpaceballButtonFunc( void (* callback)( int, int ) )
321 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSpaceballButtonFunc" );
322 SET_CALLBACK( SpaceButton );
326 * Sets the button box callback for the current window
328 void FGAPIENTRY glutButtonBoxFunc( void (* callback)( int, int ) )
330 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutButtonBoxFunc" );
331 SET_CALLBACK( ButtonBox );
335 * Sets the dials box callback for the current window
337 void FGAPIENTRY glutDialsFunc( void (* callback)( int, int ) )
339 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutDialsFunc" );
340 SET_CALLBACK( Dials );
344 * Sets the tablet motion callback for the current window
346 void FGAPIENTRY glutTabletMotionFunc( void (* callback)( int, int ) )
348 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutTabletMotionFunc" );
349 SET_CALLBACK( TabletMotion );
353 * Sets the tablet buttons callback for the current window
355 void FGAPIENTRY glutTabletButtonFunc( void (* callback)( int, int, int, int ) )
357 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutTabletButtonFunc" );
358 SET_CALLBACK( TabletButton );
361 /*** END OF FILE ***/