make console optional, other fixes
[btb/d2x.git] / arch / sdl / event.c
1 /* $Id: event.c,v 1.11 2003-06-02 05:56:37 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 #ifdef CONSOLE
18 #include "CON_console.h"
19 #endif
20
21 extern void key_handler(SDL_KeyboardEvent *event);
22 extern void mouse_button_handler(SDL_MouseButtonEvent *mbe);
23 extern void mouse_motion_handler(SDL_MouseMotionEvent *mme);
24 #ifndef USE_LINUX_JOY // stpohle - so we can choose at compile time..
25 extern void joy_button_handler(SDL_JoyButtonEvent *jbe);
26 extern void joy_hat_handler(SDL_JoyHatEvent *jhe);
27 extern void joy_axis_handler(SDL_JoyAxisEvent *jae);
28 #endif
29
30 static int initialised=0;
31
32 void event_poll()
33 {
34         SDL_Event event;
35
36         while (SDL_PollEvent(&event)) {
37 #ifdef CONSOLE
38                 if(!CON_Events(&event))
39                         continue;
40 #endif
41                 switch(event.type) {
42                 case SDL_KEYDOWN:
43                 case SDL_KEYUP:
44                         key_handler((SDL_KeyboardEvent *)&event);
45                         break;
46                 case SDL_MOUSEBUTTONDOWN:
47                 case SDL_MOUSEBUTTONUP:
48                         mouse_button_handler((SDL_MouseButtonEvent *)&event);
49                         break;
50                 case SDL_MOUSEMOTION:
51                         mouse_motion_handler((SDL_MouseMotionEvent *)&event);
52                         break;
53 #ifndef USE_LINUX_JOY       // stpohle - so we can choose at compile time..
54                 case SDL_JOYBUTTONDOWN:
55                 case SDL_JOYBUTTONUP:
56                         joy_button_handler((SDL_JoyButtonEvent *)&event);
57                         break;
58                 case SDL_JOYAXISMOTION:
59                         joy_axis_handler((SDL_JoyAxisEvent *)&event);
60                         break;
61                 case SDL_JOYHATMOTION:
62                         joy_hat_handler((SDL_JoyHatEvent *)&event);
63                         break;
64                 case SDL_JOYBALLMOTION:
65                         break;
66 #endif
67                 case SDL_QUIT: {
68                         void quit_request();
69                         quit_request();
70                 } break;
71                 }
72         }
73 }
74
75 int event_init()
76 {
77         // We should now be active and responding to events.
78         initialised = 1;
79
80         return 0;
81 }