]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/menu/item/listbox.c
Merge branch 'master' into terencehill/music_player
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / item / listbox.c
index 1087c347943df0273fb1116d3032ade90c60c92a..d4eaab2a7b8277e51866df26756550f5c6378c8c 100644 (file)
@@ -47,13 +47,31 @@ CLASS(ListBox) EXTENDS(Item)
        METHOD(ListBox, getItemAtPos, float(entity, float))
        METHOD(ListBox, getItemStart, float(entity, float))
        METHOD(ListBox, getItemHeight, float(entity, float))
+       // NOTE: if getItemAt* are overridden, it may make sense to cache the
+       // start and height of the last item returned by getItemAtPos and fast
+       // track returning their properties for getItemStart and getItemHeight.
+       // The "hot" code path calls getItemAtPos first, then will query
+       // getItemStart and getItemHeight on it soon.
+       // When overriding, the following consistency rules must hold:
+       // getTotalHeight() == SUM(getItemHeight(i), i, 0, me.nItems-1)
+       // getItemStart(i+1) == getItemStart(i) + getItemHeight(i)
+       //   for 0 <= i < me.nItems-1
+       // getItemStart(0) == 0
+       // getItemStart(getItemAtPos(p)) <= p
+       //   if p >= 0
+       // getItemAtPos(p) == 0
+       //   if p < 0
+       // getItemStart(getItemAtPos(p)) + getItemHeight(getItemAtPos(p)) > p
+       //   if p < getTotalHeigt()
+       // getItemAtPos(p) == me.nItems - 1
+       //   if p >= getTotalHeight()
 ENDCLASS(ListBox)
 #endif
 
 #ifdef IMPLEMENTATION
 void ListBox_setSelected(entity me, float i)
 {
-       me.selectedItem = floor(0.5 + bound(0, i, me.nItems - 1));
+       me.selectedItem = bound(0, i, me.nItems - 1);
 }
 void ListBox_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
 {
@@ -291,7 +309,7 @@ void ListBox_updateControlTopBottom(entity me)
                me.controlBottom = min((me.scrollPos + 1) / me.getTotalHeight(me), 1);
 
                float minfactor;
-               minfactor = 1 * me.controlWidth / me.size_y * me.size_x;
+               minfactor = 2 * me.controlWidth / me.size_y * me.size_x;
                f = me.controlBottom - me.controlTop;
                if(f < minfactor) // FIXME good default?
                {