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.
32 #include <GL/freeglut.h>
33 #include "freeglut_internal.h"
36 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
39 * All of the callbacks setting methods can be generalized to this:
41 #define SET_CALLBACK(a) \
42 if( fgStructure.Window == NULL ) \
44 SET_WCB( ( *( fgStructure.Window ) ), a, callback );
47 * Sets the Display callback for the current window
49 void FGAPIENTRY glutDisplayFunc( void (* callback)( void ) )
51 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutDisplayFunc" );
53 fgError( "Fatal error in program. NULL display callback not "
54 "permitted in GLUT 3.0+ or freeglut 2.0.1+" );
55 SET_CALLBACK( Display );
59 * Sets the Reshape callback for the current window
61 void FGAPIENTRY glutReshapeFunc( void (* callback)( int, int ) )
63 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutReshapeFunc" );
64 SET_CALLBACK( Reshape );
68 * Sets the Keyboard callback for the current window
70 void FGAPIENTRY glutKeyboardFunc( void (* callback)
71 ( unsigned char, int, int ) )
73 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutKeyboardFunc" );
74 SET_CALLBACK( Keyboard );
78 * Sets the Special callback for the current window
80 void FGAPIENTRY glutSpecialFunc( void (* callback)( int, int, int ) )
82 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSpecialFunc" );
83 SET_CALLBACK( Special );
87 * Sets the global idle callback
89 void FGAPIENTRY glutIdleFunc( void (* callback)( void ) )
91 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutIdleFunc" );
92 fgState.IdleCallback = callback;
96 * Sets the Timer callback for the current window
98 void FGAPIENTRY glutTimerFunc( unsigned int timeOut, void (* callback)( int ),
101 SFG_Timer *timer, *node;
103 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutTimerFunc" );
105 if( (timer = fgState.FreeTimers.Last) )
107 fgListRemove( &fgState.FreeTimers, &timer->Node );
111 if( ! (timer = malloc(sizeof(SFG_Timer))) )
112 fgError( "Fatal error: "
113 "Memory allocation failure in glutTimerFunc()" );
116 timer->Callback = callback;
118 timer->TriggerTime = fgElapsedTime() + timeOut;
120 for( node = fgState.Timers.First; node; node = node->Node.Next )
122 if( node->TriggerTime > timer->TriggerTime )
126 fgListInsert( &fgState.Timers, &node->Node, &timer->Node );
130 * Sets the Visibility callback for the current window.
132 static void fghVisibility( int status )
134 int glut_status = GLUT_VISIBLE;
136 freeglut_return_if_fail( fgStructure.Window );
138 if( ( GLUT_HIDDEN == status ) || ( GLUT_FULLY_COVERED == status ) )
139 glut_status = GLUT_NOT_VISIBLE;
140 INVOKE_WCB( *( fgStructure.Window ), Visibility, ( glut_status ) );
143 void FGAPIENTRY glutVisibilityFunc( void (* callback)( int ) )
145 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutVisibilityFunc" );
146 SET_CALLBACK( Visibility );
149 glutWindowStatusFunc( fghVisibility );
151 glutWindowStatusFunc( NULL );
155 * Sets the keyboard key release callback for the current window
157 void FGAPIENTRY glutKeyboardUpFunc( void (* callback)
158 ( unsigned char, int, int ) )
160 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutKeyboardUpFunc" );
161 SET_CALLBACK( KeyboardUp );
165 * Sets the special key release callback for the current window
167 void FGAPIENTRY glutSpecialUpFunc( void (* callback)( int, int, int ) )
169 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSpecialUpFunc" );
170 SET_CALLBACK( SpecialUp );
174 * Sets the joystick callback and polling rate for the current window
176 void FGAPIENTRY glutJoystickFunc( void (* callback)
177 ( unsigned int, int, int, int ),
180 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutJoystickFunc" );
181 fgInitialiseJoysticks ();
183 SET_CALLBACK( Joystick );
184 fgStructure.Window->State.JoystickPollRate = pollInterval;
186 fgStructure.Window->State.JoystickLastPoll =
187 fgElapsedTime() - fgStructure.Window->State.JoystickPollRate;
189 if( fgStructure.Window->State.JoystickLastPoll < 0 )
190 fgStructure.Window->State.JoystickLastPoll = 0;
194 * Sets the mouse callback for the current window
196 void FGAPIENTRY glutMouseFunc( void (* callback)( int, int, int, int ) )
198 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMouseFunc" );
199 SET_CALLBACK( Mouse );
203 * Sets the mouse wheel callback for the current window
205 void FGAPIENTRY glutMouseWheelFunc( void (* callback)( int, int, int, int ) )
207 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMouseWheelFunc" );
208 SET_CALLBACK( MouseWheel );
212 * Sets the mouse motion callback for the current window (one or more buttons
215 void FGAPIENTRY glutMotionFunc( void (* callback)( int, int ) )
217 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMotionFunc" );
218 SET_CALLBACK( Motion );
222 * Sets the passive mouse motion callback for the current window (no mouse
223 * buttons are pressed)
225 void FGAPIENTRY glutPassiveMotionFunc( void (* callback)( int, int ) )
227 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPassiveMotionFunc" );
228 SET_CALLBACK( Passive );
232 * Window mouse entry/leave callback
234 void FGAPIENTRY glutEntryFunc( void (* callback)( int ) )
236 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutEntryFunc" );
237 SET_CALLBACK( Entry );
241 * Window destruction callbacks
243 void FGAPIENTRY glutCloseFunc( void (* callback)( void ) )
245 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutCloseFunc" );
246 SET_CALLBACK( Destroy );
249 void FGAPIENTRY glutWMCloseFunc( void (* callback)( void ) )
251 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWMCloseFunc" );
252 glutCloseFunc( callback );
255 /* A. Donev: Destruction callback for menus */
256 void FGAPIENTRY glutMenuDestroyFunc( void (* callback)( void ) )
258 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMenuDestroyFunc" );
259 if( fgStructure.Menu )
260 fgStructure.Menu->Destroy = callback;
264 * Deprecated version of glutMenuStatusFunc callback setting method
266 void FGAPIENTRY glutMenuStateFunc( void (* callback)( int ) )
268 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMenuStateFunc" );
269 fgState.MenuStateCallback = callback;
273 * Sets the global menu status callback for the current window
275 void FGAPIENTRY glutMenuStatusFunc( void (* callback)( int, int, int ) )
277 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMenuStatusFunc" );
278 fgState.MenuStatusCallback = callback;
282 * Sets the overlay display callback for the current window
284 void FGAPIENTRY glutOverlayDisplayFunc( void (* callback)( void ) )
286 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutOverlayDisplayFunc" );
287 SET_CALLBACK( OverlayDisplay );
291 * Sets the window status callback for the current window
293 void FGAPIENTRY glutWindowStatusFunc( void (* callback)( int ) )
295 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWindowStatusFunc" );
296 SET_CALLBACK( WindowStatus );
300 * Sets the spaceball motion callback for the current window
302 void FGAPIENTRY glutSpaceballMotionFunc( void (* callback)( int, int, int ) )
304 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSpaceballMotionFunc" );
305 SET_CALLBACK( SpaceMotion );
309 * Sets the spaceball rotate callback for the current window
311 void FGAPIENTRY glutSpaceballRotateFunc( void (* callback)( int, int, int ) )
313 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSpaceballRotateFunc" );
314 SET_CALLBACK( SpaceRotation );
318 * Sets the spaceball button callback for the current window
320 void FGAPIENTRY glutSpaceballButtonFunc( void (* callback)( int, int ) )
322 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSpaceballButtonFunc" );
323 SET_CALLBACK( SpaceButton );
327 * Sets the button box callback for the current window
329 void FGAPIENTRY glutButtonBoxFunc( void (* callback)( int, int ) )
331 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutButtonBoxFunc" );
332 SET_CALLBACK( ButtonBox );
336 * Sets the dials box callback for the current window
338 void FGAPIENTRY glutDialsFunc( void (* callback)( int, int ) )
340 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutDialsFunc" );
341 SET_CALLBACK( Dials );
345 * Sets the tablet motion callback for the current window
347 void FGAPIENTRY glutTabletMotionFunc( void (* callback)( int, int ) )
349 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutTabletMotionFunc" );
350 SET_CALLBACK( TabletMotion );
354 * Sets the tablet buttons callback for the current window
356 void FGAPIENTRY glutTabletButtonFunc( void (* callback)( int, int, int, int ) )
358 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutTabletButtonFunc" );
359 SET_CALLBACK( TabletButton );
362 /*** END OF FILE ***/