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