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 static GC tile_clip_gc = None;
29 static Pixmap tile_clipmask[NUM_FONTS][NUM_FONT_COLORS][NUM_FONT_CHARS];
35 } font_info[NUM_FONTS] =
37 { &font.bitmap_big, FONT1_XSIZE, FONT1_YSIZE },
38 { &font.bitmap_medium, FONT6_XSIZE, FONT6_YSIZE }
41 static void InitFontClipmasks()
43 #if defined(TARGET_X11_NATIVE)
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 */
112 void InitFontInfo(Bitmap *bitmap_initial,
113 Bitmap *bitmap_big, Bitmap *bitmap_medium,
114 Bitmap *bitmap_small, Bitmap *bitmap_tile)
116 font.bitmap_initial = bitmap_initial;
117 font.bitmap_big = bitmap_big;
118 font.bitmap_medium = bitmap_medium;
119 font.bitmap_small = bitmap_small;
120 font.bitmap_tile = bitmap_tile;
125 int getFontWidth(int font_size, int font_type)
127 return (font_type == FC_SPECIAL1 ? FONT3_XSIZE :
128 font_type == FC_SPECIAL2 ? FONT4_XSIZE :
129 font_type == FC_SPECIAL3 ? FONT5_XSIZE :
130 font_size == FS_BIG ? FONT1_XSIZE :
131 font_size == FS_MEDIUM ? FONT6_XSIZE :
132 font_size == FS_SMALL ? FONT2_XSIZE :
136 int getFontHeight(int font_size, int font_type)
138 return (font_type == FC_SPECIAL1 ? FONT3_YSIZE :
139 font_type == FC_SPECIAL2 ? FONT4_YSIZE :
140 font_type == FC_SPECIAL3 ? FONT5_YSIZE :
141 font_size == FS_BIG ? FONT1_YSIZE :
142 font_size == FS_MEDIUM ? FONT6_YSIZE :
143 font_size == FS_SMALL ? FONT2_YSIZE :
147 void DrawInitText(char *text, int ypos, int color)
149 if (window && font.bitmap_initial)
151 ClearRectangle(window, 0, ypos, video.width, FONT2_YSIZE);
152 DrawTextExt(window, (video.width - strlen(text) * FONT2_XSIZE)/2,
153 ypos, text, FS_INITIAL, color, FONT_OPAQUE);
158 void DrawTextFCentered(int y, int font_type, char *format, ...)
160 char buffer[MAX_OUTPUT_LINESIZE + 1];
161 int font_width = getFontWidth(FS_SMALL, font_type);
164 va_start(ap, format);
165 vsprintf(buffer, format, ap);
168 DrawText(gfx.sx + (gfx.sxsize - strlen(buffer) * font_width) / 2,
169 gfx.sy + y, buffer, FS_SMALL, font_type);
172 void DrawTextF(int x, int y, int font_type, char *format, ...)
174 char buffer[MAX_OUTPUT_LINESIZE + 1];
177 va_start(ap, format);
178 vsprintf(buffer, format, ap);
181 DrawText(gfx.sx + x, gfx.sy + y, buffer, FS_SMALL, font_type);
184 void DrawText(int x, int y, char *text, int font_size, int font_type)
186 int mask_mode = FONT_OPAQUE;
188 if (DrawingOnBackground(x, y))
189 mask_mode = FONT_MASKED;
191 DrawTextExt(drawto, x, y, text, font_size, font_type, mask_mode);
194 redraw_mask |= REDRAW_FIELD;
195 else if (y < gfx.vy || gfx.vy == 0)
196 redraw_mask |= REDRAW_DOOR_1;
199 void DrawTextExt(DrawBuffer *bitmap, int x, int y, char *text,
200 int font_size, int font_type, int mask_mode)
203 int font_width, font_height, font_starty;
204 boolean print_inverse = FALSE;
206 if (font_size != FS_BIG && font_size != FS_MEDIUM && font_size != FS_SMALL)
207 font_size = FS_INITIAL;
208 if (font_type < FC_RED || font_type > FC_SPECIAL3)
211 font_width = getFontWidth(font_size, font_type);
212 font_height = getFontHeight(font_size, font_type);
214 font_bitmap = (font_type == FC_SPECIAL2 ? font.bitmap_tile :
215 font_size == FS_BIG ? font.bitmap_big :
216 font_size == FS_MEDIUM ? font.bitmap_medium :
217 font_size == FS_SMALL ? font.bitmap_small :
218 font.bitmap_initial);
220 if (font_bitmap == NULL)
223 if (font_type == FC_SPECIAL2)
224 font_starty = (font_size == FS_BIG ? 0 : FONT1_YSIZE) * 5;
226 font_starty = (font_type * (font_size == FS_BIG ? FONT1_YSIZE :
227 font_size == FS_MEDIUM ? FONT6_YSIZE :
228 font_size == FS_SMALL ? FONT2_YSIZE :
230 FONT_LINES_PER_FONT);
232 if (font_type == FC_SPECIAL3)
233 font_starty -= FONT2_YSIZE * FONT_LINES_PER_FONT;
239 if (c == '~' && font_size == FS_SMALL)
241 print_inverse = TRUE;
245 if (c >= 'a' && c <= 'z')
247 else if (c == 'ä' || c == 'Ä')
249 else if (c == 'ö' || c == 'Ö')
251 else if (c == 'ü' || c == 'Ü')
253 else if (c == '[' || c == ']') /* map to normal braces */
254 c = (c == '[' ? '(' : ')');
255 else if (c == '\\') /* bad luck ... */
258 if ((c >= 32 && c <= 95) || c == '°' || c == '´' || c == '|')
260 int src_x = ((c - 32) % FONT_CHARS_PER_LINE) * font_width;
261 int src_y = ((c - 32) / FONT_CHARS_PER_LINE) * font_height + font_starty;
262 int dest_x = x, dest_y = y;
264 if (c == '°' || c == '´' || c == '|') /* map '°' and 'TM' signs */
266 if (font_type == FC_SPECIAL2)
268 src_x = (c == '°' ? 1 : c == '´' ? 2 : 3) * font_width;
269 src_y = 4 * font_height;
273 src_x = FONT_CHARS_PER_LINE * font_width;
274 src_y = (c == '°' ? 1 : c == '´' ? 2 : 3) * font_height +font_starty;
278 if (print_inverse) /* special mode for text gadgets */
280 /* first step: draw solid colored rectangle (use "cursor" character) */
281 BlitBitmap(font_bitmap, bitmap, FONT_CHARS_PER_LINE * font_width,
282 3 * font_height + font_starty,
283 font_width, font_height, x, y);
285 /* second step: draw masked black rectangle (use "space" character) */
286 SetClipOrigin(font_bitmap, font_bitmap->stored_clip_gc,
287 dest_x - src_x, dest_y - src_y);
288 BlitBitmapMasked(font_bitmap, bitmap,
289 0, 0, font_width, font_height, dest_x, dest_y);
291 else if (mask_mode == FONT_MASKED)
293 /* clear font character background */
294 BlitBitmap(gfx.background_bitmap, bitmap,
295 dest_x - gfx.real_sx, dest_y - gfx.real_sy,
296 font_width, font_height, dest_x, dest_y);
298 /* use special font tile clipmasks, if available */
299 if (font_size == FS_BIG || font_size == FS_MEDIUM)
301 int font_nr = (font_size == FS_BIG ? 0 : 1);
302 int font_char = (c >= 32 && c <= 95 ? c - 32 : 0);
304 SetClipMask(font_bitmap, tile_clip_gc,
305 tile_clipmask[font_nr][font_type][font_char]);
306 SetClipOrigin(font_bitmap, tile_clip_gc, dest_x, dest_y);
310 SetClipOrigin(font_bitmap, font_bitmap->stored_clip_gc,
311 dest_x - src_x, dest_y - src_y);
314 BlitBitmapMasked(font_bitmap, bitmap, src_x, src_y,
315 font_width, font_height, dest_x, dest_y);
317 else /* normal, non-masked font blitting */
319 BlitBitmap(font_bitmap, bitmap, src_x, src_y,
320 font_width, font_height, dest_x, dest_y);