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