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