From e88e80a6a0c8976ac2d245c274ca5a0388736743 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 14 Aug 2018 10:28:41 +1000 Subject: 3D View boarder/lasso select tool options Add tool options to control how select operates (add/sub/set/and/xor). Note: edit mode armature select still needs to support all options, this is complicated by how it handles partial end-point selection. --- source/blender/editors/util/CMakeLists.txt | 4 +- source/blender/editors/util/select_utils.c | 70 ++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 source/blender/editors/util/select_utils.c (limited to 'source/blender/editors/util') diff --git a/source/blender/editors/util/CMakeLists.txt b/source/blender/editors/util/CMakeLists.txt index 97ea0da6007..3fd8656ad2c 100644 --- a/source/blender/editors/util/CMakeLists.txt +++ b/source/blender/editors/util/CMakeLists.txt @@ -43,6 +43,7 @@ set(SRC ed_transverts.c ed_util.c numinput.c + select_utils.c # general includes ../include/BIF_gl.h @@ -54,6 +55,7 @@ set(SRC ../include/ED_curve.h ../include/ED_datafiles.h ../include/ED_fileselect.h + ../include/ED_gizmo_library.h ../include/ED_gpencil.h ../include/ED_image.h ../include/ED_info.h @@ -63,7 +65,6 @@ set(SRC ../include/ED_lattice.h ../include/ED_logic.h ../include/ED_markers.h - ../include/ED_gizmo_library.h ../include/ED_mask.h ../include/ED_mball.h ../include/ED_mesh.h @@ -79,6 +80,7 @@ set(SRC ../include/ED_screen.h ../include/ED_screen_types.h ../include/ED_sculpt.h + ../include/ED_select_utils.h ../include/ED_sequencer.h ../include/ED_sound.h ../include/ED_space_api.h diff --git a/source/blender/editors/util/select_utils.c b/source/blender/editors/util/select_utils.c new file mode 100644 index 00000000000..39a49be3f67 --- /dev/null +++ b/source/blender/editors/util/select_utils.c @@ -0,0 +1,70 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file select_utils.c + * \ingroup editors + */ + +#include "BLI_utildefines.h" + +#include "ED_select_utils.h" + +/** 1: select, 0: deselect, -1: pass. */ +int ED_select_op_action(const eSelectOp sel_op, const bool is_select, const bool is_inside) +{ + switch (sel_op) { + case SEL_OP_ADD: + return (!is_select && (is_inside)) ? 1 : -1; + case SEL_OP_SUB: + return (is_select && is_inside) ? 0 : -1; + case SEL_OP_SET: + return is_inside ? 1 : 0; + case SEL_OP_AND: + return (is_select && is_inside) ? -1 : (is_select ? 0 : -1); + case SEL_OP_XOR: + return (is_select && is_inside) ? 0 : ((!is_select && is_inside) ? 1 : -1); + } + BLI_assert(!"invalid sel_op"); + return -1; +} +/** + * Use when we've de-selected all items first (for modes that need it). + * + * \note In some cases changing selection needs to perform other checks, + * so it's more straightforward to deselect all, then select. + */ +int ED_select_op_action_deselected(const eSelectOp sel_op, const bool is_select, const bool is_inside) +{ + switch (sel_op) { + case SEL_OP_ADD: + return (!is_select && is_inside) ? 1 : -1; + case SEL_OP_SUB: + return (is_select && is_inside) ? 0 : -1; + case SEL_OP_SET: + /* Only difference w/ function above. */ + return is_inside ? 1 : -1; + case SEL_OP_AND: + return (is_select && is_inside) ? -1 : (is_select ? 0 : -1); + case SEL_OP_XOR: + return (is_select && is_inside) ? 0 : ((!is_select && is_inside) ? 1 : -1); + } + BLI_assert(!"invalid sel_op"); + return -1; +} -- cgit v1.2.3