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 #define G_LOG_DOMAIN "freeglut-callbacks"
34 #include "../include/GL/freeglut.h"
35 #include "freeglut_internal.h"
38 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
41 * All of the callbacks setting methods can be generalized to this:
43 #define SET_CALLBACK(a) if( fgStructure.Window == NULL ) return;\
44 fgStructure.Window->Callbacks.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 );
57 * Force a redisplay with the new callback
59 fgStructure.Window->State.Redisplay = TRUE;
64 * Sets the Reshape callback for the current window
66 void FGAPIENTRY glutReshapeFunc( void (* callback)( int, int ) )
68 SET_CALLBACK( Reshape );
72 * Sets the Keyboard callback for the current window
74 void FGAPIENTRY glutKeyboardFunc( void (* callback)( unsigned char, int, int ) )
76 SET_CALLBACK( Keyboard );
80 * Sets the Special callback for the current window
82 void FGAPIENTRY glutSpecialFunc( void (* callback)( int, int, int ) )
84 SET_CALLBACK( Special );
88 * Sets the global idle callback
90 void FGAPIENTRY glutIdleFunc( void (* callback)( void ) )
92 freeglut_assert_ready;
95 * The global idle callback pointer is stored in fgState structure
97 fgState.IdleCallback = callback;
101 * Sets the Timer callback for the current window
103 void FGAPIENTRY glutTimerFunc( unsigned int timeOut, void (* callback)( int ), int timerID )
107 freeglut_assert_ready;
110 * Create a new freeglut timer hook structure
112 timer = (SFG_Timer *)calloc( sizeof(SFG_Timer), 1 );
114 fgError ("Fatal error: "
115 "Memory allocation failure in glutTimerFunc()\n");
118 * Remember the callback address and timer hook's ID
120 timer->Callback = callback;
124 * When will the time out happen (in terms of window's timer)
126 timer->TriggerTime = fgElapsedTime() + timeOut;
129 * Have the new hook attached to the current window
131 fgListAppend( &fgState.Timers, &timer->Node );
135 * Sets the Visibility callback for the current window.
137 * I had to peer to GLUT sources to clean up the mess.
138 * Can anyone please explain me what is going on here?!?
140 static void fghVisibility( int status )
142 freeglut_assert_ready; freeglut_return_if_fail( fgStructure.Window != NULL );
143 freeglut_return_if_fail( fgStructure.Window->Callbacks.Visibility != NULL );
145 if( status == GLUT_HIDDEN || status == GLUT_FULLY_COVERED )
146 fgStructure.Window->Callbacks.Visibility( GLUT_NOT_VISIBLE );
148 fgStructure.Window->Callbacks.Visibility( GLUT_VISIBLE );
151 void FGAPIENTRY glutVisibilityFunc( void (* callback)( int ) )
153 SET_CALLBACK( Visibility );
156 glutWindowStatusFunc( fghVisibility );
158 glutWindowStatusFunc( NULL );
162 * Sets the keyboard key release callback for the current window
164 void FGAPIENTRY glutKeyboardUpFunc( void (* callback)( unsigned char, int, int ) )
166 SET_CALLBACK( KeyboardUp );
170 * Sets the special key release callback for the current window
172 void FGAPIENTRY glutSpecialUpFunc( void (* callback)( int, int, int ) )
174 SET_CALLBACK( SpecialUp );
178 * Sets the joystick callback and polling rate for the current window
180 void FGAPIENTRY glutJoystickFunc( void (* callback)( unsigned int, int, int, int ), int pollInterval )
182 SET_CALLBACK( Joystick );
184 freeglut_return_if_fail( fgStructure.Window != NULL );
187 * Do not forget setting the joystick poll rate
189 fgStructure.Window->State.JoystickPollRate = pollInterval;
192 * Make sure the joystick polling routine gets called as early as possible:
194 fgStructure.Window->State.JoystickLastPoll =
195 fgElapsedTime() - fgStructure.Window->State.JoystickPollRate;
197 if( fgStructure.Window->State.JoystickLastPoll < 0 )
198 fgStructure.Window->State.JoystickLastPoll = 0;
202 * Sets the mouse callback for the current window
204 void FGAPIENTRY glutMouseFunc( void (* callback)( int, int, int, int ) )
206 SET_CALLBACK( Mouse );
210 * Sets the mouse motion callback for the current window (one or more buttons are pressed)
212 void FGAPIENTRY glutMotionFunc( void (* callback)( int, int ) )
214 SET_CALLBACK( Motion );
218 * Sets the passive mouse motion callback for the current window (no mouse buttons are pressed)
220 void FGAPIENTRY glutPassiveMotionFunc( void (* callback)( int, int ) )
222 SET_CALLBACK( Passive );
226 * Window mouse entry/leave callback
228 void FGAPIENTRY glutEntryFunc( void (* callback)( int ) )
230 SET_CALLBACK( Entry );
234 * Window destruction callbacks
236 void FGAPIENTRY glutCloseFunc( void (* callback)( void ) )
238 SET_CALLBACK( Destroy );
241 void FGAPIENTRY glutWMCloseFunc( void (* callback)( void ) )
243 glutCloseFunc( callback );
246 /* A. Donev: Destruction callback for menus */
247 void FGAPIENTRY glutMenuDestroyFunc( void (* callback)( void ) )
249 if( fgStructure.Menu == NULL ) return;
250 fgStructure.Menu->Destroy = callback;
254 * Deprecated version of glutMenuStatusFunc callback setting method
256 void FGAPIENTRY glutMenuStateFunc( void (* callback)( int ) )
258 freeglut_assert_ready;
260 fgState.MenuStateCallback = callback;
264 * Sets the global menu status callback for the current window
266 void FGAPIENTRY glutMenuStatusFunc( void (* callback)( int, int, int ) )
268 freeglut_assert_ready;
270 fgState.MenuStatusCallback = callback;
274 * Sets the overlay display callback for the current window
276 void FGAPIENTRY glutOverlayDisplayFunc( void (* callback)( void ) )
278 SET_CALLBACK( OverlayDisplay );
282 * Sets the window status callback for the current window
284 void FGAPIENTRY glutWindowStatusFunc( void (* callback)( int ) )
286 SET_CALLBACK( WindowStatus );
290 * Sets the spaceball motion callback for the current window
292 void FGAPIENTRY glutSpaceballMotionFunc( void (* callback)( int, int, int ) )
294 SET_CALLBACK( SpaceMotion );
298 * Sets the spaceball rotate callback for the current window
300 void FGAPIENTRY glutSpaceballRotateFunc( void (* callback)( int, int, int ) )
302 SET_CALLBACK( SpaceRotation );
306 * Sets the spaceball button callback for the current window
308 void FGAPIENTRY glutSpaceballButtonFunc( void (* callback)( int, int ) )
310 SET_CALLBACK( SpaceButton );
314 * Sets the button box callback for the current window
316 void FGAPIENTRY glutButtonBoxFunc( void (* callback)( int, int ) )
318 SET_CALLBACK( ButtonBox );
322 * Sets the dials box callback for the current window
324 void FGAPIENTRY glutDialsFunc( void (* callback)( int, int ) )
326 SET_CALLBACK( Dials );
330 * Sets the tablet motion callback for the current window
332 void FGAPIENTRY glutTabletMotionFunc( void (* callback)( int, int ) )
334 SET_CALLBACK( TabletMotion );
338 * Sets the tablet buttons callback for the current window
340 void FGAPIENTRY glutTabletButtonFunc( void (* callback)( int, int, int, int ) )
342 SET_CALLBACK( TabletButton );
345 /*** END OF FILE ***/