diff options
author | Campbell Barton <campbell@blender.org> | 2022-03-15 13:03:04 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-03-16 06:48:25 +0300 |
commit | 5e5285baf621a0c225cb5fc06fcec6ffed8302d7 (patch) | |
tree | fcdc655a6b063d32a7630b648e126c20ade295f2 /source/blender/editors/lattice/editlattice_select.c | |
parent | 9a763d24f2b50ad38d22cad0a23d7344afe5f1c7 (diff) |
View 3D: move picking arguments into a struct & minor refactor
- Add SelectPick_Params struct to make picking logic more
straightforward and easier to extend.
- Use `eSelectOp` instead of booleans (extend, deselect, toggle)
which were used to represent 4 states (which wasn't obvious).
- Handle deselect_all when pocking instead of view3d_select_exec,
de-duplicate de-selection which was already needed in when replacing
the selection in picking functions.
- Handle outliner update & notifiers in the picking functions
instead of view3d_select_exec.
- Fix particle select deselect_all option which did nothing.
Diffstat (limited to 'source/blender/editors/lattice/editlattice_select.c')
-rw-r--r-- | source/blender/editors/lattice/editlattice_select.c | 74 |
1 files changed, 44 insertions, 30 deletions
diff --git a/source/blender/editors/lattice/editlattice_select.c b/source/blender/editors/lattice/editlattice_select.c index d1635078126..883476aed7d 100644 --- a/source/blender/editors/lattice/editlattice_select.c +++ b/source/blender/editors/lattice/editlattice_select.c @@ -616,49 +616,63 @@ static BPoint *findnearestLattvert(ViewContext *vc, int sel, Base **r_base) return data.bp; } -bool ED_lattice_select_pick( - bContext *C, const int mval[2], bool extend, bool deselect, bool toggle) +bool ED_lattice_select_pick(bContext *C, const int mval[2], const struct SelectPick_Params *params) { Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); ViewContext vc; BPoint *bp = NULL; Base *basact = NULL; + bool changed = false; ED_view3d_viewcontext_init(C, &vc, depsgraph); vc.mval[0] = mval[0]; vc.mval[1] = mval[1]; bp = findnearestLattvert(&vc, true, &basact); - if (bp) { - ED_view3d_viewcontext_init_object(&vc, basact->object); - Lattice *lt = ((Lattice *)vc.obedit->data)->editlatt->latt; + const bool found = (bp != NULL); - if (!extend && !deselect && !toggle) { - uint objects_len = 0; - Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data( - vc.view_layer, vc.v3d, &objects_len); - for (uint ob_index = 0; ob_index < objects_len; ob_index++) { - Object *ob = objects[ob_index]; - if (ED_lattice_flags_set(ob, 0)) { - DEG_id_tag_update(ob->data, ID_RECALC_SELECT); - WM_event_add_notifier(C, NC_GEOM | ND_SELECT, ob->data); - } + if ((params->sel_op == SEL_OP_SET) && (found || params->deselect_all)) { + /* Deselect everything. */ + uint objects_len = 0; + Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data( + vc.view_layer, vc.v3d, &objects_len); + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *ob = objects[ob_index]; + if (ED_lattice_flags_set(ob, 0)) { + DEG_id_tag_update(ob->data, ID_RECALC_SELECT); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, ob->data); } - MEM_freeN(objects); } + MEM_freeN(objects); + changed = true; + } - if (extend) { - bp->f1 |= SELECT; - } - else if (deselect) { - bp->f1 &= ~SELECT; - } - else if (toggle) { - bp->f1 ^= SELECT; /* swap */ - } - else { - ED_lattice_flags_set(vc.obedit, 0); - bp->f1 |= SELECT; + if (found) { + ED_view3d_viewcontext_init_object(&vc, basact->object); + Lattice *lt = ((Lattice *)vc.obedit->data)->editlatt->latt; + + switch (params->sel_op) { + case SEL_OP_ADD: { + bp->f1 |= SELECT; + break; + } + case SEL_OP_SUB: { + bp->f1 &= ~SELECT; + break; + } + case SEL_OP_XOR: { + bp->f1 ^= SELECT; /* swap */ + break; + } + case SEL_OP_SET: { + ED_lattice_flags_set(vc.obedit, 0); + bp->f1 |= SELECT; + break; + } + case SEL_OP_AND: { + BLI_assert_unreachable(); /* Doesn't make sense for picking. */ + break; + } } if (bp->f1 & SELECT) { @@ -675,10 +689,10 @@ bool ED_lattice_select_pick( DEG_id_tag_update(vc.obedit->data, ID_RECALC_SELECT); WM_event_add_notifier(C, NC_GEOM | ND_SELECT, vc.obedit->data); - return true; + changed = true; } - return false; + return changed || found; } /** \} */ |