rnd-20131203-1-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 #else
67 typedef SDLKey                  Key;
68 #endif
69 typedef unsigned int            KeyMod;
70
71 typedef SDL_Event               Event;
72 typedef SDL_MouseButtonEvent    ButtonEvent;
73 typedef SDL_MouseMotionEvent    MotionEvent;
74 typedef SDL_KeyboardEvent       KeyEvent;
75 typedef SDL_Event               ExposeEvent;
76 typedef SDL_Event               FocusChangeEvent;
77 typedef SDL_Event               ClientMessageEvent;
78
79 typedef int                     GC;
80 typedef int                     Pixmap;
81 typedef int                     Display;
82 typedef int                     Visual;
83 typedef int                     Colormap;
84
85
86 /* structure definitions */
87
88 struct SDLSurfaceInfo
89 {
90   char *source_filename;
91
92   int width, height;
93   SDL_Surface *surface;
94   SDL_Surface *surface_masked;
95   GC gc;
96   GC stored_clip_gc;
97 };
98
99 struct MouseCursorInfo
100 {
101   int width, height;
102   int hot_x, hot_y;
103
104   byte data[CURSOR_MAX_WIDTH * CURSOR_MAX_HEIGHT / 8];
105   byte mask[CURSOR_MAX_WIDTH * CURSOR_MAX_HEIGHT / 8];
106 };
107
108
109 /* SDL symbol definitions */
110
111 #define None                    0L
112
113 #define BLACK_PIXEL             0x000000
114 #define WHITE_PIXEL             0xffffff
115
116 #define EVENT_BUTTONPRESS       SDL_MOUSEBUTTONDOWN
117 #define EVENT_BUTTONRELEASE     SDL_MOUSEBUTTONUP
118 #define EVENT_MOTIONNOTIFY      SDL_MOUSEMOTION
119 #define EVENT_KEYPRESS          SDL_KEYDOWN
120 #define EVENT_KEYRELEASE        SDL_KEYUP
121 #define EVENT_EXPOSE            SDL_USEREVENT + 0
122 #define EVENT_FOCUSIN           SDL_USEREVENT + 1
123 #define EVENT_FOCUSOUT          SDL_USEREVENT + 2
124 #define EVENT_CLIENTMESSAGE     SDL_QUIT
125 #define EVENT_MAPNOTIFY         SDL_USEREVENT + 4
126 #define EVENT_UNMAPNOTIFY       SDL_USEREVENT + 5
127
128 #define KSYM_UNDEFINED          SDLK_UNKNOWN
129
130 #define KSYM_Return             SDLK_RETURN
131 #define KSYM_Escape             SDLK_ESCAPE
132
133 #define KSYM_Left               SDLK_LEFT
134 #define KSYM_Right              SDLK_RIGHT
135 #define KSYM_Up                 SDLK_UP
136 #define KSYM_Down               SDLK_DOWN
137
138 #ifdef SDLK_KP_LEFT
139 #define KSYM_KP_Left            SDLK_KP_LEFT
140 #define KSYM_KP_Right           SDLK_KP_RIGHT
141 #define KSYM_KP_Up              SDLK_KP_UP
142 #define KSYM_KP_Down            SDLK_KP_DOWN
143 #endif
144
145 #define KSYM_KP_Enter           SDLK_KP_ENTER
146 #define KSYM_KP_Add             SDLK_KP_PLUS
147 #define KSYM_KP_Subtract        SDLK_KP_MINUS
148 #define KSYM_KP_Multiply        SDLK_KP_MULTIPLY
149 #define KSYM_KP_Divide          SDLK_KP_DIVIDE
150 #define KSYM_KP_Separator       SDLK_KP_PERIOD
151
152 #define KSYM_Shift_L            SDLK_LSHIFT
153 #define KSYM_Shift_R            SDLK_RSHIFT
154 #define KSYM_Control_L          SDLK_LCTRL
155 #define KSYM_Control_R          SDLK_RCTRL
156 #if defined(TARGET_SDL2)
157 #define KSYM_Meta_L             SDLK_LGUI
158 #define KSYM_Meta_R             SDLK_RGUI
159 #else
160 #define KSYM_Meta_L             SDLK_LMETA
161 #define KSYM_Meta_R             SDLK_RMETA
162 #endif
163 #define KSYM_Alt_L              SDLK_LALT
164 #define KSYM_Alt_R              SDLK_RALT
165 #if !defined(TARGET_SDL2)
166 #define KSYM_Super_L            SDLK_LSUPER
167 #define KSYM_Super_R            SDLK_RSUPER
168 #endif
169 #define KSYM_Mode_switch        SDLK_MODE
170 #define KSYM_Multi_key          SDLK_RCTRL
171
172 #define KSYM_BackSpace          SDLK_BACKSPACE
173 #define KSYM_Delete             SDLK_DELETE
174 #define KSYM_Insert             SDLK_INSERT
175 #define KSYM_Tab                SDLK_TAB
176 #define KSYM_Home               SDLK_HOME
177 #define KSYM_End                SDLK_END
178 #define KSYM_Page_Up            SDLK_PAGEUP
179 #define KSYM_Page_Down          SDLK_PAGEDOWN
180 #define KSYM_Menu               SDLK_MENU
181
182 #define KSYM_space              SDLK_SPACE
183 #define KSYM_exclam             SDLK_EXCLAIM
184 #define KSYM_quotedbl           SDLK_QUOTEDBL
185 #define KSYM_numbersign         SDLK_HASH
186 #define KSYM_dollar             SDLK_DOLLAR
187 #define KSYM_percent            KSYM_UNDEFINED          /* undefined */
188 #define KSYM_ampersand          SDLK_AMPERSAND
189 #define KSYM_apostrophe         SDLK_QUOTE
190 #define KSYM_parenleft          SDLK_LEFTPAREN
191 #define KSYM_parenright         SDLK_RIGHTPAREN
192 #define KSYM_asterisk           SDLK_ASTERISK
193 #define KSYM_plus               SDLK_PLUS
194 #define KSYM_comma              SDLK_COMMA
195 #define KSYM_minus              SDLK_MINUS
196 #define KSYM_period             SDLK_PERIOD
197 #define KSYM_slash              SDLK_SLASH
198
199 #define KSYM_colon              SDLK_COLON
200 #define KSYM_semicolon          SDLK_SEMICOLON
201 #define KSYM_less               SDLK_LESS
202 #define KSYM_equal              SDLK_EQUALS
203 #define KSYM_greater            SDLK_GREATER
204 #define KSYM_question           SDLK_QUESTION
205 #define KSYM_at                 SDLK_AT
206
207 #define KSYM_bracketleft        SDLK_LEFTBRACKET
208 #define KSYM_backslash          SDLK_BACKSLASH
209 #define KSYM_bracketright       SDLK_RIGHTBRACKET
210 #define KSYM_asciicircum        SDLK_CARET
211 #define KSYM_underscore         SDLK_UNDERSCORE
212 #define KSYM_grave              SDLK_BACKQUOTE
213
214 #define KSYM_quoteleft          KSYM_UNDEFINED          /* undefined */
215 #define KSYM_braceleft          KSYM_UNDEFINED          /* undefined */
216 #define KSYM_bar                KSYM_UNDEFINED          /* undefined */
217 #define KSYM_braceright         KSYM_UNDEFINED          /* undefined */
218 #define KSYM_asciitilde         KSYM_UNDEFINED          /* undefined */
219
220 #if !defined(TARGET_SDL2)
221 #define KSYM_degree             SDLK_WORLD_16
222 #define KSYM_Adiaeresis         SDLK_WORLD_36
223 #define KSYM_Odiaeresis         SDLK_WORLD_54
224 #define KSYM_Udiaeresis         SDLK_WORLD_60
225 #define KSYM_adiaeresis         SDLK_WORLD_68
226 #define KSYM_odiaeresis         SDLK_WORLD_86
227 #define KSYM_udiaeresis         SDLK_WORLD_92
228 #define KSYM_ssharp             SDLK_WORLD_63
229 #endif
230
231 #ifndef SDLK_A
232 #define SDLK_A                  65
233 #define SDLK_B                  66
234 #define SDLK_C                  67
235 #define SDLK_D                  68
236 #define SDLK_E                  69
237 #define SDLK_F                  70
238 #define SDLK_G                  71
239 #define SDLK_H                  72
240 #define SDLK_I                  73
241 #define SDLK_J                  74
242 #define SDLK_K                  75
243 #define SDLK_L                  76
244 #define SDLK_M                  77
245 #define SDLK_N                  78
246 #define SDLK_O                  79
247 #define SDLK_P                  80
248 #define SDLK_Q                  81
249 #define SDLK_R                  82
250 #define SDLK_S                  83
251 #define SDLK_T                  84
252 #define SDLK_U                  85
253 #define SDLK_V                  86
254 #define SDLK_W                  87
255 #define SDLK_X                  88
256 #define SDLK_Y                  89
257 #define SDLK_Z                  90
258 #endif
259
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
286
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
313
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
324
325 #if defined(TARGET_SDL2)
326 #define KSYM_KP_0               SDLK_KP_0
327 #define KSYM_KP_1               SDLK_KP_1
328 #define KSYM_KP_2               SDLK_KP_2
329 #define KSYM_KP_3               SDLK_KP_3
330 #define KSYM_KP_4               SDLK_KP_4
331 #define KSYM_KP_5               SDLK_KP_5
332 #define KSYM_KP_6               SDLK_KP_6
333 #define KSYM_KP_7               SDLK_KP_7
334 #define KSYM_KP_8               SDLK_KP_8
335 #define KSYM_KP_9               SDLK_KP_9
336 #else
337 #define KSYM_KP_0               SDLK_KP0
338 #define KSYM_KP_1               SDLK_KP1
339 #define KSYM_KP_2               SDLK_KP2
340 #define KSYM_KP_3               SDLK_KP3
341 #define KSYM_KP_4               SDLK_KP4
342 #define KSYM_KP_5               SDLK_KP5
343 #define KSYM_KP_6               SDLK_KP6
344 #define KSYM_KP_7               SDLK_KP7
345 #define KSYM_KP_8               SDLK_KP8
346 #define KSYM_KP_9               SDLK_KP9
347 #endif
348
349 #define KSYM_F1                 SDLK_F1
350 #define KSYM_F2                 SDLK_F2
351 #define KSYM_F3                 SDLK_F3
352 #define KSYM_F4                 SDLK_F4
353 #define KSYM_F5                 SDLK_F5
354 #define KSYM_F6                 SDLK_F6
355 #define KSYM_F7                 SDLK_F7
356 #define KSYM_F8                 SDLK_F8
357 #define KSYM_F9                 SDLK_F9
358 #define KSYM_F10                SDLK_F10
359 #define KSYM_F11                SDLK_F11
360 #define KSYM_F12                SDLK_F12
361 #define KSYM_F13                SDLK_F13
362 #define KSYM_F14                SDLK_F14
363 #define KSYM_F15                SDLK_F15
364 #define KSYM_F16                KSYM_UNDEFINED
365 #define KSYM_F17                KSYM_UNDEFINED
366 #define KSYM_F18                KSYM_UNDEFINED
367 #define KSYM_F19                KSYM_UNDEFINED
368 #define KSYM_F20                KSYM_UNDEFINED
369 #define KSYM_F21                KSYM_UNDEFINED
370 #define KSYM_F22                KSYM_UNDEFINED
371 #define KSYM_F23                KSYM_UNDEFINED
372 #define KSYM_F24                KSYM_UNDEFINED
373
374 #define KSYM_FKEY_FIRST         KSYM_F1
375 #define KSYM_FKEY_LAST          KSYM_F15
376 #define KSYM_NUM_FKEYS          (KSYM_FKEY_LAST - KSYM_FKEY_FIRST + 1)
377
378 #define KMOD_None               None
379 #define KMOD_Shift_L            KMOD_LSHIFT
380 #define KMOD_Shift_R            KMOD_RSHIFT
381 #define KMOD_Control_L          KMOD_LCTRL
382 #define KMOD_Control_R          KMOD_RCTRL
383 #if defined(TARGET_SDL2)
384 #define KMOD_Meta_L             KMOD_LGUI
385 #define KMOD_Meta_R             KMOD_RGUI
386 #else
387 #define KMOD_Meta_L             KMOD_LMETA
388 #define KMOD_Meta_R             KMOD_RMETA
389 #endif
390 #define KMOD_Alt_L              KMOD_LALT
391 #define KMOD_Alt_R              KMOD_RALT
392
393 #define KMOD_Shift              (KMOD_Shift_L   | KMOD_Shift_R)
394 #define KMOD_Control            (KMOD_Control_L | KMOD_Control_R)
395 #define KMOD_Meta               (KMOD_Meta_L    | KMOD_Meta_R)
396 #define KMOD_Alt                (KMOD_Alt_L     | KMOD_Alt_R)
397
398
399 /* SDL function definitions */
400
401 #if defined(TARGET_SDL2)
402 SDL_Surface *SDL_DisplayFormat(SDL_Surface *);
403 #endif
404
405 void SDLInitVideoDisplay(void);
406 void SDLInitVideoBuffer(DrawBuffer **, DrawWindow **, boolean);
407 boolean SDLSetVideoMode(DrawBuffer **, boolean);
408 void SDLCreateBitmapContent(Bitmap *, int, int, int);
409 void SDLFreeBitmapPointers(Bitmap *);
410 void SDLCopyArea(Bitmap *, Bitmap *, int, int, int, int, int, int, int);
411 void SDLFillRectangle(Bitmap *, int, int, int, int, Uint32);
412 void SDLFadeRectangle(Bitmap *, int, int, int, int, int, int, int,
413                       void (*draw_border_function)(void));
414 void SDLDrawSimpleLine(Bitmap *, int, int, int, int, Uint32);
415 void SDLDrawLine(Bitmap *, int, int, int, int, Uint32);
416 Pixel SDLGetPixel(Bitmap *, int, int);
417 void SDLPutPixel(Bitmap *, int, int, Pixel);
418
419 void SDLInvertArea(Bitmap *, int, int, int, int, Uint32);
420 void SDLCopyInverseMasked(Bitmap *, Bitmap *, int, int, int, int, int, int);
421
422 void SDLZoomBitmap(Bitmap *, Bitmap *);
423
424 Bitmap *SDLLoadImage(char *);
425
426 void SDLSetMouseCursor(struct MouseCursorInfo *);
427
428 void SDLOpenAudio(void);
429 void SDLCloseAudio(void);
430
431 void SDLNextEvent(Event *);
432 void SDLHandleWindowManagerEvent(Event *);
433
434 void HandleJoystickEvent(Event *);
435 void SDLInitJoysticks(void);
436 boolean SDLReadJoystick(int, int *, int *, boolean *, boolean *);
437
438 #endif /* SDL_H */