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