[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [37285] trunk/blender/source/blender/ editors/interface/interface.c: Move UI float precission calculation into its own function.

Campbell Barton ideasman42 at gmail.com
Tue Jun 7 04:39:40 CEST 2011


Revision: 37285
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37285
Author:   campbellbarton
Date:     2011-06-07 02:39:40 +0000 (Tue, 07 Jun 2011)
Log Message:
-----------
Move UI float precission calculation into its own function.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/interface/interface.c

Modified: trunk/blender/source/blender/editors/interface/interface.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface.c	2011-06-07 01:49:31 UTC (rev 37284)
+++ trunk/blender/source/blender/editors/interface/interface.c	2011-06-07 02:39:40 UTC (rev 37285)
@@ -449,6 +449,14 @@
 
 /* link line drawing is not part of buttons or theme.. so we stick with it here */
 
+static int ui_but_float_precision(uiBut *but, double UNUSED(value))
+{
+	int prec= (int)but->a2;
+	if(prec==0) prec= (but->hardmax < 10.001f) ? 3 : 2;
+	else CLAMP(prec, 1, 7);
+	return prec;
+}
+
 static void ui_draw_linkline(uiLinkLine *line)
 {
 	rcti rect;
@@ -1530,10 +1538,7 @@
 				ui_get_but_string_unit(but, str, maxlen, value, 0);
 			}
 			else {
-				int prec= (int)but->a2;
-				if(prec==0) prec= 3;
-				else CLAMP(prec, 1, 7);
-
+				const int prec= ui_but_float_precision(but, value);
 				BLI_snprintf(str, maxlen, "%.*f", prec, value);
 			}
 		}
@@ -2009,10 +2014,7 @@
 				BLI_snprintf(but->drawstr, sizeof(but->drawstr), "%s%s", but->str, new_str);
 			}
 			else {
-				int prec= (int)but->a2;
-				if(prec==0) prec= (but->hardmax < 10.001f) ? 3 : 2;
-				else CLAMP(prec, 1, 7);
-
+				const int prec= ui_but_float_precision(but, value);
 				BLI_snprintf(but->drawstr, sizeof(but->drawstr), "%s%.*f", but->str, prec, value);
 			}
 		}
@@ -2030,11 +2032,9 @@
 
 	case LABEL:
 		if(ui_is_but_float(but)) {
-			int prec= (int)but->a2;
+			int prec;
 			value= ui_get_but_val(but);
-			if(prec==0) prec= 3;
-			else CLAMP(prec, 1, 7);
-
+			prec= ui_but_float_precision(but, value);
 			BLI_snprintf(but->drawstr, sizeof(but->drawstr), "%s%.*f", but->str, prec, value);
 		}
 		else {




More information about the Bf-blender-cvs mailing list