2 * Copyright (C) 2006 Claudio Ciccani <klan@users.sf.net>
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.
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.
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
27 /*****************************************************************************/
29 static int g_ignore_key_repeat
= 0;
31 /*****************************************************************************/
35 glutDeviceGet( GLenum type
)
38 case GLUT_HAS_KEYBOARD
:
39 return (keyboard
!= NULL
);
41 return (mouse
!= NULL
);
42 case GLUT_NUM_MOUSE_BUTTONS
:
44 DFBInputDeviceDescription dsc
;
45 mouse
->GetDescription( mouse
, &dsc
);
46 return dsc
.max_button
+1;
49 case GLUT_DEVICE_IGNORE_KEY_REPEAT
:
50 return g_ignore_key_repeat
;
51 case GLUT_DEVICE_KEY_REPEAT
:
52 return (g_ignore_key_repeat
) ? GLUT_KEY_REPEAT_OFF
54 case GLUT_HAS_JOYSTICK
:
55 case GLUT_OWNS_JOYSTICK
:
56 return (g_game
&& joystick
); /* only available in game mode */
57 case GLUT_JOYSTICK_BUTTONS
:
59 DFBInputDeviceDescription dsc
;
60 joystick
->GetDescription( joystick
, &dsc
);
61 return dsc
.max_button
+1;
64 case GLUT_JOYSTICK_AXES
:
66 DFBInputDeviceDescription dsc
;
67 joystick
->GetDescription( joystick
, &dsc
);
68 return dsc
.max_axis
+1;
71 case GLUT_JOYSTICK_POLL_RATE
:
84 glutGetModifiers( void )
87 return g_current
->modifiers
;
93 glutIgnoreKeyRepeat( int ignore
)
95 g_ignore_key_repeat
= ignore
;
100 glutSetKeyRepeat( int mode
)
102 g_ignore_key_repeat
= (mode
== GLUT_KEY_REPEAT_OFF
);
107 glutForceJoystickFunc( void )
109 if (g_game
&& joystick
&& joystick_func
) {
110 joystick_func( g_game
->buttons
,
111 g_game
->jx
, g_game
->jy
, g_game
->jz
);
117 __glutSpecialKey( DFBInputDeviceKeySymbol key
)
144 case DIKS_CURSOR_LEFT
:
145 return GLUT_KEY_LEFT
;
148 case DIKS_CURSOR_RIGHT
:
149 return GLUT_KEY_RIGHT
;
150 case DIKS_CURSOR_DOWN
:
151 return GLUT_KEY_DOWN
;
153 return GLUT_KEY_PAGE_UP
;
155 return GLUT_KEY_PAGE_DOWN
;
157 return GLUT_KEY_HOME
;
161 return GLUT_KEY_INSERT
;
171 __glutButton( DFBInputDeviceButtonIdentifier button
)
175 return GLUT_LEFT_BUTTON
;
177 return GLUT_MIDDLE_BUTTON
;
179 return GLUT_RIGHT_BUTTON
;
189 __glutModifiers( DFBInputDeviceModifierMask mask
)
191 return ((mask
& DIMM_SHIFT
) ? GLUT_ACTIVE_SHIFT
: 0) |
192 ((mask
& DIMM_CONTROL
) ? GLUT_ACTIVE_CTRL
: 0) |
193 ((mask
& DIMM_ALT
) ? GLUT_ACTIVE_ALT
: 0);
198 __glutWindowEvent( DFBWindowEvent
*e
, DFBWindowEvent
*p
)
200 __GlutWindow
*window
;
202 window
= __glutFindWindow( e
->window_id
);
203 if (!window
) /* window was destroyed */
208 window
->modifiers
= __glutModifiers( e
->modifiers
);
209 if (g_ignore_key_repeat
&& p
) {
210 if (p
->type
== DWET_KEYDOWN
&&
211 p
->window_id
== e
->window_id
&&
212 p
->key_symbol
== e
->key_symbol
)
215 if (DFB_KEY_IS_ASCII( e
->key_symbol
)) {
217 __glutSetWindow( window
);
218 keyboard_func( e
->key_symbol
, e
->x
, e
->y
);
222 int key
= __glutSpecialKey( e
->key_symbol
);
223 if (key
&& special_func
) {
224 __glutSetWindow( window
);
225 special_func( key
, e
->x
, e
->y
);
230 window
->modifiers
= __glutModifiers( e
->modifiers
);
231 if (DFB_KEY_IS_ASCII( e
->key_symbol
)) {
232 if (keyboard_up_func
) {
233 __glutSetWindow( window
);
234 keyboard_up_func( e
->key_symbol
, e
->x
, e
->y
);
238 int key
= __glutSpecialKey( e
->key_symbol
);
239 if (key
&& special_up_func
) {
240 __glutSetWindow( window
);
241 special_up_func( key
, e
->x
, e
->y
);
245 case DWET_BUTTONDOWN
:
247 __glutSetWindow( window
);
248 mouse_func( __glutButton( e
->button
), GLUT_DOWN
, e
->x
, e
->y
);
253 __glutSetWindow( window
);
254 mouse_func( __glutButton( e
->button
), GLUT_UP
, e
->x
, e
->y
);
260 __glutSetWindow( window
);
261 motion_func( e
->cx
, e
->cy
);
265 if (passive_motion_func
) {
266 __glutSetWindow( window
);
267 passive_motion_func( e
->cx
, e
->cy
);
273 __glutSetWindow( window
);
274 entry_func( GLUT_ENTERED
);
279 __glutSetWindow( window
);
280 entry_func( GLUT_LEFT
);
284 window
->reshape
= GL_TRUE
;
285 window
->redisplay
= GL_TRUE
;
294 __glutInputEvent( DFBInputEvent
*e
, DFBInputEvent
*p
)
296 __glutAssert( g_game
!= NULL
);
300 g_game
->modifiers
= __glutModifiers( e
->modifiers
);
301 if (g_ignore_key_repeat
&& p
) {
302 if (p
->type
== DIET_KEYPRESS
&&
303 p
->key_symbol
== e
->key_symbol
)
306 if (DFB_KEY_IS_ASCII( e
->key_symbol
)) {
308 __glutSetWindow( g_game
);
309 keyboard_func( e
->key_symbol
, g_game
->cx
, g_game
->cy
);
313 int key
= __glutSpecialKey( e
->key_symbol
);
314 if (key
&& special_func
) {
315 __glutSetWindow( g_game
);
316 special_func( key
, g_game
->cx
, g_game
->cy
);
320 case DIET_KEYRELEASE
:
321 g_game
->modifiers
= __glutModifiers( e
->modifiers
);
322 if (DFB_KEY_IS_ASCII( e
->key_symbol
)) {
323 if (keyboard_up_func
) {
324 __glutSetWindow( g_game
);
325 keyboard_up_func( e
->key_symbol
, g_game
->cx
, g_game
->cy
);
329 int key
= __glutSpecialKey( e
->key_symbol
);
330 if (key
&& special_up_func
) {
331 __glutSetWindow( g_game
);
332 special_up_func( key
, g_game
->cx
, g_game
->cy
);
336 case DIET_BUTTONPRESS
:
337 if (e
->device_id
== DIDID_JOYSTICK
) {
338 g_game
->buttons
= e
->buttons
;
340 __glutSetWindow( g_game
);
341 joystick_func( g_game
->buttons
,
342 g_game
->jx
, g_game
->jy
, g_game
->jz
);
347 __glutSetWindow( g_game
);
348 mouse_func( __glutButton( e
->button
),
349 GLUT_DOWN
, g_game
->cx
, g_game
->cy
);
353 case DIET_BUTTONRELEASE
:
354 if (e
->device_id
== DIDID_JOYSTICK
) {
355 g_game
->buttons
= e
->buttons
;
357 __glutSetWindow( g_game
);
358 joystick_func( g_game
->buttons
,
359 g_game
->jx
, g_game
->jy
, g_game
->jz
);
364 __glutSetWindow( g_game
);
365 mouse_func( __glutButton( e
->button
),
366 GLUT_UP
, g_game
->cx
, g_game
->cy
);
370 case DIET_AXISMOTION
:
371 if (e
->device_id
== DIDID_JOYSTICK
) {
374 if (e
->flags
& DIEF_AXISABS
)
375 g_game
->jx
= e
->axisabs
;
376 else if (e
->flags
& DIEF_AXISREL
)
377 g_game
->jx
+= e
->axisrel
;
380 if (e
->flags
& DIEF_AXISABS
)
381 g_game
->jy
= e
->axisabs
;
382 else if (e
->flags
& DIEF_AXISREL
)
383 g_game
->jy
+= e
->axisrel
;
386 if (e
->flags
& DIEF_AXISABS
)
387 g_game
->jz
= e
->axisabs
;
388 else if (e
->flags
& DIEF_AXISREL
)
389 g_game
->jz
+= e
->axisrel
;
395 __glutSetWindow( g_game
);
396 joystick_func( g_game
->buttons
,
397 g_game
->jx
, g_game
->jy
, g_game
->jz
);
403 if (e
->flags
& DIEF_AXISABS
)
404 g_game
->cx
= e
->axisabs
;
405 else if (e
->flags
& DIEF_AXISREL
)
406 g_game
->cx
+= e
->axisrel
;
409 if (e
->flags
& DIEF_AXISABS
)
410 g_game
->cy
= e
->axisabs
;
411 else if (e
->flags
& DIEF_AXISREL
)
412 g_game
->cy
+= e
->axisrel
;
417 if (e
->buttons
&& motion_func
) {
418 __glutSetWindow( g_game
);
419 motion_func( g_game
->cx
, g_game
->cy
);
421 else if (!e
->buttons
&& passive_motion_func
) {
422 __glutSetWindow( g_game
);
423 passive_motion_func( g_game
->cx
, g_game
->cy
);
436 __glutAssert( events
!= NULL
);
438 __glutHandleWindows();
445 __glutHandleTimers();
447 prev
.clazz
= DFEC_NONE
;
449 while (events
->GetEvent( events
, &evt
) == DFB_OK
) {
454 if (prev
.clazz
== DFEC_WINDOW
)
455 __glutWindowEvent( &evt
.window
, &prev
.window
);
457 __glutWindowEvent( &evt
.window
, NULL
);
460 if (prev
.clazz
== DFEC_INPUT
)
461 __glutInputEvent( &evt
.input
, &prev
.input
);
463 __glutInputEvent( &evt
.input
, NULL
);
466 __glutWarning( "unexpected event class %d!\n", evt
.clazz
);
472 __glutHandleTimers();
475 __glutHandleWindows();
483 __glutSetWindow( NULL
);
484 if (__glutGetTimeout( &msec
))
485 events
->WaitForEventWithTimeout( events
, msec
/1000, msec
%1000 );
487 events
->WaitForEvent( events
);