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