added console code (from SDL_console)
[btb/d2x.git] / arch / sdl / event.c
1 /* $Id: event.c,v 1.10 2003-06-02 01:55:03 btb Exp $ */
2 /*
3  *
4  * SDL Event related stuff
5  *
6  *
7  */
8
9 #ifdef HAVE_CONFIG_H
10 #include <conf.h>
11 #endif
12
13 #include <stdio.h>
14 #include <stdlib.h>
15
16 #include <SDL.h>
17 #include "CON_console.h"
18
19 extern void key_handler(SDL_KeyboardEvent *event);
20 extern void mouse_button_handler(SDL_MouseButtonEvent *mbe);
21 extern void mouse_motion_handler(SDL_MouseMotionEvent *mme);
22 #ifndef USE_LINUX_JOY // stpohle - so we can choose at compile time..
23 extern void joy_button_handler(SDL_JoyButtonEvent *jbe);
24 extern void joy_hat_handler(SDL_JoyHatEvent *jhe);
25 extern void joy_axis_handler(SDL_JoyAxisEvent *jae);
26 #endif
27
28 static int initialised=0;
29
30 void event_poll()
31 {
32         SDL_Event event;
33
34         while (SDL_PollEvent(&event)) {
35                 if(!CON_Events(&event))
36                         continue;
37                 switch(event.type) {
38                 case SDL_KEYDOWN:
39                 case SDL_KEYUP:
40                         key_handler((SDL_KeyboardEvent *)&event);
41                         break;
42                 case SDL_MOUSEBUTTONDOWN:
43                 case SDL_MOUSEBUTTONUP:
44                         mouse_button_handler((SDL_MouseButtonEvent *)&event);
45                         break;
46                 case SDL_MOUSEMOTION:
47                         mouse_motion_handler((SDL_MouseMotionEvent *)&event);
48                         break;
49 #ifndef USE_LINUX_JOY       // stpohle - so we can choose at compile time..
50                 case SDL_JOYBUTTONDOWN:
51                 case SDL_JOYBUTTONUP:
52                         joy_button_handler((SDL_JoyButtonEvent *)&event);
53                         break;
54                 case SDL_JOYAXISMOTION:
55                         joy_axis_handler((SDL_JoyAxisEvent *)&event);
56                         break;
57                 case SDL_JOYHATMOTION:
58                         joy_hat_handler((SDL_JoyHatEvent *)&event);
59                         break;
60                 case SDL_JOYBALLMOTION:
61                         break;
62 #endif
63                 case SDL_QUIT: {
64                         void quit_request();
65                         quit_request();
66                 } break;
67                 }
68         }
69 }
70
71 int event_init()
72 {
73         // We should now be active and responding to events.
74         initialised = 1;
75
76         return 0;
77 }