Remove DirectFBGL header from Mesa bacause since 1.0.0 DirectFB installs its own...
[mesa.git] / src / glut / directfb / callback.c
1 /*
2 * Copyright (C) 2006 Claudio Ciccani <klan@users.sf.net>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <sys/time.h>
24
25 #include "internal.h"
26
27
28 typedef void (GLUTCALLBACK *__GlutTimerCallback) ( int value );
29
30 typedef struct __GlutTimer_s {
31 unsigned int interval;
32 struct timeval expire;
33
34 __GlutTimerCallback func;
35 int value;
36
37 struct __GlutTimer_s *next;
38 struct __GlutTimer_s *prev;
39 } __GlutTimer;
40
41 /*****************************************************************************/
42
43 static __GlutTimer *g_timers = NULL;
44
45 /*****************************************************************************/
46
47
48 void GLUTAPIENTRY
49 glutDisplayFunc( void (GLUTCALLBACK *func) (void) )
50 {
51 display_func = func;
52 }
53
54
55 void GLUTAPIENTRY
56 glutReshapeFunc( void (GLUTCALLBACK *func) (int width, int height) )
57 {
58 reshape_func = func;
59 }
60
61
62 void GLUTAPIENTRY
63 glutKeyboardFunc( void (GLUTCALLBACK *func) (unsigned char key, int x, int y) )
64 {
65 keyboard_func = func;
66 }
67
68
69 void GLUTAPIENTRY
70 glutMouseFunc( void (GLUTCALLBACK *func) (int button, int state, int x, int y) )
71 {
72 mouse_func = func;
73 }
74
75
76 void GLUTAPIENTRY
77 glutMotionFunc( void (GLUTCALLBACK *func) (int x, int y) )
78 {
79 motion_func = func;
80 }
81
82
83 void GLUTAPIENTRY
84 glutPassiveMotionFunc( void (GLUTCALLBACK *func) (int x, int y) )
85 {
86 passive_motion_func = func;
87 }
88
89
90 void GLUTAPIENTRY
91 glutEntryFunc( void (GLUTCALLBACK *func) (int state) )
92 {
93 entry_func = func;
94 }
95
96
97 void GLUTAPIENTRY
98 glutVisibilityFunc( void (GLUTCALLBACK *func) (int state) )
99 {
100 visibility_func = func;
101 }
102
103
104 void GLUTAPIENTRY
105 glutMenuStateFunc( void (GLUTCALLBACK *func) (int state) )
106 {
107 menu_state_func = func;
108 }
109
110
111 void GLUTAPIENTRY
112 glutSpecialFunc( void (GLUTCALLBACK *func) (int key, int x, int y) )
113 {
114 special_func = func;
115 }
116
117
118 void GLUTAPIENTRY
119 glutSpaceballMotionFunc( void (GLUTCALLBACK *func) (int x, int y, int z) )
120 {
121 }
122
123
124 void GLUTAPIENTRY
125 glutSpaceballRotateFunc( void (GLUTCALLBACK *func) (int x, int y, int z) )
126 {
127 }
128
129
130 void GLUTAPIENTRY
131 glutSpaceballButtonFunc( void (GLUTCALLBACK *func) (int button, int state) )
132 {
133 }
134
135
136 void GLUTAPIENTRY
137 glutButtonBoxFunc( void (GLUTCALLBACK *func) (int button, int state) )
138 {
139 }
140
141
142 void GLUTAPIENTRY
143 glutDialsFunc( void (GLUTCALLBACK *func) (int dial, int value) )
144 {
145 }
146
147
148 void GLUTAPIENTRY
149 glutTabletMotionFunc( void (GLUTCALLBACK *func) (int x, int y) )
150 {
151 }
152
153
154 void GLUTAPIENTRY
155 glutTabletButtonFunc( void (GLUTCALLBACK *func) (int button, int state, int x, int y) )
156 {
157 }
158
159
160 void GLUTAPIENTRY
161 glutMenuStatusFunc( void (GLUTCALLBACK *func) (int status, int x, int y) )
162 {
163 }
164
165
166 void GLUTAPIENTRY
167 glutOverlayDisplayFunc( void (GLUTCALLBACK *func) (void) )
168 {
169 }
170
171
172 void GLUTAPIENTRY
173 glutWindowStatusFunc( void (GLUTCALLBACK *func) (int state) )
174 {
175 }
176
177
178 void GLUTAPIENTRY
179 glutKeyboardUpFunc( void (GLUTCALLBACK *func) (unsigned char key, int x, int y) )
180 {
181 keyboard_up_func = func;
182 }
183
184
185 void GLUTAPIENTRY
186 glutSpecialUpFunc( void (GLUTCALLBACK *func) (int key, int x, int y) )
187 {
188 special_up_func = func;
189 }
190
191
192 void GLUTAPIENTRY
193 glutJoystickFunc( void (GLUTCALLBACK *func)(unsigned int buttons, int x, int y, int z), int pollInterval )
194 {
195 joystick_func = func;
196 /* FIXME: take care of pollInterval */
197 }
198
199
200 void GLUTAPIENTRY
201 glutIdleFunc( void (GLUTCALLBACK *func) (void) )
202 {
203 idle_func = func;
204 }
205
206
207 void GLUTAPIENTRY
208 glutTimerFunc( unsigned int msec, void (GLUTCALLBACK *func) (int value), int value )
209 {
210 __GlutTimer *timer;
211 struct timeval now;
212
213 if (!func)
214 return;
215
216 timer = calloc( 1, sizeof(__GlutTimer) );
217 if (!timer)
218 __glutFatalError( "out of memory" );
219
220 gettimeofday( &now, NULL );
221
222 timer->interval = msec;
223 timer->expire.tv_sec = now.tv_sec + (now.tv_usec/1000 + msec) / 1000;
224 timer->expire.tv_usec = (now.tv_usec + msec*1000) % 1000000;
225
226 timer->func = func;
227 timer->value = value;
228
229 if (g_timers) {
230 timer->prev = g_timers->prev;
231 g_timers->prev->next = timer;
232 g_timers->prev = timer;
233 }
234 else {
235 g_timers = timer;
236 g_timers->prev = timer;
237 }
238 }
239
240
241 void
242 __glutHandleTimers( void )
243 {
244 __GlutTimer *cur;
245 struct timeval now;
246
247 for (cur = g_timers; cur; cur = cur->next ) {
248 gettimeofday( &now, NULL );
249
250 if (cur->expire.tv_sec > now.tv_sec ||
251 (cur->expire.tv_sec == now.tv_sec &&
252 cur->expire.tv_usec >= now.tv_usec))
253 {
254 g_idle = GL_FALSE;
255
256 cur->func( cur->value );
257
258 cur->expire.tv_sec += (cur->expire.tv_usec/1000 + cur->interval) / 1000;
259 cur->expire.tv_usec = (cur->expire.tv_usec + cur->interval*1000) % 1000000;
260 }
261 }
262 }
263
264
265 void
266 __glutFreeTimers( void )
267 {
268 __GlutTimer *cur = g_timers;
269
270 while (cur) {
271 __GlutTimer *next = cur->next;
272 free( cur );
273 cur = next;
274 }
275
276 g_timers = NULL;
277 }
278