1 /* ______ ___ ___
2 * /\ _ \ /\_ \ /\_ \
3 * \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___
4 * \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\
5 * \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \
6 * \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
7 * \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
8 * /\____/
9 * \_/__/
10 *
11 * Magical wrappers for functions in vtable.
12 *
13 * By Michael Bukin.
14 *
15 * See readme.txt for copyright information.
16 */
17
18 #include "allegro.h"
19 #include "allegro/internal/aintern.h"
20 #include "allegro/platform/aintunix.h"
21 #include "xwin.h"
22
23 #ifdef ALLEGRO_MULTITHREADED
24 #include <pthread.h>
25 #endif
26
27
28 static GFX_VTABLE _xwin_vtable;
29
30
31 static void _xwin_putpixel(BITMAP *dst, int dx, int dy, int color);
32 static void _xwin_vline(BITMAP *dst, int dx, int dy1, int dy2, int color);
33 static void _xwin_hline(BITMAP *dst, int dx1, int dy, int dx2, int color);
34 static void _xwin_rectfill(BITMAP *dst, int dx1, int dy1, int dx2, int dy2, int color);
35 static void _xwin_draw_sprite(BITMAP *dst, BITMAP *src, int dx, int dy);
36 static void _xwin_draw_sprite_ex(BITMAP *dst, BITMAP *src, int dx, int dy, int mode, int flip);
37 static void _xwin_draw_256_sprite(BITMAP *dst, BITMAP *src, int dx, int dy);
38 static void _xwin_draw_sprite_v_flip(BITMAP *dst, BITMAP *src, int dx, int dy);
39 static void _xwin_draw_sprite_h_flip(BITMAP *dst, BITMAP *src, int dx, int dy);
40 static void _xwin_draw_sprite_vh_flip(BITMAP *dst, BITMAP *src, int dx, int dy);
41 static void _xwin_draw_trans_sprite(BITMAP *dst, BITMAP *src, int dx, int dy);
42 static void _xwin_draw_trans_rgba_sprite(BITMAP *dst, BITMAP *src, int dx, int dy);
43 static void _xwin_draw_lit_sprite(BITMAP *dst, BITMAP *src, int dx, int dy, int color);
44 static void _xwin_draw_rle_sprite(BITMAP *dst, AL_CONST RLE_SPRITE *src, int dx, int dy);
45 static void _xwin_draw_trans_rle_sprite(BITMAP *dst, AL_CONST RLE_SPRITE *src, int dx, int dy);
46 static void _xwin_draw_trans_rgba_rle_sprite(BITMAP *dst, AL_CONST RLE_SPRITE *src, int dx, int dy);
47 static void _xwin_draw_lit_rle_sprite(BITMAP *dst, AL_CONST RLE_SPRITE *src, int dx, int dy, int color);
48 static void _xwin_draw_character(BITMAP *dst, BITMAP *src, int dx, int dy, int color, int bg);
49 static void _xwin_draw_glyph(BITMAP *dst, AL_CONST FONT_GLYPH *src, int dx, int dy, int color, int bg);
50 static void _xwin_blit_anywhere(BITMAP *src, BITMAP *dst, int sx, int sy,
51 int dx, int dy, int w, int h);
52 static void _xwin_blit_backward(BITMAP *src, BITMAP *dst, int sx, int sy,
53 int dx, int dy, int w, int h);
54 static void _xwin_masked_blit(BITMAP *src, BITMAP *dst, int sx, int sy,
55 int dx, int dy, int w, int h);
56 static void _xwin_clear_to_color(BITMAP *dst, int color);
57
58
59
60 /* _xwin_drawing_mode:
61 * Set the GC's drawing mode
62 */
_xwin_drawing_mode(void)63 void _xwin_drawing_mode(void)
64 {
65 /* Only SOLID can be handled directly by X11. */
66 if(_xwin.matching_formats && _drawing_mode == DRAW_MODE_SOLID)
67 _xwin.drawing_mode_ok = TRUE;
68 else
69 _xwin.drawing_mode_ok = FALSE;
70 }
71
72
73
74 /* Direct X11 version of the function. */
_xwin_direct_putpixel(BITMAP * dst,int dx,int dy,int color)75 static inline int _xwin_direct_putpixel(BITMAP *dst, int dx, int dy, int color)
76 {
77 if (!_xwin.drawing_mode_ok)
78 return 0;
79
80 dx += dst->x_ofs - _xwin.scroll_x;
81 dy += dst->y_ofs - _xwin.scroll_y;
82
83 if((dx >= _xwin.screen_width) || (dx < 0) ||
84 (dy >= _xwin.screen_height) || (dy < 0))
85 return 1;
86
87 XLOCK();
88 XSetForeground(_xwin.display, _xwin.gc, color);
89 XDrawPoint(_xwin.display, _xwin.window, _xwin.gc, dx, dy);
90 XUNLOCK();
91
92 return 1;
93 }
94
95
96
97 /* Direct X11 version of the function. */
_xwin_direct_hline(BITMAP * dst,int dx1,int dy,int dx2,int color)98 static inline int _xwin_direct_hline(BITMAP *dst, int dx1, int dy, int dx2, int color)
99 {
100 if (!_xwin.drawing_mode_ok)
101 return 0;
102
103 dx1 += dst->x_ofs - _xwin.scroll_x;
104 dx2 += dst->x_ofs - _xwin.scroll_x;
105 dy += dst->y_ofs - _xwin.scroll_y;
106
107 if (dx1 < 0)
108 dx1 = 0;
109 if (dx2 >= _xwin.screen_width)
110 dx2 = _xwin.screen_width - 1;
111 if ((dx1 > dx2) || (dy < 0) || (dy >= _xwin.screen_height))
112 return 1;
113
114 XLOCK();
115 XSetForeground(_xwin.display, _xwin.gc, color);
116 XDrawLine(_xwin.display, _xwin.window, _xwin.gc, dx1, dy, dx2, dy);
117 XUNLOCK();
118
119 return 1;
120 }
121
122
123
124 /* Direct X11 version of the function. */
_xwin_direct_vline(BITMAP * dst,int dx,int dy1,int dy2,int color)125 static inline int _xwin_direct_vline(BITMAP *dst, int dx, int dy1, int dy2, int color)
126 {
127 if (!_xwin.drawing_mode_ok)
128 return 0;
129
130 dx += dst->x_ofs - _xwin.scroll_x;
131 dy1 += dst->y_ofs - _xwin.scroll_y;
132 dy2 += dst->y_ofs - _xwin.scroll_y;
133
134 if (dy1 < 0)
135 dy1 = 0;
136 if (dy2 >= _xwin.screen_height)
137 dy2 = _xwin.screen_height - 1;
138 if ((dy1 > dy2) || (dx < 0) || (dx >= _xwin.screen_width))
139 return 1;
140
141 XLOCK();
142 XSetForeground(_xwin.display, _xwin.gc, color);
143 XDrawLine(_xwin.display, _xwin.window, _xwin.gc, dx, dy1, dx, dy2);
144 XUNLOCK();
145
146 return 1;
147 }
148
149
150
151 /* Direct X11 version of the function. */
_xwin_direct_rectfill(BITMAP * dst,int dx1,int dy1,int dx2,int dy2,int color)152 static inline int _xwin_direct_rectfill(BITMAP *dst, int dx1, int dy1, int dx2, int dy2, int color)
153 {
154 if (!_xwin.drawing_mode_ok)
155 return 0;
156
157 dx1 += dst->x_ofs - _xwin.scroll_x;
158 dx2 += dst->x_ofs - _xwin.scroll_x;
159 dy1 += dst->y_ofs - _xwin.scroll_y;
160 dy2 += dst->y_ofs - _xwin.scroll_y;
161
162 if (dx1 < 0)
163 dx1 = 0;
164 if (dx2 >= _xwin.screen_width)
165 dx2 = _xwin.screen_width - 1;
166 if (dx1 > dx2)
167 return 1;
168
169 if (dy1 < 0)
170 dy1 = 0;
171 if (dy2 >= _xwin.screen_height)
172 dy2 = _xwin.screen_height - 1;
173 if (dy1 > dy2)
174 return 1;
175
176 XLOCK();
177 XSetForeground(_xwin.display, _xwin.gc, color);
178 XFillRectangle(_xwin.display, _xwin.window, _xwin.gc, dx1, dy1, dx2-dx1+1, dy2-dy1+1);
179 XUNLOCK();
180
181 return 1;
182 }
183
184
185
186 /* Direct X11 version of the function. */
_xwin_direct_clear_to_color(BITMAP * dst,int color)187 static inline int _xwin_direct_clear_to_color(BITMAP *dst, int color)
188 {
189 int dx1, dy1, dx2, dy2;
190 if (!_xwin.drawing_mode_ok)
191 return 0;
192
193 dx1 = dst->cl + dst->x_ofs - _xwin.scroll_x;
194 dx2 = dst->cr + dst->x_ofs - 1 - _xwin.scroll_x;
195 dy1 = dst->ct + dst->y_ofs - _xwin.scroll_y;
196 dy2 = dst->cb + dst->y_ofs - 1 - _xwin.scroll_y;
197
198 if (dx1 < 0)
199 dx1 = 0;
200 if (dx2 >= _xwin.screen_width)
201 dx2 = _xwin.screen_width - 1;
202 if (dx1 > dx2)
203 return 1;
204
205 if (dy1 < 0)
206 dy1 = 0;
207 if (dy2 >= _xwin.screen_height)
208 dy2 = _xwin.screen_height - 1;
209 if (dy1 > dy2)
210 return 1;
211
212 XLOCK();
213 XSetForeground(_xwin.display, _xwin.gc, color);
214 XFillRectangle(_xwin.display, _xwin.window, _xwin.gc, dx1, dy1, dx2-dx1+1, dy2-dy1+1);
215 XUNLOCK();
216
217 return 1;
218 }
219
220
221
222 /* _xwin_replace_vtable:
223 * Replace entries in vtable with magical wrappers.
224 */
_xwin_replace_vtable(struct GFX_VTABLE * vtable)225 void _xwin_replace_vtable(struct GFX_VTABLE *vtable)
226 {
227 memcpy(&_xwin_vtable, vtable, sizeof(GFX_VTABLE));
228
229 vtable->acquire = _xwin_lock;
230 vtable->release = _xwin_unlock;
231 vtable->putpixel = _xwin_putpixel;
232 vtable->vline = _xwin_vline;
233 vtable->hline = _xwin_hline;
234 vtable->hfill = _xwin_hline;
235 vtable->rectfill = _xwin_rectfill;
236 vtable->draw_sprite = _xwin_draw_sprite;
237 vtable->draw_sprite_ex = _xwin_draw_sprite_ex;
238 vtable->draw_256_sprite = _xwin_draw_256_sprite;
239 vtable->draw_sprite_v_flip = _xwin_draw_sprite_v_flip;
240 vtable->draw_sprite_h_flip = _xwin_draw_sprite_h_flip;
241 vtable->draw_sprite_vh_flip = _xwin_draw_sprite_vh_flip;
242 vtable->draw_trans_sprite = _xwin_draw_trans_sprite;
243 vtable->draw_trans_rgba_sprite = _xwin_draw_trans_rgba_sprite;
244 vtable->draw_lit_sprite = _xwin_draw_lit_sprite;
245 vtable->draw_rle_sprite = _xwin_draw_rle_sprite;
246 vtable->draw_trans_rle_sprite = _xwin_draw_trans_rle_sprite;
247 vtable->draw_trans_rgba_rle_sprite = _xwin_draw_trans_rgba_rle_sprite;
248 vtable->draw_lit_rle_sprite = _xwin_draw_lit_rle_sprite;
249 vtable->draw_character = _xwin_draw_character;
250 vtable->draw_glyph = _xwin_draw_glyph;
251 vtable->blit_from_memory = _xwin_blit_anywhere;
252 vtable->blit_from_system = _xwin_blit_anywhere;
253 vtable->blit_to_self = _xwin_blit_anywhere;
254 vtable->blit_to_self_forward = _xwin_blit_anywhere;
255 vtable->blit_to_self_backward = _xwin_blit_backward;
256 vtable->masked_blit = _xwin_masked_blit;
257 vtable->clear_to_color = _xwin_clear_to_color;
258 }
259
260
261
262 /* _xwin_lock:
263 * Lock X for drawing onto the display.
264 */
_xwin_lock(BITMAP * bmp)265 void _xwin_lock(BITMAP *bmp)
266 {
267 XLOCK ();
268 }
269
270
271
272 /* _xwin_lock:
273 * Unlock X after drawing. This will only truely call XUNLOCK when the
274 * unlock count reaches 0.
275 */
_xwin_unlock(BITMAP * bmp)276 void _xwin_unlock(BITMAP *bmp)
277 {
278 XUNLOCK();
279 }
280
281
282
283 /* _xwin_update_video_bitmap:
284 * Update screen with correct offset for sub-bitmap.
285 */
_xwin_update_video_bitmap(BITMAP * dst,int x,int y,int w,int h)286 static void _xwin_update_video_bitmap(BITMAP *dst, int x, int y, int w, int h)
287 {
288 _xwin_update_screen(x + dst->x_ofs, y + dst->y_ofs, w, h);
289 }
290
291
292
293 /* _xwin_putpixel:
294 * Wrapper for putpixel.
295 */
_xwin_putpixel(BITMAP * dst,int dx,int dy,int color)296 static void _xwin_putpixel(BITMAP *dst, int dx, int dy, int color)
297 {
298 if (_xwin_in_gfx_call) {
299 _xwin_vtable.putpixel(dst, dx, dy, color);
300 return;
301 }
302
303 if (dst->clip && ((dx < dst->cl) || (dx >= dst->cr) || (dy < dst->ct) || (dy >= dst->cb)))
304 return;
305
306 _xwin_in_gfx_call = 1;
307 _xwin_vtable.putpixel(dst, dx, dy, color);
308 _xwin_in_gfx_call = 0;
309
310 if (_xwin_direct_putpixel(dst, dx, dy, color))
311 return;
312
313 _xwin_update_video_bitmap(dst, dx, dy, 1, 1);
314 }
315
316
317
318 /* _xwin_hline:
319 * Wrapper for hline.
320 */
_xwin_hline(BITMAP * dst,int dx1,int dy,int dx2,int color)321 static void _xwin_hline(BITMAP *dst, int dx1, int dy, int dx2, int color)
322 {
323 if (_xwin_in_gfx_call) {
324 _xwin_vtable.hline(dst, dx1, dy, dx2, color);
325 return;
326 }
327
328 if (dx1 > dx2) {
329 int tmp = dx1;
330 dx1 = dx2;
331 dx2 = tmp;
332 }
333
334 if (dst->clip) {
335 if (dx1 < dst->cl)
336 dx1 = dst->cl;
337 if (dx2 >= dst->cr)
338 dx2 = dst->cr - 1;
339 if ((dx1 > dx2) || (dy < dst->ct) || (dy >= dst->cb))
340 return;
341 }
342
343 _xwin_in_gfx_call = 1;
344 _xwin_vtable.hline(dst, dx1, dy, dx2, color);
345 _xwin_in_gfx_call = 0;
346
347 if (_xwin_direct_hline(dst, dx1, dy, dx2, color))
348 return;
349
350 _xwin_update_video_bitmap(dst, dx1, dy, dx2 - dx1 + 1, 1);
351 }
352
353
354
355 /* _xwin_vline:
356 * Wrapper for vline.
357 */
_xwin_vline(BITMAP * dst,int dx,int dy1,int dy2,int color)358 static void _xwin_vline(BITMAP *dst, int dx, int dy1, int dy2, int color)
359 {
360 if (_xwin_in_gfx_call) {
361 _xwin_vtable.vline(dst, dx, dy1, dy2, color);
362 return;
363 }
364
365 if (dy1 > dy2) {
366 int tmp = dy1;
367 dy1 = dy2;
368 dy2 = tmp;
369 }
370
371 if (dst->clip) {
372 if (dy1 < dst->ct)
373 dy1 = dst->ct;
374 if (dy2 >= dst->cb)
375 dy2 = dst->cb - 1;
376 if ((dx < dst->cl) || (dx >= dst->cr) || (dy1 > dy2))
377 return;
378 }
379
380 _xwin_in_gfx_call = 1;
381 _xwin_vtable.vline(dst, dx, dy1, dy2, color);
382 _xwin_in_gfx_call = 0;
383
384 if (_xwin_direct_vline(dst, dx, dy1, dy2, color))
385 return;
386
387 _xwin_update_video_bitmap(dst, dx, dy1, 1, dy2 - dy1 + 1);
388 }
389
390
391
392 /* _xwin_rectfill:
393 * Wrapper for rectfill.
394 */
_xwin_rectfill(BITMAP * dst,int dx1,int dy1,int dx2,int dy2,int color)395 static void _xwin_rectfill(BITMAP *dst, int dx1, int dy1, int dx2, int dy2, int color)
396 {
397 if (_xwin_in_gfx_call) {
398 _xwin_vtable.rectfill(dst, dx1, dy1, dx2, dy2, color);
399 return;
400 }
401
402 if (dy1 > dy2) {
403 int tmp = dy1;
404 dy1 = dy2;
405 dy2 = tmp;
406 }
407
408 if (dx1 > dx2) {
409 int tmp = dx1;
410 dx1 = dx2;
411 dx2 = tmp;
412 }
413
414 if (dst->clip) {
415 if (dx1 < dst->cl)
416 dx1 = dst->cl;
417 if (dx2 >= dst->cr)
418 dx2 = dst->cr - 1;
419 if (dx1 > dx2)
420 return;
421
422 if (dy1 < dst->ct)
423 dy1 = dst->ct;
424 if (dy2 >= dst->cb)
425 dy2 = dst->cb - 1;
426 if (dy1 > dy2)
427 return;
428 }
429
430 _xwin_in_gfx_call = 1;
431 _xwin_vtable.rectfill(dst, dx1, dy1, dx2, dy2, color);
432 _xwin_in_gfx_call = 0;
433
434 if (_xwin_direct_rectfill(dst, dx1, dy1, dx2, dy2, color))
435 return;
436
437 _xwin_update_video_bitmap(dst, dx1, dy1, dx2 - dx1 + 1, dy2 - dy1 + 1);
438 }
439
440
441
442 /* _xwin_clear_to_color:
443 * Wrapper for clear_to_color.
444 */
_xwin_clear_to_color(BITMAP * dst,int color)445 static void _xwin_clear_to_color(BITMAP *dst, int color)
446 {
447 if (_xwin_in_gfx_call) {
448 _xwin_vtable.clear_to_color(dst, color);
449 return;
450 }
451
452 _xwin_in_gfx_call = 1;
453 _xwin_vtable.clear_to_color(dst, color);
454 _xwin_in_gfx_call = 0;
455
456 if (_xwin_direct_clear_to_color(dst, color))
457 return;
458
459 _xwin_update_video_bitmap(dst, dst->cl, dst->ct, dst->cr - dst->cl, dst->cb - dst->ct);
460 }
461
462
463
464 /* _xwin_blit_anywhere:
465 * Wrapper for blit.
466 */
_xwin_blit_anywhere(BITMAP * src,BITMAP * dst,int sx,int sy,int dx,int dy,int w,int h)467 static void _xwin_blit_anywhere(BITMAP *src, BITMAP *dst, int sx, int sy,
468 int dx, int dy, int w, int h)
469 {
470 if (_xwin_in_gfx_call) {
471 _xwin_vtable.blit_from_memory(src, dst, sx, sy, dx, dy, w, h);
472 return;
473 }
474
475 _xwin_in_gfx_call = 1;
476 _xwin_vtable.blit_from_memory(src, dst, sx, sy, dx, dy, w, h);
477 _xwin_in_gfx_call = 0;
478 _xwin_update_video_bitmap(dst, dx, dy, w, h);
479 }
480
481
482
483 /* _xwin_blit_backward:
484 * Wrapper for blit_backward.
485 */
_xwin_blit_backward(BITMAP * src,BITMAP * dst,int sx,int sy,int dx,int dy,int w,int h)486 static void _xwin_blit_backward(BITMAP *src, BITMAP *dst, int sx, int sy,
487 int dx, int dy, int w, int h)
488 {
489 if (_xwin_in_gfx_call) {
490 _xwin_vtable.blit_to_self_backward(src, dst, sx, sy, dx, dy, w, h);
491 return;
492 }
493
494 _xwin_in_gfx_call = 1;
495 _xwin_vtable.blit_to_self_backward(src, dst, sx, sy, dx, dy, w, h);
496 _xwin_in_gfx_call = 0;
497 _xwin_update_video_bitmap(dst, dx, dy, w, h);
498 }
499
500
501
502 /* _xwin_masked_blit:
503 * Wrapper for masked_blit.
504 */
_xwin_masked_blit(BITMAP * src,BITMAP * dst,int sx,int sy,int dx,int dy,int w,int h)505 static void _xwin_masked_blit(BITMAP *src, BITMAP *dst, int sx, int sy,
506 int dx, int dy, int w, int h)
507 {
508 if (_xwin_in_gfx_call) {
509 _xwin_vtable.masked_blit(src, dst, sx, sy, dx, dy, w, h);
510 return;
511 }
512
513 _xwin_in_gfx_call = 1;
514 _xwin_vtable.masked_blit(src, dst, sx, sy, dx, dy, w, h);
515 _xwin_in_gfx_call = 0;
516 _xwin_update_video_bitmap(dst, dx, dy, w, h);
517 }
518
519
520
521 #define CLIP_BOX(dst, x, y, w, h, x_orig, y_orig, w_orig, h_orig) \
522 { \
523 if (dst->clip) { \
524 int tmp, x_delta, y_delta; \
525 \
526 tmp = dst->cl - x_orig; \
527 x_delta = ((tmp < 0) ? 0 : tmp); \
528 x = x_orig + x_delta; \
529 \
530 tmp = dst->cr - x_orig; \
531 w = ((tmp > w_orig) ? w_orig : tmp) - x_delta; \
532 if (w <= 0) \
533 return; \
534 \
535 tmp = dst->ct - y_orig; \
536 y_delta = ((tmp < 0) ? 0 : tmp); \
537 y = y_orig + y_delta; \
538 \
539 tmp = dst->cb - y_orig; \
540 h = ((tmp > h_orig) ? h_orig : tmp) - y_delta; \
541 if (h <= 0) \
542 return; \
543 } \
544 else { \
545 x = x_orig; \
546 y = y_orig; \
547 w = w_orig; \
548 h = h_orig; \
549 } \
550 }
551
552
553
554 /* _xwin_draw_sprite:
555 * Wrapper for draw_sprite.
556 */
_xwin_draw_sprite(BITMAP * dst,BITMAP * src,int dx,int dy)557 static void _xwin_draw_sprite(BITMAP *dst, BITMAP *src, int dx, int dy)
558 {
559 int dxbeg, dybeg, w, h;
560
561 if (_xwin_in_gfx_call) {
562 _xwin_vtable.draw_sprite(dst, src, dx, dy);
563 return;
564 }
565
566 CLIP_BOX(dst, dxbeg, dybeg, w, h, dx, dy, src->w, src->h)
567
568 _xwin_in_gfx_call = 1;
569 _xwin_vtable.draw_sprite(dst, src, dx, dy);
570 _xwin_in_gfx_call = 0;
571 _xwin_update_video_bitmap(dst, dxbeg, dybeg, w, h);
572 }
573
574 /* _xwin_draw_sprite_ex:
575 * Wrapper for draw_sprite_ex.
576 */
_xwin_draw_sprite_ex(BITMAP * dst,BITMAP * src,int dx,int dy,int mode,int flip)577 static void _xwin_draw_sprite_ex(BITMAP *dst, BITMAP *src, int dx, int dy, int mode, int flip)
578 {
579 int dxbeg, dybeg, w, h;
580
581 if (_xwin_in_gfx_call) {
582 _xwin_vtable.draw_sprite_ex(dst, src, dx, dy, mode, flip);
583 return;
584 }
585
586 CLIP_BOX(dst, dxbeg, dybeg, w, h, dx, dy, src->w, src->h)
587
588 _xwin_in_gfx_call = 1;
589 _xwin_vtable.draw_sprite_ex(dst, src, dx, dy, mode, flip);
590 _xwin_in_gfx_call = 0;
591 _xwin_update_video_bitmap(dst, dxbeg, dybeg, w, h);
592 }
593
594 /* _xwin_draw_256_sprite:
595 * Wrapper for draw_256_sprite.
596 */
_xwin_draw_256_sprite(BITMAP * dst,BITMAP * src,int dx,int dy)597 static void _xwin_draw_256_sprite(BITMAP *dst, BITMAP *src, int dx, int dy)
598 {
599 int dxbeg, dybeg, w, h;
600
601 if (_xwin_in_gfx_call) {
602 _xwin_vtable.draw_256_sprite(dst, src, dx, dy);
603 return;
604 }
605
606 CLIP_BOX(dst, dxbeg, dybeg, w, h, dx, dy, src->w, src->h)
607
608 _xwin_in_gfx_call = 1;
609 _xwin_vtable.draw_256_sprite(dst, src, dx, dy);
610 _xwin_in_gfx_call = 0;
611 _xwin_update_video_bitmap(dst, dxbeg, dybeg, w, h);
612 }
613
614
615
616 /* _xwin_draw_sprite_v_flip:
617 * Wrapper for draw_sprite_v_flip.
618 */
_xwin_draw_sprite_v_flip(BITMAP * dst,BITMAP * src,int dx,int dy)619 static void _xwin_draw_sprite_v_flip(BITMAP *dst, BITMAP *src, int dx, int dy)
620 {
621 int dxbeg, dybeg, w, h;
622
623 if (_xwin_in_gfx_call) {
624 _xwin_vtable.draw_sprite_v_flip(dst, src, dx, dy);
625 return;
626 }
627
628 CLIP_BOX(dst, dxbeg, dybeg, w, h, dx, dy, src->w, src->h)
629
630 _xwin_in_gfx_call = 1;
631 _xwin_vtable.draw_sprite_v_flip(dst, src, dx, dy);
632 _xwin_in_gfx_call = 0;
633 _xwin_update_video_bitmap(dst, dxbeg, dybeg, w, h);
634 }
635
636
637
638 /* _xwin_draw_sprite_h_flip:
639 * Wrapper for draw_sprite_h_flip.
640 */
_xwin_draw_sprite_h_flip(BITMAP * dst,BITMAP * src,int dx,int dy)641 static void _xwin_draw_sprite_h_flip(BITMAP *dst, BITMAP *src, int dx, int dy)
642 {
643 int dxbeg, dybeg, w, h;
644
645 if (_xwin_in_gfx_call) {
646 _xwin_vtable.draw_sprite_h_flip(dst, src, dx, dy);
647 return;
648 }
649
650 CLIP_BOX(dst, dxbeg, dybeg, w, h, dx, dy, src->w, src->h)
651
652 _xwin_in_gfx_call = 1;
653 _xwin_vtable.draw_sprite_h_flip(dst, src, dx, dy);
654 _xwin_in_gfx_call = 0;
655 _xwin_update_video_bitmap(dst, dxbeg, dybeg, w, h);
656 }
657
658
659
660 /* _xwin_draw_sprite_vh_flip:
661 * Wrapper for draw_sprite_vh_flip.
662 */
_xwin_draw_sprite_vh_flip(BITMAP * dst,BITMAP * src,int dx,int dy)663 static void _xwin_draw_sprite_vh_flip(BITMAP *dst, BITMAP *src, int dx, int dy)
664 {
665 int dxbeg, dybeg, w, h;
666
667 if (_xwin_in_gfx_call) {
668 _xwin_vtable.draw_sprite_vh_flip(dst, src, dx, dy);
669 return;
670 }
671
672 CLIP_BOX(dst, dxbeg, dybeg, w, h, dx, dy, src->w, src->h)
673
674 _xwin_in_gfx_call = 1;
675 _xwin_vtable.draw_sprite_vh_flip(dst, src, dx, dy);
676 _xwin_in_gfx_call = 0;
677 _xwin_update_video_bitmap(dst, dxbeg, dybeg, w, h);
678 }
679
680 /* _xwin_draw_trans_sprite:
681 * Wrapper for draw_trans_sprite.
682 */
_xwin_draw_trans_sprite(BITMAP * dst,BITMAP * src,int dx,int dy)683 static void _xwin_draw_trans_sprite(BITMAP *dst, BITMAP *src, int dx, int dy)
684 {
685 int dxbeg, dybeg, w, h;
686
687 if (_xwin_in_gfx_call) {
688 _xwin_vtable.draw_trans_sprite(dst, src, dx, dy);
689 return;
690 }
691
692 CLIP_BOX(dst, dxbeg, dybeg, w, h, dx, dy, src->w, src->h)
693
694 _xwin_in_gfx_call = 1;
695 _xwin_vtable.draw_trans_sprite(dst, src, dx, dy);
696 _xwin_in_gfx_call = 0;
697 _xwin_update_video_bitmap(dst, dxbeg, dybeg, w, h);
698 }
699
700
701
702 /* _xwin_draw_trans_rgba_sprite:
703 * Wrapper for draw_trans_rgba_sprite.
704 */
_xwin_draw_trans_rgba_sprite(BITMAP * dst,BITMAP * src,int dx,int dy)705 static void _xwin_draw_trans_rgba_sprite(BITMAP *dst, BITMAP *src, int dx, int dy)
706 {
707 int dxbeg, dybeg, w, h;
708
709 if (_xwin_in_gfx_call) {
710 _xwin_vtable.draw_trans_rgba_sprite(dst, src, dx, dy);
711 return;
712 }
713
714 CLIP_BOX(dst, dxbeg, dybeg, w, h, dx, dy, src->w, src->h)
715
716 _xwin_in_gfx_call = 1;
717 _xwin_vtable.draw_trans_rgba_sprite(dst, src, dx, dy);
718 _xwin_in_gfx_call = 0;
719 _xwin_update_video_bitmap(dst, dxbeg, dybeg, w, h);
720 }
721
722
723
724 /* _xwin_draw_lit_sprite:
725 * Wrapper for draw_lit_sprite.
726 */
_xwin_draw_lit_sprite(BITMAP * dst,BITMAP * src,int dx,int dy,int color)727 static void _xwin_draw_lit_sprite(BITMAP *dst, BITMAP *src, int dx, int dy, int color)
728 {
729 int dxbeg, dybeg, w, h;
730
731 if (_xwin_in_gfx_call) {
732 _xwin_vtable.draw_lit_sprite(dst, src, dx, dy, color);
733 return;
734 }
735
736 CLIP_BOX(dst, dxbeg, dybeg, w, h, dx, dy, src->w, src->h)
737
738 _xwin_in_gfx_call = 1;
739 _xwin_vtable.draw_lit_sprite(dst, src, dx, dy, color);
740 _xwin_in_gfx_call = 0;
741 _xwin_update_video_bitmap(dst, dxbeg, dybeg, w, h);
742 }
743
744
745
746 /* _xwin_draw_character:
747 * Wrapper for draw_character.
748 */
_xwin_draw_character(BITMAP * dst,BITMAP * src,int dx,int dy,int color,int bg)749 static void _xwin_draw_character(BITMAP *dst, BITMAP *src, int dx, int dy, int color, int bg)
750 {
751 int dxbeg, dybeg, w, h;
752
753 if (_xwin_in_gfx_call) {
754 _xwin_vtable.draw_character(dst, src, dx, dy, color, bg);
755 return;
756 }
757
758 CLIP_BOX(dst, dxbeg, dybeg, w, h, dx, dy, src->w, src->h)
759
760 _xwin_in_gfx_call = 1;
761 _xwin_vtable.draw_character(dst, src, dx, dy, color, bg);
762 _xwin_in_gfx_call = 0;
763 _xwin_update_video_bitmap(dst, dxbeg, dybeg, w, h);
764 }
765
766
767
768 /* _xwin_draw_glyph:
769 * Wrapper for draw_glyph.
770 */
_xwin_draw_glyph(BITMAP * dst,AL_CONST FONT_GLYPH * src,int dx,int dy,int color,int bg)771 static void _xwin_draw_glyph(BITMAP *dst, AL_CONST FONT_GLYPH *src, int dx, int dy, int color, int bg)
772 {
773 int dxbeg, dybeg, w, h;
774
775 if (_xwin_in_gfx_call) {
776 _xwin_vtable.draw_glyph(dst, src, dx, dy, color, bg);
777 return;
778 }
779
780 CLIP_BOX(dst, dxbeg, dybeg, w, h, dx, dy, src->w, src->h)
781
782 _xwin_in_gfx_call = 1;
783 _xwin_vtable.draw_glyph(dst, src, dx, dy, color, bg);
784 _xwin_in_gfx_call = 0;
785 _xwin_update_video_bitmap(dst, dxbeg, dybeg, w, h);
786 }
787
788
789
790 /* _xwin_draw_rle_sprite:
791 * Wrapper for draw_rle_sprite.
792 */
_xwin_draw_rle_sprite(BITMAP * dst,AL_CONST RLE_SPRITE * src,int dx,int dy)793 static void _xwin_draw_rle_sprite(BITMAP *dst, AL_CONST RLE_SPRITE *src, int dx, int dy)
794 {
795 int dxbeg, dybeg, w, h;
796
797 if (_xwin_in_gfx_call) {
798 _xwin_vtable.draw_rle_sprite(dst, src, dx, dy);
799 return;
800 }
801
802 CLIP_BOX(dst, dxbeg, dybeg, w, h, dx, dy, src->w, src->h)
803
804 _xwin_in_gfx_call = 1;
805 _xwin_vtable.draw_rle_sprite(dst, src, dx, dy);
806 _xwin_in_gfx_call = 0;
807 _xwin_update_video_bitmap(dst, dxbeg, dybeg, w, h);
808 }
809
810
811
812 /* _xwin_draw_trans_rle_sprite:
813 * Wrapper for draw_trans_rle_sprite.
814 */
_xwin_draw_trans_rle_sprite(BITMAP * dst,AL_CONST RLE_SPRITE * src,int dx,int dy)815 static void _xwin_draw_trans_rle_sprite(BITMAP *dst, AL_CONST RLE_SPRITE *src, int dx, int dy)
816 {
817 int dxbeg, dybeg, w, h;
818
819 if (_xwin_in_gfx_call) {
820 _xwin_vtable.draw_trans_rle_sprite(dst, src, dx, dy);
821 return;
822 }
823
824 CLIP_BOX(dst, dxbeg, dybeg, w, h, dx, dy, src->w, src->h)
825
826 _xwin_in_gfx_call = 1;
827 _xwin_vtable.draw_trans_rle_sprite(dst, src, dx, dy);
828 _xwin_in_gfx_call = 0;
829 _xwin_update_video_bitmap(dst, dxbeg, dybeg, w, h);
830 }
831
832
833
834 /* _xwin_draw_trans_rgba_rle_sprite:
835 * Wrapper for draw_trans_rgba_rle_sprite.
836 */
_xwin_draw_trans_rgba_rle_sprite(BITMAP * dst,AL_CONST RLE_SPRITE * src,int dx,int dy)837 static void _xwin_draw_trans_rgba_rle_sprite(BITMAP *dst, AL_CONST RLE_SPRITE *src, int dx, int dy)
838 {
839 int dxbeg, dybeg, w, h;
840
841 if (_xwin_in_gfx_call) {
842 _xwin_vtable.draw_trans_rgba_rle_sprite(dst, src, dx, dy);
843 return;
844 }
845
846 CLIP_BOX(dst, dxbeg, dybeg, w, h, dx, dy, src->w, src->h)
847
848 _xwin_in_gfx_call = 1;
849 _xwin_vtable.draw_trans_rgba_rle_sprite(dst, src, dx, dy);
850 _xwin_in_gfx_call = 0;
851 _xwin_update_video_bitmap(dst, dxbeg, dybeg, w, h);
852 }
853
854
855
856 /* _xwin_draw_lit_rle_sprite:
857 * Wrapper for draw_lit_rle_sprite.
858 */
_xwin_draw_lit_rle_sprite(BITMAP * dst,AL_CONST RLE_SPRITE * src,int dx,int dy,int color)859 static void _xwin_draw_lit_rle_sprite(BITMAP *dst, AL_CONST RLE_SPRITE *src, int dx, int dy, int color)
860 {
861 int dxbeg, dybeg, w, h;
862
863 if (_xwin_in_gfx_call) {
864 _xwin_vtable.draw_lit_rle_sprite(dst, src, dx, dy, color);
865 return;
866 }
867
868 CLIP_BOX(dst, dxbeg, dybeg, w, h, dx, dy, src->w, src->h)
869
870 _xwin_in_gfx_call = 1;
871 _xwin_vtable.draw_lit_rle_sprite(dst, src, dx, dy, color);
872 _xwin_in_gfx_call = 0;
873 _xwin_update_video_bitmap(dst, dxbeg, dybeg, w, h);
874 }
875