[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [37543] trunk/blender/source/blender: fix [#27673] Value sliders >1 do not represent numerical ratios right

Campbell Barton ideasman42 at gmail.com
Thu Jun 16 08:47:55 CEST 2011


Revision: 37543
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37543
Author:   campbellbarton
Date:     2011-06-16 06:47:54 +0000 (Thu, 16 Jun 2011)
Log Message:
-----------
fix [#27673] Value sliders >1 do not represent numerical ratios right
the soft limits for array buttons not take into account the min/max of all array elements

Modified Paths:
--------------
    trunk/blender/source/blender/editors/interface/interface.c
    trunk/blender/source/blender/makesrna/RNA_access.h
    trunk/blender/source/blender/makesrna/intern/rna_access.c

Modified: trunk/blender/source/blender/editors/interface/interface.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface.c	2011-06-16 06:00:02 UTC (rev 37542)
+++ trunk/blender/source/blender/editors/interface/interface.c	2011-06-16 06:47:54 UTC (rev 37543)
@@ -1765,50 +1765,70 @@
 
 void ui_set_but_soft_range(uiBut *but, double value)
 {
-	PropertyType type;
-	double softmin, softmax /*, step, precision*/;
-	
+	/* ideally we would not limit this but practially, its more then
+	 * enough worst case is very long vectors wont use a smart soft-range
+	 * which isnt so bad. */
+
 	if(but->rnaprop) {
-		type= RNA_property_type(but->rnaprop);
+		const PropertyType type= RNA_property_type(but->rnaprop);
+		double softmin, softmax /*, step, precision*/;
+		double value_min= value;
+		double value_max= value;
 
 		/* clamp button range to something reasonable in case
 		 * we get -inf/inf from RNA properties */
 		if(type == PROP_INT) {
 			int imin, imax, istep;
+			const int array_len= RNA_property_array_length(&but->rnapoin, but->rnaprop);
 
 			RNA_property_int_ui_range(&but->rnapoin, but->rnaprop, &imin, &imax, &istep);
 			softmin= (imin == INT_MIN)? -1e4: imin;
 			softmax= (imin == INT_MAX)? 1e4: imax;
 			/*step= istep;*/ /*UNUSED*/
 			/*precision= 1;*/ /*UNUSED*/
+
+			if(array_len >= 2) {
+				int value_range[2];
+				RNA_property_int_get_array_range(&but->rnapoin, but->rnaprop, value_range);
+				value_min= (double)value_range[0];
+				value_max= (double)value_range[1];
+			}
 		}
 		else if(type == PROP_FLOAT) {
 			float fmin, fmax, fstep, fprecision;
+			const int array_len= RNA_property_array_length(&but->rnapoin, but->rnaprop);
 
 			RNA_property_float_ui_range(&but->rnapoin, but->rnaprop, &fmin, &fmax, &fstep, &fprecision);
 			softmin= (fmin == -FLT_MAX)? (float)-1e4: fmin;
 			softmax= (fmax == FLT_MAX)? (float)1e4: fmax;
 			/*step= fstep;*/ /*UNUSED*/
 			/*precision= fprecision;*/ /*UNUSED*/
+
+			if(array_len >= 2) {
+				float value_range[2];
+				RNA_property_float_get_array_range(&but->rnapoin, but->rnaprop, value_range);
+				value_min= (double)value_range[0];
+				value_max= (double)value_range[1];
+			}
 		}
 		else
 			return;
 
 		/* if the value goes out of the soft/max range, adapt the range */
-		if(value+1e-10 < softmin) {
-			if(value < 0.0)
-				softmin= -soft_range_round_up(-value, -softmin);
+		if(value_min+1e-10 < softmin) {
+			if(value_min < 0.0)
+				softmin= -soft_range_round_up(-value_min, -softmin);
 			else
-				softmin= soft_range_round_down(value, softmin);
+				softmin= soft_range_round_down(value_min, softmin);
 
 			if(softmin < (double)but->hardmin)
 				softmin= (double)but->hardmin;
 		}
-		else if(value-1e-10 > softmax) {
-			if(value < 0.0)
-				softmax= -soft_range_round_down(-value, -softmax);
+		else if(value_max-1e-10 > softmax) {
+			if(value_max < 0.0)
+				softmax= -soft_range_round_down(-value_max, -softmax);
 			else
-				softmax= soft_range_round_up(value, softmax);
+				softmax= soft_range_round_up(value_max, softmax);
 
 			if(softmax > (double)but->hardmax)
 				softmax= but->hardmax;

Modified: trunk/blender/source/blender/makesrna/RNA_access.h
===================================================================
--- trunk/blender/source/blender/makesrna/RNA_access.h	2011-06-16 06:00:02 UTC (rev 37542)
+++ trunk/blender/source/blender/makesrna/RNA_access.h	2011-06-16 06:47:54 UTC (rev 37543)
@@ -716,6 +716,7 @@
 int RNA_property_int_get(PointerRNA *ptr, PropertyRNA *prop);
 void RNA_property_int_set(PointerRNA *ptr, PropertyRNA *prop, int value);
 void RNA_property_int_get_array(PointerRNA *ptr, PropertyRNA *prop, int *values);
+void RNA_property_int_get_array_range(PointerRNA *ptr, PropertyRNA *prop, int values[2]);
 int RNA_property_int_get_index(PointerRNA *ptr, PropertyRNA *prop, int index);
 void RNA_property_int_set_array(PointerRNA *ptr, PropertyRNA *prop, const int *values);
 void RNA_property_int_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, int value);
@@ -726,6 +727,7 @@
 float RNA_property_float_get(PointerRNA *ptr, PropertyRNA *prop);
 void RNA_property_float_set(PointerRNA *ptr, PropertyRNA *prop, float value);
 void RNA_property_float_get_array(PointerRNA *ptr, PropertyRNA *prop, float *values);
+void RNA_property_float_get_array_range(PointerRNA *ptr, PropertyRNA *prop, float values[2]);
 float RNA_property_float_get_index(PointerRNA *ptr, PropertyRNA *prop, int index);
 void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const float *values);
 void RNA_property_float_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, float value);

Modified: trunk/blender/source/blender/makesrna/intern/rna_access.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_access.c	2011-06-16 06:00:02 UTC (rev 37542)
+++ trunk/blender/source/blender/makesrna/intern/rna_access.c	2011-06-16 06:47:54 UTC (rev 37543)
@@ -1643,6 +1643,43 @@
 		memset(values, 0, sizeof(int)*prop->totarraylength);
 }
 
+void RNA_property_int_get_array_range(PointerRNA *ptr, PropertyRNA *prop, int values[2])
+{
+	const int array_len= RNA_property_array_length(ptr, prop);
+
+	if(array_len <= 0) {
+		values[0]= 0;
+		values[1]= 0;
+	}
+	else if (array_len == 1) {
+		RNA_property_int_get_array(ptr, prop, values);
+		values[1]= values[0];
+	}
+	else {
+		int arr_stack[32];
+		int *arr;
+		int i;
+
+		if(array_len > 32) {
+			arr= MEM_mallocN(sizeof(int) * array_len, "RNA_property_int_get_array_range");
+		}
+		else {
+			arr= arr_stack;
+		}
+
+		RNA_property_int_get_array(ptr, prop, arr);
+		values[0]= values[1]= arr[0];
+		for(i= 1; i < array_len; i++) {
+			values[0]= MIN2(values[0], arr[i]);
+			values[1]= MAX2(values[1], arr[i]);
+		}
+
+		if(arr != arr_stack) {
+			MEM_freeN(arr);
+		}
+	}
+}
+
 int RNA_property_int_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
 {
 	int tmp[RNA_MAX_ARRAY_LENGTH];
@@ -1839,6 +1876,43 @@
 		memset(values, 0, sizeof(float)*prop->totarraylength);
 }
 
+void RNA_property_float_get_array_range(PointerRNA *ptr, PropertyRNA *prop, float values[2])
+{
+	const int array_len= RNA_property_array_length(ptr, prop);
+
+	if(array_len <= 0) {
+		values[0]= 0.0f;
+		values[1]= 0.0f;
+	}
+	else if (array_len == 1) {
+		RNA_property_float_get_array(ptr, prop, values);
+		values[1]= values[0];
+	}
+	else {
+		float arr_stack[32];
+		float *arr;
+		int i;
+
+		if(array_len > 32) {
+			arr= MEM_mallocN(sizeof(float) * array_len, "RNA_property_float_get_array_range");
+		}
+		else {
+			arr= arr_stack;
+		}
+
+		RNA_property_float_get_array(ptr, prop, arr);
+		values[0]= values[1]= arr[0];
+		for(i= 1; i < array_len; i++) {
+			values[0]= MIN2(values[0], arr[i]);
+			values[1]= MAX2(values[1], arr[i]);
+		}
+
+		if(arr != arr_stack) {
+			MEM_freeN(arr);
+		}
+	}
+}
+
 float RNA_property_float_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
 {
 	float tmp[RNA_MAX_ARRAY_LENGTH];




More information about the Bf-blender-cvs mailing list