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 VideoSystemInfo video;
38 struct AudioSystemInfo audio;
39 struct OptionInfo options;
42 /* ========================================================================= */
44 /* ========================================================================= */
46 inline void InitBufferedDisplay(DrawBuffer *backbuffer, DrawWindow *window)
48 video.fullscreen_available = FULLSCREEN_STATUS;
49 video.fullscreen_enabled = FALSE;
52 SDLInitBufferedDisplay(backbuffer, window);
54 X11InitBufferedDisplay(backbuffer, window);
58 inline int GetDisplayDepth(void)
61 return SDL_GetVideoSurface()->format->BitsPerPixel;
63 return XDefaultDepth(display, screen);
67 inline Bitmap CreateBitmap(int width, int height, int depth)
69 int real_depth = (depth == DEFAULT_DEPTH ? GetDisplayDepth() : depth);
72 SDL_Surface *surface_tmp, *surface_native;
74 if ((surface_tmp = SDL_CreateRGBSurface(SURFACE_FLAGS, width, height,
75 real_depth, 0, 0, 0, 0))
77 Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s", SDL_GetError());
79 if ((surface_native = SDL_DisplayFormat(surface_tmp)) == NULL)
80 Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s", SDL_GetError());
82 SDL_FreeSurface(surface_tmp);
84 return surface_native;
88 if (!(pixmap = XCreatePixmap(display, window, width, height, real_depth)))
89 Error(ERR_EXIT, "cannot create pixmap");
95 inline void FreeBitmap(Bitmap bitmap)
98 SDL_FreeSurface(bitmap);
100 XFreePixmap(display, bitmap);
104 inline void ClearRectangle(Bitmap bitmap, int x, int y, int width, int height)
107 SDLFillRectangle(bitmap, x, y, width, height, 0x000000);
109 XFillRectangle(display, bitmap, gc, x, y, width, height);
113 inline void BlitBitmap(Bitmap src_bitmap, Bitmap dst_bitmap,
114 int src_x, int src_y,
115 int width, int height,
116 int dst_x, int dst_y)
119 SDLCopyArea(src_bitmap, dst_bitmap,
120 src_x, src_y, width, height, dst_x, dst_y);
122 XCopyArea(display, src_bitmap, dst_bitmap, gc,
123 src_x, src_y, width, height, dst_x, dst_y);
128 static GC last_clip_gc = 0; /* needed for XCopyArea() through clip mask */
131 inline void SetClipMask(GC clip_gc, Pixmap clip_pixmap)
134 XSetClipMask(display, clip_gc, clip_pixmap);
135 last_clip_gc = clip_gc;
139 inline void SetClipOrigin(GC clip_gc, int clip_x, int clip_y)
142 XSetClipOrigin(display, clip_gc, clip_x, clip_y);
143 last_clip_gc = clip_gc;
147 inline void BlitBitmapMasked(Bitmap src_bitmap, Bitmap dst_bitmap,
148 int src_x, int src_y,
149 int width, int height,
150 int dst_x, int dst_y)
153 SDLCopyArea(src_bitmap, dst_bitmap,
154 src_x, src_y, width, height, dst_x, dst_y);
156 XCopyArea(display, src_bitmap, dst_bitmap, last_clip_gc,
157 src_x, src_y, width, height, dst_x, dst_y);
161 inline void DrawSimpleWhiteLine(Bitmap bitmap, int from_x, int from_y,
165 SDLDrawSimpleLine(bitmap, from_x, from_y, to_x, to_y, 0xffffff);
167 XSetForeground(display, gc, WhitePixel(display, screen));
168 XDrawLine(display, bitmap, gc, from_x, from_y, to_x, to_y);
169 XSetForeground(display, gc, BlackPixel(display, screen));
173 /* execute all pending screen drawing operations */
174 inline void FlushDisplay(void)
181 /* execute and wait for all pending screen drawing operations */
182 inline void SyncDisplay(void)
185 XSync(display, FALSE);
189 inline void KeyboardAutoRepeatOn(void)
192 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY / 2,
193 SDL_DEFAULT_REPEAT_INTERVAL / 2);
194 SDL_EnableUNICODE(1);
196 XAutoRepeatOn(display);
200 inline void KeyboardAutoRepeatOff(void)
203 SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL);
204 SDL_EnableUNICODE(0);
206 XAutoRepeatOff(display);
210 inline boolean PointerInWindow(DrawWindow window)
215 DrawWindow root, child;
220 /* if XQueryPointer() returns False, the pointer
221 is not on the same screen as the specified window */
222 return XQueryPointer(display, window, &root, &child, &root_x, &root_y,
223 &win_x, &win_y, &mask);
227 inline boolean SetVideoMode(boolean fullscreen)
230 return SDLSetVideoMode(&backbuffer, fullscreen);
232 boolean success = TRUE;
234 if (fullscreen && video.fullscreen_available)
236 Error(ERR_WARN, "fullscreen not available in X11 version");
238 /* display error message only once */
239 video.fullscreen_available = FALSE;
248 inline boolean ChangeVideoModeIfNeeded(boolean fullscreen)
251 if ((fullscreen && !video.fullscreen_enabled && video.fullscreen_available)||
252 (!fullscreen && video.fullscreen_enabled))
253 fullscreen = SetVideoMode(fullscreen_wanted);
260 /* ========================================================================= */
261 /* audio functions */
262 /* ========================================================================= */
264 inline boolean OpenAudio(struct AudioSystemInfo *audio)
266 audio->sound_available = FALSE;
267 audio->loops_available = FALSE;
268 audio->soundserver_pipe[0] = audio->soundserver_pipe[1] = 0;
269 audio->soundserver_pid = 0;
270 audio->device_name = NULL;
271 audio->device_fd = 0;
273 #if defined(TARGET_SDL)
276 audio->sound_available = TRUE;
277 audio->loops_available = TRUE;
279 #elif defined(PLATFORM_MSDOS)
280 if (MSDOSOpenAudio())
282 audio->sound_available = TRUE;
283 audio->loops_available = TRUE;
285 #elif defined(PLATFORM_UNIX)
286 UnixOpenAudio(audio);
289 return audio->sound_available;
292 inline void CloseAudio(struct AudioSystemInfo *audio)
294 #if defined(TARGET_SDL)
296 #elif defined(PLATFORM_MSDOS)
298 #elif defined(PLATFORM_UNIX)
299 UnixCloseAudio(audio);
302 audio->sound_available = FALSE;
303 audio->loops_available = FALSE;
307 /* ========================================================================= */
308 /* event functions */
309 /* ========================================================================= */
311 inline void InitEventFilter(EventFilter filter_function)
314 /* set event filter to filter out certain events */
315 SDL_SetEventFilter(filter_function);
319 inline boolean PendingEvent(void)
322 return (SDL_PollEvent(NULL) ? TRUE : FALSE);
324 return (XPending(display) ? TRUE : FALSE);
328 inline void NextEvent(Event *event)
331 SDL_WaitEvent(event);
333 XNextEvent(display, event);
337 inline Key GetEventKey(KeyEvent *event, boolean with_modifiers)
341 printf("unicode == '%d', sym == '%d', mod == '0x%04x'\n",
342 (int)event->keysym.unicode,
343 (int)event->keysym.sym,
344 (int)SDL_GetModState());
347 if (with_modifiers && event->keysym.unicode != 0)
348 return event->keysym.unicode;
350 return event->keysym.sym;
353 printf("with modifiers == '0x%04x', without modifiers == '0x%04x'\n",
354 (int)XLookupKeysym(event, event->state),
355 (int)XLookupKeysym(event, 0));
359 return XLookupKeysym(event, event->state);
361 return XLookupKeysym(event, 0);
365 inline boolean CheckCloseWindowEvent(ClientMessageEvent *event)
367 if (event->type != EVENT_CLIENTMESSAGE)
370 #if defined(TARGET_SDL)
371 return TRUE; /* the only possible message here is SDL_QUIT */
372 #elif defined(PLATFORM_UNIX)
373 if ((event->window == window) &&
374 (event->data.l[0] == XInternAtom(display, "WM_DELETE_WINDOW", FALSE)))
382 inline void dummy(void)