added optional button to restart game (door, panel and touch variants)
[rocksndiamonds.git] / src / libgame / gadgets.c
index 7c5dbacba410e0afac4f8d62625614577d345a44..b917b43df0ffeabd65c22bbacf173fc571ec14b2 100644 (file)
@@ -318,7 +318,7 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct)
                               border_x, gi->height, gi->x, gi->y);
 
        // middle part of gadget
-       for (i=0; i < gi->textbutton.size; i++)
+       for (i = 0; i < gi->textbutton.size; i++)
          BlitBitmapOnBackground(gd->bitmap, drawto, gd->x + border_x, gd->y,
                                 font_width, gi->height,
                                 gi->x + border_x + i * font_width, gi->y);
@@ -346,15 +346,19 @@ 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,
                               border_x, gi->height, gi->x, gi->y);
 
        // middle part of gadget
-       for (i=0; i < gi->textinput.size + 1; i++)
+       for (i = 0; i < gi->textinput.size + 1; i++)
          BlitBitmapOnBackground(gd->bitmap, drawto, gd->x + border_x, gd->y,
                                 font_width, gi->height,
                                 gi->x + border_x + i * font_width, gi->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,
@@ -449,7 +462,7 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct)
                               border_x, border_y, x, y);
 
        // top middle part of gadget border
-       for (i=0; i < xsize; i++)
+       for (i = 0; i < xsize; i++)
          BlitBitmapOnBackground(gd->bitmap, drawto, gd->x + border_x, gd->y,
                                 font_width, border_y,
                                 x + border_x + i * font_width, y);
@@ -461,7 +474,7 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct)
                               x + width - border_x, y);
 
        // left and right part of gadget border for each row
-       for (i=0; i < ysize; i++)
+       for (i = 0; i < ysize; i++)
        {
          BlitBitmapOnBackground(gd->bitmap, drawto, gd->x, gd->y + border_y,
                                 border_x, font_height,
@@ -481,7 +494,7 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct)
                               x, y + height - border_y);
 
        // bottom middle part of gadget border
-       for (i=0; i < xsize; i++)
+       for (i = 0; i < xsize; i++)
          BlitBitmapOnBackground(gd->bitmap, drawto,
                                 gd->x + border_x,
                                 gd->y + gd_height - border_y,
@@ -542,7 +555,7 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct)
                               border_x, gi->height, gi->x, gi->y);
 
        // middle part of gadget
-       for (i=0; i < gi->selectbox.size; i++)
+       for (i = 0; i < gi->selectbox.size; i++)
          BlitBitmapOnBackground(gd->bitmap, drawto, gd->x + border_x, gd->y,
                                 font_width, gi->height,
                                 gi->x + border_x + i * font_width, gi->y);
@@ -595,7 +608,7 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct)
                                 gi->selectbox.x, gi->selectbox.y);
 
          // top middle part of gadget border
-         for (i=0; i < gi->selectbox.size; i++)
+         for (i = 0; i < gi->selectbox.size; i++)
            BlitBitmapOnBackground(gd->bitmap, drawto, gd->x + border_x, gd->y,
                                   font_width, border_y,
                                   gi->selectbox.x + border_x + i * font_width,
@@ -616,7 +629,7 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct)
                                 gi->selectbox.y);
 
          // left and right part of gadget border for each row
-         for (i=0; i < gi->selectbox.num_values; i++)
+         for (i = 0; i < gi->selectbox.num_values; i++)
          {
            BlitBitmapOnBackground(gd->bitmap, drawto, gd->x, gd->y + border_y,
                                   border_x, font_height,
@@ -638,7 +651,7 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct)
                                 gi->selectbox.y + box_height - border_y);
 
          // bottom middle part of gadget border
-         for (i=0; i < gi->selectbox.size; i++)
+         for (i = 0; i < gi->selectbox.size; i++)
            BlitBitmapOnBackground(gd->bitmap, drawto,
                                   gd->x + border_x,
                                   gd->y + gi->height - border_y,
@@ -669,7 +682,7 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct)
                                     gi->selectbox.height - 2 * border_y);
 
          // selectbox text values
-         for (i=0; i < gi->selectbox.num_values; i++)
+         for (i = 0; i < gi->selectbox.num_values; i++)
          {
            int mask_mode = BLIT_MASKED;
 
@@ -744,7 +757,7 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct)
                               xpos, ypos);
 
        // middle part of gadget
-       for (i=0; i < num_steps; i++)
+       for (i = 0; i < num_steps; i++)
          BlitBitmapOnBackground(gd->bitmap, drawto,
                                 gd->x, gd->y + gi->border.ysize,
                                 gi->width, design_body,
@@ -791,7 +804,7 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct)
                               xpos, ypos);
 
        // middle part of gadget
-       for (i=0; i < num_steps; i++)
+       for (i = 0; i < num_steps; i++)
          BlitBitmapOnBackground(gd->bitmap, drawto,
                                 gd->x + gi->border.xsize, gd->y,
                                 design_body, gi->height,