1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * ©1995 Artsoft Development *
6 * 33659 Bielefeld-Senne *
7 * Telefon: (0521) 493245 *
8 * eMail: aeglos@valinor.owl.de *
9 * aeglos@uni-paderborn.de *
10 * q99492@pbhrzx.uni-paderborn.de *
11 *----------------------------------------------------------*
13 ***********************************************************/
18 /* ========================================================================= */
19 /* internal variables */
20 /* ========================================================================= */
27 DrawWindow window = None;
33 /* ========================================================================= */
34 /* exported variables */
35 /* ========================================================================= */
37 struct ProgramInfo program;
38 struct VideoSystemInfo video;
39 struct AudioSystemInfo audio;
40 struct OptionInfo options;
43 /* ========================================================================= */
45 /* ========================================================================= */
47 inline static int GetRealDepth(int depth)
49 return (depth == DEFAULT_DEPTH ? video.default_depth : depth);
52 inline void InitProgramInfo(char *command_name, char *program_title,
53 char *window_title, char *icon_title,
54 char *x11_icon_filename,
55 char *x11_iconmask_filename)
57 program.command_name = command_name;
58 program.program_title = program_title;
59 program.window_title = window_title;
60 program.icon_title = icon_title;
61 program.x11_icon_filename = x11_icon_filename;
62 program.x11_iconmask_filename = x11_iconmask_filename;
65 inline void InitVideoDisplay(void)
68 SDLInitVideoDisplay();
70 X11InitVideoDisplay();
74 inline void InitVideoBuffer(DrawBuffer *backbuffer, DrawWindow *window,
75 int width, int height, int depth,
79 video.height = height;
80 video.depth = GetRealDepth(depth);
81 video.fullscreen_available = FULLSCREEN_STATUS;
82 video.fullscreen_enabled = FALSE;
85 SDLInitVideoBuffer(backbuffer, window, fullscreen);
87 X11InitVideoBuffer(backbuffer, window);
91 inline Bitmap CreateBitmap(int width, int height, int depth)
93 int real_depth = GetRealDepth(depth);
96 SDL_Surface *surface_tmp, *surface_native;
98 if ((surface_tmp = SDL_CreateRGBSurface(SURFACE_FLAGS, width, height,
99 real_depth, 0, 0, 0, 0))
101 Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s", SDL_GetError());
103 if ((surface_native = SDL_DisplayFormat(surface_tmp)) == NULL)
104 Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s", SDL_GetError());
106 SDL_FreeSurface(surface_tmp);
108 return surface_native;
112 if (!(pixmap = XCreatePixmap(display, window, width, height, real_depth)))
113 Error(ERR_EXIT, "cannot create pixmap");
119 inline void FreeBitmap(Bitmap bitmap)
122 SDL_FreeSurface(bitmap);
124 XFreePixmap(display, bitmap);
128 inline void ClearRectangle(Bitmap bitmap, int x, int y, int width, int height)
131 SDLFillRectangle(bitmap, x, y, width, height, 0x000000);
133 XFillRectangle(display, bitmap, gc, x, y, width, height);
137 inline void BlitBitmap(Bitmap src_bitmap, Bitmap dst_bitmap,
138 int src_x, int src_y,
139 int width, int height,
140 int dst_x, int dst_y)
143 SDLCopyArea(src_bitmap, dst_bitmap,
144 src_x, src_y, width, height, dst_x, dst_y);
146 XCopyArea(display, src_bitmap, dst_bitmap, gc,
147 src_x, src_y, width, height, dst_x, dst_y);
152 static GC last_clip_gc = 0; /* needed for XCopyArea() through clip mask */
155 inline void SetClipMask(GC clip_gc, Pixmap clip_pixmap)
158 XSetClipMask(display, clip_gc, clip_pixmap);
159 last_clip_gc = clip_gc;
163 inline void SetClipOrigin(GC clip_gc, int clip_x, int clip_y)
166 XSetClipOrigin(display, clip_gc, clip_x, clip_y);
167 last_clip_gc = clip_gc;
171 inline void BlitBitmapMasked(Bitmap src_bitmap, Bitmap dst_bitmap,
172 int src_x, int src_y,
173 int width, int height,
174 int dst_x, int dst_y)
177 SDLCopyArea(src_bitmap, dst_bitmap,
178 src_x, src_y, width, height, dst_x, dst_y);
180 XCopyArea(display, src_bitmap, dst_bitmap, last_clip_gc,
181 src_x, src_y, width, height, dst_x, dst_y);
185 inline void DrawSimpleWhiteLine(Bitmap bitmap, int from_x, int from_y,
189 SDLDrawSimpleLine(bitmap, from_x, from_y, to_x, to_y, 0xffffff);
191 XSetForeground(display, gc, WhitePixel(display, screen));
192 XDrawLine(display, bitmap, gc, from_x, from_y, to_x, to_y);
193 XSetForeground(display, gc, BlackPixel(display, screen));
197 /* execute all pending screen drawing operations */
198 inline void FlushDisplay(void)
205 /* execute and wait for all pending screen drawing operations */
206 inline void SyncDisplay(void)
209 XSync(display, FALSE);
213 inline void KeyboardAutoRepeatOn(void)
216 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY / 2,
217 SDL_DEFAULT_REPEAT_INTERVAL / 2);
218 SDL_EnableUNICODE(1);
220 XAutoRepeatOn(display);
224 inline void KeyboardAutoRepeatOff(void)
227 SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL);
228 SDL_EnableUNICODE(0);
230 XAutoRepeatOff(display);
234 inline boolean PointerInWindow(DrawWindow window)
239 DrawWindow root, child;
244 /* if XQueryPointer() returns False, the pointer
245 is not on the same screen as the specified window */
246 return XQueryPointer(display, window, &root, &child, &root_x, &root_y,
247 &win_x, &win_y, &mask);
251 inline boolean SetVideoMode(boolean fullscreen)
254 return SDLSetVideoMode(&backbuffer, fullscreen);
256 boolean success = TRUE;
258 if (fullscreen && video.fullscreen_available)
260 Error(ERR_WARN, "fullscreen not available in X11 version");
262 /* display error message only once */
263 video.fullscreen_available = FALSE;
272 inline boolean ChangeVideoModeIfNeeded(boolean fullscreen)
275 if ((fullscreen && !video.fullscreen_enabled && video.fullscreen_available)||
276 (!fullscreen && video.fullscreen_enabled))
277 fullscreen = SetVideoMode(fullscreen_wanted);
284 /* ========================================================================= */
285 /* audio functions */
286 /* ========================================================================= */
288 inline boolean OpenAudio(struct AudioSystemInfo *audio)
290 audio->sound_available = FALSE;
291 audio->loops_available = FALSE;
292 audio->soundserver_pipe[0] = audio->soundserver_pipe[1] = 0;
293 audio->soundserver_pid = 0;
294 audio->device_name = NULL;
295 audio->device_fd = 0;
297 #if defined(TARGET_SDL)
300 audio->sound_available = TRUE;
301 audio->loops_available = TRUE;
303 #elif defined(PLATFORM_MSDOS)
304 if (MSDOSOpenAudio())
306 audio->sound_available = TRUE;
307 audio->loops_available = TRUE;
309 #elif defined(PLATFORM_UNIX)
310 UnixOpenAudio(audio);
313 return audio->sound_available;
316 inline void CloseAudio(struct AudioSystemInfo *audio)
318 #if defined(TARGET_SDL)
320 #elif defined(PLATFORM_MSDOS)
322 #elif defined(PLATFORM_UNIX)
323 UnixCloseAudio(audio);
326 audio->sound_available = FALSE;
327 audio->loops_available = FALSE;
331 /* ========================================================================= */
332 /* event functions */
333 /* ========================================================================= */
335 inline void InitEventFilter(EventFilter filter_function)
338 /* set event filter to filter out certain events */
339 SDL_SetEventFilter(filter_function);
343 inline boolean PendingEvent(void)
346 return (SDL_PollEvent(NULL) ? TRUE : FALSE);
348 return (XPending(display) ? TRUE : FALSE);
352 inline void NextEvent(Event *event)
355 SDL_WaitEvent(event);
357 XNextEvent(display, event);
361 inline Key GetEventKey(KeyEvent *event, boolean with_modifiers)
365 printf("unicode == '%d', sym == '%d', mod == '0x%04x'\n",
366 (int)event->keysym.unicode,
367 (int)event->keysym.sym,
368 (int)SDL_GetModState());
371 if (with_modifiers && event->keysym.unicode != 0)
372 return event->keysym.unicode;
374 return event->keysym.sym;
377 printf("with modifiers == '0x%04x', without modifiers == '0x%04x'\n",
378 (int)XLookupKeysym(event, event->state),
379 (int)XLookupKeysym(event, 0));
383 return XLookupKeysym(event, event->state);
385 return XLookupKeysym(event, 0);
389 inline boolean CheckCloseWindowEvent(ClientMessageEvent *event)
391 if (event->type != EVENT_CLIENTMESSAGE)
394 #if defined(TARGET_SDL)
395 return TRUE; /* the only possible message here is SDL_QUIT */
396 #elif defined(PLATFORM_UNIX)
397 if ((event->window == window) &&
398 (event->data.l[0] == XInternAtom(display, "WM_DELETE_WINDOW", FALSE)))
406 inline void dummy(void)