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