diff options
author | Jacques Lucke <jacques@blender.org> | 2020-02-25 16:46:24 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-02-25 16:46:24 +0300 |
commit | b72d4e1d98bab097e71f00058a2995c55865ffcb (patch) | |
tree | 5773dfe6040c47dba0816d3f233a49c71ba2054b | |
parent | bf9c6aad9e9514cb06ea2433bbba31920886e800 (diff) |
new operator socket
-rw-r--r-- | source/blender/simulations/nodes/my_test_node.cc | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/source/blender/simulations/nodes/my_test_node.cc b/source/blender/simulations/nodes/my_test_node.cc index 044a6712f28..9dfcc3b4d17 100644 --- a/source/blender/simulations/nodes/my_test_node.cc +++ b/source/blender/simulations/nodes/my_test_node.cc @@ -181,6 +181,47 @@ class FixedTypeSocketDecl : public SocketDecl { } }; +class OperatorSocketDecl : public SocketDecl { + eNodeSocketInOut m_in_out; + StringRefNull m_ui_name; + StringRefNull m_identifier; + + public: + OperatorSocketDecl(bNodeTree &ntree, + bNode &node, + eNodeSocketInOut in_out, + StringRefNull ui_name, + StringRefNull identifier) + : SocketDecl(ntree, node, 1), m_in_out(in_out), m_ui_name(ui_name), m_identifier(identifier) + { + } + + bool sockets_are_correct(ArrayRef<bNodeSocket *> sockets) const override + { + if (sockets.size() != 1) { + return false; + } + + bNodeSocket *socket = sockets[0]; + if (!STREQ(socket->idname, "OperatorSocket")) { + return false; + } + if (socket->name != m_ui_name) { + return false; + } + if (socket->identifier != m_identifier) { + return false; + } + return true; + } + + void build() const override + { + nodeAddSocket( + &m_ntree, &m_node, m_in_out, "OperatorSocket", m_identifier.data(), m_ui_name.data()); + } +}; + class NodeDecl { public: bNodeTree &m_ntree; @@ -284,6 +325,17 @@ class NodeBuilder { m_node_decl.m_outputs.append(decl); } + void operator_input(StringRef identifier, StringRef ui_name) + { + OperatorSocketDecl *decl = m_allocator.construct<OperatorSocketDecl>( + m_node_decl.m_ntree, + m_node_decl.m_node, + SOCK_IN, + m_allocator.copy_string(ui_name), + m_allocator.copy_string(identifier)); + m_node_decl.m_inputs.append(decl); + } + void float_input(StringRef identifier, StringRef ui_name) { this->fixed_input(identifier, ui_name, *data_socket_float); @@ -815,6 +867,7 @@ void register_node_type_my_test_node() LISTBASE_FOREACH (VariadicNodeSocketIdentifier *, value, &storage->inputs_info) { node_builder.float_input(value->identifier, "Value"); } + node_builder.operator_input("New Input", "New"); node_builder.float_output("result", "Result"); }); ntype.add_draw_fn([](uiLayout *layout, struct bContext *UNUSED(C), struct PointerRNA *ptr) { @@ -874,6 +927,11 @@ void init_socket_data_types() stype.register_type(); } { + static SocketDefinition stype("OperatorSocket"); + stype.set_color({0.0, 0.0, 0.0, 0.0}); + stype.register_type(); + } + { static SocketDefinition stype("MyFloatSocket"); stype.set_color({1, 1, 1, 1}); stype.add_dna_storage<bNodeSocketValueFloat>( |