From 9fe704800ef1288ef7258e9dda6a538dc92ddddd Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Fri, 14 Jan 2022 14:38:49 -0600 Subject: Nodes: Support link-drag search with compare node outputs The search list only displayed the "Result" output socket in this case, which is unexpected since dragging from an input gives the operations in the list as well. Also use integer mode when connecting to boolean sockets. --- .../nodes/function/nodes/node_fn_compare.cc | 61 +++++++++++----------- 1 file changed, 31 insertions(+), 30 deletions(-) (limited to 'source/blender/nodes') diff --git a/source/blender/nodes/function/nodes/node_fn_compare.cc b/source/blender/nodes/function/nodes/node_fn_compare.cc index 7c09bace756..13a7ff86624 100644 --- a/source/blender/nodes/function/nodes/node_fn_compare.cc +++ b/source/blender/nodes/function/nodes/node_fn_compare.cc @@ -122,41 +122,42 @@ class SocketSearchOp { static void node_compare_gather_link_searches(GatherLinkSearchOpParams ¶ms) { - const NodeDeclaration &declaration = *params.node_type().fixed_declaration; - if (params.in_out() == SOCK_OUT) { - search_link_ops_for_declarations(params, declaration.outputs()); + const eNodeSocketDatatype type = static_cast(params.other_socket().type); + if (!ELEM(type, SOCK_BOOLEAN, SOCK_FLOAT, SOCK_RGBA, SOCK_VECTOR, SOCK_INT, SOCK_STRING)) { return; } - const eNodeSocketDatatype type = static_cast(params.other_socket().type); - - if (ELEM(type, SOCK_BOOLEAN, SOCK_FLOAT, SOCK_RGBA, SOCK_VECTOR, SOCK_INT, SOCK_STRING)) { - const eNodeSocketDatatype mode_type = (type == SOCK_BOOLEAN) ? SOCK_FLOAT : type; - const bool string_type = (type == SOCK_STRING); - /* Add socket A compare operations. */ - for (const EnumPropertyItem *item = rna_enum_node_compare_operation_items; - item->identifier != nullptr; - item++) { - if (item->name != nullptr && item->identifier[0] != '\0') { - if (!string_type && - ELEM(item->value, NODE_COMPARE_COLOR_BRIGHTER, NODE_COMPARE_COLOR_DARKER)) { - params.add_item(IFACE_(item->name), - SocketSearchOp{"A", SOCK_RGBA, (NodeCompareOperation)item->value}); - } - else if ((!string_type) || - (string_type && ELEM(item->value, NODE_COMPARE_EQUAL, NODE_COMPARE_NOT_EQUAL))) { - params.add_item(IFACE_(item->name), - SocketSearchOp{"A", mode_type, (NodeCompareOperation)item->value}); - } + const eNodeSocketDatatype mode_type = (type == SOCK_BOOLEAN) ? SOCK_INT : type; + const bool string_type = (type == SOCK_STRING); + + const std::string socket_name = params.in_out() == SOCK_IN ? "A" : "Result"; + + for (const EnumPropertyItem *item = rna_enum_node_compare_operation_items; + item->identifier != nullptr; + item++) { + if (item->name != nullptr && item->identifier[0] != '\0') { + if (!string_type && + ELEM(item->value, NODE_COMPARE_COLOR_BRIGHTER, NODE_COMPARE_COLOR_DARKER)) { + params.add_item(IFACE_(item->name), + SocketSearchOp{socket_name, + SOCK_RGBA, + static_cast(item->value)}); + } + else if ((!string_type) || + (string_type && ELEM(item->value, NODE_COMPARE_EQUAL, NODE_COMPARE_NOT_EQUAL))) { + params.add_item(IFACE_(item->name), + SocketSearchOp{socket_name, + mode_type, + static_cast(item->value)}); } } - /* Add Angle socket. */ - if (!string_type) { - params.add_item( - IFACE_("Angle"), - SocketSearchOp{ - "Angle", SOCK_VECTOR, NODE_COMPARE_GREATER_THAN, NODE_COMPARE_MODE_DIRECTION}); - } + } + /* Add Angle socket. */ + if (!string_type && params.in_out() == SOCK_IN) { + params.add_item( + IFACE_("Angle"), + SocketSearchOp{ + "Angle", SOCK_VECTOR, NODE_COMPARE_GREATER_THAN, NODE_COMPARE_MODE_DIRECTION}); } } -- cgit v1.2.3