fixed bug where player actions were incorrectly mapped in single player mode (also...
[rocksndiamonds.git] / src / libgame / sdl.h
1 // ============================================================================
2 // Artsoft Retro-Game Library
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
5 //                  Holger Schemel
6 //                  info@artsoft.org
7 //                  http://www.artsoft.org/
8 // ----------------------------------------------------------------------------
9 // sdl.h
10 // ============================================================================
11
12 #ifndef SDL_H
13 #define SDL_H
14
15 #include <SDL.h>
16 #include <SDL_image.h>
17 #include <SDL_mixer.h>
18 #include <SDL_net.h>
19 #include <SDL_thread.h>
20 #if defined(PLATFORM_WIN32)
21 #include <SDL_syswm.h>
22 #endif
23
24 /* definitions needed for "system.c" */
25
26 #if defined(TARGET_SDL2)
27 #define SURFACE_FLAGS           (0)
28 #else
29 #define SURFACE_FLAGS           (SDL_SWSURFACE)
30 #endif
31
32 #if defined(TARGET_SDL2)
33 #define SET_TRANSPARENT_PIXEL   (SDL_TRUE)
34 #define UNSET_TRANSPARENT_PIXEL (SDL_FALSE)
35 #else
36 #define SET_TRANSPARENT_PIXEL   (SDL_SRCCOLORKEY)
37 #define UNSET_TRANSPARENT_PIXEL (0)
38 #endif
39
40 /* system dependent definitions */
41
42 #if defined(TARGET_SDL2)
43 #define TARGET_STRING           "SDL2"
44 #else
45 #define TARGET_STRING           "SDL"
46 #endif
47
48 #if defined(PLATFORM_ANDROID)
49 #define WINDOW_SCALING_STATUS   WINDOW_SCALING_NOT_AVAILABLE
50 #define FULLSCREEN_STATUS       FULLSCREEN_AVAILABLE
51 #define USE_DESKTOP_FULLSCREEN  TRUE
52 #elif defined(TARGET_SDL2)
53 #define WINDOW_SCALING_STATUS   WINDOW_SCALING_AVAILABLE
54 #define FULLSCREEN_STATUS       FULLSCREEN_AVAILABLE
55 #define USE_DESKTOP_FULLSCREEN  TRUE
56 #else   // SDL 1.2
57 #define WINDOW_SCALING_STATUS   WINDOW_SCALING_NOT_AVAILABLE
58 #define FULLSCREEN_STATUS       FULLSCREEN_AVAILABLE
59 #endif
60
61 #define CURSOR_MAX_WIDTH        32
62 #define CURSOR_MAX_HEIGHT       32
63
64
65 /* SDL type definitions */
66
67 typedef struct SDLSurfaceInfo   Bitmap;
68 typedef struct SDLSurfaceInfo   DrawBuffer;
69 typedef struct SDLSurfaceInfo   DrawWindow;
70 typedef Uint32                  Pixel;
71 typedef SDL_Cursor             *Cursor;
72
73 #if defined(TARGET_SDL2)
74 typedef SDL_Keycode             Key;
75 typedef SDL_Keymod              KeyMod;
76 #else
77 typedef SDLKey                  Key;
78 typedef unsigned int            KeyMod;
79 #endif
80
81 typedef SDL_Event               Event;
82 typedef SDL_MouseButtonEvent    ButtonEvent;
83 typedef SDL_MouseMotionEvent    MotionEvent;
84 #if defined(TARGET_SDL2)
85 typedef SDL_TouchFingerEvent    FingerEvent;
86 typedef SDL_TextInputEvent      TextEvent;
87 typedef SDL_Event               PauseResumeEvent;
88 typedef SDL_WindowEvent         WindowEvent;
89 #endif
90 typedef SDL_KeyboardEvent       KeyEvent;
91 typedef SDL_Event               ExposeEvent;
92 typedef SDL_Event               FocusChangeEvent;
93 typedef SDL_Event               ClientMessageEvent;
94
95
96 /* structure definitions */
97
98 struct SDLSurfaceInfo
99 {
100   char *source_filename;
101
102   int width, height;
103   SDL_Surface *surface;
104   SDL_Surface *surface_masked;
105 };
106
107 struct MouseCursorInfo
108 {
109   int width, height;
110   int hot_x, hot_y;
111
112   byte data[CURSOR_MAX_WIDTH * CURSOR_MAX_HEIGHT / 8];
113   byte mask[CURSOR_MAX_WIDTH * CURSOR_MAX_HEIGHT / 8];
114 };
115
116
117 /* SDL symbol definitions */
118
119 #define None                    0L
120
121 #define BLACK_PIXEL             0x000000
122 #define WHITE_PIXEL             0xffffff
123
124 #define EVENT_BUTTONPRESS       SDL_MOUSEBUTTONDOWN
125 #define EVENT_BUTTONRELEASE     SDL_MOUSEBUTTONUP
126 #define EVENT_MOTIONNOTIFY      SDL_MOUSEMOTION
127 #if defined(TARGET_SDL2)
128 #define EVENT_FINGERPRESS       SDL_FINGERDOWN
129 #define EVENT_FINGERRELEASE     SDL_FINGERUP
130 #define EVENT_FINGERMOTION      SDL_FINGERMOTION
131 #define EVENT_TEXTINPUT         SDL_TEXTINPUT
132 #endif
133 #define EVENT_KEYPRESS          SDL_KEYDOWN
134 #define EVENT_KEYRELEASE        SDL_KEYUP
135 #define EVENT_EXPOSE            SDL_USEREVENT + 0
136 #define EVENT_FOCUSIN           SDL_USEREVENT + 1
137 #define EVENT_FOCUSOUT          SDL_USEREVENT + 2
138 #define EVENT_CLIENTMESSAGE     SDL_QUIT
139 #define EVENT_MAPNOTIFY         SDL_USEREVENT + 4
140 #define EVENT_UNMAPNOTIFY       SDL_USEREVENT + 5
141
142 #define KSYM_UNDEFINED          SDLK_UNKNOWN
143
144 #define KSYM_Return             SDLK_RETURN
145 #define KSYM_Escape             SDLK_ESCAPE
146
147 #define KSYM_Left               SDLK_LEFT
148 #define KSYM_Right              SDLK_RIGHT
149 #define KSYM_Up                 SDLK_UP
150 #define KSYM_Down               SDLK_DOWN
151
152 #ifdef SDLK_KP_LEFT
153 #define KSYM_KP_Left            SDLK_KP_LEFT
154 #define KSYM_KP_Right           SDLK_KP_RIGHT
155 #define KSYM_KP_Up              SDLK_KP_UP
156 #define KSYM_KP_Down            SDLK_KP_DOWN
157 #endif
158
159 #define KSYM_KP_Enter           SDLK_KP_ENTER
160 #define KSYM_KP_Add             SDLK_KP_PLUS
161 #define KSYM_KP_Subtract        SDLK_KP_MINUS
162 #define KSYM_KP_Multiply        SDLK_KP_MULTIPLY
163 #define KSYM_KP_Divide          SDLK_KP_DIVIDE
164 #define KSYM_KP_Separator       SDLK_KP_PERIOD
165
166 #define KSYM_Shift_L            SDLK_LSHIFT
167 #define KSYM_Shift_R            SDLK_RSHIFT
168 #define KSYM_Control_L          SDLK_LCTRL
169 #define KSYM_Control_R          SDLK_RCTRL
170
171 #if defined(TARGET_SDL2)
172 #define KSYM_Meta_L             SDLK_LGUI
173 #define KSYM_Meta_R             SDLK_RGUI
174 #else
175 #define KSYM_Meta_L             SDLK_LMETA
176 #define KSYM_Meta_R             SDLK_RMETA
177 #endif
178
179 #define KSYM_Alt_L              SDLK_LALT
180 #define KSYM_Alt_R              SDLK_RALT
181 #if !defined(TARGET_SDL2)
182 #define KSYM_Super_L            SDLK_LSUPER
183 #define KSYM_Super_R            SDLK_RSUPER
184 #endif
185 #define KSYM_Mode_switch        SDLK_MODE
186 #define KSYM_Multi_key          SDLK_RCTRL
187
188 #define KSYM_BackSpace          SDLK_BACKSPACE
189 #define KSYM_Delete             SDLK_DELETE
190 #define KSYM_Insert             SDLK_INSERT
191 #define KSYM_Tab                SDLK_TAB
192 #define KSYM_Home               SDLK_HOME
193 #define KSYM_End                SDLK_END
194 #define KSYM_Page_Up            SDLK_PAGEUP
195 #define KSYM_Page_Down          SDLK_PAGEDOWN
196
197 #if defined(TARGET_SDL2)
198 #define KSYM_Menu               SDLK_MENU
199 #define KSYM_Back               SDLK_AC_BACK
200 #endif
201
202 #define KSYM_space              SDLK_SPACE
203 #define KSYM_exclam             SDLK_EXCLAIM
204 #define KSYM_quotedbl           SDLK_QUOTEDBL
205 #define KSYM_numbersign         SDLK_HASH
206 #define KSYM_dollar             SDLK_DOLLAR
207
208 #if defined(TARGET_SDL2)
209 #define KSYM_percent            SDLK_PERCENT
210 #else
211 #define KSYM_percent            37                      /* undefined in SDL */
212 #endif
213
214 #define KSYM_ampersand          SDLK_AMPERSAND
215 #define KSYM_apostrophe         SDLK_QUOTE
216 #define KSYM_parenleft          SDLK_LEFTPAREN
217 #define KSYM_parenright         SDLK_RIGHTPAREN
218 #define KSYM_asterisk           SDLK_ASTERISK
219 #define KSYM_plus               SDLK_PLUS
220 #define KSYM_comma              SDLK_COMMA
221 #define KSYM_minus              SDLK_MINUS
222 #define KSYM_period             SDLK_PERIOD
223 #define KSYM_slash              SDLK_SLASH
224
225 #define KSYM_colon              SDLK_COLON
226 #define KSYM_semicolon          SDLK_SEMICOLON
227 #define KSYM_less               SDLK_LESS
228 #define KSYM_equal              SDLK_EQUALS
229 #define KSYM_greater            SDLK_GREATER
230 #define KSYM_question           SDLK_QUESTION
231 #define KSYM_at                 SDLK_AT
232
233 #define KSYM_bracketleft        SDLK_LEFTBRACKET
234 #define KSYM_backslash          SDLK_BACKSLASH
235 #define KSYM_bracketright       SDLK_RIGHTBRACKET
236 #define KSYM_asciicircum        SDLK_CARET
237 #define KSYM_underscore         SDLK_UNDERSCORE
238 #define KSYM_grave              SDLK_BACKQUOTE
239
240 #define KSYM_quoteleft          KSYM_UNDEFINED          /* undefined */
241 #define KSYM_braceleft          KSYM_UNDEFINED          /* undefined */
242 #define KSYM_bar                KSYM_UNDEFINED          /* undefined */
243 #define KSYM_braceright         KSYM_UNDEFINED          /* undefined */
244 #define KSYM_asciitilde         KSYM_UNDEFINED          /* undefined */
245
246 #if defined(TARGET_SDL2)
247 #define KSYM_degree             176
248 #define KSYM_Adiaeresis         196
249 #define KSYM_Odiaeresis         214
250 #define KSYM_Udiaeresis         220
251 #define KSYM_adiaeresis         228
252 #define KSYM_odiaeresis         246
253 #define KSYM_udiaeresis         252
254 #define KSYM_ssharp             223
255 #else
256 #define KSYM_degree             SDLK_WORLD_16
257 #define KSYM_Adiaeresis         SDLK_WORLD_36
258 #define KSYM_Odiaeresis         SDLK_WORLD_54
259 #define KSYM_Udiaeresis         SDLK_WORLD_60
260 #define KSYM_adiaeresis         SDLK_WORLD_68
261 #define KSYM_odiaeresis         SDLK_WORLD_86
262 #define KSYM_udiaeresis         SDLK_WORLD_92
263 #define KSYM_ssharp             SDLK_WORLD_63
264 #endif
265
266 #ifndef SDLK_A
267 #define SDLK_A                  65
268 #define SDLK_B                  66
269 #define SDLK_C                  67
270 #define SDLK_D                  68
271 #define SDLK_E                  69
272 #define SDLK_F                  70
273 #define SDLK_G                  71
274 #define SDLK_H                  72
275 #define SDLK_I                  73
276 #define SDLK_J                  74
277 #define SDLK_K                  75
278 #define SDLK_L                  76
279 #define SDLK_M                  77
280 #define SDLK_N                  78
281 #define SDLK_O                  79
282 #define SDLK_P                  80
283 #define SDLK_Q                  81
284 #define SDLK_R                  82
285 #define SDLK_S                  83
286 #define SDLK_T                  84
287 #define SDLK_U                  85
288 #define SDLK_V                  86
289 #define SDLK_W                  87
290 #define SDLK_X                  88
291 #define SDLK_Y                  89
292 #define SDLK_Z                  90
293 #endif
294
295 #define KSYM_A                  SDLK_A
296 #define KSYM_B                  SDLK_B
297 #define KSYM_C                  SDLK_C
298 #define KSYM_D                  SDLK_D
299 #define KSYM_E                  SDLK_E
300 #define KSYM_F                  SDLK_F
301 #define KSYM_G                  SDLK_G
302 #define KSYM_H                  SDLK_H
303 #define KSYM_I                  SDLK_I
304 #define KSYM_J                  SDLK_J
305 #define KSYM_K                  SDLK_K
306 #define KSYM_L                  SDLK_L
307 #define KSYM_M                  SDLK_M
308 #define KSYM_N                  SDLK_N
309 #define KSYM_O                  SDLK_O
310 #define KSYM_P                  SDLK_P
311 #define KSYM_Q                  SDLK_Q
312 #define KSYM_R                  SDLK_R
313 #define KSYM_S                  SDLK_S
314 #define KSYM_T                  SDLK_T
315 #define KSYM_U                  SDLK_U
316 #define KSYM_V                  SDLK_V
317 #define KSYM_W                  SDLK_W
318 #define KSYM_X                  SDLK_X
319 #define KSYM_Y                  SDLK_Y
320 #define KSYM_Z                  SDLK_Z
321
322 #define KSYM_a                  SDLK_a
323 #define KSYM_b                  SDLK_b
324 #define KSYM_c                  SDLK_c
325 #define KSYM_d                  SDLK_d
326 #define KSYM_e                  SDLK_e
327 #define KSYM_f                  SDLK_f
328 #define KSYM_g                  SDLK_g
329 #define KSYM_h                  SDLK_h
330 #define KSYM_i                  SDLK_i
331 #define KSYM_j                  SDLK_j
332 #define KSYM_k                  SDLK_k
333 #define KSYM_l                  SDLK_l
334 #define KSYM_m                  SDLK_m
335 #define KSYM_n                  SDLK_n
336 #define KSYM_o                  SDLK_o
337 #define KSYM_p                  SDLK_p
338 #define KSYM_q                  SDLK_q
339 #define KSYM_r                  SDLK_r
340 #define KSYM_s                  SDLK_s
341 #define KSYM_t                  SDLK_t
342 #define KSYM_u                  SDLK_u
343 #define KSYM_v                  SDLK_v
344 #define KSYM_w                  SDLK_w
345 #define KSYM_x                  SDLK_x
346 #define KSYM_y                  SDLK_y
347 #define KSYM_z                  SDLK_z
348
349 #define KSYM_0                  SDLK_0
350 #define KSYM_1                  SDLK_1
351 #define KSYM_2                  SDLK_2
352 #define KSYM_3                  SDLK_3
353 #define KSYM_4                  SDLK_4
354 #define KSYM_5                  SDLK_5
355 #define KSYM_6                  SDLK_6
356 #define KSYM_7                  SDLK_7
357 #define KSYM_8                  SDLK_8
358 #define KSYM_9                  SDLK_9
359
360 #if defined(TARGET_SDL2)
361 #define KSYM_KP_0               SDLK_KP_0
362 #define KSYM_KP_1               SDLK_KP_1
363 #define KSYM_KP_2               SDLK_KP_2
364 #define KSYM_KP_3               SDLK_KP_3
365 #define KSYM_KP_4               SDLK_KP_4
366 #define KSYM_KP_5               SDLK_KP_5
367 #define KSYM_KP_6               SDLK_KP_6
368 #define KSYM_KP_7               SDLK_KP_7
369 #define KSYM_KP_8               SDLK_KP_8
370 #define KSYM_KP_9               SDLK_KP_9
371 #else
372 #define KSYM_KP_0               SDLK_KP0
373 #define KSYM_KP_1               SDLK_KP1
374 #define KSYM_KP_2               SDLK_KP2
375 #define KSYM_KP_3               SDLK_KP3
376 #define KSYM_KP_4               SDLK_KP4
377 #define KSYM_KP_5               SDLK_KP5
378 #define KSYM_KP_6               SDLK_KP6
379 #define KSYM_KP_7               SDLK_KP7
380 #define KSYM_KP_8               SDLK_KP8
381 #define KSYM_KP_9               SDLK_KP9
382 #endif
383
384 #define KSYM_F1                 SDLK_F1
385 #define KSYM_F2                 SDLK_F2
386 #define KSYM_F3                 SDLK_F3
387 #define KSYM_F4                 SDLK_F4
388 #define KSYM_F5                 SDLK_F5
389 #define KSYM_F6                 SDLK_F6
390 #define KSYM_F7                 SDLK_F7
391 #define KSYM_F8                 SDLK_F8
392 #define KSYM_F9                 SDLK_F9
393 #define KSYM_F10                SDLK_F10
394 #define KSYM_F11                SDLK_F11
395 #define KSYM_F12                SDLK_F12
396
397 #define KSYM_FKEY_FIRST         KSYM_F1
398 #define KSYM_FKEY_LAST          KSYM_F12
399 #define KSYM_NUM_FKEYS          (KSYM_FKEY_LAST - KSYM_FKEY_FIRST + 1)
400
401 #define KMOD_None               KMOD_NONE
402 #define KMOD_Shift_L            KMOD_LSHIFT
403 #define KMOD_Shift_R            KMOD_RSHIFT
404 #define KMOD_Control_L          KMOD_LCTRL
405 #define KMOD_Control_R          KMOD_RCTRL
406
407 #if defined(TARGET_SDL2)
408 #define KMOD_Meta_L             KMOD_LGUI
409 #define KMOD_Meta_R             KMOD_RGUI
410 #else
411 #define KMOD_Meta_L             KMOD_LMETA
412 #define KMOD_Meta_R             KMOD_RMETA
413 #endif
414
415 #define KMOD_Alt_L              KMOD_LALT
416 #define KMOD_Alt_R              KMOD_RALT
417
418 #define KMOD_Shift              (KMOD_Shift_L   | KMOD_Shift_R)
419 #define KMOD_Control            (KMOD_Control_L | KMOD_Control_R)
420 #define KMOD_Meta               (KMOD_Meta_L    | KMOD_Meta_R)
421 #define KMOD_Alt                (KMOD_Alt_L     | KMOD_Alt_R)
422
423 #if defined(TARGET_SDL2)
424 #define KMOD_TextInput          (KMOD_Shift | KMOD_Alt_R)
425 #endif
426
427 /* SDL function definitions */
428
429 boolean SDLSetNativeSurface(SDL_Surface **);
430 SDL_Surface *SDLGetNativeSurface(SDL_Surface *);
431
432 #if defined(TARGET_SDL2)
433 SDL_Surface *SDL_DisplayFormat(SDL_Surface *);
434 void SDLSetWindowScaling(int);
435 void SDLSetWindowScalingQuality(char *);
436 void SDLSetWindowFullscreen(boolean);
437 void SDLRedrawWindow();
438 #endif
439
440 void SDLSetWindowTitle(void);
441
442 void SDLLimitScreenUpdates(boolean);
443 void SDLInitVideoDisplay(void);
444 void SDLInitVideoBuffer(DrawBuffer **, DrawWindow **, boolean);
445 boolean SDLSetVideoMode(DrawBuffer **, boolean);
446 void SDLCreateBitmapContent(Bitmap *, int, int, int);
447 void SDLFreeBitmapPointers(Bitmap *);
448 void SDLCopyArea(Bitmap *, Bitmap *, int, int, int, int, int, int, int);
449 void SDLFillRectangle(Bitmap *, int, int, int, int, Uint32);
450 void SDLFadeRectangle(Bitmap *, int, int, int, int, int, int, int,
451                       void (*draw_border_function)(void));
452 void SDLDrawSimpleLine(Bitmap *, int, int, int, int, Uint32);
453 void SDLDrawLine(Bitmap *, int, int, int, int, Uint32);
454 Pixel SDLGetPixel(Bitmap *, int, int);
455 void SDLPutPixel(Bitmap *, int, int, Pixel);
456
457 void SDLInvertArea(Bitmap *, int, int, int, int, Uint32);
458 void SDLCopyInverseMasked(Bitmap *, Bitmap *, int, int, int, int, int, int);
459
460 Bitmap *SDLZoomBitmap(Bitmap *, int, int);
461
462 Bitmap *SDLLoadImage(char *);
463
464 void SDLSetMouseCursor(struct MouseCursorInfo *);
465
466 void SDLOpenAudio(void);
467 void SDLCloseAudio(void);
468
469 void SDLNextEvent(Event *);
470 void SDLHandleWindowManagerEvent(Event *);
471
472 void HandleJoystickEvent(Event *);
473 void SDLInitJoysticks(void);
474 boolean SDLReadJoystick(int, int *, int *, boolean *, boolean *);
475
476 #endif /* SDL_H */