[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19450] branches/blender2.5/blender/source /blender: UI:

Brecht Van Lommel brecht at blender.org
Sun Mar 29 20:44:49 CEST 2009


Revision: 19450
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19450
Author:   blendix
Date:     2009-03-29 20:44:49 +0200 (Sun, 29 Mar 2009)

Log Message:
-----------
UI:
* Added support for soft/hard range in the buttons code. Currently
  it works by only allowing to drag or click increment in the soft
  range, but typing a number value allows to go outside it.

  If the number is outside the soft range, the range will be extended,
  rounded to values like:
  .., 0.1, 0.2, 0.5, 1.0, 2.0, 5.0, 10.0, 20.0, 50.0, ..

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/editors/interface/interface.c
    branches/blender2.5/blender/source/blender/editors/interface/interface_draw.c
    branches/blender2.5/blender/source/blender/editors/interface/interface_handlers.c
    branches/blender2.5/blender/source/blender/editors/interface/interface_intern.h
    branches/blender2.5/blender/source/blender/editors/interface/interface_regions.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_define.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_scene.c

Modified: branches/blender2.5/blender/source/blender/editors/interface/interface.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/interface/interface.c	2009-03-29 18:34:35 UTC (rev 19449)
+++ branches/blender2.5/blender/source/blender/editors/interface/interface.c	2009-03-29 18:44:49 UTC (rev 19450)
@@ -538,6 +538,8 @@
 				but->editcumap= oldbut->editcumap;
 				but->selsta= oldbut->selsta;
 				but->selend= oldbut->selend;
+				but->softmin= oldbut->softmin;
+				but->softmax= oldbut->softmax;
 				found= 1;
 
 				oldbut->active= NULL;
@@ -605,6 +607,10 @@
 				but->lock = 1;
 			}
 		}
+
+		/* only update soft range while not editing */
+		if(but->rnaprop && !(but->editval || but->editstr || but->editvec))
+			ui_set_but_soft_range(but, ui_get_but_val(but));
 	}
 
 	if(block->oldblock) {
@@ -691,14 +697,14 @@
 		case TOG3:
 		case BUT_TOGDUAL:
 		case ICONTOG:
-			if(value!=but->min) push= 1;
+			if(value!=but->hardmin) push= 1;
 			break;
 		case ICONTOGN:
 		case TOGN:
 			if(value==0.0) push= 1;
 			break;
 		case ROW:
-			if(value == but->max) push= 1;
+			if(value == but->hardmax) push= 1;
 			break;
 		case COL:
 			push= 1;
@@ -733,7 +739,7 @@
 			}
 		}
 		else if(but->type==INLINK && bt->type==LINK) {
-			if( bt->link->tocode == (int)but->min ) {
+			if( bt->link->tocode == (int)but->hardmin ) {
 				return bt;
 			}
 		}
@@ -1420,9 +1426,94 @@
 			RNA_property_string_set(&but->rnapoin, but->rnaprop, str);
 	}
 	else
-		BLI_strncpy(but->poin, str, but->max);
+		BLI_strncpy(but->poin, str, but->hardmax);
 }
 
+static double soft_range_round_up(double value, double max)
+{
+	/* round up to .., 0.1, 0.2, 0.5, 1, 2, 5, 10, 20, 50, .. */
+	double newmax= pow(10.0, ceil(log(value)/log(10.0)));
+
+	if(newmax*0.2 >= max && newmax*0.2 >= value)
+		return newmax*0.2;
+	else if(newmax*0.5 >= max && newmax*0.5 >= value)
+		return newmax*0.5;
+	else
+		return newmax;
+}
+
+static double soft_range_round_down(double value, double max)
+{
+	/* round down to .., 0.1, 0.2, 0.5, 1, 2, 5, 10, 20, 50, .. */
+	double newmax= pow(10.0, floor(log(value)/log(10.0)));
+
+	if(newmax*5.0 <= max && newmax*5.0 <= value)
+		return newmax*5.0;
+	else if(newmax*2.0 <= max && newmax*2.0 <= value)
+		return newmax*2.0;
+	else
+		return newmax;
+}
+
+void ui_set_but_soft_range(uiBut *but, double value)
+{
+	PropertyType type;
+	double softmin, softmax, step, precision;
+	
+	if(but->rnaprop) {
+		type= RNA_property_type(&but->rnapoin, but->rnaprop);
+
+		if(type == PROP_INT) {
+			int imin, imax, istep;
+
+			RNA_property_int_ui_range(&but->rnapoin, but->rnaprop, &imin, &imax, &istep);
+			softmin= imin;
+			softmax= imax;
+			step= istep;
+			precision= 1;
+		}
+		else if(type == PROP_FLOAT) {
+			float fmin, fmax, fstep, fprecision;
+
+			RNA_property_float_ui_range(&but->rnapoin, but->rnaprop, &fmin, &fmax, &fstep, &fprecision);
+			softmin= fmin;
+			softmax= fmax;
+			step= fstep;
+			precision= fprecision;
+		}
+		else
+			return;
+
+		/* clamp button range to something reasonable in case
+		 * we get -inf/inf from RNA properties */
+		softmin= MAX2(softmin, -1e4);
+		softmax= MIN2(softmax, 1e4);
+
+		/* 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);
+			else
+				softmin= soft_range_round_down(value, softmin);
+
+			if(softmin < but->hardmin)
+				softmin= but->hardmin;
+		}
+		else if(value-1e-10 > softmax) {
+			if(value < 0.0)
+				softmax= -soft_range_round_down(-value, -softmax);
+			else
+				softmax= soft_range_round_up(value, softmax);
+
+			if(softmax > but->hardmax)
+				softmax= but->hardmax;
+		}
+
+		but->softmin= softmin;
+		but->softmax= softmax;
+	}
+}
+
 /* ******************* Font ********************/
 
 static void ui_set_ftf_font(float aspect)
@@ -1681,14 +1772,14 @@
 		case NUMSLI:
 		case HSVSLI:
 			value= ui_get_but_val(but);
-			if(value < but->min) ui_set_but_val(but, but->min);
-			else if(value > but->max) ui_set_but_val(but, but->max);
+			if(value < but->hardmin) ui_set_but_val(but, but->hardmin);
+			else if(value > but->hardmax) ui_set_but_val(but, but->hardmax);
 			break;
 			
 		case NUMABS:
 			value= fabs( ui_get_but_val(but) );
-			if(value < but->min) ui_set_but_val(but, but->min);
-			else if(value > but->max) ui_set_but_val(but, but->max);
+			if(value < but->hardmin) ui_set_but_val(but, but->hardmin);
+			else if(value > but->hardmax) ui_set_but_val(but, but->hardmax);
 			break;
 			
 		case ICONTOG: 
@@ -1699,12 +1790,12 @@
 			
 		case ICONROW:
 			value= ui_get_but_val(but);
-			but->iconadd= (int)value- (int)(but->min);
+			but->iconadd= (int)value- (int)(but->hardmin);
 			break;
 			
 		case ICONTEXTROW:
 			value= ui_get_but_val(but);
-			but->iconadd= (int)value- (int)(but->min);
+			but->iconadd= (int)value- (int)(but->hardmin);
 			break;
 	}
 	
@@ -1741,7 +1832,7 @@
 				else sprintf(but->drawstr, "%s%.4f", but->str, value);
 			}
 			else {
-				if(but->max<10.001) sprintf(but->drawstr, "%s%.3f", but->str, value);
+				if(but->hardmax<10.001) sprintf(but->drawstr, "%s%.3f", but->str, value);
 				else sprintf(but->drawstr, "%s%.2f", but->str, value);
 			}
 		}
@@ -2133,8 +2224,8 @@
 		but->y2= (y1+y2);
 	}
 	but->poin= poin;
-	but->min= min; 
-	but->max= max;
+	but->hardmin= but->softmin= min; 
+	but->hardmax= but->softmax= max;
 	but->a1= a1; 
 	but->a2= a2;
 	but->tip= tip;
@@ -2267,13 +2358,14 @@
 
 		if(min == max || a1 == -1 || a2 == -1) {
 			if(proptype == PROP_INT) {
-				int softmin, softmax, step;
+				int hardmin, hardmax, softmin, softmax, step;
 
+				RNA_property_int_range(ptr, prop, &hardmin, &hardmax);
 				RNA_property_int_ui_range(ptr, prop, &softmin, &softmax, &step);
 
 				if(min == max) {
-					min= softmin;
-					max= softmax;
+					min= hardmin;
+					max= hardmax;
 				}
 				if(a1 == -1)
 					a1= step;
@@ -2281,13 +2373,14 @@
 					a2= 0;
 			}
 			else if(proptype == PROP_FLOAT) {
-				float softmin, softmax, step, precision;
+				float hardmin, hardmax, softmin, softmax, step, precision;
 
+				RNA_property_float_range(ptr, prop, &hardmin, &hardmax);
 				RNA_property_float_ui_range(ptr, prop, &softmin, &softmax, &step, &precision);
 
 				if(min == max) {
-					min= softmin;
-					max= softmax;
+					min= hardmin;
+					max= hardmax;
 				}
 				if(a1 == -1)
 					a1= step;

Modified: branches/blender2.5/blender/source/blender/editors/interface/interface_draw.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/interface/interface_draw.c	2009-03-29 18:34:35 UTC (rev 19449)
+++ branches/blender2.5/blender/source/blender/editors/interface/interface_draw.c	2009-03-29 18:44:49 UTC (rev 19450)
@@ -2213,7 +2213,7 @@
 	float ypos = (sunken==BUT_TEXT_SUNKEN) ? (y-1) : y;
 	char *cpoin;
 	
-	if(but->type==LABEL && but->min!=0.0) {
+	if(but->type==LABEL && but->hardmin!=0.0) {
 		UI_ThemeColor(TH_BUT_TEXT_HI);
 	}
 	else if(but->dt==UI_EMBOSSP) {
@@ -3122,7 +3122,7 @@
 	UI_ThemeColorShadeAlpha(but->themecol, but->a2, but->a2);
 
 	uiSetRoundBox(but->a1);
-	gl_round_box(GL_POLYGON, but->x1, but->y1, but->x2, but->y2, but->min);
+	gl_round_box(GL_POLYGON, but->x1, but->y1, but->x2, but->y2, but->hardmin);
 
 	glDisable(GL_BLEND);
 }
@@ -3263,7 +3263,7 @@
 		y2= but->y2;
 		
 		value= ui_get_but_val(but);
-		fac= (value-but->min)*(x2-x1)/(but->max - but->min);
+		fac= (value-but->softmin)*(x2-x1)/(but->softmax - but->softmin);
 		
 		but->sliderfunc(but->themecol, fac, but->aspect, x1, y1, x2, y2, but->flag);
 		ui_draw_text_icon(but);

Modified: branches/blender2.5/blender/source/blender/editors/interface/interface_handlers.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/interface/interface_handlers.c	2009-03-29 18:34:35 UTC (rev 19449)
+++ branches/blender2.5/blender/source/blender/editors/interface/interface_handlers.c	2009-03-29 18:44:49 UTC (rev 19450)
@@ -101,7 +101,7 @@
 
 	/* edited value */
 	char *str, *origstr;
-	double value, origvalue;
+	double value, origvalue, startvalue;
 	float vec[3], origvec[3];
 	int togdual, togonly;
 	ColorBand *coba;
@@ -300,7 +300,7 @@
 
 static void ui_apply_but_BUTM(bContext *C, uiBut *but, uiHandleButtonData *data)
 {
-	ui_set_but_val(but, but->min);
+	ui_set_but_val(but, but->hardmin);
 	ui_apply_but_func(C, but);
 
 	data->retval= but->retval;
@@ -381,7 +381,7 @@
 
 static void ui_apply_but_ROW(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data)
 {
-	ui_set_but_val(but, but->max);
+	ui_set_but_val(but, but->hardmax);
 	ui_apply_but_func(C, but);
 
 	data->retval= but->retval;
@@ -426,8 +426,10 @@
 
 		if(!ui_is_but_float(but)) data->value= (int)data->value;
 		if(but->type==NUMABS) data->value= fabs(data->value);
-		if(data->value<but->min) data->value= but->min;
-		if(data->value>but->max) data->value= but->max;
+
+		/* not that we use hard limits here */
+		if(data->value<but->hardmin) data->value= but->hardmin;
+		if(data->value>but->hardmax) data->value= but->hardmax;
 	}
 
 	ui_set_but_val(but, data->value);
@@ -1138,7 +1140,7 @@
 
 	/* retrieve string */
 	if(but->type == TEX) {
-		data->maxlen= but->max;
+		data->maxlen= but->hardmax;
 		data->str= MEM_callocN(sizeof(char)*(data->maxlen+1), "textedit str");
 
 		ui_get_but_string(but, data->str, data->maxlen+1);
@@ -1389,18 +1391,9 @@
 
 /* ************* number editing for various types ************* */
 
-static void but_clamped_range(uiBut *but, float *butmin, float *butmax, float *butrange)
-{
-	/* clamp button range to something reasonable in case
-	 * we get -inf/inf from RNA properties */
-	*butmin= MAX2(but->min, -1e4f);
-	*butmax= MIN2(but->max, 1e4f);
-	*butrange= *butmax - *butmin;
-}
-
 static void ui_numedit_begin(uiBut *but, uiHandleButtonData *data)
 {
-	float butrange, butmin, butmax;
+	float softrange, softmin, softmax;
 
 	if(but->type == BUT_CURVE) {
 		data->cumap= (CurveMapping*)but->poin;
@@ -1416,13 +1409,16 @@
 		but->editvec= data->vec;
 	}
 	else {
-		data->origvalue= ui_get_but_val(but);
+		data->startvalue= ui_get_but_val(but);
+		data->origvalue= data->startvalue;
 		data->value= data->origvalue;
 		but->editval= &data->value;
 
-		but_clamped_range(but, &butmin, &butmax, &butrange);
+		softmin= but->softmin;
+		softmax= but->softmax;
+		softrange= softmax - softmin;
 
-		data->dragfstart= (butrange == 0.0)? 0.0f: (data->value - butmin)/butrange;

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list