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