71b248e805e6d5c4deea6805460420bf08fb6c79
[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 #ifdef  USE_SDL_LIBRARY
18 #include "sdl.h"
19 #endif
20
21 inline void ClearRectangle(Bitmap bitmap, int x, int y, int width, int height)
22 {
23 #ifdef USE_SDL_LIBRARY
24   SDLFillRectangle(bitmap, x, y, width, height, 0x000000);
25 #else
26   XFillRectangle(display, bitmap, gc, x, y, width, height);
27 #endif
28 }
29
30 inline void BlitBitmap(Bitmap src_bitmap, Bitmap dst_bitmap,
31                        int src_x, int src_y,
32                        int width, int height,
33                        int dst_x, int dst_y)
34 {
35 #ifdef USE_SDL_LIBRARY
36   SDLCopyArea(src_bitmap, dst_bitmap,
37               src_x, src_y, width, height, dst_x, dst_y);
38 #else
39   XCopyArea(display, src_bitmap, dst_bitmap, gc,
40             src_x, src_y, width, height, dst_x, dst_y);
41 #endif
42 }
43
44 #ifndef USE_SDL_LIBRARY
45 static GC last_clip_gc = 0;     /* needed for XCopyArea() through clip mask */
46 #endif
47
48 inline void SetClipMask(GC clip_gc, Pixmap clip_pixmap)
49 {
50 #ifndef USE_SDL_LIBRARY
51   XSetClipMask(display, clip_gc, clip_pixmap);
52   last_clip_gc = clip_gc;
53 #endif
54 }
55
56 inline void SetClipOrigin(GC clip_gc, int clip_x, int clip_y)
57 {
58 #ifndef USE_SDL_LIBRARY
59   XSetClipOrigin(display, clip_gc, clip_x, clip_y);
60   last_clip_gc = clip_gc;
61 #endif
62 }
63
64 inline void BlitBitmapMasked(Bitmap src_bitmap, Bitmap dst_bitmap,
65                              int src_x, int src_y,
66                              int width, int height,
67                              int dst_x, int dst_y)
68 {
69 #ifdef USE_SDL_LIBRARY
70   SDLCopyArea(src_bitmap, dst_bitmap,
71               src_x, src_y, width, height, dst_x, dst_y);
72 #else
73   XCopyArea(display, src_bitmap, dst_bitmap, last_clip_gc,
74             src_x, src_y, width, height, dst_x, dst_y);
75 #endif
76 }
77
78 inline void DrawSimpleWhiteLine(Bitmap bitmap, int from_x, int from_y,
79                                 int to_x, int to_y)
80 {
81 #ifdef USE_SDL_LIBRARY
82   SDLDrawSimpleLine(bitmap, from_x, from_y, to_x, to_y, 0xffffff);
83 #else
84   XSetForeground(display, gc, WhitePixel(display, screen));
85   XDrawLine(display, bitmap, gc, from_x, from_y, to_x, to_y);
86   XSetForeground(display, gc, BlackPixel(display, screen));
87 #endif
88 }
89
90 /* execute all pending screen drawing operations */
91 inline void FlushDisplay()
92 {
93 #ifndef USE_SDL_LIBRARY
94   XFlush(display);
95 #endif
96 }
97
98 /* execute and wait for all pending screen drawing operations */
99 inline void SyncDisplay()
100 {
101 #ifndef USE_SDL_LIBRARY
102   XSync(display, FALSE);
103 #endif
104 }
105
106 inline void KeyboardAutoRepeatOn()
107 {
108 #ifndef USE_SDL_LIBRARY
109   XAutoRepeatOn(display);
110 #endif
111 }
112
113 inline void KeyboardAutoRepeatOff()
114 {
115 #ifndef USE_SDL_LIBRARY
116   XAutoRepeatOff(display);
117 #endif
118 }
119
120 inline boolean QueryPointer(DrawWindow window, int *win_x, int *win_y)
121 {
122 #ifdef USE_SDL_LIBRARY
123   SDL_GetMouseState(win_x, win_y);
124   return TRUE;
125 #else
126   DrawWindow root, child;
127   int root_x, root_y;
128   unsigned int mask;
129
130   /* if XQueryPointer() returns False, the pointer
131      is not on the same screen as the specified window */
132   return XQueryPointer(display, window, &root, &child, &root_x, &root_y,
133                        win_x, win_y, &mask);
134 #endif
135 }
136
137 inline boolean PendingEvent()
138 {
139 #ifdef USE_SDL_LIBRARY
140   return (SDL_PollEvent(NULL) ? TRUE : FALSE);
141 #else
142   return (XPending(display) ? TRUE : FALSE);
143 #endif
144 }
145
146 inline void NextEvent(Event *event)
147 {
148 #ifdef USE_SDL_LIBRARY
149   SDL_WaitEvent(event);
150 #else
151   XNextEvent(display, event);
152 #endif
153 }
154
155 inline void dummy()
156 {
157 #ifdef USE_SDL_LIBRARY
158 #else
159 #endif
160 }