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