[Bf-blender-cvs] [b44ea9f8bb1] blender2.8: Ruler Tool: Fix text background glitch

Clément Foucault noreply at git.blender.org
Mon Nov 12 13:50:26 CET 2018


Commit: b44ea9f8bb10dd6550c9c147cf71605542b0747c
Author: Clément Foucault
Date:   Sat Nov 10 18:39:22 2018 +0100
Branches: blender2.8
https://developer.blender.org/rBb44ea9f8bb10dd6550c9c147cf71605542b0747c

Ruler Tool: Fix text background glitch

It was using UI_draw_roundbox_aa which is not available when drawing with
the view3d opengl context (because of VAO not being shared). Replace with
simpler rect box. Of course it's a bit more ugly but at least it's working.

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

M	source/blender/editors/space_view3d/view3d_gizmo_ruler.c
M	source/blender/editors/space_view3d/view3d_ruler.c

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

diff --git a/source/blender/editors/space_view3d/view3d_gizmo_ruler.c b/source/blender/editors/space_view3d/view3d_gizmo_ruler.c
index 06dcafbe614..f35b88950d7 100644
--- a/source/blender/editors/space_view3d/view3d_gizmo_ruler.c
+++ b/source/blender/editors/space_view3d/view3d_gizmo_ruler.c
@@ -652,30 +652,33 @@ static void gizmo_ruler_draw(const bContext *C, wmGizmo *gz)
 			GPU_blend(false);
 		}
 
+		/* text */
+		char numstr[256];
+		float numstr_size[2];
+		float posit[2];
+		const int prec = 2;  /* XXX, todo, make optional */
+
+		ruler_item_as_string(ruler_item, unit, numstr, sizeof(numstr), prec);
+
+		BLF_width_and_height(blf_mono_font, numstr, sizeof(numstr), &numstr_size[0], &numstr_size[1]);
+
+		posit[0] = co_ss[1][0] + (cap_size * 2.0f);
+		posit[1] = co_ss[1][1] - (numstr_size[1] / 2.0f);
+
+		/* draw text (bg) */
+		{
+			immUniformColor4fv(color_back);
+			GPU_blend(true);
+			immRectf(shdr_pos,
+			         posit[0] - bg_margin,                  posit[1] - bg_margin,
+			         posit[0] + bg_margin + numstr_size[0], posit[1] + bg_margin + numstr_size[1]);
+			GPU_blend(false);
+		}
+
 		immUnbindProgram();
 
-		/* text */
+		/* draw text */
 		{
-			char numstr[256];
-			float numstr_size[2];
-			float posit[2];
-			const int prec = 2;  /* XXX, todo, make optional */
-
-			ruler_item_as_string(ruler_item, unit, numstr, sizeof(numstr), prec);
-
-			BLF_width_and_height(blf_mono_font, numstr, sizeof(numstr), &numstr_size[0], &numstr_size[1]);
-
-			posit[0] = co_ss[1][0] + (cap_size * 2.0f);
-			posit[1] = co_ss[1][1] - (numstr_size[1] / 2.0f);
-
-			/* draw text (bg) */
-			UI_draw_roundbox_corner_set(UI_CNR_ALL);
-			UI_draw_roundbox_aa(
-			        true,
-			        posit[0] - bg_margin,                  posit[1] - bg_margin,
-			        posit[0] + bg_margin + numstr_size[0], posit[1] + bg_margin + numstr_size[1],
-			        bg_radius, color_back);
-			/* draw text */
 			BLF_color3ubv(blf_mono_font, color_text);
 			BLF_position(blf_mono_font, posit[0], posit[1], 0.0f);
 			BLF_rotation(blf_mono_font, 0.0f);
@@ -735,33 +738,36 @@ static void gizmo_ruler_draw(const bContext *C, wmGizmo *gz)
 			GPU_blend(false);
 		}
 
-		immUnbindProgram();
-
 		/* text */
-		{
-			char numstr[256];
-			float numstr_size[2];
-			const int prec = 6;  /* XXX, todo, make optional */
-			float posit[2];
+		char numstr[256];
+		float numstr_size[2];
+		const int prec = 6;  /* XXX, todo, make optional */
+		float posit[2];
 
-			ruler_item_as_string(ruler_item, unit, numstr, sizeof(numstr), prec);
+		ruler_item_as_string(ruler_item, unit, numstr, sizeof(numstr), prec);
 
-			BLF_width_and_height(blf_mono_font, numstr, sizeof(numstr), &numstr_size[0], &numstr_size[1]);
+		BLF_width_and_height(blf_mono_font, numstr, sizeof(numstr), &numstr_size[0], &numstr_size[1]);
 
-			mid_v2_v2v2(posit, co_ss[0], co_ss[2]);
+		mid_v2_v2v2(posit, co_ss[0], co_ss[2]);
 
-			/* center text */
-			posit[0] -= numstr_size[0] / 2.0f;
-			posit[1] -= numstr_size[1] / 2.0f;
+		/* center text */
+		posit[0] -= numstr_size[0] / 2.0f;
+		posit[1] -= numstr_size[1] / 2.0f;
 
-			/* draw text (bg) */
-			UI_draw_roundbox_corner_set(UI_CNR_ALL);
-			UI_draw_roundbox_aa(
-			        true,
-			        posit[0] - bg_margin,                  posit[1] - bg_margin,
-			        posit[0] + bg_margin + numstr_size[0], posit[1] + bg_margin + numstr_size[1],
-			        bg_radius, color_back);
-			/* draw text */
+		/* draw text (bg) */
+		{
+			immUniformColor4fv(color_back);
+			GPU_blend(true);
+			immRectf(shdr_pos,
+			         posit[0] - bg_margin,                  posit[1] - bg_margin,
+			         posit[0] + bg_margin + numstr_size[0], posit[1] + bg_margin + numstr_size[1]);
+			GPU_blend(false);
+		}
+
+		immUnbindProgram();
+
+		/* draw text */
+		{
 			BLF_color3ubv(blf_mono_font, color_text);
 			BLF_position(blf_mono_font, posit[0], posit[1], 0.0f);
 			BLF_draw(blf_mono_font, numstr, sizeof(numstr));
diff --git a/source/blender/editors/space_view3d/view3d_ruler.c b/source/blender/editors/space_view3d/view3d_ruler.c
index 1250e97c26f..0d61fa30ebf 100644
--- a/source/blender/editors/space_view3d/view3d_ruler.c
+++ b/source/blender/editors/space_view3d/view3d_ruler.c
@@ -566,28 +566,32 @@ static void ruler_info_draw_pixel(const struct bContext *C, ARegion *ar, void *a
 				GPU_blend(false);
 			}
 
-			immUnbindProgram();
+			char numstr[256];
+			float numstr_size[2];
+			float posit[2];
+			const int prec = 2;  /* XXX, todo, make optional */
 
-			/* text */
-			{
-				char numstr[256];
-				float numstr_size[2];
-				float posit[2];
-				const int prec = 2;  /* XXX, todo, make optional */
+			ruler_item_as_string(ruler_item, unit, numstr, sizeof(numstr), prec);
 
-				ruler_item_as_string(ruler_item, unit, numstr, sizeof(numstr), prec);
+			BLF_width_and_height(blf_mono_font, numstr, sizeof(numstr), &numstr_size[0], &numstr_size[1]);
 
-				BLF_width_and_height(blf_mono_font, numstr, sizeof(numstr), &numstr_size[0], &numstr_size[1]);
+			posit[0] = co_ss[1][0] + (cap_size * 2.0f);
+			posit[1] = co_ss[1][1] - (numstr_size[1] / 2.0f);
 
-				posit[0] = co_ss[1][0] + (cap_size * 2.0f);
-				posit[1] = co_ss[1][1] - (numstr_size[1] / 2.0f);
+			/* draw text (bg) */
+			{
+				immUniformColor4fv(color_back);
+				GPU_blend(true);
+				immRectf(shdr_pos,
+				         posit[0] - bg_margin,                  posit[1] - bg_margin,
+				         posit[0] + bg_margin + numstr_size[0], posit[1] + bg_margin + numstr_size[1]);
+				GPU_blend(false);
+			}
+
+			immUnbindProgram();
 
-				/* draw text (bg) */
-				UI_draw_roundbox_corner_set(UI_CNR_ALL);
-				UI_draw_roundbox_aa(true,
-				        posit[0] - bg_margin,                  posit[1] - bg_margin,
-				        posit[0] + bg_margin + numstr_size[0], posit[1] + bg_margin + numstr_size[1],
-				        bg_radius, color_back);
+			/* text */
+			{
 				/* draw text */
 				BLF_color3ubv(blf_mono_font, color_text);
 				BLF_position(blf_mono_font, posit[0], posit[1], 0.0f);
@@ -648,31 +652,35 @@ static void ruler_info_draw_pixel(const struct bContext *C, ARegion *ar, void *a
 				GPU_blend(false);
 			}
 
-			immUnbindProgram();
+			char numstr[256];
+			float numstr_size[2];
+			const int prec = 6;  /* XXX, todo, make optional */
+			float posit[2];
 
-			/* text */
-			{
-				char numstr[256];
-				float numstr_size[2];
-				const int prec = 6;  /* XXX, todo, make optional */
-				float posit[2];
+			ruler_item_as_string(ruler_item, unit, numstr, sizeof(numstr), prec);
 
-				ruler_item_as_string(ruler_item, unit, numstr, sizeof(numstr), prec);
+			BLF_width_and_height(blf_mono_font, numstr, sizeof(numstr), &numstr_size[0], &numstr_size[1]);
 
-				BLF_width_and_height(blf_mono_font, numstr, sizeof(numstr), &numstr_size[0], &numstr_size[1]);
+			mid_v2_v2v2(posit, co_ss[0], co_ss[2]);
 
-				mid_v2_v2v2(posit, co_ss[0], co_ss[2]);
+			/* center text */
+			posit[0] -= numstr_size[0] / 2.0f;
+			posit[1] -= numstr_size[1] / 2.0f;
 
-				/* center text */
-				posit[0] -= numstr_size[0] / 2.0f;
-				posit[1] -= numstr_size[1] / 2.0f;
+			/* draw text (bg) */
+			{
+				immUniformColor4fv(color_back);
+				GPU_blend(true);
+				immRectf(shdr_pos,
+				         posit[0] - bg_margin,                  posit[1] - bg_margin,
+				         posit[0] + bg_margin + numstr_size[0], posit[1] + bg_margin + numstr_size[1]);
+				GPU_blend(false);
+			}
+
+			immUnbindProgram();
 
-				/* draw text (bg) */
-				UI_draw_roundbox_corner_set(UI_CNR_ALL);
-				UI_draw_roundbox_aa(true,
-				           posit[0] - bg_margin,                  posit[1] - bg_margin,
-				           posit[0] + bg_margin + numstr_size[0], posit[1] + bg_margin + numstr_size[1],
-				           bg_radius, color_back);
+			/* text */
+			{
 				/* draw text */
 				BLF_color3ubv(blf_mono_font, color_text);
 				BLF_position(blf_mono_font, posit[0], posit[1], 0.0f);



More information about the Bf-blender-cvs mailing list