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 ***********************************************************/
20 /* ========================================================================= */
22 /* ========================================================================= */
24 inline void InitBufferedDisplay(DrawBuffer *backbuffer, DrawWindow *window)
27 SDLInitBufferedDisplay(backbuffer, window);
29 X11InitBufferedDisplay(backbuffer, window);
33 inline int GetDisplayDepth(void)
36 return SDL_GetVideoSurface()->format->BitsPerPixel;
38 return XDefaultDepth(display, screen);
42 inline Bitmap CreateBitmap(int width, int height, int depth)
44 int real_depth = (depth == DEFAULT_DEPTH ? GetDisplayDepth() : depth);
47 SDL_Surface *surface_tmp, *surface_native;
49 if ((surface_tmp = SDL_CreateRGBSurface(SURFACE_FLAGS, width, height,
50 real_depth, 0, 0, 0, 0))
52 Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s", SDL_GetError());
54 if ((surface_native = SDL_DisplayFormat(surface_tmp)) == NULL)
55 Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s", SDL_GetError());
57 SDL_FreeSurface(surface_tmp);
59 return surface_native;
63 if (!(pixmap = XCreatePixmap(display, window, width, height, real_depth)))
64 Error(ERR_EXIT, "cannot create pixmap");
70 inline void FreeBitmap(Bitmap bitmap)
73 SDL_FreeSurface(bitmap);
75 XFreePixmap(display, bitmap);
79 inline void ClearRectangle(Bitmap bitmap, int x, int y, int width, int height)
82 SDLFillRectangle(bitmap, x, y, width, height, 0x000000);
84 XFillRectangle(display, bitmap, gc, x, y, width, height);
88 inline void BlitBitmap(Bitmap src_bitmap, Bitmap dst_bitmap,
90 int width, int height,
94 SDLCopyArea(src_bitmap, dst_bitmap,
95 src_x, src_y, width, height, dst_x, dst_y);
97 XCopyArea(display, src_bitmap, dst_bitmap, gc,
98 src_x, src_y, width, height, dst_x, dst_y);
103 static GC last_clip_gc = 0; /* needed for XCopyArea() through clip mask */
106 inline void SetClipMask(GC clip_gc, Pixmap clip_pixmap)
109 XSetClipMask(display, clip_gc, clip_pixmap);
110 last_clip_gc = clip_gc;
114 inline void SetClipOrigin(GC clip_gc, int clip_x, int clip_y)
117 XSetClipOrigin(display, clip_gc, clip_x, clip_y);
118 last_clip_gc = clip_gc;
122 inline void BlitBitmapMasked(Bitmap src_bitmap, Bitmap dst_bitmap,
123 int src_x, int src_y,
124 int width, int height,
125 int dst_x, int dst_y)
128 SDLCopyArea(src_bitmap, dst_bitmap,
129 src_x, src_y, width, height, dst_x, dst_y);
131 XCopyArea(display, src_bitmap, dst_bitmap, last_clip_gc,
132 src_x, src_y, width, height, dst_x, dst_y);
136 inline void DrawSimpleWhiteLine(Bitmap bitmap, int from_x, int from_y,
140 SDLDrawSimpleLine(bitmap, from_x, from_y, to_x, to_y, 0xffffff);
142 XSetForeground(display, gc, WhitePixel(display, screen));
143 XDrawLine(display, bitmap, gc, from_x, from_y, to_x, to_y);
144 XSetForeground(display, gc, BlackPixel(display, screen));
148 /* execute all pending screen drawing operations */
149 inline void FlushDisplay(void)
156 /* execute and wait for all pending screen drawing operations */
157 inline void SyncDisplay(void)
160 XSync(display, FALSE);
164 inline void KeyboardAutoRepeatOn(void)
167 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY / 2,
168 SDL_DEFAULT_REPEAT_INTERVAL / 2);
169 SDL_EnableUNICODE(1);
171 XAutoRepeatOn(display);
175 inline void KeyboardAutoRepeatOff(void)
178 SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL);
179 SDL_EnableUNICODE(0);
181 XAutoRepeatOff(display);
185 inline boolean PointerInWindow(DrawWindow window)
190 DrawWindow root, child;
195 /* if XQueryPointer() returns False, the pointer
196 is not on the same screen as the specified window */
197 return XQueryPointer(display, window, &root, &child, &root_x, &root_y,
198 &win_x, &win_y, &mask);
202 inline boolean SetVideoMode(void)
205 return SDLSetVideoMode(&backbuffer);
207 boolean success = TRUE;
209 if (setup.fullscreen && fullscreen_available)
211 Error(ERR_WARN, "fullscreen not available in X11 version");
213 /* display error message only once */
214 fullscreen_available = FALSE;
223 inline void ChangeVideoModeIfNeeded(void)
226 if ((setup.fullscreen && !fullscreen_enabled && fullscreen_available) ||
227 (!setup.fullscreen && fullscreen_enabled))
233 /* ========================================================================= */
234 /* audio functions */
235 /* ========================================================================= */
237 inline boolean OpenAudio(struct AudioSystemInfo *audio)
239 audio->sound_available = FALSE;
240 audio->loops_available = FALSE;
241 audio->soundserver_pipe[0] = audio->soundserver_pipe[1] = 0;
242 audio->soundserver_pid = 0;
243 audio->device_fd = 0;
245 #if defined(TARGET_SDL)
248 audio->sound_available = TRUE;
249 audio->loops_available = TRUE;
251 #elif defined(PLATFORM_MSDOS)
252 if (MSDOSOpenAudio())
254 audio->sound_available = TRUE;
255 audio->loops_available = TRUE;
257 #elif defined(PLATFORM_UNIX)
258 UnixOpenAudio(audio);
261 return audio->sound_available;
264 inline void CloseAudio(struct AudioSystemInfo *audio)
266 #if defined(TARGET_SDL)
268 #elif defined(PLATFORM_MSDOS)
270 #elif defined(PLATFORM_UNIX)
271 UnixCloseAudio(audio);
274 audio->sound_available = FALSE;
275 audio->loops_available = FALSE;
279 /* ========================================================================= */
280 /* event functions */
281 /* ========================================================================= */
283 inline void InitEventFilter(EventFilter filter_function)
286 /* set event filter to filter out certain events */
287 SDL_SetEventFilter(filter_function);
291 inline boolean PendingEvent(void)
294 return (SDL_PollEvent(NULL) ? TRUE : FALSE);
296 return (XPending(display) ? TRUE : FALSE);
300 inline void NextEvent(Event *event)
303 SDL_WaitEvent(event);
305 XNextEvent(display, event);
309 inline Key GetEventKey(KeyEvent *event, boolean with_modifiers)
313 printf("unicode == '%d', sym == '%d', mod == '0x%04x'\n",
314 (int)event->keysym.unicode,
315 (int)event->keysym.sym,
316 (int)SDL_GetModState());
319 if (with_modifiers && event->keysym.unicode != 0)
320 return event->keysym.unicode;
322 return event->keysym.sym;
325 printf("with modifiers == '0x%04x', without modifiers == '0x%04x'\n",
326 (int)XLookupKeysym(event, event->state),
327 (int)XLookupKeysym(event, 0));
331 return XLookupKeysym(event, event->state);
333 return XLookupKeysym(event, 0);
337 inline boolean CheckCloseWindowEvent(ClientMessageEvent *event)
339 if (event->type != EVENT_CLIENTMESSAGE)
342 #if defined(TARGET_SDL)
343 return TRUE; /* the only possible message here is SDL_QUIT */
344 #elif defined(PLATFORM_UNIX)
345 if ((event->window == window) &&
346 (event->data.l[0] == XInternAtom(display, "WM_DELETE_WINDOW", FALSE)))
354 inline void dummy(void)