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