From c192ce6717d7c1da741d80671ffcc7ea02e664c8 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 5 Nov 2018 10:44:30 +1100 Subject: Gizmo: use fonts for drawing 3D axis characters --- .../space_view3d/view3d_gizmo_navigate_type.c | 63 +++++++++++++++++++++- 1 file changed, 61 insertions(+), 2 deletions(-) (limited to 'source/blender/editors/space_view3d/view3d_gizmo_navigate_type.c') diff --git a/source/blender/editors/space_view3d/view3d_gizmo_navigate_type.c b/source/blender/editors/space_view3d/view3d_gizmo_navigate_type.c index 169a7387302..5c251fe4136 100644 --- a/source/blender/editors/space_view3d/view3d_gizmo_navigate_type.c +++ b/source/blender/editors/space_view3d/view3d_gizmo_navigate_type.c @@ -60,6 +60,11 @@ #include "view3d_intern.h" +#define USE_AXIS_FONT +#ifdef USE_AXIS_FONT +# include "BLF_api.h" +#endif + #define DIAL_RESOLUTION 32 /* Sizes of axis spheres containing XYZ characters. */ @@ -69,6 +74,7 @@ /* How far axis handles are away from the center. */ #define AXIS_HANDLE_OFFSET (1.0f - AXIS_HANDLE_SIZE_FG) +#ifndef USE_AXIS_FONT /** * \param viewmat_local_unit is typically the 'rv3d->viewmatob' * copied into a 3x3 matrix and normalized. @@ -172,8 +178,12 @@ static void draw_xyz_wire( } immEnd(); } +#endif /* !USE_AXIS_FONT */ -static void axis_geom_draw(const wmGizmo *gz, const float color[4], const bool UNUSED(select)) +static void axis_geom_draw( + const wmGizmo *gz, const float color[4], const bool UNUSED(select), + /* Needed for screen-aligned font drawing. */ + const float matrix_final[4][4]) { GPU_line_width(gz->line_width); @@ -199,6 +209,33 @@ static void axis_geom_draw(const wmGizmo *gz, const float color[4], const bool U static const float axis_highlight[4] = {1, 1, 1, 1}; static const float axis_black[4] = {0, 0, 0, 1}; static float axis_color[3][4]; + + +#ifdef USE_AXIS_FONT + struct { + float matrix[4][4]; + } font; + + { + BLF_disable(blf_mono_font, BLF_ROTATION | BLF_SHADOW | BLF_MATRIX | BLF_ASPECT | BLF_WORD_WRAP); + BLF_color4fv(blf_mono_font, axis_black); + BLF_size(blf_mono_font, 11 * U.dpi_fac, 72); + + /* Calculate the inverse of the (matrix_final * matrix_offset). + * This allows us to use the final location, while reversing the rotation so fonts + * show without any rotation. */ + float m3[3][3]; + float m3_offset[3][3]; + copy_m3_m4(m3, matrix_final); + copy_m3_m4(m3_offset, gz->matrix_offset); + mul_m3_m3m3(m3, m3, m3_offset); + invert_m3(m3); + copy_m4_m3(font.matrix, m3); + } +#else + UNUSED_VARS(matrix_final); +#endif + GPU_matrix_push(); GPU_matrix_mul(gz->matrix_offset); @@ -292,15 +329,37 @@ static void axis_geom_draw(const wmGizmo *gz, const float color[4], const bool U /* Axis XYZ Character. */ if (show_axis_char) { +#ifdef USE_AXIS_FONT + immUnbindProgram(); + + GPU_matrix_push(); + GPU_matrix_translate_3fv(v_final); + GPU_matrix_mul(font.matrix); + + const char axis_str[2] = {'X' + axis, 0}; + float offset[2] = {0}; + BLF_width_and_height(blf_mono_font, axis_str, 2, &offset[0], &offset[1]); + BLF_position(blf_mono_font, roundf(offset[0] * -0.5f), roundf(offset[1] * -0.5f), 0); + BLF_draw_ascii(blf_mono_font, axis_str, 2); + GPU_blend(true); /* XXX, blf disables */ + GPU_matrix_pop(); + + immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); +#else GPU_line_width(1.0f); float m3[3][3]; copy_m3_m4(m3, gz->matrix_offset); immUniformColor4fv(axis_black); draw_xyz_wire(pos_id, m3, v_final, 1.0, axis); +#endif } } } +#ifdef USE_AXIS_FONT + BLF_disable(blf_mono_font, BLF_MATRIX); +#endif + GPU_matrix_pop(); immUnbindProgram(); } @@ -325,7 +384,7 @@ static void axis3d_draw_intern( GPU_matrix_mul(matrix_final); GPU_blend(true); - axis_geom_draw(gz, color, select); + axis_geom_draw(gz, color, select, matrix_final); GPU_blend(false); GPU_matrix_pop(); } -- cgit v1.2.3