rnd-20030406-2-src
[rocksndiamonds.git] / src / libgame / gadgets.c
index 45744a8c99f01d14c2c5059ea590371cc650e57f..69108942972fe2f8112a25dbb7d868e9b6945eb4 100644 (file)
@@ -137,7 +137,7 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct)
       {
        int i;
        char cursor_letter;
-       char cursor_string[3];
+       char cursor_string[2];
        char text[MAX_GADGET_TEXTSIZE + 1];
        int font_type = gi->text.font_type;
        int font_width = getFontWidth(font_type);
@@ -165,19 +165,20 @@ 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';
+       cursor_string[0] = (cursor_letter != '\0' ? cursor_letter : ' ');
+       cursor_string[1] = '\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_INVERSE);
       }
       break;
 
@@ -222,7 +223,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)
        {
@@ -322,28 +323,35 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct)
          /* selectbox text values */
          for (i=0; i < gi->selectbox.num_values; i++)
          {
+           int mask_mode;
+
            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);
+             strncpy(text, gi->selectbox.values[i], gi->selectbox.size);
              text[1 + gi->selectbox.size] = '\0';
+
+             SetInverseTextColor(gi->selectbox.inverse_color);
+
+             mask_mode = BLIT_INVERSE;
            }
            else
            {
              strncpy(text, gi->selectbox.values[i], gi->selectbox.size);
              text[gi->selectbox.size] = '\0';
+
+             mask_mode = BLIT_MASKED;
            }
 
            DrawTextExt(drawto,
                        gi->selectbox.x + border,
                        gi->selectbox.y + border + i * font_height, text,
-                       font_type, FONT_MASKED);
+                       font_type, mask_mode);
          }
 
          redraw_selectbox = TRUE;
@@ -746,23 +754,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 +802,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 +1226,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 */