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 "../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 FETCH_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+\n" );
54 SET_CALLBACK( Display );
55 fgStructure.Window->State.Redisplay = TRUE;
59 * Sets the Reshape callback for the current window
61 void FGAPIENTRY glutReshapeFunc( void (* callback)( int, int ) )
63 SET_CALLBACK( Reshape );
67 * Sets the Keyboard callback for the current window
69 void FGAPIENTRY glutKeyboardFunc( void (* callback)
70 ( unsigned char, int, int ) )
72 SET_CALLBACK( Keyboard );
76 * Sets the Special callback for the current window
78 void FGAPIENTRY glutSpecialFunc( void (* callback)( int, int, int ) )
80 SET_CALLBACK( Special );
84 * Sets the global idle callback
86 void FGAPIENTRY glutIdleFunc( void (* callback)( void ) )
88 freeglut_assert_ready;
89 fgState.IdleCallback = callback;
93 * Sets the Timer callback for the current window
95 void FGAPIENTRY glutTimerFunc( unsigned int timeOut, void (* callback)( int ),
100 freeglut_assert_ready;
102 timer = (SFG_Timer *)calloc( sizeof(SFG_Timer), 1 );
104 fgError( "Fatal error: "
105 "Memory allocation failure in glutTimerFunc()\n" );
107 timer->Callback = callback;
109 timer->TriggerTime = fgElapsedTime() + timeOut;
110 fgListAppend( &fgState.Timers, &timer->Node );
114 * Sets the Visibility callback for the current window.
116 static void fghVisibility( int status )
121 freeglut_assert_ready;
122 freeglut_return_if_fail( fgStructure.Window );
123 vis = FETCH_WCB( ( *( fgStructure.Window ) ), Visibility );
124 freeglut_return_if_fail( vis );
126 if( status == GLUT_HIDDEN || status == GLUT_FULLY_COVERED )
127 glut_status = GLUT_NOT_VISIBLE;
129 glut_status = GLUT_VISIBLE;
133 void FGAPIENTRY glutVisibilityFunc( void (* callback)( int ) )
135 SET_CALLBACK( Visibility );
138 glutWindowStatusFunc( fghVisibility );
140 glutWindowStatusFunc( NULL );
144 * Sets the keyboard key release callback for the current window
146 void FGAPIENTRY glutKeyboardUpFunc( void (* callback)
147 ( unsigned char, int, int ) )
149 SET_CALLBACK( KeyboardUp );
153 * Sets the special key release callback for the current window
155 void FGAPIENTRY glutSpecialUpFunc( void (* callback)( int, int, int ) )
157 SET_CALLBACK( SpecialUp );
161 * Sets the joystick callback and polling rate for the current window
163 void FGAPIENTRY glutJoystickFunc( void (* callback)
164 ( unsigned int, int, int, int ),
167 SET_CALLBACK( Joystick );
168 fgStructure.Window->State.JoystickPollRate = pollInterval;
170 fgStructure.Window->State.JoystickLastPoll =
171 fgElapsedTime() - fgStructure.Window->State.JoystickPollRate;
173 if( fgStructure.Window->State.JoystickLastPoll < 0 )
174 fgStructure.Window->State.JoystickLastPoll = 0;
178 * Sets the mouse callback for the current window
180 void FGAPIENTRY glutMouseFunc( void (* callback)( int, int, int, int ) )
182 SET_CALLBACK( Mouse );
186 * Sets the mouse wheel callback for the current window
188 void FGAPIENTRY glutMouseWheelFunc( void (* callback)( int, int, int, int ) )
190 SET_CALLBACK( MouseWheel );
194 * Sets the mouse motion callback for the current window (one or more buttons
197 void FGAPIENTRY glutMotionFunc( void (* callback)( int, int ) )
199 SET_CALLBACK( Motion );
203 * Sets the passive mouse motion callback for the current window (no mouse
204 * buttons are pressed)
206 void FGAPIENTRY glutPassiveMotionFunc( void (* callback)( int, int ) )
208 SET_CALLBACK( Passive );
212 * Window mouse entry/leave callback
214 void FGAPIENTRY glutEntryFunc( void (* callback)( int ) )
216 SET_CALLBACK( Entry );
220 * Window destruction callbacks
222 void FGAPIENTRY glutCloseFunc( void (* callback)( void ) )
224 SET_CALLBACK( Destroy );
227 void FGAPIENTRY glutWMCloseFunc( void (* callback)( void ) )
229 glutCloseFunc( callback );
232 /* A. Donev: Destruction callback for menus */
233 void FGAPIENTRY glutMenuDestroyFunc( void (* callback)( void ) )
235 if( fgStructure.Menu == NULL )
237 fgStructure.Menu->Destroy = callback;
241 * Deprecated version of glutMenuStatusFunc callback setting method
243 void FGAPIENTRY glutMenuStateFunc( void (* callback)( int ) )
245 freeglut_assert_ready;
246 fgState.MenuStateCallback = callback;
250 * Sets the global menu status callback for the current window
252 void FGAPIENTRY glutMenuStatusFunc( void (* callback)( int, int, int ) )
254 freeglut_assert_ready;
255 fgState.MenuStatusCallback = callback;
259 * Sets the overlay display callback for the current window
261 void FGAPIENTRY glutOverlayDisplayFunc( void (* callback)( void ) )
263 SET_CALLBACK( OverlayDisplay );
267 * Sets the window status callback for the current window
269 void FGAPIENTRY glutWindowStatusFunc( void (* callback)( int ) )
271 SET_CALLBACK( WindowStatus );
275 * Sets the spaceball motion callback for the current window
277 void FGAPIENTRY glutSpaceballMotionFunc( void (* callback)( int, int, int ) )
279 SET_CALLBACK( SpaceMotion );
283 * Sets the spaceball rotate callback for the current window
285 void FGAPIENTRY glutSpaceballRotateFunc( void (* callback)( int, int, int ) )
287 SET_CALLBACK( SpaceRotation );
291 * Sets the spaceball button callback for the current window
293 void FGAPIENTRY glutSpaceballButtonFunc( void (* callback)( int, int ) )
295 SET_CALLBACK( SpaceButton );
299 * Sets the button box callback for the current window
301 void FGAPIENTRY glutButtonBoxFunc( void (* callback)( int, int ) )
303 SET_CALLBACK( ButtonBox );
307 * Sets the dials box callback for the current window
309 void FGAPIENTRY glutDialsFunc( void (* callback)( int, int ) )
311 SET_CALLBACK( Dials );
315 * Sets the tablet motion callback for the current window
317 void FGAPIENTRY glutTabletMotionFunc( void (* callback)( int, int ) )
319 SET_CALLBACK( TabletMotion );
323 * Sets the tablet buttons callback for the current window
325 void FGAPIENTRY glutTabletButtonFunc( void (* callback)( int, int, int, int ) )
327 SET_CALLBACK( TabletButton );
330 /*** END OF FILE ***/