[Bf-blender-cvs] [dc5b1d6c757] master: Cleanup: pass selection threshold to curve picking

Campbell Barton noreply at git.blender.org
Mon Apr 4 05:36:55 CEST 2022


Commit: dc5b1d6c75717a41c00042b667bc4a1a1609e588
Author: Campbell Barton
Date:   Mon Apr 4 13:11:44 2022 +1000
Branches: master
https://developer.blender.org/rBdc5b1d6c75717a41c00042b667bc4a1a1609e588

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.

===================================================================

M	source/blender/editors/curve/curve_intern.h
M	source/blender/editors/curve/editcurve.c
M	source/blender/editors/curve/editcurve_pen.c
M	source/blender/editors/curve/editcurve_query.c
M	source/blender/editors/include/ED_curve.h
M	source/blender/editors/space_view3d/view3d_select.c

===================================================================

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, &params)) {
+        if (ED_curve_editnurb_select_pick(C, event->mval, threshold_dist_px, &params)) {
           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, &params);
+          ED_curve_editnurb_select_pick(C, event->mval, threshold_dist_px, &params);
         }
       }
 
@@ -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, &params);
     }
     else if (ELEM(obedit->type, OB_CURVES_LEGACY, OB_SURF)) {
-      changed = ED_curve_editnurb_select_pick(C, mval, &params);
+      changed = ED_curve_editnurb_select_pick(C, mval, ED_view3d_select_dist_px(), &params);
     }
     else if (obedit->type == OB_MBALL) {
       changed = ED_mball_select_pick(C, mval, &params);



More information about the Bf-blender-cvs mailing list