rnd-20030406-1-src
[rocksndiamonds.git] / src / libgame / gadgets.c
index 45744a8c99f01d14c2c5059ea590371cc650e57f..594131676338192ac4fd05444fd8b1ce6d6b9b15 100644 (file)
@@ -165,19 +165,21 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct)
        /* gadget text value */
        DrawTextExt(drawto,
                    gi->x + border, gi->y + border, text,
-                   font_type, FONT_MASKED);
+                   font_type, BLIT_MASKED);
 
        cursor_letter = gi->text.value[gi->text.cursor_position];
        cursor_string[0] = '~';
        cursor_string[1] = (cursor_letter != '\0' ? cursor_letter : ' ');
        cursor_string[2] = '\0';
 
+       SetInverseTextColor(gi->text.inverse_color);
+
        /* draw cursor, if active */
        if (pressed)
          DrawTextExt(drawto,
                      gi->x + border + gi->text.cursor_position * font_width,
                      gi->y + border, cursor_string,
-                     font_type, FONT_MASKED);
+                     font_type, BLIT_MASKED);
       }
       break;
 
@@ -222,7 +224,7 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct)
 
        /* gadget text value */
        DrawTextExt(drawto, gi->x + border, gi->y + border, text,
-                   font_type, FONT_MASKED);
+                   font_type, BLIT_MASKED);
 
        if (pressed)
        {
@@ -324,15 +326,17 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct)
          {
            if (i == gi->selectbox.current_index)
            {
-             DrawRectangle(drawto,
+             FillRectangle(drawto,
                            gi->selectbox.x + border,
                            gi->selectbox.y + border + i * font_height,
                            gi->selectbox.width - 2 * border, font_height,
-                           gi->selectbox.reverse_color);
+                           gi->selectbox.inverse_color);
 
              text[0] = '~';
              strncpy(&text[1], gi->selectbox.values[i], gi->selectbox.size);
              text[1 + gi->selectbox.size] = '\0';
+
+             SetInverseTextColor(gi->selectbox.inverse_color);
            }
            else
            {
@@ -343,7 +347,7 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct)
            DrawTextExt(drawto,
                        gi->selectbox.x + border,
                        gi->selectbox.y + border + i * font_height, text,
-                       font_type, FONT_MASKED);
+                       font_type, BLIT_MASKED);
          }
 
          redraw_selectbox = TRUE;
@@ -746,23 +750,30 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap)
 
   if (gi->type & GD_TYPE_TEXTINPUT)
   {
-    int font_width = getFontWidth(gi->text.font_type);
-    int font_height = getFontHeight(gi->text.font_type);
+    int font_nr = gi->text.font_type;
+    int font_width = getFontWidth(font_nr);
+    int font_height = getFontHeight(font_nr);
     int border_size = gi->border.size;
+    Bitmap *src_bitmap;
+    int src_x, src_y;
 
     gi->width  = 2 * border_size + (gi->text.size + 1) * font_width;
     gi->height = 2 * border_size + font_height;
+
+    getFontCharSource(font_nr, FONT_ASCII_CURSOR, &src_bitmap, &src_x, &src_y);
+    src_x += font_width / 2;
+    src_y += font_height / 2;
+    gi->text.inverse_color = GetPixel(src_bitmap, src_x, src_y);
   }
 
   if (gi->type & GD_TYPE_SELECTBOX)
   {
     int font_nr = gi->selectbox.font_type;
-    int font_bitmap_id = gfx.select_font_function(font_nr);
-    struct FontBitmapInfo *font = &gfx.font_bitmap_info[font_bitmap_id];
-    int font_width = getFontWidth(gi->selectbox.font_type);
-    int font_height = getFontHeight(gi->selectbox.font_type);
+    int font_width = getFontWidth(font_nr);
+    int font_height = getFontHeight(font_nr);
     int border_size = gi->border.size;
     int button_size = gi->border.size_selectbutton;
+    Bitmap *src_bitmap;
     int src_x, src_y;
 
     gi->width  = 2 * border_size + gi->text.size * font_width + button_size;
@@ -787,10 +798,10 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap)
     if (gi->selectbox.y < 0)
       gi->selectbox.y = gfx.real_sy + gfx.full_sysize - gi->selectbox.height;
 
-    if (!getFontChar(font_nr, '|', &src_x, &src_y))
-      Error(ERR_EXIT, "selectbox gadget incomplete (cannot get cursor)");
-
-    gi->selectbox.reverse_color = GetPixel(font->bitmap, src_x, src_y);
+    getFontCharSource(font_nr, FONT_ASCII_CURSOR, &src_bitmap, &src_x, &src_y);
+    src_x += font_width / 2;
+    src_y += font_height / 2;
+    gi->selectbox.inverse_color = GetPixel(src_bitmap, src_x, src_y);
 
     /* always start with closed selectbox */
     gi->selectbox.open = FALSE;
@@ -1211,6 +1222,24 @@ void HandleGadgets(int mx, int my, int button)
       if (last_x != gi->event.x || last_y != gi->event.y)
        changed_position = TRUE;
     }
+    else if (gi->type & GD_TYPE_SELECTBOX)
+    {
+      int old_index = gi->selectbox.current_index;
+
+      /* if mouse moving inside activated selectbox, select value */
+      if (my >= gi->selectbox.y && my < gi->selectbox.y + gi->selectbox.height)
+       gi->selectbox.current_index =
+         (my - gi->selectbox.y - gi->border.size) /
+         getFontWidth(gi->selectbox.font_type);
+
+      if (gi->selectbox.current_index < 0)
+       gi->selectbox.current_index = 0;
+      else if (gi->selectbox.current_index > gi->selectbox.num_values - 1)
+       gi->selectbox.current_index = gi->selectbox.num_values - 1;
+
+      if (gi->selectbox.current_index != old_index)
+       DrawGadget(gi, DG_PRESSED, DG_DIRECT);
+    }
   }
 
   /* handle gadget popup info text */