From b44ea9f8bb10dd6550c9c147cf71605542b0747c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Sat, 10 Nov 2018 18:39:22 +0100 Subject: 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. --- .../editors/space_view3d/view3d_gizmo_ruler.c | 90 ++++++++++++---------- 1 file changed, 48 insertions(+), 42 deletions(-) (limited to 'source/blender/editors/space_view3d/view3d_gizmo_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)); -- cgit v1.2.3