Caught a few more little style issues.
[freeglut] / src / freeglut_callbacks.c
1 /*
2  * freeglut_callbacks.c
3  *
4  * The callbacks setting methods.
5  *
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
9  *
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:
16  *
17  * The above copyright notice and this permission notice shall be included
18  * in all copies or substantial portions of the Software.
19  *
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.
26  */
27
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31
32 #define  G_LOG_DOMAIN  "freeglut-callbacks"
33
34 #include "../include/GL/freeglut.h"
35 #include "freeglut_internal.h"
36
37
38 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
39
40 /*
41  * All of the callbacks setting methods can be generalized to this:
42  */
43 #define SET_CALLBACK(a)              \
44     if( fgStructure.Window == NULL ) \
45         return;                      \
46     fgStructure.Window->Callbacks.a = callback;
47
48 /*
49  * Sets the Display callback for the current window
50  */
51 void FGAPIENTRY glutDisplayFunc( void (* callback)( void ) )
52 {
53     if( !callback )
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;
58 }
59
60 /*
61  * Sets the Reshape callback for the current window
62  */
63 void FGAPIENTRY glutReshapeFunc( void (* callback)( int, int ) )
64 {
65     SET_CALLBACK( Reshape );
66 }
67
68 /*
69  * Sets the Keyboard callback for the current window
70  */
71 void FGAPIENTRY glutKeyboardFunc( void (* callback)
72                                   ( unsigned char, int, int ) )
73 {
74     SET_CALLBACK( Keyboard );
75 }
76
77 /*
78  * Sets the Special callback for the current window
79  */
80 void FGAPIENTRY glutSpecialFunc( void (* callback)( int, int, int ) )
81 {
82     SET_CALLBACK( Special );
83 }
84
85 /*
86  * Sets the global idle callback
87  */
88 void FGAPIENTRY glutIdleFunc( void (* callback)( void ) )
89 {
90     freeglut_assert_ready;
91     fgState.IdleCallback = callback;
92 }
93
94 /*
95  * Sets the Timer callback for the current window
96  */
97 void FGAPIENTRY glutTimerFunc( unsigned int timeOut, void (* callback)( int ),
98                                int timerID )
99 {
100     SFG_Timer* timer;
101
102     freeglut_assert_ready;
103
104     timer = (SFG_Timer *)calloc( sizeof(SFG_Timer), 1 );
105     if (!timer)
106       fgError ("Fatal error: "
107           "Memory allocation failure in glutTimerFunc()\n");
108
109     timer->Callback  = callback;
110     timer->ID        = timerID;
111     timer->TriggerTime = fgElapsedTime() + timeOut;
112     fgListAppend( &fgState.Timers, &timer->Node );
113 }
114
115 /*
116  * Sets the Visibility callback for the current window.
117  */
118 static void fghVisibility( int status )
119 {
120     freeglut_assert_ready;
121     freeglut_return_if_fail( fgStructure.Window );
122     freeglut_return_if_fail( fgStructure.Window->Callbacks.Visibility );
123
124     if( status == GLUT_HIDDEN  || status == GLUT_FULLY_COVERED )
125         fgStructure.Window->Callbacks.Visibility( GLUT_NOT_VISIBLE );
126     else
127         fgStructure.Window->Callbacks.Visibility( GLUT_VISIBLE );
128 }
129
130 void FGAPIENTRY glutVisibilityFunc( void (* callback)( int ) )
131 {
132     SET_CALLBACK( Visibility );
133
134     if( callback )
135         glutWindowStatusFunc( fghVisibility );
136     else
137         glutWindowStatusFunc( NULL );
138 }
139
140 /*
141  * Sets the keyboard key release callback for the current window
142  */
143 void FGAPIENTRY glutKeyboardUpFunc( void (* callback)
144                                     ( unsigned char, int, int ) )
145 {
146     SET_CALLBACK( KeyboardUp );
147 }
148
149 /*
150  * Sets the special key release callback for the current window
151  */
152 void FGAPIENTRY glutSpecialUpFunc( void (* callback)( int, int, int ) )
153 {
154     SET_CALLBACK( SpecialUp );
155 }
156
157 /*
158  * Sets the joystick callback and polling rate for the current window
159  */
160 void FGAPIENTRY glutJoystickFunc( void (* callback)
161                                   ( unsigned int, int, int, int ),
162                                   int pollInterval )
163 {
164     SET_CALLBACK( Joystick );
165     fgStructure.Window->State.JoystickPollRate = pollInterval;
166
167     fgStructure.Window->State.JoystickLastPoll =
168         fgElapsedTime() - fgStructure.Window->State.JoystickPollRate;
169
170     if( fgStructure.Window->State.JoystickLastPoll < 0 )
171         fgStructure.Window->State.JoystickLastPoll = 0;
172 }
173
174 /*
175  * Sets the mouse callback for the current window
176  */
177 void FGAPIENTRY glutMouseFunc( void (* callback)( int, int, int, int ) )
178 {
179     SET_CALLBACK( Mouse );
180 }
181
182 /*
183  * Sets the mouse wheel callback for the current window
184  */
185 void FGAPIENTRY glutMouseWheelFunc( void (* callback)( int, int, int, int ) )
186 {
187     SET_CALLBACK( MouseWheel );
188 }
189
190 /*
191  * Sets the mouse motion callback for the current window (one or more buttons
192  * are pressed)
193  */
194 void FGAPIENTRY glutMotionFunc( void (* callback)( int, int ) )
195 {
196     SET_CALLBACK( Motion );
197 }
198
199 /*
200  * Sets the passive mouse motion callback for the current window (no mouse
201  * buttons are pressed)
202  */
203 void FGAPIENTRY glutPassiveMotionFunc( void (* callback)( int, int ) )
204 {
205     SET_CALLBACK( Passive );
206 }
207
208 /*
209  * Window mouse entry/leave callback
210  */
211 void FGAPIENTRY glutEntryFunc( void (* callback)( int ) )
212 {
213     SET_CALLBACK( Entry );
214 }
215
216 /*
217  * Window destruction callbacks
218  */
219 void FGAPIENTRY glutCloseFunc( void (* callback)( void ) )
220 {
221     SET_CALLBACK( Destroy );
222 }
223
224 void FGAPIENTRY glutWMCloseFunc( void (* callback)( void ) )
225 {
226     glutCloseFunc( callback );
227 }
228
229 /* A. Donev: Destruction callback for menus */
230 void FGAPIENTRY glutMenuDestroyFunc( void (* callback)( void ) )
231 {
232    if( fgStructure.Menu == NULL )
233        return;
234    fgStructure.Menu->Destroy = callback;
235 }
236
237 /*
238  * Deprecated version of glutMenuStatusFunc callback setting method
239  */
240 void FGAPIENTRY glutMenuStateFunc( void (* callback)( int ) )
241 {
242     freeglut_assert_ready;
243     fgState.MenuStateCallback = callback;
244 }
245
246 /*
247  * Sets the global menu status callback for the current window
248  */
249 void FGAPIENTRY glutMenuStatusFunc( void (* callback)( int, int, int ) )
250 {
251     freeglut_assert_ready;
252     fgState.MenuStatusCallback = callback;
253 }
254
255 /*
256  * Sets the overlay display callback for the current window
257  */
258 void FGAPIENTRY glutOverlayDisplayFunc( void (* callback)( void ) )
259 {
260     SET_CALLBACK( OverlayDisplay );
261 }
262
263 /*
264  * Sets the window status callback for the current window
265  */
266 void FGAPIENTRY glutWindowStatusFunc( void (* callback)( int ) )
267 {
268     SET_CALLBACK( WindowStatus );
269 }
270
271 /*
272  * Sets the spaceball motion callback for the current window
273  */
274 void FGAPIENTRY glutSpaceballMotionFunc( void (* callback)( int, int, int ) )
275 {
276     SET_CALLBACK( SpaceMotion );
277 }
278
279 /*
280  * Sets the spaceball rotate callback for the current window
281  */
282 void FGAPIENTRY glutSpaceballRotateFunc( void (* callback)( int, int, int ) )
283 {
284     SET_CALLBACK( SpaceRotation );
285 }
286
287 /*
288  * Sets the spaceball button callback for the current window
289  */
290 void FGAPIENTRY glutSpaceballButtonFunc( void (* callback)( int, int ) )
291 {
292     SET_CALLBACK( SpaceButton );
293 }
294
295 /*
296  * Sets the button box callback for the current window
297  */
298 void FGAPIENTRY glutButtonBoxFunc( void (* callback)( int, int ) )
299 {
300     SET_CALLBACK( ButtonBox );
301 }
302
303 /*
304  * Sets the dials box callback for the current window
305  */
306 void FGAPIENTRY glutDialsFunc( void (* callback)( int, int ) )
307 {
308     SET_CALLBACK( Dials );
309 }
310
311 /*
312  * Sets the tablet motion callback for the current window
313  */
314 void FGAPIENTRY glutTabletMotionFunc( void (* callback)( int, int ) )
315 {
316     SET_CALLBACK( TabletMotion );
317 }
318
319 /*
320  * Sets the tablet buttons callback for the current window
321  */
322 void FGAPIENTRY glutTabletButtonFunc( void (* callback)( int, int, int, int ) )
323 {
324     SET_CALLBACK( TabletButton );
325 }
326
327 /*** END OF FILE ***/