1 // ============================================================================
2 // Artsoft Retro-Game Library
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
7 // https://www.artsoft.org/
8 // ----------------------------------------------------------------------------
10 // ============================================================================
16 #include <SDL_image.h>
17 #include <SDL_mixer.h>
19 #include <SDL_thread.h>
20 #if defined(PLATFORM_WINDOWS)
21 #include <SDL_syswm.h>
24 // definitions needed for "system.c"
26 #define SURFACE_FLAGS (SDL_WINDOW_RESIZABLE)
28 #define SET_TRANSPARENT_PIXEL (SDL_TRUE)
29 #define UNSET_TRANSPARENT_PIXEL (SDL_FALSE)
31 // system dependent definitions
33 #define TARGET_STRING "SDL2"
35 #if defined(PLATFORM_ANDROID)
36 #define WINDOW_SCALING_STATUS WINDOW_SCALING_NOT_AVAILABLE
37 #define FULLSCREEN_STATUS FULLSCREEN_AVAILABLE
39 #define WINDOW_SCALING_STATUS WINDOW_SCALING_AVAILABLE
40 #define FULLSCREEN_STATUS FULLSCREEN_AVAILABLE
43 #define CURSOR_MAX_WIDTH 32
44 #define CURSOR_MAX_HEIGHT 32
47 // SDL type definitions
49 typedef struct SDLSurfaceInfo Bitmap;
50 typedef struct SDLSurfaceInfo DrawBuffer;
51 typedef struct SDLSurfaceInfo DrawWindow;
53 typedef SDL_Cursor *Cursor;
55 typedef SDL_Keycode Key;
56 typedef SDL_Keymod KeyMod;
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;
68 typedef SDL_EventFilter EventFilter;
71 // structure definitions
75 char *source_filename;
79 SDL_Surface *surface_masked;
81 SDL_Texture *texture_masked;
84 struct MouseCursorInfo
89 byte data[CURSOR_MAX_WIDTH * CURSOR_MAX_HEIGHT / 8];
90 byte mask[CURSOR_MAX_WIDTH * CURSOR_MAX_HEIGHT / 8];
95 // same as in "struct SDL_UserEvent"
101 // changed to use integer values instead of void pointers
106 typedef struct UserEventInfo UserEvent;
109 // SDL symbol definitions
113 #define BLACK_PIXEL 0x000000
114 #define WHITE_PIXEL 0xffffff
116 #define EVENT_BUTTONPRESS SDL_MOUSEBUTTONDOWN
117 #define EVENT_BUTTONRELEASE SDL_MOUSEBUTTONUP
118 #define EVENT_MOTIONNOTIFY SDL_MOUSEMOTION
119 #define EVENT_WHEELMOTION SDL_MOUSEWHEEL
120 #define EVENT_FINGERPRESS SDL_FINGERDOWN
121 #define EVENT_FINGERRELEASE SDL_FINGERUP
122 #define EVENT_FINGERMOTION SDL_FINGERMOTION
123 #define EVENT_TEXTINPUT SDL_TEXTINPUT
124 #define EVENT_KEYPRESS SDL_KEYDOWN
125 #define EVENT_KEYRELEASE SDL_KEYUP
126 #define EVENT_USER SDL_USEREVENT
127 #define EVENT_QUIT SDL_QUIT
129 #define KSYM_UNDEFINED SDLK_UNKNOWN
131 #define KSYM_Return SDLK_RETURN
132 #define KSYM_Escape SDLK_ESCAPE
134 #define KSYM_Left SDLK_LEFT
135 #define KSYM_Right SDLK_RIGHT
136 #define KSYM_Up SDLK_UP
137 #define KSYM_Down SDLK_DOWN
140 #define KSYM_KP_Left SDLK_KP_LEFT
141 #define KSYM_KP_Right SDLK_KP_RIGHT
142 #define KSYM_KP_Up SDLK_KP_UP
143 #define KSYM_KP_Down SDLK_KP_DOWN
146 #define KSYM_KP_Enter SDLK_KP_ENTER
147 #define KSYM_KP_Add SDLK_KP_PLUS
148 #define KSYM_KP_Subtract SDLK_KP_MINUS
149 #define KSYM_KP_Multiply SDLK_KP_MULTIPLY
150 #define KSYM_KP_Divide SDLK_KP_DIVIDE
151 #define KSYM_KP_Separator SDLK_KP_PERIOD
153 #define KSYM_Shift_L SDLK_LSHIFT
154 #define KSYM_Shift_R SDLK_RSHIFT
155 #define KSYM_Control_L SDLK_LCTRL
156 #define KSYM_Control_R SDLK_RCTRL
158 #define KSYM_Meta_L SDLK_LGUI
159 #define KSYM_Meta_R SDLK_RGUI
161 #define KSYM_Alt_L SDLK_LALT
162 #define KSYM_Alt_R SDLK_RALT
163 #define KSYM_Mode_switch SDLK_MODE
164 #define KSYM_Multi_key SDLK_RCTRL
166 #define KSYM_BackSpace SDLK_BACKSPACE
167 #define KSYM_Delete SDLK_DELETE
168 #define KSYM_Insert SDLK_INSERT
169 #define KSYM_Tab SDLK_TAB
170 #define KSYM_Home SDLK_HOME
171 #define KSYM_End SDLK_END
172 #define KSYM_Page_Up SDLK_PAGEUP
173 #define KSYM_Page_Down SDLK_PAGEDOWN
175 #define KSYM_Select SDLK_SELECT
176 #define KSYM_Menu SDLK_MENU
177 #define KSYM_Back SDLK_AC_BACK
178 #define KSYM_PlayPause SDLK_AUDIOPLAY
179 #if defined(PLATFORM_ANDROID)
180 #define KSYM_Rewind SDLK_AUDIOREWIND
181 #define KSYM_FastForward SDLK_AUDIOFASTFORWARD
184 #define KSYM_space SDLK_SPACE
185 #define KSYM_exclam SDLK_EXCLAIM
186 #define KSYM_quotedbl SDLK_QUOTEDBL
187 #define KSYM_numbersign SDLK_HASH
188 #define KSYM_dollar SDLK_DOLLAR
189 #define KSYM_percent SDLK_PERCENT
190 #define KSYM_ampersand SDLK_AMPERSAND
191 #define KSYM_apostrophe SDLK_QUOTE
192 #define KSYM_parenleft SDLK_LEFTPAREN
193 #define KSYM_parenright SDLK_RIGHTPAREN
194 #define KSYM_asterisk SDLK_ASTERISK
195 #define KSYM_plus SDLK_PLUS
196 #define KSYM_comma SDLK_COMMA
197 #define KSYM_minus SDLK_MINUS
198 #define KSYM_period SDLK_PERIOD
199 #define KSYM_slash SDLK_SLASH
201 #define KSYM_colon SDLK_COLON
202 #define KSYM_semicolon SDLK_SEMICOLON
203 #define KSYM_less SDLK_LESS
204 #define KSYM_equal SDLK_EQUALS
205 #define KSYM_greater SDLK_GREATER
206 #define KSYM_question SDLK_QUESTION
207 #define KSYM_at SDLK_AT
209 #define KSYM_bracketleft SDLK_LEFTBRACKET
210 #define KSYM_backslash SDLK_BACKSLASH
211 #define KSYM_bracketright SDLK_RIGHTBRACKET
212 #define KSYM_asciicircum SDLK_CARET
213 #define KSYM_underscore SDLK_UNDERSCORE
214 #define KSYM_grave SDLK_BACKQUOTE
216 #define KSYM_quoteleft KSYM_UNDEFINED // undefined
217 #define KSYM_braceleft KSYM_UNDEFINED // undefined
218 #define KSYM_bar KSYM_UNDEFINED // undefined
219 #define KSYM_braceright KSYM_UNDEFINED // undefined
220 #define KSYM_asciitilde KSYM_UNDEFINED // undefined
222 #define KSYM_degree 176
223 #define KSYM_Adiaeresis 196
224 #define KSYM_Odiaeresis 214
225 #define KSYM_Udiaeresis 220
226 #define KSYM_adiaeresis 228
227 #define KSYM_odiaeresis 246
228 #define KSYM_udiaeresis 252
229 #define KSYM_ssharp 223
260 #define KSYM_A SDLK_A
261 #define KSYM_B SDLK_B
262 #define KSYM_C SDLK_C
263 #define KSYM_D SDLK_D
264 #define KSYM_E SDLK_E
265 #define KSYM_F SDLK_F
266 #define KSYM_G SDLK_G
267 #define KSYM_H SDLK_H
268 #define KSYM_I SDLK_I
269 #define KSYM_J SDLK_J
270 #define KSYM_K SDLK_K
271 #define KSYM_L SDLK_L
272 #define KSYM_M SDLK_M
273 #define KSYM_N SDLK_N
274 #define KSYM_O SDLK_O
275 #define KSYM_P SDLK_P
276 #define KSYM_Q SDLK_Q
277 #define KSYM_R SDLK_R
278 #define KSYM_S SDLK_S
279 #define KSYM_T SDLK_T
280 #define KSYM_U SDLK_U
281 #define KSYM_V SDLK_V
282 #define KSYM_W SDLK_W
283 #define KSYM_X SDLK_X
284 #define KSYM_Y SDLK_Y
285 #define KSYM_Z SDLK_Z
287 #define KSYM_a SDLK_a
288 #define KSYM_b SDLK_b
289 #define KSYM_c SDLK_c
290 #define KSYM_d SDLK_d
291 #define KSYM_e SDLK_e
292 #define KSYM_f SDLK_f
293 #define KSYM_g SDLK_g
294 #define KSYM_h SDLK_h
295 #define KSYM_i SDLK_i
296 #define KSYM_j SDLK_j
297 #define KSYM_k SDLK_k
298 #define KSYM_l SDLK_l
299 #define KSYM_m SDLK_m
300 #define KSYM_n SDLK_n
301 #define KSYM_o SDLK_o
302 #define KSYM_p SDLK_p
303 #define KSYM_q SDLK_q
304 #define KSYM_r SDLK_r
305 #define KSYM_s SDLK_s
306 #define KSYM_t SDLK_t
307 #define KSYM_u SDLK_u
308 #define KSYM_v SDLK_v
309 #define KSYM_w SDLK_w
310 #define KSYM_x SDLK_x
311 #define KSYM_y SDLK_y
312 #define KSYM_z SDLK_z
314 #define KSYM_0 SDLK_0
315 #define KSYM_1 SDLK_1
316 #define KSYM_2 SDLK_2
317 #define KSYM_3 SDLK_3
318 #define KSYM_4 SDLK_4
319 #define KSYM_5 SDLK_5
320 #define KSYM_6 SDLK_6
321 #define KSYM_7 SDLK_7
322 #define KSYM_8 SDLK_8
323 #define KSYM_9 SDLK_9
325 #define KSYM_KP_0 SDLK_KP_0
326 #define KSYM_KP_1 SDLK_KP_1
327 #define KSYM_KP_2 SDLK_KP_2
328 #define KSYM_KP_3 SDLK_KP_3
329 #define KSYM_KP_4 SDLK_KP_4
330 #define KSYM_KP_5 SDLK_KP_5
331 #define KSYM_KP_6 SDLK_KP_6
332 #define KSYM_KP_7 SDLK_KP_7
333 #define KSYM_KP_8 SDLK_KP_8
334 #define KSYM_KP_9 SDLK_KP_9
336 #define KSYM_F1 SDLK_F1
337 #define KSYM_F2 SDLK_F2
338 #define KSYM_F3 SDLK_F3
339 #define KSYM_F4 SDLK_F4
340 #define KSYM_F5 SDLK_F5
341 #define KSYM_F6 SDLK_F6
342 #define KSYM_F7 SDLK_F7
343 #define KSYM_F8 SDLK_F8
344 #define KSYM_F9 SDLK_F9
345 #define KSYM_F10 SDLK_F10
346 #define KSYM_F11 SDLK_F11
347 #define KSYM_F12 SDLK_F12
349 #define KSYM_FKEY_FIRST KSYM_F1
350 #define KSYM_FKEY_LAST KSYM_F12
351 #define KSYM_NUM_FKEYS (KSYM_FKEY_LAST - KSYM_FKEY_FIRST + 1)
353 #define KSYM_RAW(k) (((k) >= KSYM_a && \
359 #define KSYM_PRINTABLE(k) (((k) >= KSYM_space && \
361 (k) == KSYM_Adiaeresis || \
362 (k) == KSYM_Odiaeresis || \
363 (k) == KSYM_Udiaeresis || \
364 (k) == KSYM_adiaeresis || \
365 (k) == KSYM_odiaeresis || \
366 (k) == KSYM_udiaeresis)
368 #define KMOD_None KMOD_NONE
369 #define KMOD_Shift_L KMOD_LSHIFT
370 #define KMOD_Shift_R KMOD_RSHIFT
371 #define KMOD_Control_L KMOD_LCTRL
372 #define KMOD_Control_R KMOD_RCTRL
373 #define KMOD_Meta_L KMOD_LGUI
374 #define KMOD_Meta_R KMOD_RGUI
375 #define KMOD_Alt_L KMOD_LALT
376 #define KMOD_Alt_R KMOD_RALT
378 #define KMOD_Shift (KMOD_Shift_L | KMOD_Shift_R)
379 #define KMOD_Control (KMOD_Control_L | KMOD_Control_R)
380 #define KMOD_Meta (KMOD_Meta_L | KMOD_Meta_R)
381 #define KMOD_Alt (KMOD_Alt_L | KMOD_Alt_R)
383 // this only contains "valid" key modifiers (and ignores keys like "NumLock")
384 #define KMOD_Valid (KMOD_Shift | \
389 #define KMOD_TextInput (KMOD_Shift | KMOD_Alt_R)
392 // SDL function definitions
394 void SDLSetAlpha(SDL_Surface *, boolean, int);
395 const char *SDLGetRendererName(void);
396 boolean SDLSetNativeSurface(SDL_Surface **);
397 SDL_Surface *SDLGetNativeSurface(SDL_Surface *);
398 void SDLCreateBitmapTextures(Bitmap *);
399 void SDLFreeBitmapTextures(Bitmap *);
401 SDL_Surface *SDL_DisplayFormat(SDL_Surface *);
402 void SDLSetWindowScaling(int);
403 void SDLSetWindowScalingQuality(char *);
404 void SDLSetWindowFullscreen(boolean);
405 void SDLSetDisplaySize(void);
406 void SDLSetScreenSizeAndOffsets(int, int);
407 void SDLSetScreenSizeForRenderer(int, int);
408 void SDLSetScreenProperties(void);
410 void SDLSetScreenRenderingMode(char *);
411 void SDLSetScreenVsyncMode(char *);
412 void SDLRedrawWindow(void);
413 void SDLSetWindowTitle(void);
415 void SDLLimitScreenUpdates(boolean);
416 void SDLInitVideoDisplay(void);
417 void SDLInitVideoBuffer(boolean);
418 boolean SDLSetVideoMode(boolean);
419 void SDLCreateBitmapContent(Bitmap *, int, int, int);
420 void SDLFreeBitmapPointers(Bitmap *);
421 void SDLCopyArea(Bitmap *, Bitmap *, int, int, int, int, int, int, int);
422 void SDLBlitTexture(Bitmap *, int, int, int, int, int, int, int);
423 void SDLFillRectangle(Bitmap *, int, int, int, int, Uint32);
424 void SDLFadeRectangle(int, int, int, int, int, int, int,
425 void (*draw_border_function)(void));
426 void SDLDrawSimpleLine(Bitmap *, int, int, int, int, Uint32);
427 void SDLDrawLine(Bitmap *, int, int, int, int, Uint32);
428 Pixel SDLGetPixel(Bitmap *, int, int);
429 void SDLPutPixel(Bitmap *, int, int, Pixel);
431 void SDLInvertArea(Bitmap *, int, int, int, int, Uint32);
432 void SDLCopyInverseMasked(Bitmap *, Bitmap *, int, int, int, int, int, int);
434 Bitmap *SDLZoomBitmap(Bitmap *, int, int);
436 Bitmap *SDLLoadImage(char *);
438 void SDLSetMouseCursor(struct MouseCursorInfo *);
440 void SDLOpenAudio(void);
441 void SDLCloseAudio(void);
443 void SDLWaitEvent(Event *);
444 void SDLCorrectRawMousePosition(int *, int *);
446 void HandleJoystickEvent(Event *);
447 void SDLInitJoysticks(void);
448 boolean SDLReadJoystick(int, int *, int *, boolean *, boolean *);
449 boolean SDLCheckJoystickOpened(int);
450 void SDLClearJoystickState(void);
451 boolean SDLOpenJoystick(int);
452 void SDLCloseJoystick(int);
454 void PrepareFadeBitmap(int);
456 void Delay_WithScreenUpdates(unsigned int);