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)
215 static unsigned int progress_delay = 0;
216 unsigned int progress_delay_value = 100; /* (in milliseconds) */
219 // LimitScreenUpdates(TRUE); // (ignore "force" for now)
220 // LimitScreenUpdates(!force);
221 LimitScreenUpdates(TRUE);
226 if (!force && !DelayReached(&progress_delay, progress_delay_value))
230 if (window != NULL &&
231 gfx.draw_init_text &&
233 gfx.font_bitmap_info[font_nr].bitmap != NULL)
235 int x = (video.width - getTextWidth(text, font_nr)) / 2;
237 int width = video.width;
238 int height = getFontHeight(font_nr);
240 ClearRectangle(drawto, 0, y, width, height);
241 DrawTextExt(drawto, x, y, text, font_nr, BLIT_OPAQUE);
243 BlitBitmap(drawto, window, 0, 0, video.width, video.height, 0, 0);
246 static unsigned int progress_delay = 0;
247 unsigned int progress_delay_value = 100; /* (in milliseconds) */
249 // LimitScreenUpdates(TRUE); // (ignore "force" for now)
250 LimitScreenUpdates(!force);
254 if (!force && !DelayReached(&progress_delay, progress_delay_value))
257 if (window != NULL &&
258 gfx.draw_init_text &&
260 gfx.font_bitmap_info[font_nr].bitmap != NULL)
262 int x = (video.width - getTextWidth(text, font_nr)) / 2;
264 int width = video.width;
265 int height = getFontHeight(font_nr);
267 ClearRectangle(drawto, 0, y, width, height);
268 DrawTextExt(drawto, x, y, text, font_nr, BLIT_OPAQUE);
270 /* this makes things significantly faster than directly drawing to window */
271 BlitBitmap(drawto, window, 0, y, width, height, 0, y);
276 void DrawInitText(char *text, int ypos, int font_nr)
278 // DrawInitTextExt(text, ypos, font_nr, TRUE);
279 DrawInitTextExt(text, ypos, font_nr, FALSE);
282 void DrawInitTextAlways(char *text, int ypos, int font_nr)
284 DrawInitTextExt(text, ypos, font_nr, TRUE);
287 void DrawInitTextIfNeeded(char *text, int ypos, int font_nr)
289 DrawInitTextExt(text, ypos, font_nr, FALSE);
292 void DrawTextF(int x, int y, int font_nr, char *format, ...)
294 char buffer[MAX_OUTPUT_LINESIZE + 1];
297 va_start(ap, format);
298 vsprintf(buffer, format, ap);
301 if (strlen(buffer) > MAX_OUTPUT_LINESIZE)
302 Error(ERR_EXIT, "string too long in DrawTextF() -- aborting");
304 DrawText(gfx.sx + x, gfx.sy + y, buffer, font_nr);
307 void DrawTextFCentered(int y, int font_nr, char *format, ...)
309 char buffer[MAX_OUTPUT_LINESIZE + 1];
312 va_start(ap, format);
313 vsprintf(buffer, format, ap);
316 if (strlen(buffer) > MAX_OUTPUT_LINESIZE)
317 Error(ERR_EXIT, "string too long in DrawTextFCentered() -- aborting");
319 DrawText(gfx.sx + (gfx.sxsize - getTextWidth(buffer, font_nr)) / 2,
320 gfx.sy + y, buffer, font_nr);
323 void DrawTextS(int x, int y, int font_nr, char *text)
325 DrawText(gfx.sx + x, gfx.sy + y, text, font_nr);
328 void DrawTextSCentered(int y, int font_nr, char *text)
330 DrawText(gfx.sx + (gfx.sxsize - getTextWidth(text, font_nr)) / 2,
331 gfx.sy + y, text, font_nr);
334 void DrawTextCentered(int y, int font_nr, char *text)
336 DrawText((gfx.sxsize - getTextWidth(text, font_nr)) / 2, y, text, font_nr);
339 void DrawTextSAligned(int x, int y, char *text, int font_nr, int align)
341 DrawText(gfx.sx + ALIGNED_XPOS(x, getTextWidth(text, font_nr), align),
342 gfx.sx + y, text, font_nr);
345 void DrawTextAligned(int x, int y, char *text, int font_nr, int align)
347 DrawText(ALIGNED_XPOS(x, getTextWidth(text, font_nr), align),
351 void DrawText(int x, int y, char *text, int font_nr)
353 int mask_mode = BLIT_OPAQUE;
355 if (DrawingOnBackground(x, y))
356 mask_mode = BLIT_ON_BACKGROUND;
358 DrawTextExt(drawto, x, y, text, font_nr, mask_mode);
361 redraw_mask |= REDRAW_FIELD;
362 else if (y < gfx.vy || gfx.vy == 0)
363 redraw_mask |= REDRAW_DOOR_1;
366 void DrawTextExt(DrawBuffer *dst_bitmap, int dst_x, int dst_y, char *text,
367 int font_nr, int mask_mode)
370 struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
372 int font_bitmap_id = gfx.select_font_function(font_nr);
373 struct FontBitmapInfo *font = &gfx.font_bitmap_info[font_bitmap_id];
375 int font_width = getFontWidth(font_nr);
376 int font_height = getFontHeight(font_nr);
378 int border_1 = gfx.sx + gfx.sxsize;
379 int border_2 = gfx.dx + gfx.dxsize;
380 int dst_x_start = dst_x;
384 char *text_ptr = text;
386 if (font->bitmap == NULL)
389 /* skip text to be printed outside the window (left/right will be clipped) */
390 if (dst_y < 0 || dst_y + font_height > video.height)
393 /* add offset for drawing font characters */
394 dst_x += font->draw_xoffset;
395 dst_y += font->draw_yoffset;
399 char c = *text_ptr++;
402 c = ' '; /* print space instead of newline */
404 getFontCharSource(font_nr, c, &src_bitmap, &src_x, &src_y);
406 /* clip text at the left side of the window */
414 /* clip text at the right side of the window */
416 if (dst_x + font_width > video.width)
419 /* (this does not work well when trying to print text to whole screen) */
420 if ((dst_x_start < border_1 && dst_x + font_width > border_1) ||
421 (dst_x_start < border_2 && dst_x + font_width > border_2))
425 if (mask_mode == BLIT_INVERSE) /* special mode for text gadgets */
427 /* first step: draw solid colored rectangle (use "cursor" character) */
428 if (strlen(text) == 1) /* only one char inverted => draw cursor */
430 Bitmap *cursor_bitmap;
431 int cursor_x, cursor_y;
433 getFontCharSource(font_nr, FONT_ASCII_CURSOR, &cursor_bitmap,
434 &cursor_x, &cursor_y);
436 BlitBitmap(cursor_bitmap, dst_bitmap, cursor_x, cursor_y,
437 font_width, font_height, dst_x, dst_y);
440 #if defined(TARGET_SDL)
441 /* second step: draw masked inverted character */
442 SDLCopyInverseMasked(src_bitmap, dst_bitmap, src_x, src_y,
443 font_width, font_height, dst_x, dst_y);
445 /* second step: draw masked black rectangle (use "space" character) */
446 SetClipOrigin(src_bitmap, src_bitmap->stored_clip_gc,
447 dst_x - src_x, dst_y - src_y);
448 BlitBitmapMasked(src_bitmap, dst_bitmap, 0, 0,
449 font_width, font_height, dst_x, dst_y);
452 else if (mask_mode == BLIT_MASKED || mask_mode == BLIT_ON_BACKGROUND)
454 if (mask_mode == BLIT_ON_BACKGROUND)
456 /* clear font character background */
457 ClearRectangleOnBackground(dst_bitmap, dst_x, dst_y,
458 font_width, font_height);
461 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
462 /* use special font tile clipmasks */
464 int font_pos = getFontCharPosition(font_nr, c);
466 SetClipMask(src_bitmap, font_clip_gc, font->clip_mask[font_pos]);
467 SetClipOrigin(src_bitmap, font_clip_gc, dst_x, dst_y);
470 SetClipOrigin(src_bitmap, src_bitmap->stored_clip_gc,
471 dst_x - src_x, dst_y - src_y);
474 BlitBitmapMasked(src_bitmap, dst_bitmap, src_x, src_y,
475 font_width, font_height, dst_x, dst_y);
477 else /* normal, non-masked font blitting */
479 BlitBitmap(src_bitmap, dst_bitmap, src_x, src_y,
480 font_width, font_height, dst_x, dst_y);
488 /* ========================================================================= */
489 /* text buffer drawing functions */
490 /* ========================================================================= */
492 #define MAX_LINES_FROM_FILE 1024
496 char *GetTextBufferFromFile(char *filename, int max_lines)
502 if (filename == NULL)
505 if (!(file = openFile(filename, MODE_READ)))
508 buffer = checked_calloc(1); /* start with valid, but empty text buffer */
510 while (!checkEndOfFile(file) && num_lines < max_lines)
512 char line[MAX_LINE_LEN];
514 /* read next line of input file */
515 if (!getStringFromFile(file, line, MAX_LINE_LEN))
518 buffer = checked_realloc(buffer, strlen(buffer) + strlen(line) + 1);
520 strcat(buffer, line);
532 char *GetTextBufferFromFile(char *filename, int max_lines)
538 if (filename == NULL)
541 if (!(file = fopen(filename, MODE_READ)))
544 buffer = checked_calloc(1); /* start with valid, but empty text buffer */
546 while (!feof(file) && num_lines < max_lines)
548 char line[MAX_LINE_LEN];
550 /* read next line of input file */
551 if (!fgets(line, MAX_LINE_LEN, file))
554 buffer = checked_realloc(buffer, strlen(buffer) + strlen(line) + 1);
556 strcat(buffer, line);
568 void DrawTextToTextArea_OLD(int x, int y, char *text, int font_nr, int line_length,
569 int area_xsize, int area_ysize, int mask_mode)
572 int font_height = getFontHeight(font_nr);
577 while (*text && area_line < area_ysize)
579 char buffer[MAX_OUTPUT_LINESIZE + 1];
582 for (i = 0; i < line_length && *text; i++)
583 if ((buffer[i] = *text++) == '\n')
585 buffer[MIN(i, area_xsize)] = '\0';
587 DrawTextExt(drawto, x, y + area_line * font_height, buffer, font_nr,
593 redraw_mask |= REDRAW_FIELD;
596 static boolean RenderLineToBuffer(char **src_buffer_ptr, char *dst_buffer,
597 int *dst_buffer_len, int line_length,
598 boolean last_line_was_empty)
600 char *text_ptr = *src_buffer_ptr;
601 char *buffer = dst_buffer;
602 int buffer_len = *dst_buffer_len;
603 boolean buffer_filled = FALSE;
610 /* skip leading whitespaces */
611 while (*text_ptr == ' ' || *text_ptr == '\t')
617 /* look for end of next word */
618 while (*word_ptr != ' ' && *word_ptr != '\t' && *word_ptr != '\0')
628 else if (*text_ptr == '\n') /* special case: force empty line */
633 /* prevent printing of multiple empty lines */
634 if (buffer_len > 0 || !last_line_was_empty)
635 buffer_filled = TRUE;
637 else if (word_len < line_length - buffer_len)
639 /* word fits into text buffer -- add word */
642 buffer[buffer_len++] = ' ';
644 strncpy(&buffer[buffer_len], text_ptr, word_len);
645 buffer_len += word_len;
646 buffer[buffer_len] = '\0';
647 text_ptr += word_len;
649 else if (buffer_len > 0)
651 /* not enough space left for word in text buffer -- print buffer */
653 buffer_filled = TRUE;
657 /* word does not fit at all into empty text buffer -- cut word */
659 strncpy(buffer, text_ptr, line_length);
660 buffer[line_length] = '\0';
661 text_ptr += line_length;
662 buffer_filled = TRUE;
669 *src_buffer_ptr = text_ptr;
670 *dst_buffer_len = buffer_len;
672 return buffer_filled;
676 void DrawTextWrapped_OLD(int x, int y, char *text, int font_nr, int line_length,
679 char *text_ptr = text;
680 int current_line = 0;
681 int font_height = getFontHeight(font_nr);
683 while (*text_ptr && current_line < max_lines)
685 char buffer[line_length + 1];
690 RenderLineToBuffer(&text_ptr, buffer, &buffer_len, line_length, TRUE);
692 DrawText(x, y + current_line * font_height, buffer, font_nr);
699 int DrawTextFromFile_OLD(int x, int y, char *filename, int font_nr,
700 int line_length, int max_lines, boolean wrap_text)
702 int font_height = getFontHeight(font_nr);
703 char line[MAX_LINE_LEN];
704 char buffer[line_length + 1];
706 int current_line = 0;
709 if (current_line >= max_lines)
712 if (filename == NULL)
715 if (!(file = fopen(filename, MODE_READ)))
721 while (!feof(file) && current_line < max_lines)
724 boolean last_line_was_empty = TRUE;
726 /* read next line of input file */
727 if (!fgets(line, MAX_LINE_LEN, file))
730 /* skip comments (lines directly beginning with '#') */
734 /* cut trailing newline from input line */
735 for (line_ptr = line; *line_ptr; line_ptr++)
737 if (*line_ptr == '\n' || *line_ptr == '\r')
744 if (strlen(line) == 0) /* special case: force empty line */
749 while (*line_ptr && current_line < max_lines)
752 boolean buffer_filled;
756 buffer_filled = RenderLineToBuffer(&line_ptr, buffer, &buffer_len,
757 line_length, last_line_was_empty);
761 if (strlen(line_ptr) <= line_length)
763 buffer_len = strlen(line_ptr);
764 strcpy(buffer, line_ptr);
768 buffer_len = line_length;
769 strncpy(buffer, line_ptr, line_length);
772 buffer[buffer_len] = '\0';
773 line_ptr += buffer_len;
775 buffer_filled = TRUE;
778 boolean buffer_filled = RenderLineToBuffer(&line_ptr, buffer, &buffer_len,
779 line_length, last_line_was_empty);
784 DrawText(x, y + current_line * font_height, buffer, font_nr);
787 last_line_was_empty = (buffer_len == 0);
797 if (buffer_len > 0 && current_line < max_lines)
799 DrawText(x, y + current_line * font_height, buffer, font_nr);
807 static boolean getCheckedTokenValueFromString(char *string, char **token,
812 if (!getTokenValueFromString(string, token, value))
815 if (**token != '.') /* token should begin with dot */
818 for (ptr = *token; *ptr; ptr++) /* token should contain no whitespace */
819 if (*ptr == ' ' || *ptr == '\t')
822 for (ptr = *value; *ptr; ptr++) /* value should contain no whitespace */
823 if (*ptr == ' ' || *ptr == '\t')
829 static void DrawTextBuffer_Flush(int x, int y, char *buffer, int font_nr,
830 int line_length, int cut_length,
831 int line_spacing, int mask_mode,
832 boolean centered, int current_line)
834 int buffer_len = strlen(buffer);
835 int font_width = getFontWidth(font_nr);
836 int font_height = getFontHeight(font_nr);
837 int offset_chars = (centered ? (line_length - buffer_len) / 2 : 0);
839 (centered ? font_width * (line_length - buffer_len) / 2 : 0);
840 int final_cut_length = MAX(0, cut_length - offset_chars);
841 int xx = x + offset_xsize;
842 int yy = y + current_line * (font_height + line_spacing);
844 buffer[final_cut_length] = '\0';
847 DrawTextExt(drawto, xx, yy, buffer, font_nr, mask_mode);
849 DrawText(xx, yy, buffer, font_nr);
852 int DrawTextBuffer(int x, int y, char *text_buffer, int font_nr,
853 int line_length, int cut_length, int max_lines,
854 int line_spacing, int mask_mode, boolean autowrap,
855 boolean centered, boolean parse_comments)
858 int font_width = getFontWidth(font_nr);
859 int font_height = getFontHeight(font_nr);
861 char buffer[line_length + 1];
863 int current_line = 0;
865 if (text_buffer == NULL || *text_buffer == '\0')
868 if (current_line >= max_lines)
871 if (cut_length == -1)
872 cut_length = line_length;
877 while (*text_buffer && current_line < max_lines)
879 char line[MAX_LINE_LEN + 1];
881 boolean last_line_was_empty = TRUE;
883 int num_line_chars = MAX_LINE_LEN;
885 int num_line_chars = (autowrap ? MAX_LINE_LEN : line_length);
889 /* copy next line from text buffer to line buffer (nearly fgets() style) */
890 for (i = 0; i < num_line_chars && *text_buffer; i++)
891 if ((line[i] = *text_buffer++) == '\n')
895 /* prevent 'num_line_chars' sized lines to cause additional empty line */
896 if (i == num_line_chars && *text_buffer == '\n')
899 /* skip comments (lines directly beginning with '#') */
900 if (line[0] == '#' && parse_comments)
904 /* try to read generic token/value pair definition after comment sign */
905 if (getCheckedTokenValueFromString(line + 1, &token, &value))
907 /* if found, flush the current buffer, if non-empty */
908 if (buffer_len > 0 && current_line < max_lines)
910 DrawTextBuffer_Flush(x, y, buffer, font_nr, line_length, cut_length,
911 line_spacing, mask_mode, centered, current_line);
919 if (strEqual(token, ".font"))
920 font_nr = gfx.get_font_from_token_function(value);
921 else if (strEqual(token, ".autowrap"))
922 autowrap = get_boolean_from_string(value);
923 else if (strEqual(token, ".centered"))
924 centered = get_boolean_from_string(value);
925 else if (strEqual(token, ".parse_comments"))
926 parse_comments = get_boolean_from_string(value);
932 /* cut trailing newline and carriage return from input line */
933 for (line_ptr = line; *line_ptr; line_ptr++)
935 if (*line_ptr == '\n' || *line_ptr == '\r')
942 if (strlen(line) == 0) /* special case: force empty line */
947 while (*line_ptr && current_line < max_lines)
949 boolean buffer_filled;
953 buffer_filled = RenderLineToBuffer(&line_ptr, buffer, &buffer_len,
954 line_length, last_line_was_empty);
958 if (strlen(line_ptr) <= line_length)
960 buffer_len = strlen(line_ptr);
961 strcpy(buffer, line_ptr);
965 buffer_len = line_length;
966 strncpy(buffer, line_ptr, line_length);
969 buffer[buffer_len] = '\0';
970 line_ptr += buffer_len;
972 buffer_filled = TRUE;
978 DrawTextBuffer_Flush(x, y, buffer, font_nr, line_length, cut_length,
979 line_spacing, mask_mode, centered, current_line);
981 int offset_chars = (centered ? (line_length - buffer_len) / 2 : 0);
983 (centered ? font_width * (line_length - buffer_len) / 2 : 0);
984 int final_cut_length = MAX(0, cut_length - offset_chars);
985 int xx = x + offset_xsize;
987 buffer[final_cut_length] = '\0';
990 DrawTextExt(drawto, xx, y + current_line * font_height, buffer,
993 DrawText(xx, y + current_line * font_height, buffer, font_nr);
998 last_line_was_empty = (buffer_len == 0);
1006 if (buffer_len > 0 && current_line < max_lines)
1009 DrawTextBuffer_Flush(x, y, buffer, font_nr, line_length, cut_length,
1010 line_spacing, mask_mode, centered, current_line);
1012 int offset_chars = (centered ? (line_length - buffer_len) / 2 : 0);
1014 (centered ? font_width * (line_length - buffer_len) / 2 : 0);
1015 int final_cut_length = MAX(0, cut_length - offset_chars);
1016 int xx = x + offset_xsize;
1018 buffer[final_cut_length] = '\0';
1020 if (mask_mode != -1)
1021 DrawTextExt(drawto, xx, y + current_line * font_height, buffer,
1022 font_nr, mask_mode);
1024 DrawText(xx, y + current_line * font_height, buffer, font_nr);
1030 return current_line;
1033 int DrawTextBufferVA(int x, int y, char *format, va_list ap, int font_nr,
1034 int line_length, int cut_length, int max_lines,
1035 int line_spacing, int mask_mode, boolean autowrap,
1036 boolean centered, boolean parse_comments)
1038 char text_buffer[MAX_OUTPUT_LINESIZE];
1039 int text_length = vsnprintf(text_buffer, MAX_OUTPUT_LINESIZE, format, ap);
1041 if (text_length >= MAX_OUTPUT_LINESIZE)
1042 Error(ERR_WARN, "string too long in DrawTextBufferVA() -- truncated");
1044 int num_lines_printed = DrawTextBuffer(x, y, text_buffer, font_nr,
1045 line_length, cut_length, max_lines,
1046 line_spacing, mask_mode, autowrap,
1047 centered, parse_comments);
1048 return num_lines_printed;
1051 int DrawTextFile(int x, int y, char *filename, int font_nr,
1052 int line_length, int cut_length, int max_lines,
1053 int line_spacing, int mask_mode, boolean autowrap,
1054 boolean centered, boolean parse_comments)
1056 char *text_buffer = GetTextBufferFromFile(filename, MAX_LINES_FROM_FILE);
1057 int num_lines_printed = DrawTextBuffer(x, y, text_buffer, font_nr,
1058 line_length, cut_length, max_lines,
1059 line_spacing, mask_mode, autowrap,
1060 centered, parse_comments);
1061 checked_free(text_buffer);
1063 return num_lines_printed;
1067 void DrawTextWrapped(int x, int y, char *text, int font_nr, int line_length,
1070 DrawTextBuffer(x, y, text, font_nr, line_length, -1, max_lines, -1, TRUE,
1074 void DrawTextToTextArea(int x, int y, char *text, int font_nr, int line_length,
1075 int cut_length, int max_lines, int mask_mode)
1077 DrawTextBuffer(x, y, text, font_nr, line_length, cut_length, max_lines,
1078 mask_mode, FALSE, FALSE, FALSE);