rnd-20050202-1-src
[rocksndiamonds.git] / src / libgame / gadgets.c
index 3431719caeb799898974860d5982cced01e4df71..50dc853129dd107128b5a6f103520758cb46c763 100644 (file)
@@ -1101,16 +1101,23 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap)
   if (gi->type & GD_TYPE_SCROLLBAR)
   {
     struct GadgetScrollbar *gs = &gi->scrollbar;
+    int scrollbar_size_cmp;
 
     if (gi->width == 0 || gi->height == 0 ||
        gs->items_max == 0 || gs->items_visible == 0)
       Error(ERR_EXIT, "scrollbar gadget incomplete (missing tags)");
 
     /* calculate internal scrollbar values */
+    gs->size_min = (gi->type == GD_TYPE_SCROLLBAR_VERTICAL ?
+                   gi->width : gi->height);
     gs->size_max = (gi->type == GD_TYPE_SCROLLBAR_VERTICAL ?
                    gi->height : gi->width);
-    gs->size = gs->size_max * gs->items_visible / gs->items_max;
-    gs->position = gs->size_max * gs->item_position / gs->items_max;
+
+    scrollbar_size_cmp = gs->size_max * gs->items_visible / gs->items_max;
+    gs->size = MAX(scrollbar_size_cmp, gs->size_min);
+    gs->size_max_cmp = (gs->size_max - (gs->size - scrollbar_size_cmp));
+
+    gs->position = gs->size_max_cmp * gs->item_position / gs->items_max;
     gs->position_max = gs->size_max - gs->size;
     gs->correction = gs->size_max / gs->items_max / 2;
 
@@ -1309,21 +1316,33 @@ void RemapAllGadgets()
   MultiMapGadgets(MULTIMAP_ALL | MULTIMAP_REMAP);
 }
 
-static boolean anyTextInputGadgetActive()
+boolean anyTextInputGadgetActive()
 {
   return (last_gi && (last_gi->type & GD_TYPE_TEXT_INPUT) && last_gi->mapped);
 }
 
-static boolean anyTextAreaGadgetActive()
+boolean anyTextAreaGadgetActive()
 {
   return (last_gi && (last_gi->type & GD_TYPE_TEXT_AREA) && last_gi->mapped);
 }
 
-static boolean anySelectboxGadgetActive()
+boolean anySelectboxGadgetActive()
 {
   return (last_gi && (last_gi->type & GD_TYPE_SELECTBOX) && last_gi->mapped);
 }
 
+boolean anyScrollbarGadgetActive()
+{
+  return (last_gi && (last_gi->type & GD_TYPE_SCROLLBAR) && last_gi->mapped);
+}
+
+boolean anyTextGadgetActive()
+{
+  return (anyTextInputGadgetActive() ||
+         anyTextAreaGadgetActive() ||
+         anySelectboxGadgetActive());
+}
+
 static boolean insideSelectboxLine(struct GadgetInfo *gi, int mx, int my)
 {
   return(gi != NULL &&
@@ -1340,13 +1359,6 @@ static boolean insideSelectboxArea(struct GadgetInfo *gi, int mx, int my)
         my >= gi->selectbox.y && my < gi->selectbox.y + gi->selectbox.height);
 }
 
-boolean anyTextGadgetActive()
-{
-  return (anyTextInputGadgetActive() ||
-         anyTextAreaGadgetActive() ||
-         anySelectboxGadgetActive());
-}
-
 void ClickOnGadget(struct GadgetInfo *gi, int button)
 {
   if (!gi->mapped)
@@ -1789,7 +1801,7 @@ boolean HandleGadgets(int mx, int my, int button)
        gs->position = gs->position_max;
 
       gs->item_position =
-       gs->items_max * (gs->position + gs->correction) / gs->size_max;
+       gs->items_max * (gs->position + gs->correction) / gs->size_max_cmp;
 
       if (gs->item_position < 0)
        gs->item_position = 0;