Blender V4.3
interface_template_node_inputs.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "BLI_vector.hh"
10
11#include "BKE_context.hh"
12#include "BKE_node.hh"
13#include "BKE_node_runtime.hh"
14#include "BKE_screen.hh"
15
16#include "BLT_translation.hh"
17
19
20#include "RNA_access.hh"
21#include "RNA_prototypes.hh"
22
23#include "UI_interface.hh"
24#include "UI_resources.hh"
25
26/* -------------------------------------------------------------------- */
34
36
38
40 uiLayout *layout,
41 PointerRNA *node_ptr,
42 bNodeSocket &socket)
43{
44 BLI_assert(socket.typeinfo != nullptr);
45 /* Ignore disabled sockets and linked sockets and sockets without a `draw` callback. */
46 if (!socket.is_available()) {
47 return;
48 }
49 if ((socket.flag & (SOCK_IS_LINKED | SOCK_HIDE_VALUE)) != 0) {
50 return;
51 }
52 if (socket.typeinfo->draw == nullptr) {
53 return;
54 }
56 return;
57 }
58 const bNode &node = *static_cast<bNode *>(node_ptr->data);
59 if (node.is_reroute()) {
60 return;
61 }
62
63 PointerRNA socket_ptr = RNA_pointer_create(node_ptr->owner_id, &RNA_NodeSocket, &socket);
64 const char *text = IFACE_(bke::nodeSocketLabel(&socket));
65 uiLayout *row = uiLayoutRow(layout, true);
66 socket.typeinfo->draw(C, row, &socket_ptr, node_ptr, text);
67}
68
70 uiLayout *layout,
71 PointerRNA *node_ptr,
72 StringRefNull identifier)
73{
74 bNode &node = *static_cast<bNode *>(node_ptr->data);
75 bNodeSocket *socket = node.runtime->inputs_by_identifier.lookup(identifier);
76 draw_node_input(C, layout, node_ptr, *socket);
77}
78
79/* Consume the item range, draw buttons if layout is not null. */
81 Panel *root_panel,
82 uiLayout *layout,
83 PointerRNA *node_ptr,
84 ItemIterator &item_iter,
85 const ItemIterator item_end)
86{
87 while (item_iter != item_end) {
88 const ItemDeclaration *item_decl = item_iter->get();
89 ++item_iter;
90
91 if (const SocketDeclaration *socket_decl = dynamic_cast<const SocketDeclaration *>(item_decl))
92 {
93 if (layout && socket_decl->in_out == SOCK_IN) {
94 draw_node_input(C, layout, node_ptr, socket_decl->identifier);
95 }
96 }
97 else if (const PanelDeclaration *panel_decl = dynamic_cast<const PanelDeclaration *>(
98 item_decl))
99 {
100 const ItemIterator panel_item_end = item_iter + panel_decl->num_child_decls;
101 BLI_assert(panel_item_end <= item_end);
102
103 /* Use a root panel property to toggle open/closed state. */
104 const std::string panel_idname = "NodePanel" + std::to_string(panel_decl->identifier);
106 root_panel, panel_idname.c_str(), panel_decl->default_collapsed);
107 PointerRNA state_ptr = RNA_pointer_create(nullptr, &RNA_LayoutPanelState, state);
108 uiLayout *panel_layout = uiLayoutPanelProp(
109 C, layout, &state_ptr, "is_open", IFACE_(panel_decl->name.c_str()));
110 /* Draw panel buttons at the top of each panel section. */
111 if (panel_layout && panel_decl->draw_buttons) {
112 panel_decl->draw_buttons(panel_layout, C, node_ptr);
113 }
114
116 C, root_panel, panel_layout, node_ptr, item_iter, panel_item_end);
117 }
118 }
119}
120
121} // namespace blender::ui::nodes
122
124{
125 bNodeTree &tree = *reinterpret_cast<bNodeTree *>(ptr->owner_id);
126 bNode &node = *static_cast<bNode *>(ptr->data);
127
128 tree.ensure_topology_cache();
129
130 BLI_assert(node.typeinfo != nullptr);
131 /* Draw top-level node buttons. */
132 if (node.typeinfo->draw_buttons_ex) {
133 node.typeinfo->draw_buttons_ex(layout, C, ptr);
134 }
135 else if (node.typeinfo->draw_buttons) {
136 node.typeinfo->draw_buttons(layout, C, ptr);
137 }
138
139 if (node.declaration()) {
140 /* Draw socket inputs and panel buttons in the order of declaration panels. */
141 ItemIterator item_iter = node.declaration()->items.begin();
142 const ItemIterator item_end = node.declaration()->items.end();
143 Panel *root_panel = uiLayoutGetRootPanel(layout);
145 C, root_panel, layout, ptr, item_iter, item_end);
146 }
147 else {
148 /* Draw socket values using the flat inputs list. */
149 for (bNodeSocket *input : node.runtime->inputs) {
150 blender::ui::nodes::draw_node_input(C, layout, ptr, *input);
151 }
152 }
153}
154
LayoutPanelState * BKE_panel_layout_panel_state_ensure(Panel *panel, const char *idname, bool default_closed)
Definition screen.cc:502
#define BLI_assert(a)
Definition BLI_assert.h:50
#define ELEM(...)
#define IFACE_(msgid)
@ SOCK_IN
@ SOCK_HIDE_VALUE
@ SOCK_IS_LINKED
@ SOCK_SHADER
@ SOCK_MATRIX
@ SOCK_GEOMETRY
Panel * uiLayoutGetRootPanel(uiLayout *layout)
uiLayout * uiLayoutRow(uiLayout *layout, bool align)
PanelLayout uiLayoutPanelProp(const bContext *C, uiLayout *layout, PointerRNA *open_prop_owner, const char *open_prop_name)
const T * const_iterator
Definition BLI_vector.hh:73
KDTree_3d * tree
blender::Vector< blender::nodes::ItemDeclarationPtr >::const_iterator ItemIterator
void uiTemplateNodeInputs(uiLayout *layout, bContext *C, PointerRNA *ptr)
static ulong state[N]
const char * nodeSocketLabel(const bNodeSocket *sock)
Definition node.cc:4296
static void draw_node_input(bContext *C, uiLayout *layout, PointerRNA *node_ptr, bNodeSocket &socket)
static void handle_node_declaration_items(bContext *C, Panel *root_panel, uiLayout *layout, PointerRNA *node_ptr, ItemIterator &item_iter, const ItemIterator item_end)
PointerRNA RNA_pointer_create(ID *id, StructRNA *type, void *data)
ID * owner_id
Definition RNA_types.hh:40
void * data
Definition RNA_types.hh:42
bNodeSocketRuntimeHandle * runtime
bNodeSocketTypeHandle * typeinfo
PointerRNA * ptr
Definition wm_files.cc:4126