rnd-20030403-3-src
[rocksndiamonds.git] / src / libgame / text.c
index d00151646f6c51d96b6c8abe29b0f1995ec04549..29f558f4b2101033f8e21b1d253f3d26690bd27d 100644 (file)
@@ -123,12 +123,39 @@ void InitFontInfo(struct FontBitmapInfo *font_bitmap_info, int num_fonts,
 
 int getFontWidth(int font_nr)
 {
-  return gfx.font_bitmap_info[font_nr].width;
+  int font_bitmap_id = gfx.select_font_function(font_nr);
+
+  return gfx.font_bitmap_info[font_bitmap_id].width;
 }
 
 int getFontHeight(int font_nr)
 {
-  return gfx.font_bitmap_info[font_nr].height;
+  int font_bitmap_id = gfx.select_font_function(font_nr);
+
+  return gfx.font_bitmap_info[font_bitmap_id].height;
+}
+
+boolean getFontChar(int font_nr, char c, int *src_x, int *src_y)
+{
+  int font_bitmap_id = gfx.select_font_function(font_nr);
+  struct FontBitmapInfo *font = &gfx.font_bitmap_info[font_bitmap_id];
+
+  if ((c >= 32 && c <= 95) || c == '°' || c == '´' || c == '|')
+  {
+    *src_x = font->src_x + ((c - 32) % FONT_CHARS_PER_LINE) * font->width;
+    *src_y = font->src_y + ((c - 32) / FONT_CHARS_PER_LINE) * font->height;
+
+    /* map '°' and 'TM' signs and cursor */
+    if (c == '°' || c == '´' || c == '|')
+    {
+      *src_x = font->src_x + FONT_CHARS_PER_LINE * font->width;
+      *src_y = font->src_y + (c == '°' ? 1 : c == '´' ? 2 : 3) * font->height;
+    }
+
+    return TRUE;
+  }
+
+  return FALSE;
 }
 
 void DrawInitText(char *text, int ypos, int font_nr)
@@ -141,7 +168,7 @@ void DrawInitText(char *text, int ypos, int font_nr)
 
     ClearRectangle(window, 0, ypos, video.width, getFontHeight(font_nr));
     DrawTextExt(window, (video.width - text_width) / 2, ypos, text, font_nr,
-               FONT_OPAQUE);
+               BLIT_OPAQUE);
     FlushDisplay();
   }
 }
@@ -179,10 +206,10 @@ void DrawTextF(int x, int y, int font_nr, char *format, ...)
 
 void DrawText(int x, int y, char *text, int font_nr)
 {
-  int mask_mode = FONT_OPAQUE;
+  int mask_mode = BLIT_OPAQUE;
 
   if (DrawingOnBackground(x, y))
-    mask_mode = FONT_MASKED;
+    mask_mode = BLIT_MASKED;
 
   DrawTextExt(drawto, x, y, text, font_nr, mask_mode);
 
@@ -198,6 +225,8 @@ void DrawTextExt(DrawBuffer *dst_bitmap, int dst_x, int dst_y, char *text,
   int font_bitmap_id = gfx.select_font_function(font_nr);
   struct FontBitmapInfo *font = &gfx.font_bitmap_info[font_bitmap_id];
   boolean print_inverse = FALSE;
+  boolean print_inverse_cursor = FALSE;
+  int src_x, src_y;
 
   if (font->bitmap == NULL)
     return;
@@ -213,6 +242,9 @@ void DrawTextExt(DrawBuffer *dst_bitmap, int dst_x, int dst_y, char *text,
     if (c == '~')
     {
       print_inverse = TRUE;
+      if (strlen(text) == 1)
+       print_inverse_cursor = TRUE;
+
       continue;
     }
 
@@ -229,24 +261,16 @@ void DrawTextExt(DrawBuffer *dst_bitmap, int dst_x, int dst_y, char *text,
     else if (c == '\\')                        /* bad luck ... */
       c = '/';
 
-    if ((c >= 32 && c <= 95) || c == '°' || c == '´' || c == '|')
+    if (getFontChar(font_nr, c, &src_x, &src_y))
     {
-      int src_x= font->src_x + ((c - 32) % FONT_CHARS_PER_LINE) * font->width;
-      int src_y= font->src_y + ((c - 32) / FONT_CHARS_PER_LINE) * font->height;
-
-      if (c == '°' || c == '´' || c == '|')    /* map '°' and 'TM' signs */
-      {
-       src_x = font->src_x + FONT_CHARS_PER_LINE * font->width;
-       src_y = font->src_y + (c == '°' ? 1 : c == '´' ? 2 : 3) * font->height;
-      }
-
       if (print_inverse)       /* special mode for text gadgets */
       {
        /* first step: draw solid colored rectangle (use "cursor" character) */
-       BlitBitmap(font->bitmap, dst_bitmap,
-                  font->src_x + FONT_CHARS_PER_LINE * font->width,
-                  font->src_y + 3 * font->height,
-                  font->width, font->height, dst_x, dst_y);
+       if (print_inverse_cursor)
+         BlitBitmap(font->bitmap, dst_bitmap,
+                    font->src_x + FONT_CHARS_PER_LINE * font->width,
+                    font->src_y + 3 * font->height,
+                    font->width, font->height, dst_x, dst_y);
 
        /* second step: draw masked black rectangle (use "space" character) */
        SetClipOrigin(font->bitmap, font->bitmap->stored_clip_gc,
@@ -254,7 +278,7 @@ void DrawTextExt(DrawBuffer *dst_bitmap, int dst_x, int dst_y, char *text,
        BlitBitmapMasked(font->bitmap, dst_bitmap,
                         0, 0, font->width, font->height, dst_x, dst_y);
       }
-      else if (mask_mode == FONT_MASKED)
+      else if (mask_mode == BLIT_MASKED)
       {
        /* clear font character background */
        ClearRectangleOnBackground(dst_bitmap, dst_x, dst_y,