rnd-20040822-2-src
[rocksndiamonds.git] / src / game_em / graphics.c
1 /* 2000-08-13T14:36:17Z
2  *
3  * graphics manipulation crap
4  */
5
6 #include <X11/Xlib.h>
7 #include <X11/Xutil.h>
8
9 #include "global.h"
10 #include "display.h"
11 #include "level.h"
12
13 #include <stdio.h>
14
15
16 #if defined(TARGET_X11)
17
18 extern void DrawGameDoorValues_EM(int, int, int, int);
19
20 unsigned int frame; /* current frame */
21 unsigned int screen_x; /* current scroll position */
22 unsigned int screen_y;
23
24 /* tiles currently on screen */
25 static unsigned short screentiles[MAX_BUF_YSIZE][MAX_BUF_XSIZE];
26
27 static unsigned int colours[8];
28 static unsigned int colour_anim;
29
30 static void xdebug(char *msg)
31 {
32 #if 0
33   XSync(display, False);
34   printf("EM DEBUG: %s\n", msg);
35 #endif
36 }
37
38 static void colour_shuffle(void)
39 {
40   unsigned int i, j, k;
41
42   for (i = 0; i < 8; i++)
43     colours[i] = i;
44
45   for (i = 0; i < 8; i++)
46   {
47     Random = Random * 129 + 1;
48     j = (Random >> 10) & 7;
49     k = colours[i];
50     colours[i] = colours[j];
51     colours[j] = k;
52   }
53 }
54
55
56 /* copy the entire screen to the window at the scroll position
57  *
58  * perhaps use mit-shm to speed this up
59  */
60
61 void blitscreen(void)
62 {
63   unsigned int x = screen_x % (MAX_BUF_XSIZE * TILEX);
64   unsigned int y = screen_y % (MAX_BUF_YSIZE * TILEY);
65
66   xdebug("blitscreen");
67
68   if (em_game_status == EM_GAME_STATUS_MENU)
69   {
70     ClearRectangle(screenBitmap, 0, SCR_MENUY * TILEY,
71                    SCR_FIELDX * TILEX, (17 - SCR_MENUY) * TILEY);
72     BlitBitmap(scoreBitmap, screenBitmap, 0, 0, SCR_MENUX * TILEX, SCOREY,
73                0, SCR_MENUY * TILEY);
74   }
75
76   if (x < 2 * TILEX && y < 2 * TILEY)
77   {
78     BlitBitmap(screenBitmap, window, x, y,
79                SCR_FIELDX * TILEX, SCR_FIELDY * TILEY, SX, SY);
80   }
81   else if (x < 2 * TILEX && y >= 2 * TILEY)
82   {
83     BlitBitmap(screenBitmap, window, x, y,
84                SCR_FIELDX * TILEX, MAX_BUF_YSIZE * TILEY - y,
85                SX, SY);
86     BlitBitmap(screenBitmap, window, x, 0,
87                SCR_FIELDX * TILEX, y - 2 * TILEY,
88                SX, SY + MAX_BUF_YSIZE * TILEY - y);
89   }
90   else if (x >= 2 * TILEX && y < 2 * TILEY)
91   {
92     BlitBitmap(screenBitmap, window, x, y,
93                MAX_BUF_XSIZE * TILEX - x, SCR_FIELDY * TILEY,
94                SX, SY);
95     BlitBitmap(screenBitmap, window, 0, y,
96                x - 2 * TILEX, SCR_FIELDY * TILEY,
97                SX + MAX_BUF_XSIZE * TILEX - x, SY);
98   }
99   else
100   {
101     BlitBitmap(screenBitmap, window, x, y,
102                MAX_BUF_XSIZE * TILEX - x, MAX_BUF_YSIZE * TILEY - y,
103                SX, SY);
104     BlitBitmap(screenBitmap, window, 0, y,
105                x - 2 * TILEX, MAX_BUF_YSIZE * TILEY - y,
106                SX + MAX_BUF_XSIZE * TILEX - x, SY);
107     BlitBitmap(screenBitmap, window, x, 0,
108                MAX_BUF_XSIZE * TILEX - x, y - 2 * TILEY,
109                SX, SY + MAX_BUF_YSIZE * TILEY - y);
110     BlitBitmap(screenBitmap, window, 0, 0,
111                x - 2 * TILEX, y - 2 * TILEY,
112                SX + MAX_BUF_XSIZE * TILEX - x, SY + MAX_BUF_YSIZE * TILEY - y);
113   }
114
115   if (em_game_status == EM_GAME_STATUS_PLAY && SCR_FIELDY < 17)
116   {
117     BlitBitmap(scoreBitmap, window, 0, 0, SCR_FIELDX * TILEX, SCOREY,
118                SX, SY + SCR_FIELDY * TILEY);
119     ClearRectangle(window, SX, SY + SCR_FIELDY * TILEY + SCOREY,
120                    SCR_FIELDX * TILEX, (17 - SCR_FIELDY) * TILEY - SCOREY);
121   }
122
123   XFlush(display);
124
125   xdebug("blitscreen - done");
126 }
127
128
129 /* draw differences between game tiles and screen tiles
130  *
131  * implicitly handles scrolling and restoring background under the sprites
132  *
133  * perhaps use mit-shm to speed this up
134  */
135
136 static void animscreen(void)
137 {
138   unsigned int x, y, dx, dy;
139   unsigned short obj;
140   unsigned int left = screen_x / TILEX;
141   unsigned int top = screen_y / TILEY;
142
143   xdebug("animscreen");
144
145   for (y = top; y < top + MAX_BUF_YSIZE; y++)
146   {
147     dy = y % MAX_BUF_YSIZE;
148     for (x = left; x < left + MAX_BUF_XSIZE; x++)
149     {
150       dx = x % MAX_BUF_XSIZE;
151       obj = map_obj[frame][Draw[y][x]];
152
153       if (screentiles[dy][dx] != obj)
154       {
155         screentiles[dy][dx] = obj;
156         BlitBitmap(objBitmap, screenBitmap,
157                    (obj / 512) * TILEX, (obj % 512) * TILEY / 16,
158                    TILEX, TILEY, dx * TILEX, dy * TILEY);
159       }
160     }
161   }
162 }
163
164
165 /* blit players to the screen
166  *
167  * handles transparency and movement
168  */
169
170 static void blitplayer(struct PLAYER *ply)
171 {
172   unsigned int x, y, dx, dy;
173   unsigned short obj, spr;
174
175   xdebug("blitplayer");
176
177   if (ply->alive)
178   {
179     x = (frame * ply->oldx + (8 - frame) * ply->x) * TILEX / 8;
180     y = (frame * ply->oldy + (8 - frame) * ply->y) * TILEY / 8;
181     dx = x + TILEX - 1;
182     dy = y + TILEY - 1;
183
184     if ((unsigned int)(dx - screen_x) < ((MAX_BUF_XSIZE - 1) * TILEX - 1) &&
185         (unsigned int)(dy - screen_y) < ((MAX_BUF_YSIZE - 1) * TILEY - 1))
186     {
187       spr = map_spr[ply->num][frame][ply->anim];
188       x  %= MAX_BUF_XSIZE * TILEX;
189       y  %= MAX_BUF_YSIZE * TILEY;
190       dx %= MAX_BUF_XSIZE * TILEX;
191       dy %= MAX_BUF_YSIZE * TILEY;
192
193       if (objmaskBitmap)
194       {
195         obj = screentiles[y / TILEY][x / TILEX];
196         XCopyArea(display, objmaskBitmap, spriteBitmap, spriteGC,
197                   (obj / 512) * TILEX, (obj % 512) * TILEY / 16, TILEX, TILEY,
198                   -(x % TILEX), -(y % TILEY));
199
200         obj = screentiles[dy / TILEY][dx / TILEX];
201         XCopyArea(display, objmaskBitmap, spriteBitmap, spriteGC,
202                   (obj / 512) * TILEX, (obj % 512) * TILEY / 16, TILEX, TILEY,
203                   (MAX_BUF_XSIZE * TILEX - x) % TILEX,
204                   (MAX_BUF_YSIZE * TILEY - y) % TILEY);
205       }
206       else if (sprmaskBitmap)
207       {
208         XCopyArea(display, sprmaskBitmap, spriteBitmap, spriteGC,
209                   (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY, 0, 0);
210       }
211       else
212       {
213         XFillRectangle(display, spriteBitmap, spriteGC, 0, 0, TILEX, TILEY);
214       }
215
216       screentiles[y / TILEY][x / TILEX] = -1; /* mark screen as dirty */
217       screentiles[dy / TILEY][dx / TILEX] = -1;
218
219 #if 1
220
221
222 #if 1
223
224       SetClipMask(sprBitmap, sprBitmap->stored_clip_gc, spriteBitmap);
225
226       SetClipOrigin(sprBitmap, sprBitmap->stored_clip_gc, x, y);
227       BlitBitmapMasked(sprBitmap, screenBitmap,
228                        (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
229                        x, y);
230
231       SetClipOrigin(sprBitmap, sprBitmap->stored_clip_gc,
232                     x - MAX_BUF_XSIZE * TILEX, y);
233       BlitBitmapMasked(sprBitmap, screenBitmap,
234                        (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
235                        x - MAX_BUF_XSIZE * TILEX, y);
236
237       SetClipOrigin(sprBitmap, sprBitmap->stored_clip_gc,
238                     x, y - MAX_BUF_YSIZE * TILEY);
239       BlitBitmapMasked(sprBitmap, screenBitmap,
240                        (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
241                        x, y - MAX_BUF_YSIZE * TILEY);
242
243       SetClipMask(sprBitmap, sprBitmap->stored_clip_gc, None);
244
245 #else
246
247       XSetClipMask(display, sprBitmap->stored_clip_gc, spriteBitmap);
248
249       XSetClipOrigin(display, sprBitmap->stored_clip_gc, x, y);
250       XCopyArea(display, sprBitmap->drawable, screenBitmap->drawable,
251                 sprBitmap->stored_clip_gc,
252                 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
253                 x, y);
254
255       XSetClipOrigin(display, sprBitmap->stored_clip_gc,
256                      x - MAX_BUF_XSIZE * TILEX, y);
257       XCopyArea(display, sprBitmap->drawable, screenBitmap->drawable,
258                 sprBitmap->stored_clip_gc,
259                 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
260                 x - MAX_BUF_XSIZE * TILEX, y);
261
262       XSetClipOrigin(display, sprBitmap->stored_clip_gc,
263                      x, y - MAX_BUF_YSIZE * TILEY);
264       XCopyArea(display, sprBitmap->drawable, screenBitmap->drawable,
265                 sprBitmap->stored_clip_gc,
266                 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
267                 x, y - MAX_BUF_YSIZE * TILEY);
268
269       XSetClipMask(display, sprBitmap->stored_clip_gc, None);
270
271 #endif
272
273 #else
274
275       XSetClipMask(display, screenGC, spriteBitmap);
276       XSetClipOrigin(display, screenGC, x, y);
277       XCopyArea(display, sprPixmap, screenPixmap, screenGC,
278                 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
279                 x, y);
280       XSetClipOrigin(display, screenGC, x - MAX_BUF_XSIZE * TILEX, y);
281       XCopyArea(display, sprPixmap, screenPixmap, screenGC,
282                 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
283                 x - MAX_BUF_XSIZE * TILEX, y);
284       XSetClipOrigin(display, screenGC, x, y - MAX_BUF_YSIZE * TILEY);
285       XCopyArea(display, sprPixmap, screenPixmap, screenGC,
286                 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
287                 x, y - MAX_BUF_YSIZE * TILEY);
288       XSetClipMask(display, screenGC, None);
289
290 #endif
291     }
292   }
293 }
294
295
296 /* draw static text for time, gems and score counter */
297
298 void game_initscreen(void)
299 {
300   unsigned int x,y;
301
302   xdebug("game_initscreen");
303
304   frame = 6;
305   screen_x = 0;
306   screen_y = 0;
307
308   for (y = 0; y < MAX_BUF_YSIZE; y++)
309     for (x = 0; x < MAX_BUF_XSIZE; x++)
310       screentiles[y][x] = -1;
311
312   colour_shuffle();
313   colours[0] += 16;
314   colours[1] += 16;
315   colours[2] += 16;
316   colour_anim = 0;
317
318   ClearRectangle(scoreBitmap, 0, 0, SCR_FIELDX * TILEX, SCOREY);
319   BlitBitmap(botBitmap, scoreBitmap,
320              11 * SCOREX, colours[0] * SCOREY, 3 * SCOREX, SCOREY,
321              1 * SCOREX, 0);                            /* 0-63 time */
322   BlitBitmap(botBitmap, scoreBitmap,
323              18 * SCOREX, colours[0] * SCOREY, 6 * SCOREX, SCOREY,
324              11 * SCOREX, 0);                           /* 112-207 diamonds */
325   BlitBitmap(botBitmap, scoreBitmap,
326              14 * SCOREX, colours[0] * SCOREY, 4 * SCOREX, SCOREY,
327              24 * SCOREX, 0);                           /* 256-319 score */
328 }
329
330
331 /* draw current values for time, gems and score counter */
332
333 void game_blitscore(void)
334 {
335   unsigned int i;
336
337   xdebug("game_blitscore");
338
339   DrawGameDoorValues_EM(lev.required, ply1.dynamite, lev.score,
340                         (lev.time + 4) / 5);
341
342   i = (lev.time + 4) / 5;
343   BlitBitmap(botBitmap, scoreBitmap,
344              (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
345              7 * SCOREX, 0);
346   i /= 10;
347   BlitBitmap(botBitmap, scoreBitmap,
348              (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
349              6 * SCOREX, 0);
350   i /= 10;
351   BlitBitmap(botBitmap, scoreBitmap,
352              (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
353              5 * SCOREX, 0);
354   i /= 10;
355   BlitBitmap(botBitmap, scoreBitmap,
356              (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
357              4 * SCOREX, 0);
358
359   i = lev.score;
360   BlitBitmap(botBitmap, scoreBitmap,
361              (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
362              31 * SCOREX, 0);
363   i /= 10;
364   BlitBitmap(botBitmap, scoreBitmap,
365              (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
366              30 * SCOREX, 0);
367   i /= 10;
368   BlitBitmap(botBitmap, scoreBitmap,
369              (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
370              29 * SCOREX, 0);
371   i /= 10;
372   BlitBitmap(botBitmap, scoreBitmap,
373              (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
374              28 * SCOREX, 0);
375
376   if (lev.home == 0)
377   {
378     BlitBitmap(botBitmap, scoreBitmap,
379                12 * SCOREX, 24 * SCOREY, 12 * SCOREX, SCOREY,
380                14 * SCOREX, 0); /* relax */
381
382     goto done;
383   }
384
385   if (ply1.alive + ply2.alive >= lev.home && lev.required == 0)
386   {
387     BlitBitmap(botBitmap, scoreBitmap,
388                24 * SCOREX, colours[2] * SCOREY, 12 * SCOREX, SCOREY,
389                14 * SCOREX, 0); /* find the exit */
390
391     goto done;
392   }
393
394   if (ply1.alive + ply2.alive < lev.home)
395   {
396     if (++colour_anim > 11)
397       colour_anim = 0;
398
399     if (colour_anim < 6)
400     {
401       BlitBitmap(botBitmap, scoreBitmap,
402                  0, 24 * SCOREY, 12 * SCOREX, SCOREY,
403                  14 * SCOREX, 0); /* forget it */
404
405       goto done;
406     }
407
408     BlitBitmap(botBitmap, scoreBitmap,
409                18 * SCOREX, colours[0] * SCOREY, 6 * SCOREX, SCOREY,
410                15 * SCOREX, 0); /* diamonds */
411   }
412
413   i = lev.required;
414   BlitBitmap(botBitmap, scoreBitmap,
415              (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
416              20 * SCOREX, 0);
417   i /= 10;
418   BlitBitmap(botBitmap, scoreBitmap,
419              (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
420              19 * SCOREX, 0);
421   i /= 10;
422   BlitBitmap(botBitmap, scoreBitmap,
423              (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
424              18 * SCOREX, 0);
425   i /= 10;
426   BlitBitmap(botBitmap, scoreBitmap,
427              (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
428              17 * SCOREX, 0);
429
430  done:
431 }
432
433 void game_animscreen(void)
434 {
435   unsigned int x,y;
436
437   xdebug("game_animscreen");
438
439   x = (frame * ply1.oldx + (8 - frame) * ply1.x) * TILEX / 8
440     + ((SCR_FIELDX - 1) * TILEX) / 2;
441   y = (frame * ply1.oldy + (8 - frame) * ply1.y) * TILEY / 8
442     + ((SCR_FIELDY - 1) * TILEY) / 2;
443
444   if (x > lev.width * TILEX)
445     x = lev.width * TILEX;
446   if (y > lev.height * TILEY)
447     y = lev.height * TILEY;
448
449   if (x < SCR_FIELDX * TILEX)
450     x = SCR_FIELDX * TILEY;
451   if (y < SCR_FIELDY * TILEY)
452     y = SCR_FIELDY * TILEY;
453
454   screen_x = x - (SCR_FIELDX - 1) * TILEX;
455   screen_y = y - (SCR_FIELDY - 1) * TILEY;
456
457   animscreen();
458   blitplayer(&ply1);
459   blitplayer(&ply2);
460   blitscreen();
461
462   XFlush(display);
463
464   Random = Random * 129 + 1;
465 }
466
467
468 /* draw main menu background and copyright note */
469
470 void title_initscreen(void)
471 {
472   xdebug("title_initscreen");
473
474   screen_x = 0;
475   screen_y = 0;
476
477   colour_shuffle();
478   colours[1] += 8;
479   colour_anim = 0;
480
481 #if 1
482
483   /* draw title screen on menu background */
484
485   BlitBitmap(ttlBitmap, screenBitmap, ORIG_MENU_SX, ORIG_MENU_SY,
486              SCR_MENUX * TILEX, SCR_MENUY * TILEY, 0, 0);
487
488   /* draw copyright note at footer */
489
490   if (botmaskBitmap)
491   {
492     BlitBitmap(botBitmap, scoreBitmap, 0, colours[1] * SCOREY,
493                SCR_MENUX * TILEX, SCOREY, 0, 0);
494
495     SetClipOrigin(botBitmap, botBitmap->stored_clip_gc,
496                   0, 0 - colours[0] * SCOREY);
497   }
498
499   BlitBitmapMasked(botBitmap, scoreBitmap, 0, colours[0] * SCOREY,
500                    SCR_MENUX * TILEX, SCOREY, 0, 0);
501
502 #else
503
504   XCopyArea(display, ttlPixmap, screenPixmap, screenGC,
505             0, 0, SCR_MENUX * TILEX, SCR_MENUY * TILEY, 0, 0);
506
507   if (botmaskBitmap)
508   {
509     XCopyArea(display, botPixmap, scorePixmap, scoreGC,
510               0, colours[1] * SCOREY, SCR_MENUX * TILEX, SCOREY, 0, 0);
511     XSetClipMask(display, scoreGC, botmaskBitmap);
512     XSetClipOrigin(display, scoreGC, 0, 0 - colours[0] * SCOREY);
513   }
514
515   XCopyArea(display, botPixmap, scorePixmap, scoreGC,
516             0, colours[0] * SCOREY, SCR_MENUX * TILEX, SCOREY, 0, 0);
517
518   if (botmaskBitmap)
519     XSetClipMask(display, scoreGC, None);
520
521 #endif
522 }
523
524
525 /* draw bouncing ball on main menu footer */
526
527 void title_blitscore(void)
528 {
529   unsigned int x, y, i;
530
531   xdebug("title_blitscore");
532
533   if (++colour_anim > 30)
534     colour_anim = 0;
535
536   i = colour_anim >= 16 ? 31 - colour_anim : colour_anim;
537   x = (i / 8 + 18) * 2 * SCOREX;
538   y = (i % 8 + 16) * SCOREY;
539
540 #if 1
541   if (botmaskBitmap)
542   {
543     BlitBitmap(botBitmap, scoreBitmap,
544                32 * SCOREX, colours[1] * SCOREY, 2 * SCOREX, SCOREY,
545                32 * SCOREX, 0);
546
547     SetClipOrigin(botBitmap, botBitmap->stored_clip_gc,
548                   32 * SCOREX - x, 0 - y);
549   }
550
551   BlitBitmapMasked(botBitmap, scoreBitmap,
552                    x, y, 2 * SCOREX, SCOREY, 32 * SCOREX, 0);
553
554 #else
555
556   if (botmaskBitmap)
557   {
558     XCopyArea(display, botPixmap, scorePixmap, scoreGC,
559               32 * SCOREX, colours[1] * SCOREY, 2 * SCOREX, SCOREY,
560               32 * SCOREX, 0);
561     XSetClipMask(display, scoreGC, botmaskBitmap);
562     XSetClipOrigin(display, scoreGC, 32 * SCOREX - x, 0 - y);
563   }
564
565   XCopyArea(display, botPixmap, scorePixmap, scoreGC,
566             x, y, 2 * SCOREX, SCOREY, 32 * SCOREX, 0);
567
568   if (botmaskBitmap)
569     XSetClipMask(display, scoreGC, None);
570 #endif
571 }
572
573 void title_blitants(unsigned int y)
574 {
575   static const char ants_dashes[2] = { 8, 7 };
576
577   xdebug("title_blitants");
578
579   XSetDashes(display, antsGC, colour_anim, ants_dashes, 2);
580   XDrawRectangle(display, screenPixmap, antsGC,
581                  0, y * TILEY, SCR_MENUX * TILEX - 1, TILEY - 1);
582 }
583
584 void title_animscreen(void)
585 {
586   blitscreen();
587   XFlush(display);
588
589   Random = Random * 129 + 1;
590 }
591
592 static int ttl_map[] =
593 {
594   -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
595   -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
596   -1,0,-1,-1,-1,-1,-1,1,-1,-1,-1,-1,2,3,4,-1,      /* !',-. */
597   5,6,7,8,9,10,11,12,13,14,15,-1,-1,-1,-1,16,      /* 0123456789:? */
598   -1,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, /* ABCDEFGHIJKLMNO */
599   32,33,34,35,36,37,38,39,40,41,42,-1,-1,-1,-1,-1, /* PQRSTUVWXYZ */
600   -1,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, /* abcdefghijklmno */
601   32,33,34,35,36,37,38,39,40,41,42,-1,-1,-1,-1,-1  /* pqrstuvwxyz */
602 };
603
604 void title_string(unsigned int y, unsigned int left, unsigned int right,
605                   char *string)
606 {
607   int i;
608   unsigned int x;
609
610   xdebug("title_string");
611
612   y *= TILEY;
613   left *= SCOREX;
614   right *= SCOREX;
615
616   x = (left + right - strlen(string) * MENUFONTX) / 2;
617   if (x < left || x >= right)
618     x = left;
619
620   /* restore background graphic where text will be drawn */
621   BlitBitmap(ttlBitmap, screenBitmap, ORIG_MENU_SX + left, ORIG_MENU_SY + y,
622              right - left, MENUFONTY, left, y);
623
624 #if 1
625 #else
626   if (ttlmaskBitmap)
627     XSetClipMask(display, screenGC, ttlmaskBitmap);
628 #endif
629
630   for (i = 0; string[i] && x < right; i++)
631   {
632     int ch_pos, ch_x, ch_y;
633
634     ch_pos = ttl_map[string[i] & 127];
635
636     if (ch_pos == -1 || ch_pos > 22 * 2)
637       continue;                         /* no graphic for this character */
638
639     ch_x = (ch_pos % 22) * GFXMENUFONTX;
640     ch_y = (ch_pos / 22 + 12) * TILEY;
641
642 #if 1
643     SetClipOrigin(ttlBitmap, ttlBitmap->stored_clip_gc,
644                   x - ORIG_MENU_SX - ch_x, y - ORIG_MENU_SY - ch_y);
645
646     BlitBitmapMasked(ttlBitmap, screenBitmap, ch_x, ch_y, MENUFONTX, MENUFONTY,
647                      x - ORIG_MENU_SX, y - ORIG_MENU_SY);
648 #else
649     if (ttlmaskBitmap)
650       XSetClipOrigin(display, screenGC, x - ch_x, y - ch_y);
651
652     XCopyArea(display, ttlPixmap, screenPixmap, screenGC,
653               ch_x, ch_y, MENUFONTX, MENUFONTY, x, y);
654 #endif
655
656     x += MENUFONTX;
657   }
658
659 #if 1
660 #else
661   XSetClipMask(display, screenGC, None);
662 #endif
663 }
664
665 #endif