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 inline void ClearRectangle(Bitmap bitmap, int x, int y, int width, int height)
21 #ifdef USE_SDL_LIBRARY
22 SDLFillRectangle(bitmap, x, y, width, height, 0x000000);
24 XFillRectangle(display, bitmap, gc, x, y, width, height);
28 inline void BlitBitmap(Bitmap src_bitmap, Bitmap dst_bitmap,
30 int width, int height,
33 #ifdef USE_SDL_LIBRARY
34 SDLCopyArea(src_bitmap, dst_bitmap,
35 src_x, src_y, width, height, dst_x, dst_y);
37 XCopyArea(display, src_bitmap, dst_bitmap, gc,
38 src_x, src_y, width, height, dst_x, dst_y);
42 #ifndef USE_SDL_LIBRARY
43 static GC last_clip_gc = 0; /* needed for XCopyArea() through clip mask */
46 inline void SetClipMask(GC clip_gc, Pixmap clip_pixmap)
48 #ifndef USE_SDL_LIBRARY
49 XSetClipMask(display, clip_gc, clip_pixmap);
50 last_clip_gc = clip_gc;
54 inline void SetClipOrigin(GC clip_gc, int clip_x, int clip_y)
56 #ifndef USE_SDL_LIBRARY
57 XSetClipOrigin(display, clip_gc, clip_x, clip_y);
58 last_clip_gc = clip_gc;
62 inline void BlitBitmapMasked(Bitmap src_bitmap, Bitmap dst_bitmap,
64 int width, int height,
67 #ifdef USE_SDL_LIBRARY
68 SDLCopyArea(src_bitmap, dst_bitmap,
69 src_x, src_y, width, height, dst_x, dst_y);
71 XCopyArea(display, src_bitmap, dst_bitmap, last_clip_gc,
72 src_x, src_y, width, height, dst_x, dst_y);
76 inline void DrawSimpleWhiteLine(Bitmap bitmap, int from_x, int from_y,
79 #ifdef USE_SDL_LIBRARY
80 SDLDrawSimpleLine(bitmap, from_x, from_y, to_x, to_y, 0xffffff);
82 XSetForeground(display, gc, WhitePixel(display, screen));
83 XDrawLine(display, bitmap, gc, from_x, from_y, to_x, to_y);
84 XSetForeground(display, gc, BlackPixel(display, screen));
88 /* execute all pending screen drawing operations */
89 inline void FlushDisplay(void)
91 #ifndef USE_SDL_LIBRARY
96 /* execute and wait for all pending screen drawing operations */
97 inline void SyncDisplay(void)
99 #ifndef USE_SDL_LIBRARY
100 XSync(display, FALSE);
104 inline void KeyboardAutoRepeatOn(void)
106 #ifdef USE_SDL_LIBRARY
107 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY / 2,
108 SDL_DEFAULT_REPEAT_INTERVAL / 2);
109 SDL_EnableUNICODE(1);
111 XAutoRepeatOn(display);
115 inline void KeyboardAutoRepeatOff(void)
117 #ifdef USE_SDL_LIBRARY
118 SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL);
119 SDL_EnableUNICODE(0);
121 XAutoRepeatOff(display);
125 inline boolean PointerInWindow(DrawWindow window)
127 #ifdef USE_SDL_LIBRARY
130 DrawWindow root, child;
135 /* if XQueryPointer() returns False, the pointer
136 is not on the same screen as the specified window */
137 return XQueryPointer(display, window, &root, &child, &root_x, &root_y,
138 &win_x, &win_y, &mask);
142 inline boolean PendingEvent(void)
144 #ifdef USE_SDL_LIBRARY
145 return (SDL_PollEvent(NULL) ? TRUE : FALSE);
147 return (XPending(display) ? TRUE : FALSE);
151 inline void NextEvent(Event *event)
153 #ifdef USE_SDL_LIBRARY
154 SDL_WaitEvent(event);
156 XNextEvent(display, event);
160 inline Key GetEventKey(KeyEvent *event, boolean with_modifiers)
162 #ifdef USE_SDL_LIBRARY
164 printf("unicode == '%d', sym == '%d', mod == '0x%04x'\n",
165 (int)event->keysym.unicode,
166 (int)event->keysym.sym,
167 (int)SDL_GetModState());
170 if (with_modifiers && event->keysym.unicode != 0)
171 return event->keysym.unicode;
173 return event->keysym.sym;
176 printf("with modifiers == '0x%04x', without modifiers == '0x%04x'\n",
177 (int)XLookupKeysym(event, event->state),
178 (int)XLookupKeysym(event, 0));
182 return XLookupKeysym(event, event->state);
184 return XLookupKeysym(event, 0);
188 inline boolean SetVideoMode(void)
190 boolean success = TRUE;
192 #ifdef USE_SDL_LIBRARY
193 if (setup.fullscreen && !fullscreen_enabled && fullscreen_available)
195 /* switch display to fullscreen mode, if available */
196 DrawWindow window_old = window;
197 DrawWindow window_new;
199 if ((window_new = SDL_SetVideoMode(WIN_XSIZE, WIN_YSIZE, WIN_SDL_DEPTH,
200 SDL_HWSURFACE|SDL_FULLSCREEN))
203 /* switching display to fullscreen mode failed */
204 Error(ERR_WARN, "SDL_SetVideoMode() failed: %s", SDL_GetError());
206 /* do not try it again */
207 fullscreen_available = FALSE;
213 SDL_FreeSurface(window_old);
216 fullscreen_enabled = TRUE;
221 if ((!setup.fullscreen && fullscreen_enabled) || !window)
223 /* switch display to window mode */
224 DrawWindow window_old = window;
225 DrawWindow window_new;
227 if ((window_new = SDL_SetVideoMode(WIN_XSIZE, WIN_YSIZE, WIN_SDL_DEPTH,
231 /* switching display to window mode failed -- should not happen */
232 Error(ERR_WARN, "SDL_SetVideoMode() failed: %s", SDL_GetError());
239 SDL_FreeSurface(window_old);
242 fullscreen_enabled = FALSE;
247 if (setup.fullscreen && fullscreen_available)
249 Error(ERR_WARN, "fullscreen not available in X11 version");
251 /* display error message only once */
252 fullscreen_available = FALSE;
261 inline void ChangeVideoModeIfNeeded(void)
263 #ifdef USE_SDL_LIBRARY
264 if ((setup.fullscreen && !fullscreen_enabled && fullscreen_available) ||
265 (!setup.fullscreen && fullscreen_enabled))
267 SetDrawtoField(DRAW_BACKBUFFER);
271 inline void dummy(void)
273 #ifdef USE_SDL_LIBRARY