From 18db6ed3c9d386bb178ab887604943298a9bac57 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 15 Mar 2022 19:50:11 +1100 Subject: Fix T96357: Issue clicking on stem of arrow gizmos to scale on axis Caused by 0cb5eae9d0617abedf745753c23061ddfcfd1416 which restored support for 3D depth when selecting gizmos - making it difficult to select single lines drawn in front of other gizmos. Previously the first hit was always used. Resolve by using a margin around arrow stems when selecting which was already done for 2D arrows. --- .../editors/gizmo_library/gizmo_types/arrow3d_gizmo.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/source/blender/editors/gizmo_library/gizmo_types/arrow3d_gizmo.c b/source/blender/editors/gizmo_library/gizmo_types/arrow3d_gizmo.c index 3362cf9732e..9cfb5e4b056 100644 --- a/source/blender/editors/gizmo_library/gizmo_types/arrow3d_gizmo.c +++ b/source/blender/editors/gizmo_library/gizmo_types/arrow3d_gizmo.c @@ -66,6 +66,11 @@ /* to use custom arrows exported to geom_arrow_gizmo.c */ //#define USE_GIZMO_CUSTOM_ARROWS +/** Margins to add when selecting the arrow stem. */ +#define ARROW_SELECT_THRESHOLD_PX_STEM (5 * UI_DPI_FAC) +/** Margins to add when selecting the arrow head. */ +#define ARROW_SELECT_THRESHOLD_PX_HEAD (12 * UI_DPI_FAC) + typedef struct ArrowGizmo3D { wmGizmo gizmo; GizmoCommonData data; @@ -88,8 +93,7 @@ static void arrow_draw_geom(const ArrowGizmo3D *arrow, const bool select, const const int draw_style = RNA_enum_get(arrow->gizmo.ptr, "draw_style"); const int draw_options = RNA_enum_get(arrow->gizmo.ptr, "draw_options"); - immBindBuiltinProgram(select ? GPU_SHADER_3D_UNIFORM_COLOR : - GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR); + immBindBuiltinProgram(GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR); float viewport[4]; GPU_viewport_size_get_f(viewport); @@ -133,7 +137,9 @@ static void arrow_draw_geom(const ArrowGizmo3D *arrow, const bool select, const }; if (draw_options & ED_GIZMO_ARROW_DRAW_FLAG_STEM) { - immUniform1f("lineWidth", arrow->gizmo.line_width * U.pixelsize); + const float stem_width = (arrow->gizmo.line_width * U.pixelsize) + + (select ? ARROW_SELECT_THRESHOLD_PX_STEM : 0); + immUniform1f("lineWidth", stem_width); wm_gizmo_vec_draw(color, vec, ARRAY_SIZE(vec), pos, GPU_PRIM_LINE_STRIP); } else { @@ -144,6 +150,8 @@ static void arrow_draw_geom(const ArrowGizmo3D *arrow, const bool select, const GPU_matrix_push(); + /* NOTE: ideally #ARROW_SELECT_THRESHOLD_PX_HEAD would be added here, however adding a + * margin in pixel space isn't so simple, nor is it as important as for the arrow stem. */ if (draw_style == ED_GIZMO_ARROW_STYLE_BOX) { const float size = 0.05f; @@ -248,8 +256,8 @@ static int gizmo_arrow_test_select(bContext *UNUSED(C), wmGizmo *gz, const int m } const float mval_fl[2] = {UNPACK2(mval)}; - const float arrow_stem_threshold_px = 5 * UI_DPI_FAC; - const float arrow_head_threshold_px = 12 * UI_DPI_FAC; + const float arrow_stem_threshold_px = ARROW_SELECT_THRESHOLD_PX_STEM; + const float arrow_head_threshold_px = ARROW_SELECT_THRESHOLD_PX_HEAD; /* Distance to arrow head. */ if (len_squared_v2v2(mval_fl, arrow_end) < square_f(arrow_head_threshold_px)) { -- cgit v1.2.3