r2973 - trunk/data/qcsrc/menu-div0test/item

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Fri Nov 16 10:51:55 EST 2007


Author: div0
Date: 2007-11-16 10:51:55 -0500 (Fri, 16 Nov 2007)
New Revision: 2973

Modified:
   trunk/data/qcsrc/menu-div0test/item/listbox.c
Log:
oops... implement minimum height for listbox slider


Modified: trunk/data/qcsrc/menu-div0test/item/listbox.c
===================================================================
--- trunk/data/qcsrc/menu-div0test/item/listbox.c	2007-11-16 15:35:45 UTC (rev 2972)
+++ trunk/data/qcsrc/menu-div0test/item/listbox.c	2007-11-16 15:51:55 UTC (rev 2973)
@@ -98,7 +98,7 @@
 		{
 			// calculate new pos to v
 			float delta;
-			delta = (pos_y - me.pressOffset) / (1 - 1 / (me.nItems * me.itemHeight)) * (me.nItems * me.itemHeight - 1);
+			delta = (pos_y - me.pressOffset) / (1 - (me.controlBottom - me.controlTop)) * (me.nItems * me.itemHeight - 1);
 			me.scrollPos = me.previousValue + delta;
 		}
 		else
@@ -180,6 +180,7 @@
 }
 void updateControlTopBottomListBox(entity me)
 {
+	float f;
 	// scrollPos is in 0..1 and indicates where the "page" currently shown starts.
 	if(me.nItems * me.itemHeight <= 1)
 	{
@@ -212,6 +213,20 @@
 		// now that we know where the list is scrolled to, find out where to draw the control
 		me.controlTop = max(0, me.scrollPos / (me.nItems * me.itemHeight));
 		me.controlBottom = min((me.scrollPos + 1) / (me.nItems * me.itemHeight), 1);
+
+		float fmin;
+		fmin = 1 * me.controlWidth / me.size_y * me.size_x;
+		f = me.controlBottom - me.controlTop;
+		if(f < fmin) // FIXME good default?
+		{
+			// f * X + 1 * (1-X) = fmin
+			// (f - 1) * X + 1 = fmin
+			// (f - 1) * X = fmin - 1
+			// X = (fmin - 1) / (f - 1)
+			f = (fmin - 1) / (f - 1);
+			me.controlTop = me.controlTop * f + 0 * (1 - f);
+			me.controlBottom = me.controlBottom * f + 1 * (1 - f);
+		}
 	}
 }
 void drawListBox(entity me)




More information about the nexuiz-commits mailing list