X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fgadgets.c;h=aaf01eb7e99d70c806f148697b08a82444d27b96;hb=3fb9d9cf97f3d4da6066f3c6b2ce84c81b768982;hp=50dc853129dd107128b5a6f103520758cb46c763;hpb=fda8c9f42aa13663ad6b2f698da787a7280b9965;p=rocksndiamonds.git diff --git a/src/libgame/gadgets.c b/src/libgame/gadgets.c index 50dc8531..aaf01eb7 100644 --- a/src/libgame/gadgets.c +++ b/src/libgame/gadgets.c @@ -1068,7 +1068,11 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap) 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); + + /* there may be esoteric cases with missing or too small font bitmap */ + if (src_bitmap != NULL && + src_x < src_bitmap->width && src_y < src_bitmap->height) + gi->selectbox.inverse_color = GetPixel(src_bitmap, src_x, src_y); /* always start with closed selectbox */ gi->selectbox.open = FALSE; @@ -1713,7 +1717,7 @@ boolean HandleGadgets(int mx, int my, int button) if (gs->item_position < 0) gs->item_position = 0; - if (gs->item_position > gs->items_max - gs->items_visible) + else if (gs->item_position > gs->items_max - gs->items_visible) gs->item_position = gs->items_max - gs->items_visible; if (old_item_position != gs->item_position) @@ -1795,13 +1799,22 @@ boolean HandleGadgets(int mx, int my, int button) gs->position = scrollbar_mouse_pos - gs->drag_position; - if (gs->position < 0) + /* make sure to always precisely reach end positions when dragging */ + if (gs->position <= 0) + { gs->position = 0; - if (gs->position > gs->position_max) + gs->item_position = 0; + } + else if (gs->position >= gs->position_max) + { gs->position = gs->position_max; - - gs->item_position = - gs->items_max * (gs->position + gs->correction) / gs->size_max_cmp; + gs->item_position = gs->items_max - gs->items_visible; + } + else + { + gs->item_position = + gs->items_max * (gs->position + gs->correction) / gs->size_max_cmp; + } if (gs->item_position < 0) gs->item_position = 0;