1 /***********************************************************
2 * Artsoft Retro-Game Library *
3 *----------------------------------------------------------*
4 * (c) 1994-2002 Artsoft Entertainment *
6 * Detmolder Strasse 189 *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
12 ***********************************************************/
20 /* ========================================================================= */
22 /* ========================================================================= */
25 #define NUM_FONT_COLORS 4
26 #define NUM_FONT_CHARS (FONT_LINES_PER_FONT * FONT_CHARS_PER_LINE)
28 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
29 static GC tile_clip_gc = None;
30 static Pixmap tile_clipmask[NUM_FONTS][NUM_FONT_COLORS][NUM_FONT_CHARS];
36 } font_info[NUM_FONTS] =
38 { &font.bitmap_big, FONT1_XSIZE, FONT1_YSIZE },
39 { &font.bitmap_medium, FONT6_XSIZE, FONT6_YSIZE }
42 static void InitFontClipmasks()
44 static boolean clipmasks_initialized = FALSE;
45 boolean fonts_initialized = TRUE;
46 XGCValues clip_gc_values;
47 unsigned long clip_gc_valuemask;
51 for (i=0; i<NUM_FONTS; i++)
52 if (*font_info[i].bitmap == NULL)
53 fonts_initialized = FALSE;
55 if (!fonts_initialized)
58 if (clipmasks_initialized)
59 for (i=0; i<NUM_FONTS; i++)
60 for (j=0; j<NUM_FONT_COLORS; j++)
61 for (k=0; k<NUM_FONT_CHARS; k++)
62 XFreePixmap(display, tile_clipmask[i][j][k]);
65 XFreeGC(display, tile_clip_gc);
68 /* This stuff is needed because X11 (XSetClipOrigin(), to be precise) is
69 often very slow when preparing a masked XCopyArea() for big Pixmaps.
70 To prevent this, create small (tile-sized) mask Pixmaps which will then
71 be set much faster with XSetClipOrigin() and speed things up a lot. */
73 clip_gc_values.graphics_exposures = False;
74 clip_gc_valuemask = GCGraphicsExposures;
75 tile_clip_gc = XCreateGC(display, window->drawable,
76 clip_gc_valuemask, &clip_gc_values);
78 /* create graphic context structures needed for clipping */
79 clip_gc_values.graphics_exposures = False;
80 clip_gc_valuemask = GCGraphicsExposures;
81 copy_clipmask_gc = XCreateGC(display, (*font_info[0].bitmap)->clip_mask,
82 clip_gc_valuemask, &clip_gc_values);
84 /* create only those clipping Pixmaps we really need */
85 for (i=0; i<NUM_FONTS; i++)
86 for (j=0; j<NUM_FONT_COLORS; j++)
87 for (k=0; k<NUM_FONT_CHARS; k++)
89 Bitmap *src_bitmap = *font_info[i].bitmap;
90 Pixmap src_pixmap = src_bitmap->clip_mask;
91 int xpos = k % FONT_CHARS_PER_LINE;
92 int ypos = k / FONT_CHARS_PER_LINE;
93 int xsize = font_info[i].xsize;
94 int ysize = font_info[i].ysize;
95 int src_x = xsize * xpos;
96 int src_y = ysize * (ypos + j * FONT_LINES_PER_FONT);
98 tile_clipmask[i][j][k] =
99 XCreatePixmap(display, window->drawable, xsize, ysize, 1);
101 XCopyArea(display, src_pixmap, tile_clipmask[i][j][k], copy_clipmask_gc,
102 src_x, src_y, xsize, ysize, 0, 0);
105 XFreeGC(display, copy_clipmask_gc);
107 clipmasks_initialized = TRUE;
109 #endif /* TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND */
111 void InitFontInfo(Bitmap *bitmap_initial,
112 Bitmap *bitmap_big, Bitmap *bitmap_medium,
113 Bitmap *bitmap_small, Bitmap *bitmap_tile)
115 font.bitmap_initial = bitmap_initial;
116 font.bitmap_big = bitmap_big;
117 font.bitmap_medium = bitmap_medium;
118 font.bitmap_small = bitmap_small;
119 font.bitmap_tile = bitmap_tile;
121 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
126 int getFontWidth(int font_size, int font_type)
128 return (font_type == FC_SPECIAL1 ? FONT3_XSIZE :
129 font_type == FC_SPECIAL2 ? FONT4_XSIZE :
130 font_type == FC_SPECIAL3 ? FONT5_XSIZE :
131 font_size == FS_BIG ? FONT1_XSIZE :
132 font_size == FS_MEDIUM ? FONT6_XSIZE :
133 font_size == FS_SMALL ? FONT2_XSIZE :
137 int getFontHeight(int font_size, int font_type)
139 return (font_type == FC_SPECIAL1 ? FONT3_YSIZE :
140 font_type == FC_SPECIAL2 ? FONT4_YSIZE :
141 font_type == FC_SPECIAL3 ? FONT5_YSIZE :
142 font_size == FS_BIG ? FONT1_YSIZE :
143 font_size == FS_MEDIUM ? FONT6_YSIZE :
144 font_size == FS_SMALL ? FONT2_YSIZE :
148 void DrawInitText(char *text, int ypos, int color)
150 if (window && font.bitmap_initial)
152 ClearRectangle(window, 0, ypos, video.width, FONT2_YSIZE);
153 DrawTextExt(window, (video.width - strlen(text) * FONT2_XSIZE)/2,
154 ypos, text, FS_INITIAL, color, FONT_OPAQUE);
159 void DrawTextFCentered(int y, int font_type, char *format, ...)
161 char buffer[MAX_OUTPUT_LINESIZE + 1];
162 int font_width = getFontWidth(FS_SMALL, font_type);
165 va_start(ap, format);
166 vsprintf(buffer, format, ap);
169 DrawText(gfx.sx + (gfx.sxsize - strlen(buffer) * font_width) / 2,
170 gfx.sy + y, buffer, FS_SMALL, font_type);
173 void DrawTextF(int x, int y, int font_type, char *format, ...)
175 char buffer[MAX_OUTPUT_LINESIZE + 1];
178 va_start(ap, format);
179 vsprintf(buffer, format, ap);
182 DrawText(gfx.sx + x, gfx.sy + y, buffer, FS_SMALL, font_type);
185 void DrawText(int x, int y, char *text, int font_size, int font_type)
187 int mask_mode = FONT_OPAQUE;
189 if (DrawingOnBackground(x, y))
190 mask_mode = FONT_MASKED;
192 DrawTextExt(drawto, x, y, text, font_size, font_type, mask_mode);
195 redraw_mask |= REDRAW_FIELD;
196 else if (y < gfx.vy || gfx.vy == 0)
197 redraw_mask |= REDRAW_DOOR_1;
200 void DrawTextExt(DrawBuffer *bitmap, int x, int y, char *text,
201 int font_size, int font_type, int mask_mode)
204 int font_width, font_height, font_starty;
205 boolean print_inverse = FALSE;
207 if (font_size != FS_BIG && font_size != FS_MEDIUM && font_size != FS_SMALL)
208 font_size = FS_INITIAL;
209 if (font_type < FC_RED || font_type > FC_SPECIAL3)
212 font_width = getFontWidth(font_size, font_type);
213 font_height = getFontHeight(font_size, font_type);
215 font_bitmap = (font_type == FC_SPECIAL2 ? font.bitmap_tile :
216 font_size == FS_BIG ? font.bitmap_big :
217 font_size == FS_MEDIUM ? font.bitmap_medium :
218 font_size == FS_SMALL ? font.bitmap_small :
219 font.bitmap_initial);
221 if (font_bitmap == NULL)
224 if (font_type == FC_SPECIAL2)
225 font_starty = (font_size == FS_BIG ? 0 : FONT1_YSIZE) * 5;
227 font_starty = (font_type * (font_size == FS_BIG ? FONT1_YSIZE :
228 font_size == FS_MEDIUM ? FONT6_YSIZE :
229 font_size == FS_SMALL ? FONT2_YSIZE :
231 FONT_LINES_PER_FONT);
233 if (font_type == FC_SPECIAL3)
234 font_starty -= FONT2_YSIZE * FONT_LINES_PER_FONT;
240 if (c == '~' && font_size == FS_SMALL)
242 print_inverse = TRUE;
246 if (c >= 'a' && c <= 'z')
248 else if (c == 'ä' || c == 'Ä')
250 else if (c == 'ö' || c == 'Ö')
252 else if (c == 'ü' || c == 'Ü')
254 else if (c == '[' || c == ']') /* map to normal braces */
255 c = (c == '[' ? '(' : ')');
256 else if (c == '\\') /* bad luck ... */
259 if ((c >= 32 && c <= 95) || c == '°' || c == '´' || c == '|')
261 int src_x = ((c - 32) % FONT_CHARS_PER_LINE) * font_width;
262 int src_y = ((c - 32) / FONT_CHARS_PER_LINE) * font_height + font_starty;
263 int dest_x = x, dest_y = y;
265 if (c == '°' || c == '´' || c == '|') /* map '°' and 'TM' signs */
267 if (font_type == FC_SPECIAL2)
269 src_x = (c == '°' ? 1 : c == '´' ? 2 : 3) * font_width;
270 src_y = 4 * font_height;
274 src_x = FONT_CHARS_PER_LINE * font_width;
275 src_y = (c == '°' ? 1 : c == '´' ? 2 : 3) * font_height +font_starty;
279 if (print_inverse) /* special mode for text gadgets */
281 /* first step: draw solid colored rectangle (use "cursor" character) */
282 BlitBitmap(font_bitmap, bitmap, FONT_CHARS_PER_LINE * font_width,
283 3 * font_height + font_starty,
284 font_width, font_height, x, y);
286 /* second step: draw masked black rectangle (use "space" character) */
287 SetClipOrigin(font_bitmap, font_bitmap->stored_clip_gc,
288 dest_x - src_x, dest_y - src_y);
289 BlitBitmapMasked(font_bitmap, bitmap,
290 0, 0, font_width, font_height, dest_x, dest_y);
292 else if (mask_mode == FONT_MASKED)
294 /* clear font character background */
295 ClearRectangleOnBackground(bitmap, dest_x, dest_y,
296 font_width, font_height);
298 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
299 /* use special font tile clipmasks, if available */
300 if (font_size == FS_BIG || font_size == FS_MEDIUM)
302 int font_nr = (font_size == FS_BIG ? 0 : 1);
303 int font_char = (c >= 32 && c <= 95 ? c - 32 : 0);
305 SetClipMask(font_bitmap, tile_clip_gc,
306 tile_clipmask[font_nr][font_type][font_char]);
307 SetClipOrigin(font_bitmap, tile_clip_gc, dest_x, dest_y);
311 SetClipOrigin(font_bitmap, font_bitmap->stored_clip_gc,
312 dest_x - src_x, dest_y - src_y);
315 SetClipOrigin(font_bitmap, font_bitmap->stored_clip_gc,
316 dest_x - src_x, dest_y - src_y);
319 BlitBitmapMasked(font_bitmap, bitmap, src_x, src_y,
320 font_width, font_height, dest_x, dest_y);
322 else /* normal, non-masked font blitting */
324 BlitBitmap(font_bitmap, bitmap, src_x, src_y,
325 font_width, font_height, dest_x, dest_y);