Compositor: Improve link drag search

Add link drag search for Math operations
Add link drag search for Mix operations

Pull Request: https://projects.blender.org/blender/blender/pulls/110575
This commit is contained in:
Charlie Jolly
2023-08-01 20:03:32 +02:00
committed by Charlie Jolly
parent 40de15d521
commit 5b80d9bbaf
2 changed files with 61 additions and 0 deletions

View File

@@ -11,6 +11,9 @@
#include "COM_shader_node.hh"
#include "NOD_math_functions.hh"
#include "NOD_socket_search_link.hh"
#include "RNA_enum_types.h"
#include "node_composite_util.hh"
@@ -38,6 +41,32 @@ static void cmp_node_math_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Float>("Value");
}
class SocketSearchOp {
public:
std::string socket_name;
NodeMathOperation mode = NODE_MATH_ADD;
void operator()(LinkSearchOpParams &params)
{
bNode &node = params.add_node("CompositorNodeMath");
node.custom1 = mode;
params.update_and_connect_available_socket(node, socket_name);
}
};
static void node_gather_link_searches(GatherLinkSearchOpParams &params)
{
const int weight = ELEM(params.other_socket().type, SOCK_FLOAT) ? 0 : -1;
for (const EnumPropertyItem *item = rna_enum_node_math_items; item->identifier != nullptr;
item++) {
if (item->name != nullptr && item->identifier[0] != '\0') {
params.add_item(CTX_IFACE_(BLT_I18NCONTEXT_ID_NODETREE, item->name),
SocketSearchOp{"Value", (NodeMathOperation)item->value},
weight);
}
}
}
using namespace blender::realtime_compositor;
class MathShaderNode : public ShaderNode {
@@ -99,6 +128,7 @@ void register_node_type_cmp_math()
ntype.labelfunc = node_math_label;
ntype.updatefunc = node_math_update;
ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
ntype.gather_link_search_ops = file_ns::node_gather_link_searches;
nodeRegisterType(&ntype);
}

View File

@@ -14,6 +14,10 @@
#include "COM_shader_node.hh"
#include "NOD_socket_search_link.hh"
#include "RNA_enum_types.h"
#include "node_composite_util.hh"
/* **************** MIX RGB ******************** */
@@ -37,6 +41,32 @@ static void cmp_node_mixrgb_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Color>("Image");
}
class SocketSearchOp {
public:
std::string socket_name;
int mode = MA_RAMP_BLEND;
void operator()(LinkSearchOpParams &params)
{
bNode &node = params.add_node("CompositorNodeMixRGB");
node.custom1 = mode;
params.update_and_connect_available_socket(node, socket_name);
}
};
static void node_gather_link_searches(GatherLinkSearchOpParams &params)
{
const int weight = ELEM(params.other_socket().type, SOCK_RGBA) ? 0 : -1;
for (const EnumPropertyItem *item = rna_enum_ramp_blend_items; item->identifier != nullptr;
item++) {
if (item->name != nullptr && item->identifier[0] != '\0') {
params.add_item(CTX_IFACE_(BLT_I18NCONTEXT_ID_NODETREE, item->name),
SocketSearchOp{"Image", item->value},
weight);
}
}
}
using namespace blender::realtime_compositor;
class MixRGBShaderNode : public ShaderNode {
@@ -153,6 +183,7 @@ void register_node_type_cmp_mix_rgb()
ntype.declare = file_ns::cmp_node_mixrgb_declare;
ntype.labelfunc = node_blend_label;
ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
ntype.gather_link_search_ops = file_ns::node_gather_link_searches;
nodeRegisterType(&ntype);
}