From a18bd403bf3edb495ee0531600bbf3cf23d45e1c Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Tue, 25 Jan 2022 09:51:20 -0600 Subject: Nodes: Improve link-drag search support for boolean math node List the operations in the search instead of the "Boolean" socket names. --- source/blender/makesdna/DNA_node_types.h | 4 ++-- .../nodes/function/nodes/node_fn_boolean_math.cc | 25 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h index 34252715545..b154576df76 100644 --- a/source/blender/makesdna/DNA_node_types.h +++ b/source/blender/makesdna/DNA_node_types.h @@ -1927,7 +1927,7 @@ typedef enum NodeVectorMathOperation { } NodeVectorMathOperation; /** Boolean math node operations. */ -enum { +typedef enum NodeBooleanMathOperation { NODE_BOOLEAN_MATH_AND = 0, NODE_BOOLEAN_MATH_OR = 1, NODE_BOOLEAN_MATH_NOT = 2, @@ -1939,7 +1939,7 @@ enum { NODE_BOOLEAN_MATH_IMPLY = 7, NODE_BOOLEAN_MATH_NIMPLY = 8, -}; +} NodeBooleanMathOperation; /** Float compare node operations. */ typedef enum NodeCompareMode { diff --git a/source/blender/nodes/function/nodes/node_fn_boolean_math.cc b/source/blender/nodes/function/nodes/node_fn_boolean_math.cc index 15b0bab22b7..8c75a1c538d 100644 --- a/source/blender/nodes/function/nodes/node_fn_boolean_math.cc +++ b/source/blender/nodes/function/nodes/node_fn_boolean_math.cc @@ -22,6 +22,8 @@ #include "UI_interface.h" #include "UI_resources.h" +#include "NOD_socket_search_link.hh" + #include "node_function_util.hh" namespace blender::nodes::node_fn_boolean_math_cc { @@ -59,6 +61,28 @@ static void node_boolean_math_label(const bNodeTree *UNUSED(ntree), BLI_strncpy(label, IFACE_(name), maxlen); } +static void node_gather_link_searches(GatherLinkSearchOpParams ¶ms) +{ + const eNodeSocketDatatype type = static_cast(params.other_socket().type); + if (!params.node_tree().typeinfo->validate_link( + static_cast(params.other_socket().type), SOCK_BOOLEAN)) { + return; + } + + for (const EnumPropertyItem *item = rna_enum_node_boolean_math_items; + item->identifier != nullptr; + item++) { + if (item->name != nullptr && item->identifier[0] != '\0') { + NodeBooleanMathOperation operation = static_cast(item->value); + params.add_item(IFACE_(item->name), [operation](LinkSearchOpParams ¶ms) { + bNode &node = params.add_node("FunctionNodeBooleanMath"); + node.custom1 = operation; + params.update_and_connect_available_socket(node, "Boolean"); + }); + } + } +} + static const fn::MultiFunction *get_multi_function(bNode &bnode) { static fn::CustomMF_SI_SI_SO and_fn{"And", @@ -124,5 +148,6 @@ void register_node_type_fn_boolean_math() node_type_update(&ntype, file_ns::node_boolean_math_update); ntype.build_multi_function = file_ns::fn_node_boolean_math_build_multi_function; ntype.draw_buttons = file_ns::fn_node_boolean_math_layout; + ntype.gather_link_search_ops = file_ns::node_gather_link_searches; nodeRegisterType(&ntype); } -- cgit v1.2.3