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) \
44 if( fgStructure.Window == NULL ) \
46 fgStructure.Window->Callbacks.a = callback;
49 * Sets the Display callback for the current window
51 void FGAPIENTRY glutDisplayFunc( void (* callback)( void ) )
54 fgError( "Fatal error in program. NULL display callback not "
55 "permitted in GLUT 3.0+ or freeglut 2.0.1+\n" );
56 SET_CALLBACK( Display );
57 fgStructure.Window->State.Redisplay = TRUE;
61 * Sets the Reshape callback for the current window
63 void FGAPIENTRY glutReshapeFunc( void (* callback)( int, int ) )
65 SET_CALLBACK( Reshape );
69 * Sets the Keyboard callback for the current window
71 void FGAPIENTRY glutKeyboardFunc( void (* callback)
72 ( unsigned char, int, int ) )
74 SET_CALLBACK( Keyboard );
78 * Sets the Special callback for the current window
80 void FGAPIENTRY glutSpecialFunc( void (* callback)( int, int, int ) )
82 SET_CALLBACK( Special );
86 * Sets the global idle callback
88 void FGAPIENTRY glutIdleFunc( void (* callback)( void ) )
90 freeglut_assert_ready;
91 fgState.IdleCallback = callback;
95 * Sets the Timer callback for the current window
97 void FGAPIENTRY glutTimerFunc( unsigned int timeOut, void (* callback)( int ),
102 freeglut_assert_ready;
104 timer = (SFG_Timer *)calloc( sizeof(SFG_Timer), 1 );
106 fgError( "Fatal error: "
107 "Memory allocation failure in glutTimerFunc()\n" );
109 timer->Callback = callback;
111 timer->TriggerTime = fgElapsedTime() + timeOut;
112 fgListAppend( &fgState.Timers, &timer->Node );
116 * Sets the Visibility callback for the current window.
118 static void fghVisibility( int status )
120 freeglut_assert_ready;
121 freeglut_return_if_fail( fgStructure.Window );
122 freeglut_return_if_fail( fgStructure.Window->Callbacks.Visibility );
124 if( status == GLUT_HIDDEN || status == GLUT_FULLY_COVERED )
125 fgStructure.Window->Callbacks.Visibility( GLUT_NOT_VISIBLE );
127 fgStructure.Window->Callbacks.Visibility( GLUT_VISIBLE );
130 void FGAPIENTRY glutVisibilityFunc( void (* callback)( int ) )
132 SET_CALLBACK( Visibility );
135 glutWindowStatusFunc( fghVisibility );
137 glutWindowStatusFunc( NULL );
141 * Sets the keyboard key release callback for the current window
143 void FGAPIENTRY glutKeyboardUpFunc( void (* callback)
144 ( unsigned char, int, int ) )
146 SET_CALLBACK( KeyboardUp );
150 * Sets the special key release callback for the current window
152 void FGAPIENTRY glutSpecialUpFunc( void (* callback)( int, int, int ) )
154 SET_CALLBACK( SpecialUp );
158 * Sets the joystick callback and polling rate for the current window
160 void FGAPIENTRY glutJoystickFunc( void (* callback)
161 ( unsigned int, int, int, int ),
164 SET_CALLBACK( Joystick );
165 fgStructure.Window->State.JoystickPollRate = pollInterval;
167 fgStructure.Window->State.JoystickLastPoll =
168 fgElapsedTime() - fgStructure.Window->State.JoystickPollRate;
170 if( fgStructure.Window->State.JoystickLastPoll < 0 )
171 fgStructure.Window->State.JoystickLastPoll = 0;
175 * Sets the mouse callback for the current window
177 void FGAPIENTRY glutMouseFunc( void (* callback)( int, int, int, int ) )
179 SET_CALLBACK( Mouse );
183 * Sets the mouse wheel callback for the current window
185 void FGAPIENTRY glutMouseWheelFunc( void (* callback)( int, int, int, int ) )
187 SET_CALLBACK( MouseWheel );
191 * Sets the mouse motion callback for the current window (one or more buttons
194 void FGAPIENTRY glutMotionFunc( void (* callback)( int, int ) )
196 SET_CALLBACK( Motion );
200 * Sets the passive mouse motion callback for the current window (no mouse
201 * buttons are pressed)
203 void FGAPIENTRY glutPassiveMotionFunc( void (* callback)( int, int ) )
205 SET_CALLBACK( Passive );
209 * Window mouse entry/leave callback
211 void FGAPIENTRY glutEntryFunc( void (* callback)( int ) )
213 SET_CALLBACK( Entry );
217 * Window destruction callbacks
219 void FGAPIENTRY glutCloseFunc( void (* callback)( void ) )
221 SET_CALLBACK( Destroy );
224 void FGAPIENTRY glutWMCloseFunc( void (* callback)( void ) )
226 glutCloseFunc( callback );
229 /* A. Donev: Destruction callback for menus */
230 void FGAPIENTRY glutMenuDestroyFunc( void (* callback)( void ) )
232 if( fgStructure.Menu == NULL )
234 fgStructure.Menu->Destroy = callback;
238 * Deprecated version of glutMenuStatusFunc callback setting method
240 void FGAPIENTRY glutMenuStateFunc( void (* callback)( int ) )
242 freeglut_assert_ready;
243 fgState.MenuStateCallback = callback;
247 * Sets the global menu status callback for the current window
249 void FGAPIENTRY glutMenuStatusFunc( void (* callback)( int, int, int ) )
251 freeglut_assert_ready;
252 fgState.MenuStatusCallback = callback;
256 * Sets the overlay display callback for the current window
258 void FGAPIENTRY glutOverlayDisplayFunc( void (* callback)( void ) )
260 SET_CALLBACK( OverlayDisplay );
264 * Sets the window status callback for the current window
266 void FGAPIENTRY glutWindowStatusFunc( void (* callback)( int ) )
268 SET_CALLBACK( WindowStatus );
272 * Sets the spaceball motion callback for the current window
274 void FGAPIENTRY glutSpaceballMotionFunc( void (* callback)( int, int, int ) )
276 SET_CALLBACK( SpaceMotion );
280 * Sets the spaceball rotate callback for the current window
282 void FGAPIENTRY glutSpaceballRotateFunc( void (* callback)( int, int, int ) )
284 SET_CALLBACK( SpaceRotation );
288 * Sets the spaceball button callback for the current window
290 void FGAPIENTRY glutSpaceballButtonFunc( void (* callback)( int, int ) )
292 SET_CALLBACK( SpaceButton );
296 * Sets the button box callback for the current window
298 void FGAPIENTRY glutButtonBoxFunc( void (* callback)( int, int ) )
300 SET_CALLBACK( ButtonBox );
304 * Sets the dials box callback for the current window
306 void FGAPIENTRY glutDialsFunc( void (* callback)( int, int ) )
308 SET_CALLBACK( Dials );
312 * Sets the tablet motion callback for the current window
314 void FGAPIENTRY glutTabletMotionFunc( void (* callback)( int, int ) )
316 SET_CALLBACK( TabletMotion );
320 * Sets the tablet buttons callback for the current window
322 void FGAPIENTRY glutTabletButtonFunc( void (* callback)( int, int, int, int ) )
324 SET_CALLBACK( TabletButton );
327 /*** END OF FILE ***/