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 ClearRectangle(Bitmap bitmap, int x, int y, int width, int height)
74 #ifdef USE_SDL_LIBRARY
75 SDLFillRectangle(bitmap, x, y, width, height, 0x000000);
77 XFillRectangle(display, bitmap, gc, x, y, width, height);
81 inline void BlitBitmap(Bitmap src_bitmap, Bitmap dst_bitmap,
83 int width, int height,
86 #ifdef USE_SDL_LIBRARY
87 SDLCopyArea(src_bitmap, dst_bitmap,
88 src_x, src_y, width, height, dst_x, dst_y);
90 XCopyArea(display, src_bitmap, dst_bitmap, gc,
91 src_x, src_y, width, height, dst_x, dst_y);
95 #ifndef USE_SDL_LIBRARY
96 static GC last_clip_gc = 0; /* needed for XCopyArea() through clip mask */
99 inline void SetClipMask(GC clip_gc, Pixmap clip_pixmap)
101 #ifndef USE_SDL_LIBRARY
102 XSetClipMask(display, clip_gc, clip_pixmap);
103 last_clip_gc = clip_gc;
107 inline void SetClipOrigin(GC clip_gc, int clip_x, int clip_y)
109 #ifndef USE_SDL_LIBRARY
110 XSetClipOrigin(display, clip_gc, clip_x, clip_y);
111 last_clip_gc = clip_gc;
115 inline void BlitBitmapMasked(Bitmap src_bitmap, Bitmap dst_bitmap,
116 int src_x, int src_y,
117 int width, int height,
118 int dst_x, int dst_y)
120 #ifdef USE_SDL_LIBRARY
121 SDLCopyArea(src_bitmap, dst_bitmap,
122 src_x, src_y, width, height, dst_x, dst_y);
124 XCopyArea(display, src_bitmap, dst_bitmap, last_clip_gc,
125 src_x, src_y, width, height, dst_x, dst_y);
129 inline void DrawSimpleWhiteLine(Bitmap bitmap, int from_x, int from_y,
132 #ifdef USE_SDL_LIBRARY
133 SDLDrawSimpleLine(bitmap, from_x, from_y, to_x, to_y, 0xffffff);
135 XSetForeground(display, gc, WhitePixel(display, screen));
136 XDrawLine(display, bitmap, gc, from_x, from_y, to_x, to_y);
137 XSetForeground(display, gc, BlackPixel(display, screen));
141 /* execute all pending screen drawing operations */
142 inline void FlushDisplay(void)
144 #ifndef USE_SDL_LIBRARY
149 /* execute and wait for all pending screen drawing operations */
150 inline void SyncDisplay(void)
152 #ifndef USE_SDL_LIBRARY
153 XSync(display, FALSE);
157 inline void KeyboardAutoRepeatOn(void)
159 #ifdef USE_SDL_LIBRARY
160 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY / 2,
161 SDL_DEFAULT_REPEAT_INTERVAL / 2);
162 SDL_EnableUNICODE(1);
164 XAutoRepeatOn(display);
168 inline void KeyboardAutoRepeatOff(void)
170 #ifdef USE_SDL_LIBRARY
171 SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL);
172 SDL_EnableUNICODE(0);
174 XAutoRepeatOff(display);
178 inline boolean PointerInWindow(DrawWindow window)
180 #ifdef USE_SDL_LIBRARY
183 DrawWindow root, child;
188 /* if XQueryPointer() returns False, the pointer
189 is not on the same screen as the specified window */
190 return XQueryPointer(display, window, &root, &child, &root_x, &root_y,
191 &win_x, &win_y, &mask);
195 inline boolean PendingEvent(void)
197 #ifdef USE_SDL_LIBRARY
198 return (SDL_PollEvent(NULL) ? TRUE : FALSE);
200 return (XPending(display) ? TRUE : FALSE);
204 inline void NextEvent(Event *event)
206 #ifdef USE_SDL_LIBRARY
207 SDL_WaitEvent(event);
209 XNextEvent(display, event);
213 inline Key GetEventKey(KeyEvent *event, boolean with_modifiers)
215 #ifdef USE_SDL_LIBRARY
217 printf("unicode == '%d', sym == '%d', mod == '0x%04x'\n",
218 (int)event->keysym.unicode,
219 (int)event->keysym.sym,
220 (int)SDL_GetModState());
223 if (with_modifiers && event->keysym.unicode != 0)
224 return event->keysym.unicode;
226 return event->keysym.sym;
229 printf("with modifiers == '0x%04x', without modifiers == '0x%04x'\n",
230 (int)XLookupKeysym(event, event->state),
231 (int)XLookupKeysym(event, 0));
235 return XLookupKeysym(event, event->state);
237 return XLookupKeysym(event, 0);
241 inline boolean SetVideoMode(void)
243 #ifdef USE_SDL_LIBRARY
244 return SDLSetVideoMode(&backbuffer, &window);
246 boolean success = TRUE;
248 if (setup.fullscreen && fullscreen_available)
250 Error(ERR_WARN, "fullscreen not available in X11 version");
252 /* display error message only once */
253 fullscreen_available = FALSE;
262 inline void ChangeVideoModeIfNeeded(void)
264 #ifdef USE_SDL_LIBRARY
265 if ((setup.fullscreen && !fullscreen_enabled && fullscreen_available) ||
266 (!setup.fullscreen && fullscreen_enabled))
271 inline void dummy(void)
273 #ifdef USE_SDL_LIBRARY