[Bf-blender-cvs] [2fb43d04cb3] temp-enum-socket: support custom socket drawing
Jacques Lucke
noreply at git.blender.org
Mon Nov 8 16:07:02 CET 2021
Commit: 2fb43d04cb3c580073765dc81a451d5a87ff543b
Author: Jacques Lucke
Date: Sat Nov 6 19:26:58 2021 +0100
Branches: temp-enum-socket
https://developer.blender.org/rB2fb43d04cb3c580073765dc81a451d5a87ff543b
support custom socket drawing
===================================================================
M source/blender/blenkernel/BKE_node.h
M source/blender/editors/space_node/node_draw.cc
M source/blender/nodes/function/nodes/node_fn_enum.cc
===================================================================
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index 222a53a86fe..778cf45f184 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -264,6 +264,12 @@ typedef struct bNodeType {
/* Additional parameters in the side panel */
void (*draw_buttons_ex)(struct uiLayout *, struct bContext *C, struct PointerRNA *ptr);
+ bool (*draw_socket)(struct uiLayout *layout,
+ const struct bContext *C,
+ struct bNodeTree *ntree,
+ struct bNode *node,
+ struct bNodeSocket *socket);
+
/* Additional drawing on backdrop */
void (*draw_backdrop)(
struct SpaceNode *snode, struct ImBuf *backdrop, struct bNode *node, int x, int y);
diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc
index b6c24a55a78..2fc0c226fd6 100644
--- a/source/blender/editors/space_node/node_draw.cc
+++ b/source/blender/editors/space_node/node_draw.cc
@@ -419,7 +419,10 @@ static void node_update_basis(const bContext *C, bNodeTree *ntree, bNode *node)
uiLayout *row = uiLayoutRow(layout, true);
uiLayoutSetAlignment(row, UI_LAYOUT_ALIGN_RIGHT);
const char *socket_label = nodeSocketLabel(nsock);
- nsock->typeinfo->draw((bContext *)C, row, &sockptr, &nodeptr, IFACE_(socket_label));
+ if (node->typeinfo->draw_socket == NULL ||
+ !node->typeinfo->draw_socket(row, C, ntree, node, nsock)) {
+ nsock->typeinfo->draw((bContext *)C, row, &sockptr, &nodeptr, IFACE_(socket_label));
+ }
UI_block_align_end(node->block);
UI_block_layout_resolve(node->block, nullptr, &buty);
@@ -554,8 +557,11 @@ static void node_update_basis(const bContext *C, bNodeTree *ntree, bNode *node)
uiLayout *row = uiLayoutRow(layout, true);
- const char *socket_label = nodeSocketLabel(nsock);
- nsock->typeinfo->draw((bContext *)C, row, &sockptr, &nodeptr, IFACE_(socket_label));
+ if (node->typeinfo->draw_socket == NULL ||
+ !node->typeinfo->draw_socket(row, C, ntree, node, nsock)) {
+ const char *socket_label = nodeSocketLabel(nsock);
+ nsock->typeinfo->draw((bContext *)C, row, &sockptr, &nodeptr, IFACE_(socket_label));
+ }
UI_block_align_end(node->block);
UI_block_layout_resolve(node->block, nullptr, &buty);
diff --git a/source/blender/nodes/function/nodes/node_fn_enum.cc b/source/blender/nodes/function/nodes/node_fn_enum.cc
index bf83fb043ed..a3ba9e0f657 100644
--- a/source/blender/nodes/function/nodes/node_fn_enum.cc
+++ b/source/blender/nodes/function/nodes/node_fn_enum.cc
@@ -37,6 +37,16 @@ static void fn_node_enum_declare(NodeDeclarationBuilder &b)
}
};
+static bool fn_node_enum_draw_socket(uiLayout *layout,
+ const bContext *UNUSED(C),
+ bNodeTree *UNUSED(ntree),
+ bNode *UNUSED(node),
+ bNodeSocket *UNUSED(socket))
+{
+ uiItemL(layout, "Hello World", ICON_NONE);
+ return true;
+}
+
static void fn_node_enum_init(bNodeTree *UNUSED(tree), bNode *node)
{
NodeFunctionEnum *data = (NodeFunctionEnum *)MEM_callocN(sizeof(NodeFunctionEnum), __func__);
@@ -104,5 +114,6 @@ void register_node_type_fn_enum()
ntype.declaration_is_dynamic = true;
ntype.build_multi_function = blender::nodes::fn_node_enum_build_multi_function;
ntype.draw_buttons = blender::nodes::fn_node_enum_layout;
+ ntype.draw_socket = blender::nodes::fn_node_enum_draw_socket;
nodeRegisterType(&ntype);
}
More information about the Bf-blender-cvs
mailing list