cleanup of unnecessarily convoluted function call
[rocksndiamonds.git] / src / libgame / gadgets.c
index cefffd27dd469d64baf3998ab77c9233511d59f6..844f4f4e9c527fe8025cd3a38665298bb9da4a3c 100644 (file)
@@ -346,8 +346,12 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct)
        char text[MAX_GADGET_TEXTSIZE + 1];
        int font_nr = (pressed ? gi->font_active : gi->font);
        int font_width = getFontWidth(font_nr);
+       int font_height = getFontHeight(font_nr);
+       struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
        int border_x = gi->border.xsize;
        int border_y = gi->border.ysize;
+       int text_x = gi->x + font->draw_xoffset;
+       int text_y = gi->y + font->draw_yoffset;
 
        // left part of gadget
        BlitBitmapOnBackground(gd->bitmap, drawto, gd->x, gd->y,
@@ -369,6 +373,15 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct)
        strcpy(text, gi->textinput.value);
        strcat(text, " ");
 
+       // dirty workaround to erase text if input gadget font has draw offset
+       if (font->draw_xoffset != 0 || font->draw_yoffset != 0)
+         for (i = 0; i < gi->textinput.size + 1; i++)
+           BlitBitmapOnBackground(gd->bitmap, drawto,
+                                  gd->x + border_x, gd->y + border_y,
+                                  font_width, font_height,
+                                  text_x + border_x + i * font_width,
+                                  text_y + border_y);
+
        // gadget text value
        DrawTextExt(drawto,
                    gi->x + border_x, gi->y + border_y, text,
@@ -621,13 +634,13 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct)
            BlitBitmapOnBackground(gd->bitmap, drawto, gd->x, gd->y + border_y,
                                   border_x, font_height,
                                   gi->selectbox.x,
-                                  gi->selectbox.y + border_y + i*font_height);
+                                  gi->selectbox.y + border_y + i * font_height);
            BlitBitmapOnBackground(gd->bitmap, drawto,
                                   gd->x + gi->border.width - border_x,
                                   gd->y + border_y,
                                   border_x, font_height,
                                   gi->selectbox.x + box_width - border_x,
-                                  gi->selectbox.y + border_y + i*font_height);
+                                  gi->selectbox.y + border_y + i * font_height);
          }
 
          // bottom left part of gadget border
@@ -1154,7 +1167,7 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap)
        break;
 
       case GDI_ALT_DESIGN_UNPRESSED:
-       gi->alt_design[GD_BUTTON_UNPRESSED].bitmap= va_arg(ap, Bitmap *);
+       gi->alt_design[GD_BUTTON_UNPRESSED].bitmap = va_arg(ap, Bitmap *);
        gi->alt_design[GD_BUTTON_UNPRESSED].x = va_arg(ap, int);
        gi->alt_design[GD_BUTTON_UNPRESSED].y = va_arg(ap, int);
        break;
@@ -1346,7 +1359,7 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap)
     Bitmap *src_bitmap;
     int src_x, src_y;
 
-    gi->width  = 2 * border_xsize + gi->textinput.size*font_width +button_size;
+    gi->width  = 2 * border_xsize + gi->textinput.size * font_width + button_size;
     gi->height = 2 * border_ysize + font_height;
 
     if (gi->selectbox.options == NULL)
@@ -2442,8 +2455,7 @@ boolean HandleGadgetsKeyInput(Key key)
     int cursor_pos = gi->textinput.cursor_position;
     char letter = getCharFromKey(key);
     boolean legal_letter = (gi->type == GD_TYPE_TEXT_INPUT_NUMERIC ?
-                           letter >= '0' && letter <= '9' :
-                           letter != 0);
+                           (letter >= '0' && letter <= '9') || letter == '-' : letter != 0);
 
     if (legal_letter && text_length < gi->textinput.size)
     {