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 int alpha[2][2]; // [surface|texture][opaque|masked]
83 SDL_Surface *surface_masked;
85 SDL_Texture *texture_masked;
88 struct MouseCursorInfo
93 byte data[CURSOR_MAX_WIDTH * CURSOR_MAX_HEIGHT / 8];
94 byte mask[CURSOR_MAX_WIDTH * CURSOR_MAX_HEIGHT / 8];
99 // same as in "struct SDL_UserEvent"
105 // changed to use integer values instead of void pointers
110 typedef struct UserEventInfo UserEvent;
113 // SDL symbol definitions
117 #define BLACK_PIXEL 0x000000
118 #define WHITE_PIXEL 0xffffff
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
133 #define KSYM_UNDEFINED SDLK_UNKNOWN
135 #define KSYM_Return SDLK_RETURN
136 #define KSYM_Escape SDLK_ESCAPE
138 #define KSYM_Left SDLK_LEFT
139 #define KSYM_Right SDLK_RIGHT
140 #define KSYM_Up SDLK_UP
141 #define KSYM_Down SDLK_DOWN
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
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
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
162 #define KSYM_Meta_L SDLK_LGUI
163 #define KSYM_Meta_R SDLK_RGUI
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
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
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
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
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
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
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
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
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
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
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
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
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
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)
357 #define KSYM_RAW(k) (((k) >= KSYM_a && \
363 #define KSYM_PRINTABLE(k) (((k) >= KSYM_space && \
365 (k) == KSYM_Adiaeresis || \
366 (k) == KSYM_Odiaeresis || \
367 (k) == KSYM_Udiaeresis || \
368 (k) == KSYM_adiaeresis || \
369 (k) == KSYM_odiaeresis || \
370 (k) == KSYM_udiaeresis)
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
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)
387 // this only contains "valid" key modifiers (and ignores keys like "NumLock")
388 #define KMOD_Valid (KMOD_Shift | \
393 #define KMOD_TextInput (KMOD_Shift | KMOD_Alt_R)
396 // SDL function definitions
398 void SDLSetAlpha(SDL_Surface *, boolean, int);
399 const char *SDLGetRendererName(void);
400 boolean SDLSetNativeSurface(SDL_Surface **);
401 SDL_Surface *SDLGetNativeSurface(SDL_Surface *);
402 void SDLCreateBitmapTextures(Bitmap *);
403 void SDLFreeBitmapTextures(Bitmap *);
405 SDL_Surface *SDL_DisplayFormat(SDL_Surface *);
406 void SDLSetWindowScaling(int);
407 void SDLSetWindowScalingQuality(char *);
408 void SDLSetWindowFullscreen(boolean);
409 void SDLSetDisplaySize(void);
410 void SDLSetScreenSizeAndOffsets(int, int);
411 void SDLSetScreenSizeForRenderer(int, int);
412 void SDLSetScreenProperties(void);
414 void SDLSetScreenRenderingMode(char *);
415 void SDLSetScreenVsyncMode(char *);
416 void SDLRedrawWindow(void);
417 void SDLSetWindowTitle(void);
419 void SDLLimitScreenUpdates(boolean);
420 void SDLInitVideoDisplay(void);
421 void SDLInitVideoBuffer(boolean);
422 boolean SDLSetVideoMode(boolean);
423 void SDLCreateBitmapContent(Bitmap *, int, int, int);
424 void SDLFreeBitmapPointers(Bitmap *);
425 void SDLCopyArea(Bitmap *, Bitmap *, int, int, int, int, int, int, int);
426 void SDLBlitTexture(Bitmap *, int, int, int, int, int, int, int);
427 void SDLFillRectangle(Bitmap *, int, int, int, int, Uint32);
428 void SDLFadeRectangle(int, int, int, int, int, int, int,
429 void (*draw_border_function)(void));
430 void SDLDrawSimpleLine(Bitmap *, int, int, int, int, Uint32);
431 void SDLDrawLine(Bitmap *, int, int, int, int, Uint32);
432 Pixel SDLGetPixel(Bitmap *, int, int);
433 void SDLPutPixel(Bitmap *, int, int, Pixel);
435 void SDLCopyInverseMasked(Bitmap *, Bitmap *, int, int, int, int, int, int);
437 Bitmap *SDLZoomBitmap(Bitmap *, int, int);
439 Bitmap *SDLLoadImage(char *);
441 void SDLSetMouseCursor(struct MouseCursorInfo *);
443 void SDLOpenAudio(void);
444 void SDLCloseAudio(void);
446 void SDLWaitEvent(Event *);
447 void SDLCorrectRawMousePosition(int *, int *);
449 void HandleJoystickEvent(Event *);
450 void SDLInitJoysticks(void);
451 boolean SDLReadJoystick(int, int *, int *, boolean *, boolean *);
452 boolean SDLCheckJoystickOpened(int);
453 void SDLClearJoystickState(void);
454 boolean SDLOpenJoystick(int);
455 void SDLCloseJoystick(int);
457 void PrepareFadeBitmap(int);
459 void Delay_WithScreenUpdates(unsigned int);