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