ef2cfd25e243a7085e96e50de988fc358d5c4861
[rocksndiamonds.git] / src / libgame / sdl.h
1 /***********************************************************
2 * Artsoft Retro-Game Library                               *
3 *----------------------------------------------------------*
4 * (c) 1994-2006 Artsoft Entertainment                      *
5 *               Holger Schemel                             *
6 *               Detmolder Strasse 189                      *
7 *               33604 Bielefeld                            *
8 *               Germany                                    *
9 *               e-mail: info@artsoft.org                   *
10 *----------------------------------------------------------*
11 * sdl.h                                                    *
12 ***********************************************************/
13
14 #ifndef SDL_H
15 #define SDL_H
16
17 #include <SDL.h>
18 #include <SDL_image.h>
19 #include <SDL_mixer.h>
20 #include <SDL_net.h>
21 #include <SDL_thread.h>
22 #if defined(PLATFORM_WIN32)
23 #include <SDL_syswm.h>
24 #endif
25
26 /* definitions needed for "system.c" */
27
28 #if defined(TARGET_SDL2)
29 #define SURFACE_FLAGS           (0)
30 #else
31 #define SURFACE_FLAGS           (SDL_SWSURFACE)
32 #endif
33
34 #if defined(TARGET_SDL2)
35 #define SET_TRANSPARENT_PIXEL   (SDL_TRUE)
36 #define UNSET_TRANSPARENT_PIXEL (SDL_FALSE)
37 #else
38 #define SET_TRANSPARENT_PIXEL   (SDL_SRCCOLORKEY)
39 #define UNSET_TRANSPARENT_PIXEL (0)
40 #endif
41
42 /* system dependent definitions */
43
44 #if defined(TARGET_SDL2)
45 #define TARGET_STRING           "SDL2"
46 #else
47 #define TARGET_STRING           "SDL"
48 #endif
49
50 #if defined(PLATFORM_ANDROID)
51 #define WINDOW_SCALING_STATUS   WINDOW_SCALING_NOT_AVAILABLE
52 #define FULLSCREEN_STATUS       FULLSCREEN_AVAILABLE
53 #define USE_DESKTOP_FULLSCREEN  TRUE
54 #elif defined(TARGET_SDL2)
55 #define WINDOW_SCALING_STATUS   WINDOW_SCALING_AVAILABLE
56 #define FULLSCREEN_STATUS       FULLSCREEN_AVAILABLE
57 #define USE_DESKTOP_FULLSCREEN  TRUE
58 #else   // SDL 1.2
59 #define WINDOW_SCALING_STATUS   WINDOW_SCALING_NOT_AVAILABLE
60 #define FULLSCREEN_STATUS       FULLSCREEN_AVAILABLE
61 #endif
62
63 #define CURSOR_MAX_WIDTH        32
64 #define CURSOR_MAX_HEIGHT       32
65
66
67 /* SDL type definitions */
68
69 typedef struct SDLSurfaceInfo   Bitmap;
70 typedef struct SDLSurfaceInfo   DrawBuffer;
71 typedef struct SDLSurfaceInfo   DrawWindow;
72 typedef Uint32                  Pixel;
73 typedef SDL_Cursor             *Cursor;
74
75 #if defined(TARGET_SDL2)
76 typedef SDL_Keycode             Key;
77 typedef SDL_Keymod              KeyMod;
78 #else
79 typedef SDLKey                  Key;
80 typedef unsigned int            KeyMod;
81 #endif
82
83 typedef SDL_Event               Event;
84 typedef SDL_MouseButtonEvent    ButtonEvent;
85 typedef SDL_MouseMotionEvent    MotionEvent;
86 #if defined(TARGET_SDL2)
87 typedef SDL_TouchFingerEvent    FingerEvent;
88 typedef SDL_TextInputEvent      TextEvent;
89 typedef SDL_Event               PauseResumeEvent;
90 typedef SDL_WindowEvent         WindowEvent;
91 #endif
92 typedef SDL_KeyboardEvent       KeyEvent;
93 typedef SDL_Event               ExposeEvent;
94 typedef SDL_Event               FocusChangeEvent;
95 typedef SDL_Event               ClientMessageEvent;
96
97 typedef int                     GC;
98 typedef int                     Pixmap;
99 typedef int                     Display;
100 typedef int                     Visual;
101 typedef int                     Colormap;
102
103
104 /* structure definitions */
105
106 struct SDLSurfaceInfo
107 {
108   char *source_filename;
109
110   int width, height;
111   SDL_Surface *surface;
112   SDL_Surface *surface_masked;
113   GC gc;
114   GC stored_clip_gc;
115 };
116
117 struct MouseCursorInfo
118 {
119   int width, height;
120   int hot_x, hot_y;
121
122   byte data[CURSOR_MAX_WIDTH * CURSOR_MAX_HEIGHT / 8];
123   byte mask[CURSOR_MAX_WIDTH * CURSOR_MAX_HEIGHT / 8];
124 };
125
126
127 /* SDL symbol definitions */
128
129 #define None                    0L
130
131 #define BLACK_PIXEL             0x000000
132 #define WHITE_PIXEL             0xffffff
133
134 #define EVENT_BUTTONPRESS       SDL_MOUSEBUTTONDOWN
135 #define EVENT_BUTTONRELEASE     SDL_MOUSEBUTTONUP
136 #define EVENT_MOTIONNOTIFY      SDL_MOUSEMOTION
137 #if defined(TARGET_SDL2)
138 #define EVENT_FINGERPRESS       SDL_FINGERDOWN
139 #define EVENT_FINGERRELEASE     SDL_FINGERUP
140 #define EVENT_FINGERMOTION      SDL_FINGERMOTION
141 #define EVENT_TEXTINPUT         SDL_TEXTINPUT
142 #endif
143 #define EVENT_KEYPRESS          SDL_KEYDOWN
144 #define EVENT_KEYRELEASE        SDL_KEYUP
145 #define EVENT_EXPOSE            SDL_USEREVENT + 0
146 #define EVENT_FOCUSIN           SDL_USEREVENT + 1
147 #define EVENT_FOCUSOUT          SDL_USEREVENT + 2
148 #define EVENT_CLIENTMESSAGE     SDL_QUIT
149 #define EVENT_MAPNOTIFY         SDL_USEREVENT + 4
150 #define EVENT_UNMAPNOTIFY       SDL_USEREVENT + 5
151
152 #define KSYM_UNDEFINED          SDLK_UNKNOWN
153
154 #define KSYM_Return             SDLK_RETURN
155 #define KSYM_Escape             SDLK_ESCAPE
156
157 #define KSYM_Left               SDLK_LEFT
158 #define KSYM_Right              SDLK_RIGHT
159 #define KSYM_Up                 SDLK_UP
160 #define KSYM_Down               SDLK_DOWN
161
162 #ifdef SDLK_KP_LEFT
163 #define KSYM_KP_Left            SDLK_KP_LEFT
164 #define KSYM_KP_Right           SDLK_KP_RIGHT
165 #define KSYM_KP_Up              SDLK_KP_UP
166 #define KSYM_KP_Down            SDLK_KP_DOWN
167 #endif
168
169 #define KSYM_KP_Enter           SDLK_KP_ENTER
170 #define KSYM_KP_Add             SDLK_KP_PLUS
171 #define KSYM_KP_Subtract        SDLK_KP_MINUS
172 #define KSYM_KP_Multiply        SDLK_KP_MULTIPLY
173 #define KSYM_KP_Divide          SDLK_KP_DIVIDE
174 #define KSYM_KP_Separator       SDLK_KP_PERIOD
175
176 #define KSYM_Shift_L            SDLK_LSHIFT
177 #define KSYM_Shift_R            SDLK_RSHIFT
178 #define KSYM_Control_L          SDLK_LCTRL
179 #define KSYM_Control_R          SDLK_RCTRL
180
181 #if defined(TARGET_SDL2)
182 #define KSYM_Meta_L             SDLK_LGUI
183 #define KSYM_Meta_R             SDLK_RGUI
184 #else
185 #define KSYM_Meta_L             SDLK_LMETA
186 #define KSYM_Meta_R             SDLK_RMETA
187 #endif
188
189 #define KSYM_Alt_L              SDLK_LALT
190 #define KSYM_Alt_R              SDLK_RALT
191 #if !defined(TARGET_SDL2)
192 #define KSYM_Super_L            SDLK_LSUPER
193 #define KSYM_Super_R            SDLK_RSUPER
194 #endif
195 #define KSYM_Mode_switch        SDLK_MODE
196 #define KSYM_Multi_key          SDLK_RCTRL
197
198 #define KSYM_BackSpace          SDLK_BACKSPACE
199 #define KSYM_Delete             SDLK_DELETE
200 #define KSYM_Insert             SDLK_INSERT
201 #define KSYM_Tab                SDLK_TAB
202 #define KSYM_Home               SDLK_HOME
203 #define KSYM_End                SDLK_END
204 #define KSYM_Page_Up            SDLK_PAGEUP
205 #define KSYM_Page_Down          SDLK_PAGEDOWN
206
207 #if defined(TARGET_SDL2)
208 #define KSYM_Menu               SDLK_MENU
209 #define KSYM_Back               SDLK_AC_BACK
210 #endif
211
212 #define KSYM_space              SDLK_SPACE
213 #define KSYM_exclam             SDLK_EXCLAIM
214 #define KSYM_quotedbl           SDLK_QUOTEDBL
215 #define KSYM_numbersign         SDLK_HASH
216 #define KSYM_dollar             SDLK_DOLLAR
217
218 #if defined(TARGET_SDL2)
219 #define KSYM_percent            SDLK_PERCENT
220 #else
221 #define KSYM_percent            37                      /* undefined in SDL */
222 #endif
223
224 #define KSYM_ampersand          SDLK_AMPERSAND
225 #define KSYM_apostrophe         SDLK_QUOTE
226 #define KSYM_parenleft          SDLK_LEFTPAREN
227 #define KSYM_parenright         SDLK_RIGHTPAREN
228 #define KSYM_asterisk           SDLK_ASTERISK
229 #define KSYM_plus               SDLK_PLUS
230 #define KSYM_comma              SDLK_COMMA
231 #define KSYM_minus              SDLK_MINUS
232 #define KSYM_period             SDLK_PERIOD
233 #define KSYM_slash              SDLK_SLASH
234
235 #define KSYM_colon              SDLK_COLON
236 #define KSYM_semicolon          SDLK_SEMICOLON
237 #define KSYM_less               SDLK_LESS
238 #define KSYM_equal              SDLK_EQUALS
239 #define KSYM_greater            SDLK_GREATER
240 #define KSYM_question           SDLK_QUESTION
241 #define KSYM_at                 SDLK_AT
242
243 #define KSYM_bracketleft        SDLK_LEFTBRACKET
244 #define KSYM_backslash          SDLK_BACKSLASH
245 #define KSYM_bracketright       SDLK_RIGHTBRACKET
246 #define KSYM_asciicircum        SDLK_CARET
247 #define KSYM_underscore         SDLK_UNDERSCORE
248 #define KSYM_grave              SDLK_BACKQUOTE
249
250 #define KSYM_quoteleft          KSYM_UNDEFINED          /* undefined */
251 #define KSYM_braceleft          KSYM_UNDEFINED          /* undefined */
252 #define KSYM_bar                KSYM_UNDEFINED          /* undefined */
253 #define KSYM_braceright         KSYM_UNDEFINED          /* undefined */
254 #define KSYM_asciitilde         KSYM_UNDEFINED          /* undefined */
255
256 #if defined(TARGET_SDL2)
257 #define KSYM_degree             176
258 #define KSYM_Adiaeresis         196
259 #define KSYM_Odiaeresis         214
260 #define KSYM_Udiaeresis         220
261 #define KSYM_adiaeresis         228
262 #define KSYM_odiaeresis         246
263 #define KSYM_udiaeresis         252
264 #define KSYM_ssharp             223
265 #else
266 #define KSYM_degree             SDLK_WORLD_16
267 #define KSYM_Adiaeresis         SDLK_WORLD_36
268 #define KSYM_Odiaeresis         SDLK_WORLD_54
269 #define KSYM_Udiaeresis         SDLK_WORLD_60
270 #define KSYM_adiaeresis         SDLK_WORLD_68
271 #define KSYM_odiaeresis         SDLK_WORLD_86
272 #define KSYM_udiaeresis         SDLK_WORLD_92
273 #define KSYM_ssharp             SDLK_WORLD_63
274 #endif
275
276 #ifndef SDLK_A
277 #define SDLK_A                  65
278 #define SDLK_B                  66
279 #define SDLK_C                  67
280 #define SDLK_D                  68
281 #define SDLK_E                  69
282 #define SDLK_F                  70
283 #define SDLK_G                  71
284 #define SDLK_H                  72
285 #define SDLK_I                  73
286 #define SDLK_J                  74
287 #define SDLK_K                  75
288 #define SDLK_L                  76
289 #define SDLK_M                  77
290 #define SDLK_N                  78
291 #define SDLK_O                  79
292 #define SDLK_P                  80
293 #define SDLK_Q                  81
294 #define SDLK_R                  82
295 #define SDLK_S                  83
296 #define SDLK_T                  84
297 #define SDLK_U                  85
298 #define SDLK_V                  86
299 #define SDLK_W                  87
300 #define SDLK_X                  88
301 #define SDLK_Y                  89
302 #define SDLK_Z                  90
303 #endif
304
305 #define KSYM_A                  SDLK_A
306 #define KSYM_B                  SDLK_B
307 #define KSYM_C                  SDLK_C
308 #define KSYM_D                  SDLK_D
309 #define KSYM_E                  SDLK_E
310 #define KSYM_F                  SDLK_F
311 #define KSYM_G                  SDLK_G
312 #define KSYM_H                  SDLK_H
313 #define KSYM_I                  SDLK_I
314 #define KSYM_J                  SDLK_J
315 #define KSYM_K                  SDLK_K
316 #define KSYM_L                  SDLK_L
317 #define KSYM_M                  SDLK_M
318 #define KSYM_N                  SDLK_N
319 #define KSYM_O                  SDLK_O
320 #define KSYM_P                  SDLK_P
321 #define KSYM_Q                  SDLK_Q
322 #define KSYM_R                  SDLK_R
323 #define KSYM_S                  SDLK_S
324 #define KSYM_T                  SDLK_T
325 #define KSYM_U                  SDLK_U
326 #define KSYM_V                  SDLK_V
327 #define KSYM_W                  SDLK_W
328 #define KSYM_X                  SDLK_X
329 #define KSYM_Y                  SDLK_Y
330 #define KSYM_Z                  SDLK_Z
331
332 #define KSYM_a                  SDLK_a
333 #define KSYM_b                  SDLK_b
334 #define KSYM_c                  SDLK_c
335 #define KSYM_d                  SDLK_d
336 #define KSYM_e                  SDLK_e
337 #define KSYM_f                  SDLK_f
338 #define KSYM_g                  SDLK_g
339 #define KSYM_h                  SDLK_h
340 #define KSYM_i                  SDLK_i
341 #define KSYM_j                  SDLK_j
342 #define KSYM_k                  SDLK_k
343 #define KSYM_l                  SDLK_l
344 #define KSYM_m                  SDLK_m
345 #define KSYM_n                  SDLK_n
346 #define KSYM_o                  SDLK_o
347 #define KSYM_p                  SDLK_p
348 #define KSYM_q                  SDLK_q
349 #define KSYM_r                  SDLK_r
350 #define KSYM_s                  SDLK_s
351 #define KSYM_t                  SDLK_t
352 #define KSYM_u                  SDLK_u
353 #define KSYM_v                  SDLK_v
354 #define KSYM_w                  SDLK_w
355 #define KSYM_x                  SDLK_x
356 #define KSYM_y                  SDLK_y
357 #define KSYM_z                  SDLK_z
358
359 #define KSYM_0                  SDLK_0
360 #define KSYM_1                  SDLK_1
361 #define KSYM_2                  SDLK_2
362 #define KSYM_3                  SDLK_3
363 #define KSYM_4                  SDLK_4
364 #define KSYM_5                  SDLK_5
365 #define KSYM_6                  SDLK_6
366 #define KSYM_7                  SDLK_7
367 #define KSYM_8                  SDLK_8
368 #define KSYM_9                  SDLK_9
369
370 #if defined(TARGET_SDL2)
371 #define KSYM_KP_0               SDLK_KP_0
372 #define KSYM_KP_1               SDLK_KP_1
373 #define KSYM_KP_2               SDLK_KP_2
374 #define KSYM_KP_3               SDLK_KP_3
375 #define KSYM_KP_4               SDLK_KP_4
376 #define KSYM_KP_5               SDLK_KP_5
377 #define KSYM_KP_6               SDLK_KP_6
378 #define KSYM_KP_7               SDLK_KP_7
379 #define KSYM_KP_8               SDLK_KP_8
380 #define KSYM_KP_9               SDLK_KP_9
381 #else
382 #define KSYM_KP_0               SDLK_KP0
383 #define KSYM_KP_1               SDLK_KP1
384 #define KSYM_KP_2               SDLK_KP2
385 #define KSYM_KP_3               SDLK_KP3
386 #define KSYM_KP_4               SDLK_KP4
387 #define KSYM_KP_5               SDLK_KP5
388 #define KSYM_KP_6               SDLK_KP6
389 #define KSYM_KP_7               SDLK_KP7
390 #define KSYM_KP_8               SDLK_KP8
391 #define KSYM_KP_9               SDLK_KP9
392 #endif
393
394 #define KSYM_F1                 SDLK_F1
395 #define KSYM_F2                 SDLK_F2
396 #define KSYM_F3                 SDLK_F3
397 #define KSYM_F4                 SDLK_F4
398 #define KSYM_F5                 SDLK_F5
399 #define KSYM_F6                 SDLK_F6
400 #define KSYM_F7                 SDLK_F7
401 #define KSYM_F8                 SDLK_F8
402 #define KSYM_F9                 SDLK_F9
403 #define KSYM_F10                SDLK_F10
404 #define KSYM_F11                SDLK_F11
405 #define KSYM_F12                SDLK_F12
406
407 #define KSYM_FKEY_FIRST         KSYM_F1
408 #define KSYM_FKEY_LAST          KSYM_F12
409 #define KSYM_NUM_FKEYS          (KSYM_FKEY_LAST - KSYM_FKEY_FIRST + 1)
410
411 #define KMOD_None               KMOD_NONE
412 #define KMOD_Shift_L            KMOD_LSHIFT
413 #define KMOD_Shift_R            KMOD_RSHIFT
414 #define KMOD_Control_L          KMOD_LCTRL
415 #define KMOD_Control_R          KMOD_RCTRL
416
417 #if defined(TARGET_SDL2)
418 #define KMOD_Meta_L             KMOD_LGUI
419 #define KMOD_Meta_R             KMOD_RGUI
420 #else
421 #define KMOD_Meta_L             KMOD_LMETA
422 #define KMOD_Meta_R             KMOD_RMETA
423 #endif
424
425 #define KMOD_Alt_L              KMOD_LALT
426 #define KMOD_Alt_R              KMOD_RALT
427
428 #define KMOD_Shift              (KMOD_Shift_L   | KMOD_Shift_R)
429 #define KMOD_Control            (KMOD_Control_L | KMOD_Control_R)
430 #define KMOD_Meta               (KMOD_Meta_L    | KMOD_Meta_R)
431 #define KMOD_Alt                (KMOD_Alt_L     | KMOD_Alt_R)
432
433 #if defined(TARGET_SDL2)
434 #define KMOD_TextInput          (KMOD_Shift | KMOD_Alt_R)
435 #endif
436
437 /* SDL function definitions */
438
439 boolean SDLSetNativeSurface(SDL_Surface **);
440 SDL_Surface *SDLGetNativeSurface(SDL_Surface *);
441
442 #if defined(TARGET_SDL2)
443 SDL_Surface *SDL_DisplayFormat(SDL_Surface *);
444 void SDLSetWindowScaling(int);
445 void SDLSetWindowScalingQuality(char *);
446 void SDLSetWindowFullscreen(boolean);
447 void SDLRedrawWindow();
448 #endif
449
450 void SDLSetWindowTitle(void);
451
452 void SDLLimitScreenUpdates(boolean);
453 void SDLInitVideoDisplay(void);
454 void SDLInitVideoBuffer(DrawBuffer **, DrawWindow **, boolean);
455 boolean SDLSetVideoMode(DrawBuffer **, boolean);
456 void SDLCreateBitmapContent(Bitmap *, int, int, int);
457 void SDLFreeBitmapPointers(Bitmap *);
458 void SDLCopyArea(Bitmap *, Bitmap *, int, int, int, int, int, int, int);
459 void SDLFillRectangle(Bitmap *, int, int, int, int, Uint32);
460 void SDLFadeRectangle(Bitmap *, int, int, int, int, int, int, int,
461                       void (*draw_border_function)(void));
462 void SDLDrawSimpleLine(Bitmap *, int, int, int, int, Uint32);
463 void SDLDrawLine(Bitmap *, int, int, int, int, Uint32);
464 Pixel SDLGetPixel(Bitmap *, int, int);
465 void SDLPutPixel(Bitmap *, int, int, Pixel);
466
467 void SDLInvertArea(Bitmap *, int, int, int, int, Uint32);
468 void SDLCopyInverseMasked(Bitmap *, Bitmap *, int, int, int, int, int, int);
469
470 #if 1
471 Bitmap *SDLZoomBitmap(Bitmap *, int, int);
472 #else
473 void SDLZoomBitmap(Bitmap *, Bitmap *);
474 #endif
475
476 Bitmap *SDLLoadImage(char *);
477
478 void SDLSetMouseCursor(struct MouseCursorInfo *);
479
480 void SDLOpenAudio(void);
481 void SDLCloseAudio(void);
482
483 void SDLNextEvent(Event *);
484 void SDLHandleWindowManagerEvent(Event *);
485
486 void HandleJoystickEvent(Event *);
487 void SDLInitJoysticks(void);
488 boolean SDLReadJoystick(int, int *, int *, boolean *, boolean *);
489
490 #endif /* SDL_H */