From dc5b1d6c75717a41c00042b667bc4a1a1609e588 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 4 Apr 2022 13:11:44 +1000 Subject: Cleanup: pass selection threshold to curve picking Remove the extended version of ED_curve_editnurb_select_pick, pass the size threshold directly to this function but as the distance in pixels instead of a multiplier for ED_view3d_select_dist_px. Using a multiplier is a less direct way to reference the threshold. --- source/blender/editors/curve/curve_intern.h | 2 +- source/blender/editors/curve/editcurve.c | 12 ++---------- source/blender/editors/curve/editcurve_pen.c | 11 +++++++---- source/blender/editors/curve/editcurve_query.c | 2 +- source/blender/editors/include/ED_curve.h | 10 ++-------- source/blender/editors/space_view3d/view3d_select.c | 2 +- 6 files changed, 14 insertions(+), 25 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/curve/curve_intern.h b/source/blender/editors/curve/curve_intern.h index c96b75ff3e7..0f27f26b458 100644 --- a/source/blender/editors/curve/curve_intern.h +++ b/source/blender/editors/curve/curve_intern.h @@ -204,7 +204,7 @@ bool ED_curve_pick_vert(struct ViewContext *vc, */ bool ED_curve_pick_vert_ex(struct ViewContext *vc, short sel, - float dist_px, + int dist_px, struct Nurb **r_nurb, struct BezTriple **r_bezt, struct BPoint **r_bp, diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c index 58ee5ccae64..755e538f415 100644 --- a/source/blender/editors/curve/editcurve.c +++ b/source/blender/editors/curve/editcurve.c @@ -4725,15 +4725,8 @@ void CURVE_OT_make_segment(wmOperatorType *ot) bool ED_curve_editnurb_select_pick(bContext *C, const int mval[2], + const int dist_px, const struct SelectPick_Params *params) -{ - return ED_curve_editnurb_select_pick_ex(C, mval, 1.0f, params); -} - -bool ED_curve_editnurb_select_pick_ex(bContext *C, - const int mval[2], - const float sel_dist_mul, - const struct SelectPick_Params *params) { Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); ViewContext vc; @@ -4748,8 +4741,7 @@ bool ED_curve_editnurb_select_pick_ex(bContext *C, ED_view3d_viewcontext_init(C, &vc, depsgraph); copy_v2_v2_int(vc.mval, mval); - bool found = ED_curve_pick_vert_ex( - &vc, 1, sel_dist_mul * ED_view3d_select_dist_px(), &nu, &bezt, &bp, &hand, &basact); + bool found = ED_curve_pick_vert_ex(&vc, 1, dist_px, &nu, &bezt, &bp, &hand, &basact); if (params->sel_op == SEL_OP_SET) { if ((found && params->select_passthrough) && diff --git a/source/blender/editors/curve/editcurve_pen.c b/source/blender/editors/curve/editcurve_pen.c index e3a2bd479bb..0524159fe54 100644 --- a/source/blender/editors/curve/editcurve_pen.c +++ b/source/blender/editors/curve/editcurve_pen.c @@ -844,8 +844,9 @@ static bool insert_point_to_segment(const ViewContext *vc, const wmEvent *event) Curve *cu = vc->obedit->data; CutData cd = init_cut_data(event); float mval[2] = {UNPACK2(event->mval)}; + const float threshold_dist_px = ED_view3d_select_dist_px() * SEL_DIST_FACTOR; const bool near_spline = update_cut_data_for_all_nurbs( - vc, BKE_curve_editNurbs_get(cu), mval, SEL_DIST_FACTOR * ED_view3d_select_dist_px(), &cd); + vc, BKE_curve_editNurbs_get(cu), mval, threshold_dist_px, &cd); if (near_spline && !cd.nurb->hide) { Nurb *nu = cd.nurb; @@ -1554,6 +1555,7 @@ static int curve_pen_modal(bContext *C, wmOperator *op, const wmEvent *event) ED_view3d_viewcontext_init(C, &vc, depsgraph); Curve *cu = vc.obedit->data; ListBase *nurbs = &cu->editnurb->nurbs; + const float threshold_dist_px = ED_view3d_select_dist_px() * SEL_DIST_FACTOR; BezTriple *bezt = NULL; BPoint *bp = NULL; @@ -1655,7 +1657,7 @@ static int curve_pen_modal(bContext *C, wmOperator *op, const wmEvent *event) else if (ELEM(event->type, LEFTMOUSE)) { if (ELEM(event->val, KM_RELEASE, KM_DBL_CLICK)) { if (delete_point && !cpd->new_point && !cpd->dragging) { - if (ED_curve_editnurb_select_pick_ex(C, event->mval, SEL_DIST_FACTOR, ¶ms)) { + if (ED_curve_editnurb_select_pick(C, event->mval, threshold_dist_px, ¶ms)) { cpd->acted = delete_point_under_mouse(&vc, event); } } @@ -1714,7 +1716,7 @@ static int curve_pen_modal(bContext *C, wmOperator *op, const wmEvent *event) } } else if (select_point) { - ED_curve_editnurb_select_pick_ex(C, event->mval, SEL_DIST_FACTOR, ¶ms); + ED_curve_editnurb_select_pick(C, event->mval, threshold_dist_px, ¶ms); } } @@ -1749,6 +1751,7 @@ static int curve_pen_invoke(bContext *C, wmOperator *op, const wmEvent *event) /* Distance threshold for mouse clicks to affect the spline or its points */ const float mval_fl[2] = {UNPACK2(event->mval)}; + const float threshold_dist_px = ED_view3d_select_dist_px() * SEL_DIST_FACTOR; const bool extrude_point = RNA_boolean_get(op->ptr, "extrude_point"); const bool insert_point = RNA_boolean_get(op->ptr, "insert_point"); @@ -1804,7 +1807,7 @@ static int curve_pen_invoke(bContext *C, wmOperator *op, const wmEvent *event) } } else if (!cpd->acted) { - if (is_spline_nearby(&vc, op, event, SEL_DIST_FACTOR * ED_view3d_select_dist_px())) { + if (is_spline_nearby(&vc, op, event, threshold_dist_px)) { cpd->spline_nearby = true; /* If move segment is disabled, then insert point on key press and set diff --git a/source/blender/editors/curve/editcurve_query.c b/source/blender/editors/curve/editcurve_query.c index 684840775c3..a08dbbe6132 100644 --- a/source/blender/editors/curve/editcurve_query.c +++ b/source/blender/editors/curve/editcurve_query.c @@ -90,7 +90,7 @@ static void ED_curve_pick_vert__do_closest(void *userData, bool ED_curve_pick_vert_ex(ViewContext *vc, short sel, - float dist_px, + const int dist_px, Nurb **r_nurb, BezTriple **r_bezt, BPoint **r_bp, diff --git a/source/blender/editors/include/ED_curve.h b/source/blender/editors/include/ED_curve.h index 191291ad91b..9f4833bf1d7 100644 --- a/source/blender/editors/include/ED_curve.h +++ b/source/blender/editors/include/ED_curve.h @@ -48,18 +48,12 @@ void ED_curve_editnurb_make(struct Object *obedit); void ED_curve_editnurb_free(struct Object *obedit); /** - * \return True when pick finds an element or the selection changed. + * \param dist_px: Maximum distance to pick (in pixels). */ bool ED_curve_editnurb_select_pick(struct bContext *C, const int mval[2], + int dist_px, const struct SelectPick_Params *params); -/** - * \param sel_dist_mul: A multiplier on the default select distance. - */ -bool ED_curve_editnurb_select_pick_ex(struct bContext *C, - const int mval[2], - const float sel_dist_mul, - const struct SelectPick_Params *params); struct Nurb *ED_curve_add_nurbs_primitive( struct bContext *C, struct Object *obedit, float mat[4][4], int type, int newob); diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index 9b66e24ce7d..520d234e261 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -2974,7 +2974,7 @@ static int view3d_select_exec(bContext *C, wmOperator *op) changed = ED_lattice_select_pick(C, mval, ¶ms); } else if (ELEM(obedit->type, OB_CURVES_LEGACY, OB_SURF)) { - changed = ED_curve_editnurb_select_pick(C, mval, ¶ms); + changed = ED_curve_editnurb_select_pick(C, mval, ED_view3d_select_dist_px(), ¶ms); } else if (obedit->type == OB_MBALL) { changed = ED_mball_select_pick(C, mval, ¶ms); -- cgit v1.2.3