[Bf-blender-cvs] [2579367c932] soc-2021-curves: Select distance refactor

Dilith Jayakody noreply at git.blender.org
Sun Apr 3 17:34:25 CEST 2022


Commit: 2579367c93296eb2ab1da0b51dc107287dc09fd3
Author: Dilith Jayakody
Date:   Sun Apr 3 07:39:14 2022 +0530
Branches: soc-2021-curves
https://developer.blender.org/rB2579367c93296eb2ab1da0b51dc107287dc09fd3

Select distance refactor

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

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

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

diff --git a/source/blender/editors/curve/curve_intern.h b/source/blender/editors/curve/curve_intern.h
index 439cc425d04..09a0dbc541f 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 sel_dist_mul,
+                           float 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 f0661c7117b..c7c2468a6e4 100644
--- a/source/blender/editors/curve/editcurve.c
+++ b/source/blender/editors/curve/editcurve.c
@@ -4748,7 +4748,8 @@ 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, &nu, &bezt, &bp, &hand, &basact);
+  bool found = ED_curve_pick_vert_ex(
+      &vc, 1, sel_dist_mul * ED_view3d_select_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 1abe6ad1f94..a848fdb56ca 100644
--- a/source/blender/editors/curve/editcurve_pen.c
+++ b/source/blender/editors/curve/editcurve_pen.c
@@ -49,7 +49,8 @@
   } \
   ((void)0)
 
-#define SEL_DIST 0.2f
+/* Used to scale the default select distance. */
+#define SEL_DIST_FACTOR 0.2f
 
 /**
  * Data structure to keep track of details about the cut location
@@ -532,7 +533,7 @@ static bool get_closest_vertex_to_point_in_nurbs(const ViewContext *vc,
   }
 
   /* Assign closest data to the returned variables. */
-  const float threshold_dist = ED_view3d_select_dist_px() * SEL_DIST;
+  const float threshold_dist = ED_view3d_select_dist_px() * SEL_DIST_FACTOR;
   if (min_dist_bezt < threshold_dist || min_dist_bp < threshold_dist) {
     if (min_dist_bp < min_dist_bezt) {
       *r_bp = closest_bp;
@@ -844,7 +845,7 @@ static bool insert_point_to_segment(const ViewContext *vc, const wmEvent *event)
   CutData cd = init_cut_data(event);
   float mval[2] = {UNPACK2(event->mval)};
   const bool near_spline = update_cut_data_for_all_nurbs(
-      vc, BKE_curve_editNurbs_get(cu), mval, SEL_DIST * ED_view3d_select_dist_px(), &cd);
+      vc, BKE_curve_editNurbs_get(cu), mval, SEL_DIST_FACTOR * ED_view3d_select_dist_px(), &cd);
 
   if (near_spline && !cd.nurb->hide) {
     Nurb *nu = cd.nurb;
@@ -1649,7 +1650,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, &params)) {
+        if (ED_curve_editnurb_select_pick_ex(C, event->mval, SEL_DIST_FACTOR, &params)) {
           cpd->acted = delete_point_under_mouse(&vc, event);
         }
       }
@@ -1708,7 +1709,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, &params);
+          ED_curve_editnurb_select_pick_ex(C, event->mval, SEL_DIST_FACTOR, &params);
         }
       }
 
@@ -1798,7 +1799,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 * ED_view3d_select_dist_px())) {
+      if (is_spline_nearby(&vc, op, event, SEL_DIST_FACTOR * ED_view3d_select_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 d52a1af5268..684840775c3 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,
-                           const float sel_dist_mul,
+                           float dist_px,
                            Nurb **r_nurb,
                            BezTriple **r_bezt,
                            BPoint **r_bp,
@@ -110,7 +110,7 @@ bool ED_curve_pick_vert_ex(ViewContext *vc,
     bool is_changed;
   } data = {NULL};
 
-  data.dist = ED_view3d_select_dist_px() * sel_dist_mul;
+  data.dist = dist_px;
   data.hpoint = 0;
   data.select = sel;
   data.mval_fl[0] = vc->mval[0];
@@ -152,7 +152,8 @@ bool ED_curve_pick_vert(ViewContext *vc,
                         short *r_handle,
                         Base **r_base)
 {
-  return ED_curve_pick_vert_ex(vc, sel, 1.0f, r_nurb, r_bezt, r_bp, r_handle, r_base);
+  return ED_curve_pick_vert_ex(
+      vc, sel, ED_view3d_select_dist_px(), r_nurb, r_bezt, r_bp, r_handle, r_base);
 }
 
 /** \} */



More information about the Bf-blender-cvs mailing list