6b85ccb38c219d7fe790031bdbf817a355c179d6
[rocksndiamonds.git] / src / system.c
1 /***********************************************************
2 *  Rocks'n'Diamonds -- McDuffin Strikes Back!              *
3 *----------------------------------------------------------*
4 *  ©1995 Artsoft Development                               *
5 *        Holger Schemel                                    *
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 *----------------------------------------------------------*
12 *  system.c                                                *
13 ***********************************************************/
14
15 #include "main.h"
16
17 inline void ClearRectangle(Bitmap bitmap, int x, int y, int width, int height)
18 {
19 #ifdef USE_SDL_LIBRARY
20   SDLFillRectangle(bitmap, x, y, width, height, 0x000000);
21 #else
22   XFillRectangle(display, bitmap, gc, x, y, width, height);
23 #endif
24 }
25
26 inline void BlitBitmap(Bitmap src_bitmap, Bitmap dst_bitmap,
27                        int src_x, int src_y,
28                        int width, int height,
29                        int dst_x, int dst_y)
30 {
31 #ifdef USE_SDL_LIBRARY
32   SDLCopyArea(src_bitmap, dst_bitmap,
33               src_x, src_y, width, height, dst_x, dst_y);
34 #else
35   XCopyArea(display, src_bitmap, dst_bitmap, gc,
36             src_x, src_y, width, height, dst_x, dst_y);
37 #endif
38 }
39
40 #ifndef USE_SDL_LIBRARY
41 static GC last_clip_gc = 0;     /* needed for XCopyArea() through clip mask */
42 #endif
43
44 inline void SetClipMask(GC clip_gc, Pixmap clip_pixmap)
45 {
46 #ifndef USE_SDL_LIBRARY
47   XSetClipMask(display, clip_gc, clip_pixmap);
48   last_clip_gc = clip_gc;
49 #endif
50 }
51
52 inline void SetClipOrigin(GC clip_gc, int clip_x, int clip_y)
53 {
54 #ifndef USE_SDL_LIBRARY
55   XSetClipOrigin(display, clip_gc, clip_x, clip_y);
56   last_clip_gc = clip_gc;
57 #endif
58 }
59
60 inline void BlitBitmapMasked(Bitmap src_bitmap, Bitmap dst_bitmap,
61                              int src_x, int src_y,
62                              int width, int height,
63                              int dst_x, int dst_y)
64 {
65 #ifdef USE_SDL_LIBRARY
66   SDLCopyArea(src_bitmap, dst_bitmap,
67               src_x, src_y, width, height, dst_x, dst_y);
68 #else
69   XCopyArea(display, src_bitmap, dst_bitmap, last_clip_gc,
70             src_x, src_y, width, height, dst_x, dst_y);
71 #endif
72 }
73
74 inline void DrawSimpleWhiteLine(Bitmap bitmap, int from_x, int from_y,
75                                 int to_x, int to_y)
76 {
77 #ifdef USE_SDL_LIBRARY
78   SDLDrawSimpleLine(bitmap, from_x, from_y, to_x, to_y, 0xffffff);
79 #else
80   XSetForeground(display, gc, WhitePixel(display, screen));
81   XDrawLine(display, bitmap, gc, from_x, from_y, to_x, to_y);
82   XSetForeground(display, gc, BlackPixel(display, screen));
83 #endif
84 }
85
86 /* execute all pending screen drawing operations */
87 inline void FlushDisplay()
88 {
89 #ifndef USE_SDL_LIBRARY
90   XFlush(display);
91 #endif
92 }
93
94 /* execute and wait for all pending screen drawing operations */
95 inline void SyncDisplay()
96 {
97 #ifndef USE_SDL_LIBRARY
98   XSync(display, FALSE);
99 #endif
100 }
101
102 inline void KeyboardAutoRepeatOn()
103 {
104 #ifdef USE_SDL_LIBRARY
105   SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY / 2,
106                       SDL_DEFAULT_REPEAT_INTERVAL / 2);
107   SDL_EnableUNICODE(1);
108 #else
109   XAutoRepeatOn(display);
110 #endif
111 }
112
113 inline void KeyboardAutoRepeatOff()
114 {
115 #ifdef USE_SDL_LIBRARY
116   SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL);
117   SDL_EnableUNICODE(0);
118 #else
119   XAutoRepeatOff(display);
120 #endif
121 }
122
123 inline boolean PointerInWindow(DrawWindow window)
124 {
125 #ifdef USE_SDL_LIBRARY
126   return TRUE;
127 #else
128   DrawWindow root, child;
129   int root_x, root_y;
130   unsigned int mask;
131   int win_x, win_y;
132
133   /* if XQueryPointer() returns False, the pointer
134      is not on the same screen as the specified window */
135   return XQueryPointer(display, window, &root, &child, &root_x, &root_y,
136                        &win_x, &win_y, &mask);
137 #endif
138 }
139
140 inline boolean PendingEvent()
141 {
142 #ifdef USE_SDL_LIBRARY
143   return (SDL_PollEvent(NULL) ? TRUE : FALSE);
144 #else
145   return (XPending(display) ? TRUE : FALSE);
146 #endif
147 }
148
149 inline void NextEvent(Event *event)
150 {
151 #ifdef USE_SDL_LIBRARY
152   SDL_WaitEvent(event);
153 #else
154   XNextEvent(display, event);
155 #endif
156 }
157
158 inline Key GetEventKey(KeyEvent *event, boolean with_modifiers)
159 {
160 #ifdef USE_SDL_LIBRARY
161   if (with_modifiers && event->keysym.unicode != 0)
162     return event->keysym.unicode;
163   else
164     return event->keysym.sym;
165 #else
166   if (with_modifiers)
167     return XLookupKeysym(event, event->state);
168   else
169     return XLookupKeysym(event, 0);
170 #endif
171 }
172
173 inline void dummy()
174 {
175 #ifdef USE_SDL_LIBRARY
176 #else
177 #endif
178 }