[Bf-blender-cvs] [a18bd403bf3] master: Nodes: Improve link-drag search support for boolean math node

Hans Goudey noreply at git.blender.org
Tue Jan 25 16:51:29 CET 2022


Commit: a18bd403bf3edb495ee0531600bbf3cf23d45e1c
Author: Hans Goudey
Date:   Tue Jan 25 09:51:20 2022 -0600
Branches: master
https://developer.blender.org/rBa18bd403bf3edb495ee0531600bbf3cf23d45e1c

Nodes: Improve link-drag search support for boolean math node

List the operations in the search instead of the "Boolean" socket names.

===================================================================

M	source/blender/makesdna/DNA_node_types.h
M	source/blender/nodes/function/nodes/node_fn_boolean_math.cc

===================================================================

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 &params)
+{
+  const eNodeSocketDatatype type = static_cast<eNodeSocketDatatype>(params.other_socket().type);
+  if (!params.node_tree().typeinfo->validate_link(
+          static_cast<eNodeSocketDatatype>(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<NodeBooleanMathOperation>(item->value);
+      params.add_item(IFACE_(item->name), [operation](LinkSearchOpParams &params) {
+        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<bool, bool, bool> 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);
 }



More information about the Bf-blender-cvs mailing list