Blender V5.3
compositor_nodes_caller_ui.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BKE_context.hh"
10
11#include "BLI_array.hh"
12#include "BLI_listbase.hh"
14#include "BLI_span.hh"
15#include "BLI_string_utf8.hh"
16#include "BLI_vector.hh"
17
18#include "BLT_translation.hh"
19
21#include "DNA_node_types.h"
22#include "DNA_sequence_types.h"
23
24#include "NOD_caller_ui.hh"
25#include "NOD_composite.hh"
29
30#include "SEQ_effects.hh"
31#include "SEQ_iterator.hh"
32#include "SEQ_modifier.hh"
33#include "SEQ_modifiertypes.hh"
34#include "SEQ_sequencer.hh"
35
36#include "RNA_access.hh"
37#include "RNA_define.hh"
38#include "RNA_prototypes.hh"
39
40#include "UI_interface.hh"
41#include "UI_interface_c.hh"
43
44namespace blender::nodes {
45
46namespace {
47
48struct DrawGroupInputsContext {
49 const bContext &C;
50 bNodeTree *tree;
51 PointerRNA *properties_ptr;
52 PointerRNA *bmain_ptr;
53
54 Array<nodes::socket_usage_inference::SocketUsage> input_usages;
55 Array<nodes::socket_usage_inference::SocketUsage> output_usages;
56
57 bool input_is_visible(const bNodeTreeInterfaceSocket &socket) const
58 {
59 return this->input_usages[this->tree->interface_input_index(socket)].is_visible;
60 }
61
62 bool input_is_active(const bNodeTreeInterfaceSocket &socket) const
63 {
64 return this->input_usages[this->tree->interface_input_index(socket)].is_used;
65 }
66};
67}; // namespace
68
69/* Drawing the properties manually with #ui::Layout::prop instead of #uiDefAutoButsRNA allows using
70 * the node socket identifier for the property names, since they are unique, but also having
71 * the correct label displayed in the UI. */
72static void draw_property_for_socket(DrawGroupInputsContext &ctx,
73 ui::Layout &layout,
74 const bNodeTreeInterfaceSocket &socket,
75 PointerRNA *socket_props_ptr,
76 const std::optional<StringRef> parent_name = std::nullopt)
77{
78 if (!ctx.input_is_visible(socket)) {
79 /* The input is not used currently, but it would be used if any menu input is changed.
80 * By convention, the input is hidden in this case instead of just grayed out. */
81 return;
82 }
83
84 ui::Layout &row = layout.row(true);
86 row.active_set(ctx.input_is_active(socket));
87
88 /* Use #ui::Layout::prop_search to draw pointer properties because #ui::Layout::prop would not
89 * have enough information about what type of ID to select for editing the values. This is
90 * because pointer IDProperties contain no information about their type. */
91 const bke::bNodeSocketType *typeinfo = socket.socket_typeinfo();
92 const eNodeSocketDatatype type = typeinfo ? typeinfo->type : SOCK_CUSTOM;
93
94 /* Check #composite_node_tree_socket_type_valid for which socket types are valid and should be
95 * drawn. */
96 if (!ELEM(type,
102 SOCK_RGBA,
105 SOCK_MENU,
107 SOCK_FONT,
109 {
110 return;
111 }
112
113 std::string name = IFACE_(socket.name());
114
115 /* If the property has a prefix that's the same string as the name of the panel it's in, remove
116 * the prefix so it appears less verbose. */
117 if (parent_name.has_value()) {
118 const StringRef prefix_to_remove = *parent_name;
119 const int prefix_size = prefix_to_remove.size();
120 const int pos = name.find(prefix_to_remove);
121 if (pos == 0 && name.size() > prefix_size && name[prefix_size] == ' ') {
122 name = name.substr(prefix_size + 1);
123 }
124 }
125
126 switch (type) {
127 case SOCK_OBJECT: {
128 row.prop_search(socket_props_ptr, "value", ctx.bmain_ptr, "objects", name, ICON_OBJECT_DATA);
129 break;
130 }
131 case SOCK_MENU: {
133 /* Use a single space when the name is empty to work around a bug with expanded enums. Also
134 * see #ui_item_enum_expand_exec. */
135 row.prop(socket_props_ptr,
136 "value",
138 StringRef(name).is_empty() ? " " : name,
139 ICON_NONE);
140 }
141 else {
142 row.prop(socket_props_ptr, "value", UI_ITEM_NONE, name, ICON_NONE);
143 }
144 break;
145 }
146 case SOCK_FONT: {
147 template_id(&row,
148 &ctx.C,
149 socket_props_ptr,
150 "value",
151 nullptr,
152 "FONT_OT_open",
153 "FONT_OT_unlink",
155 false,
156 name);
157 break;
158 }
159 default: {
160 row.prop(socket_props_ptr, "value", UI_ITEM_NONE, name, ICON_NONE);
161 break;
162 }
163 }
164}
165
166static void draw_interface_root_panel_content(DrawGroupInputsContext &ctx,
167 ui::Layout &layout,
168 const bNodeTreeInterfacePanel &interface_panel,
169 const Span<bool> skipped_inputs)
170{
171 const auto input_is_skipped = [&](const bNodeTreeInterfaceSocket &socket) {
172 return skipped_inputs[ctx.tree->interface_input_index(socket)];
173 };
174 for (const bNodeTreeInterfaceItem *item : interface_panel.items()) {
175 switch (item->item_type) {
177 const auto &sub_interface_panel = *reinterpret_cast<const bNodeTreeInterfacePanel *>(item);
179 ctx.C,
180 layout,
181 ctx.properties_ptr,
182 sub_interface_panel,
183 [&](const bNodeTreeInterfaceSocket &socket) {
184 return !input_is_skipped(socket) && ctx.input_is_visible(socket);
185 },
186 [&](const bNodeTreeInterfaceSocket &socket) {
187 return !input_is_skipped(socket) && ctx.input_is_active(socket);
188 },
189 [&](ui::Layout &layout,
190 const bNodeTreeInterfaceSocket &socket,
191 PointerRNA *socket_props_ptr,
192 const std::optional<StringRef> parent_name) {
193 if (!input_is_skipped(socket)) {
194 draw_property_for_socket(ctx, layout, socket, socket_props_ptr, parent_name);
195 }
196 });
197 break;
198 }
200 const auto &interface_socket = *reinterpret_cast<const bNodeTreeInterfaceSocket *>(item);
201 if (interface_socket.flag & NODE_INTERFACE_SOCKET_INPUT) {
202 if (!input_is_skipped(interface_socket) &&
203 !(interface_socket.flag & NODE_INTERFACE_SOCKET_HIDE_IN_MODIFIER))
204 {
205 PointerRNA inputs_ptr = RNA_pointer_get(ctx.properties_ptr, "inputs");
206 PointerRNA socket_props_ptr = RNA_pointer_get(&inputs_ptr,
207 interface_socket.identifier);
209 ctx, layout, interface_socket, &socket_props_ptr, std::nullopt);
210 }
211 }
212 break;
213 }
214 }
215 }
216}
217
219 const int num_float_inputs,
220 const int num_color_inputs)
221{
222 const Span<const bNodeTreeInterfaceSocket *> inputs = tree.interface_inputs();
223 Array<bool> supplied_inputs(inputs.size(), false);
224 int floats_left = num_float_inputs;
225 int colors_left = num_color_inputs;
226 for (const int i : inputs.index_range()) {
227 const bke::bNodeSocketType *typeinfo = inputs[i]->socket_typeinfo();
228 const eNodeSocketDatatype socket_type = typeinfo ? typeinfo->type : SOCK_CUSTOM;
229 if (floats_left > 0 && socket_type == SOCK_FLOAT) {
230 supplied_inputs[i] = true;
231 floats_left--;
232 }
233 else if (colors_left > 0 && socket_type == SOCK_RGBA) {
234 supplied_inputs[i] = true;
235 colors_left--;
236 }
237 }
238 return supplied_inputs;
239}
240
242{
243 Scene *sequencer_scene = CTX_data_sequencer_scene(&C);
244 Editing *ed = seq::editing_get(sequencer_scene);
245
246 const int input_mask_type = RNA_enum_get(ptr, "input_mask_type");
247
248 layout.use_property_split_set(true);
249
250 ui::Layout &col = layout.column(false);
251 ui::Layout *row = &col.row(true);
252 row->prop(ptr, "input_mask_type", ui::ITEM_R_EXPAND, IFACE_("Type"), ICON_NONE);
253
254 if (input_mask_type == STRIP_MASK_INPUT_STRIP) {
255 PointerRNA sequences_object = RNA_pointer_create_discrete(
256 &sequencer_scene->id, RNA_SequenceEditor, ed);
257 col.prop_search(
258 ptr, "input_mask_strip", &sequences_object, "strips_all", IFACE_("Mask"), ICON_NONE);
259 }
260 else {
261 col.prop(ptr, "input_mask_id", UI_ITEM_NONE, std::nullopt, ICON_NONE);
262 row = &col.row(true);
263 row->prop(ptr, "mask_time", ui::ITEM_R_EXPAND, std::nullopt, ICON_NONE);
264 }
265}
266
267static void draw_error_message(const bNodeTree &tree, ui::Layout &layout, const bool is_mask_used)
268{
269 const Span<const bNodeTreeInterfaceSocket *> interface_inputs = tree.interface_inputs();
270 const Span<const bNodeTreeInterfaceSocket *> interface_ouputs = tree.interface_outputs();
271
272 if (interface_inputs.size() > 0) {
273 const bke::bNodeSocketType *typeinfo = interface_inputs[0]->socket_typeinfo();
274 const eNodeSocketDatatype socket_type = typeinfo ? typeinfo->type : SOCK_CUSTOM;
275 if (socket_type != SOCK_RGBA) {
276 ui::Layout &row = layout.row(false);
277 row.label(RPT_("The first node group input must have the Color type"), ICON_STATUS_ERROR);
278 }
279 }
280
281 if (is_mask_used) {
282 if (interface_inputs.size() < 2) {
283 ui::Layout &row = layout.row(false);
284 row.label(RPT_("Node group must have at least two inputs to use the mask input"),
285 ICON_STATUS_ERROR);
286 }
287 else {
288 const bke::bNodeSocketType *typeinfo = interface_inputs[1]->socket_typeinfo();
289 const eNodeSocketDatatype socket_type = typeinfo ? typeinfo->type : SOCK_CUSTOM;
290 if (socket_type != SOCK_RGBA) {
291 ui::Layout &row = layout.row(false);
292 row.label(RPT_("The second node group input must have the Color type"), ICON_STATUS_ERROR);
293 }
294 }
295 }
296
297 if (interface_ouputs.is_empty()) {
298 ui::Layout &row = layout.row(false);
299 row.label(RPT_("Node group must have an output"), ICON_STATUS_ERROR);
300 }
301 else {
302 const bke::bNodeSocketType *typeinfo = interface_ouputs[0]->socket_typeinfo();
303 const eNodeSocketDatatype socket_type = typeinfo ? typeinfo->type : SOCK_CUSTOM;
304 if (socket_type != SOCK_RGBA) {
305 ui::Layout &row = layout.row(false);
306 row.label(RPT_("The first node group output must have the Color type"), ICON_STATUS_ERROR);
307 }
308 }
309}
310
312 PointerRNA *modifier_ptr,
313 ui::Layout &layout)
314{
315 Main *bmain = CTX_data_main(&C);
316 PointerRNA bmain_ptr = RNA_main_pointer_create(bmain);
318 PointerRNA properties_ptr = RNA_pointer_get(modifier_ptr, "properties");
319 DrawGroupInputsContext ctx{C, cmd.node_group, &properties_ptr, &bmain_ptr};
320
321 layout.use_property_split_set(true);
322
324 const char *newop = (cmd.node_group == nullptr) ?
325 "node.new_compositor_sequencer_node_group" :
326 "node.duplicate_compositing_modifier_node_group";
327 template_id(&layout, &C, modifier_ptr, "node_group", newop, nullptr, nullptr);
328 }
329
330 const StripModifierData &smd = cmd.modifier;
331 const bool is_mask_used = smd.mask_input_type == STRIP_MASK_INPUT_STRIP ?
332 smd.mask_strip != nullptr :
333 smd.mask_id != nullptr;
334
335 if (cmd.node_group != nullptr && !(ID_MISSING(cmd.node_group))) {
336 bNodeTree &tree = *cmd.node_group;
337 tree.ensure_interface_cache();
338 draw_error_message(tree, layout, is_mask_used);
339
340 ctx.input_usages.reinitialize(tree.interface_inputs().size());
341 ctx.output_usages.reinitialize(tree.interface_outputs().size());
343 tree, *ctx.properties_ptr, ctx.input_usages, ctx.output_usages);
344 const Array<bool> supplied_inputs = find_automatic_inputs(tree, 0, is_mask_used ? 2 : 1);
346 ctx, layout, tree.tree_interface.root_panel, supplied_inputs);
347 }
348
349 if (ui::Layout *mask_input_layout = layout.panel_prop(
350 &C, modifier_ptr, "open_mask_input_panel", IFACE_("Mask Input")))
351 {
352 draw_mask_input_type_settings(C, *mask_input_layout, modifier_ptr);
353 }
354}
355
357{
358 Strip &strip = *strip_ptr->data_as<Strip>();
359 if (strip.type != STRIP_TYPE_COMPOSITOR || strip.effectdata == nullptr) {
360 return;
361 }
362 const auto *comp = static_cast<const CompositorEffectVars *>(strip.effectdata);
363 if (comp->node_group == nullptr || ID_MISSING(comp->node_group)) {
364 return;
365 }
366
367 Main *bmain = CTX_data_main(&C);
368 PointerRNA bmain_ptr = RNA_main_pointer_create(bmain);
369 Scene *sequencer_scene = CTX_data_sequencer_scene(&C);
370 PointerRNA properties_ptr = RNA_pointer_get(strip_ptr, "properties");
371 if (!properties_ptr) {
372 return;
373 }
374
375 bNodeTree &tree = *comp->node_group;
376 tree.ensure_interface_cache();
377
378 DrawGroupInputsContext ctx{C, &tree, &properties_ptr, &bmain_ptr};
379
380 layout.use_property_split_set(true);
381
382 const int inputs_num = tree.interface_inputs().size();
383 ctx.input_usages.reinitialize(inputs_num);
384
385 Vector<bool> used, visible;
386 seq::compositor_effect_nodes_input_usages(*sequencer_scene, strip, used, visible);
387 for (const int i : IndexRange(inputs_num)) {
388 ctx.input_usages[i].is_used = i < used.size() ? used[i] : true;
389 ctx.input_usages[i].is_visible = i < visible.size() ? visible[i] : true;
390 }
391
392 const Array<bool> supplied_inputs = find_automatic_inputs(
393 tree, 1, strip.effect_num_inputs_get());
394 draw_interface_root_panel_content(ctx, layout, tree.tree_interface.root_panel, supplied_inputs);
395}
396
397}; // namespace blender::nodes
#define RPT_(msgid)
#define IFACE_(msgid)
#define ID_MISSING(_id)
Definition DNA_ID.h:695
#define C
Definition RandGen.cpp:29
#define UI_ITEM_NONE
#define ELEM(...)
constexpr int64_t size() const
Definition BLI_span.hh:256
constexpr IndexRange index_range() const
Definition BLI_span.hh:405
constexpr bool is_empty() const
Definition BLI_span.hh:264
constexpr StringRef()
int64_t size() const
constexpr int64_t size() const
void infer_group_interface_inputs_usage(const bNodeTree &group, Span< const bNodeSocket * > input_sockets, MutableSpan< SocketUsage > r_input_usages)
void draw_interface_panel_as_panel(const bContext &C, ui::Layout &layout, PointerRNA *properties_ptr, const bNodeTreeInterfacePanel &interface_panel, FunctionRef< bool(const bNodeTreeInterfaceSocket &)> fn_input_is_visible, FunctionRef< bool(const bNodeTreeInterfaceSocket &)> fn_input_is_active, FunctionRef< void(ui::Layout &, const bNodeTreeInterfaceSocket &, PointerRNA *, const std::optional< StringRef >)> fn_draw_property_for_socket)
static Array< bool > find_automatic_inputs(const bNodeTree &tree, const int num_float_inputs, const int num_color_inputs)
void draw_compositor_nodes_effect_ui(const bContext &C, PointerRNA *strip_ptr, ui::Layout &layout)
void draw_compositor_nodes_modifier_ui(const bContext &C, PointerRNA *modifier_ptr, ui::Layout &layout)
static void draw_mask_input_type_settings(const bContext &C, ui::Layout &layout, PointerRNA *ptr)
static void draw_error_message(const bNodeTree &tree, ui::Layout &layout, const bool is_mask_used)
static void draw_property_for_socket(DrawGroupInputsContext &ctx, ui::Layout &layout, const bNodeTreeInterfaceSocket &socket, PointerRNA *socket_props_ptr, const std::optional< StringRef > parent_name=std::nullopt)
static void draw_interface_root_panel_content(DrawGroupInputsContext &ctx, ui::Layout &layout, const bNodeTreeInterfacePanel &interface_panel, const Span< bool > skipped_inputs)
Editing * editing_get(const Scene *scene)
Definition sequencer.cc:304
void compositor_effect_nodes_input_usages(const Scene &sequencer_scene, Strip &strip, Vector< bool > &r_used, Vector< bool > &r_visible)
int RNA_enum_get(PointerRNA *ptr, const char *name)
Scene * CTX_data_sequencer_scene(const bContext *C)
PointerRNA RNA_main_pointer_create(Main *main)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
@ SEQ_COMP_MOD_HIDE_DATABLOCK_SELECTOR
PointerRNA RNA_pointer_get(PointerRNA *ptr, const char *name)
Main * CTX_data_main(const bContext *C)
T * data_as() const
Definition RNA_types.hh:139
bNodeTreeInterface tree_interface
Defines a socket type.
Definition BKE_node.hh:163
eNodeSocketDatatype type
Definition BKE_node.hh:198
void prop_search(PointerRNA *ptr, PropertyRNA *prop, PointerRNA *searchptr, PropertyRNA *searchprop, PropertyRNA *item_searchpropname, std::optional< StringRefNull > name, int icon, bool results_are_suggestions)
void use_property_decorate_set(bool is_decorate)
void use_property_split_set(bool is_sep)
void label(StringRef name, int icon)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)
void active_set(bool active)
Layout & column(bool align)
PanelLayout panel_prop(const bContext *C, PointerRNA *open_prop_owner, StringRefNull open_prop_name)
Layout & row(bool align)