+ else if (IN_GFX_DOOR_2(x, y))
+ redraw_mask |= REDRAW_DOOR_2;
+ else if (IN_GFX_DOOR_3(x, y))
+ redraw_mask |= REDRAW_DOOR_3;
+ else
+ redraw_mask |= REDRAW_ALL;
+}
+
+void DrawTextExt(DrawBuffer *dst_bitmap, int dst_x, int dst_y, char *text,
+ int font_nr, int mask_mode)
+{
+ struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
+ int font_width = getFontWidth(font_nr);
+ int font_height = getFontHeight(font_nr);
+ Bitmap *src_bitmap;
+ int src_x, src_y;
+ char *text_ptr = text;
+
+ if (font->bitmap == NULL)
+ return;
+
+ /* skip text to be printed outside the window (left/right will be clipped) */
+ if (dst_y < 0 || dst_y + font_height > video.height)
+ return;
+
+ /* add offset for drawing font characters */
+ dst_x += font->draw_xoffset;
+ dst_y += font->draw_yoffset;
+
+ while (*text_ptr)
+ {
+ char c = *text_ptr++;
+
+ if (c == '\n')
+ c = ' '; /* print space instead of newline */
+
+ getFontCharSource(font_nr, c, &src_bitmap, &src_x, &src_y);
+
+ /* clip text at the left side of the window */
+ if (dst_x < 0)
+ {
+ dst_x += font_width;
+
+ continue;
+ }
+
+ /* clip text at the right side of the window */
+ if (dst_x + font_width > video.width)
+ break;
+
+ if (mask_mode == BLIT_INVERSE) /* special mode for text gadgets */
+ {
+ /* first step: draw solid colored rectangle (use "cursor" character) */
+ if (strlen(text) == 1) /* only one char inverted => draw cursor */
+ {
+ Bitmap *cursor_bitmap;
+ int cursor_x, cursor_y;
+
+ getFontCharSource(font_nr, FONT_ASCII_CURSOR, &cursor_bitmap,
+ &cursor_x, &cursor_y);
+
+ BlitBitmap(cursor_bitmap, dst_bitmap, cursor_x, cursor_y,
+ font_width, font_height, dst_x, dst_y);
+ }
+
+ /* second step: draw masked inverted character */
+ SDLCopyInverseMasked(src_bitmap, dst_bitmap, src_x, src_y,
+ font_width, font_height, dst_x, dst_y);
+ }
+ else if (mask_mode == BLIT_MASKED || mask_mode == BLIT_ON_BACKGROUND)
+ {
+ if (mask_mode == BLIT_ON_BACKGROUND)
+ {
+ /* clear font character background */
+ ClearRectangleOnBackground(dst_bitmap, dst_x, dst_y,
+ font_width, font_height);
+ }
+
+ BlitBitmapMasked(src_bitmap, dst_bitmap, src_x, src_y,
+ font_width, font_height, dst_x, dst_y);
+ }
+ else /* normal, non-masked font blitting */
+ {
+ BlitBitmap(src_bitmap, dst_bitmap, src_x, src_y,
+ font_width, font_height, dst_x, dst_y);
+ }
+
+ dst_x += font_width;
+ }
+}
+
+
+/* ========================================================================= */
+/* text buffer drawing functions */
+/* ========================================================================= */
+
+#define MAX_LINES_FROM_FILE 1024
+
+char *GetTextBufferFromFile(char *filename, int max_lines)
+{
+ File *file;
+ char *buffer;
+ int num_lines = 0;
+
+ if (filename == NULL)
+ return NULL;
+
+ if (!(file = openFile(filename, MODE_READ)))
+ return NULL;
+
+ buffer = checked_calloc(1); /* start with valid, but empty text buffer */
+
+ while (!checkEndOfFile(file) && num_lines < max_lines)
+ {
+ char line[MAX_LINE_LEN];
+
+ /* read next line of input file */
+ if (!getStringFromFile(file, line, MAX_LINE_LEN))
+ break;
+
+ buffer = checked_realloc(buffer, strlen(buffer) + strlen(line) + 1);
+
+ strcat(buffer, line);
+
+ num_lines++;
+ }
+
+ closeFile(file);
+
+ return buffer;
+}
+
+static boolean RenderLineToBuffer(char **src_buffer_ptr, char *dst_buffer,
+ int *dst_buffer_len, int line_length,
+ boolean last_line_was_empty)
+{
+ char *text_ptr = *src_buffer_ptr;
+ char *buffer = dst_buffer;
+ int buffer_len = *dst_buffer_len;
+ boolean buffer_filled = FALSE;
+
+ while (*text_ptr)
+ {
+ char *word_ptr;
+ int word_len;
+
+ /* skip leading whitespaces */
+ while (*text_ptr == ' ' || *text_ptr == '\t')
+ text_ptr++;
+
+ word_ptr = text_ptr;
+ word_len = 0;
+
+ /* look for end of next word */
+ while (*word_ptr != ' ' && *word_ptr != '\t' && *word_ptr != '\0')
+ {
+ word_ptr++;
+ word_len++;
+ }
+
+ if (word_len == 0)
+ {
+ continue;
+ }
+ else if (*text_ptr == '\n') /* special case: force empty line */
+ {
+ if (buffer_len == 0)
+ text_ptr++;
+
+ /* prevent printing of multiple empty lines */
+ if (buffer_len > 0 || !last_line_was_empty)
+ buffer_filled = TRUE;
+ }
+ else if (word_len < line_length - buffer_len)
+ {
+ /* word fits into text buffer -- add word */
+
+ if (buffer_len > 0)
+ buffer[buffer_len++] = ' ';
+
+ strncpy(&buffer[buffer_len], text_ptr, word_len);
+ buffer_len += word_len;
+ buffer[buffer_len] = '\0';
+ text_ptr += word_len;
+ }
+ else if (buffer_len > 0)
+ {
+ /* not enough space left for word in text buffer -- print buffer */
+
+ buffer_filled = TRUE;
+ }
+ else
+ {
+ /* word does not fit at all into empty text buffer -- cut word */
+
+ strncpy(buffer, text_ptr, line_length);
+ buffer[line_length] = '\0';
+ text_ptr += line_length;
+ buffer_filled = TRUE;
+ }
+
+ if (buffer_filled)
+ break;
+ }
+
+ *src_buffer_ptr = text_ptr;
+ *dst_buffer_len = buffer_len;
+
+ return buffer_filled;