X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fgadgets.c;h=0058bf1890d8593d5c7634dfda8dd4512381ff67;hb=608be3bcd270eb45628a274eddb6dbcc8940accf;hp=45744a8c99f01d14c2c5059ea590371cc650e57f;hpb=6ed4958820f8f97174ca47594dcc6f00ee31b2cb;p=rocksndiamonds.git diff --git a/src/libgame/gadgets.c b/src/libgame/gadgets.c index 45744a8c..0058bf18 100644 --- a/src/libgame/gadgets.c +++ b/src/libgame/gadgets.c @@ -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,12 +750,23 @@ 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_bitmap_id = gfx.select_font_function(font_nr); + struct FontBitmapInfo *font = &gfx.font_bitmap_info[font_bitmap_id]; + int font_width = getFontWidth(font_nr); + int font_height = getFontHeight(font_nr); int border_size = gi->border.size; + int src_x, src_y; gi->width = 2 * border_size + (gi->text.size + 1) * font_width; gi->height = 2 * border_size + font_height; + + if (!getFontChar(font_nr, '|', &src_x, &src_y)) + Error(ERR_EXIT, "text input gadget incomplete (cannot get cursor)"); + + src_x += font_width / 2; + src_y += font_height / 2; + gi->text.inverse_color = GetPixel(font->bitmap, src_x, src_y); } if (gi->type & GD_TYPE_SELECTBOX) @@ -759,8 +774,8 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap) 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; int src_x, src_y; @@ -790,7 +805,9 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap) 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); + src_x += font_width / 2; + src_y += font_height / 2; + gi->selectbox.inverse_color = GetPixel(font->bitmap, src_x, src_y); /* always start with closed selectbox */ gi->selectbox.open = FALSE; @@ -1211,6 +1228,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 */