rnd-20031122-2-src
[rocksndiamonds.git] / src / libgame / text.c
index a4b60302110914df7d3b35640470c9b9ddbc95e3..9e9556095fbd9dddd8b09534b2c007543044a732 100644 (file)
@@ -191,7 +191,7 @@ void DrawInitText(char *text, int ypos, int font_nr)
   }
 }
 
-void DrawTextFCentered(int y, int font_nr, char *format, ...)
+void DrawTextF(int x, int y, int font_nr, char *format, ...)
 {
   char buffer[MAX_OUTPUT_LINESIZE + 1];
   va_list ap;
@@ -201,13 +201,12 @@ void DrawTextFCentered(int y, int font_nr, char *format, ...)
   va_end(ap);
 
   if (strlen(buffer) > MAX_OUTPUT_LINESIZE)
-    Error(ERR_EXIT, "string too long in DrawTextFCentered() -- aborting");
+    Error(ERR_EXIT, "string too long in DrawTextF() -- aborting");
 
-  DrawText(gfx.sx + (gfx.sxsize - getTextWidth(buffer, font_nr)) / 2,
-          gfx.sy + y, buffer, font_nr);
+  DrawText(gfx.sx + x, gfx.sy + y, buffer, font_nr);
 }
 
-void DrawTextF(int x, int y, int font_nr, char *format, ...)
+void DrawTextFCentered(int y, int font_nr, char *format, ...)
 {
   char buffer[MAX_OUTPUT_LINESIZE + 1];
   va_list ap;
@@ -217,9 +216,21 @@ void DrawTextF(int x, int y, int font_nr, char *format, ...)
   va_end(ap);
 
   if (strlen(buffer) > MAX_OUTPUT_LINESIZE)
-    Error(ERR_EXIT, "string too long in DrawTextF() -- aborting");
+    Error(ERR_EXIT, "string too long in DrawTextFCentered() -- aborting");
 
-  DrawText(gfx.sx + x, gfx.sy + y, buffer, font_nr);
+  DrawText(gfx.sx + (gfx.sxsize - getTextWidth(buffer, font_nr)) / 2,
+          gfx.sy + y, buffer, font_nr);
+}
+
+void DrawTextS(int x, int y, int font_nr, char *text)
+{
+  DrawText(gfx.sx + x, gfx.sy + y, text, font_nr);
+}
+
+void DrawTextSCentered(int y, int font_nr, char *text)
+{
+  DrawText(gfx.sx + (gfx.sxsize - getTextWidth(text, font_nr)) / 2,
+          gfx.sy + y, text, font_nr);
 }
 
 void DrawText(int x, int y, char *text, int font_nr)
@@ -259,6 +270,9 @@ void DrawTextExt(DrawBuffer *dst_bitmap, int dst_x, int dst_y, char *text,
   {
     char c = *text_ptr++;
 
+    if (c == '\n')
+      c = ' ';         /* print space instaed of newline */
+
     getFontCharSource(font_nr, c, &src_bitmap, &src_x, &src_y);
 
     if (mask_mode == BLIT_INVERSE)     /* special mode for text gadgets */
@@ -322,3 +336,31 @@ void DrawTextExt(DrawBuffer *dst_bitmap, int dst_x, int dst_y, char *text,
     dst_x += font_width;
   }
 }
+
+void DrawTextToTextArea(int x, int y, char *text, int font_nr, int line_length,
+                       int area_xsize, int area_ysize, int mask_mode)
+{
+  int area_line = 0;
+  int font_height = getFontHeight(font_nr);
+
+  if (text == NULL)
+    return;
+
+  while (*text && area_line < area_ysize)
+  {
+    char buffer[MAX_OUTPUT_LINESIZE + 1];
+    int i;
+
+    for (i=0; i < line_length && *text; i++)
+      if ((buffer[i] = *text++) == '\n')
+       break;
+    buffer[MIN(i, area_xsize)] = '\0';
+
+    DrawTextExt(drawto, x, y + area_line * font_height, buffer, font_nr,
+               mask_mode);
+
+    area_line++;
+  }
+
+  redraw_mask |= REDRAW_FIELD;
+}