[Bf-blender-cvs] [09eec62] master: UI: cleanup UI_fontstyle_string_width, UI_draw_string

Campbell Barton noreply at git.blender.org
Tue Jan 20 06:06:17 CET 2015


Commit: 09eec627ed730532905b45d409f9009023623437
Author: Campbell Barton
Date:   Tue Jan 20 14:25:39 2015 +1100
Branches: master
https://developer.blender.org/rB09eec627ed730532905b45d409f9009023623437

UI: cleanup UI_fontstyle_string_width, UI_draw_string

Both were maked as temp, but used often.

Now pass uiFontStyle to both, rename UI_draw_string to UI_fontstyle_draw_simple,
since its a variant of UI_fontstyle_draw that skips shadow, align... etc.

===================================================================

M	source/blender/editors/animation/anim_channels_defines.c
M	source/blender/editors/animation/anim_draw.c
M	source/blender/editors/animation/anim_markers.c
M	source/blender/editors/animation/fmodifier_ui.c
M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface_eyedropper.c
M	source/blender/editors/interface/interface_layout.c
M	source/blender/editors/interface/interface_regions.c
M	source/blender/editors/interface/interface_style.c
M	source/blender/editors/space_file/file_draw.c
M	source/blender/editors/space_outliner/outliner_draw.c
M	source/blender/windowmanager/intern/wm_dragdrop.c

===================================================================

diff --git a/source/blender/editors/animation/anim_channels_defines.c b/source/blender/editors/animation/anim_channels_defines.c
index d76eba9..7b29414 100644
--- a/source/blender/editors/animation/anim_channels_defines.c
+++ b/source/blender/editors/animation/anim_channels_defines.c
@@ -3519,6 +3519,7 @@ void ANIM_channel_draw(bAnimContext *ac, bAnimListElem *ale, float yminc, float
 	/* step 5) draw name ............................................... */
 	/* TODO: when renaming, we might not want to draw this, especially if name happens to be longer than channel */
 	if (acf->name) {
+		const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
 		char name[ANIM_CHAN_NAME_SIZE]; /* hopefully this will be enough! */
 		
 		/* set text color */
@@ -3532,7 +3533,7 @@ void ANIM_channel_draw(bAnimContext *ac, bAnimListElem *ale, float yminc, float
 		acf->name(ale, name);
 		
 		offset += 3;
-		UI_draw_string(offset, ytext, name);
+		UI_fontstyle_draw_simple(fstyle, offset, ytext, name);
 		
 		/* draw red underline if channel is disabled */
 		if ((ale->type == ANIMTYPE_FCURVE) && (ale->flag & FCURVE_DISABLED)) {
diff --git a/source/blender/editors/animation/anim_draw.c b/source/blender/editors/animation/anim_draw.c
index 2d76566..0e05227 100644
--- a/source/blender/editors/animation/anim_draw.c
+++ b/source/blender/editors/animation/anim_draw.c
@@ -59,6 +59,7 @@
 /* Draw current frame number in a little green box beside the current frame indicator */
 static void draw_cfra_number(Scene *scene, View2D *v2d, const float cfra, const bool time)
 {
+	const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
 	float xscale, yscale, x, y;
 	char numstr[32] = "    t";  /* t is the character to start replacing from */
 	int slen;
@@ -78,7 +79,8 @@ static void draw_cfra_number(Scene *scene, View2D *v2d, const float cfra, const
 	else {
 		BLI_timecode_string_from_time_simple(&numstr[4], sizeof(numstr) - 4, 1, cfra);
 	}
-	slen = UI_fontstyle_string_width(numstr) - 1;
+
+	slen = UI_fontstyle_string_width(fstyle, numstr) - 1;
 	
 	/* get starting coordinates for drawing */
 	x = cfra * xscale;
@@ -90,7 +92,7 @@ static void draw_cfra_number(Scene *scene, View2D *v2d, const float cfra, const
 	
 	/* draw current frame number - black text */
 	UI_ThemeColor(TH_TEXT);
-	UI_draw_string(x - 0.25f * U.widget_unit, y + 0.15f * U.widget_unit, numstr);
+	UI_fontstyle_draw_simple(fstyle, x - 0.25f * U.widget_unit, y + 0.15f * U.widget_unit, numstr);
 	
 	/* restore view transform */
 	glScalef(xscale, 1.0, 1.0);
diff --git a/source/blender/editors/animation/anim_markers.c b/source/blender/editors/animation/anim_markers.c
index b6c7a4a..d778b06 100644
--- a/source/blender/editors/animation/anim_markers.c
+++ b/source/blender/editors/animation/anim_markers.c
@@ -317,7 +317,7 @@ void debug_markers_print_list(ListBase *markers)
 
 /* function to draw markers */
 static void draw_marker(
-        View2D *v2d, TimeMarker *marker, int cfra, int flag,
+        View2D *v2d, const uiFontStyle *fstyle, TimeMarker *marker, int cfra, int flag,
         /* avoid re-calculating each time */
         const float ypixels, const float xscale, const float yscale)
 {
@@ -399,13 +399,14 @@ static void draw_marker(
 		}
 #endif
 
-		UI_draw_string(x, y, marker->name);
+		UI_fontstyle_draw_simple(fstyle, x, y, marker->name);
 	}
 }
 
 /* Draw Scene-Markers in time window */
 void ED_markers_draw(const bContext *C, int flag)
 {
+	const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
 	ListBase *markers = ED_context_get_markers(C);
 	View2D *v2d;
 	TimeMarker *marker;
@@ -455,7 +456,7 @@ void ED_markers_draw(const bContext *C, int flag)
 				if ((marker->frame >= v2d_clip_range_x[0]) &&
 				    (marker->frame <= v2d_clip_range_x[1]))
 				{
-					draw_marker(v2d, marker, scene->r.cfra, flag,
+					draw_marker(v2d, fstyle, marker, scene->r.cfra, flag,
 					            ypixels, xscale, yscale);
 				}
 			}
diff --git a/source/blender/editors/animation/fmodifier_ui.c b/source/blender/editors/animation/fmodifier_ui.c
index 8ede1a0..bcdad1c 100644
--- a/source/blender/editors/animation/fmodifier_ui.c
+++ b/source/blender/editors/animation/fmodifier_ui.c
@@ -130,6 +130,7 @@ static void draw_modifier__generator(uiLayout *layout, ID *id, FModifier *fcm, s
 	switch (data->mode) {
 		case FCM_GENERATOR_POLYNOMIAL: /* polynomial expression */
 		{
+			const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
 			float *cp = NULL;
 			char xval[32];
 			unsigned int i;
@@ -147,11 +148,12 @@ static void draw_modifier__generator(uiLayout *layout, ID *id, FModifier *fcm, s
 			/* calculate maximum width of label for "x^n" labels */
 			if (data->arraysize > 2) {
 				BLI_snprintf(xval, sizeof(xval), "x^%u", data->arraysize);
-				maxXWidth = UI_fontstyle_string_width(xval) + 0.5 * UI_UNIT_X; /* XXX: UI_fontstyle_string_width is not accurate */
+				/* XXX: UI_fontstyle_string_width is not accurate */
+				maxXWidth = UI_fontstyle_string_width(fstyle, xval) + 0.5 * UI_UNIT_X;
 			}
 			else {
 				/* basic size (just "x") */
-				maxXWidth = UI_fontstyle_string_width("x") + 0.5 * UI_UNIT_X;
+				maxXWidth = UI_fontstyle_string_width(fstyle, "x") + 0.5 * UI_UNIT_X;
 			}
 			
 			/* draw controls for each coefficient and a + sign at end of row */
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 159fda8..da857c2 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -974,15 +974,15 @@ void UI_context_active_but_prop_get_filebrowser(const struct bContext *C, struct
 void UI_context_active_but_prop_get_templateID(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA **prop);
 
 /* Styled text draw */
-void UI_fontstyle_set(struct uiFontStyle *fs);
+void UI_fontstyle_set(const struct uiFontStyle *fs);
 void UI_fontstyle_draw_ex(
-        struct uiFontStyle *fs, const struct rcti *rect, const char *str,
+        const struct uiFontStyle *fs, const struct rcti *rect, const char *str,
         size_t len, float *r_xofs, float *r_yofs);
-void UI_fontstyle_draw(struct uiFontStyle *fs, const struct rcti *rect, const char *str);
-void UI_fontstyle_draw_rotated(struct uiFontStyle *fs, const struct rcti *rect, const char *str);
+void UI_fontstyle_draw(const struct uiFontStyle *fs, const struct rcti *rect, const char *str);
+void UI_fontstyle_draw_rotated(const struct uiFontStyle *fs, const struct rcti *rect, const char *str);
+void UI_fontstyle_draw_simple(const struct uiFontStyle *fs, float x, float y, const char *str);
 
-int UI_fontstyle_string_width(const char *str); // XXX temp
-void UI_draw_string(float x, float y, const char *str); // XXX temp
+int UI_fontstyle_string_width(const struct uiFontStyle *fs, const char *str);
 void UI_draw_icon_tri(float x, float y, char dir);
 
 uiStyle *UI_style_get(void);		/* use for fonts etc */
@@ -1013,6 +1013,9 @@ void UI_butstore_unregister(uiButStore *bs_handle, uiBut **but_p);
 /* Float precision helpers */
 #define UI_PRECISION_FLOAT_MAX 7
 
+/* Typical UI text */
+#define UI_FSTYLE_WIDGET (const uiFontStyle *)&(UI_style_get()->widget)
+
 int UI_calc_float_precision(int prec, double value);
 
 #endif  /* __UI_INTERFACE_H__ */
diff --git a/source/blender/editors/interface/interface_eyedropper.c b/source/blender/editors/interface/interface_eyedropper.c
index 9b5d067..dfcafd7 100644
--- a/source/blender/editors/interface/interface_eyedropper.c
+++ b/source/blender/editors/interface/interface_eyedropper.c
@@ -73,10 +73,11 @@
 
 static void eyedropper_draw_cursor_text(const struct bContext *C, ARegion *ar, const char *name)
 {
-	int width;
+	const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
 	wmWindow *win = CTX_wm_window(C);
 	int x = win->eventstate->x;
 	int y = win->eventstate->y;
+	int width;
 
 	if ((name[0] == '\0') ||
 	    (BLI_rcti_isect_pt(&ar->winrct, x, y) == false))
@@ -84,7 +85,7 @@ static void eyedropper_draw_cursor_text(const struct bContext *C, ARegion *ar, c
 		return;
 	}
 
-	width = UI_fontstyle_string_width(name);
+	width = UI_fontstyle_string_width(fstyle, name);
 	x = x - ar->winrct.xmin;
 	y = y - ar->winrct.ymin;
 
@@ -96,7 +97,7 @@ static void eyedropper_draw_cursor_text(const struct bContext *C, ARegion *ar, c
 	UI_draw_roundbox(x, y, x + width + 8, y + 15, 4);
 
 	glColor4ub(255, 255, 255, 255);
-	UI_draw_string(x + 4, y + 4, name);
+	UI_fontstyle_draw_simple(fstyle, x + 4, y + 4, name);
 }
 
 /** \} */
diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c
index f02c6a2..9d1b312 100644
--- a/source/blender/editors/interface/interface_layout.c
+++ b/source/blender/editors/interface/interface_layout.c
@@ -235,9 +235,10 @@ static int ui_text_icon_width(uiLayout *layout, const char *name, int icon, bool
 	variable = (ui_layout_vary_direction(layout) == UI_ITEM_VARY_X);
 
 	if (variable) {
+		const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
 		/* it may seem odd that the icon only adds (UI_UNIT_X / 4)
 		 * but taking margins into account its fine */
-		return (UI_fontstyle_string_width(name) +
+		return (UI_fontstyle_string_width(fstyle, name) +
 		        (UI_UNIT_X * ((compact ? 1.25f : 1.50f) +
 		                      (icon    ? 0.25f : 0.0f))));
 	}
@@ -639,7 +640,7 @@ static uiBut *ui_item_with_label(uiLayout *layout, uiBlock *block, const char *n
 	if (name[0]) {
 		/* XXX UI_fontstyle_string_width is not accurate */
 #if 0
-		labelw = UI_fontstyle_string_width(name);
+		labelw = UI_fontstyle_string_width(fstyle, name);
 		CLAMP(labelw, w / 4, 3 * w / 4);
 #endif
 		labelw = w / 3;
diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c
index 0ec59e4..21e7b8e 100644
--- a/source/blender/editors/interface/interface_regions.c
+++ b/source/blender/editors/interface/interface_regions.c
@@ -2726,7 +2726,8 @@ static uiBlock *ui_block_func_PIE(bContext *UNUSED(C), uiPopupBlockHandle *handl
 
 static float ui_pie_menu_title_width(const char *name, int icon)
 {
-	return (UI_fontstyle_string_width(name) +
+	const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
+	return (UI_fontstyle_string_width(fstyle, name) +
 	         (UI_UNIT_X * (1.50f + (icon ? 0.25f

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list