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