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 ***********************************************************/
19 /* ========================================================================= */
21 /* ========================================================================= */
23 inline void InitBufferedDisplay(DrawBuffer *backbuffer, DrawWindow *window)
26 SDLInitBufferedDisplay(backbuffer, window);
28 X11InitBufferedDisplay(backbuffer, window);
32 inline int GetDisplayDepth(void)
35 return SDL_GetVideoSurface()->format->BitsPerPixel;
37 return XDefaultDepth(display, screen);
41 inline Bitmap CreateBitmap(int width, int height, int depth)
43 int real_depth = (depth == DEFAULT_DEPTH ? GetDisplayDepth() : depth);
46 SDL_Surface *surface_tmp, *surface_native;
48 if ((surface_tmp = SDL_CreateRGBSurface(SURFACE_FLAGS, width, height,
49 real_depth, 0, 0, 0, 0))
51 Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s", SDL_GetError());
53 if ((surface_native = SDL_DisplayFormat(surface_tmp)) == NULL)
54 Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s", SDL_GetError());
56 SDL_FreeSurface(surface_tmp);
58 return surface_native;
62 if (!(pixmap = XCreatePixmap(display, window, width, height, real_depth)))
63 Error(ERR_EXIT, "cannot create pixmap");
69 inline void FreeBitmap(Bitmap bitmap)
72 SDL_FreeSurface(bitmap);
74 XFreePixmap(display, bitmap);
78 inline void ClearRectangle(Bitmap bitmap, int x, int y, int width, int height)
81 SDLFillRectangle(bitmap, x, y, width, height, 0x000000);
83 XFillRectangle(display, bitmap, gc, x, y, width, height);
87 inline void BlitBitmap(Bitmap src_bitmap, Bitmap dst_bitmap,
89 int width, int height,
93 SDLCopyArea(src_bitmap, dst_bitmap,
94 src_x, src_y, width, height, dst_x, dst_y);
96 XCopyArea(display, src_bitmap, dst_bitmap, gc,
97 src_x, src_y, width, height, dst_x, dst_y);
102 static GC last_clip_gc = 0; /* needed for XCopyArea() through clip mask */
105 inline void SetClipMask(GC clip_gc, Pixmap clip_pixmap)
108 XSetClipMask(display, clip_gc, clip_pixmap);
109 last_clip_gc = clip_gc;
113 inline void SetClipOrigin(GC clip_gc, int clip_x, int clip_y)
116 XSetClipOrigin(display, clip_gc, clip_x, clip_y);
117 last_clip_gc = clip_gc;
121 inline void BlitBitmapMasked(Bitmap src_bitmap, Bitmap dst_bitmap,
122 int src_x, int src_y,
123 int width, int height,
124 int dst_x, int dst_y)
127 SDLCopyArea(src_bitmap, dst_bitmap,
128 src_x, src_y, width, height, dst_x, dst_y);
130 XCopyArea(display, src_bitmap, dst_bitmap, last_clip_gc,
131 src_x, src_y, width, height, dst_x, dst_y);
135 inline void DrawSimpleWhiteLine(Bitmap bitmap, int from_x, int from_y,
139 SDLDrawSimpleLine(bitmap, from_x, from_y, to_x, to_y, 0xffffff);
141 XSetForeground(display, gc, WhitePixel(display, screen));
142 XDrawLine(display, bitmap, gc, from_x, from_y, to_x, to_y);
143 XSetForeground(display, gc, BlackPixel(display, screen));
147 /* execute all pending screen drawing operations */
148 inline void FlushDisplay(void)
155 /* execute and wait for all pending screen drawing operations */
156 inline void SyncDisplay(void)
159 XSync(display, FALSE);
163 inline void KeyboardAutoRepeatOn(void)
166 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY / 2,
167 SDL_DEFAULT_REPEAT_INTERVAL / 2);
168 SDL_EnableUNICODE(1);
170 XAutoRepeatOn(display);
174 inline void KeyboardAutoRepeatOff(void)
177 SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL);
178 SDL_EnableUNICODE(0);
180 XAutoRepeatOff(display);
184 inline boolean PointerInWindow(DrawWindow window)
189 DrawWindow root, child;
194 /* if XQueryPointer() returns False, the pointer
195 is not on the same screen as the specified window */
196 return XQueryPointer(display, window, &root, &child, &root_x, &root_y,
197 &win_x, &win_y, &mask);
201 inline boolean SetVideoMode(void)
204 return SDLSetVideoMode(&backbuffer);
206 boolean success = TRUE;
208 if (setup.fullscreen && fullscreen_available)
210 Error(ERR_WARN, "fullscreen not available in X11 version");
212 /* display error message only once */
213 fullscreen_available = FALSE;
222 inline void ChangeVideoModeIfNeeded(void)
225 if ((setup.fullscreen && !fullscreen_enabled && fullscreen_available) ||
226 (!setup.fullscreen && fullscreen_enabled))
232 /* ========================================================================= */
233 /* audio functions */
234 /* ========================================================================= */
236 inline boolean InitAudio(void)
239 return SDLInitAudio();
246 /* ========================================================================= */
247 /* event functions */
248 /* ========================================================================= */
250 inline void InitEventFilter(EventFilter filter_function)
253 /* set event filter to filter out certain events */
254 SDL_SetEventFilter(filter_function);
258 inline boolean PendingEvent(void)
261 return (SDL_PollEvent(NULL) ? TRUE : FALSE);
263 return (XPending(display) ? TRUE : FALSE);
267 inline void NextEvent(Event *event)
270 SDL_WaitEvent(event);
272 XNextEvent(display, event);
276 inline Key GetEventKey(KeyEvent *event, boolean with_modifiers)
280 printf("unicode == '%d', sym == '%d', mod == '0x%04x'\n",
281 (int)event->keysym.unicode,
282 (int)event->keysym.sym,
283 (int)SDL_GetModState());
286 if (with_modifiers && event->keysym.unicode != 0)
287 return event->keysym.unicode;
289 return event->keysym.sym;
292 printf("with modifiers == '0x%04x', without modifiers == '0x%04x'\n",
293 (int)XLookupKeysym(event, event->state),
294 (int)XLookupKeysym(event, 0));
298 return XLookupKeysym(event, event->state);
300 return XLookupKeysym(event, 0);
304 inline boolean CheckCloseWindowEvent(ClientMessageEvent *event)
306 if (event->type != EVENT_CLIENTMESSAGE)
309 #if defined(TARGET_SDL)
310 return TRUE; /* the only possible message here is SDL_QUIT */
311 #elif defined(PLATFORM_UNIX)
312 if ((event->window == window) &&
313 (event->data.l[0] == XInternAtom(display, "WM_DELETE_WINDOW", FALSE)))
321 inline void dummy(void)