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 ) )
52 fgError( "Fatal error in program. NULL display callback not "
53 "permitted in GLUT 3.0+ or freeglut 2.0.1+" );
54 SET_CALLBACK( Display );
58 * Sets the Reshape callback for the current window
60 void FGAPIENTRY glutReshapeFunc( void (* callback)( int, int ) )
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 SET_CALLBACK( Keyboard );
75 * Sets the Special callback for the current window
77 void FGAPIENTRY glutSpecialFunc( void (* callback)( int, int, int ) )
79 SET_CALLBACK( Special );
83 * Sets the global idle callback
85 void FGAPIENTRY glutIdleFunc( void (* callback)( void ) )
87 freeglut_assert_ready;
88 fgState.IdleCallback = callback;
92 * Sets the Timer callback for the current window
94 void FGAPIENTRY glutTimerFunc( unsigned int timeOut, void (* callback)( int ),
97 SFG_Timer *timer, *node;
99 freeglut_assert_ready;
101 if( (timer = fgState.FreeTimers.Last) )
103 fgListRemove( &fgState.FreeTimers, &timer->Node );
107 if( ! (timer = malloc(sizeof(SFG_Timer))) )
108 fgError( "Fatal error: "
109 "Memory allocation failure in glutTimerFunc()" );
112 timer->Callback = callback;
114 timer->TriggerTime = fgElapsedTime() + timeOut;
116 for( node = fgState.Timers.First; node; node = node->Node.Next )
118 if( node->TriggerTime > timer->TriggerTime )
122 fgListInsert( &fgState.Timers, &node->Node, &timer->Node );
126 * Sets the Visibility callback for the current window.
128 static void fghVisibility( int status )
130 int glut_status = GLUT_VISIBLE;
132 freeglut_assert_ready;
133 freeglut_return_if_fail( fgStructure.Window );
135 if( ( GLUT_HIDDEN == status ) || ( GLUT_FULLY_COVERED == status ) )
136 glut_status = GLUT_NOT_VISIBLE;
137 INVOKE_WCB( *( fgStructure.Window ), Visibility, ( glut_status ) );
140 void FGAPIENTRY glutVisibilityFunc( void (* callback)( int ) )
142 SET_CALLBACK( Visibility );
145 glutWindowStatusFunc( fghVisibility );
147 glutWindowStatusFunc( NULL );
151 * Sets the keyboard key release callback for the current window
153 void FGAPIENTRY glutKeyboardUpFunc( void (* callback)
154 ( unsigned char, int, int ) )
156 SET_CALLBACK( KeyboardUp );
160 * Sets the special key release callback for the current window
162 void FGAPIENTRY glutSpecialUpFunc( void (* callback)( int, int, int ) )
164 SET_CALLBACK( SpecialUp );
168 * Sets the joystick callback and polling rate for the current window
170 void FGAPIENTRY glutJoystickFunc( void (* callback)
171 ( unsigned int, int, int, int ),
174 fgInitialiseJoysticks ();
176 SET_CALLBACK( Joystick );
177 fgStructure.Window->State.JoystickPollRate = pollInterval;
179 fgStructure.Window->State.JoystickLastPoll =
180 fgElapsedTime() - fgStructure.Window->State.JoystickPollRate;
182 if( fgStructure.Window->State.JoystickLastPoll < 0 )
183 fgStructure.Window->State.JoystickLastPoll = 0;
187 * Sets the mouse callback for the current window
189 void FGAPIENTRY glutMouseFunc( void (* callback)( int, int, int, int ) )
191 SET_CALLBACK( Mouse );
195 * Sets the mouse wheel callback for the current window
197 void FGAPIENTRY glutMouseWheelFunc( void (* callback)( int, int, int, int ) )
199 SET_CALLBACK( MouseWheel );
203 * Sets the mouse motion callback for the current window (one or more buttons
206 void FGAPIENTRY glutMotionFunc( void (* callback)( int, int ) )
208 SET_CALLBACK( Motion );
212 * Sets the passive mouse motion callback for the current window (no mouse
213 * buttons are pressed)
215 void FGAPIENTRY glutPassiveMotionFunc( void (* callback)( int, int ) )
217 SET_CALLBACK( Passive );
221 * Window mouse entry/leave callback
223 void FGAPIENTRY glutEntryFunc( void (* callback)( int ) )
225 SET_CALLBACK( Entry );
229 * Window destruction callbacks
231 void FGAPIENTRY glutCloseFunc( void (* callback)( void ) )
233 SET_CALLBACK( Destroy );
236 void FGAPIENTRY glutWMCloseFunc( void (* callback)( void ) )
238 glutCloseFunc( callback );
241 /* A. Donev: Destruction callback for menus */
242 void FGAPIENTRY glutMenuDestroyFunc( void (* callback)( void ) )
244 if( fgStructure.Menu )
245 fgStructure.Menu->Destroy = callback;
249 * Deprecated version of glutMenuStatusFunc callback setting method
251 void FGAPIENTRY glutMenuStateFunc( void (* callback)( int ) )
253 freeglut_assert_ready;
254 fgState.MenuStateCallback = callback;
258 * Sets the global menu status callback for the current window
260 void FGAPIENTRY glutMenuStatusFunc( void (* callback)( int, int, int ) )
262 freeglut_assert_ready;
263 fgState.MenuStatusCallback = callback;
267 * Sets the overlay display callback for the current window
269 void FGAPIENTRY glutOverlayDisplayFunc( void (* callback)( void ) )
271 SET_CALLBACK( OverlayDisplay );
275 * Sets the window status callback for the current window
277 void FGAPIENTRY glutWindowStatusFunc( void (* callback)( int ) )
279 SET_CALLBACK( WindowStatus );
283 * Sets the spaceball motion callback for the current window
285 void FGAPIENTRY glutSpaceballMotionFunc( void (* callback)( int, int, int ) )
287 SET_CALLBACK( SpaceMotion );
291 * Sets the spaceball rotate callback for the current window
293 void FGAPIENTRY glutSpaceballRotateFunc( void (* callback)( int, int, int ) )
295 SET_CALLBACK( SpaceRotation );
299 * Sets the spaceball button callback for the current window
301 void FGAPIENTRY glutSpaceballButtonFunc( void (* callback)( int, int ) )
303 SET_CALLBACK( SpaceButton );
307 * Sets the button box callback for the current window
309 void FGAPIENTRY glutButtonBoxFunc( void (* callback)( int, int ) )
311 SET_CALLBACK( ButtonBox );
315 * Sets the dials box callback for the current window
317 void FGAPIENTRY glutDialsFunc( void (* callback)( int, int ) )
319 SET_CALLBACK( Dials );
323 * Sets the tablet motion callback for the current window
325 void FGAPIENTRY glutTabletMotionFunc( void (* callback)( int, int ) )
327 SET_CALLBACK( TabletMotion );
331 * Sets the tablet buttons callback for the current window
333 void FGAPIENTRY glutTabletButtonFunc( void (* callback)( int, int, int, int ) )
335 SET_CALLBACK( TabletButton );
338 /*** END OF FILE ***/