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.
This commit is contained in:
Campbell Barton 2022-04-04 13:11:44 +10:00
parent ff82bb5e3a
commit dc5b1d6c75
6 changed files with 14 additions and 25 deletions

View File

@ -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,

View File

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

View File

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

View File

@ -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,

View File

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

View File

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