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