Fix T96357: Issue clicking on stem of arrow gizmos to scale on axis

Caused by 0cb5eae9d0 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.
This commit is contained in:
Campbell Barton 2022-03-15 19:50:11 +11:00 committed by Philipp Oeser
parent 188277f951
commit 18db6ed3c9
Notes: blender-bot 2023-02-14 04:56:36 +01:00
Referenced by issue #96357, Issue clicking on stem of arrow gizmos to scale on axis
Referenced by issue #96241, 3.1: Potential candidates for corrective releases
1 changed files with 13 additions and 5 deletions

View File

@ -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)) {