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 "../include/GL/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 ) )
51 SET_CALLBACK( Display );
55 * Sets the Reshape callback for the current window
57 void FGAPIENTRY glutReshapeFunc( void (* callback)( int, int ) )
59 SET_CALLBACK( Reshape );
63 * Sets the Keyboard callback for the current window
65 void FGAPIENTRY glutKeyboardFunc( void (* callback)( unsigned char, int, int ) )
67 SET_CALLBACK( Keyboard );
71 * Sets the Special callback for the current window
73 void FGAPIENTRY glutSpecialFunc( void (* callback)( int, int, int ) )
75 SET_CALLBACK( Special );
79 * Sets the global idle callback
81 void FGAPIENTRY glutIdleFunc( void (* callback)( void ) )
83 freeglut_assert_ready;
86 * The global idle callback pointer is stored in fgState structure
88 fgState.IdleCallback = callback;
92 * Sets the Timer callback for the current window
94 void FGAPIENTRY glutTimerFunc( unsigned int timeOut, void (* callback)( int ), int timerID )
98 freeglut_assert_ready;
101 * Create a new freeglut timer hook structure
103 timer = g_new0( SFG_Timer, 1 );
106 * Remember the callback address and timer hook's ID
108 timer->Callback = callback;
112 * When will the time out happen (in terms of window's timer)
115 g_timer_elapsed( fgState.Timer, NULL ) + (((double) timeOut) / 1000.0);
118 * Have the new hook attached to the current window
120 fgState.Timers = g_list_append( fgState.Timers, timer );
124 * Sets the Visibility callback for the current window.
126 * I had to peer to GLUT sources to clean up the mess.
127 * Can anyone please explain me what is going on here?!?
129 static void fghVisibility( gint status )
131 freeglut_assert_ready; freeglut_return_if_fail( fgStructure.Window != NULL );
132 freeglut_return_if_fail( fgStructure.Window->Callbacks.Visibility != NULL );
134 if( status == GLUT_HIDDEN || status == GLUT_FULLY_COVERED )
135 fgStructure.Window->Callbacks.Visibility( GLUT_NOT_VISIBLE );
137 fgStructure.Window->Callbacks.Visibility( GLUT_VISIBLE );
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)( unsigned char, int, int ) )
155 SET_CALLBACK( KeyboardUp );
159 * Sets the special key release callback for the current window
161 void FGAPIENTRY glutSpecialUpFunc( void (* callback)( int, int, int ) )
163 SET_CALLBACK( SpecialUp );
167 * Sets the joystick callback and polling rate for the current window
169 void FGAPIENTRY glutJoystickFunc( void (* callback)( unsigned int, int, int, int ), int pollInterval )
171 SET_CALLBACK( Joystick );
173 freeglut_return_if_fail( fgStructure.Window != NULL );
176 * Do not forget setting the joystick poll rate
178 fgStructure.Window->State.JoystickPollRate = ((double) pollInterval) / 1000.0;
181 * Make sure the joystick polling routine gets called as early as possible:
183 fgStructure.Window->State.JoystickLastPoll =
184 g_timer_elapsed( fgState.Timer, NULL ) - fgStructure.Window->State.JoystickPollRate;
186 if( fgStructure.Window->State.JoystickLastPoll < 0.0 )
187 fgStructure.Window->State.JoystickLastPoll = 0.0;
191 * Sets the mouse callback for the current window
193 void FGAPIENTRY glutMouseFunc( void (* callback)( int, int, int, int ) )
195 SET_CALLBACK( Mouse );
199 * Sets the mouse motion callback for the current window (one or more buttons are pressed)
201 void FGAPIENTRY glutMotionFunc( void (* callback)( int, int ) )
203 SET_CALLBACK( Motion );
207 * Sets the passive mouse motion callback for the current window (no mouse buttons are pressed)
209 void FGAPIENTRY glutPassiveMotionFunc( void (* callback)( int, int ) )
211 SET_CALLBACK( Passive );
215 * Window mouse entry/leave callback
217 void FGAPIENTRY glutEntryFunc( void (* callback)( int ) )
219 SET_CALLBACK( Entry );
223 * Deprecated version of glutMenuStatusFunc callback setting method
225 void FGAPIENTRY glutMenuStateFunc( void (* callback)( int ) )
227 SET_CALLBACK( MenuState );
231 * Sets the global menu status callback for the current window
233 void FGAPIENTRY glutMenuStatusFunc( void (* callback)( int, int, int ) )
235 SET_CALLBACK( MenuStatus );
239 * Sets the overlay display callback for the current window
241 void FGAPIENTRY glutOverlayDisplayFunc( void (* callback)( void ) )
243 SET_CALLBACK( OverlayDisplay );
247 * Sets the window status callback for the current window
249 void FGAPIENTRY glutWindowStatusFunc( void (* callback)( int ) )
251 SET_CALLBACK( WindowStatus );
255 * Sets the spaceball motion callback for the current window
257 void FGAPIENTRY glutSpaceballMotionFunc( void (* callback)( int, int, int ) )
259 SET_CALLBACK( SpaceMotion );
263 * Sets the spaceball rotate callback for the current window
265 void FGAPIENTRY glutSpaceballRotateFunc( void (* callback)( int, int, int ) )
267 SET_CALLBACK( SpaceRotation );
271 * Sets the spaceball button callback for the current window
273 void FGAPIENTRY glutSpaceballButtonFunc( void (* callback)( int, int ) )
275 SET_CALLBACK( SpaceButton );
279 * Sets the button box callback for the current window
281 void FGAPIENTRY glutButtonBoxFunc( void (* callback)( int, int ) )
283 SET_CALLBACK( ButtonBox );
287 * Sets the dials box callback for the current window
289 void FGAPIENTRY glutDialsFunc( void (* callback)( int, int ) )
291 SET_CALLBACK( Dials );
295 * Sets the tablet motion callback for the current window
297 void FGAPIENTRY glutTabletMotionFunc( void (* callback)( int, int ) )
299 SET_CALLBACK( TabletMotion );
303 * Sets the tablet buttons callback for the current window
305 void FGAPIENTRY glutTabletButtonFunc( void (* callback)( int, int, int, int ) )
307 SET_CALLBACK( TabletButton );
310 /*** END OF FILE ***/