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 inline void InitEventFilter(EventFilter filter_function)
20 #ifdef USE_SDL_LIBRARY
21 /* set event filter to filter out certain events */
22 SDL_SetEventFilter(filter_function);
26 inline void InitBufferedDisplay(DrawBuffer *backbuffer, DrawWindow *window)
28 #ifdef USE_SDL_LIBRARY
29 SDLInitBufferedDisplay(backbuffer, window);
31 X11InitBufferedDisplay(backbuffer, window);
35 inline int GetDisplayDepth(void)
37 #ifdef USE_SDL_LIBRARY
38 return SDL_GetVideoSurface()->format->BitsPerPixel;
40 return XDefaultDepth(display, screen);
44 inline Bitmap CreateBitmap(int width, int height, int depth)
46 int real_depth = (depth == DEFAULT_DEPTH ? GetDisplayDepth() : depth);
48 #ifdef USE_SDL_LIBRARY
49 SDL_Surface *surface_tmp, *surface_native;
51 if ((surface_tmp = SDL_CreateRGBSurface(SURFACE_FLAGS, width, height,
52 real_depth, 0, 0, 0, 0))
54 Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s", SDL_GetError());
56 if ((surface_native = SDL_DisplayFormat(surface_tmp)) == NULL)
57 Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s", SDL_GetError());
59 SDL_FreeSurface(surface_tmp);
61 return surface_native;
65 if (!(pixmap = XCreatePixmap(display, window, width, height, real_depth)))
66 Error(ERR_EXIT, "cannot create pixmap");
72 inline void FreeBitmap(Bitmap bitmap)
74 #ifdef USE_SDL_LIBRARY
75 SDL_FreeSurface(bitmap);
77 XFreePixmap(display, bitmap);
81 inline void ClearRectangle(Bitmap bitmap, int x, int y, int width, int height)
83 #ifdef USE_SDL_LIBRARY
84 SDLFillRectangle(bitmap, x, y, width, height, 0x000000);
86 XFillRectangle(display, bitmap, gc, x, y, width, height);
90 inline void BlitBitmap(Bitmap src_bitmap, Bitmap dst_bitmap,
92 int width, int height,
95 #ifdef USE_SDL_LIBRARY
96 SDLCopyArea(src_bitmap, dst_bitmap,
97 src_x, src_y, width, height, dst_x, dst_y);
99 XCopyArea(display, src_bitmap, dst_bitmap, gc,
100 src_x, src_y, width, height, dst_x, dst_y);
104 #ifndef USE_SDL_LIBRARY
105 static GC last_clip_gc = 0; /* needed for XCopyArea() through clip mask */
108 inline void SetClipMask(GC clip_gc, Pixmap clip_pixmap)
110 #ifndef USE_SDL_LIBRARY
111 XSetClipMask(display, clip_gc, clip_pixmap);
112 last_clip_gc = clip_gc;
116 inline void SetClipOrigin(GC clip_gc, int clip_x, int clip_y)
118 #ifndef USE_SDL_LIBRARY
119 XSetClipOrigin(display, clip_gc, clip_x, clip_y);
120 last_clip_gc = clip_gc;
124 inline void BlitBitmapMasked(Bitmap src_bitmap, Bitmap dst_bitmap,
125 int src_x, int src_y,
126 int width, int height,
127 int dst_x, int dst_y)
129 #ifdef USE_SDL_LIBRARY
130 SDLCopyArea(src_bitmap, dst_bitmap,
131 src_x, src_y, width, height, dst_x, dst_y);
133 XCopyArea(display, src_bitmap, dst_bitmap, last_clip_gc,
134 src_x, src_y, width, height, dst_x, dst_y);
138 inline void DrawSimpleWhiteLine(Bitmap bitmap, int from_x, int from_y,
141 #ifdef USE_SDL_LIBRARY
142 SDLDrawSimpleLine(bitmap, from_x, from_y, to_x, to_y, 0xffffff);
144 XSetForeground(display, gc, WhitePixel(display, screen));
145 XDrawLine(display, bitmap, gc, from_x, from_y, to_x, to_y);
146 XSetForeground(display, gc, BlackPixel(display, screen));
150 /* execute all pending screen drawing operations */
151 inline void FlushDisplay(void)
153 #ifndef USE_SDL_LIBRARY
158 /* execute and wait for all pending screen drawing operations */
159 inline void SyncDisplay(void)
161 #ifndef USE_SDL_LIBRARY
162 XSync(display, FALSE);
166 inline void KeyboardAutoRepeatOn(void)
168 #ifdef USE_SDL_LIBRARY
169 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY / 2,
170 SDL_DEFAULT_REPEAT_INTERVAL / 2);
171 SDL_EnableUNICODE(1);
173 XAutoRepeatOn(display);
177 inline void KeyboardAutoRepeatOff(void)
179 #ifdef USE_SDL_LIBRARY
180 SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL);
181 SDL_EnableUNICODE(0);
183 XAutoRepeatOff(display);
187 inline boolean PointerInWindow(DrawWindow window)
189 #ifdef USE_SDL_LIBRARY
192 DrawWindow root, child;
197 /* if XQueryPointer() returns False, the pointer
198 is not on the same screen as the specified window */
199 return XQueryPointer(display, window, &root, &child, &root_x, &root_y,
200 &win_x, &win_y, &mask);
204 inline boolean PendingEvent(void)
206 #ifdef USE_SDL_LIBRARY
207 return (SDL_PollEvent(NULL) ? TRUE : FALSE);
209 return (XPending(display) ? TRUE : FALSE);
213 inline void NextEvent(Event *event)
215 #ifdef USE_SDL_LIBRARY
216 SDL_WaitEvent(event);
218 XNextEvent(display, event);
222 inline Key GetEventKey(KeyEvent *event, boolean with_modifiers)
224 #ifdef USE_SDL_LIBRARY
226 printf("unicode == '%d', sym == '%d', mod == '0x%04x'\n",
227 (int)event->keysym.unicode,
228 (int)event->keysym.sym,
229 (int)SDL_GetModState());
232 if (with_modifiers && event->keysym.unicode != 0)
233 return event->keysym.unicode;
235 return event->keysym.sym;
238 printf("with modifiers == '0x%04x', without modifiers == '0x%04x'\n",
239 (int)XLookupKeysym(event, event->state),
240 (int)XLookupKeysym(event, 0));
244 return XLookupKeysym(event, event->state);
246 return XLookupKeysym(event, 0);
250 inline boolean SetVideoMode(void)
252 #ifdef USE_SDL_LIBRARY
253 return SDLSetVideoMode(&backbuffer);
255 boolean success = TRUE;
257 if (setup.fullscreen && fullscreen_available)
259 Error(ERR_WARN, "fullscreen not available in X11 version");
261 /* display error message only once */
262 fullscreen_available = FALSE;
271 inline void ChangeVideoModeIfNeeded(void)
273 #ifdef USE_SDL_LIBRARY
274 if ((setup.fullscreen && !fullscreen_enabled && fullscreen_available) ||
275 (!setup.fullscreen && fullscreen_enabled))
280 inline void dummy(void)
282 #ifdef USE_SDL_LIBRARY