[Bf-blender-cvs] [6b85f364e81] simulation-tree: test drawing settings in node and have them update the sockets
Jacques Lucke
noreply at git.blender.org
Mon Feb 17 18:16:45 CET 2020
Commit: 6b85f364e81b725ea515a8e3302a57380f973b93
Author: Jacques Lucke
Date: Mon Feb 17 18:13:54 2020 +0100
Branches: simulation-tree
https://developer.blender.org/rB6b85f364e81b725ea515a8e3302a57380f973b93
test drawing settings in node and have them update the sockets
===================================================================
M source/blender/editors/space_node/drawnode.c
M source/blender/makesdna/DNA_node_types.h
M source/blender/simulations/nodes/my_test_node.cc
===================================================================
diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c
index 3227a1bed5c..9a6aace57b0 100644
--- a/source/blender/editors/space_node/drawnode.c
+++ b/source/blender/editors/space_node/drawnode.c
@@ -3215,7 +3215,7 @@ void ED_node_init_butfuncs(void)
ntype->draw_nodetype_prepare = node_update_default;
ntype->select_area_func = node_select_area_default;
ntype->tweak_area_func = node_tweak_area_default;
- ntype->draw_buttons = NULL;
+ // ntype->draw_buttons = NULL; /* TODO */
ntype->draw_buttons_ex = NULL;
ntype->resize_area_func = node_resize_area_default;
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index 1b6cce02b3c..3eda5874c63 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -1043,6 +1043,10 @@ typedef struct NodeDenoise {
char _pad[7];
} NodeDenoise;
+typedef struct MyTestNodeStorage {
+ int x;
+} MyTestNodeStorage;
+
/* script node mode */
#define NODE_SCRIPT_INTERNAL 0
#define NODE_SCRIPT_EXTERNAL 1
diff --git a/source/blender/simulations/nodes/my_test_node.cc b/source/blender/simulations/nodes/my_test_node.cc
index 9316fdc7fdd..5339e5dff57 100644
--- a/source/blender/simulations/nodes/my_test_node.cc
+++ b/source/blender/simulations/nodes/my_test_node.cc
@@ -1,4 +1,5 @@
#include <cstring>
+#include <typeinfo>
#include "BKE_node.h"
#include "SIM_node_tree.h"
@@ -10,8 +11,13 @@
#include "BLI_color.h"
#include "BLI_string.h"
#include "BLI_array_cxx.h"
+
#include "PIL_time.h"
+#include "BKE_context.h"
+
+#include "DNA_space_types.h"
+
#include "UI_interface.h"
using BLI::Array;
@@ -236,6 +242,16 @@ class NodeBuilder {
{
}
+ template<typename T> T *node_storage()
+ {
+#ifdef DEBUG
+ const char *type_name = typeid(T).name();
+ const char *expected_name = m_node_decl.m_node.typeinfo->storagename;
+ BLI_assert(strstr(type_name, expected_name));
+#endif
+ return (T *)m_node_decl.m_node.storage;
+ }
+
void fixed_input(StringRef identifier, StringRef ui_name, SocketDataType &type)
{
FixedTypeSocketDecl *decl = m_allocator.construct<FixedTypeSocketDecl>(
@@ -265,12 +281,17 @@ using DeclareNodeFunc = void (*)(NodeBuilder &builder);
static void declare_test_node(NodeBuilder &builder)
{
+ MyTestNodeStorage *storage = builder.node_storage<MyTestNodeStorage>();
+
builder.fixed_input("id1", "ID 1", *data_socket_float);
builder.fixed_input("id2", "ID 2", *data_socket_int);
builder.fixed_input("id4", "ID 4", *data_socket_int_list);
builder.fixed_output("id3", "ID 3", *data_socket_float);
- builder.fixed_output(
- "id5", "Hello " + std::to_string(PIL_check_seconds_timer_i() / 10), *data_socket_float_list);
+
+ for (int i = 0; i < storage->x; i++) {
+ builder.fixed_input(
+ "id" + std::to_string(i), "Hello " + std::to_string(i), *data_socket_float_list);
+ }
}
static void init_node(bNodeTree *ntree, bNode *node)
@@ -278,6 +299,8 @@ static void init_node(bNodeTree *ntree, bNode *node)
LinearAllocator<> allocator;
NodeDecl node_decl{*ntree, *node};
NodeBuilder node_builder{allocator, node_decl};
+ /* TODO: free storage */
+ node->storage = MEM_callocN(sizeof(MyTestNodeStorage), __func__);
declare_test_node(node_builder);
node_decl.build();
}
@@ -295,12 +318,42 @@ void register_node_type_my_test_node()
strcpy(ntype.idname, "MyTestNode");
strcpy(ntype.ui_name, "My Test Node");
strcpy(ntype.ui_description, "My Test Node Description");
+ strcpy(ntype.storagename, "MyTestNodeStorage");
ntype.type = NODE_CUSTOM;
ntype.initfunc = init_node;
ntype.poll = [](bNodeType *UNUSED(ntype), bNodeTree *UNUSED(ntree)) { return true; };
ntype.userdata = (void *)declare_test_node;
+ ntype.draw_buttons = [](uiLayout *layout, struct bContext *UNUSED(C), struct PointerRNA *ptr) {
+ bNode *node = (bNode *)ptr->data;
+ MyTestNodeStorage *storage = (MyTestNodeStorage *)node->storage;
+ uiBut *but = uiDefButI(uiLayoutGetBlock(layout),
+ UI_BTYPE_NUM,
+ 0,
+ "X value",
+ 0,
+ 0,
+ 50,
+ 50,
+ &storage->x,
+ -1000,
+ 1000,
+ 3,
+ 20,
+ "my x value");
+ uiItemL(layout, "Hello World", 0);
+ UI_but_func_set(
+ but,
+ [](bContext *C, void *UNUSED(arg1), void *UNUSED(arg2)) {
+ bNodeTree *ntree = CTX_wm_space_node(C)->edittree;
+ ntree->update = NTREE_UPDATE;
+ ntreeUpdateTree(CTX_data_main(C), ntree);
+ },
+ nullptr,
+ nullptr);
+ };
+
nodeRegisterType(&ntype);
}
@@ -353,6 +406,7 @@ void init_socket_data_types()
socket_data_types->add_data_type(data_socket_int_list);
}
+/* TODO: actually call this function */
void free_socket_data_types()
{
delete socket_data_types;
More information about the Bf-blender-cvs
mailing list