1 /***********************************************************
2 * Artsoft Retro-Game Library *
3 *----------------------------------------------------------*
4 * (c) 1994-2006 Artsoft Entertainment *
6 * Detmolder Strasse 189 *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
12 ***********************************************************/
21 /* ========================================================================= */
23 /* ========================================================================= */
25 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
26 static GC font_clip_gc = None;
28 static void InitFontClipmasks()
30 XGCValues clip_gc_values;
31 unsigned int clip_gc_valuemask;
35 /* This stuff is needed because X11 (XSetClipOrigin(), to be precise) is
36 often very slow when preparing a masked XCopyArea() for big Pixmaps.
37 To prevent this, create small (tile-sized) mask Pixmaps which will then
38 be set much faster with XSetClipOrigin() and speed things up a lot. */
40 clip_gc_values.graphics_exposures = False;
41 clip_gc_valuemask = GCGraphicsExposures;
42 font_clip_gc = XCreateGC(display, window->drawable,
43 clip_gc_valuemask, &clip_gc_values);
45 /* create graphic context structures needed for clipping */
46 clip_gc_values.graphics_exposures = False;
47 clip_gc_valuemask = GCGraphicsExposures;
48 copy_clipmask_gc = XCreateGC(display,
49 gfx.font_bitmap_info[0].bitmap->clip_mask,
50 clip_gc_valuemask, &clip_gc_values);
52 /* create only those clipping Pixmaps we really need */
53 for (i = 0; i < gfx.num_fonts; i++)
55 if (gfx.font_bitmap_info[i].bitmap == NULL)
58 gfx.font_bitmap_info[i].clip_mask =
59 checked_calloc(gfx.font_bitmap_info[i].num_chars * sizeof(Pixmap));
61 for (j = 0; j < gfx.font_bitmap_info[i].num_chars; j++)
63 Bitmap *src_bitmap = gfx.font_bitmap_info[i].bitmap;
64 Pixmap src_pixmap = src_bitmap->clip_mask;
65 int xpos = j % gfx.font_bitmap_info[i].num_chars_per_line;
66 int ypos = j / gfx.font_bitmap_info[i].num_chars_per_line;
67 int width = gfx.font_bitmap_info[i].width;
68 int height = gfx.font_bitmap_info[i].height;
69 int src_x = gfx.font_bitmap_info[i].src_x + xpos * width;
70 int src_y = gfx.font_bitmap_info[i].src_y + ypos * height;
72 gfx.font_bitmap_info[i].clip_mask[j] =
73 XCreatePixmap(display, window->drawable, width, height, 1);
75 XCopyArea(display, src_pixmap, gfx.font_bitmap_info[i].clip_mask[j],
76 copy_clipmask_gc, src_x, src_y, width, height, 0, 0);
80 XFreeGC(display, copy_clipmask_gc);
83 static void FreeFontClipmasks()
87 if (gfx.num_fonts == 0 || gfx.font_bitmap_info[0].bitmap == NULL)
90 for (i = 0; i < gfx.num_fonts; i++)
92 if (gfx.font_bitmap_info[i].clip_mask)
94 for (j = 0; j < gfx.font_bitmap_info[i].num_chars; j++)
95 XFreePixmap(display, gfx.font_bitmap_info[i].clip_mask[j]);
96 free(gfx.font_bitmap_info[i].clip_mask);
99 gfx.font_bitmap_info[i].clip_mask = NULL;
100 gfx.font_bitmap_info[i].num_chars = 0;
104 XFreeGC(display, font_clip_gc);
107 #endif /* TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND */
109 void InitFontInfo(struct FontBitmapInfo *font_bitmap_info, int num_fonts,
110 int (*select_font_function)(int),
111 int (*get_font_from_token_function)(char *))
113 gfx.num_fonts = num_fonts;
114 gfx.font_bitmap_info = font_bitmap_info;
115 gfx.select_font_function = select_font_function;
116 gfx.get_font_from_token_function = get_font_from_token_function;
118 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
123 void FreeFontInfo(struct FontBitmapInfo *font_bitmap_info)
125 if (font_bitmap_info == NULL)
128 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
132 free(font_bitmap_info);
135 struct FontBitmapInfo *getFontBitmapInfo(int font_nr)
137 int font_bitmap_id = gfx.select_font_function(font_nr);
139 return &gfx.font_bitmap_info[font_bitmap_id];
142 int getFontWidth(int font_nr)
144 int font_bitmap_id = gfx.select_font_function(font_nr);
146 return gfx.font_bitmap_info[font_bitmap_id].width;
149 int getFontHeight(int font_nr)
151 int font_bitmap_id = gfx.select_font_function(font_nr);
153 return gfx.font_bitmap_info[font_bitmap_id].height;
156 int getTextWidth(char *text, int font_nr)
158 return (text != NULL ? strlen(text) * getFontWidth(font_nr) : 0);
161 static int getFontCharPosition(int font_nr, char c)
163 int font_bitmap_id = gfx.select_font_function(font_nr);
164 struct FontBitmapInfo *font = &gfx.font_bitmap_info[font_bitmap_id];
165 boolean default_font = (font->num_chars == DEFAULT_NUM_CHARS_PER_FONT);
166 int font_pos = (unsigned char)c - 32;
168 /* map some special characters to their ascii values in default font */
170 font_pos = MAP_FONT_ASCII(c) - 32;
172 /* this allows dynamic special characters together with special font */
173 if (font_pos < 0 || font_pos >= font->num_chars)
179 void getFontCharSource(int font_nr, char c, Bitmap **bitmap, int *x, int *y)
181 int font_bitmap_id = gfx.select_font_function(font_nr);
182 struct FontBitmapInfo *font = &gfx.font_bitmap_info[font_bitmap_id];
183 int font_pos = getFontCharPosition(font_nr, c);
185 *bitmap = font->bitmap;
186 *x = font->src_x + (font_pos % font->num_chars_per_line) * font->width;
187 *y = font->src_y + (font_pos / font->num_chars_per_line) * font->height;
191 /* ========================================================================= */
192 /* text string helper functions */
193 /* ========================================================================= */
195 int maxWordLengthInString(char *text)
198 int max_word_len = 0;
200 for (text_ptr = text; *text_ptr; text_ptr++)
201 max_word_len = (*text_ptr != ' ' ? max_word_len + 1 : 0);
207 /* ========================================================================= */
208 /* simple text drawing functions */
209 /* ========================================================================= */
211 void DrawInitTextExt(char *text, int ypos, int font_nr, boolean force)
213 static unsigned int progress_delay = 0;
214 unsigned int progress_delay_value = 100; /* (in milliseconds) */
218 if (!force && !DelayReached(&progress_delay, progress_delay_value))
221 if (window != NULL &&
222 gfx.draw_init_text &&
224 gfx.font_bitmap_info[font_nr].bitmap != NULL)
226 int x = (video.width - getTextWidth(text, font_nr)) / 2;
228 int width = video.width;
229 int height = getFontHeight(font_nr);
231 ClearRectangle(drawto, 0, y, width, height);
232 DrawTextExt(drawto, x, y, text, font_nr, BLIT_OPAQUE);
234 /* this makes things significantly faster than directly drawing to window */
235 BlitBitmap(drawto, window, 0, y, width, height, 0, y);
239 void DrawInitText(char *text, int ypos, int font_nr)
241 DrawInitTextExt(text, ypos, font_nr, TRUE);
244 void DrawInitTextIfNeeded(char *text, int ypos, int font_nr)
246 DrawInitTextExt(text, ypos, font_nr, FALSE);
249 void DrawTextF(int x, int y, int font_nr, char *format, ...)
251 char buffer[MAX_OUTPUT_LINESIZE + 1];
254 va_start(ap, format);
255 vsprintf(buffer, format, ap);
258 if (strlen(buffer) > MAX_OUTPUT_LINESIZE)
259 Error(ERR_EXIT, "string too long in DrawTextF() -- aborting");
261 DrawText(gfx.sx + x, gfx.sy + y, buffer, font_nr);
264 void DrawTextFCentered(int y, int font_nr, char *format, ...)
266 char buffer[MAX_OUTPUT_LINESIZE + 1];
269 va_start(ap, format);
270 vsprintf(buffer, format, ap);
273 if (strlen(buffer) > MAX_OUTPUT_LINESIZE)
274 Error(ERR_EXIT, "string too long in DrawTextFCentered() -- aborting");
276 DrawText(gfx.sx + (gfx.sxsize - getTextWidth(buffer, font_nr)) / 2,
277 gfx.sy + y, buffer, font_nr);
280 void DrawTextS(int x, int y, int font_nr, char *text)
282 DrawText(gfx.sx + x, gfx.sy + y, text, font_nr);
285 void DrawTextSCentered(int y, int font_nr, char *text)
287 DrawText(gfx.sx + (gfx.sxsize - getTextWidth(text, font_nr)) / 2,
288 gfx.sy + y, text, font_nr);
291 void DrawTextCentered(int y, int font_nr, char *text)
293 DrawText((gfx.sxsize - getTextWidth(text, font_nr)) / 2, y, text, font_nr);
296 void DrawTextSAligned(int x, int y, char *text, int font_nr, int align)
298 DrawText(gfx.sx + ALIGNED_XPOS(x, getTextWidth(text, font_nr), align),
299 gfx.sx + y, text, font_nr);
302 void DrawTextAligned(int x, int y, char *text, int font_nr, int align)
304 DrawText(ALIGNED_XPOS(x, getTextWidth(text, font_nr), align),
308 void DrawText(int x, int y, char *text, int font_nr)
310 int mask_mode = BLIT_OPAQUE;
312 if (DrawingOnBackground(x, y))
313 mask_mode = BLIT_ON_BACKGROUND;
315 DrawTextExt(drawto, x, y, text, font_nr, mask_mode);
318 redraw_mask |= REDRAW_FIELD;
319 else if (y < gfx.vy || gfx.vy == 0)
320 redraw_mask |= REDRAW_DOOR_1;
323 void DrawTextExt(DrawBuffer *dst_bitmap, int dst_x, int dst_y, char *text,
324 int font_nr, int mask_mode)
327 struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
329 int font_bitmap_id = gfx.select_font_function(font_nr);
330 struct FontBitmapInfo *font = &gfx.font_bitmap_info[font_bitmap_id];
332 int font_width = getFontWidth(font_nr);
333 int font_height = getFontHeight(font_nr);
335 int border_1 = gfx.sx + gfx.sxsize;
336 int border_2 = gfx.dx + gfx.dxsize;
337 int dst_x_start = dst_x;
341 char *text_ptr = text;
343 if (font->bitmap == NULL)
346 /* skip text to be printed outside the window (left/right will be clipped) */
347 if (dst_y < 0 || dst_y + font_height > video.height)
350 /* add offset for drawing font characters */
351 dst_x += font->draw_xoffset;
352 dst_y += font->draw_yoffset;
356 char c = *text_ptr++;
359 c = ' '; /* print space instead of newline */
361 getFontCharSource(font_nr, c, &src_bitmap, &src_x, &src_y);
363 /* clip text at the left side of the window */
371 /* clip text at the right side of the window */
373 if (dst_x + font_width > video.width)
376 /* (this does not work well when trying to print text to whole screen) */
377 if ((dst_x_start < border_1 && dst_x + font_width > border_1) ||
378 (dst_x_start < border_2 && dst_x + font_width > border_2))
382 if (mask_mode == BLIT_INVERSE) /* special mode for text gadgets */
384 /* first step: draw solid colored rectangle (use "cursor" character) */
385 if (strlen(text) == 1) /* only one char inverted => draw cursor */
387 Bitmap *cursor_bitmap;
388 int cursor_x, cursor_y;
390 getFontCharSource(font_nr, FONT_ASCII_CURSOR, &cursor_bitmap,
391 &cursor_x, &cursor_y);
393 BlitBitmap(cursor_bitmap, dst_bitmap, cursor_x, cursor_y,
394 font_width, font_height, dst_x, dst_y);
397 #if defined(TARGET_SDL)
398 /* second step: draw masked inverted character */
399 SDLCopyInverseMasked(src_bitmap, dst_bitmap, src_x, src_y,
400 font_width, font_height, dst_x, dst_y);
402 /* second step: draw masked black rectangle (use "space" character) */
403 SetClipOrigin(src_bitmap, src_bitmap->stored_clip_gc,
404 dst_x - src_x, dst_y - src_y);
405 BlitBitmapMasked(src_bitmap, dst_bitmap, 0, 0,
406 font_width, font_height, dst_x, dst_y);
409 else if (mask_mode == BLIT_MASKED || mask_mode == BLIT_ON_BACKGROUND)
411 if (mask_mode == BLIT_ON_BACKGROUND)
413 /* clear font character background */
414 ClearRectangleOnBackground(dst_bitmap, dst_x, dst_y,
415 font_width, font_height);
418 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
419 /* use special font tile clipmasks */
421 int font_pos = getFontCharPosition(font_nr, c);
423 SetClipMask(src_bitmap, font_clip_gc, font->clip_mask[font_pos]);
424 SetClipOrigin(src_bitmap, font_clip_gc, dst_x, dst_y);
427 SetClipOrigin(src_bitmap, src_bitmap->stored_clip_gc,
428 dst_x - src_x, dst_y - src_y);
431 BlitBitmapMasked(src_bitmap, dst_bitmap, src_x, src_y,
432 font_width, font_height, dst_x, dst_y);
434 else /* normal, non-masked font blitting */
436 BlitBitmap(src_bitmap, dst_bitmap, src_x, src_y,
437 font_width, font_height, dst_x, dst_y);
445 /* ========================================================================= */
446 /* text buffer drawing functions */
447 /* ========================================================================= */
449 #define MAX_LINES_FROM_FILE 1024
453 char *GetTextBufferFromFile(char *filename, int max_lines)
459 if (filename == NULL)
462 if (!(file = openFile(filename, MODE_READ)))
465 buffer = checked_calloc(1); /* start with valid, but empty text buffer */
467 while (!checkEndOfFile(file) && num_lines < max_lines)
469 char line[MAX_LINE_LEN];
471 /* read next line of input file */
472 if (!getStringFromFile(file, line, MAX_LINE_LEN))
475 buffer = checked_realloc(buffer, strlen(buffer) + strlen(line) + 1);
477 strcat(buffer, line);
489 char *GetTextBufferFromFile(char *filename, int max_lines)
495 if (filename == NULL)
498 if (!(file = fopen(filename, MODE_READ)))
501 buffer = checked_calloc(1); /* start with valid, but empty text buffer */
503 while (!feof(file) && num_lines < max_lines)
505 char line[MAX_LINE_LEN];
507 /* read next line of input file */
508 if (!fgets(line, MAX_LINE_LEN, file))
511 buffer = checked_realloc(buffer, strlen(buffer) + strlen(line) + 1);
513 strcat(buffer, line);
525 void DrawTextToTextArea_OLD(int x, int y, char *text, int font_nr, int line_length,
526 int area_xsize, int area_ysize, int mask_mode)
529 int font_height = getFontHeight(font_nr);
534 while (*text && area_line < area_ysize)
536 char buffer[MAX_OUTPUT_LINESIZE + 1];
539 for (i = 0; i < line_length && *text; i++)
540 if ((buffer[i] = *text++) == '\n')
542 buffer[MIN(i, area_xsize)] = '\0';
544 DrawTextExt(drawto, x, y + area_line * font_height, buffer, font_nr,
550 redraw_mask |= REDRAW_FIELD;
553 static boolean RenderLineToBuffer(char **src_buffer_ptr, char *dst_buffer,
554 int *dst_buffer_len, int line_length,
555 boolean last_line_was_empty)
557 char *text_ptr = *src_buffer_ptr;
558 char *buffer = dst_buffer;
559 int buffer_len = *dst_buffer_len;
560 boolean buffer_filled = FALSE;
567 /* skip leading whitespaces */
568 while (*text_ptr == ' ' || *text_ptr == '\t')
574 /* look for end of next word */
575 while (*word_ptr != ' ' && *word_ptr != '\t' && *word_ptr != '\0')
585 else if (*text_ptr == '\n') /* special case: force empty line */
590 /* prevent printing of multiple empty lines */
591 if (buffer_len > 0 || !last_line_was_empty)
592 buffer_filled = TRUE;
594 else if (word_len < line_length - buffer_len)
596 /* word fits into text buffer -- add word */
599 buffer[buffer_len++] = ' ';
601 strncpy(&buffer[buffer_len], text_ptr, word_len);
602 buffer_len += word_len;
603 buffer[buffer_len] = '\0';
604 text_ptr += word_len;
606 else if (buffer_len > 0)
608 /* not enough space left for word in text buffer -- print buffer */
610 buffer_filled = TRUE;
614 /* word does not fit at all into empty text buffer -- cut word */
616 strncpy(buffer, text_ptr, line_length);
617 buffer[line_length] = '\0';
618 text_ptr += line_length;
619 buffer_filled = TRUE;
626 *src_buffer_ptr = text_ptr;
627 *dst_buffer_len = buffer_len;
629 return buffer_filled;
633 void DrawTextWrapped_OLD(int x, int y, char *text, int font_nr, int line_length,
636 char *text_ptr = text;
637 int current_line = 0;
638 int font_height = getFontHeight(font_nr);
640 while (*text_ptr && current_line < max_lines)
642 char buffer[line_length + 1];
647 RenderLineToBuffer(&text_ptr, buffer, &buffer_len, line_length, TRUE);
649 DrawText(x, y + current_line * font_height, buffer, font_nr);
656 int DrawTextFromFile_OLD(int x, int y, char *filename, int font_nr,
657 int line_length, int max_lines, boolean wrap_text)
659 int font_height = getFontHeight(font_nr);
660 char line[MAX_LINE_LEN];
661 char buffer[line_length + 1];
663 int current_line = 0;
666 if (current_line >= max_lines)
669 if (filename == NULL)
672 if (!(file = fopen(filename, MODE_READ)))
678 while (!feof(file) && current_line < max_lines)
681 boolean last_line_was_empty = TRUE;
683 /* read next line of input file */
684 if (!fgets(line, MAX_LINE_LEN, file))
687 /* skip comments (lines directly beginning with '#') */
691 /* cut trailing newline from input line */
692 for (line_ptr = line; *line_ptr; line_ptr++)
694 if (*line_ptr == '\n' || *line_ptr == '\r')
701 if (strlen(line) == 0) /* special case: force empty line */
706 while (*line_ptr && current_line < max_lines)
709 boolean buffer_filled;
713 buffer_filled = RenderLineToBuffer(&line_ptr, buffer, &buffer_len,
714 line_length, last_line_was_empty);
718 if (strlen(line_ptr) <= line_length)
720 buffer_len = strlen(line_ptr);
721 strcpy(buffer, line_ptr);
725 buffer_len = line_length;
726 strncpy(buffer, line_ptr, line_length);
729 buffer[buffer_len] = '\0';
730 line_ptr += buffer_len;
732 buffer_filled = TRUE;
735 boolean buffer_filled = RenderLineToBuffer(&line_ptr, buffer, &buffer_len,
736 line_length, last_line_was_empty);
741 DrawText(x, y + current_line * font_height, buffer, font_nr);
744 last_line_was_empty = (buffer_len == 0);
754 if (buffer_len > 0 && current_line < max_lines)
756 DrawText(x, y + current_line * font_height, buffer, font_nr);
764 static boolean getCheckedTokenValueFromString(char *string, char **token,
769 if (!getTokenValueFromString(string, token, value))
772 if (**token != '.') /* token should begin with dot */
775 for (ptr = *token; *ptr; ptr++) /* token should contain no whitespace */
776 if (*ptr == ' ' || *ptr == '\t')
779 for (ptr = *value; *ptr; ptr++) /* value should contain no whitespace */
780 if (*ptr == ' ' || *ptr == '\t')
786 static void DrawTextBuffer_Flush(int x, int y, char *buffer, int font_nr,
787 int line_length, int cut_length,
788 int line_spacing, int mask_mode,
789 boolean centered, int current_line)
791 int buffer_len = strlen(buffer);
792 int font_width = getFontWidth(font_nr);
793 int font_height = getFontHeight(font_nr);
794 int offset_chars = (centered ? (line_length - buffer_len) / 2 : 0);
796 (centered ? font_width * (line_length - buffer_len) / 2 : 0);
797 int final_cut_length = MAX(0, cut_length - offset_chars);
798 int xx = x + offset_xsize;
799 int yy = y + current_line * (font_height + line_spacing);
801 buffer[final_cut_length] = '\0';
804 DrawTextExt(drawto, xx, yy, buffer, font_nr, mask_mode);
806 DrawText(xx, yy, buffer, font_nr);
809 int DrawTextBuffer(int x, int y, char *text_buffer, int font_nr,
810 int line_length, int cut_length, int max_lines,
811 int line_spacing, int mask_mode, boolean autowrap,
812 boolean centered, boolean parse_comments)
815 int font_width = getFontWidth(font_nr);
816 int font_height = getFontHeight(font_nr);
818 char buffer[line_length + 1];
820 int current_line = 0;
822 if (text_buffer == NULL || *text_buffer == '\0')
825 if (current_line >= max_lines)
828 if (cut_length == -1)
829 cut_length = line_length;
834 while (*text_buffer && current_line < max_lines)
836 char line[MAX_LINE_LEN + 1];
838 boolean last_line_was_empty = TRUE;
840 int num_line_chars = MAX_LINE_LEN;
842 int num_line_chars = (autowrap ? MAX_LINE_LEN : line_length);
846 /* copy next line from text buffer to line buffer (nearly fgets() style) */
847 for (i = 0; i < num_line_chars && *text_buffer; i++)
848 if ((line[i] = *text_buffer++) == '\n')
852 /* prevent 'num_line_chars' sized lines to cause additional empty line */
853 if (i == num_line_chars && *text_buffer == '\n')
856 /* skip comments (lines directly beginning with '#') */
857 if (line[0] == '#' && parse_comments)
861 /* try to read generic token/value pair definition after comment sign */
862 if (getCheckedTokenValueFromString(line + 1, &token, &value))
864 /* if found, flush the current buffer, if non-empty */
865 if (buffer_len > 0 && current_line < max_lines)
867 DrawTextBuffer_Flush(x, y, buffer, font_nr, line_length, cut_length,
868 line_spacing, mask_mode, centered, current_line);
876 if (strEqual(token, ".font"))
877 font_nr = gfx.get_font_from_token_function(value);
878 else if (strEqual(token, ".autowrap"))
879 autowrap = get_boolean_from_string(value);
880 else if (strEqual(token, ".centered"))
881 centered = get_boolean_from_string(value);
882 else if (strEqual(token, ".parse_comments"))
883 parse_comments = get_boolean_from_string(value);
889 /* cut trailing newline and carriage return from input line */
890 for (line_ptr = line; *line_ptr; line_ptr++)
892 if (*line_ptr == '\n' || *line_ptr == '\r')
899 if (strlen(line) == 0) /* special case: force empty line */
904 while (*line_ptr && current_line < max_lines)
906 boolean buffer_filled;
910 buffer_filled = RenderLineToBuffer(&line_ptr, buffer, &buffer_len,
911 line_length, last_line_was_empty);
915 if (strlen(line_ptr) <= line_length)
917 buffer_len = strlen(line_ptr);
918 strcpy(buffer, line_ptr);
922 buffer_len = line_length;
923 strncpy(buffer, line_ptr, line_length);
926 buffer[buffer_len] = '\0';
927 line_ptr += buffer_len;
929 buffer_filled = TRUE;
935 DrawTextBuffer_Flush(x, y, buffer, font_nr, line_length, cut_length,
936 line_spacing, mask_mode, centered, current_line);
938 int offset_chars = (centered ? (line_length - buffer_len) / 2 : 0);
940 (centered ? font_width * (line_length - buffer_len) / 2 : 0);
941 int final_cut_length = MAX(0, cut_length - offset_chars);
942 int xx = x + offset_xsize;
944 buffer[final_cut_length] = '\0';
947 DrawTextExt(drawto, xx, y + current_line * font_height, buffer,
950 DrawText(xx, y + current_line * font_height, buffer, font_nr);
955 last_line_was_empty = (buffer_len == 0);
963 if (buffer_len > 0 && current_line < max_lines)
966 DrawTextBuffer_Flush(x, y, buffer, font_nr, line_length, cut_length,
967 line_spacing, mask_mode, centered, current_line);
969 int offset_chars = (centered ? (line_length - buffer_len) / 2 : 0);
971 (centered ? font_width * (line_length - buffer_len) / 2 : 0);
972 int final_cut_length = MAX(0, cut_length - offset_chars);
973 int xx = x + offset_xsize;
975 buffer[final_cut_length] = '\0';
978 DrawTextExt(drawto, xx, y + current_line * font_height, buffer,
981 DrawText(xx, y + current_line * font_height, buffer, font_nr);
990 int DrawTextBufferVA(int x, int y, char *format, va_list ap, int font_nr,
991 int line_length, int cut_length, int max_lines,
992 int line_spacing, int mask_mode, boolean autowrap,
993 boolean centered, boolean parse_comments)
995 char text_buffer[MAX_OUTPUT_LINESIZE];
996 int text_length = vsnprintf(text_buffer, MAX_OUTPUT_LINESIZE, format, ap);
998 if (text_length >= MAX_OUTPUT_LINESIZE)
999 Error(ERR_WARN, "string too long in DrawTextBufferVA() -- truncated");
1001 int num_lines_printed = DrawTextBuffer(x, y, text_buffer, font_nr,
1002 line_length, cut_length, max_lines,
1003 line_spacing, mask_mode, autowrap,
1004 centered, parse_comments);
1005 return num_lines_printed;
1008 int DrawTextFile(int x, int y, char *filename, int font_nr,
1009 int line_length, int cut_length, int max_lines,
1010 int line_spacing, int mask_mode, boolean autowrap,
1011 boolean centered, boolean parse_comments)
1013 char *text_buffer = GetTextBufferFromFile(filename, MAX_LINES_FROM_FILE);
1014 int num_lines_printed = DrawTextBuffer(x, y, text_buffer, font_nr,
1015 line_length, cut_length, max_lines,
1016 line_spacing, mask_mode, autowrap,
1017 centered, parse_comments);
1018 checked_free(text_buffer);
1020 return num_lines_printed;
1024 void DrawTextWrapped(int x, int y, char *text, int font_nr, int line_length,
1027 DrawTextBuffer(x, y, text, font_nr, line_length, -1, max_lines, -1, TRUE,
1031 void DrawTextToTextArea(int x, int y, char *text, int font_nr, int line_length,
1032 int cut_length, int max_lines, int mask_mode)
1034 DrawTextBuffer(x, y, text, font_nr, line_length, cut_length, max_lines,
1035 mask_mode, FALSE, FALSE, FALSE);