Subversion Repositories Games.Rick Dangerous

Rev

Rev 1 | Rev 10 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 pmbaty 1
/*
2
 * src/sysevt.c
3
 *
4
 * Copyright (C) 1998-2002 BigOrno (bigorno@bigorno.net). All rights reserved.
5
 *
6
 * The use and distribution terms for this software are contained in the file
7
 * named README, which can be found in the root of this distribution. By
8
 * using this software in any fashion, you are agreeing to be bound by the
9
 * terms of this license.
10
 *
11
 * You must not remove this notice, or any other, from this software.
12
 */
13
 
14
#include <SDL.h>
15
 
16
#include "system.h"
17
#include "game.h"
18
 
19
#include "control.h"
20
#include "draw.h"
21
 
22
#define SYSJOY_RANGE 3280
23
 
24
static SDL_Event event;
25
extern U8 want_filter;
26
extern U8 want_fullscreen;
7 pmbaty 27
extern U8 recreate_screen;
1 pmbaty 28
 
29
 
30
/*
31
 * Process an event
32
 */
33
static void processEvent (void)
34
{
35
   static U8 alt_pressed = FALSE;
36
 
7 pmbaty 37
   U16 key = event.key.keysym.scancode;
1 pmbaty 38
 
39
   switch (event.type)
40
   {
41
   case SDL_KEYDOWN:
7 pmbaty 42
      if (key == SDL_SCANCODE_LALT)
1 pmbaty 43
         alt_pressed = TRUE;
7 pmbaty 44
      else if (alt_pressed && key == SDL_SCANCODE_RETURN)
1 pmbaty 45
      {
46
         want_fullscreen ^= TRUE;
7 pmbaty 47
         recreate_screen = TRUE;
1 pmbaty 48
      }
7 pmbaty 49
      else if (alt_pressed && key == SDL_SCANCODE_F4)
1 pmbaty 50
      {
51
         control_status |= CONTROL_EXIT;
52
         control_last = CONTROL_EXIT;
53
      }
7 pmbaty 54
      else if (key == SDL_SCANCODE_O || key == SDL_SCANCODE_UP)
1 pmbaty 55
      {
56
         control_status |= CONTROL_UP;
57
         control_last = CONTROL_UP;
58
      }
7 pmbaty 59
      else if (key == SDL_SCANCODE_K || key == SDL_SCANCODE_DOWN)
1 pmbaty 60
      {
61
         control_status |= CONTROL_DOWN;
62
         control_last = CONTROL_DOWN;
63
      }
7 pmbaty 64
      else if (key == SDL_SCANCODE_Z || key == SDL_SCANCODE_LEFT)
1 pmbaty 65
      {
66
         control_status |= CONTROL_LEFT;
67
         control_last = CONTROL_LEFT;
68
      }
7 pmbaty 69
      else if (key == SDL_SCANCODE_X || key == SDL_SCANCODE_RIGHT)
1 pmbaty 70
      {
71
         control_status |= CONTROL_RIGHT;
72
         control_last = CONTROL_RIGHT;
73
      }
7 pmbaty 74
      else if (key == SDL_SCANCODE_PAUSE)
1 pmbaty 75
      {
76
         control_status |= CONTROL_PAUSE;
77
         control_last = CONTROL_PAUSE;
78
      }
7 pmbaty 79
      else if (key == SDL_SCANCODE_END)
1 pmbaty 80
      {
81
         control_status |= CONTROL_END;
82
         control_last = CONTROL_END;
83
      }
7 pmbaty 84
      else if (key == SDL_SCANCODE_ESCAPE)
1 pmbaty 85
      {
86
         control_status |= CONTROL_EXIT;
87
         control_last = CONTROL_EXIT;
88
      }
7 pmbaty 89
      else if (key == SDL_SCANCODE_SPACE)
1 pmbaty 90
      {
91
         control_status |= CONTROL_FIRE;
92
         control_last = CONTROL_FIRE;
93
      }
7 pmbaty 94
      else if (key == SDL_SCANCODE_F4)
1 pmbaty 95
         syssnd_toggleMute();
7 pmbaty 96
      else if (key == SDL_SCANCODE_F5)
1 pmbaty 97
         syssnd_vol(-1);
7 pmbaty 98
      else if (key == SDL_SCANCODE_F6)
1 pmbaty 99
         syssnd_vol(+1);
7 pmbaty 100
      else if (key == SDL_SCANCODE_F7)
1 pmbaty 101
         want_filter ^= TRUE;
7 pmbaty 102
      else if (key == SDL_SCANCODE_F10)
1 pmbaty 103
      {
104
         control_status &= ~CONTROL_EXIT;
105
         control_last = CONTROL_EXIT;
106
      }
107
      break;
108
   case SDL_KEYUP:
7 pmbaty 109
      if (key == SDL_SCANCODE_LALT)
1 pmbaty 110
         alt_pressed = FALSE;
7 pmbaty 111
      else if (key == SDL_SCANCODE_O || key == SDL_SCANCODE_UP)
1 pmbaty 112
      {
113
         control_status &= ~CONTROL_UP;
114
         control_last = CONTROL_UP;
115
      }
7 pmbaty 116
      else if (key == SDL_SCANCODE_K || key == SDL_SCANCODE_DOWN)
1 pmbaty 117
      {
118
         control_status &= ~CONTROL_DOWN;
119
         control_last = CONTROL_DOWN;
120
      }
7 pmbaty 121
      else if (key == SDL_SCANCODE_Z || key == SDL_SCANCODE_LEFT)
1 pmbaty 122
      {
123
         control_status &= ~CONTROL_LEFT;
124
         control_last = CONTROL_LEFT;
125
      }
7 pmbaty 126
      else if (key == SDL_SCANCODE_X || key == SDL_SCANCODE_RIGHT)
1 pmbaty 127
      {
128
         control_status &= ~CONTROL_RIGHT;
129
         control_last = CONTROL_RIGHT;
130
      }
7 pmbaty 131
      else if (key == SDL_SCANCODE_PAUSE)
1 pmbaty 132
      {
133
         control_status &= ~CONTROL_PAUSE;
134
         control_last = CONTROL_PAUSE;
135
      }
7 pmbaty 136
      else if (key == SDL_SCANCODE_END)
1 pmbaty 137
      {
138
         control_status &= ~CONTROL_END;
139
         control_last = CONTROL_END;
140
      }
7 pmbaty 141
      else if (key == SDL_SCANCODE_ESCAPE)
1 pmbaty 142
      {
143
         control_status &= ~CONTROL_EXIT;
144
         control_last = CONTROL_EXIT;
145
      }
7 pmbaty 146
      else if (key == SDL_SCANCODE_SPACE)
1 pmbaty 147
      {
148
         control_status &= ~CONTROL_FIRE;
149
         control_last = CONTROL_FIRE;
150
      }
151
      break;
152
   case SDL_QUIT:
153
      /* player tries to close the window -- this is the same as pressing ESC */
154
      control_status |= CONTROL_EXIT;
155
      control_last = CONTROL_EXIT;
156
      break;
157
   case SDL_JOYAXISMOTION:
158
      if (event.jaxis.axis == 0)
159
      {
160
         /* left-right */
161
         if (event.jaxis.value < -SYSJOY_RANGE)
162
         {   /* left */
163
            control_status |= CONTROL_LEFT;
164
            control_status &= ~CONTROL_RIGHT;
165
         }
166
         else if (event.jaxis.value > SYSJOY_RANGE)
167
         {   /* right */
168
            control_status |= CONTROL_RIGHT;
169
            control_status &= ~CONTROL_LEFT;
170
         }
171
         else
172
         {   /* center */
173
            control_status &= ~CONTROL_RIGHT;
174
            control_status &= ~CONTROL_LEFT;
175
         }
176
      }
177
      if (event.jaxis.axis == 1)
178
      {
179
         /* up-down */
180
         if (event.jaxis.value < -SYSJOY_RANGE)
181
         {   /* up */
182
            control_status |= CONTROL_UP;
183
            control_status &= ~CONTROL_DOWN;
184
         }
185
         else if (event.jaxis.value > SYSJOY_RANGE)
186
         {   /* down */
187
            control_status |= CONTROL_DOWN;
188
            control_status &= ~CONTROL_UP;
189
         }
190
         else
191
         {   /* center */
192
            control_status &= ~CONTROL_DOWN;
193
            control_status &= ~CONTROL_UP;
194
         }
195
      }
196
      break;
197
   case SDL_JOYBUTTONDOWN:
198
      control_status |= CONTROL_FIRE;
199
      break;
200
   case SDL_JOYBUTTONUP:
201
      control_status &= ~CONTROL_FIRE;
202
      break;
203
   default:
204
      break;
205
   }
206
}
207
 
208
 
209
/*
210
 * Process events, if any, then return
211
 */
212
void sysevt_poll (void)
213
{
214
   while (SDL_PollEvent (&event))
215
      processEvent ();
216
}
217
 
218
 
219
/*
220
 * Wait for an event, then process it and return
221
 */
222
void sysevt_wait (void)
223
{
224
   SDL_WaitEvent (&event);
225
   processEvent ();
226
}