From 5e5285baf621a0c225cb5fc06fcec6ffed8302d7 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 15 Mar 2022 21:03:04 +1100 Subject: 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. --- source/blender/editors/include/ED_armature.h | 28 ++++++++++++++---------- source/blender/editors/include/ED_curve.h | 18 ++++++++++----- source/blender/editors/include/ED_lattice.h | 9 ++++++-- source/blender/editors/include/ED_mball.h | 10 ++++++--- source/blender/editors/include/ED_mesh.h | 15 ++++++++----- source/blender/editors/include/ED_particle.h | 6 +++-- source/blender/editors/include/ED_select_utils.h | 19 ++++++++++++++++ 7 files changed, 75 insertions(+), 30 deletions(-) (limited to 'source/blender/editors/include') diff --git a/source/blender/editors/include/ED_armature.h b/source/blender/editors/include/ED_armature.h index 2f5f82e332c..84efc875be7 100644 --- a/source/blender/editors/include/ED_armature.h +++ b/source/blender/editors/include/ED_armature.h @@ -27,6 +27,7 @@ struct MeshDeformModifierData; struct Object; struct ReportList; struct Scene; +struct SelectPick_Params; struct UndoType; struct View3D; struct ViewLayer; @@ -164,18 +165,20 @@ bool ED_armature_edit_deselect_all_visible(struct Object *obedit); bool ED_armature_edit_deselect_all_multi_ex(struct Base **bases, uint bases_len); bool ED_armature_edit_deselect_all_visible_multi_ex(struct Base **bases, uint bases_len); bool ED_armature_edit_deselect_all_visible_multi(struct bContext *C); +/** + * \return True when pick finds an element or the selection changed. + */ bool ED_armature_edit_select_pick_bone(struct bContext *C, struct Base *basact, struct EditBone *ebone, int selmask, - bool extend, - bool deselect, - bool toggle); + const struct SelectPick_Params *params); /** * Bone selection picking for armature edit-mode in the view3d. */ -bool ED_armature_edit_select_pick( - struct bContext *C, const int mval[2], bool extend, bool deselect, bool toggle); +bool ED_armature_edit_select_pick(struct bContext *C, + const int mval[2], + const struct SelectPick_Params *params); /** * Perform a selection operation on elements which have been 'touched', * use for lasso & border select but can be used elsewhere too. @@ -305,25 +308,26 @@ void ED_pose_recalculate_paths(struct bContext *C, /* pose_select.c */ -void ED_armature_pose_select_pick_bone(struct ViewLayer *view_layer, +/** + * \return True when pick finds an element or the selection changed. + */ +bool ED_armature_pose_select_pick_bone(struct ViewLayer *view_layer, struct View3D *v3d, struct Object *ob, struct Bone *bone, - bool extend, - bool deselect, - bool toggle); + const struct SelectPick_Params *params); /** * Called for mode-less pose selection. * assumes the active object is still on old situation. + * + * \return True when pick finds an element or the selection changed. */ bool ED_armature_pose_select_pick_with_buffer(struct ViewLayer *view_layer, struct View3D *v3d, struct Base *base, const struct GPUSelectResult *buffer, short hits, - bool extend, - bool deselect, - bool toggle, + const struct SelectPick_Params *params, bool do_nearest); /** * While in weight-paint mode, a single pose may be active as well. diff --git a/source/blender/editors/include/ED_curve.h b/source/blender/editors/include/ED_curve.h index c97f97a2ddc..6097e7c69d9 100644 --- a/source/blender/editors/include/ED_curve.h +++ b/source/blender/editors/include/ED_curve.h @@ -19,6 +19,7 @@ struct EditNurb; struct Main; struct Nurb; struct Object; +struct SelectPick_Params; struct Text; struct UndoType; struct View3D; @@ -46,8 +47,12 @@ void ED_curve_editnurb_load(struct Main *bmain, struct Object *obedit); void ED_curve_editnurb_make(struct Object *obedit); void ED_curve_editnurb_free(struct Object *obedit); -bool ED_curve_editnurb_select_pick( - struct bContext *C, const int mval[2], bool extend, bool deselect, bool toggle); +/** + * \return True when pick finds an element or the selection changed. + */ +bool ED_curve_editnurb_select_pick(struct bContext *C, + const int mval[2], + 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); @@ -100,10 +105,13 @@ int ED_curve_updateAnimPaths(struct Main *bmain, struct Curve *cu); bool ED_curve_active_center(struct Curve *cu, float center[3]); /** - * TextBox selection + * Text box selection. + * + * \return True when pick finds an element or the selection changed. */ -bool ED_curve_editfont_select_pick( - struct bContext *C, const int mval[2], bool extend, bool deselect, bool toggle); +bool ED_curve_editfont_select_pick(struct bContext *C, + const int mval[2], + const struct SelectPick_Params *params); /* editfont_undo.c */ diff --git a/source/blender/editors/include/ED_lattice.h b/source/blender/editors/include/ED_lattice.h index eddf69e1cb6..1b9311cbacf 100644 --- a/source/blender/editors/include/ED_lattice.h +++ b/source/blender/editors/include/ED_lattice.h @@ -13,6 +13,7 @@ extern "C" { struct Base; struct Object; +struct SelectPick_Params; struct UndoType; struct wmKeyConfig; @@ -24,8 +25,12 @@ void ED_keymap_lattice(struct wmKeyConfig *keyconf); /* editlattice_select.c */ bool ED_lattice_flags_set(struct Object *obedit, int flag); -bool ED_lattice_select_pick( - struct bContext *C, const int mval[2], bool extend, bool deselect, bool toggle); +/** + * \return True when pick finds an element or the selection changed. + */ +bool ED_lattice_select_pick(struct bContext *C, + const int mval[2], + const struct SelectPick_Params *params); bool ED_lattice_deselect_all_multi_ex(struct Base **bases, uint bases_len); bool ED_lattice_deselect_all_multi(struct bContext *C); diff --git a/source/blender/editors/include/ED_mball.h b/source/blender/editors/include/ED_mball.h index e0c921ea0db..74071765716 100644 --- a/source/blender/editors/include/ED_mball.h +++ b/source/blender/editors/include/ED_mball.h @@ -13,6 +13,7 @@ extern "C" { struct Base; struct Object; +struct SelectPick_Params; struct UndoType; struct bContext; struct wmKeyConfig; @@ -32,10 +33,13 @@ struct MetaElem *ED_mball_add_primitive(struct bContext *C, int type); /** - * Select MetaElement with mouse click (user can select radius circle or stiffness circle). + * Select meta-element with mouse click (user can select radius circle or stiffness circle). + * + * \return True when pick finds an element or the selection changed. */ -bool ED_mball_select_pick( - struct bContext *C, const int mval[2], bool extend, bool deselect, bool toggle); +bool ED_mball_select_pick(struct bContext *C, + const int mval[2], + const struct SelectPick_Params *params); bool ED_mball_deselect_all_multi_ex(struct Base **bases, uint bases_len); bool ED_mball_deselect_all_multi(struct bContext *C); diff --git a/source/blender/editors/include/ED_mesh.h b/source/blender/editors/include/ED_mesh.h index 68e46dfa0e5..03ca4cd062b 100644 --- a/source/blender/editors/include/ED_mesh.h +++ b/source/blender/editors/include/ED_mesh.h @@ -31,6 +31,7 @@ struct Mesh; struct Object; struct ReportList; struct Scene; +struct SelectPick_Params; struct UndoType; struct UvMapVert; struct UvVertMap; @@ -268,8 +269,9 @@ bool EDBM_unified_findnearest_from_raycast(struct ViewContext *vc, struct BMEdge **r_eed, struct BMFace **r_efa); -bool EDBM_select_pick( - struct bContext *C, const int mval[2], bool extend, bool deselect, bool toggle); +bool EDBM_select_pick(struct bContext *C, + const int mval[2], + const struct SelectPick_Params *params); /** * When switching select mode, makes sure selection is consistent for editing @@ -387,12 +389,13 @@ void ED_keymap_mesh(struct wmKeyConfig *keyconf); * use in object mode when selecting faces (while painting). */ void paintface_flush_flags(struct bContext *C, struct Object *ob, short flag); +/** + * \return True when pick finds an element or the selection changed. + */ bool paintface_mouse_select(struct bContext *C, - struct Object *ob, const int mval[2], - bool extend, - bool deselect, - bool toggle); + const struct SelectPick_Params *params, + struct Object *ob); bool paintface_deselect_all_visible(struct bContext *C, struct Object *ob, int action, diff --git a/source/blender/editors/include/ED_particle.h b/source/blender/editors/include/ED_particle.h index a4797ff167c..553aa444891 100644 --- a/source/blender/editors/include/ED_particle.h +++ b/source/blender/editors/include/ED_particle.h @@ -16,6 +16,7 @@ struct PTCacheEdit; struct ParticleEditSettings; struct ParticleSystem; struct Scene; +struct SelectPick_Params; struct UndoType; struct ViewLayer; struct bContext; @@ -54,8 +55,9 @@ void PE_update_object(struct Depsgraph *depsgraph, /* selection tools */ -bool PE_mouse_particles( - struct bContext *C, const int mval[2], bool extend, bool deselect, bool toggle); +bool PE_mouse_particles(struct bContext *C, + const int mval[2], + const struct SelectPick_Params *params); bool PE_box_select(struct bContext *C, const struct rcti *rect, int sel_op); bool PE_circle_select(struct bContext *C, struct wmGenericUserData *wm_userdata, diff --git a/source/blender/editors/include/ED_select_utils.h b/source/blender/editors/include/ED_select_utils.h index 26d8d0a3d8c..c24c9168fe8 100644 --- a/source/blender/editors/include/ED_select_utils.h +++ b/source/blender/editors/include/ED_select_utils.h @@ -70,6 +70,25 @@ bool ED_select_similar_compare_float_tree(const struct KDTree_1d *tree, */ eSelectOp ED_select_op_modal(eSelectOp sel_op, bool is_first); +/** Argument passed to picking functions. */ +struct SelectPick_Params { + /** + * - #SEL_OP_ADD named "extend" from operators. + * - #SEL_OP_SUB named "deselect" from operators. + * - #SEL_OP_XOR named "toggle" from operators. + * - #SEL_OP_AND (never used for picking). + * - #SEL_OP_SET use when "extend", "deselect" and "toggle" are all disabled. + */ + eSelectOp sel_op; + /** Deselect all, even when there is nothing found at the cursor location. */ + bool deselect_all; +}; + +/** + * Utility to get #eSelectPickMode from booleans for convenience. + */ +eSelectOp ED_select_op_from_booleans(bool extend, bool deselect, bool toggle); + #ifdef __cplusplus } #endif -- cgit v1.2.3