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.Window == NULL ) \
41 SET_WCB( ( *( fgStructure.Window ) ), 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_return_if_fail( fgStructure.Window );
136 if( ( GLUT_HIDDEN == status ) || ( GLUT_FULLY_COVERED == status ) )
137 glut_status = GLUT_NOT_VISIBLE;
138 INVOKE_WCB( *( fgStructure.Window ), Visibility, ( glut_status ) );
141 void FGAPIENTRY glutVisibilityFunc( void (* callback)( int ) )
143 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutVisibilityFunc" );
144 SET_CALLBACK( Visibility );
147 glutWindowStatusFunc( fghVisibility );
149 glutWindowStatusFunc( NULL );
153 * Sets the keyboard key release callback for the current window
155 void FGAPIENTRY glutKeyboardUpFunc( void (* callback)
156 ( unsigned char, int, int ) )
158 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutKeyboardUpFunc" );
159 SET_CALLBACK( KeyboardUp );
163 * Sets the special key release callback for the current window
165 void FGAPIENTRY glutSpecialUpFunc( void (* callback)( int, int, int ) )
167 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSpecialUpFunc" );
168 SET_CALLBACK( SpecialUp );
172 * Sets the joystick callback and polling rate for the current window
174 void FGAPIENTRY glutJoystickFunc( void (* callback)
175 ( unsigned int, int, int, int ),
178 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutJoystickFunc" );
179 fgInitialiseJoysticks ();
181 SET_CALLBACK( Joystick );
182 fgStructure.Window->State.JoystickPollRate = pollInterval;
184 fgStructure.Window->State.JoystickLastPoll =
185 fgElapsedTime() - fgStructure.Window->State.JoystickPollRate;
187 if( fgStructure.Window->State.JoystickLastPoll < 0 )
188 fgStructure.Window->State.JoystickLastPoll = 0;
192 * Sets the mouse callback for the current window
194 void FGAPIENTRY glutMouseFunc( void (* callback)( int, int, int, int ) )
196 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMouseFunc" );
197 SET_CALLBACK( Mouse );
201 * Sets the mouse wheel callback for the current window
203 void FGAPIENTRY glutMouseWheelFunc( void (* callback)( int, int, int, int ) )
205 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMouseWheelFunc" );
206 SET_CALLBACK( MouseWheel );
210 * Sets the mouse motion callback for the current window (one or more buttons
213 void FGAPIENTRY glutMotionFunc( void (* callback)( int, int ) )
215 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMotionFunc" );
216 SET_CALLBACK( Motion );
220 * Sets the passive mouse motion callback for the current window (no mouse
221 * buttons are pressed)
223 void FGAPIENTRY glutPassiveMotionFunc( void (* callback)( int, int ) )
225 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPassiveMotionFunc" );
226 SET_CALLBACK( Passive );
230 * Window mouse entry/leave callback
232 void FGAPIENTRY glutEntryFunc( void (* callback)( int ) )
234 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutEntryFunc" );
235 SET_CALLBACK( Entry );
239 * Window destruction callbacks
241 void FGAPIENTRY glutCloseFunc( void (* callback)( void ) )
243 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutCloseFunc" );
244 SET_CALLBACK( Destroy );
247 void FGAPIENTRY glutWMCloseFunc( void (* callback)( void ) )
249 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWMCloseFunc" );
250 glutCloseFunc( callback );
253 /* A. Donev: Destruction callback for menus */
254 void FGAPIENTRY glutMenuDestroyFunc( void (* callback)( void ) )
256 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMenuDestroyFunc" );
257 if( fgStructure.Menu )
258 fgStructure.Menu->Destroy = callback;
262 * Deprecated version of glutMenuStatusFunc callback setting method
264 void FGAPIENTRY glutMenuStateFunc( void (* callback)( int ) )
266 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMenuStateFunc" );
267 fgState.MenuStateCallback = callback;
271 * Sets the global menu status callback for the current window
273 void FGAPIENTRY glutMenuStatusFunc( void (* callback)( int, int, int ) )
275 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMenuStatusFunc" );
276 fgState.MenuStatusCallback = callback;
280 * Sets the overlay display callback for the current window
282 void FGAPIENTRY glutOverlayDisplayFunc( void (* callback)( void ) )
284 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutOverlayDisplayFunc" );
285 SET_CALLBACK( OverlayDisplay );
289 * Sets the window status callback for the current window
291 void FGAPIENTRY glutWindowStatusFunc( void (* callback)( int ) )
293 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWindowStatusFunc" );
294 SET_CALLBACK( WindowStatus );
298 * Sets the spaceball motion callback for the current window
300 void FGAPIENTRY glutSpaceballMotionFunc( void (* callback)( int, int, int ) )
302 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSpaceballMotionFunc" );
303 SET_CALLBACK( SpaceMotion );
307 * Sets the spaceball rotate callback for the current window
309 void FGAPIENTRY glutSpaceballRotateFunc( void (* callback)( int, int, int ) )
311 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSpaceballRotateFunc" );
312 SET_CALLBACK( SpaceRotation );
316 * Sets the spaceball button callback for the current window
318 void FGAPIENTRY glutSpaceballButtonFunc( void (* callback)( int, int ) )
320 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSpaceballButtonFunc" );
321 SET_CALLBACK( SpaceButton );
325 * Sets the button box callback for the current window
327 void FGAPIENTRY glutButtonBoxFunc( void (* callback)( int, int ) )
329 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutButtonBoxFunc" );
330 SET_CALLBACK( ButtonBox );
334 * Sets the dials box callback for the current window
336 void FGAPIENTRY glutDialsFunc( void (* callback)( int, int ) )
338 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutDialsFunc" );
339 SET_CALLBACK( Dials );
343 * Sets the tablet motion callback for the current window
345 void FGAPIENTRY glutTabletMotionFunc( void (* callback)( int, int ) )
347 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutTabletMotionFunc" );
348 SET_CALLBACK( TabletMotion );
352 * Sets the tablet buttons callback for the current window
354 void FGAPIENTRY glutTabletButtonFunc( void (* callback)( int, int, int, int ) )
356 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutTabletButtonFunc" );
357 SET_CALLBACK( TabletButton );
360 /*** END OF FILE ***/