Blender V5.3
node_draw.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2008 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9
10#include <iomanip>
11
12#include "BKE_idprop.hh"
13#include "MEM_guardedalloc.h"
14
15#include "DNA_light_types.h"
16#include "DNA_linestyle_types.h"
17#include "DNA_material_types.h"
18#include "DNA_modifier_types.h"
19#include "DNA_node_types.h"
20#include "DNA_screen_types.h"
21#include "DNA_space_types.h"
22#include "DNA_text_types.h"
23#include "DNA_world_types.h"
24
25#include "BLI_array.hh"
26#include "BLI_bounds.hh"
27#include "BLI_convexhull_2d.hh"
28#include "BLI_function_ref.hh"
29#include "BLI_listbase.hh"
30#include "BLI_map.hh"
31#include "BLI_math_color_c.hh"
32#include "BLI_set.hh"
33#include "BLI_span.hh"
34#include "BLI_string.hh"
35#include "BLI_string_ref.hh"
36#include "BLI_string_utf8.hh"
37#include "BLI_vector.hh"
38
39#include "BLT_translation.hh"
40
43#include "BKE_context.hh"
44#include "BKE_curves.hh"
45#include "BKE_global.hh"
46#include "BKE_idtype.hh"
47#include "BKE_image.hh"
48#include "BKE_lib_id.hh"
49#include "BKE_library.hh"
50#include "BKE_main.hh"
52#include "BKE_node.hh"
54#include "BKE_node_runtime.hh"
57#include "BKE_object.hh"
58#include "BKE_scene.hh"
59#include "BKE_scene_runtime.hh"
60#include "BKE_screen.hh"
61
62#include "IMB_imbuf.hh"
63
64#include "DEG_depsgraph.hh"
65
66#include "BLF_api.hh"
67
68#include "BIF_glutil.hh"
69
70#include "GPU_framebuffer.hh"
71#include "GPU_immediate.hh"
72#include "GPU_immediate_util.hh"
73#include "GPU_matrix.hh"
74#include "GPU_state.hh"
75#include "GPU_viewport.hh"
76
77#include "WM_api.hh"
78#include "WM_types.hh"
79
80#include "ED_gpencil_legacy.hh"
81#include "ED_node.hh"
82#include "ED_node_preview.hh"
83#include "ED_screen.hh"
84#include "ED_space_api.hh"
85#include "ED_util.hh"
86#include "ED_viewer_path.hh"
87
88#include "UI_interface.hh"
90#include "UI_resources.hh"
91#include "UI_view2d.hh"
92
93#include "RNA_access.hh"
94#include "RNA_path.hh"
95#include "RNA_prototypes.hh"
96
97#include "NOD_eval_log.hh"
100#include "NOD_node_extra_info.hh"
101#include "NOD_sync_sockets.hh"
102#include "NOD_trace_values.hh"
103
104#include "GEO_fillet_curves.hh"
105
106#include "node_intern.hh" /* own include */
107
108#include <fmt/format.h>
109#include <fmt/ranges.h>
110#include <sstream>
111
112namespace blender {
113
118
119namespace ed::space_node {
120
121#define NODE_ZONE_PADDING UI_UNIT_X
122#define ZONE_ZONE_PADDING 0.3f * UI_UNIT_X
123#define EXTRA_INFO_ROW_HEIGHT (20.0f * UI_SCALE_FAC)
124
183
185{
186 return NODE_GRID_STEP_SIZE;
187}
188
190{
191 SpaceNode *snode = CTX_wm_space_node(C);
192 if (snode) {
194
195 if (snode->nodetree) {
196 id_us_ensure_real(&snode->nodetree->id);
197 }
198 }
199}
200
201static void node_socket_add_tooltip_in_node_editor(const bNodeSocket &sock, ui::Layout &layout);
202
204static bool compare_node_depth(const bNode *a, const bNode *b)
205{
206 /* These tell if either the node or any of the parent nodes is selected.
207 * A selected parent means an unselected node is also in foreground! */
208 bool a_select = a->is_selected(), b_select = b->is_selected();
209 bool a_active = (a->flag & NODE_ACTIVE) != 0, b_active = (b->flag & NODE_ACTIVE) != 0;
210
211 /* If one is an ancestor of the other. */
212 /* XXX there might be a better sorting algorithm for stable topological sort,
213 * this is O(n^2) worst case. */
214 for (bNode *parent = a->parent; parent; parent = parent->parent) {
215 /* If B is an ancestor, it is always behind A. */
216 if (parent == b) {
217 return false;
218 }
219 /* Any selected ancestor moves the node forward. */
220 if (parent->flag & NODE_ACTIVE) {
221 a_active = true;
222 }
223 if (parent->is_selected()) {
224 a_select = true;
225 }
226 }
227 for (bNode *parent = b->parent; parent; parent = parent->parent) {
228 /* If A is an ancestor, it is always behind B. */
229 if (parent == a) {
230 return true;
231 }
232 /* Any selected ancestor moves the node forward. */
233 if (parent->flag & NODE_ACTIVE) {
234 b_active = true;
235 }
236 if (parent->is_selected()) {
237 b_select = true;
238 }
239 }
240
241 if (a->is_frame() && !b->is_frame()) {
242 return true;
243 }
244 if (b->is_frame() && !a->is_frame()) {
245 return false;
246 }
247
248 /* One has a higher selection state (active > selected > nothing). */
249 if (a_active && !b_active) {
250 return false;
251 }
252 if (b_active && !a_active) {
253 return true;
254 }
255 if (!b_select && (a_active || a_select)) {
256 return false;
257 }
258 if (!a_select && (b_active || b_select)) {
259 return true;
260 }
261
262 return false;
263}
264
266{
267 Array<bNode *> sort_nodes = ntree.all_nodes();
268 std::ranges::sort(sort_nodes, [](bNode *a, bNode *b) { return a->ui_order < b->ui_order; });
269 std::stable_sort(sort_nodes.begin(), sort_nodes.end(), compare_node_depth);
270 for (const int i : sort_nodes.index_range()) {
271 sort_nodes[i]->ui_order = i;
272 }
273}
274
276{
277 Array<bNode *> nodes = ntree.all_nodes();
278 if (nodes.is_empty()) {
279 return {};
280 }
281 std::ranges::sort(nodes,
282 [](const bNode *a, const bNode *b) { return a->ui_order < b->ui_order; });
283 return nodes;
284}
285
287{
288 Array<bNode *> nodes = ntree.all_nodes();
289 if (nodes.is_empty()) {
290 return {};
291 }
292 std::ranges::sort(nodes,
293 [](const bNode *a, const bNode *b) { return a->ui_order > b->ui_order; });
294 return nodes;
295}
296
298{
299 Array<ui::Block *> blocks(nodes.size());
300
301 /* Add node ui::Blocks in drawing order - prevents events going to overlapping nodes. */
302 Scene *scene = CTX_data_scene(&C);
303 wmWindow *window = CTX_wm_window(&C);
304 ARegion *region = CTX_wm_region(&C);
305 for (const int i : nodes.index_range()) {
306 const bNode &node = *nodes[i];
307 std::string block_name = "node_" + std::string(node.name);
308 ui::Block *block = block_begin(
309 &C, scene, window, region, std::move(block_name), ui::EmbossType::Emboss);
310 blocks[node.index()] = block;
311 /* This cancels events for background nodes. */
312 block_flag_enable(block, ui::BLOCK_CLIP_EVENTS);
313 }
314
315 return blocks;
316}
317
319{
320 return co * UI_SCALE_FAC;
321}
322
324{
325 rctf rect{};
326 rect.xmin = node.location[0];
327 rect.ymin = node.location[1] - node.height;
328 rect.xmax = node.location[0] + node.width;
329 rect.ymax = node.location[1];
330 return rect;
331}
332
333void node_to_updated_rect(const bNode &node, rctf &r_rect)
334{
335 r_rect = node_to_rect(node);
336 BLI_rctf_mul(&r_rect, UI_SCALE_FAC);
337}
338
340{
341 return co / UI_SCALE_FAC;
342}
343
345{
346 return node.declaration() && node.declaration()->use_custom_socket_order;
347}
348
349/* Draw UI for options, buttons, and previews. */
351 bNodeTree &ntree,
352 bNode &node,
354 ui::Block &block,
355 int &dy)
356{
357 /* Buttons rect? */
358 const bool node_options = draw_buttons && (node.flag & NODE_OPTIONS);
359 if (!node_options) {
360 return false;
361 }
362
363 PointerRNA nodeptr = RNA_pointer_create_discrete(&ntree.id, RNA_Node, &node);
364
365 /* Round the node origin because text contents are always pixel-aligned. */
366 const float2 loc = math::round(node_to_view(node.location));
367
368 dy -= NODE_DYS / 4;
369
370 ui::Layout &layout = ui::block_layout(&block,
373 loc.x + NODE_DYS,
374 dy,
376 0,
377 0,
379
380 if (node.is_muted()) {
381 layout.active_set(false);
382 }
383 if (!ID_IS_EDITABLE(&ntree.id)) {
384 layout.enabled_set(false);
385 }
386
387 layout.context_ptr_set("node", &nodeptr);
388
389 draw_buttons(layout, const_cast<bContext *>(&C), &nodeptr);
390
391 block_align_end(&block);
392 const int buty = ui::block_layout_resolve(&block).y;
393
394 dy = buty - NODE_DYS / 4;
395 return true;
396}
397
398const char *node_socket_get_label(const bNodeSocket *socket, const char *panel_label)
399{
400 /* Get the short label if possible. This is used when grouping sockets under panels,
401 * to avoid redundancy in the label. */
402 const std::optional<StringRefNull> socket_short_label = bke::node_socket_short_label(*socket);
403 const char *socket_translation_context = bke::node_socket_translation_context(*socket);
404
405 if (socket_short_label.has_value()) {
406 return CTX_IFACE_(socket_translation_context, socket_short_label->c_str());
407 }
408
409 const StringRefNull socket_label = bke::node_socket_label(*socket);
410 const char *translated_socket_label = CTX_IFACE_(socket_translation_context,
411 socket_label.c_str());
412
413 /* Shorten socket label if it begins with the panel label. */
414 if (panel_label) {
415 const int len_prefix = strlen(panel_label);
416 if (STREQLEN(translated_socket_label, panel_label, len_prefix) &&
417 translated_socket_label[len_prefix] == ' ')
418 {
419 return translated_socket_label + len_prefix + 1;
420 }
421 }
422
423 /* Full label. */
424 return translated_socket_label;
425}
426
427const char *node_socket_get_description(const bNodeSocket *socket)
428{
429 if (socket->runtime->declaration == nullptr) {
430 if (socket->description[0]) {
431 return TIP_(socket->description);
432 }
433 return nullptr;
434 }
435 const nodes::SocketDeclaration &socket_decl = *socket->runtime->declaration;
436 if (!socket_decl.description.empty()) {
437 return TIP_(socket_decl.description.c_str());
438 }
439 return nullptr;
440}
441
442static void draw_socket_layout(TreeDrawContext &tree_draw_ctx,
443 const bContext &C,
444 ui::Layout &layout,
445 bNodeSocket &socket,
446 bNodeTree &ntree,
447 bNode &node,
448 PointerRNA &node_ptr,
449 PointerRNA &socket_ptr,
450 const char *panel_label)
451{
452 const nodes::SocketDeclaration *socket_decl = socket.runtime->declaration;
453 const StringRefNull label = node_socket_get_label(&socket, panel_label);
455 layout,
456 ntree,
457 node,
458 socket,
459 node_ptr,
460 socket_ptr,
461 label,
463 if (socket_decl) {
464 if (socket_decl->custom_draw_fn) {
465 (*socket_decl->custom_draw_fn)(params);
466 return;
467 }
468 }
469 params.draw_standard(layout);
470}
471
472static bool node_update_basis_socket(TreeDrawContext &tree_draw_ctx,
473 const bContext &C,
474 bNodeTree &ntree,
475 bNode &node,
476 const char *panel_label,
477 bNodeSocket *input_socket,
478 bNodeSocket *output_socket,
479 ui::Block &block,
480 const int &locx,
481 int &locy)
482{
483 if ((!input_socket || !input_socket->is_visible()) &&
484 (!output_socket || !output_socket->is_visible()))
485 {
486 return false;
487 }
488
489 const int topy = locy;
490
491 /* Add the half the height of a multi-input socket to cursor Y
492 * to account for the increased height of the taller sockets. */
493 const bool is_multi_input = (input_socket ? (input_socket->flag & SOCK_MULTI_INPUT) != 0 :
494 false);
495 const float multi_input_socket_offset = is_multi_input ?
496 std::max(input_socket->runtime->total_inputs - 2,
497 0) *
499 0.0f;
500 locy -= multi_input_socket_offset * 0.5f;
501
502 ui::Layout &layout = ui::block_layout(&block,
505 locx + NODE_DYS,
506 locy,
508 NODE_DY,
509 0,
511
512 if (node.is_muted()) {
513 layout.active_set(false);
514 }
515 if (!ID_IS_EDITABLE(&ntree.id)) {
516 layout.enabled_set(false);
517 }
518
519 ui::Layout *row = &layout.row(true);
520 PointerRNA nodeptr = RNA_pointer_create_discrete(&ntree.id, RNA_Node, &node);
521 row->context_ptr_set("node", &nodeptr);
522
523 if (input_socket) {
524 /* Context pointers for current node and socket. */
525 PointerRNA sockptr = RNA_pointer_create_discrete(&ntree.id, RNA_NodeSocket, input_socket);
526 row->context_ptr_set("socket", &sockptr);
527
529
531 tree_draw_ctx, C, *row, *input_socket, ntree, node, nodeptr, sockptr, panel_label);
532 }
533 else {
534 /* Context pointers for current node and socket. */
535 PointerRNA sockptr = RNA_pointer_create_discrete(&ntree.id, RNA_NodeSocket, output_socket);
536 row->context_ptr_set("socket", &sockptr);
537
538 /* Align output buttons to the right. */
540
542 tree_draw_ctx, C, *row, *output_socket, ntree, node, nodeptr, sockptr, panel_label);
543 }
544
545 if (input_socket) {
546 /* Round the socket location to stop it from jiggling. */
547 input_socket->runtime->location = float2(round(locx), round(locy - NODE_DYS));
548 }
549 if (output_socket) {
550 /* Round the socket location to stop it from jiggling. */
551 output_socket->runtime->location = float2(round(locx + NODE_WIDTH(node)),
552 round(locy - NODE_DYS));
553 }
554
555 /* Prioritize tooltip for inputs if available. The tooltip for the output is still accessible
556 * when hovering exactly over the output socket. */
557 if (input_socket) {
558 node_socket_add_tooltip_in_node_editor(*input_socket, *row);
559 }
560 else if (output_socket) {
561 node_socket_add_tooltip_in_node_editor(*output_socket, *row);
562 }
563
564 block_align_end(&block);
565
566 int buty = ui::block_layout_resolve(&block).y;
567 /* Ensure minimum socket height in case layout is empty. */
568 buty = min_ii(buty, topy - NODE_DY);
569 locy = buty - multi_input_socket_offset * 0.5;
570 return true;
571}
572
573namespace flat_item {
574
583
584struct Socket {
585 static constexpr Type type = Type::Socket;
586 bNodeSocket *input = nullptr;
587 bNodeSocket *output = nullptr;
589};
590struct Separator {
591 static constexpr Type type = Type::Separator;
592};
607struct Layout {
608 static constexpr Type type = Type::Layout;
610};
611
612} // namespace flat_item
613
615 std::variant<flat_item::Socket,
622
624 {
625 return std::visit([](auto &&item) { return item.type; }, this->item);
626 }
627};
628
630 const bNode &node, const nodes::PanelDeclaration &panel_decl, MutableSpan<bool> r_result)
631{
632 bool potentially_visible = false;
633 for (const nodes::ItemDeclaration *item_decl : panel_decl.items) {
634 if (const auto *socket_decl = dynamic_cast<const nodes::SocketDeclaration *>(item_decl)) {
635 const bNodeSocket &socket = node.socket_by_decl(*socket_decl);
636 potentially_visible |= socket.is_visible();
637 }
638 else if (const auto *sub_panel_decl = dynamic_cast<const nodes::PanelDeclaration *>(item_decl))
639 {
640 determine_potentially_visible_panels_recursive(node, *sub_panel_decl, r_result);
641 potentially_visible |= r_result[sub_panel_decl->index];
642 }
643 }
644 r_result[panel_decl.index] = potentially_visible;
645}
646
651{
652 for (const nodes::ItemDeclaration *item_decl : node.declaration()->root_items) {
653 if (const auto *panel_decl = dynamic_cast<const nodes::PanelDeclaration *>(item_decl)) {
655 }
656 }
657}
658
660 const nodes::PanelDeclaration &panel_decl,
661 const Span<bool> potentially_visible_states,
662 MutableSpan<bool> r_result)
663{
664 if (!potentially_visible_states[panel_decl.index]) {
665 /* This panel does not contain any visible sockets. */
666 return;
667 }
668 r_result[panel_decl.index] = true;
669 const bNodePanelState &panel_state = node.panel_states_array[panel_decl.index];
670 if (panel_state.is_collapsed()) {
671 /* The sub-panels can't be visible if this panel is collapsed. */
672 return;
673 }
674 for (const nodes::ItemDeclaration *item_decl : panel_decl.items) {
675 if (const auto *sub_panel_decl = dynamic_cast<const nodes::PanelDeclaration *>(item_decl)) {
677 node, *sub_panel_decl, potentially_visible_states, r_result);
678 }
679 }
680}
681
683 const Span<bool> potentially_visible_states,
684 MutableSpan<bool> r_result)
685{
686 for (const nodes::ItemDeclaration *item_decl : node.declaration()->root_items) {
687 if (const auto *panel_decl = dynamic_cast<const nodes::PanelDeclaration *>(item_decl)) {
689 node, *panel_decl, potentially_visible_states, r_result);
690 }
691 }
692}
693
699static void determine_visible_panels(const bNode &node, MutableSpan<bool> r_visibility_states)
700{
701 Array<bool> potentially_visible_states(r_visibility_states.size(), false);
702 determine_potentially_visible_panels(node, potentially_visible_states);
703 determine_visible_panels_impl(node, potentially_visible_states, r_visibility_states);
704}
705
707 const nodes::SocketDeclaration &socket_decl,
708 const nodes::PanelDeclaration *panel_decl,
709 const nodes::SocketDeclaration *prev_socket_decl,
710 Vector<FlatNodeItem> &r_items)
711{
712 bNodeSocket &socket = node.socket_by_decl(socket_decl);
713 if (!socket.is_visible()) {
714 return;
715 }
716 if (socket_decl.align_with_previous_socket) {
717 if (!prev_socket_decl || !node.socket_by_decl(*prev_socket_decl).is_visible()) {
718 r_items.append({flat_item::Socket()});
719 }
720 }
721 else {
722 r_items.append({flat_item::Socket()});
723 }
724 flat_item::Socket &item = std::get<flat_item::Socket>(r_items.last().item);
725 if (socket_decl.in_out == SOCK_IN) {
726 BLI_assert(!item.input);
727 item.input = &socket;
728 }
729 else {
730 BLI_assert(!item.output);
731 item.output = &socket;
732 }
733 item.panel_decl = panel_decl;
734}
735
737{
738 r_items.append({flat_item::Separator()});
739}
740
742 const nodes::LayoutDeclaration &layout_decl,
743 Vector<FlatNodeItem> &r_items)
744{
745 if (!(node.flag & NODE_OPTIONS)) {
746 return;
747 }
748 r_items.append({flat_item::Layout{&layout_decl}});
749}
750
752 const nodes::PanelDeclaration &panel_decl,
753 const Span<bool> panel_visibility,
754 Vector<FlatNodeItem> &r_items)
755{
756 if (!panel_visibility[panel_decl.index]) {
757 return;
758 }
759 flat_item::PanelHeader header_item;
760 header_item.decl = &panel_decl;
761 const nodes::SocketDeclaration *panel_input_decl = panel_decl.panel_input_decl();
762 if (panel_input_decl) {
763 header_item.input = &node.socket_by_decl(*panel_input_decl);
764 }
765 r_items.append({header_item});
766
767 const bNodePanelState &panel_state = node.panel_states_array[panel_decl.index];
768 if (panel_state.is_collapsed()) {
769 return;
770 }
771 r_items.append({flat_item::PanelContentBegin{&panel_decl}});
772 const nodes::SocketDeclaration *prev_socket_decl = nullptr;
773 for (const nodes::ItemDeclaration *item_decl : panel_decl.items) {
774 if (item_decl == panel_input_decl) {
775 continue;
776 }
777 if (const auto *socket_decl = dynamic_cast<const nodes::SocketDeclaration *>(item_decl)) {
778 add_flat_items_for_socket(node, *socket_decl, &panel_decl, prev_socket_decl, r_items);
779 prev_socket_decl = socket_decl;
780 }
781 else {
782 if (const auto *sub_panel_decl = dynamic_cast<const nodes::PanelDeclaration *>(item_decl)) {
783 add_flat_items_for_panel(node, *sub_panel_decl, panel_visibility, r_items);
784 }
785 else if (dynamic_cast<const nodes::SeparatorDeclaration *>(item_decl)) {
787 }
788 else if (const auto *layout_decl = dynamic_cast<const nodes::LayoutDeclaration *>(item_decl))
789 {
790 add_flat_items_for_layout(node, *layout_decl, r_items);
791 }
792 prev_socket_decl = nullptr;
793 }
794 }
795 r_items.append({flat_item::PanelContentEnd{&panel_decl}});
796}
797
802{
804 BLI_assert(node.runtime->panels.size() == node.num_panel_states);
805
806 const int panels_num = node.num_panel_states;
807 Array<bool> panel_visibility(panels_num, false);
808 determine_visible_panels(node, panel_visibility);
809
810 const nodes::SocketDeclaration *prev_socket_decl = nullptr;
811
813 for (const nodes::ItemDeclaration *item_decl : node.declaration()->root_items) {
814 if (const auto *socket_decl = dynamic_cast<const nodes::SocketDeclaration *>(item_decl)) {
815 add_flat_items_for_socket(node, *socket_decl, nullptr, prev_socket_decl, items);
816 prev_socket_decl = socket_decl;
817 }
818 else {
819 if (const auto *panel_decl = dynamic_cast<const nodes::PanelDeclaration *>(item_decl)) {
820 add_flat_items_for_panel(node, *panel_decl, panel_visibility, items);
821 }
822 else if (dynamic_cast<const nodes::SeparatorDeclaration *>(item_decl)) {
824 }
825 else if (const auto *layout_decl = dynamic_cast<const nodes::LayoutDeclaration *>(item_decl))
826 {
827 add_flat_items_for_layout(node, *layout_decl, items);
828 }
829 prev_socket_decl = nullptr;
830 }
831 }
832 return items;
833}
834
836static float get_margin_empty()
837{
838 return NODE_DYS;
839}
840
843{
844 const FlatNodeItem &first_item = items[0];
845 const flat_item::Type first_item_type = first_item.type();
846 switch (first_item_type) {
848 return 2 * NODE_ITEM_SPACING_Y;
850 return NODE_ITEM_SPACING_Y / 2;
852 return 3 * NODE_ITEM_SPACING_Y;
854 return 4 * NODE_ITEM_SPACING_Y;
857 break;
858 }
860 return 0;
861}
862
865{
866 const FlatNodeItem &last_item = items.last();
867 const flat_item::Type last_item_type = last_item.type();
868 switch (last_item_type) {
870 return 2 * NODE_ITEM_SPACING_Y;
872 return NODE_ITEM_SPACING_Y;
874 return 5 * NODE_ITEM_SPACING_Y;
876 return 4 * NODE_ITEM_SPACING_Y;
878 break;
880 return 1 * NODE_ITEM_SPACING_Y;
881 }
883 return 0;
884}
885
887static float get_margin_between_elements(const Span<FlatNodeItem> items, const int next_index)
888{
889 BLI_assert(next_index >= 1);
890 const FlatNodeItem &prev = items[next_index - 1];
891 const FlatNodeItem &next = items[next_index];
892 using flat_item::Type;
893 const Type prev_type = prev.type();
894 const Type next_type = next.type();
895
896 /* Handle all cases explicitly. This simplifies modifying the margins for specific cases
897 * without breaking other cases significantly. */
898 switch (prev_type) {
899 case Type::Socket: {
900 switch (next_type) {
901 case Type::Socket:
902 return NODE_ITEM_SPACING_Y;
903 case Type::Separator:
904 return 0;
905 case Type::Layout:
906 return 2 * NODE_ITEM_SPACING_Y;
907 case Type::PanelHeader:
908 return 3 * NODE_ITEM_SPACING_Y;
909 case Type::PanelContentBegin:
910 break;
911 case Type::PanelContentEnd:
912 return 2 * NODE_ITEM_SPACING_Y;
913 }
914 break;
915 }
916 case Type::Layout: {
917 switch (next_type) {
918 case Type::Socket:
919 return 2 * NODE_ITEM_SPACING_Y;
920 case Type::Separator:
921 return 0;
922 case Type::Layout:
923 return NODE_ITEM_SPACING_Y;
924 case Type::PanelHeader:
925 return 3 * NODE_ITEM_SPACING_Y;
926 case Type::PanelContentBegin:
927 break;
928 case Type::PanelContentEnd:
929 return 2 * NODE_ITEM_SPACING_Y;
930 }
931 break;
932 }
933 case Type::Separator: {
934 switch (next_type) {
935 case Type::Socket:
936 return 2 * NODE_ITEM_SPACING_Y;
937 case Type::Separator:
938 return NODE_ITEM_SPACING_Y;
939 case Type::Layout:
940 return NODE_ITEM_SPACING_Y;
941 case Type::PanelHeader:
942 return NODE_ITEM_SPACING_Y;
943 case Type::PanelContentBegin:
944 break;
945 case Type::PanelContentEnd:
946 return NODE_ITEM_SPACING_Y;
947 }
948 break;
949 }
950 case Type::PanelHeader: {
951 switch (next_type) {
952 case Type::Socket:
953 return 4 * NODE_ITEM_SPACING_Y;
954 case Type::Separator:
955 return 3 * NODE_ITEM_SPACING_Y;
956 case Type::Layout:
957 return 3 * NODE_ITEM_SPACING_Y;
958 case Type::PanelHeader:
959 return 5 * NODE_ITEM_SPACING_Y;
960 case Type::PanelContentBegin:
961 return 3 * NODE_ITEM_SPACING_Y;
962 case Type::PanelContentEnd:
963 return 3 * NODE_ITEM_SPACING_Y;
964 }
965 break;
966 }
967 case Type::PanelContentBegin: {
968 switch (next_type) {
969 case Type::Socket:
970 return 2 * NODE_ITEM_SPACING_Y;
971 case Type::Separator:
972 return NODE_ITEM_SPACING_Y;
973 case Type::Layout:
974 return 2 * NODE_ITEM_SPACING_Y;
975 case Type::PanelHeader:
976 return 3 * NODE_ITEM_SPACING_Y;
977 case Type::PanelContentBegin:
978 break;
979 case Type::PanelContentEnd:
980 return NODE_ITEM_SPACING_Y;
981 }
982 break;
983 }
984 case Type::PanelContentEnd: {
985 switch (next_type) {
986 case Type::Socket:
987 return NODE_ITEM_SPACING_Y;
988 case Type::Separator:
989 return NODE_ITEM_SPACING_Y;
990 case Type::Layout:
991 return NODE_ITEM_SPACING_Y;
992 case Type::PanelHeader:
993 return 3 * NODE_ITEM_SPACING_Y;
994 case Type::PanelContentBegin:
995 break;
996 case Type::PanelContentEnd:
997 return 0;
998 }
999 break;
1000 }
1001 }
1003 return 0.0f;
1004}
1005
1008 const int node_left_x,
1009 const nodes::PanelDeclaration &visible_panel_decl,
1010 const nodes::PanelDeclaration &panel_decl)
1011{
1012 const bke::bNodePanelRuntime &visible_panel_runtime =
1013 node.runtime->panels[visible_panel_decl.index];
1014
1015 /* If the panel runtime is not initialized, then it is not visible. */
1016 if (!visible_panel_runtime.header_center_y.has_value()) {
1017 return;
1018 }
1019
1020 for (const nodes::ItemDeclaration *item_decl : panel_decl.items) {
1021 if (const auto *socket_decl = dynamic_cast<const nodes::SocketDeclaration *>(item_decl)) {
1022 bNodeSocket &socket = node.socket_by_decl(*socket_decl);
1023 const int socket_x = socket.in_out == SOCK_IN ? node_left_x : node_left_x + NODE_WIDTH(node);
1024 socket.runtime->location = math::round(
1025 float2(socket_x, *visible_panel_runtime.header_center_y));
1026 socket.flag |= SOCK_PANEL_COLLAPSED;
1027 }
1028 else if (const auto *sub_panel_decl = dynamic_cast<const nodes::PanelDeclaration *>(item_decl))
1029 {
1030 mark_sockets_collapsed_recursive(node, node_left_x, visible_panel_decl, *sub_panel_decl);
1031 }
1032 }
1033}
1034
1036 const int node_left_x,
1037 const nodes::PanelDeclaration &panel_decl)
1038{
1039 const bNodePanelState &panel_state = node.panel_states_array[panel_decl.index];
1040 if (panel_state.is_collapsed()) {
1041 mark_sockets_collapsed_recursive(node, node_left_x, panel_decl, panel_decl);
1042 return;
1043 }
1044 for (const nodes::ItemDeclaration *item_decl : panel_decl.items) {
1045 if (const auto *sub_panel_decl = dynamic_cast<const nodes::PanelDeclaration *>(item_decl)) {
1046 update_collapsed_sockets_recursive(node, node_left_x, *sub_panel_decl);
1047 }
1048 }
1049}
1050
1055static void update_collapsed_sockets(bNode &node, const int node_left_x)
1056{
1057 for (const nodes::ItemDeclaration *item_decl : node.declaration()->root_items) {
1058 if (const auto *panel_decl = dynamic_cast<const nodes::PanelDeclaration *>(item_decl)) {
1059 update_collapsed_sockets_recursive(node, node_left_x, *panel_decl);
1060 }
1061 }
1062}
1063
1069{
1070 const flat_item::PanelContentEnd *final_panel = nullptr;
1071 for (int item_i = items.size() - 1; item_i >= 0; item_i--) {
1072 const FlatNodeItem &item = items[item_i];
1073 if (const auto *panel_item = std::get_if<flat_item::PanelContentEnd>(&item.item)) {
1074 final_panel = panel_item;
1075 }
1076 else {
1077 break;
1078 }
1079 }
1080 if (final_panel) {
1081 bke::bNodePanelRuntime &final_panel_runtime = node.runtime->panels[final_panel->decl->index];
1082 final_panel_runtime.content_extent->fill_node_end = true;
1083 }
1084}
1085
1086/* Advanced drawing with panels and arbitrary input/output ordering. */
1088 const bContext &C,
1089 bNodeTree &ntree,
1090 bNode &node,
1091 ui::Block &block,
1092 const int locx,
1093 int &locy)
1094{
1096 BLI_assert(node.runtime->panels.size() == node.num_panel_states);
1097
1098 /* Reset states. */
1099 for (bke::bNodePanelRuntime &panel_runtime : node.runtime->panels) {
1100 panel_runtime.header_center_y.reset();
1101 panel_runtime.content_extent.reset();
1102 panel_runtime.input_socket = nullptr;
1103 }
1104 for (bNodeSocket *socket : node.input_sockets()) {
1105 socket->flag &= ~SOCK_PANEL_COLLAPSED;
1106 }
1107 for (bNodeSocket *socket : node.output_sockets()) {
1108 socket->flag &= ~SOCK_PANEL_COLLAPSED;
1109 }
1110
1111 /* Gather flattened list of items in the node. */
1113 if (flat_items.is_empty()) {
1114 const float margin = get_margin_empty();
1115 locy -= margin;
1116 return;
1117 }
1118
1119 for (const int item_i : flat_items.index_range()) {
1120 /* Apply margins. This should be the only place that applies margins between elements so that
1121 * it is easy change later on. */
1122 if (item_i == 0) {
1123 const float margin = get_margin_from_top(flat_items);
1124 locy -= margin;
1125 }
1126 else {
1127 const float margin = get_margin_between_elements(flat_items, item_i);
1128 locy -= margin;
1129 }
1130
1131 const FlatNodeItem &item_variant = flat_items[item_i];
1132 std::visit(
1133 [&](const auto &item) {
1134 using ItemT = std::decay_t<decltype(item)>;
1135 if constexpr (std::is_same_v<ItemT, flat_item::Socket>) {
1136 bNodeSocket *input_socket = item.input;
1137 bNodeSocket *output_socket = item.output;
1138 const nodes::PanelDeclaration *panel_decl = item.panel_decl;
1139 const char *parent_label = panel_decl ? panel_decl->name.c_str() : "";
1140 node_update_basis_socket(tree_draw_ctx,
1141 C,
1142 ntree,
1143 node,
1144 parent_label,
1145 input_socket,
1146 output_socket,
1147 block,
1148 locx,
1149 locy);
1150 }
1151 else if constexpr (std::is_same_v<ItemT, flat_item::Layout>) {
1152 const nodes::LayoutDeclaration &decl = *item.decl;
1153 /* Round the node origin because text contents are always pixel-aligned. */
1154 const float2 loc = math::round(node_to_view(node.location));
1155 ui::Layout &layout = ui::block_layout(&block,
1158 loc.x + NODE_DYS,
1159 locy,
1161 0,
1162 0,
1164 if (node.is_muted()) {
1165 layout.active_set(false);
1166 }
1167 if (!ID_IS_EDITABLE(&ntree.id)) {
1168 layout.enabled_set(false);
1169 }
1170 PointerRNA node_ptr = RNA_pointer_create_discrete(&ntree.id, RNA_Node, &node);
1171 layout.context_ptr_set("node", &node_ptr);
1172 decl.draw(layout, const_cast<bContext *>(&C), &node_ptr);
1173 block_align_end(&block);
1174 locy = ui::block_layout_resolve(&block).y;
1175 }
1176 else if constexpr (std::is_same_v<ItemT, flat_item::Separator>) {
1177 ui::Layout &layout = ui::block_layout(&block,
1180 locx + NODE_DYS,
1181 locy,
1183 NODE_DY,
1184 0,
1188 }
1189 else if constexpr (std::is_same_v<ItemT, flat_item::PanelHeader>) {
1190 const nodes::PanelDeclaration &node_decl = *item.decl;
1191 bke::bNodePanelRuntime &panel_runtime = node.runtime->panels[node_decl.index];
1192 const float panel_header_height = NODE_DYS;
1193 locy -= panel_header_height / 2;
1194 panel_runtime.header_center_y = locy;
1195 locy -= panel_header_height / 2;
1196 bNodeSocket *input_socket = item.input;
1197 if (input_socket) {
1198 panel_runtime.input_socket = input_socket;
1199 input_socket->runtime->location = float2(locx, *panel_runtime.header_center_y);
1200 }
1201 }
1202 else if constexpr (std::is_same_v<ItemT, flat_item::PanelContentBegin>) {
1203 const nodes::PanelDeclaration &node_decl = *item.decl;
1204 bke::bNodePanelRuntime &panel_runtime = node.runtime->panels[node_decl.index];
1205 panel_runtime.content_extent.emplace();
1206 panel_runtime.content_extent->max_y = locy;
1207 }
1208 else if constexpr (std::is_same_v<ItemT, flat_item::PanelContentEnd>) {
1209 const nodes::PanelDeclaration &node_decl = *item.decl;
1210 bke::bNodePanelRuntime &panel_runtime = node.runtime->panels[node_decl.index];
1211 panel_runtime.content_extent->min_y = locy;
1212 }
1213 else {
1215 }
1216 },
1217 item_variant.item);
1218 }
1219
1220 const float bottom_margin = get_margin_to_bottom(flat_items);
1221 locy -= bottom_margin;
1222
1224 tag_final_panel(node, flat_items);
1225}
1226
1227/* Conventional drawing in outputs/buttons/inputs order. */
1229 const bContext &C,
1230 bNodeTree &ntree,
1231 bNode &node,
1232 ui::Block &block,
1233 const int locx,
1234 int &locy)
1235{
1236 /* Space at the top. */
1237 locy -= NODE_ITEM_SPACING_Y * 2;
1238
1239 /* Output sockets. */
1240 bool add_output_space = false;
1241
1242 for (bNodeSocket *socket : node.output_sockets()) {
1243 /* Clear flag, conventional drawing does not support panels. */
1244 socket->flag &= ~SOCK_PANEL_COLLAPSED;
1245
1246 if (socket->is_visible() && add_output_space) {
1247 locy -= NODE_ITEM_SPACING_Y;
1248 }
1250 tree_draw_ctx, C, ntree, node, nullptr, nullptr, socket, block, locx, locy))
1251 {
1252 add_output_space = true;
1253 }
1254 }
1255
1256 const bool add_button_space = node_update_basis_buttons(
1257 C, ntree, node, node.typeinfo->draw_buttons, block, locy);
1258
1259 bool add_input_space = false;
1260 const bool add_before_first_input = add_output_space && !add_button_space;
1261
1262 /* Input sockets. */
1263 for (bNodeSocket *socket : node.input_sockets()) {
1264 /* Clear flag, conventional drawing does not support panels. */
1265 socket->flag &= ~SOCK_PANEL_COLLAPSED;
1266
1267 if (socket->is_visible() && (add_input_space || add_before_first_input)) {
1268 locy -= NODE_ITEM_SPACING_Y;
1269 }
1271 tree_draw_ctx, C, ntree, node, nullptr, socket, nullptr, block, locx, locy))
1272 {
1273 add_input_space = true;
1274 }
1275 }
1276
1277 /* Little bit of padding at the bottom. */
1278 if (add_output_space || add_input_space || add_button_space) {
1279 locy -= NODE_ITEM_SPACING_Y * 2;
1280 }
1281}
1282
1286static void node_update_basis(const bContext &C,
1287 TreeDrawContext &tree_draw_ctx,
1288 bNodeTree &ntree,
1289 bNode &node,
1290 ui::Block &block)
1291{
1292 /* Round the node origin because text contents are always pixel-aligned. */
1293 const float2 loc = math::round(node_to_view(node.location));
1294
1295 int dy = loc.y;
1296
1297 /* Header. */
1298 dy -= NODE_DY;
1299
1301 node_update_basis_from_declaration(tree_draw_ctx, C, ntree, node, block, loc.x, dy);
1302 }
1303 else {
1304 node_update_basis_from_socket_lists(tree_draw_ctx, C, ntree, node, block, loc.x, dy);
1305 }
1306
1307 node.runtime->draw_bounds.xmin = loc.x;
1308 node.runtime->draw_bounds.xmax = loc.x + NODE_WIDTH(node);
1309 node.runtime->draw_bounds.ymax = loc.y;
1310 node.runtime->draw_bounds.ymin = min_ff(dy, loc.y - 2 * NODE_DY);
1311
1312 /* Set the block bounds to clip mouse events from underlying nodes.
1313 * Add a margin for sockets on each side. */
1314 block_bounds_set_explicit(&block,
1315 node.runtime->draw_bounds.xmin - NODE_SOCKSIZE,
1316 node.runtime->draw_bounds.ymin,
1317 node.runtime->draw_bounds.xmax + NODE_SOCKSIZE,
1318 node.runtime->draw_bounds.ymax);
1319}
1320
1325{
1326 int totin = 0, totout = 0;
1327
1328 /* Round the node origin because text contents are always pixel-aligned. */
1329 const float2 loc = math::round(node_to_view(node.location));
1330
1331 /* Calculate minimal radius. */
1332 for (const bNodeSocket *socket : node.input_sockets()) {
1333 if (socket->is_visible()) {
1334 totin++;
1335 }
1336 }
1337 for (const bNodeSocket *socket : node.output_sockets()) {
1338 if (socket->is_visible()) {
1339 totout++;
1340 }
1341 }
1342
1343 const float dy = NODE_DY * 0.5f;
1344 const float height = dy * std::max({totin, totout, 2}) + BASIS_RAD * 2.0f;
1345 /* This offset for Y values keeps the text in the same spot as in non-collapsed nodes. */
1346 const float offset = NODE_DY * -0.5f;
1347
1348 node.runtime->draw_bounds.xmin = loc.x;
1349 node.runtime->draw_bounds.xmax = loc.x + NODE_WIDTH(node);
1350 node.runtime->draw_bounds.ymax = loc.y + height * 0.5f + offset;
1351 node.runtime->draw_bounds.ymin = loc.y - height * 0.5f + offset;
1352
1353 /* Output sockets. */
1354 {
1355 const float x = node.runtime->draw_bounds.xmax;
1356 float y = loc.y + dy * float(totout - 1) * 0.5f + offset;
1357 for (bNodeSocket *socket : node.output_sockets()) {
1358 if (socket->is_visible()) {
1359 socket->runtime->location = {x, y};
1360 y -= dy;
1361 }
1362 }
1363 }
1364
1365 /* Input sockets. */
1366 {
1367 const float x = node.runtime->draw_bounds.xmin;
1368 float y = loc.y + dy * float(totin - 1) * 0.5f + offset;
1369 for (bNodeSocket *socket : node.input_sockets()) {
1370 if (socket->is_visible()) {
1371 socket->runtime->location = {x, y};
1372 y -= dy;
1373 }
1374 }
1375 }
1376
1377 /* Set the block bounds to clip mouse events from underlying nodes.
1378 * Add a margin for sockets on each side. */
1379 block_bounds_set_explicit(&block,
1380 node.runtime->draw_bounds.xmin - NODE_SOCKSIZE,
1381 node.runtime->draw_bounds.ymin,
1382 node.runtime->draw_bounds.xmax + NODE_SOCKSIZE,
1383 node.runtime->draw_bounds.ymax);
1384}
1385
1386static int node_get_colorid(TreeDrawContext &tree_draw_ctx, const bNode &node)
1387{
1388 const int nclass = (node.typeinfo->ui_class == nullptr) ? node.typeinfo->nclass :
1389 node.typeinfo->ui_class(&node);
1390 switch (nclass) {
1391 case NODE_CLASS_INPUT:
1392 return TH_NODE_INPUT;
1393 case NODE_CLASS_OUTPUT: {
1394 if (node.type_legacy == GEO_NODE_VIEWER) {
1395 return &node == tree_draw_ctx.active_geometry_nodes_viewer ? TH_NODE_OUTPUT : TH_NODE;
1396 }
1397 const bool is_output_node = (node.flag & NODE_DO_OUTPUT) ||
1398 (node.type_legacy == CMP_NODE_OUTPUT_FILE);
1399 return is_output_node ? TH_NODE_OUTPUT : TH_NODE;
1400 }
1402 return TH_NODE_CONVERTER;
1404 return TH_NODE_COLOR;
1406 return TH_NODE_VECTOR;
1408 return TH_NODE_FILTER;
1409 case NODE_CLASS_GROUP:
1410 return TH_NODE_GROUP;
1412 return TH_NODE_INTERFACE;
1413 case NODE_CLASS_MATTE:
1414 return TH_NODE_MATTE;
1415 case NODE_CLASS_DISTORT:
1416 return TH_NODE_DISTORT;
1417 case NODE_CLASS_TEXTURE:
1418 return TH_NODE_TEXTURE;
1419 case NODE_CLASS_SHADER:
1420 return TH_NODE_SHADER;
1421 case NODE_CLASS_SCRIPT:
1422 return TH_NODE_SCRIPT;
1424 return TH_NODE_GEOMETRY;
1426 return TH_NODE_ATTRIBUTE;
1427 case NODE_CLASS_LAYOUT:
1428 return node.is_frame() ? TH_NODE_FRAME : TH_NODE;
1429 default:
1430 return TH_NODE;
1431 }
1432}
1433
1434static void node_draw_mute_line(const bContext &C,
1435 const View2D &v2d,
1436 const SpaceNode &snode,
1437 const bNode &node)
1438{
1440
1441 for (const bNodeInternalLink &internal_link : node.internal_links()) {
1442 bNodeLink link{};
1443 link.fromnode = const_cast<bNode *>(&node);
1444 link.tonode = const_cast<bNode *>(&node);
1445 link.fromsock = internal_link.in;
1446 link.tosock = internal_link.out;
1447 link.flag |= NODE_LINK_VALID;
1448 if (internal_link.in->is_multi_input()) {
1449 for (const bNodeLink *connected_link : internal_link.in->directly_linked_links()) {
1450 if (!connected_link->fromnode->is_dangling_reroute()) {
1451 link.multi_input_sort_id = connected_link->multi_input_sort_id;
1452 break;
1453 }
1454 }
1455 }
1456 if (!bke::node_link_is_hidden(link)) {
1457 node_draw_link_bezier(C, v2d, snode, link, TH_WIRE_INNER, TH_WIRE_INNER, TH_WIRE, false);
1458 }
1459 }
1460
1462}
1463
1465 const int socket_index_in_tree,
1466 const float2 location,
1467 const float2 size)
1468{
1469 /* Ideally sockets themselves should be buttons, but they aren't currently. So add an invisible
1470 * button on top of them for the tooltip. */
1471 ui::Button *but = uiDefIconBut(&block,
1473 ICON_NONE,
1474 location.x - size.x / 2.0f,
1475 location.y - size.y / 2.0f,
1476 size.x,
1477 size.y,
1478 nullptr,
1479 0,
1480 0,
1481 std::nullopt);
1482
1483 button_func_tooltip_custom_set(
1484 but,
1485 [](bContext &C, ui::TooltipData &tip, ui::Button *but, void *argN) {
1486 const SpaceNode &snode = *CTX_wm_space_node(&C);
1487 const bNodeTree &ntree = *snode.edittree;
1488 const int index_in_tree = POINTER_AS_INT(argN);
1489 ntree.ensure_topology_cache();
1490 const bNodeSocket &socket = *ntree.all_sockets()[index_in_tree];
1491 build_socket_tooltip(tip, C, but, ntree, socket);
1492 },
1493 POINTER_FROM_INT(socket_index_in_tree),
1494 nullptr);
1495}
1496
1497static const float virtual_node_socket_outline_color[4] = {0.5, 0.5, 0.5, 1.0};
1498
1499static void node_socket_outline_color_get(const bool selected,
1500 const int socket_type,
1501 float r_outline_color[4])
1502{
1503 /* Explicitly use the node editor theme for the outline color to ensure consistency even when
1504 * sockets are drawn in other editors.
1505 */
1506 if (selected) {
1508 }
1509 else if (socket_type == SOCK_CUSTOM) {
1510 /* Until there is a better place for per socket color,
1511 * the outline color for virtual sockets is set here. */
1513 }
1514 else {
1516 r_outline_color[3] = 1.0f;
1517 }
1518}
1519
1521 const bNodeTree &ntree,
1522 PointerRNA &node_ptr,
1523 const bNodeSocket &sock,
1524 float r_color[4])
1525{
1526 if (!sock.typeinfo->draw_color) {
1527 /* Fall back to the simple variant. If not defined either, fall back to a magenta color. */
1528 if (sock.typeinfo->draw_color_simple) {
1529 sock.typeinfo->draw_color_simple(sock.typeinfo, r_color);
1530 }
1531 else {
1532 copy_v4_v4(r_color, float4(1.0f, 0.0f, 1.0f, 1.0f));
1533 }
1534 return;
1535 }
1536
1537 BLI_assert(RNA_struct_is_a(node_ptr.type, RNA_Node));
1539 &const_cast<ID &>(ntree.id), RNA_NodeSocket, &const_cast<bNodeSocket &>(sock));
1540 sock.typeinfo->draw_color(const_cast<bContext *>(&C), &ptr, &node_ptr, r_color);
1541}
1542
1544{
1545 uiLayoutSetTooltipCustomFunc(
1546 &layout,
1547 [](bContext &C, ui::TooltipData &tip, ui::Button *but, void *argN) {
1548 const SpaceNode &snode = *CTX_wm_space_node(&C);
1549 const bNodeTree &ntree = *snode.edittree;
1550 const int index_in_tree = POINTER_AS_INT(argN);
1551 ntree.ensure_topology_cache();
1552 const bNodeSocket &socket = *ntree.all_sockets()[index_in_tree];
1553 build_socket_tooltip(tip, C, but, ntree, socket);
1554 },
1555 POINTER_FROM_INT(sock.index_in_tree()),
1556 nullptr,
1557 nullptr);
1558}
1559
1560void node_socket_add_tooltip(const bNodeTree &ntree, const bNodeSocket &sock, ui::Layout &layout)
1561{
1562 struct SocketTooltipData {
1563 const bNodeTree *ntree;
1564 const bNodeSocket *socket;
1565 };
1566
1567 SocketTooltipData *data = MEM_new_zeroed<SocketTooltipData>(__func__);
1568 data->ntree = &ntree;
1569 data->socket = &sock;
1570
1571 uiLayoutSetTooltipCustomFunc(
1572 &layout,
1573 [](bContext &C, ui::TooltipData &tip, ui::Button *but, void *argN) {
1574 SocketTooltipData *data = static_cast<SocketTooltipData *>(argN);
1575 build_socket_tooltip(tip, C, but, *data->ntree, *data->socket);
1576 },
1577 data,
1580}
1581
1582#define NODE_SOCKET_OUTLINE U.pixelsize
1583
1584void node_socket_draw(bNodeSocket *sock, const rcti *rect, const float color[4], float scale)
1585{
1586 const float radius = NODE_SOCKSIZE * scale;
1587 const float2 center = {BLI_rcti_cent_x_fl(rect), BLI_rcti_cent_y_fl(rect)};
1588 const rctf draw_rect = {
1589 center.x - radius,
1590 center.x + radius,
1591 center.y - radius,
1592 center.y + radius,
1593 };
1594
1595 ColorTheme4f outline_color;
1596 node_socket_outline_color_get(sock->flag & SELECT, sock->type, outline_color);
1597
1598 node_draw_nodesocket(&draw_rect,
1599 color,
1600 outline_color,
1602 sock->display_shape,
1603 1.0 / scale);
1604}
1605
1607#define NODE_TREE_SCALE_SMALL 0.2f
1608
1610static float node_tree_view_scale(const SpaceNode &snode)
1611{
1612 return (1.0f / snode.runtime->aspect) * UI_SCALE_FAC;
1613}
1614
1615/* Some elements of the node tree like labels or node sockets are hardly visible when zoomed
1616 * out and can slow down the drawing quite a bit.
1617 * This function can be used to check if it's worth to draw those details and return
1618 * early. */
1619static bool draw_node_details(const SpaceNode &snode)
1620{
1622}
1623
1625{
1626 GPUVertFormat *format = immVertexFormat();
1627 uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
1628
1630
1631 /* Drawing the checkerboard. */
1632 const float checker_dark = UI_ALPHA_CHECKER_DARK / 255.0f;
1633 const float checker_light = UI_ALPHA_CHECKER_LIGHT / 255.0f;
1634 immUniform4f("color1", checker_dark, checker_dark, checker_dark, 1.0f);
1635 immUniform4f("color2", checker_light, checker_light, checker_light, 1.0f);
1636 immUniform1i("size", 8);
1637 immRectf(pos, rect->xmin, rect->ymin, rect->xmax, rect->ymax);
1639}
1640
1641/* Not a callback. */
1642static void node_draw_preview(const Scene *scene, const ImBuf *preview, const rctf *prv)
1643{
1644 float xrect = BLI_rctf_size_x(prv);
1645 float yrect = BLI_rctf_size_y(prv);
1646 float xscale = xrect / float(preview->x);
1647 float yscale = yrect / float(preview->y);
1648 float scale;
1649
1650 /* Uniform scale and offset. */
1651 rctf draw_rect = *prv;
1652 if (xscale < yscale) {
1653 float offset = 0.5f * (yrect - float(preview->y) * xscale);
1654 draw_rect.ymin += offset;
1655 draw_rect.ymax -= offset;
1656 scale = xscale;
1657 }
1658 else {
1659 float offset = 0.5f * (xrect - float(preview->x) * yscale);
1660 draw_rect.xmin += offset;
1661 draw_rect.xmax -= offset;
1662 scale = yscale;
1663 }
1664
1665 node_draw_preview_background(&draw_rect);
1666
1668 /* Pre-multiply graphics. */
1670
1671 ED_draw_imbuf(preview,
1672 draw_rect.xmin,
1673 draw_rect.ymin,
1674 false,
1675 &scene->view_settings,
1676 &scene->display_settings,
1677 scale,
1678 scale);
1679
1681
1682 float black[4] = {0.0f, 0.0f, 0.0f, 1.0f};
1683 draw_roundbox_corner_set(ui::CNR_ALL);
1684 const float outline_width = 1.0f;
1685 draw_rect.xmin -= outline_width;
1686 draw_rect.xmax += outline_width;
1687 draw_rect.ymin -= outline_width;
1688 draw_rect.ymax += outline_width;
1689 ui::draw_roundbox_4fv(&draw_rect, false, BASIS_RAD / 2, black);
1690}
1691
1692/* Common handle function for operator buttons that need to select the node first. */
1693static void node_toggle_button_cb(bContext *C, void *node_argv, void *op_argv)
1694{
1695 SpaceNode &snode = *CTX_wm_space_node(C);
1696 bNodeTree &node_tree = *snode.edittree;
1697 bNode &node = *node_tree.node_by_id(POINTER_AS_INT(node_argv));
1698 const char *opname = static_cast<const char *>(op_argv);
1699
1700 /* Select & activate only the button's node. */
1702
1703 WM_operator_name_call(C, opname, wm::OpCallContext::InvokeDefault, nullptr, nullptr);
1704}
1705
1706static void node_draw_shadow(const SpaceNode &snode,
1707 const bNode &node,
1708 const float radius,
1709 const float alpha)
1710{
1711 const rctf &rct = node.runtime->draw_bounds;
1712 draw_roundbox_corner_set(ui::CNR_ALL);
1713
1714 const float shadow_width = 0.4f * U.widget_unit;
1715 const float shadow_alpha = 0.2f * alpha;
1716
1717 ui::draw_dropshadow(&rct, radius, shadow_width, snode.runtime->aspect, shadow_alpha);
1718
1719 /* Outline emphasis. Slight darkening _inside_ the outline. */
1720 const float color[4] = {0.0f, 0.0f, 0.0f, 0.4f};
1721 rctf rect{};
1722 rect.xmin = rct.xmin - 0.5f;
1723 rect.xmax = rct.xmax + 0.5f;
1724 rect.ymin = rct.ymin - 0.5f;
1725 rect.ymax = rct.ymax + 0.5f;
1726 ui::draw_roundbox_4fv(&rect, false, radius + 0.5f, color);
1727}
1728
1729/* Node groups draw two "copies" of the node body underneath, just narrower and dimmer. */
1731 const bNode &node,
1732 const rctf &rect,
1733 const float radius,
1734 const float color[4])
1735{
1736 if (node.type_legacy != NODE_GROUP) {
1737 return;
1738 }
1739
1740 /* How far it extends down and narrows. */
1741 const bool is_selected = node.is_selected();
1742 const bool is_collapsed = node.flag & NODE_COLLAPSED;
1743 const float offset_x = 3.6f * UI_SCALE_FAC;
1744 const float offset_y = 2.4f * UI_SCALE_FAC;
1745 const float shadow_width = 0.2f * U.widget_unit;
1746 const float shadow_alpha = is_selected ? 0.4f : 0.2f;
1747 const float dim_collapsed = is_collapsed ? 0.2f : 0.0f;
1748
1749 const float outline_width = is_selected ? 1.0f : 0.5f;
1750 float outline_color[4];
1752
1753 if (is_selected) {
1754 ui::theme::get_color_4fv((node.flag & NODE_ACTIVE) ? TH_ACTIVE : TH_SELECT, outline_color);
1755 }
1756
1758
1759 /* Start with the last copy. */
1760 {
1761 const rctf rect_group_front = {
1762 rect.xmin + offset_x * 4,
1763 rect.xmax - offset_x * 4,
1764 rect.ymin - (offset_y * 2) - U.pixelsize,
1765 rect.ymin - offset_y + (U.pixelsize * 2),
1766 };
1767
1768 const rctf rect_group_front_shadow = {
1769 rect_group_front.xmin + outline_width,
1770 rect_group_front.xmax - outline_width,
1771 rect_group_front.ymin + outline_width,
1772 rect_group_front.ymax - outline_width,
1773 };
1774
1775 ui::draw_dropshadow(&rect_group_front_shadow,
1776 radius + outline_width,
1777 shadow_width,
1778 snode.runtime->aspect,
1779 shadow_alpha);
1780
1781 /* Use the node color (or header color when collapsed) but slightly darker. */
1782 float fill_color_front[4], outline_color_front[4];
1783 copy_v4_v4(fill_color_front, color);
1784 mul_v3_fl(fill_color_front, 0.8f - dim_collapsed);
1785
1786 copy_v4_v4(outline_color_front, outline_color);
1787 mul_v3_fl(outline_color_front, (is_selected ? 0.5f : 1.0f) - dim_collapsed);
1788
1789 ui::draw_roundbox_4fv_ex(&rect_group_front,
1790 fill_color_front,
1791 nullptr,
1792 0.0f,
1793 outline_color_front,
1794 outline_width,
1795 radius);
1796 }
1797
1798 /* Draw the first copy in the front. */
1799 {
1800 const rctf rect_group_back = {
1801 rect.xmin + offset_x * 2,
1802 rect.xmax - offset_x * 2,
1803 rect.ymin - offset_y - U.pixelsize,
1804 rect.ymin + (U.pixelsize * 2),
1805 };
1806
1807 const rctf rect_group_back_shadow = {
1808 rect_group_back.xmin + outline_width,
1809 rect_group_back.xmax - outline_width,
1810 rect_group_back.ymin + outline_width,
1811 rect_group_back.ymax - outline_width,
1812 };
1813
1814 ui::draw_dropshadow(&rect_group_back_shadow,
1815 radius + outline_width,
1816 shadow_width,
1817 snode.runtime->aspect,
1818 shadow_alpha);
1819
1820 float fill_color_back[4], outline_color_back[4];
1821 copy_v4_v4(fill_color_back, color);
1822 mul_v3_fl(fill_color_back, 0.9f - dim_collapsed);
1823
1824 copy_v4_v4(outline_color_back, outline_color);
1825 mul_v3_fl(outline_color_back, (is_selected ? 0.7f : 1.1f) - dim_collapsed);
1826
1827 ui::draw_roundbox_4fv_ex(&rect_group_back,
1828 fill_color_back,
1829 nullptr,
1830 0.0f,
1831 outline_color_back,
1832 outline_width,
1833 radius);
1834 }
1835}
1836
1837static void node_draw_socket(const bContext &C,
1838 const bNodeTree &ntree,
1839 const bNode &node,
1840 PointerRNA &node_ptr,
1841 ui::Block &block,
1842 const bNodeSocket &sock,
1843 const float outline_thickness,
1844 const bool selected,
1845 const float aspect)
1846{
1847 const float half_width = NODE_SOCKSIZE;
1848
1849 const bool multi_socket = (sock.flag & SOCK_MULTI_INPUT) && !(node.flag & NODE_COLLAPSED);
1850 float half_height = multi_socket ? node_socket_calculate_height(sock) : half_width;
1851
1852 ColorTheme4f socket_color;
1853 ColorTheme4f outline_color;
1854 node_socket_color_get(C, ntree, node_ptr, sock, socket_color);
1855 node_socket_outline_color_get(selected, sock.type, outline_color);
1856
1857 const float2 socket_location = sock.runtime->location;
1858
1859 const rctf rect = {
1860 socket_location.x - half_width,
1861 socket_location.x + half_width,
1862 socket_location.y - half_height,
1863 socket_location.y + half_height,
1864 };
1865
1867 &rect, socket_color, outline_color, outline_thickness, sock.display_shape, aspect);
1868
1870 block, sock.index_in_tree(), socket_location, float2(2.0f * half_width, 2.0f * half_height));
1871}
1872
1873static void node_draw_sockets(const bContext &C,
1874 ui::Block &block,
1875 const SpaceNode &snode,
1876 const bNodeTree &ntree,
1877 const bNode &node)
1878{
1879 if (!draw_node_details(snode)) {
1880 return;
1881 }
1882
1883 if (node.input_sockets().is_empty() && node.output_sockets().is_empty()) {
1884 return;
1885 }
1886
1888 const_cast<ID *>(&ntree.id), RNA_Node, const_cast<bNode *>(&node));
1889
1890 const float outline_thickness = NODE_SOCKET_OUTLINE;
1891
1893 /* Input sockets. */
1894 for (const bNodeSocket *sock : node.input_sockets()) {
1895 if (!sock->is_icon_visible()) {
1896 continue;
1897 }
1898 const bool selected = (sock->flag & SELECT);
1900 C, ntree, node, nodeptr, block, *sock, outline_thickness, selected, snode.runtime->aspect);
1901 }
1902
1903 /* Output sockets. */
1904 for (const bNodeSocket *sock : node.output_sockets()) {
1905 if (!sock->is_icon_visible()) {
1906 continue;
1907 }
1908 const bool selected = (sock->flag & SELECT);
1910 C, ntree, node, nodeptr, block, *sock, outline_thickness, selected, snode.runtime->aspect);
1911 }
1913}
1914
1915static void node_panel_toggle_button_cb(bContext *C, void *panel_state_argv, void *ntree_argv)
1916{
1917 Main *bmain = CTX_data_main(C);
1918 bNodePanelState *panel_state = static_cast<bNodePanelState *>(panel_state_argv);
1919 bNodeTree *ntree = static_cast<bNodeTree *>(ntree_argv);
1920
1921 panel_state->flag ^= NODE_PANEL_COLLAPSED;
1922
1923 BKE_main_ensure_invariants(*bmain, ntree->id);
1924}
1925
1926/* Draw panel backgrounds first, so other node elements can be rendered on top. */
1928{
1930
1931 float panel_color[4];
1933 /* Increase contrast in nodes a bit. */
1934 panel_color[3] *= 1.5f;
1935 const rctf &draw_bounds = node.runtime->draw_bounds;
1936
1937 const nodes::PanelDeclaration *final_panel_decl = nullptr;
1938
1939 const nodes::NodeDeclaration &node_decl = *node.declaration();
1940 for (const int panel_i : node_decl.panels.index_range()) {
1941 const nodes::PanelDeclaration &panel_decl = *node_decl.panels[panel_i];
1942 const bke::bNodePanelRuntime &panel_runtime = node.runtime->panels[panel_i];
1943 if (!panel_runtime.content_extent.has_value()) {
1944 continue;
1945 }
1946 const rctf content_rect = {draw_bounds.xmin,
1947 draw_bounds.xmax,
1948 panel_runtime.content_extent->min_y,
1949 panel_runtime.content_extent->max_y};
1951 ui::draw_roundbox_4fv(&content_rect, true, BASIS_RAD, panel_color);
1952 if (panel_runtime.content_extent->fill_node_end) {
1953 final_panel_decl = &panel_decl;
1954 }
1955 }
1956 if (final_panel_decl) {
1957 const bke::bNodePanelRuntime &final_panel_runtime =
1958 node.runtime->panels[final_panel_decl->index];
1959 const rctf content_rect = {draw_bounds.xmin,
1960 draw_bounds.xmax,
1961 draw_bounds.ymin,
1962 final_panel_runtime.content_extent->min_y};
1964 const int repeats = final_panel_decl->depth() + 1;
1965 for ([[maybe_unused]] const int i : IndexRange(repeats)) {
1966 ui::draw_roundbox_4fv(&content_rect, true, BASIS_RAD, panel_color);
1967 }
1968 }
1969}
1970
1977 const nodes::PanelDeclaration &panel_decl)
1978{
1979 for (const nodes::ItemDeclaration *item_decl : panel_decl.items) {
1980 if (const auto *socket_decl = dynamic_cast<const nodes::SocketDeclaration *>(item_decl)) {
1981 if (socket_decl->in_out == SOCK_OUT) {
1982 return false;
1983 }
1984 const bNodeSocket &socket = node.socket_by_decl(*socket_decl);
1985 if (!socket.is_inactive()) {
1986 return false;
1987 }
1988 }
1989 else if (const auto *sub_panel_decl = dynamic_cast<const nodes::PanelDeclaration *>(item_decl))
1990 {
1991 if (!panel_has_only_inactive_inputs(node, *sub_panel_decl)) {
1992 return false;
1993 }
1994 }
1995 }
1996 return true;
1997}
1998
1999static void node_draw_panels(bNodeTree &ntree, const bNode &node, ui::Block &block)
2000{
2002 const rctf &draw_bounds = node.runtime->draw_bounds;
2003
2004 const nodes::NodeDeclaration &node_decl = *node.declaration();
2005 for (const int panel_i : node_decl.panels.index_range()) {
2006 const nodes::PanelDeclaration &panel_decl = *node_decl.panels[panel_i];
2007 const bke::bNodePanelRuntime &panel_runtime = node.runtime->panels[panel_i];
2008 bNodeSocket *input_socket = panel_runtime.input_socket;
2009 const bNodePanelState &panel_state = node.panel_states_array[panel_i];
2010 if (!panel_runtime.header_center_y.has_value()) {
2011 continue;
2012 }
2013 const bool only_inactive_inputs = panel_has_only_inactive_inputs(node, panel_decl);
2014 const bool panel_is_inactive = node.is_muted() || only_inactive_inputs;
2015
2016 const rctf header_rect = {draw_bounds.xmin,
2017 draw_bounds.xmax,
2018 *panel_runtime.header_center_y - NODE_DYS,
2019 *panel_runtime.header_center_y + NODE_DYS};
2020 block_emboss_set(&block, ui::EmbossType::None);
2021
2022 /* Invisible button covering the entire header for collapsing/expanding. */
2023 const int header_but_margin = NODE_MARGIN_X / 3;
2024 ui::Button *toggle_action_but = uiDefIconBut(
2025 &block,
2027 ICON_NONE,
2028 header_rect.xmin + header_but_margin,
2029 header_rect.ymin,
2030 std::max(int(header_rect.xmax - header_rect.xmin - 2 * header_but_margin), 0),
2031 header_rect.ymax - header_rect.ymin,
2032 nullptr,
2033 0.0f,
2034 0.0f,
2035 panel_decl.description.c_str());
2036 button_flag_disable(toggle_action_but, ui::BUT_UNDO);
2037 button_func_pushed_state_set(toggle_action_but, [&panel_state](const ui::Button &) {
2038 return panel_state.is_collapsed();
2039 });
2040 button_func_set(toggle_action_but,
2042 const_cast<bNodePanelState *>(&panel_state),
2043 &ntree);
2044
2045 /* Collapse/expand icon. */
2046 const int but_size = U.widget_unit * 0.8f;
2047 const int but_padding = NODE_MARGIN_X / 4;
2048 int offsetx = draw_bounds.xmin + (NODE_MARGIN_X / 3);
2049 uiDefIconBut(&block,
2051 panel_state.is_collapsed() ? ICON_RIGHTARROW : ICON_DOWNARROW_HLT,
2052 offsetx,
2053 *panel_runtime.header_center_y - but_size / 2,
2054 but_size,
2055 but_size,
2056 nullptr,
2057 0.0f,
2058 0.0f,
2059 "");
2060 offsetx += but_size + but_padding;
2061
2062 block_emboss_set(&block, ui::EmbossType::Emboss);
2063
2064 /* Panel toggle. */
2065 if (input_socket && !input_socket->is_logically_linked()) {
2066 PointerRNA socket_ptr = RNA_pointer_create_discrete(&ntree.id, RNA_NodeSocket, input_socket);
2067 ui::Button *panel_toggle_but = uiDefButR(&block,
2069 "",
2070 offsetx,
2071 int(*panel_runtime.header_center_y - NODE_DYS),
2072 UI_UNIT_X,
2073 NODE_DY,
2074 &socket_ptr,
2075 "default_value",
2076 0,
2077 0,
2078 0,
2079 "");
2080 button_func_tooltip_custom_set(
2081 panel_toggle_but,
2082 [](bContext &C, ui::TooltipData &tip, ui::Button *but, void *argN) {
2083 const SpaceNode &snode = *CTX_wm_space_node(&C);
2084 const bNodeTree &ntree = *snode.edittree;
2085 const int index_in_tree = POINTER_AS_INT(argN);
2086 ntree.ensure_topology_cache();
2087 const bNodeSocket &socket = *ntree.all_sockets()[index_in_tree];
2088 build_socket_tooltip(tip, C, but, ntree, socket);
2089 },
2090 POINTER_FROM_INT(input_socket->index_in_tree()),
2091 nullptr);
2092 if (panel_is_inactive) {
2093 button_flag_enable(panel_toggle_but, ui::BUT_INACTIVE);
2094 }
2095 offsetx += UI_UNIT_X;
2096 }
2097
2098 /* Panel label. */
2099 const char *panel_translation_context = (panel_decl.translation_context.has_value() ?
2100 panel_decl.translation_context->c_str() :
2101 nullptr);
2102 const float left_padding = (input_socket == nullptr) ? 40.0f : 60.0f;
2103 ui::Button *label_but = uiDefBut(
2104 &block,
2106 CTX_IFACE_(panel_translation_context, panel_decl.name.ref()),
2107 offsetx,
2108 int(*panel_runtime.header_center_y - NODE_DYS),
2109 short(draw_bounds.xmax - draw_bounds.xmin - (left_padding * UI_SCALE_FAC)),
2110 NODE_DY,
2111 nullptr,
2112 0,
2113 0,
2114 "");
2115
2116 if (panel_is_inactive) {
2117 button_flag_enable(label_but, ui::BUT_INACTIVE);
2118 }
2119 }
2120}
2121
2122template<typename WarningsRange>
2123static nodes::NodeWarningType node_error_highest_priority(const WarningsRange &warnings)
2124{
2125 int highest_priority = 0;
2127 for (const auto &warning : warnings) {
2128 const int priority = node_warning_type_severity(warning.type);
2129 if (priority > highest_priority) {
2130 highest_priority = priority;
2131 highest_priority_type = warning.type;
2132 }
2133 }
2134 return highest_priority_type;
2135}
2136
2137static std::string node_errors_tooltip_fn(const Span<nodes::NodeWarning> warnings)
2138{
2139 std::string complete_string;
2140
2141 for (const nodes::NodeWarning &warning : warnings.drop_back(1)) {
2142 complete_string += warning.message;
2143 /* Adding the period is not ideal for multi-line messages, but it is consistent
2144 * with other tooltip implementations in Blender, so it is added here. */
2145 complete_string += '.';
2146 complete_string += '\n';
2147 }
2148
2149 /* Let the tooltip system automatically add the last period. */
2150 complete_string += warnings.last().message;
2151
2152 return complete_string;
2153}
2154
2155#define NODE_HEADER_ICON_SIZE (0.8f * U.widget_unit)
2156
2158 const rctf &rect,
2159 const int icon,
2160 float &icon_offset,
2161 const char *tooltip = nullptr)
2162{
2163 icon_offset -= NODE_HEADER_ICON_SIZE;
2164 block_emboss_set(&block, ui::EmbossType::None);
2165 ui::Button *but = uiDefIconBut(&block,
2167 icon,
2168 icon_offset,
2169 rect.ymax - NODE_DY,
2171 UI_UNIT_Y,
2172 nullptr,
2173 0,
2174 0,
2175 tooltip);
2176 block_emboss_set(&block, ui::EmbossType::Emboss);
2177 return but;
2178}
2179
2180static void node_add_error_message_button(const TreeDrawContext &tree_draw_ctx,
2181 const bNodeTree &ntree,
2182 const bNode &node,
2183 ui::Block &block,
2184 const rctf &rect,
2185 float &icon_offset)
2186{
2187 if (ELEM(ntree.type, NTREE_GEOMETRY, NTREE_COMPOSIT)) {
2189 const bNodeTreeZones *zones = node.owner_tree().zones();
2190 if (!zones) {
2191 return nullptr;
2192 }
2193 const bNodeTreeZone *zone = zones->get_zone_by_node(node.identifier);
2194 if (zone && ELEM(node.identifier, zone->input_node_id, zone->output_node_id)) {
2195 zone = zone->parent_zone;
2196 }
2197 return tree_draw_ctx.tree_logs.get_main_tree_log(zone);
2198 }();
2199
2200 Span<nodes::NodeWarning> warnings;
2201 if (geo_tree_log) {
2202 nodes::eval_log::NodeLog *node_log = geo_tree_log->find_node_log(node.identifier);
2203 if (node_log != nullptr) {
2204 warnings = node_log->warnings;
2205 }
2206 }
2207 if (warnings.is_empty()) {
2208 return;
2209 }
2210
2211 const nodes::NodeWarningType display_type = node_error_highest_priority(warnings);
2212
2214 block, rect, nodes::node_warning_type_icon(display_type), icon_offset);
2215 button_func_quick_tooltip_set(
2216 but, [warnings = Array<nodes::NodeWarning>(warnings)](const ui::Button * /*but*/) {
2217 return node_errors_tooltip_fn(warnings);
2218 });
2219 return;
2220 }
2221 if (ntree.type == NTREE_SHADER) {
2222 const VectorSet<nodes::NodeWarning> *errors = tree_draw_ctx.shader_node_errors.lookup_ptr(
2223 node.identifier);
2224 if (!errors) {
2225 return;
2226 }
2227 if (errors->is_empty()) {
2228 return;
2229 }
2230 const nodes::NodeWarningType display_type = node_error_highest_priority(*errors);
2232 block, rect, nodes::node_warning_type_icon(display_type), icon_offset);
2233 button_func_quick_tooltip_set(but, [errors = *errors](const ui::Button * /*but*/) {
2234 Vector<std::string> tooltip_lines;
2235 for (const nodes::NodeWarning &error : errors) {
2236 std::string message = error.message;
2237 if (message.empty()) {
2238 continue;
2239 }
2240 if (!message.ends_with(".")) {
2241 message += ".";
2242 }
2243 tooltip_lines.append(std::move(message));
2244 }
2245 return fmt::format("{}", fmt::join(tooltip_lines, "\n"));
2246 });
2247 }
2248}
2249
2250static std::optional<std::chrono::nanoseconds> node_get_execution_time(
2251 const TreeDrawContext &tree_draw_ctx, const SpaceNode &snode, const bNode &node)
2252{
2253 const bNodeTree &ntree = *snode.edittree;
2254 if (!ELEM(ntree.type, NTREE_GEOMETRY, NTREE_COMPOSIT)) {
2255 return std::nullopt;
2256 }
2257
2259 const bNodeTreeZones *zones = ntree.zones();
2260 if (!zones) {
2261 return nullptr;
2262 }
2263 const bNodeTreeZone *zone = zones->get_zone_by_node(node.identifier);
2264 if (zone && ELEM(node.identifier, zone->input_node_id, zone->output_node_id)) {
2265 zone = zone->parent_zone;
2266 }
2267 return tree_draw_ctx.tree_logs.get_main_tree_log(zone);
2268 }();
2269
2270 if (tree_log == nullptr) {
2271 return std::nullopt;
2272 }
2273 if (node.is_group_output()) {
2274 return tree_log->execution_time;
2275 }
2276 if (node.is_type("CompositorNodeViewer"_ustr)) {
2277 /* Don't display execution times on compositor viewer nodes for consistency with Geometry
2278 * Nodes. */
2279 return std::nullopt;
2280 }
2281 if (node.is_frame()) {
2282 /* Could be cached in the future if this recursive code turns out to be slow. */
2283 std::chrono::nanoseconds run_time{0};
2284 bool found_node = false;
2285
2286 for (const bNode *tnode : node.direct_children_in_frame()) {
2287 if (tnode->is_frame()) {
2288 std::optional<std::chrono::nanoseconds> sub_frame_run_time = node_get_execution_time(
2289 tree_draw_ctx, snode, *tnode);
2290 if (sub_frame_run_time.has_value()) {
2291 run_time += *sub_frame_run_time;
2292 found_node = true;
2293 }
2294 }
2295 else {
2296 if (const nodes::eval_log::NodeLog *node_log = tree_log->find_node_log(tnode->identifier))
2297 {
2298 found_node = true;
2299 run_time += node_log->execution_time;
2300 }
2301 }
2302 }
2303 if (found_node) {
2304 return run_time;
2305 }
2306 return std::nullopt;
2307 }
2308 if (const nodes::eval_log::NodeLog *node_log = tree_log->find_node_log(node.identifier)) {
2309 return node_log->execution_time;
2310 }
2311 return std::nullopt;
2312}
2313
2314static std::string node_get_execution_time_label(TreeDrawContext &tree_draw_ctx,
2315 const SpaceNode &snode,
2316 const bNode &node)
2317{
2318 const std::optional<std::chrono::nanoseconds> exec_time = node_get_execution_time(
2319 tree_draw_ctx, snode, node);
2320
2321 if (!exec_time.has_value()) {
2322 return std::string("");
2323 }
2324
2325 const uint64_t exec_time_us =
2326 std::chrono::duration_cast<std::chrono::microseconds>(*exec_time).count();
2327
2328 /* Don't show time if execution time is 0 microseconds. */
2329 if (exec_time_us == 0) {
2330 return std::string("-");
2331 }
2332 if (exec_time_us < 100) {
2333 return std::string("< 0.1 ms");
2334 }
2335
2336 int precision = 0;
2337 /* Show decimal if value is below 1ms */
2338 if (exec_time_us < 1000) {
2339 precision = 2;
2340 }
2341 else if (exec_time_us < 10000) {
2342 precision = 1;
2343 }
2344
2345 std::stringstream stream;
2346 stream << std::fixed << std::setprecision(precision) << (exec_time_us / 1000.0f);
2347 return stream.str() + " ms";
2348}
2349
2353
2354static std::string named_attribute_tooltip(bContext * /*C*/, void *argN, const StringRef /*tip*/)
2355{
2356 NamedAttributeTooltipArg &arg = *static_cast<NamedAttributeTooltipArg *>(argN);
2357
2358 fmt::memory_buffer buf;
2359 fmt::format_to(fmt::appender(buf), "{}", TIP_("Accessed named attributes:"));
2360 fmt::format_to(fmt::appender(buf), "\n");
2361
2362 struct NameWithUsage {
2363 StringRefNull name;
2365 };
2366
2367 Vector<NameWithUsage> sorted_used_attribute;
2368 for (auto &&item : arg.usage_by_attribute.items()) {
2369 sorted_used_attribute.append({item.key, item.value});
2370 }
2371 std::ranges::sort(sorted_used_attribute, [](const NameWithUsage &a, const NameWithUsage &b) {
2372 return BLI_strcasecmp_natural(a.name.c_str(), b.name.c_str()) < 0;
2373 });
2374
2375 for (const NameWithUsage &attribute : sorted_used_attribute) {
2376 const StringRefNull name = attribute.name;
2378 fmt::format_to(fmt::appender(buf), fmt::runtime(TIP_(" \u2022 \"{}\": ")), name);
2379 Vector<std::string> usages;
2380 if (flag_is_set(usage, nodes::eval_log::NamedAttributeUsage::Read)) {
2381 usages.append(TIP_("read"));
2382 }
2383 if (flag_is_set(usage, nodes::eval_log::NamedAttributeUsage::Write)) {
2384 usages.append(TIP_("write"));
2385 }
2386 if (flag_is_set(usage, nodes::eval_log::NamedAttributeUsage::Remove)) {
2387 usages.append(TIP_("remove"));
2388 }
2389 for (const int i : usages.index_range()) {
2390 fmt::format_to(fmt::appender(buf), "{}", usages[i]);
2391 if (i < usages.size() - 1) {
2392 fmt::format_to(fmt::appender(buf), ", ");
2393 }
2394 }
2395 fmt::format_to(fmt::appender(buf), "\n");
2396 }
2397 fmt::format_to(fmt::appender(buf), "\n");
2398 fmt::format_to(
2399 fmt::appender(buf),
2400 fmt::runtime(TIP_("Attributes with these names used within the group may conflict with "
2401 "existing attributes")));
2402 return fmt::to_string(buf);
2403}
2404
2406 const Map<StringRefNull, nodes::eval_log::NamedAttributeUsage> &usage_by_attribute_name)
2407{
2408 const int attributes_num = usage_by_attribute_name.size();
2409
2410 NodeExtraInfoRow row;
2411 row.text = std::to_string(attributes_num) +
2412 (attributes_num == 1 ? RPT_(" Named Attribute") : RPT_(" Named Attributes"));
2413 row.icon = ICON_SPREADSHEET;
2415 row.tooltip_fn_arg = new NamedAttributeTooltipArg{usage_by_attribute_name};
2416 row.tooltip_fn_free_arg = [](void *arg) { delete static_cast<NamedAttributeTooltipArg *>(arg); };
2417 row.tooltip_fn_copy_arg = [](void *arg) -> void * {
2418 return new NamedAttributeTooltipArg(*static_cast<NamedAttributeTooltipArg *>(arg));
2419 };
2420 return row;
2421}
2422
2423static std::optional<NodeExtraInfoRow> node_get_accessed_attributes_row(
2424 TreeDrawContext &tree_draw_ctx, const bNode &node)
2425{
2426 nodes::eval_log::NodeTreeLog *geo_tree_log = tree_draw_ctx.tree_logs.get_main_tree_log(node);
2427 if (geo_tree_log == nullptr) {
2428 return std::nullopt;
2429 }
2430 if (ELEM(node.type_legacy,
2434 {
2435 /* Only show the overlay when the name is passed in from somewhere else. */
2436 for (const bNodeSocket *socket : node.input_sockets()) {
2437 if (STREQ(socket->name, "Name")) {
2438 if (!socket->is_directly_linked()) {
2439 return std::nullopt;
2440 }
2441 }
2442 }
2443 }
2444 geo_tree_log->ensure_used_named_attributes();
2445 nodes::eval_log::NodeLog *node_log = geo_tree_log->find_node_log(node.identifier);
2446 if (node_log == nullptr) {
2447 return std::nullopt;
2448 }
2449 if (node_log->used_named_attributes.is_empty()) {
2450 return std::nullopt;
2451 }
2453}
2454
2455static std::optional<NodeExtraInfoRow> node_get_execution_time_label_row(
2456 TreeDrawContext &tree_draw_ctx, const SpaceNode &snode, const bNode &node)
2457{
2458 NodeExtraInfoRow row;
2459 row.text = node_get_execution_time_label(tree_draw_ctx, snode, node);
2460 if (row.text.empty()) {
2461 return std::nullopt;
2462 }
2463 row.tooltip = TIP_(
2464 "The execution time from the node tree's latest evaluation. For frame and group "
2465 "nodes, the time for all sub-nodes");
2466 row.icon = ICON_PREVIEW_RANGE;
2467 return row;
2468}
2469
2471 const SpaceNode &snode,
2472 const bNode &node,
2474{
2475 if (snode.overlay.flag & SN_OVERLAY_SHOW_TIMINGS) {
2476 std::optional<NodeExtraInfoRow> row = node_get_execution_time_label_row(
2477 tree_draw_ctx, snode, node);
2478 if (row.has_value()) {
2479 rows.append(std::move(*row));
2480 }
2481 }
2482}
2483
2485 TreeDrawContext &tree_draw_ctx,
2486 const SpaceNode &snode,
2487 const bNode &node)
2488{
2490
2491 if (node.typeinfo->get_extra_info) {
2492 nodes::NodeExtraInfoParams params{rows, *snode.edittree, node, C};
2493 node.typeinfo->get_extra_info(params);
2494 }
2495
2496 if (node.typeinfo->deprecation_notice) {
2497 NodeExtraInfoRow row;
2498 row.text = IFACE_("Deprecated");
2499 row.icon = ICON_STATUS_INFO;
2500 row.tooltip = TIP_(node.typeinfo->deprecation_notice);
2501 rows.append(std::move(row));
2502 }
2503
2504 if (snode.edittree->type == NTREE_COMPOSIT) {
2505 node_get_compositor_extra_info(tree_draw_ctx, snode, node, rows);
2506 return rows;
2507 }
2508
2509 if (!(snode.edittree->type == NTREE_GEOMETRY)) {
2510 /* Currently geometry and compositor nodes are the only nodes to have extra info per nodes. */
2511 return rows;
2512 }
2513
2515 if (std::optional<NodeExtraInfoRow> row = node_get_accessed_attributes_row(tree_draw_ctx,
2516 node))
2517 {
2518 rows.append(std::move(*row));
2519 }
2520 }
2521
2522 if (snode.overlay.flag & SN_OVERLAY_SHOW_TIMINGS &&
2524 ELEM(node.type_legacy,
2525 NODE_FRAME,
2531 StringRef(node.idname).startswith("GeometryNodeImport") ||
2532 node.is_type("GeometryNodeClosureToList"_ustr) ||
2533 node.is_type("GeometryNodeCombineList"_ustr) ||
2534 node.is_type("GeometryNodeFilterList"_ustr) ||
2535 node.is_type("GeometryNodeListGetItem"_ustr) ||
2536 node.is_type("GeometryNodeFieldToList"_ustr) ||
2537 node.is_type("GeometryNodeListLength"_ustr)))
2538 {
2539 std::optional<NodeExtraInfoRow> row = node_get_execution_time_label_row(
2540 tree_draw_ctx, snode, node);
2541 if (row.has_value()) {
2542 rows.append(std::move(*row));
2543 }
2544 }
2545
2547
2548 if (tree_log) {
2549 tree_log->ensure_debug_messages();
2550 const nodes::eval_log::NodeLog *node_log = tree_log->find_node_log(node.identifier);
2551 if (node_log != nullptr) {
2552 for (const StringRef message : node_log->debug_messages) {
2553 NodeExtraInfoRow row;
2554 row.text = message;
2555 row.icon = ICON_STATUS_INFO;
2556 rows.append(std::move(row));
2557 }
2558 }
2559 }
2560
2561 return rows;
2562}
2563
2565 ui::Block &block,
2566 const rctf &rect,
2567 const int row,
2568 const NodeExtraInfoRow &extra_info_row)
2569{
2570 const float but_icon_left = rect.xmin + 6.0f * UI_SCALE_FAC;
2571 const float but_icon_width = NODE_HEADER_ICON_SIZE * 0.8f;
2572 const float but_icon_right = but_icon_left + but_icon_width;
2573
2574 void *tooltip_arg = extra_info_row.tooltip_fn_arg;
2575 if (tooltip_arg && extra_info_row.tooltip_fn_free_arg) {
2576 BLI_assert(extra_info_row.tooltip_fn_copy_arg);
2577 tooltip_arg = extra_info_row.tooltip_fn_copy_arg(tooltip_arg);
2578 }
2579
2580 block_emboss_set(&block, ui::EmbossType::None);
2581 ui::Button *but_icon = uiDefIconBut(&block,
2583 extra_info_row.icon,
2584 int(but_icon_left),
2585 int(rect.ymin + row * EXTRA_INFO_ROW_HEIGHT),
2586 but_icon_width,
2587 UI_UNIT_Y,
2588 nullptr,
2589 0,
2590 0,
2591 extra_info_row.tooltip);
2592 if (extra_info_row.set_execute_fn) {
2593 extra_info_row.set_execute_fn(*but_icon);
2594 }
2595 if (extra_info_row.tooltip_fn != nullptr) {
2596 button_func_tooltip_set(
2597 but_icon, extra_info_row.tooltip_fn, tooltip_arg, extra_info_row.tooltip_fn_free_arg);
2598 }
2599
2600 const float but_text_left = but_icon_right + 6.0f * UI_SCALE_FAC;
2601 const float but_text_right = rect.xmax;
2602 const float but_text_width = but_text_right - but_text_left;
2603
2604 ui::Button *but_text = uiDefBut(&block,
2605 extra_info_row.set_execute_fn ? ui::ButtonType::But :
2607 extra_info_row.text.c_str(),
2608 int(but_text_left),
2609 int(rect.ymin + row * EXTRA_INFO_ROW_HEIGHT),
2610 short(but_text_width),
2611 NODE_DY,
2612 nullptr,
2613 0,
2614 0,
2615 extra_info_row.tooltip);
2616 button_drawflag_enable(but_text, ui::BUT_TEXT_LEFT);
2617 if (extra_info_row.set_execute_fn) {
2618 extra_info_row.set_execute_fn(*but_text);
2619 }
2620 if (extra_info_row.tooltip_fn != nullptr) {
2621 /* Don't pass tooltip free function because it's already used on the ui::Button above. */
2622 button_func_tooltip_set(but_text, extra_info_row.tooltip_fn, tooltip_arg, nullptr);
2623 }
2624
2625 if (node.is_muted()) {
2626 button_flag_enable(but_text, ui::BUT_INACTIVE);
2627 button_flag_enable(but_icon, ui::BUT_INACTIVE);
2628 }
2629
2630 block_emboss_set(&block, ui::EmbossType::Emboss);
2631}
2632
2633static void node_draw_extra_info_panel_back(const bNode &node, const rctf &extra_info_rect)
2634{
2635 rctf panel_back_rect = extra_info_rect;
2636
2638 if (node.is_muted()) {
2640 }
2641 else {
2643 }
2644 color.a -= 0.35f;
2645
2646 ColorTheme4f color_outline;
2647 ui::theme::get_color_blend_shade_4fv(TH_BACK, TH_NODE, 0.4f, -20, color_outline);
2648
2649 const float outline_width = U.pixelsize;
2650 BLI_rctf_pad(&panel_back_rect, outline_width, outline_width);
2651
2654 &panel_back_rect, color, nullptr, 0.0f, color_outline, outline_width, BASIS_RAD);
2655}
2656
2658 TreeDrawContext &tree_draw_ctx,
2659 const SpaceNode &snode,
2660 const bNode &node,
2661 const ImBuf *preview,
2662 ui::Block &block)
2663{
2664 const Scene *scene = CTX_data_scene(&C);
2665 if (!(snode.overlay.flag & SN_OVERLAY_SHOW_OVERLAYS)) {
2666 return;
2667 }
2668 if (preview && !(preview->x > 0 && preview->y > 0)) {
2669 /* If the preview has an non-drawable size, just don't draw it. */
2670 preview = nullptr;
2671 }
2672 const Span<NodeExtraInfoRow> extra_info_rows =
2673 tree_draw_ctx.extra_info_rows_per_node[node.index()];
2674 if (extra_info_rows.is_empty() && !preview) {
2675 return;
2676 }
2677
2678 const rctf &rct = node.runtime->draw_bounds;
2679 rctf extra_info_rect;
2680
2681 if (node.is_frame()) {
2682 extra_info_rect.xmin = rct.xmin;
2683 extra_info_rect.xmax = rct.xmin + 95.0f * UI_SCALE_FAC;
2684 extra_info_rect.ymin = rct.ymin + 2.0f * UI_SCALE_FAC;
2685 extra_info_rect.ymax = rct.ymin + 2.0f * UI_SCALE_FAC;
2686 }
2687 else {
2688 const float padding = 3.0f * UI_SCALE_FAC;
2689
2690 extra_info_rect.xmin = rct.xmin + padding;
2691 extra_info_rect.xmax = rct.xmax - padding;
2692 extra_info_rect.ymin = rct.ymax;
2693 extra_info_rect.ymax = rct.ymax + extra_info_rows.size() * EXTRA_INFO_ROW_HEIGHT;
2694
2695 float preview_height = 0.0f;
2696 rctf preview_rect;
2697 if (preview) {
2698 const float width = BLI_rctf_size_x(&extra_info_rect);
2699 if (preview->x > preview->y) {
2700 preview_height = (width - 2.0f * padding) * float(preview->y) / float(preview->x) +
2701 2.0f * padding;
2702 preview_rect.ymin = extra_info_rect.ymin + padding;
2703 preview_rect.ymax = extra_info_rect.ymin + preview_height - padding;
2704 preview_rect.xmin = extra_info_rect.xmin + padding;
2705 preview_rect.xmax = extra_info_rect.xmax - padding;
2706 extra_info_rect.ymax += preview_height;
2707 }
2708 else {
2709 preview_height = width;
2710 const float preview_width = (width - 2.0f * padding) * float(preview->x) /
2711 float(preview->y) +
2712 2.0f * padding;
2713 preview_rect.ymin = extra_info_rect.ymin + padding;
2714 preview_rect.ymax = extra_info_rect.ymin + preview_height - padding;
2715 preview_rect.xmin = extra_info_rect.xmin + padding + (width - preview_width) / 2;
2716 preview_rect.xmax = extra_info_rect.xmax - padding - (width - preview_width) / 2;
2717 extra_info_rect.ymax += preview_height;
2718 }
2719 }
2720
2721 node_draw_extra_info_panel_back(node, extra_info_rect);
2722
2723 if (preview) {
2724 node_draw_preview(scene, preview, &preview_rect);
2725 }
2726
2727 /* Resize the rect to draw the textual infos on top of the preview. */
2728 extra_info_rect.ymin += preview_height;
2729 }
2730
2731 for (int row : extra_info_rows.index_range()) {
2732 node_draw_extra_info_row(node, block, extra_info_rect, row, extra_info_rows[row]);
2733 }
2734}
2735
2737{
2738 BLI_assert(node.is_type("CompositorNodeViewer"_ustr) || node.is_type("GeometryNodeViewer"_ustr));
2739 switch (node.custom1) {
2741 /* No change by default. */
2742 return node.typeinfo->ui_icon;
2744 return ICON_EVENT_ONEKEY;
2746 return ICON_EVENT_TWOKEY;
2748 return ICON_EVENT_THREEKEY;
2750 return ICON_EVENT_FOURKEY;
2752 return ICON_EVENT_FIVEKEY;
2754 return ICON_EVENT_SIXKEY;
2756 return ICON_EVENT_SEVENKEY;
2758 return ICON_EVENT_EIGHTKEY;
2760 return ICON_EVENT_NINEKEY;
2761 }
2762
2763 return node.typeinfo->ui_icon;
2764}
2765
2766/* Returns true if the given node has an undefined type, a missing group node tree, or is
2767 * unsupported in the given node tree. */
2768static bool node_undefined_or_unsupported(const bNodeTree &node_tree, const bNode &node)
2769{
2770 if (node.typeinfo == &bke::NodeTypeUndefined) {
2771 return true;
2772 }
2773
2774 const char *disabled_hint = nullptr;
2775 if (!node.typeinfo->poll(node.typeinfo, &node_tree, &disabled_hint)) {
2776 return true;
2777 }
2778
2779 if (node.is_group()) {
2780 const ID *group_tree = node.id;
2781 if (group_tree == nullptr) {
2782 return false;
2783 }
2784 if (!ID_IS_LINKED(group_tree)) {
2785 return false;
2786 }
2787 if ((group_tree->tag & ID_TAG_MISSING) == 0) {
2788 return false;
2789 }
2790 return true;
2791 }
2792 return false;
2793}
2794
2796 const bNode &node,
2797 const int color_id)
2798{
2799 ColorTheme4f color_header;
2800 /* Use node backdrop alpha for node header, blend between 0.55 - 1.0. */
2801 ColorTheme4f color_alpha;
2802 ui::theme::get_color_4fv(TH_NODE, color_alpha);
2803 const float alpha = 0.55f + color_alpha.a * (1.0f - 0.55f);
2804
2805 /* The base color of the node header. */
2806 if (node_undefined_or_unsupported(ntree, node)) {
2807 /* Use warning color to indicate undefined types. */
2808 ColorTheme4f color_alert;
2811 TH_REDALERT, color_id, 1.0f - color_alert.a, -60, color_header);
2812 color_header.a = alpha;
2813 }
2814 else if ((node.flag & NODE_COLLAPSED) && (node.flag & NODE_CUSTOM_COLOR)) {
2815 rgba_float_args_set(color_header, node.color[0], node.color[1], node.color[2], alpha);
2816 }
2817 else {
2818 ui::theme::get_color_4fv(color_id, color_header);
2819 color_header.a = alpha;
2820 }
2821
2822 /* Draw selected nodes fully opaque. */
2823 if (node.is_selected()) {
2824 color_header.a = 1.0f;
2825 }
2826
2827 /* Muted nodes get a mix of the background with the node color and are drawn slightly
2828 * transparent so the wires inside are visible. */
2829 if (node.is_muted()) {
2830 ColorTheme4f color_background;
2831 ui::theme::get_color_4fv(TH_BACK, color_background);
2832
2834 color_header, color_background, 0.6f, -0.2f, color_header);
2835 }
2836
2837 return color_header;
2838}
2839
2840static void node_header_custom_tooltip(const bNodeTree &ntree, const bNode &node, ui::Button &but)
2841{
2842 button_func_tooltip_custom_set_cpp(
2843 but, [&node, &ntree](bContext & /*C*/, ui::TooltipData &data) {
2844 const std::string description = node.typeinfo->ui_description_fn ?
2845 TIP_(node.typeinfo->ui_description_fn(node)) :
2846 TIP_(node.typeinfo->ui_description);
2847 const bool have_description = !description.empty();
2848 if (have_description) {
2849 tooltip_text_field_add(
2850 data, std::move(description), "", ui::TIP_STYLE_NORMAL, ui::TIP_LC_NORMAL);
2851 }
2852 if (U.flag & USER_TOOLTIPS_PYTHON) {
2854 const_cast<ID *>(&ntree.id), RNA_Node, const_cast<bNode *>(&node));
2855 tooltip_text_field_add(data,
2856 fmt::format("Python: {}\n{}",
2857 node.idname,
2858 RNA_path_full_struct_py(&nodeptr).value_or("")),
2859 "",
2862 have_description);
2863 }
2864 });
2865}
2866
2867static void node_draw_basis(const bContext &C,
2868 TreeDrawContext &tree_draw_ctx,
2869 const View2D &v2d,
2870 const SpaceNode &snode,
2871 bNodeTree &ntree,
2872 const bNode &node,
2873 ui::Block &block)
2874{
2875 const float iconbutw = NODE_HEADER_ICON_SIZE;
2876 const bool show_preview = (snode.overlay.flag & SN_OVERLAY_SHOW_OVERLAYS) &&
2878 (node.flag & NODE_PREVIEW) &&
2879 (USER_EXPERIMENTAL_TEST(&U, use_shader_node_previews) ||
2880 ntree.type != NTREE_SHADER);
2881
2882 /* Skip if out of view. */
2883 rctf rect_with_preview = node.runtime->draw_bounds;
2884 if (show_preview) {
2885 rect_with_preview.ymax += NODE_WIDTH(node);
2886 }
2887 if (BLI_rctf_isect(&rect_with_preview, &v2d.cur, nullptr) == false) {
2888 block_end_ex(&C,
2889 tree_draw_ctx.bmain,
2890 tree_draw_ctx.window,
2891 tree_draw_ctx.scene,
2892 tree_draw_ctx.region,
2893 tree_draw_ctx.depsgraph,
2894 &block);
2895 return;
2896 }
2897
2898 /* Shadow. */
2899 if (!bke::all_zone_node_types().contains(node.type_legacy)) {
2900 node_draw_shadow(snode, node, BASIS_RAD, 1.0f);
2901 }
2902
2903 const rctf &rct = node.runtime->draw_bounds;
2904 float color[4], color_alert[4];
2906 int color_id = node_get_colorid(tree_draw_ctx, node);
2907
2908 GPU_line_width(1.0f);
2909
2910 /* Overlay atop the node. */
2911 {
2912 bool drawn_with_previews = false;
2913
2914 if (show_preview) {
2915 NestedTreePreviews *previews_shader = tree_draw_ctx.nested_group_infos;
2916
2917 if (previews_shader) {
2918 ImBuf *preview = node_preview_acquire_ibuf(ntree, *previews_shader, node);
2919 node_draw_extra_info_panel(C, tree_draw_ctx, snode, node, preview, block);
2920 node_release_preview_ibuf(*previews_shader);
2921 drawn_with_previews = true;
2922 }
2923
2924 if (const nodes::eval_log::NodeTreeLog *tree_log = tree_draw_ctx.tree_logs.get_main_tree_log(
2925 node))
2926 {
2927 if (const nodes::eval_log::NodeLog *node_log = tree_log->find_node_log(node.identifier)) {
2928 if (node_log->image_preview) {
2930 C, tree_draw_ctx, snode, node, node_log->image_preview, block);
2931 drawn_with_previews = true;
2932 }
2933 }
2934 }
2935 }
2936
2937 if (drawn_with_previews == false) {
2938 node_draw_extra_info_panel(C, tree_draw_ctx, snode, node, nullptr, block);
2939 }
2940 }
2941
2942 const float padding = 0.5f;
2943 const float corner_radius = BASIS_RAD + padding;
2944 const float outline_width = U.pixelsize;
2945 /* Header. */
2946 {
2947 /* Add some padding to prevent transparent gaps with the outline. */
2948 const rctf rect = {
2949 rct.xmin - padding,
2950 rct.xmax + padding,
2951 rct.ymax - NODE_DY - padding,
2952 rct.ymax + padding,
2953 };
2954
2955 const ColorTheme4f color_header = node_header_color_get(ntree, node, color_id);
2956
2958 ui::draw_roundbox_4fv(&rect, true, corner_radius, color_header);
2959 }
2960
2961 /* Show/hide icons. */
2962 float iconofs = rct.xmax - 0.35f * U.widget_unit;
2963
2964 if (nodes::node_can_sync_sockets(C, ntree, node)) {
2965 iconofs -= iconbutw;
2966 block_emboss_set(&block, ui::EmbossType::None);
2967 ui::Button *but = uiDefIconBut(&block,
2969 ICON_FILE_REFRESH,
2970 iconofs,
2971 rct.ymax - NODE_DY,
2972 iconbutw,
2973 UI_UNIT_Y,
2974 nullptr,
2975 0,
2976 0,
2977 "");
2978
2979 wmOperatorType *ot = WM_operatortype_find("NODE_OT_sockets_sync", false);
2980 button_operator_set(but, ot, wm::OpCallContext::InvokeDefault);
2981 PointerRNA *opptr = button_operator_ptr_ensure(but);
2982 opptr->data = bke::idprop::create_group("wmOperatorProperties").release();
2983 RNA_string_set(opptr, "node_name", node.name);
2984 block_emboss_set(&block, ui::EmbossType::Emboss);
2985 }
2986
2987 /* Preview. */
2988 if (node_is_previewable(snode, ntree, node)) {
2989 const bool is_active = node.flag & NODE_PREVIEW;
2990 iconofs -= iconbutw;
2991 block_emboss_set(&block, ui::EmbossType::None);
2992 ui::Button *but = uiDefIconBut(&block,
2994 is_active ? ICON_HIDE_OFF : ICON_HIDE_ON,
2995 iconofs,
2996 rct.ymax - NODE_DY,
2997 iconbutw,
2998 UI_UNIT_Y,
2999 nullptr,
3000 0,
3001 0,
3002 "");
3003 /* The operator already adds an undo step, so no need for the button to also add one. */
3004 button_flag_disable(but, ui::BUT_UNDO);
3005 button_func_set(but,
3007 POINTER_FROM_INT(node.identifier),
3008 (void *)("NODE_OT_preview_toggle"));
3009 block_emboss_set(&block, ui::EmbossType::Emboss);
3010 }
3011 if (ELEM(node.type_legacy, NODE_CUSTOM, NODE_CUSTOM_GROUP) &&
3012 node.typeinfo->ui_icon != ICON_NONE)
3013 {
3014 iconofs -= iconbutw;
3015 block_emboss_set(&block, ui::EmbossType::None);
3016 uiDefIconBut(&block,
3018 node.typeinfo->ui_icon,
3019 iconofs,
3020 rct.ymax - NODE_DY,
3021 iconbutw,
3022 UI_UNIT_Y,
3023 nullptr,
3024 0,
3025 0,
3026 "");
3027 block_emboss_set(&block, ui::EmbossType::Emboss);
3028 }
3029 if (node.type_legacy == GEO_NODE_VIEWER) {
3030 const bool is_active = &node == tree_draw_ctx.active_geometry_nodes_viewer;
3031 iconofs -= iconbutw;
3032 block_emboss_set(&block, ui::EmbossType::None);
3033 ui::Button *but = uiDefIconBut(&block,
3035 is_active ? ICON_RESTRICT_VIEW_OFF : ICON_RESTRICT_VIEW_ON,
3036 iconofs,
3037 rct.ymax - NODE_DY,
3038 iconbutw,
3039 UI_UNIT_Y,
3040 nullptr,
3041 0,
3042 0,
3043 "");
3044 /* Selection implicitly activates the node. */
3045 const char *operator_idname = is_active ? "NODE_OT_deactivate_viewer" :
3046 "NODE_OT_activate_viewer";
3047 button_func_set(
3048 but, node_toggle_button_cb, POINTER_FROM_INT(node.identifier), (void *)(operator_idname));
3049
3050 short shortcut_icon = get_viewer_shortcut_icon(node);
3051 uiDefIconBut(&block,
3053 shortcut_icon,
3054 iconofs - 1.2 * iconbutw,
3055 rct.ymax - NODE_DY,
3056 iconbutw,
3057 UI_UNIT_Y,
3058 nullptr,
3059 0,
3060 0,
3061 "");
3062 block_emboss_set(&block, ui::EmbossType::Emboss);
3063 }
3064 /* Viewer node shortcuts. */
3065 if (node.is_type("CompositorNodeViewer"_ustr)) {
3066 short shortcut_icon = get_viewer_shortcut_icon(node);
3067 iconofs -= iconbutw;
3068 const bool is_active = node.flag & NODE_DO_OUTPUT;
3069 block_emboss_set(&block, ui::EmbossType::None);
3070 ui::Button *but = uiDefIconBut(&block,
3072 is_active ? ICON_RESTRICT_VIEW_OFF : ICON_RESTRICT_VIEW_ON,
3073 iconofs,
3074 rct.ymax - NODE_DY,
3075 iconbutw,
3076 UI_UNIT_Y,
3077 nullptr,
3078 0,
3079 0,
3080 "");
3081
3082 button_func_set(but,
3084 POINTER_FROM_INT(node.identifier),
3085 (void *)("NODE_OT_activate_viewer"));
3086
3087 uiDefIconBut(&block,
3089 shortcut_icon,
3090 iconofs - 1.2 * iconbutw,
3091 rct.ymax - NODE_DY,
3092 iconbutw,
3093 UI_UNIT_Y,
3094 nullptr,
3095 0,
3096 0,
3097 "");
3098 block_emboss_set(&block, ui::EmbossType::Emboss);
3099 }
3100
3101 node_add_error_message_button(tree_draw_ctx, ntree, node, block, rct, iconofs);
3102
3103 /* Title. */
3104 if (node.is_selected()) {
3106 }
3107 else {
3109 }
3110
3111 /* Collapse/expand icon. */
3112 {
3113 const int but_size = U.widget_unit * 0.8f;
3114 block_emboss_set(&block, ui::EmbossType::None);
3115
3116 ui::Button *but = uiDefIconBut(&block,
3118 ICON_DOWNARROW_HLT,
3119 rct.xmin + (NODE_MARGIN_X / 3),
3120 rct.ymax - NODE_DY / 2.2f - but_size / 2,
3121 but_size,
3122 but_size,
3123 nullptr,
3124 0.0f,
3125 0.0f,
3126 "");
3127
3128 /* The operator already adds an undo step, so no need for the button to also add one. */
3129 button_flag_disable(but, ui::BUT_UNDO);
3130 button_func_set(but,
3132 POINTER_FROM_INT(node.identifier),
3133 (void *)("NODE_OT_hide_toggle"));
3134 block_emboss_set(&block, ui::EmbossType::Emboss);
3135 }
3136
3137 const std::string showname = bke::node_label(ntree, node);
3138
3139 ui::Button *but = uiDefBut(&block,
3141 showname,
3143 int(rct.ymax - NODE_DY),
3144 short(iconofs - rct.xmin - NODE_MARGIN_X),
3145 NODE_DY,
3146 nullptr,
3147 0,
3148 0,
3149 std::nullopt);
3150 node_header_custom_tooltip(ntree, node, *but);
3151
3152 if (node.is_muted()) {
3153 button_flag_enable(but, ui::BUT_INACTIVE);
3154 }
3155
3156 /* Wire across the node when muted/disabled. */
3157 if (node.is_muted()) {
3158 node_draw_mute_line(C, v2d, snode, node);
3159 }
3160
3161 /* Body. */
3162 {
3163 /* Use warning color to indicate undefined types. */
3164 if (node_undefined_or_unsupported(ntree, node)) {
3166 TH_REDALERT, color_id, 1.0f - color_alert[3], -80, color);
3167 }
3168 else if (node.flag & NODE_CUSTOM_COLOR) {
3169 rgba_float_args_set(color, node.color[0], node.color[1], node.color[2], 1.0f);
3170 }
3171 else {
3173 }
3174
3175 /* Draw selected nodes fully opaque. */
3176 if (node.is_selected()) {
3177 color[3] = 1.0f;
3178 }
3179
3180 /* Muted nodes get a mix of the background with the node color and are drawn slightly
3181 * transparent so the wires inside are visible. */
3182 if (node.is_muted()) {
3183 float color_background[4];
3184 ui::theme::get_color_4fv(TH_BACK, color_background);
3185
3186 ui::theme::get_color_blend_alpha_4fv(color, color_background, 0.8f, -0.2f, color);
3187 }
3188
3189 /* Add some padding to prevent transparent gaps with the outline. */
3190 const rctf rect = {
3191 rct.xmin - padding,
3192 rct.xmax + padding,
3193 rct.ymin - padding,
3194 rct.ymax - NODE_DY + padding,
3195 };
3196
3197 /* Node Group indicator. */
3198 if (draw_node_details(snode)) {
3199 node_draw_node_group_indicator(snode, node, rect, corner_radius, color);
3200 }
3201
3203 ui::draw_roundbox_4fv(&rect, true, corner_radius, color);
3204
3207 }
3208 }
3209
3210 /* Outline around the entire node to highlight selection, alert, or for simulation zones. */
3211 {
3212 const rctf rect_node = {
3213 rct.xmin - outline_width,
3214 rct.xmax + outline_width,
3215 rct.ymin - outline_width,
3216 rct.ymax + outline_width,
3217 };
3218 float color_outline[4] = {0.0f, 0.0f, 0.0f, 1.0f};
3219 if (node.is_selected()) {
3220 ui::theme::get_color_4fv((node.flag & NODE_ACTIVE) ? TH_ACTIVE : TH_SELECT, color_outline);
3221 }
3222 else if (node_undefined_or_unsupported(ntree, node)) {
3223 ui::theme::get_color_4fv(TH_REDALERT, color_outline);
3224 color_outline[3] = 1.0f;
3225 }
3226 else if (const bke::bNodeZoneType *zone_type = bke::zone_type_by_node_type(node.type_legacy)) {
3227 ui::theme::get_color_4fv(zone_type->theme_id, color_outline);
3228 color_outline[3] = 1.0f;
3229 }
3230 else {
3232 }
3234 ui::draw_roundbox_4fv(&rect_node, false, BASIS_RAD + outline_width, color_outline);
3235 }
3236
3237 /* Skip slow socket drawing if zoom is small. */
3238 if (draw_node_details(snode)) {
3239 node_draw_sockets(C, block, snode, ntree, node);
3240 }
3241
3243 node_draw_panels(ntree, node, block);
3244 }
3245
3246 block_end_ex(&C,
3247 tree_draw_ctx.bmain,
3248 tree_draw_ctx.window,
3249 tree_draw_ctx.scene,
3250 tree_draw_ctx.region,
3251 tree_draw_ctx.depsgraph,
3252 &block);
3253 block_draw(&C, &block);
3254}
3255
3256static void node_draw_collapsed(const bContext &C,
3257 TreeDrawContext &tree_draw_ctx,
3258 const View2D &v2d,
3259 const SpaceNode &snode,
3260 bNodeTree &ntree,
3261 bNode &node,
3262 ui::Block &block)
3263{
3264 const rctf &rct = node.runtime->draw_bounds;
3265 float centy = BLI_rctf_cent_y(&rct);
3266
3267 float scale;
3268 ui::view2d_scale_get(&v2d, &scale, nullptr);
3269
3270 const int color_id = node_get_colorid(tree_draw_ctx, node);
3271
3272 node_draw_extra_info_panel(C, tree_draw_ctx, snode, node, nullptr, block);
3273
3274 /* Shadow. */
3275 node_draw_shadow(snode, node, BASIS_RAD, 1.0f);
3276
3277 /* Wire across the node when muted/disabled. */
3278 if (node.is_muted()) {
3279 node_draw_mute_line(C, v2d, snode, node);
3280 }
3281
3282 /* Body. */
3283 ColorTheme4f color = node_header_color_get(ntree, node, color_id);
3284 {
3285 /* Add some padding to prevent transparent gaps with the outline. */
3286 const float padding = 0.5f;
3287 const rctf rect = {
3288 rct.xmin - padding,
3289 rct.xmax + padding,
3290 rct.ymin - padding,
3291 rct.ymax + padding,
3292 };
3293
3294 /* Node Group indicator. */
3295 if (draw_node_details(snode)) {
3297 }
3298
3299 draw_roundbox_corner_set(ui::CNR_ALL);
3301 }
3302
3303 /* Title. */
3304 if (node.is_selected()) {
3306 }
3307 else {
3309 }
3310
3311 const rctf header_rect = {
3312 rct.xmin,
3313 rct.xmax,
3314 centy - NODE_DY * 0.5f,
3315 centy + NODE_DY * 0.5f,
3316 };
3317
3318 float iconofs = rct.xmax - 0.35f * U.widget_unit;
3319 node_add_error_message_button(tree_draw_ctx, ntree, node, block, header_rect, iconofs);
3320
3321 /* Collapse/expand icon. */
3322 {
3323 const int but_size = 0.8f * U.widget_unit;
3324 block_emboss_set(&block, ui::EmbossType::None);
3325
3326 ui::Button *but = uiDefIconBut(&block,
3328 ICON_RIGHTARROW,
3329 rct.xmin + (NODE_MARGIN_X / 3) + 0.1f * U.widget_unit,
3330 centy - but_size / 2,
3331 but_size,
3332 but_size,
3333 nullptr,
3334 0.0f,
3335 0.0f,
3336 "");
3337
3338 /* The operator already adds an undo step, so no need for the button to also add one. */
3339 button_flag_disable(but, ui::BUT_UNDO);
3340 button_func_set(but,
3342 POINTER_FROM_INT(node.identifier),
3343 (void *)("NODE_OT_hide_toggle"));
3344 block_emboss_set(&block, ui::EmbossType::Emboss);
3345 }
3346
3347 const std::string showname = bke::node_label(ntree, node);
3348
3349 ui::Button *but = uiDefBut(&block,
3351 showname,
3353 round_fl_to_int(centy - NODE_DY * 0.5f),
3354 short(iconofs - rct.xmin - NODE_MARGIN_X),
3355 NODE_DY,
3356 nullptr,
3357 0,
3358 0,
3359 std::nullopt);
3360 node_header_custom_tooltip(ntree, node, *but);
3361
3362 /* Outline. */
3363 {
3364 const float outline_width = U.pixelsize;
3365 const rctf rect = {
3366 rct.xmin - outline_width,
3367 rct.xmax + outline_width,
3368 rct.ymin - outline_width,
3369 rct.ymax + outline_width,
3370 };
3371
3372 /* Color the outline according to active, selected, or undefined status. */
3373 float color_outline[4];
3374
3375 if (node.is_selected()) {
3376 ui::theme::get_color_4fv((node.flag & NODE_ACTIVE) ? TH_ACTIVE : TH_SELECT, color_outline);
3377 }
3378 else if (node_undefined_or_unsupported(ntree, node)) {
3379 ui::theme::get_color_4fv(TH_REDALERT, color_outline);
3380 color_outline[3] = 1.0f;
3381 }
3382 else if (node.is_muted()) {
3383 /* Muted nodes get a mix of the background with the node color. */
3384 ui::theme::get_color_blend_shade_4fv(TH_BACK, color_id, .4f, 10, color_outline);
3385 }
3386 else {
3388 }
3389
3390 draw_roundbox_corner_set(ui::CNR_ALL);
3391 ui::draw_roundbox_4fv(&rect, false, BASIS_RAD + outline_width, color_outline);
3392 }
3393
3394 if (node.is_muted()) {
3395 button_flag_enable(but, ui::BUT_INACTIVE);
3396 }
3397
3398 node_draw_sockets(C, block, snode, ntree, node);
3399
3400 block_end_ex(&C,
3401 tree_draw_ctx.bmain,
3402 tree_draw_ctx.window,
3403 tree_draw_ctx.scene,
3404 tree_draw_ctx.region,
3405 tree_draw_ctx.depsgraph,
3406 &block);
3407 block_draw(&C, &block);
3408}
3409
3411{
3412 if (directions == 0) {
3413 return WM_CURSOR_DEFAULT;
3414 }
3415 if ((directions & ~(NODE_RESIZE_TOP | NODE_RESIZE_BOTTOM)) == 0) {
3416 return WM_CURSOR_Y_MOVE;
3417 }
3418 if ((directions & ~(NODE_RESIZE_RIGHT | NODE_RESIZE_LEFT)) == 0) {
3419 return WM_CURSOR_X_MOVE;
3420 }
3421 return WM_CURSOR_EDIT;
3422}
3423
3424static const bNode *find_node_under_cursor(SpaceNode &snode, const float2 &cursor)
3425{
3427 if (BLI_rctf_isect_pt(&node->runtime->draw_bounds, cursor[0], cursor[1])) {
3428 return node;
3429 }
3430 }
3431 return nullptr;
3432}
3433
3434void node_set_cursor(wmWindow &win, ARegion &region, SpaceNode &snode, const float2 &cursor)
3435{
3436 const bNodeTree *ntree = snode.edittree;
3437 if (ntree == nullptr) {
3439 return;
3440 }
3441 if (node_find_indicated_socket(snode, region, cursor, SOCK_IN | SOCK_OUT)) {
3443 return;
3444 }
3445 const bNode *node = find_node_under_cursor(snode, cursor);
3446 if (!node) {
3448 return;
3449 }
3450 const NodeResizeDirection dir = node_get_resize_direction(snode, node, cursor[0], cursor[1]);
3451 if (node->is_frame() && dir == NODE_RESIZE_NONE) {
3452 /* Indicate that frame nodes can be moved/selected on their borders. */
3453 const rctf frame_inside = node_frame_rect_inside(snode, *node);
3454 if (!BLI_rctf_isect_pt(&frame_inside, cursor[0], cursor[1])) {
3456 return;
3457 }
3459 return;
3460 }
3461
3463}
3464
3466{
3467 for (bNode *node : ntree.all_nodes()) {
3468 for (bNodeSocket *socket : node->input_sockets()) {
3469 if (socket->is_multi_input()) {
3470 socket->runtime->total_inputs = socket->directly_linked_links().size();
3471 }
3472 }
3473 }
3474 /* Count temporary links going into this socket. */
3475 if (snode.runtime->linkdrag) {
3476 for (const bNodeLink &link : snode.runtime->linkdrag->links) {
3477 if (link.tosock && (link.tosock->flag & SOCK_MULTI_INPUT)) {
3478 link.tosock->runtime->total_inputs++;
3479 }
3480 }
3481 }
3482}
3483
3485 float margin = 0;
3486 float margin_top = 0;
3487 float label_height = 0;
3489 bool has_label = false;
3490};
3491
3492static FrameNodeLayout frame_node_layout(const bNode &frame_node)
3493{
3494 BLI_assert(frame_node.is_frame());
3495
3496 const NodeFrame *frame_data = static_cast<NodeFrame *>(frame_node.storage);
3497
3498 FrameNodeLayout frame_layout;
3499
3500 frame_layout.has_label = frame_node.label[0] != '\0';
3501
3502 /* This is not the actual height of the letters in the label, but an approximation that includes
3503 * some of the white-space above and below the actual letters. */
3504 frame_layout.label_height = frame_data->label_size * UI_SCALE_FAC;
3505
3506 /* The side and bottom margins are 50% bigger than the widget unit */
3507 frame_layout.margin = 1.5f * U.widget_unit;
3508
3509 if (frame_layout.has_label) {
3510 /* The label takes up 1.5 times the label height plus 0.2 times the margin.
3511 * These coefficients are selected to provide good layout and spacing for the descenders. */
3512 float room_for_label = 1.5f * frame_layout.label_height + 0.2f * frame_layout.margin;
3513
3514 /* Make top margin bigger, if needed for the label, but never smaller than the side margins. */
3515 frame_layout.margin_top = std::max(frame_layout.margin, room_for_label);
3516
3517 /* This adjustment approximately centers the cap height in the margin.
3518 * This is achieved by finding the y value that is the center of the top margin, then lowering
3519 * that by 35% of the label height. Since font cap heights are typically about 70% of the total
3520 * line height, moving the text by half that achieves rough centering. */
3521 frame_layout.label_baseline = 0.5f * frame_layout.margin_top +
3522 0.35f * frame_layout.label_height;
3523 }
3524 else {
3525 /* If there is no label, the top margin is the same as the sides. */
3526 frame_layout.margin_top = frame_layout.margin;
3527 frame_layout.label_baseline = 0;
3528 }
3529
3530 return frame_layout;
3531}
3532
3540 TreeDrawContext &tree_draw_ctx,
3541 const SpaceNode &snode,
3542 bNode &node)
3543{
3544 if (!node.is_frame()) {
3545 rctf node_bounds = node.runtime->draw_bounds;
3546
3547 float zone_padding = 0;
3548 float extra_row_padding = 0;
3549
3550 /* Pad if the node type is a zone input or output. */
3551 if (bke::zone_type_by_node_type(node.type_legacy) != nullptr) {
3552 zone_padding = NODE_ZONE_PADDING;
3553 }
3554
3555 /* Compute the height of the info row for each node, which may vary per child node.
3556 * This has to get the full extra_rows information (including all the text strings), even
3557 * though all that's actually needed is the count of how many info_rows there are. */
3559 extra_row_padding = tree_draw_ctx.extra_info_rows_per_node[node.index()].size() *
3561 }
3562
3563 node_bounds.ymax += std::max(zone_padding, extra_row_padding);
3564 node_bounds.ymin -= zone_padding;
3565
3566 return node_bounds;
3567 }
3568
3569 NodeFrame *data = static_cast<NodeFrame *>(node.storage);
3570
3571 const FrameNodeLayout frame_layout = frame_node_layout(node);
3572
3573 /* Initialize rect from current frame size. */
3574 rctf rect;
3576
3577 /* Frame can be resized manually only if shrinking is disabled or no children are attached. */
3578 data->flag |= NODE_FRAME_RESIZEABLE;
3579 /* For shrinking bounding box, initialize the rect from first child node. */
3580 bool bbinit = (data->flag & NODE_FRAME_SHRINK);
3581 /* Fit bounding box to all children. */
3582 for (bNode *child : node.direct_children_in_frame()) {
3583 /* Add margin to node rect. */
3584 rctf noderect = calc_node_frame_dimensions(C, tree_draw_ctx, snode, *child);
3585
3586 noderect.xmin -= frame_layout.margin;
3587 noderect.xmax += frame_layout.margin;
3588 noderect.ymin -= frame_layout.margin;
3589 noderect.ymax += frame_layout.margin_top;
3590
3591 /* First child initializes frame. */
3592 if (bbinit) {
3593 bbinit = false;
3594 rect = noderect;
3596 }
3597 else {
3598 BLI_rctf_union(&rect, &noderect);
3599 }
3600 }
3601
3602 /* Now adjust the frame size from view-space bounding box. */
3603 const float2 min = node_from_view({rect.xmin, rect.ymin});
3604 const float2 max = node_from_view({rect.xmax, rect.ymax});
3605 node.location[0] = min.x;
3606 node.location[1] = max.y;
3607 node.width = max.x - min.x;
3608 node.height = max.y - min.y;
3609
3610 node.runtime->draw_bounds = rect;
3611 return rect;
3612}
3613
3615{
3616 const float2 loc = node_to_view(node.location);
3617
3618 /* When the node is collapsed, the input and output socket are both in the same place. */
3619 node.input_socket(0).runtime->location = loc;
3620 node.output_socket(0).runtime->location = loc;
3621
3622 const float radius = NODE_SOCKSIZE;
3623 node.width = radius * 2;
3624 node.runtime->draw_bounds.xmin = loc.x - radius;
3625 node.runtime->draw_bounds.xmax = loc.x + radius;
3626 node.runtime->draw_bounds.ymax = loc.y + radius;
3627 node.runtime->draw_bounds.ymin = loc.y - radius;
3628}
3629
3630static void node_comment_edit_button_cb(bContext *C, void *node_argv, void * /*arg*/)
3631{
3632 SpaceNode &snode = *CTX_wm_space_node(C);
3633 bNodeTree &node_tree = *snode.edittree;
3634 bNode &node = *node_tree.node_by_id(POINTER_AS_INT(node_argv));
3635
3637
3638 PointerRNA props_ptr = WM_operator_properties_create("NODE_OT_comment_edit");
3639 RNA_boolean_set(&props_ptr, "use_active", true);
3641 C, "NODE_OT_comment_edit", wm::OpCallContext::InvokeDefault, &props_ptr, nullptr);
3642 WM_operator_properties_free(&props_ptr);
3643}
3644
3646 bNodeTree &ntree,
3647 bNode &node,
3648 ui::Block &block)
3649{
3650 NodeComment &storage = *static_cast<NodeComment *>(node.storage);
3651 const bool is_edit = bool(storage.flag & NodeCommentFlag::Edit);
3652 const StringRef text = storage.text;
3653
3654 const float2 loc = node_to_view(node.location);
3655 PointerRNA node_ptr = RNA_pointer_create_discrete(&ntree.id, RNA_Node, &node);
3656
3657 float bottom_y;
3658 if (is_edit) {
3659 const int but_h = ui::textbox_but_height(storage.textbox_state_node);
3660 ui::Button *but = uiDefButTextBoxR(&block,
3661 &node_ptr,
3662 "text",
3663 &storage.textbox_state_node,
3664 loc.x,
3665 loc.y - but_h,
3666 int(node.width * UI_SCALE_FAC));
3667 /* Same approach to detecting when a text property is not active anymore is used elsewhere
3668 * (e.g. #outliner_buttons) */
3669 if (!ui::button_active_only(&C, CTX_wm_region(&C), &block, but)) {
3670 storage.flag &= ~NodeCommentFlag::Edit;
3672 }
3673 bottom_y = loc.y - but_h;
3674 }
3675 else {
3676 /* Different paddings are used here to compensate for padding applied elsewhere. */
3677 const int pad_left = 0.4 * UI_UNIT_X;
3678 const int pad_right = 0.45 * UI_UNIT_X;
3679 const int pad_top = 0.4 * UI_UNIT_Y;
3680 const int pad_bottom = 0.4 * UI_UNIT_Y;
3681
3682 ui::Layout &layout = ui::block_layout(&block,
3685 loc.x + pad_left,
3686 loc.y - pad_top,
3687 node.width * UI_SCALE_FAC - pad_left - pad_right,
3688 0,
3689 0,
3691 layout.label_markdown(text);
3692 block_align_end(&block);
3693 bottom_y = ui::block_layout_resolve(&block).y - pad_bottom;
3694 }
3695
3696 const float icon_pad = 0.15f * U.widget_unit;
3697 float height = std::max<float>(is_edit || !text.trim().is_empty() ? loc.y - bottom_y : 0,
3698 NODE_HEADER_ICON_SIZE + 2 * icon_pad + 0.1 * U.widget_unit);
3699
3700 node.runtime->draw_bounds.xmin = loc.x;
3701 node.runtime->draw_bounds.xmax = loc.x + node.width * UI_SCALE_FAC;
3702 node.runtime->draw_bounds.ymin = loc.y - height;
3703 node.runtime->draw_bounds.ymax = loc.y;
3704
3705 if (!is_edit && node.is_selected()) {
3706 block_emboss_set(&block, ui::EmbossType::None);
3707 const int but_x = node.runtime->draw_bounds.xmax - icon_pad - NODE_HEADER_ICON_SIZE;
3708 const int but_y = node.runtime->draw_bounds.ymax - icon_pad - NODE_HEADER_ICON_SIZE;
3709 ui::Button *but = uiDefIconBut(&block,
3711 ICON_GREASEPENCIL,
3712 but_x,
3713 but_y,
3716 nullptr,
3717 0,
3718 0,
3719 "");
3720 /* The operator already adds an undo step, so no need for the button to also add one. */
3721 button_flag_disable(but, ui::BUT_UNDO);
3722 button_func_set(but, node_comment_edit_button_cb, POINTER_FROM_INT(node.identifier), nullptr);
3723 block_emboss_set(&block, ui::EmbossType::Emboss);
3724 }
3725}
3726
3728 TreeDrawContext &tree_draw_ctx,
3729 bNodeTree &ntree,
3731 Span<ui::Block *> blocks)
3732{
3733 /* Make sure socket "used" tags are correct, for displaying value buttons. */
3734 SpaceNode *snode = CTX_wm_space_node(&C);
3735
3736 count_multi_input_socket_links(ntree, *snode);
3737
3738 for (const int i : nodes.index_range()) {
3739 bNode &node = *nodes[i];
3740 ui::Block &block = *blocks[node.index()];
3741 if (node.is_frame()) {
3742 /* Frame sizes are calculated after all other nodes have calculating their #draw_bounds. */
3743 continue;
3744 }
3745
3746 if (node.is_reroute()) {
3748 }
3749 else if (node.is_type("NodeComment"_ustr)) {
3750 comment_node_prepare_for_draw(C, ntree, node, block);
3751 }
3752 else {
3753 if (node.flag & NODE_COLLAPSED) {
3755 }
3756 else {
3757 node_update_basis(C, tree_draw_ctx, ntree, node, block);
3758 }
3759 }
3760 }
3761
3762 /* Now calculate the size of frame nodes, which can depend on the size of other nodes. */
3763 for (bNode *frame : ntree.root_frames()) {
3764 calc_node_frame_dimensions(C, tree_draw_ctx, *snode, *frame);
3765 }
3766}
3767
3768static void node_frame_get_color(const bNode &node, float r_color[4])
3769{
3770 if (node.flag & NODE_CUSTOM_COLOR) {
3771 rgba_float_args_set(r_color, node.color[0], node.color[1], node.color[2], 1.0f);
3772 }
3773 else {
3774 /* Checking for nested frames. */
3775 int depth = 0;
3776 for (const bNode *parent = node.parent; parent; parent = parent->parent) {
3777 depth++;
3778 }
3779 if (depth % 2 == 0) {
3781 }
3782 else {
3784 }
3785 }
3786}
3787
3788static void node_frame_get_label_color(const float bgcolor[4], uchar r_color[3])
3789{
3790 float text_color_rgb[3];
3791 ui::theme::get_color_3fv(TH_TEXT, text_color_rgb);
3792
3793 float text_color_hsl[3];
3794 rgb_to_hsl_v(text_color_rgb, text_color_hsl);
3795
3796 if (srgb_to_grayscale(bgcolor) > 0.5f) {
3797 /* Light background -> dark text. */
3798 text_color_hsl[2] = 0.05f;
3799 }
3800 else {
3801 /* Dark background -> light text. */
3802 text_color_hsl[2] = 0.95f;
3803 }
3804
3805 hsl_to_rgb_v(text_color_hsl, text_color_rgb);
3806 rgb_float_to_uchar(r_color, text_color_rgb);
3807}
3808
3809static void frame_node_draw_label(const bNode &node, const SpaceNode &snode)
3810{
3811 /* XXX font id is crap design */
3812 const int fontid = ui::style_get()->widget.uifont_id;
3813 const NodeFrame *data = static_cast<const NodeFrame *>(node.storage);
3814
3815 /* Setting BLF_aspect() and then counter-scaling by aspect in BLF_size() has no effect on the
3816 * rendered text size, because the two adjustments cancel each other out. But, using aspect
3817 * renders the text at higher resolution, which sharpens the rasterization of the text. */
3818 const float aspect = snode.runtime->aspect;
3819 BLF_enable(fontid, BLF_ASPECT);
3820 BLF_aspect(fontid, aspect, aspect, 1.0f);
3821 BLF_size(fontid, data->label_size * UI_SCALE_FAC / aspect);
3822
3823 const FrameNodeLayout frame_layout = frame_node_layout(node);
3824
3825 /* Calculate frame background color to determine text contrast. */
3826 float bgcolor[4];
3827 node_frame_get_color(node, bgcolor);
3828
3829 /* The Text color changes according to background color. */
3830 uchar text_color[3];
3831 node_frame_get_label_color(bgcolor, text_color);
3832 BLF_color3ubv(fontid, text_color);
3833
3834 const float label_width = BLF_width(fontid, node.label, strlen(node.label));
3835
3836 const rctf &rct = node.runtime->draw_bounds;
3837 const float label_x = BLI_rctf_cent_x(&rct) - (0.5f * label_width);
3838 const float label_y = rct.ymax - frame_layout.label_baseline;
3839
3840 /* Label. */
3841 if (frame_layout.has_label) {
3842 BLF_position(fontid, label_x, label_y, 0);
3843 BLF_draw(fontid, node.label, strlen(node.label));
3844 }
3845
3846 /* Draw text body. */
3847 if (node.id) {
3848 const Text *text = id_cast<const Text *>(node.id);
3849 const float line_spacing = BLF_height_max(fontid) * aspect;
3850 const float line_width = (BLI_rctf_size_x(&rct) - 2 * frame_layout.margin) / aspect;
3851
3852 const float x = rct.xmin + frame_layout.margin;
3853 float y = rct.ymax - frame_layout.label_height -
3854 (frame_layout.has_label ? line_spacing + frame_layout.margin : 0);
3855
3856 const int y_min = rct.ymin + frame_layout.margin;
3857
3859 BLF_clipping(fontid, rct.xmin, rct.ymin + frame_layout.margin, rct.xmax, rct.ymax);
3860
3861 BLF_wordwrap(fontid, line_width);
3862
3863 for (const TextLine &line : text->lines) {
3864 if (line.line[0]) {
3865 BLF_position(fontid, x, y, 0);
3866 ResultBLF info;
3867 BLF_draw(fontid, line.line, line.len, &info);
3868 y -= line_spacing * info.lines;
3869 }
3870 else {
3871 y -= line_spacing;
3872 }
3873 if (y < y_min) {
3874 break;
3875 }
3876 }
3877
3879 }
3880
3881 BLF_disable(fontid, BLF_ASPECT);
3882}
3883
3884static void frame_node_draw_background(const ARegion &region,
3885 const SpaceNode &snode,
3886 const bNode &node)
3887{
3888 /* Skip if out of view. */
3889 if (BLI_rctf_isect(&node.runtime->draw_bounds, &region.v2d.cur, nullptr) == false) {
3890 return;
3891 }
3892
3893 /* Use opacity from theme, but color from the frame. */
3894 float temp_theme_color[4];
3895 ui::theme::get_color_4fv(TH_NODE_FRAME, temp_theme_color);
3896 const float alpha = temp_theme_color[3];
3897
3898 float color[4];
3900 color[3] = alpha;
3901
3902 node_draw_shadow(snode, node, BASIS_RAD, alpha);
3903
3904 const rctf &rct = node.runtime->draw_bounds;
3905 draw_roundbox_corner_set(ui::CNR_ALL);
3907}
3908
3909static void frame_node_draw_outline(const ARegion &region,
3910 const SpaceNode &snode,
3911 const bNode &node)
3912{
3913 /* Skip if out of view. */
3914 const rctf &rct = node.runtime->draw_bounds;
3915 if (BLI_rctf_isect(&rct, &region.v2d.cur, nullptr) == false) {
3916 return;
3917 }
3918
3919 ColorTheme4f outline_color;
3920 bool draw_outline = false;
3921
3922 if (snode.runtime->frame_identifier_to_highlight == node.identifier) {
3923 draw_outline = true;
3924 ui::theme::get_color_shade_alpha_4fv(TH_ACTIVE, 0, -100, outline_color);
3925 }
3926 else if (node.is_selected()) {
3927 draw_outline = true;
3928 if (node.flag & NODE_ACTIVE) {
3929 ui::theme::get_color_shade_alpha_4fv(TH_ACTIVE, 0, -40, outline_color);
3930 }
3931 else {
3932 ui::theme::get_color_shade_alpha_4fv(TH_SELECT, 0, -40, outline_color);
3933 }
3934 }
3935
3936 if (draw_outline) {
3937 ui::draw_roundbox_aa(&rct, false, BASIS_RAD, outline_color);
3938 }
3939}
3940
3942 TreeDrawContext &tree_draw_ctx,
3943 const ARegion &region,
3944 const SpaceNode &snode,
3945 const bNode &node,
3946 ui::Block &block)
3947{
3948 /* Skip if out of view. */
3949 if (BLI_rctf_isect(&node.runtime->draw_bounds, &region.v2d.cur, nullptr) == false) {
3950 block_end_ex(&C,
3951 tree_draw_ctx.bmain,
3952 tree_draw_ctx.window,
3953 tree_draw_ctx.scene,
3954 tree_draw_ctx.region,
3955 tree_draw_ctx.depsgraph,
3956 &block);
3957 return;
3958 }
3959
3960 /* Label and text. */
3962
3963 node_draw_extra_info_panel(C, tree_draw_ctx, snode, node, nullptr, block);
3964
3965 block_end_ex(&C,
3966 tree_draw_ctx.bmain,
3967 tree_draw_ctx.window,
3968 tree_draw_ctx.scene,
3969 tree_draw_ctx.region,
3970 tree_draw_ctx.depsgraph,
3971 &block);
3972 block_draw(&C, &block);
3973}
3974
3976 const bContext &C, const SpaceNode &snode, bke::ComputeContextCache &compute_context_cache)
3977{
3978 const std::optional<ed::space_node::ObjectAndModifier> object_and_modifier =
3980 if (!object_and_modifier) {
3981 return {};
3982 }
3983 snode.edittree->ensure_topology_cache();
3984
3985 const ComputeContext *current_compute_context = ed::space_node::compute_context_for_edittree(
3986 snode, compute_context_cache);
3987 if (!current_compute_context) {
3988 return {};
3989 }
3990
3991 Set<const bNodeSocket *> sockets_on_gizmo_paths;
3992
3994 C,
3995 compute_context_cache,
3996 [&](const Object &gizmo_object,
3997 const NodesModifierData &gizmo_nmd,
3998 const ComputeContext &gizmo_context,
3999 const bNode &gizmo_node,
4000 const bNodeSocket &gizmo_socket) {
4001 if (&gizmo_object != object_and_modifier->object) {
4002 return;
4003 }
4004 if (&gizmo_nmd != object_and_modifier->nmd) {
4005 return;
4006 }
4008 gizmo_context,
4009 gizmo_node,
4010 gizmo_socket,
4011 [&](const ComputeContext &compute_context,
4012 const bNodeSocket &socket,
4013 const nodes::inverse_eval::ElemVariant & /*elem*/) {
4014 if (compute_context.hash() == current_compute_context->hash()) {
4015 sockets_on_gizmo_paths.add(&socket);
4016 }
4017 });
4018 });
4019
4020 return sockets_on_gizmo_paths;
4021}
4022
4026static const bNode *reroute_node_get_linked_reroute(const bNode &reroute)
4027{
4028 BLI_assert(reroute.is_reroute());
4029
4030 const bNodeSocket *input_socket = reroute.input_sockets().first();
4031 if (input_socket->directly_linked_links().is_empty()) {
4032 return nullptr;
4033 }
4034 const bNodeLink *input_link = input_socket->directly_linked_links().first();
4035 const bNode *from_node = input_link->fromnode;
4036 return from_node->is_reroute() ? from_node : nullptr;
4037}
4038
4044 const bNode &src_reroute)
4045{
4046 BLI_assert(src_reroute.is_reroute());
4047
4048 if (src_reroute.label[0] != '\0') {
4049 return src_reroute.label;
4050 }
4051
4052 Map<const bNode *, StringRef> &reroute_auto_labels = tree_draw_ctx.reroute_auto_labels;
4053
4054 StringRef label;
4055 Vector<const bNode *> reroute_path;
4056
4057 /* Traverse reroute path backwards until label, non-reroute node or link-cycle is found. */
4058 for (const bNode *reroute = &src_reroute; reroute;
4059 reroute = reroute_node_get_linked_reroute(*reroute))
4060 {
4061 reroute_path.append(reroute);
4062 if (const StringRef *label_ptr = reroute_auto_labels.lookup_ptr(reroute)) {
4063 label = *label_ptr;
4064 break;
4065 }
4066 if (reroute->label[0] != '\0') {
4067 label = reroute->label;
4068 break;
4069 }
4070 /* This makes sure that the loop eventually ends even if there are link-cycles. */
4071 reroute_auto_labels.add(reroute, "");
4072 }
4073
4074 /* Remember the label for each node on the path to avoid recomputing it. */
4075 for (const bNode *reroute : reroute_path) {
4076 reroute_auto_labels.add_overwrite(reroute, label);
4077 }
4078
4079 return label;
4080}
4081
4083 const SpaceNode &snode,
4084 const bNodeTree &ntree,
4085 const bNode &node,
4086 ui::Block &block,
4087 const bool selected)
4088{
4089 BLI_assert(node.is_reroute());
4090
4091 bNodeSocket &sock = *node.inputs.first();
4092
4094 const_cast<ID *>(&ntree.id), RNA_Node, const_cast<bNode *>(&node));
4095
4096 ColorTheme4f socket_color;
4097 ColorTheme4f outline_color;
4098
4099 node_socket_color_get(C, ntree, nodeptr, sock, socket_color);
4100 node_socket_outline_color_get(selected, sock.type, outline_color);
4101
4102 node_draw_nodesocket(&node.runtime->draw_bounds,
4103 socket_color,
4104 outline_color,
4106 sock.display_shape,
4107 snode.runtime->aspect);
4108
4109 const float2 location = float2(BLI_rctf_cent_x(&node.runtime->draw_bounds),
4110 BLI_rctf_cent_y(&node.runtime->draw_bounds));
4111 const float2 size = float2(BLI_rctf_size_x(&node.runtime->draw_bounds),
4112 BLI_rctf_size_y(&node.runtime->draw_bounds));
4113 node_socket_tooltip_set(block, sock.index_in_tree(), location, size);
4114}
4115
4116static void reroute_node_draw_label(TreeDrawContext &tree_draw_ctx,
4117 const SpaceNode &snode,
4118 const bNode &node,
4119 ui::Block &block)
4120{
4121 const bool has_label = node.label[0] != '\0';
4122 const bool use_auto_label = !has_label && (snode.overlay.flag & SN_OVERLAY_SHOW_OVERLAYS) &&
4124
4125 if (!has_label && !use_auto_label) {
4126 return;
4127 }
4128
4129 /* Don't show the automatic label, when being zoomed out. */
4130 if (!has_label && !draw_node_details(snode)) {
4131 return;
4132 }
4133
4134 const StringRef text = has_label ? node.label : reroute_node_get_auto_label(tree_draw_ctx, node);
4135 if (text.is_empty()) {
4136 return;
4137 }
4138
4139 const short width = 512;
4140 const int x = BLI_rctf_cent_x(&node.runtime->draw_bounds) - (width / 2);
4141 const int y = node.runtime->draw_bounds.ymax - 4 * UI_SCALE_FAC;
4142
4143 ui::Button *label_but = uiDefBut(
4144 &block, ui::ButtonType::Label, text, x, y, width, NODE_DY, nullptr, 0, 0, std::nullopt);
4145
4146 button_drawflag_disable(label_but, ui::BUT_TEXT_LEFT);
4147
4148 if (use_auto_label && !node.is_selected()) {
4149 button_flag_enable(label_but, ui::BUT_INACTIVE);
4150 }
4151}
4152
4153static void reroute_node_draw(const bContext &C,
4154 TreeDrawContext &tree_draw_ctx,
4155 ARegion &region,
4156 const SpaceNode &snode,
4157 bNodeTree &ntree,
4158 const bNode &node,
4159 ui::Block &block)
4160{
4161 const rctf &rct = node.runtime->draw_bounds;
4162 const View2D &v2d = region.v2d;
4163
4164 /* Skip if out of view. */
4165 if (rct.xmax < v2d.cur.xmin || rct.xmin > v2d.cur.xmax || rct.ymax < v2d.cur.ymin ||
4166 node.runtime->draw_bounds.ymin > v2d.cur.ymax)
4167 {
4168 block_end_ex(&C,
4169 tree_draw_ctx.bmain,
4170 tree_draw_ctx.window,
4171 tree_draw_ctx.scene,
4172 tree_draw_ctx.region,
4173 tree_draw_ctx.depsgraph,
4174 &block);
4175 return;
4176 }
4177
4178 if (draw_node_details(snode)) {
4179 reroute_node_draw_label(tree_draw_ctx, snode, node, block);
4180 }
4181
4182 /* Only draw the input socket, since all sockets are at the same location. */
4183 const bool selected = node.is_selected();
4184 reroute_node_draw_body(C, snode, ntree, node, block, selected);
4185
4186 block_end_ex(&C,
4187 tree_draw_ctx.bmain,
4188 tree_draw_ctx.window,
4189 tree_draw_ctx.scene,
4190 tree_draw_ctx.region,
4191 tree_draw_ctx.depsgraph,
4192 &block);
4193 block_draw(&C, &block);
4194}
4195
4196static void node_draw_comment(const bContext &C,
4197 TreeDrawContext &tree_draw_ctx,
4198 ARegion &region,
4199 bNode &node,
4200 ui::Block &block)
4201{
4202 const SpaceNode &snode = *CTX_wm_space_node(&C);
4203 const rctf &rct = node.runtime->draw_bounds;
4204 const View2D &v2d = region.v2d;
4205
4206 /* Skip if out of view. */
4207 if (rct.xmax < v2d.cur.xmin || rct.xmin > v2d.cur.xmax || rct.ymax < v2d.cur.ymin ||
4208 node.runtime->draw_bounds.ymin > v2d.cur.ymax)
4209 {
4210 block_end_ex(&C,
4211 tree_draw_ctx.bmain,
4212 tree_draw_ctx.window,
4213 tree_draw_ctx.scene,
4214 tree_draw_ctx.region,
4215 tree_draw_ctx.depsgraph,
4216 &block);
4217 return;
4218 }
4219
4220 node_draw_shadow(snode, node, BASIS_RAD, 1.0f);
4221
4222 const NodeComment &storage = *static_cast<const NodeComment *>(node.storage);
4223 const bool is_edit = bool(storage.flag & NodeCommentFlag::Edit);
4224
4225 if (!is_edit) {
4230 }
4231
4232 block_end_ex(&C,
4233 tree_draw_ctx.bmain,
4234 tree_draw_ctx.window,
4235 tree_draw_ctx.scene,
4236 tree_draw_ctx.region,
4237 tree_draw_ctx.depsgraph,
4238 &block);
4239 block_draw(&C, &block);
4240
4241 if (node.flag & SELECT && !is_edit) {
4242 ColorTheme4f outline_color;
4243 if (node.flag & NODE_ACTIVE) {
4244 ui::theme::get_color_shade_alpha_4fv(TH_ACTIVE, 0, -40, outline_color);
4245 }
4246 else {
4247 ui::theme::get_color_shade_alpha_4fv(TH_SELECT, 0, -40, outline_color);
4248 }
4249 ui::draw_roundbox_4fv(&rct, false, BASIS_RAD, outline_color);
4250 }
4251}
4252
4253static void node_draw(const bContext &C,
4254 TreeDrawContext &tree_draw_ctx,
4255 ARegion &region,
4256 const SpaceNode &snode,
4257 bNodeTree &ntree,
4258 bNode &node,
4259 ui::Block &block)
4260{
4261 if (node.is_frame()) {
4262 /* Should have been drawn before already. */
4264 }
4265 else if (node.is_type("NodeComment"_ustr)) {
4266 node_draw_comment(C, tree_draw_ctx, region, node, block);
4267 }
4268 else if (node.is_reroute()) {
4269 reroute_node_draw(C, tree_draw_ctx, region, snode, ntree, node, block);
4270 }
4271 else {
4272 const View2D &v2d = region.v2d;
4273 if (node.flag & NODE_COLLAPSED) {
4274 node_draw_collapsed(C, tree_draw_ctx, v2d, snode, ntree, node, block);
4275 }
4276 else {
4277 node_draw_basis(C, tree_draw_ctx, v2d, snode, ntree, node, block);
4278 }
4279 }
4280}
4281
4282static void add_rect_corner_positions(Vector<float2> &positions, const rctf &rect)
4283{
4284 positions.append({rect.xmin, rect.ymin});
4285 positions.append({rect.xmin, rect.ymax});
4286 positions.append({rect.xmax, rect.ymin});
4287 positions.append({rect.xmax, rect.ymax});
4288}
4289
4291 const bNodeTreeZone &zone,
4292 const Span<const bNodeTreeZone *> all_zones,
4293 MutableSpan<Vector<float2>> r_bounds_by_zone)
4294{
4295 const float node_padding = NODE_ZONE_PADDING;
4296 const float zone_padding = ZONE_ZONE_PADDING;
4297
4298 Vector<float2> &bounds = r_bounds_by_zone[zone.index];
4299 if (!bounds.is_empty()) {
4300 return;
4301 }
4302
4303 Vector<float2> possible_bounds;
4304 for (const bNodeTreeZone *child_zone : zone.child_zones) {
4305 find_bounds_by_zone_recursive(snode, *child_zone, all_zones, r_bounds_by_zone);
4306 const Span<float2> child_bounds = r_bounds_by_zone[child_zone->index];
4307 for (const float2 &pos : child_bounds) {
4308 rctf rect;
4309 BLI_rctf_init_pt_radius(&rect, pos, zone_padding);
4310 add_rect_corner_positions(possible_bounds, rect);
4311 }
4312 }
4313 for (const int child_node_id : zone.child_node_ids) {
4314 const bNode *child_node = snode.edittree->node_by_id(child_node_id);
4315 if (!child_node) {
4316 /* Can happen when drawing zone errors. */
4317 continue;
4318 }
4319 rctf rect = child_node->runtime->draw_bounds;
4320 BLI_rctf_pad(&rect, node_padding, node_padding);
4321 add_rect_corner_positions(possible_bounds, rect);
4322 }
4323 if (const bNode *input_node = zone.input_node()) {
4324 const rctf &draw_bounds = input_node->runtime->draw_bounds;
4325 rctf rect = draw_bounds;
4326 BLI_rctf_pad(&rect, node_padding, node_padding);
4327 rect.xmin = math::interpolate(draw_bounds.xmin, draw_bounds.xmax, 0.25f);
4328 add_rect_corner_positions(possible_bounds, rect);
4329 }
4330 if (const bNode *output_node = zone.output_node()) {
4331 const rctf &draw_bounds = output_node->runtime->draw_bounds;
4332 rctf rect = draw_bounds;
4333 BLI_rctf_pad(&rect, node_padding, node_padding);
4334 rect.xmax = math::interpolate(draw_bounds.xmin, draw_bounds.xmax, 0.75f);
4335 add_rect_corner_positions(possible_bounds, rect);
4336 }
4337
4338 if (snode.runtime->linkdrag) {
4339 for (const bNodeLink &link : snode.runtime->linkdrag->links) {
4340 if (link.fromnode == nullptr) {
4341 continue;
4342 }
4343 if (zone.contains_node_recursively(*link.fromnode) &&
4344 zone.output_node_id != link.fromnode->identifier)
4345 {
4346 const float2 pos = node_link_bezier_points_dragged(snode, link)[3];
4347 rctf rect;
4348 BLI_rctf_init_pt_radius(&rect, pos, node_padding);
4349 add_rect_corner_positions(possible_bounds, rect);
4350 }
4351 }
4352 }
4353
4354 Vector<int> convex_indices(possible_bounds.size());
4355 const int convex_positions_num = BLI_convexhull_2d(possible_bounds, convex_indices.data());
4356 convex_indices.resize(convex_positions_num);
4357
4358 for (const int i : convex_indices) {
4359 bounds.append(possible_bounds[i]);
4360 }
4361}
4362
4363static void node_draw_zones_and_frames(const ARegion &region,
4364 const SpaceNode &snode,
4365 const bNodeTree &ntree)
4366{
4367 const bNodeTreeZones *zones = ntree.zones();
4368 if (!zones) {
4369 /* Try use backup zones. */
4370 zones = ntree.runtime->last_valid_zones.get();
4371 }
4372 const int zones_num = zones ? zones->zones.size() : 0;
4373
4374 Array<Vector<float2>> bounds_by_zone(zones_num);
4375 Array<std::optional<bke::CurvesGeometry>> fillet_curve_by_zone(zones_num);
4376 /* Bounding box area of zones is used to determine draw order. */
4377 Array<float> bounding_box_width_by_zone(zones_num);
4378
4379 for (const int zone_i : IndexRange(zones_num)) {
4380 const bNodeTreeZone &zone = *zones->zones[zone_i];
4381
4382 find_bounds_by_zone_recursive(snode, zone, zones->zones, bounds_by_zone);
4383 const Span<float2> boundary_positions = bounds_by_zone[zone_i];
4384 const int boundary_positions_num = boundary_positions.size();
4385 if (boundary_positions_num < 3) {
4386 /* Can happen when drawing zone errors. */
4387 continue;
4388 }
4389
4390 const Bounds<float2> bounding_box = *bounds::min_max(boundary_positions);
4391 const float bounding_box_width = bounding_box.max.x - bounding_box.min.x;
4392 bounding_box_width_by_zone[zone_i] = bounding_box_width;
4393
4394 bke::CurvesGeometry boundary_curve(boundary_positions_num, 1);
4395 boundary_curve.cyclic_for_write().first() = true;
4396 boundary_curve.fill_curve_types(CURVE_TYPE_POLY);
4397 MutableSpan<float3> boundary_curve_positions = boundary_curve.positions_for_write();
4398 boundary_curve.offsets_for_write().copy_from({0, boundary_positions_num});
4399 for (const int i : boundary_positions.index_range()) {
4400 boundary_curve_positions[i] = float3(boundary_positions[i], 0.0f);
4401 }
4402
4403 fillet_curve_by_zone[zone_i] = geometry::fillet_curves_poly(
4404 boundary_curve,
4405 IndexRange(1),
4406 VArray<float>::from_single(BASIS_RAD, boundary_positions_num),
4407 VArray<int>::from_single(5, boundary_positions_num),
4408 true,
4409 {});
4410 }
4411
4412 const View2D &v2d = region.v2d;
4413 float scale;
4414 ui::view2d_scale_get(&v2d, &scale, nullptr);
4415 float line_width = 1.0f * scale;
4416 float viewport[4] = {};
4417 GPU_viewport_size_get_f(viewport);
4418
4419 const auto get_theme_id = [&](const int zone_i) {
4420 const bNode *node = zones->zones[zone_i]->output_node();
4421 if (!node) {
4422 return TH_REDALERT;
4423 }
4424 return ThemeColorID(bke::zone_type_by_node_type(node->type_legacy)->theme_id);
4425 };
4426
4427 const uint pos = GPU_vertformat_attr_add(
4428 immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32_32);
4429
4430 using ZoneOrNode = std::variant<const bNodeTreeZone *, const bNode *>;
4431 Vector<ZoneOrNode> draw_order;
4432 for (const int zone_i : IndexRange(zones_num)) {
4433 draw_order.append(zones->zones[zone_i]);
4434 }
4435 for (const bNode *node : ntree.all_nodes()) {
4436 if (node->is_frame()) {
4437 draw_order.append(node);
4438 }
4439 }
4440 auto get_zone_or_node_width = [&](const ZoneOrNode &zone_or_node) {
4441 if (const bNodeTreeZone *const *zone_p = std::get_if<const bNodeTreeZone *>(&zone_or_node)) {
4442 const bNodeTreeZone &zone = **zone_p;
4443 return bounding_box_width_by_zone[zone.index];
4444 }
4445 if (const bNode *const *node_p = std::get_if<const bNode *>(&zone_or_node)) {
4446 const bNode &node = **node_p;
4447 return BLI_rctf_size_x(&node.runtime->draw_bounds);
4448 }
4450 return 0.0f;
4451 };
4452 std::ranges::sort(draw_order, [&](const ZoneOrNode &a, const ZoneOrNode &b) {
4453 /* Draw zones with smaller bounding box on top to make them visible. */
4454 return get_zone_or_node_width(a) > get_zone_or_node_width(b);
4455 });
4456
4457 for (const ZoneOrNode &zone_or_node : draw_order) {
4458 if (const bNodeTreeZone *const *zone_p = std::get_if<const bNodeTreeZone *>(&zone_or_node)) {
4459 const bNodeTreeZone &zone = **zone_p;
4460 const int zone_i = zone.index;
4461 float zone_color[4];
4462 ui::theme::get_color_4fv(get_theme_id(zone_i), zone_color);
4463 if (zone_color[3] == 0.0f) {
4464 continue;
4465 }
4466 if (!fillet_curve_by_zone[zone_i].has_value()) {
4467 /* Can happen when drawing zone errors. */
4468 continue;
4469 }
4470 const Span<float3> fillet_boundary_positions = fillet_curve_by_zone[zone_i]->positions();
4471 /* Draw the background. */
4473 immUniformThemeColorBlend(TH_BACK, get_theme_id(zone_i), zone_color[3]);
4474
4475 immBegin(GPU_PRIM_TRI_FAN, fillet_boundary_positions.size() + 1);
4476 for (const float3 &p : fillet_boundary_positions) {
4477 immVertex3fv(pos, p);
4478 }
4479 immVertex3fv(pos, fillet_boundary_positions[0]);
4480 immEnd();
4481
4483 }
4484 if (const bNode *const *node_p = std::get_if<const bNode *>(&zone_or_node)) {
4485 const bNode &node = **node_p;
4486 frame_node_draw_background(region, snode, node);
4487 }
4488 }
4489
4491
4492 /* Draw all the contour lines after to prevent them from getting hidden by overlapping zones. */
4493 for (const ZoneOrNode &zone_or_node : draw_order) {
4494 if (const bNodeTreeZone *const *zone_p = std::get_if<const bNodeTreeZone *>(&zone_or_node)) {
4495 const bNodeTreeZone &zone = **zone_p;
4496 const int zone_i = zone.index;
4497 if (!fillet_curve_by_zone[zone_i].has_value()) {
4498 /* Can happen when drawing zone errors. */
4499 continue;
4500 }
4501 const Span<float3> fillet_boundary_positions = fillet_curve_by_zone[zone_i]->positions();
4502 /* Draw the contour lines. */
4504
4505 immUniform2fv("viewportSize", &viewport[2]);
4506 immUniform1f("lineWidth", line_width * U.pixelsize);
4507
4509 *zone.output_node_id) ?
4510 TH_REDALERT :
4511 get_theme_id(zone_i);
4512
4513 immUniformThemeColorAlpha(theme_id, 1.0f);
4514 immBegin(GPU_PRIM_LINE_STRIP, fillet_boundary_positions.size() + 1);
4515 for (const float3 &p : fillet_boundary_positions) {
4516 immVertex3fv(pos, p);
4517 }
4518 immVertex3fv(pos, fillet_boundary_positions[0]);
4519 immEnd();
4520
4522 }
4523 if (const bNode *const *node_p = std::get_if<const bNode *>(&zone_or_node)) {
4524 const bNode &node = **node_p;
4525 frame_node_draw_outline(region, snode, node);
4526 }
4527 }
4528
4530}
4531
4532static void draw_frame_overlays(const bContext &C,
4533 TreeDrawContext &tree_draw_ctx,
4534 const ARegion &region,
4535 const SpaceNode &snode,
4536 const bNodeTree &ntree,
4537 Span<ui::Block *> blocks)
4538{
4539 for (const bNode *node : ntree.nodes_by_type("NodeFrame"_ustr)) {
4540 frame_node_draw_overlay(C, tree_draw_ctx, region, snode, *node, *blocks[node->index()]);
4541 }
4542}
4543
4549static std::optional<float2> find_visible_center_of_link(const View2D &v2d,
4550 const bNodeLink &link,
4551 const float radius,
4552 const float region_padding)
4553{
4554 /* Compute center of the link because that's used as "ideal" position. */
4555 const float2 start = socket_link_connection_location(*link.fromnode, *link.fromsock, link);
4556 const float2 end = socket_link_connection_location(*link.tonode, *link.tosock, link);
4557 const float2 center = math::midpoint(start, end);
4558
4559 /* The rectangle that we would like to stay within if possible. */
4560 rctf inner_rect = v2d.cur;
4561 BLI_rctf_pad(&inner_rect, -(region_padding + radius), -(region_padding + radius));
4562
4563 if (BLI_rctf_isect_pt_v(&inner_rect, center)) {
4564 /* The center is visible. */
4565 return center;
4566 }
4567
4568 /* The rectangle containing all points which are valid result positions. */
4569 rctf outer_rect = v2d.cur;
4570 BLI_rctf_pad(&outer_rect, radius, radius);
4571
4572 /* Get the straight individual link segments. */
4573 std::array<float2, NODE_LINK_RESOL + 1> link_points;
4574 node_link_bezier_points_evaluated(link, link_points);
4575
4576 const float required_socket_distance = UI_UNIT_X;
4577 /* Define a cost function that returns a value that is larger the worse the given position is.
4578 * The point on the link with the lowest cost will be picked. */
4579 const auto cost_function = [&](const float2 &p) -> float {
4580 const float distance_to_inner_rect = std::max(BLI_rctf_length_x(&inner_rect, p.x),
4581 BLI_rctf_length_y(&inner_rect, p.y));
4582 const float distance_to_center = math::distance(p, center);
4583
4584 /* Set a high cost when the point is close to a socket. The distance to the center still has to
4585 * be taken account though. Otherwise there is bad behavior when both sockets are close to the
4586 * point. */
4587 const float distance_to_socket = std::min(math::distance(p, start), math::distance(p, end));
4588 if (distance_to_socket < required_socket_distance) {
4589 return 1e5f + distance_to_center;
4590 }
4591 return
4592 /* The larger the distance to the link center, the higher the cost.
4593 * The importance of this distance decreases the further the center is away. */
4594 std::sqrt(distance_to_center)
4595 /* The larger the distance to the inner rectangle, the higher the cost. Apply an additional
4596 * factor because it's more important that the position stays visible than that it is at
4597 * the center. */
4598 + 10.0f * distance_to_inner_rect;
4599 };
4600
4601 /* Iterate over visible points on the link, compute the cost of each and pick the best one. A
4602 * more direct algorithm to find a good position would be nice. However, that seems to be
4603 * surprisingly tricky to achieve without resulting in very "jumpy" positions, especially when
4604 * the link is colinear to the region border. */
4605 float best_cost;
4606 std::optional<float2> best_position;
4607 for (const int i : IndexRange(link_points.size() - 1)) {
4608 float2 p0 = link_points[i];
4609 float2 p1 = link_points[i + 1];
4610 if (!BLI_rctf_clamp_segment(&outer_rect, p0, p1)) {
4611 continue;
4612 }
4613 const float length = math::distance(p0, p1);
4614 const float point_distance = 1.0f;
4615 /* Might be possible to do a smarter scan of the cost function using some sort of binary sort,
4616 * but it's not entirely straight forward because the cost function is not monotonic. */
4617 const int points_to_check = std::max(2, 1 + int(length / point_distance));
4618 for (const int j : IndexRange(points_to_check)) {
4619 const float t = float(j) / (points_to_check - 1);
4620 const float2 p = math::interpolate(p0, p1, t);
4621 const float cost = cost_function(p);
4622 if (!best_position.has_value() || cost < best_cost) {
4623 best_cost = cost;
4624 best_position = p;
4625 }
4626 }
4627 }
4628 return best_position;
4629}
4630
4631static void draw_link_errors(const bContext &C,
4632 SpaceNode &snode,
4633 const bNodeLink &link,
4634 const Span<bke::NodeLinkError> errors,
4635 ui::Block &invalid_links_block)
4636{
4637 const ARegion &region = *CTX_wm_region(&C);
4638 if (errors.is_empty()) {
4639 return;
4640 }
4641 if (!link.fromsock || !link.tosock || !link.fromnode || !link.tonode) {
4642 /* Likely because the link is being dragged. */
4643 return;
4644 }
4645
4646 /* Generate full tooltip from potentially multiple errors. */
4647 std::string error_tooltip;
4648 if (errors.size() == 1) {
4649 error_tooltip = errors[0].tooltip;
4650 }
4651 else {
4652 for (const bke::NodeLinkError &error : errors) {
4653 error_tooltip += fmt::format("\u2022 {}\n", error.tooltip);
4654 }
4655 }
4656
4657 const float bg_radius = UI_UNIT_X * 0.5f;
4658 const float bg_corner_radius = UI_UNIT_X * 0.2f;
4659 const float icon_size = UI_UNIT_X;
4660 const float region_padding = UI_UNIT_X * 0.5f;
4661
4662 /* Compute error icon location. */
4663 std::optional<float2> draw_position_opt = find_visible_center_of_link(
4664 region.v2d, link, bg_radius, region_padding);
4665 if (!draw_position_opt.has_value()) {
4666 return;
4667 }
4668 const int2 draw_position = int2(draw_position_opt.value());
4669
4670 /* Draw a background for the error icon. */
4671 rctf bg_rect;
4672 BLI_rctf_init_pt_radius(&bg_rect, float2(draw_position), bg_radius);
4673 ColorTheme4f bg_color, alert_color;
4676 alert_color.a = std::min(alert_color.a + 0.4f, 0.8f);
4677 ui::theme::get_color_blend_3f(TH_REDALERT, TH_NODE, 1.0f - alert_color.a, bg_color);
4678 bg_color.a = 1.0f;
4679 draw_roundbox_corner_set(ui::CNR_ALL);
4680 ui::draw_dropshadow(&bg_rect, bg_corner_radius, UI_UNIT_X * 0.2f, snode.runtime->aspect, 0.5f);
4681 ui::draw_roundbox_4fv(&bg_rect, true, bg_corner_radius, bg_color);
4682
4683 /* Draw the icon itself with a tooltip. */
4684 block_emboss_set(&invalid_links_block, ui::EmbossType::None);
4685 ui::Button *but = uiDefIconBut(&invalid_links_block,
4687 ICON_STATUS_WARNING_FILLED,
4688 draw_position.x - icon_size / 2,
4689 draw_position.y - icon_size / 2,
4690 icon_size,
4691 icon_size,
4692 nullptr,
4693 0,
4694 0,
4695 std::nullopt);
4696 button_func_quick_tooltip_set(
4697 but, [tooltip = std::move(error_tooltip)](const ui::Button * /*but*/) { return tooltip; });
4698}
4699
4701{
4702 Scene *scene = CTX_data_scene(&C);
4703 wmWindow *window = CTX_wm_window(&C);
4704 ARegion *region = CTX_wm_region(&C);
4705 return *block_begin(&C, scene, window, region, "invalid_links", ui::EmbossType::None);
4706}
4707
4708#define USE_DRAW_TOT_UPDATE
4709
4710static void node_draw_nodetree(const bContext &C,
4711 TreeDrawContext &tree_draw_ctx,
4712 ARegion &region,
4713 SpaceNode &snode,
4714 bNodeTree &ntree,
4716 Span<ui::Block *> blocks)
4717{
4718#ifdef USE_DRAW_TOT_UPDATE
4719 BLI_rctf_init_minmax(&region.v2d.tot);
4720#endif
4721
4722 for (const int i : nodes.index_range()) {
4723#ifdef USE_DRAW_TOT_UPDATE
4724 /* Unrelated to background nodes, update the v2d->tot,
4725 * can be anywhere before we draw the scroll bars. */
4726 BLI_rctf_union(&region.v2d.tot, &nodes[i]->runtime->draw_bounds);
4727#endif
4728 }
4729
4730 /* Node lines. */
4732 nodelink_batch_start(snode);
4733
4734 for (const bNodeLink *link : ntree.all_links()) {
4736 node_draw_link(C, region.v2d, snode, *link, false);
4737 }
4738 }
4739
4740 /* Draw selected node links after the unselected ones, so they are shown on top. */
4741 for (const bNodeLink *link : ntree.all_links()) {
4743 node_draw_link(C, region.v2d, snode, *link, true);
4744 }
4745 }
4746
4747 nodelink_batch_end(snode);
4748
4750
4751 draw_frame_overlays(C, tree_draw_ctx, region, snode, ntree, blocks);
4752
4753 /* Draw foreground nodes, last nodes in front. */
4754 for (const int i : nodes.index_range()) {
4755 bNode &node = *nodes[i];
4756 if (node.is_frame()) {
4757 /* Those nodes are drawn before already. */
4758 continue;
4759 }
4760
4761 node_draw(C, tree_draw_ctx, region, snode, ntree, node, *blocks[node.index()]);
4762 }
4763
4764 ui::Block &invalid_links_block = invalid_links_uiblock_init(C);
4765 for (auto &&item : ntree.runtime->link_errors.items()) {
4766 if (const bNodeLink *link = item.key.try_find(ntree)) {
4767 if (!bke::node_link_is_hidden(*link)) {
4768 draw_link_errors(C, snode, *link, item.value, invalid_links_block);
4769 }
4770 }
4771 }
4772 block_end(&C, &invalid_links_block);
4773 block_draw(&C, &invalid_links_block);
4774}
4775
4776/* Draw the breadcrumb on the top of the editor. */
4777static void draw_tree_path(const bContext &C, ARegion &region)
4778{
4781
4782 const rcti *rect = ED_region_visible_rect(&region);
4783
4784 const uiStyle *style = ui::style_get_dpi();
4785 const float padding_x = 16 * UI_SCALE_FAC;
4786 const int x = rect->xmin + padding_x;
4787 const int y = region.winy - UI_UNIT_Y * 0.6f;
4788 const int width = BLI_rcti_size_x(rect) - 2 * padding_x;
4789
4790 ui::Block *block = block_begin(&C, &region, __func__, ui::EmbossType::None);
4791 ui::Layout &layout = ui::block_layout(
4792 block, ui::LayoutDirection::Vertical, ui::LayoutType::Panel, x, y, width, 1, 0, style);
4793
4795 ui::template_breadcrumbs(layout, context_path);
4796
4798 block_end(&C, block);
4799 block_draw(&C, block);
4800
4802}
4803
4804static void snode_setup_v2d(SpaceNode &snode,
4805 ARegion &region,
4806 const float2 &center,
4807 const float size_x)
4808{
4809 View2D &v2d = region.v2d;
4811 const float aspect = BLI_rctf_size_x(&v2d.cur) / BLI_rctf_size_y(&v2d.cur);
4812 BLI_rctf_resize(&v2d.cur, size_x, size_x / aspect);
4813
4814 /* Shift view to node tree center. */
4815 ui::view2d_center_set(&v2d, center[0], center[1]);
4817
4818 snode.runtime->aspect = BLI_rctf_size_x(&v2d.cur) / float(region.winx);
4819}
4820
4822 const SpaceNode &snode,
4823 const bNodeTree &ntree,
4824 bke::ComputeContextCache &compute_context_cache)
4825{
4827 for (const bNode *index_switch_node : ntree.nodes_by_type("GeometryNodeIndexSwitch"_ustr)) {
4828 const bNodeSocket &index_socket = index_switch_node->input_socket(0);
4830 snode, compute_context_cache, index_socket);
4831 if (!compute_context) {
4832 continue;
4833 }
4834 const std::optional<nodes::NodeInContext> menu_switch = nodes::find_origin_index_menu_switch(
4835 {compute_context, &index_socket}, compute_context_cache);
4836 if (!menu_switch) {
4837 continue;
4838 }
4839 result.add(index_switch_node, menu_switch->node);
4840 }
4841 return result;
4842}
4843
4844static void draw_nodetree(const bContext &C, ARegion &region, bNodeTree &ntree)
4845{
4846 SpaceNode *snode = CTX_wm_space_node(&C);
4847 ntree.ensure_topology_cache();
4848
4850
4852
4853 bke::ComputeContextCache compute_context_cache;
4854
4855 TreeDrawContext tree_draw_ctx;
4856 tree_draw_ctx.bmain = CTX_data_main(&C);
4857 tree_draw_ctx.window = CTX_wm_window(&C);
4858 tree_draw_ctx.scene = CTX_data_scene(&C);
4859 tree_draw_ctx.region = CTX_wm_region(&C);
4860 tree_draw_ctx.depsgraph = CTX_data_depsgraph_pointer(&C);
4861 tree_draw_ctx.extra_info_rows_per_node.reinitialize(nodes.size());
4863 find_menu_switch_sources_for_index_switch_nodes(*snode, ntree, compute_context_cache);
4864
4865 if (ELEM(ntree.type, NTREE_GEOMETRY, NTREE_COMPOSIT)) {
4868 log.ensure_node_warnings(*tree_draw_ctx.bmain);
4869 log.ensure_execution_times();
4870 log.ensure_node_image_previews();
4871 });
4872 }
4873
4874 BLI_SCOPED_DEFER([&]() { ntree.runtime->sockets_on_active_gizmo_paths.clear(); });
4875 if (ntree.type == NTREE_GEOMETRY) {
4876 const WorkSpace *workspace = CTX_wm_workspace(&C);
4878 workspace->viewer_path, *snode);
4879
4880 /* This set of socket is used when drawing links to determine which links should use the
4881 * special gizmo drawing. */
4883 C, *snode, compute_context_cache);
4884 }
4885 else if (ntree.type == NTREE_SHADER) {
4886 if (USER_EXPERIMENTAL_TEST(&U, use_shader_node_previews) &&
4890 {
4891 tree_draw_ctx.nested_group_infos = get_nested_previews(C, *snode);
4892 }
4893 {
4894 std::lock_guard lock(ntree.runtime->shader_node_errors_mutex);
4895 /* Make a local copy to avoid mutex access for each node. Typically, there are only very few
4896 * error message. */
4897 tree_draw_ctx.shader_node_errors = ntree.runtime->shader_node_errors;
4898 }
4899 }
4900
4901 for (const int i : nodes.index_range()) {
4902 const bNode &node = *nodes[i];
4903 tree_draw_ctx.extra_info_rows_per_node[node.index()] = node_get_extra_info(
4904 C, tree_draw_ctx, *snode, node);
4905 }
4906
4907 node_update_nodetree(C, tree_draw_ctx, ntree, nodes, blocks);
4908 node_draw_zones_and_frames(region, *snode, ntree);
4909 node_draw_nodetree(C, tree_draw_ctx, region, *snode, ntree, nodes, blocks);
4910}
4911
4913{
4914 float color[3];
4916 GPU_clear_color(color[0], color[1], color[2], 1.0);
4917}
4918
4919void node_draw_space(const bContext &C, ARegion &region)
4920{
4921 wmWindow *win = CTX_wm_window(&C);
4922 SpaceNode &snode = *CTX_wm_space_node(&C);
4923 View2D &v2d = region.v2d;
4924 Scene &scene = *CTX_data_scene(&C);
4925 Main &bmain = *CTX_data_main(&C);
4926
4927 /* Setup off-screen buffers. */
4928 GPUViewport *viewport = WM_draw_region_get_viewport(&region);
4929
4930 gpu::FrameBuffer *framebuffer_overlay = GPU_viewport_framebuffer_overlay_get(viewport);
4931 GPU_framebuffer_bind_no_srgb(framebuffer_overlay);
4932
4936
4937 /* XXX `snode->runtime->cursor` set in coordinate-space for placing new nodes,
4938 * used for drawing noodles too. */
4940 win->runtime->eventstate->xy[0] - region.winrct.xmin,
4941 win->runtime->eventstate->xy[1] - region.winrct.ymin,
4942 &snode.runtime->cursor[0],
4943 &snode.runtime->cursor[1]);
4944 snode.runtime->cursor[0] /= UI_SCALE_FAC;
4945 snode.runtime->cursor[1] /= UI_SCALE_FAC;
4946
4948
4949 /* Only set once. */
4951
4952 /* Nodes. */
4954
4957
4958 /* Draw parent node trees. */
4959 if (snode.treepath.last()) {
4960 bNodeTreePath *path = snode.treepath.last();
4961
4962 /* Update tree path name (drawn in the bottom left). */
4963 ID *name_id = (path->nodetree && path->nodetree != snode.nodetree) ? &path->nodetree->id :
4964 snode.id;
4965
4966 if (name_id && UNLIKELY(!STREQ(path->display_name, name_id->name + 2))) {
4967 STRNCPY_UTF8(path->display_name, name_id->name + 2);
4968 }
4969
4970 /* Current View2D center, will be set temporarily for parent node trees. */
4971 float2 center;
4972 ui::view2d_center_get(&v2d, &center.x, &center.y);
4973 const float size_x = BLI_rctf_size_x(&v2d.cur);
4974
4975 /* Store new view center in path and current edit tree. */
4976 copy_v2_v2(path->view_center, center);
4977 path->view_width = size_x;
4978 if (snode.edittree) {
4979 copy_v2_v2(snode.edittree->view_center, center);
4980 snode.edittree->view_width = size_x;
4981 }
4982
4983 /* Top-level edit tree. */
4984 bNodeTree *ntree = path->nodetree;
4985 if (ntree) {
4986 snode_setup_v2d(snode, region, center, size_x);
4987
4988 /* Backdrop. */
4989 draw_nodespace_back_pix(C, region, snode, path->parent_key);
4990
4991 {
4994
4995 const bool show_render_region = ED_node_is_compositor(&snode) &&
4998 snode.flag & SNODE_BACKDRAW;
4999 if (show_render_region) {
5000 int render_size_x, render_size_y;
5001 BKE_render_resolution(&scene.r, true, &render_size_x, &render_size_y);
5002 rcti render_region;
5003 BLI_rcti_init(&render_region, 0, render_size_x, 0, render_size_y);
5004
5005 ED_region_render_region_draw(region.winx / 2 + snode.xof,
5006 region.winy / 2 + snode.yof,
5007 &render_region,
5008 snode.zoom,
5009 snode.zoom,
5011 }
5013 }
5014
5015 {
5016 float original_proj[4][4];
5017 GPU_matrix_projection_get(original_proj);
5018
5021
5022 wmOrtho2_pixelspace(region.winx, region.winy);
5023
5025
5027 GPU_matrix_projection_set(original_proj);
5028 }
5029
5030 draw_nodetree(C, region, *ntree);
5031 }
5032
5033 /* Temporary links. */
5035 GPU_line_smooth(true);
5036 if (snode.runtime->linkdrag) {
5037 for (const bNodeLink &link : snode.runtime->linkdrag->links) {
5038 node_draw_link_dragged(C, v2d, snode, link);
5039 }
5040 }
5041 GPU_line_smooth(false);
5043
5045 /* Draw grease-pencil annotations. */
5047 }
5048 }
5049 else {
5050
5051 /* Backdrop. */
5053 }
5054
5056
5057 /* Reset view matrix. */
5059
5060 int text_info_y_offset = 0;
5062 if (snode.flag & SNODE_SHOW_GPENCIL && snode.treepath.last()) {
5063 /* Draw grease-pencil (screen strokes, and also paint-buffer). */
5065 }
5066
5067 /* Draw context path. */
5068 if (snode.overlay.flag & SN_OVERLAY_SHOW_PATH) {
5069 text_info_y_offset += UI_UNIT_Y;
5070 draw_tree_path(C, region);
5071 }
5072 }
5073
5074 const bool show_text_info = ED_node_is_compositor(&snode) &&
5077 snode.flag & SNODE_BACKDRAW);
5078
5079 if (show_text_info) {
5080 int render_size_x, render_size_y;
5081 BKE_render_resolution(&scene.r, true, &render_size_x, &render_size_y);
5082
5083 /* Use same padding as path tree. */
5084 const rcti *rect = ED_region_visible_rect(&region);
5085 int xoffset = rect->xmin + 16 * UI_SCALE_FAC;
5086 int yoffset = rect->ymax - (0.4f * UI_UNIT_Y) - text_info_y_offset;
5087
5088 int viewer_size_x = 0;
5089 int viewer_size_y = 0;
5090 void *lock;
5091
5092 Image *ima = BKE_image_ensure_viewer(&bmain, IMA_TYPE_COMPOSITE, "Viewer Node");
5093 ImBuf *ibuf = BKE_image_acquire_ibuf(ima, nullptr, &lock);
5094 if (ibuf) {
5095 viewer_size_x = ibuf->x;
5096 viewer_size_y = ibuf->y;
5097 }
5098 BKE_image_release_ibuf(ima, ibuf, lock);
5099
5101 render_size_x, render_size_y, viewer_size_x, viewer_size_y, xoffset, yoffset);
5102 }
5103
5104 /* Scrollers. */
5105
5106 /* Hide the right scrollbar while a right-aligned region
5107 * is open. Otherwise we can have two scroll bars. #141225 */
5108 ScrArea *area = CTX_wm_area(&C);
5109 bool sidebar = false;
5110 for (ARegion &region : area->regionbase) {
5111 if (region.alignment == RGN_ALIGN_RIGHT && region.overlap && !(region.flag & RGN_FLAG_HIDDEN))
5112 {
5113 sidebar = true;
5114 break;
5115 }
5116 }
5117
5118 if (sidebar) {
5120 }
5121 else {
5122 v2d.scroll |= V2D_SCROLL_RIGHT;
5123 }
5124
5125 ui::view2d_scrollers_draw(&v2d, nullptr);
5126}
5127
5128} // namespace ed::space_node
5129
5130} // namespace blender
Low-level operations for curves.
#define SELECT
Definition BKE_mask.hh:19
#define NODE_CLASS_OUTPUT
Definition BKE_node.hh:479
#define NODE_CLASS_INTERFACE
Definition BKE_node.hh:490
#define NODE_CUSTOM_GROUP
Definition BKE_node.hh:870
#define NODE_CLASS_MATTE
Definition BKE_node.hh:485
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:484
#define NODE_CUSTOM
Definition BKE_node.hh:864
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:492
#define NODE_GROUP_OUTPUT
Definition BKE_node.hh:869
#define NODE_CLASS_DISTORT
Definition BKE_node.hh:486
#define NODE_CLASS_OP_VECTOR
Definition BKE_node.hh:481
#define NODE_GROUP
Definition BKE_node.hh:865
#define NODE_CLASS_LAYOUT
Definition BKE_node.hh:494
#define NODE_CLASS_OP_COLOR
Definition BKE_node.hh:480
#define NODE_CLASS_INPUT
Definition BKE_node.hh:478
#define NODE_CLASS_OP_FILTER
Definition BKE_node.hh:482
#define NODE_FRAME
Definition BKE_node.hh:866
#define NODE_CLASS_GROUP
Definition BKE_node.hh:483
#define NODE_CLASS_ATTRIBUTE
Definition BKE_node.hh:493
#define NODE_CLASS_TEXTURE
Definition BKE_node.hh:488
#define NODE_CLASS_SHADER
Definition BKE_node.hh:491
#define NODE_CLASS_SCRIPT
Definition BKE_node.hh:489
#define NODE_EVALUATE_CLOSURE
#define GEO_NODE_STORE_NAMED_ATTRIBUTE
#define GEO_NODE_VIEWER
#define GEO_NODE_REMOVE_ATTRIBUTE
#define GEO_NODE_FOREACH_GEOMETRY_ELEMENT_OUTPUT
#define GEO_NODE_INPUT_NAMED_ATTRIBUTE
#define GEO_NODE_SIMULATION_OUTPUT
#define CMP_NODE_OUTPUT_FILE
#define GEO_NODE_REPEAT_OUTPUT
General operations, lookup, etc. for blender objects.
#define BLI_SCOPED_DEFER(function_to_defer)
#define STRNCPY_UTF8(dst, src)
#define RPT_(msgid)
#define TIP_(msgid)
#define CTX_IFACE_(context, msgid)
#define IFACE_(msgid)
#define ID_IS_LINKED(_id)
Definition DNA_ID.h:697
#define ID_IS_EDITABLE(_id)
Definition DNA_ID.h:708
#define UI_SCALE_FAC
#define UI_INV_SCALE_FAC
#define USER_EXPERIMENTAL_TEST(userdef, member)
#define NODE_GRID_STEP_SIZE
Definition ED_node_c.hh:32
#define REGION_DRAW_POST_VIEW
#define REGION_DRAW_PRE_VIEW
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define UI_ALPHA_CHECKER_LIGHT
#define UI_UNIT_Y
#define UI_ALPHA_CHECKER_DARK
#define UI_UNIT_X
#define NC_NODE
Definition WM_types.hh:407
#define ND_DISPLAY
Definition WM_types.hh:534
volatile int lock
#define BLI_assert_unreachable()
#define BLI_assert_unreachable_static_t(T)
#define STREQLEN(a, b, n)
#define POINTER_FROM_INT(i)
#define POINTER_AS_INT(i)
#define UNLIKELY(x)
#define ELEM(...)
#define STREQ(a, b)
btScalar max
const T * end() const
Definition BLI_array.hh:336
IndexRange index_range() const
Definition BLI_array.hh:371
const T * begin() const
Definition BLI_array.hh:332
ChannelStorageType a
const ComputeContextHash & hash() const
constexpr IndexRange()=default
const Value * lookup_ptr(const Key &key) const
Definition BLI_map.hh:508
bool add_overwrite(const Key &key, const Value &value)
Definition BLI_map.hh:325
bool add(const Key &key, const Value &value)
Definition BLI_map.hh:295
int64_t size() const
Definition BLI_map.hh:976
constexpr int64_t size() const
Definition BLI_span.hh:499
bool contains(const Key &key) const
Definition BLI_set.hh:310
bool add(const Key &key)
Definition BLI_set.hh:248
constexpr Span drop_back(int64_t n) const
Definition BLI_span.hh:186
constexpr int64_t size() const
Definition BLI_span.hh:256
constexpr const T & last(const int64_t n=0) const
Definition BLI_span.hh:329
constexpr IndexRange index_range() const
Definition BLI_span.hh:405
constexpr bool is_empty() const
Definition BLI_span.hh:264
constexpr const char * c_str() const
const char * c_str() const
StringRefNull ref() const
static VArray from_single(T value, const int64_t size)
int64_t size() const
void append(const T &value)
const T & last(const int64_t n=0) const
bool is_empty() const
IndexRange index_range() const
void resize(const int64_t new_size)
MutableSpan< float3 > positions_for_write()
MutableSpan< int > offsets_for_write()
void fill_curve_types(CurveType type)
MutableSpan< bool > cyclic_for_write()
std::optional< float > header_center_y
std::optional< bNodePanelExtent > content_extent
const nodes::SocketDeclaration * declaration
MultiValueMap< NodeLinkKey, NodeLinkError > link_errors
Set< const bNodeSocket * > sockets_on_active_gizmo_paths
std::shared_ptr< bNodeTreeZones > last_valid_zones
Map< int32_t, VectorSet< nodes::NodeWarning > > shader_node_errors
std::optional< int > output_node_id
const bNode * output_node() const
bool contains_node_recursively(const bNode &node) const
std::optional< int > input_node_id
Vector< bNodeTreeZone * > child_zones
const bNode * input_node() const
Vector< bNodeTreeZone * > zones
const bNodeTreeZone * get_zone_by_node(const int32_t node_id) const
constexpr bool startswith(StringRef prefix) const
Vector< PanelDeclaration * > panels
std::optional< std::string > translation_context
Vector< ItemDeclaration * > items
const SocketDeclaration * panel_input_decl() const
std::unique_ptr< CustomSocketDrawFn > custom_draw_fn
NodeTreeLog * get_main_tree_log(const bke::bNodeTreeZone *zone) const
Definition eval_log.cc:1116
void foreach_tree_log(FunctionRef< void(NodeTreeLog &)> callback) const
Definition eval_log.cc:1143
Map< StringRefNull, NamedAttributeUsage > used_named_attributes
VectorSet< NodeWarning > warnings
Vector< StringRefNull > debug_messages
std::chrono::nanoseconds execution_time
NodeLog * find_node_log(int32_t identifier) const
Definition eval_log.cc:718
static ContextualNodeTreeLogs get_contextual_tree_logs(const SpaceNode &snode)
Definition eval_log.cc:1048
#define storage(slot, qualifiers)
#define attribute(slot)
#define log
#define round
float length(VecOp< float, D >) RET
float3x3 scale(float3x3 mat, float2 scale)
std::unique_ptr< IDProperty, IDPropertyDeleter > create_group(StringRef prop_name, eIDPropertyFlag flags={})
Allocate a new IDProperty of type IDP_GROUP.
const bNodeZoneType * zone_type_by_node_type(const int node_type)
std::string node_label(const bNodeTree &ntree, const bNode &node)
Definition node.cc:5732
bool node_link_is_selected(const bNodeLink &link)
Definition node.cc:4770
std::optional< StringRefNull > node_socket_short_label(const bNodeSocket &sock)
Definition node.cc:5747
const char * node_socket_translation_context(const bNodeSocket &sock)
Definition node.cc:5770
bNodeType NodeTypeUndefined
Definition node.cc:134
Span< int > all_zone_node_types()
const bNodeInstanceKey NODE_INSTANCE_KEY_NONE
Definition node.cc:5601
StringRefNull node_socket_label(const bNodeSocket &sock)
Definition node.cc:5758
bool node_link_is_hidden(const bNodeLink &link)
Definition node.cc:4711
std::optional< Bounds< T > > min_max(const std::optional< Bounds< T > > &a, const T &b)
Definition BLI_bounds.hh:56
static bool compare_node_depth(const bNode *a, const bNode *b)
Definition node_draw.cc:204
static rctf calc_node_frame_dimensions(const bContext &C, TreeDrawContext &tree_draw_ctx, const SpaceNode &snode, bNode &node)
static void determine_visible_panels_impl_recursive(const bNode &node, const nodes::PanelDeclaration &panel_decl, const Span< bool > potentially_visible_states, MutableSpan< bool > r_result)
Definition node_draw.cc:659
static void node_draw_sockets(const bContext &C, ui::Block &block, const SpaceNode &snode, const bNodeTree &ntree, const bNode &node)
static void reroute_node_draw_label(TreeDrawContext &tree_draw_ctx, const SpaceNode &snode, const bNode &node, ui::Block &block)
const ComputeContext * compute_context_for_edittree_socket(const SpaceNode &snode, bke::ComputeContextCache &compute_context_cache, const bNodeSocket &socket)
static void add_flat_items_for_panel(bNode &node, const nodes::PanelDeclaration &panel_decl, const Span< bool > panel_visibility, Vector< FlatNodeItem > &r_items)
Definition node_draw.cc:751
float node_socket_calculate_height(const bNodeSocket &socket)
Definition node_edit.cc:753
static bool node_update_basis_buttons(const bContext &C, bNodeTree &ntree, bNode &node, FunctionRef< nodes::DrawNodeLayoutFn > draw_buttons, ui::Block &block, int &dy)
Definition node_draw.cc:350
rctf node_frame_rect_inside(const SpaceNode &snode, const bNode &node)
int node_get_resize_cursor(NodeResizeDirection directions)
static float get_margin_to_bottom(const Span< FlatNodeItem > items)
Definition node_draw.cc:864
static void node_socket_outline_color_get(const bool selected, const int socket_type, float r_outline_color[4])
static void mark_sockets_collapsed_recursive(bNode &node, const int node_left_x, const nodes::PanelDeclaration &visible_panel_decl, const nodes::PanelDeclaration &panel_decl)
static const bNode * reroute_node_get_linked_reroute(const bNode &reroute)
void tree_draw_order_update(bNodeTree &ntree)
Definition node_draw.cc:265
void node_socket_draw(bNodeSocket *sock, const rcti *rect, const float color[4], float scale)
static Map< const bNode *, const bNode * > find_menu_switch_sources_for_index_switch_nodes(const SpaceNode &snode, const bNodeTree &ntree, bke::ComputeContextCache &compute_context_cache)
static void update_collapsed_sockets(bNode &node, const int node_left_x)
static void draw_link_errors(const bContext &C, SpaceNode &snode, const bNodeLink &link, const Span< bke::NodeLinkError > errors, ui::Block &invalid_links_block)
static void node_draw_comment(const bContext &C, TreeDrawContext &tree_draw_ctx, ARegion &region, bNode &node, ui::Block &block)
static void tag_final_panel(bNode &node, const Span< FlatNodeItem > items)
static void node_update_basis(const bContext &C, TreeDrawContext &tree_draw_ctx, bNodeTree &ntree, bNode &node, ui::Block &block)
static float get_margin_between_elements(const Span< FlatNodeItem > items, const int next_index)
Definition node_draw.cc:887
static float node_tree_view_scale(const SpaceNode &snode)
static void determine_potentially_visible_panels(const bNode &node, MutableSpan< bool > r_result)
Definition node_draw.cc:650
static void frame_node_draw_background(const ARegion &region, const SpaceNode &snode, const bNode &node)
static void node_draw_node_group_indicator(const SpaceNode &snode, const bNode &node, const rctf &rect, const float radius, const float color[4])
static void node_draw_nodetree(const bContext &C, TreeDrawContext &tree_draw_ctx, ARegion &region, SpaceNode &snode, bNodeTree &ntree, Span< bNode * > nodes, Span< ui::Block * > blocks)
float2 node_from_view(const float2 &co)
Definition node_draw.cc:339
void node_draw_link_bezier(const bContext &C, const View2D &v2d, const SpaceNode &snode, const bNodeLink &link, const int th_col1, const int th_col2, const int th_col3, const bool selected)
Definition drawnode.cc:2466
std::optional< ObjectAndModifier > get_geometry_nodes_modifier_for_node_editor(const SpaceNode &snode)
static std::optional< std::chrono::nanoseconds > node_get_execution_time(const TreeDrawContext &tree_draw_ctx, const SpaceNode &snode, const bNode &node)
static float get_margin_from_top(const Span< FlatNodeItem > items)
Definition node_draw.cc:842
ImBuf * node_preview_acquire_ibuf(bNodeTree &ntree, NestedTreePreviews &tree_previews, const bNode &node)
static void node_draw(const bContext &C, TreeDrawContext &tree_draw_ctx, ARegion &region, const SpaceNode &snode, bNodeTree &ntree, bNode &node, ui::Block &block)
std::array< float2, 4 > node_link_bezier_points_dragged(const SpaceNode &snode, const bNodeLink &link)
Definition drawnode.cc:2523
bNodeSocket * node_find_indicated_socket(SpaceNode &snode, ARegion &region, const float2 &cursor, const eNodeSocketInOut in_out)
Definition node_edit.cc:793
static void node_draw_panels_background(const bNode &node)
static void find_bounds_by_zone_recursive(const SpaceNode &snode, const bNodeTreeZone &zone, const Span< const bNodeTreeZone * > all_zones, MutableSpan< Vector< float2 > > r_bounds_by_zone)
static std::optional< NodeExtraInfoRow > node_get_accessed_attributes_row(TreeDrawContext &tree_draw_ctx, const bNode &node)
void node_socket_color_get(const bContext &C, const bNodeTree &ntree, PointerRNA &node_ptr, const bNodeSocket &sock, float r_color[4])
Array< bNode * > tree_draw_order_calc_nodes_reversed(bNodeTree &ntree)
Definition node_draw.cc:286
static void node_get_compositor_extra_info(TreeDrawContext &tree_draw_ctx, const SpaceNode &snode, const bNode &node, Vector< NodeExtraInfoRow > &rows)
static bool node_update_basis_socket(TreeDrawContext &tree_draw_ctx, const bContext &C, bNodeTree &ntree, bNode &node, const char *panel_label, bNodeSocket *input_socket, bNodeSocket *output_socket, ui::Block &block, const int &locx, int &locy)
Definition node_draw.cc:472
void node_set_cursor(wmWindow &win, ARegion &region, SpaceNode &snode, const float2 &cursor)
void node_draw_link(const bContext &C, const View2D &v2d, const SpaceNode &snode, const bNodeLink &link, const bool selected)
Definition drawnode.cc:2485
static void node_draw_mute_line(const bContext &C, const View2D &v2d, const SpaceNode &snode, const bNode &node)
static void reroute_node_prepare_for_draw(bNode &node)
static void node_frame_get_color(const bNode &node, float r_color[4])
static NodeExtraInfoRow row_from_used_named_attribute(const Map< StringRefNull, nodes::eval_log::NamedAttributeUsage > &usage_by_attribute_name)
void node_socket_add_tooltip(const bNodeTree &ntree, const bNodeSocket &sock, ui::Layout &layout)
static const bNode * find_node_under_cursor(SpaceNode &snode, const float2 &cursor)
static bool is_node_panels_supported(const bNode &node)
Definition node_draw.cc:344
void node_draw_link_dragged(const bContext &C, const View2D &v2d, const SpaceNode &snode, const bNodeLink &link)
Definition drawnode.cc:2537
static std::string node_errors_tooltip_fn(const Span< nodes::NodeWarning > warnings)
static void node_update_nodetree(const bContext &C, TreeDrawContext &tree_draw_ctx, bNodeTree &ntree, Span< bNode * > nodes, Span< ui::Block * > blocks)
static void add_flat_items_for_separator(Vector< FlatNodeItem > &r_items)
Definition node_draw.cc:736
static void node_toggle_button_cb(bContext *C, void *node_argv, void *op_argv)
static Set< const bNodeSocket * > find_sockets_on_active_gizmo_paths(const bContext &C, const SpaceNode &snode, bke::ComputeContextCache &compute_context_cache)
static void node_draw_extra_info_row(const bNode &node, ui::Block &block, const rctf &rect, const int row, const NodeExtraInfoRow &extra_info_row)
static void node_draw_basis(const bContext &C, TreeDrawContext &tree_draw_ctx, const View2D &v2d, const SpaceNode &snode, bNodeTree &ntree, const bNode &node, ui::Block &block)
static void draw_background_color()
static void node_update_collapsed(bNode &node, ui::Block &block)
void build_socket_tooltip(ui::TooltipData &tip_data, bContext &C, ui::Button *but, const bNodeTree &tree, const bNodeSocket &socket)
static void add_rect_corner_positions(Vector< float2 > &positions, const rctf &rect)
bool node_is_previewable(const SpaceNode &snode, const bNodeTree &ntree, const bNode &node)
Definition node_edit.cc:739
static void determine_potentially_visible_panels_recursive(const bNode &node, const nodes::PanelDeclaration &panel_decl, MutableSpan< bool > r_result)
Definition node_draw.cc:629
const ComputeContext * compute_context_for_edittree(const SpaceNode &snode, bke::ComputeContextCache &compute_context_cache)
void draw_nodespace_back_pix(const bContext &C, ARegion &region, SpaceNode &snode, bNodeInstanceKey parent_key)
Definition drawnode.cc:1724
static void node_comment_edit_button_cb(bContext *C, void *node_argv, void *)
static bool panel_has_only_inactive_inputs(const bNode &node, const nodes::PanelDeclaration &panel_decl)
static std::string named_attribute_tooltip(bContext *, void *argN, const StringRef)
static void node_draw_extra_info_panel_back(const bNode &node, const rctf &extra_info_rect)
static void count_multi_input_socket_links(bNodeTree &ntree, SpaceNode &snode)
static void node_draw_preview(const Scene *scene, const ImBuf *preview, const rctf *prv)
static void snode_setup_v2d(SpaceNode &snode, ARegion &region, const float2 &center, const float size_x)
static void determine_visible_panels(const bNode &node, MutableSpan< bool > r_visibility_states)
Definition node_draw.cc:699
static void node_header_custom_tooltip(const bNodeTree &ntree, const bNode &node, ui::Button &but)
static ui::Button * add_error_message_button(ui::Block &block, const rctf &rect, const int icon, float &icon_offset, const char *tooltip=nullptr)
static void node_draw_collapsed(const bContext &C, TreeDrawContext &tree_draw_ctx, const View2D &v2d, const SpaceNode &snode, bNodeTree &ntree, bNode &node, ui::Block &block)
static void node_draw_extra_info_panel(const bContext &C, TreeDrawContext &tree_draw_ctx, const SpaceNode &snode, const bNode &node, const ImBuf *preview, ui::Block &block)
static void node_frame_get_label_color(const float bgcolor[4], uchar r_color[3])
static void node_socket_tooltip_set(ui::Block &block, const int socket_index_in_tree, const float2 location, const float2 size)
void tree_update(const bContext *C)
Definition node_draw.cc:189
static std::string node_get_execution_time_label(TreeDrawContext &tree_draw_ctx, const SpaceNode &snode, const bNode &node)
static void node_add_error_message_button(const TreeDrawContext &tree_draw_ctx, const bNodeTree &ntree, const bNode &node, ui::Block &block, const rctf &rect, float &icon_offset)
static ui::Block & invalid_links_uiblock_init(const bContext &C)
static void reroute_node_draw_body(const bContext &C, const SpaceNode &snode, const bNodeTree &ntree, const bNode &node, ui::Block &block, const bool selected)
const char * node_socket_get_label(const bNodeSocket *socket, const char *panel_label=nullptr)
Definition node_draw.cc:398
static Array< ui::Block * > node_uiblocks_init(const bContext &C, const Span< bNode * > nodes)
Definition node_draw.cc:297
static void node_update_basis_from_declaration(TreeDrawContext &tree_draw_ctx, const bContext &C, bNodeTree &ntree, bNode &node, ui::Block &block, const int locx, int &locy)
static short get_viewer_shortcut_icon(const bNode &node)
Array< bNode * > tree_draw_order_calc_nodes(bNodeTree &ntree)
Definition node_draw.cc:275
static void node_socket_add_tooltip_in_node_editor(const bNodeSocket &sock, ui::Layout &layout)
static void update_collapsed_sockets_recursive(bNode &node, const int node_left_x, const nodes::PanelDeclaration &panel_decl)
static void frame_node_draw_overlay(const bContext &C, TreeDrawContext &tree_draw_ctx, const ARegion &region, const SpaceNode &snode, const bNode &node, ui::Block &block)
Vector< ui::ContextPathItem > context_path_for_space_node(const bContext &C)
float2 node_to_view(const float2 &co)
Definition node_draw.cc:318
static void add_flat_items_for_socket(bNode &node, const nodes::SocketDeclaration &socket_decl, const nodes::PanelDeclaration *panel_decl, const nodes::SocketDeclaration *prev_socket_decl, Vector< FlatNodeItem > &r_items)
Definition node_draw.cc:706
void node_select_single(bContext &C, bNode &node)
static rctf node_to_rect(const bNode &node)
Definition node_draw.cc:323
static Vector< NodeExtraInfoRow > node_get_extra_info(const bContext &C, TreeDrawContext &tree_draw_ctx, const SpaceNode &snode, const bNode &node)
NestedTreePreviews * get_nested_previews(const bContext &C, SpaceNode &snode)
static std::optional< NodeExtraInfoRow > node_get_execution_time_label_row(TreeDrawContext &tree_draw_ctx, const SpaceNode &snode, const bNode &node)
static void reroute_node_draw(const bContext &C, TreeDrawContext &tree_draw_ctx, ARegion &region, const SpaceNode &snode, bNodeTree &ntree, const bNode &node, ui::Block &block)
void node_link_bezier_points_evaluated(const bNodeLink &link, std::array< float2, NODE_LINK_RESOL+1 > &coords)
Definition drawnode.cc:1864
static Vector< FlatNodeItem > make_flat_node_items(bNode &node)
Definition node_draw.cc:801
static void node_draw_panels(bNodeTree &ntree, const bNode &node, ui::Block &block)
static const float virtual_node_socket_outline_color[4]
static std::optional< float2 > find_visible_center_of_link(const View2D &v2d, const bNodeLink &link, const float radius, const float region_padding)
static void draw_frame_overlays(const bContext &C, TreeDrawContext &tree_draw_ctx, const ARegion &region, const SpaceNode &snode, const bNodeTree &ntree, Span< ui::Block * > blocks)
float2 socket_link_connection_location(const bNode &node, const bNodeSocket &socket, const bNodeLink &link)
Definition drawnode.cc:1804
static void frame_node_draw_label(const bNode &node, const SpaceNode &snode)
static FrameNodeLayout frame_node_layout(const bNode &frame_node)
static void frame_node_draw_outline(const ARegion &region, const SpaceNode &snode, const bNode &node)
void snode_set_context(const bContext &C)
Definition node_edit.cc:191
static void node_panel_toggle_button_cb(bContext *C, void *panel_state_argv, void *ntree_argv)
NodeResizeDirection node_get_resize_direction(const SpaceNode &snode, const bNode *node, const int x, const int y)
Definition drawnode.cc:211
void nodelink_batch_end(const SpaceNode &snode)
Definition drawnode.cc:2224
void nodelink_batch_start(const SpaceNode &)
Definition drawnode.cc:2219
void node_release_preview_ibuf(NestedTreePreviews &tree_previews)
static void node_draw_zones_and_frames(const ARegion &region, const SpaceNode &snode, const bNodeTree &ntree)
static void add_flat_items_for_layout(const bNode &node, const nodes::LayoutDeclaration &layout_decl, Vector< FlatNodeItem > &r_items)
Definition node_draw.cc:741
void node_to_updated_rect(const bNode &node, rctf &r_rect)
Definition node_draw.cc:333
static bool draw_node_details(const SpaceNode &snode)
void node_draw_space(const bContext &C, ARegion &region)
static void node_draw_preview_background(rctf *rect)
static void node_draw_shadow(const SpaceNode &snode, const bNode &node, const float radius, const float alpha)
const char * node_socket_get_description(const bNodeSocket *socket)
Definition node_draw.cc:427
static bool node_undefined_or_unsupported(const bNodeTree &node_tree, const bNode &node)
static void draw_tree_path(const bContext &C, ARegion &region)
static float get_margin_empty()
Definition node_draw.cc:836
static void comment_node_prepare_for_draw(const bContext &C, bNodeTree &ntree, bNode &node, ui::Block &block)
static void node_draw_socket(const bContext &C, const bNodeTree &ntree, const bNode &node, PointerRNA &node_ptr, ui::Block &block, const bNodeSocket &sock, const float outline_thickness, const bool selected, const float aspect)
static void draw_socket_layout(TreeDrawContext &tree_draw_ctx, const bContext &C, ui::Layout &layout, bNodeSocket &socket, bNodeTree &ntree, bNode &node, PointerRNA &node_ptr, PointerRNA &socket_ptr, const char *panel_label)
Definition node_draw.cc:442
static StringRef reroute_node_get_auto_label(TreeDrawContext &tree_draw_ctx, const bNode &src_reroute)
std::optional< Bounds< float2 > > node_bounds(Span< const bNode * > nodes)
static nodes::NodeWarningType node_error_highest_priority(const WarningsRange &warnings)
static void draw_nodetree(const bContext &C, ARegion &region, bNodeTree &ntree)
static void node_update_basis_from_socket_lists(TreeDrawContext &tree_draw_ctx, const bContext &C, bNodeTree &ntree, bNode &node, ui::Block &block, const int locx, int &locy)
void node_draw_nodesocket(const rctf *rect, const float color_inner[4], const float color_outline[4], float outline_thickness, int shape, float aspect)
Definition drawnode.cc:1988
static ColorTheme4f node_header_color_get(const bNodeTree &ntree, const bNode &node, const int color_id)
static int node_get_colorid(TreeDrawContext &tree_draw_ctx, const bNode &node)
static void determine_visible_panels_impl(const bNode &node, const Span< bool > potentially_visible_states, MutableSpan< bool > r_result)
Definition node_draw.cc:682
bNode * find_geometry_nodes_viewer(const ViewerPath &viewer_path, SpaceNode &snode)
bke::CurvesGeometry fillet_curves_poly(const bke::CurvesGeometry &src_curves, const IndexMask &curve_selection, const VArray< float > &radius, const VArray< int > &counts, bool limit_radius, const bke::AttributeFilter &attribute_filter)
T distance(const T &a, const T &b)
T midpoint(const T &a, const T &b)
T interpolate(const T &a, const T &b, const FactorT &t)
T round(const T &a)
void foreach_socket_on_gizmo_path(const ComputeContext &gizmo_context, const bNode &gizmo_node, const bNodeSocket &gizmo_socket, FunctionRef< void(const ComputeContext &context, const bNodeSocket &socket, const ie::ElemVariant &elem)> fn)
void foreach_active_gizmo(const bContext &C, bke::ComputeContextCache &compute_context_cache, const ForeachGizmoFn fn)
int node_warning_type_severity(const NodeWarningType type)
Definition warning.cc:51
bool node_can_sync_sockets(const bContext &C, const bNodeTree &, const bNode &node)
int node_warning_type_icon(const NodeWarningType type)
Definition warning.cc:37
std::optional< NodeInContext > find_origin_index_menu_switch(const SocketInContext &src_socket, bke::ComputeContextCache &compute_context_cache)
void get_color_blend_alpha_4fv(const float cp1[4], const float cp2[4], float fac, float alphaoffset, float r_col[4])
int get_value_type(int colorid, int spacetype)
void get_color_3fv(int colorid, float col[3])
void get_color_4fv(int colorid, float col[4])
void get_color_blend_shade_3fv(int colorid1, int colorid2, float fac, int offset, float col[3])
void get_color_shade_4fv(int colorid, int offset, float col[4])
void get_color_blend_shade_4fv(int colorid1, int colorid2, float fac, int offset, float col[4])
void get_color_blend_3f(int colorid1, int colorid2, float fac, float r_col[3])
void get_color_blend_4f(int colorid1, int colorid2, float fac, float r_col[4])
void get_color_shade_alpha_4fv(int colorid, int coloffset, int alphaoffset, float col[4])
void get_color_type_4fv(int colorid, int spacetype, float col[4])
void view2d_view_ortho(const View2D *v2d)
Definition view2d.cc:1080
int textbox_but_height(const TextboxState &state)
const uiStyle * style_get()
void view2d_view_restore(const bContext *C)
Definition view2d.cc:1147
void draw_dropshadow(const rctf *rct, float radius, float width, float aspect, float alpha)
void view2d_center_set(View2D *v2d, float x, float y)
Definition view2d.cc:1939
const uiStyle * style_get_dpi()
void view2d_scrollers_draw(View2D *v2d, const rcti *mask_custom)
Definition view2d.cc:1487
void view2d_region_to_view(const View2D *v2d, float x, float y, float *r_view_x, float *r_view_y) ATTR_NONNULL()
Definition view2d.cc:1651
void view2d_dot_grid_draw(const View2D *v2d, int grid_color_id, float min_step, int grid_subdivisions)
Definition view2d.cc:1271
void draw_roundbox_corner_set(int type)
void view2d_center_get(const View2D *v2d, float *r_x, float *r_y)
Definition view2d.cc:1929
bool button_active_only(const bContext *C, ARegion *region, Block *block, Button *but)
void draw_roundbox_aa(const rctf *rect, bool filled, float rad, const float color[4])
void draw_roundbox_4fv_ex(const rctf *rect, const float inner1[4], const float inner2[4], float shade_dir, const float outline[4], float outline_width, float rad)
int2 block_layout_resolve(Block *block)
Layout & block_layout(Block *block, LayoutDirection direction, LayoutType type, int x, int y, int size, int em, int padding, const uiStyle *style)
void template_breadcrumbs(Layout &layout, Span< ContextPathItem > context_path)
void view2d_scale_get(const View2D *v2d, float *r_x, float *r_y)
Definition view2d.cc:1893
void draw_roundbox_4fv(const rctf *rect, bool filled, float rad, const float col[4])
BMesh Iterators.
MINLINE float min_ff(float a, float b)
bool ED_node_is_compositor(const SpaceNode *snode)
Definition node_edit.cc:135
UserDef U
Definition blender.cc:58
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
unsigned __int64 uint64_t
Definition BKE_text.h:91
ScrArea * CTX_wm_area(const bContext *C)
void wmOrtho2_region_pixelspace(const ARegion *region)
void ED_region_draw_cb_draw(const bContext *C, ARegion *region, int type)
void immUniformThemeColorBlend(int color_id1, int color_id2, float fac)
uint padding(uint offset, uint alignment)
void BLF_aspect(int fontid, float x, float y, float z)
Definition blf.cc:379
void BLF_position(int fontid, float x, float y, float z)
Definition blf.cc:390
float BLI_rctf_length_y(const rctf *rect, float y)
Definition rct.cc:184
void immEnd()
bool BLI_rctf_clamp_segment(const struct rctf *rect, float s1[2], float s2[2])
int char char int int int BLI_strcasecmp_natural(const char *s1, const char *s2) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
float BLF_width(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2)
Definition blf.cc:835
bool BLI_rctf_isect_pt_v(const struct rctf *rect, const float xy[2])
bool RNA_struct_is_a(const StructRNA *type, const StructRNA *srna)
unsigned int uint
Definition BKE_text.h:55
void GPU_clear_color(float red, float green, float blue, float alpha)
WorkSpace * CTX_wm_workspace(const bContext *C)
void wmOrtho2_pixelspace(const float x, const float y)
MINLINE int round_fl_to_int(float a)
std::optional< std::string > RNA_path_full_struct_py(const PointerRNA *ptr)
Definition rna_path.cc:1325
void WM_operator_properties_free(PointerRNA *ptr)
void BLF_wordwrap(int fontid, int wrap_width, BLFWrapMode mode=BLFWrapMode::Minimal)
Definition blf.cc:957
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
void GPU_matrix_identity_set()
MINLINE void copy_v2_v2(float r[2], const float a[2])
GPUVertFormat * immVertexFormat()
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
void rgb_to_hsl_v(const float rgb[3], float r_hsl[3])
void ED_region_overlay_info_text_draw(const int render_size_x, const int render_size_y, const int viewer_size_x, const int viewer_size_y, const int draw_offset_x, const int draw_offset_y)
Definition ed_draw.cc:953
void ED_draw_imbuf(const ImBuf *ibuf, float x, float y, bool use_filter, const ColorManagedViewSettings *view_settings, const ColorManagedDisplaySettings *display_settings, float zoom_x, float zoom_y)
Definition glutil.cc:121
void BLI_rctf_resize(struct rctf *rect, float x, float y)
Definition rct.cc:671
void immBegin(GPUPrimType, uint vertex_len)
void GPU_line_smooth(bool enable)
Definition gpu_state.cc:80
@ GPU_PRIM_LINE_STRIP
wmWindow * CTX_wm_window(const bContext *C)
@ TH_NODE_INTERFACE
@ TH_PANEL_SUB_BACK
@ TH_NODE_CONVERTER
@ TH_NODE_ATTRIBUTE
@ TH_NODE_GRID_LEVELS
const rcti * ED_region_visible_rect(ARegion *region)
Definition area.cc:4791
void immUniformThemeColorAlpha(int color_id, float a)
MINLINE void rgb_float_to_uchar(unsigned char r_col[3], const float col_f[3])
MINLINE float srgb_to_grayscale(const float rgb[3])
void BLF_disable(int fontid, FontFlags flag)
Definition blf.cc:331
void MEM_delete_void(void *vmemh)
void immUnbindProgram()
void BKE_render_resolution(const RenderData *r, const bool use_crop, int *r_width, int *r_height)
Definition scene.cc:3168
MINLINE void mul_v3_fl(float r[3], float f)
void GPU_line_width(float width)
Definition gpu_state.cc:151
@ GPU_BLEND_NONE
Definition GPU_state.hh:88
@ GPU_BLEND_ALPHA
Definition GPU_state.hh:90
int BLI_convexhull_2d(Span< float2 > points, int r_points[])
VecBase< float, 4 > float4
void immBindBuiltinProgram(GPUBuiltinShader shader_id)
PointerRNA WM_operator_properties_create(const char *opstring)
void BLF_size(int fontid, float size)
Definition blf.cc:445
void BLI_rctf_init_pt_radius(struct rctf *rect, const float xy[2], float size)
Definition rct.cc:472
bool BLI_rctf_is_empty(const struct rctf *rect)
void BLI_rctf_mul(struct rctf *rect, float factor)
Definition rct.cc:602
void * MEM_dupalloc_void(const void *vmemh) ATTR_WARN_UNUSED_RESULT
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
void immUniform1f(const char *name, float x)
@ GPU_DEPTH_NONE
Definition GPU_state.hh:132
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
unsigned char uchar
Definition BKE_text.h:58
void GPU_viewport_size_get_f(float coords[4])
Definition gpu_state.cc:258
BMesh const char void * data
void BLF_color3ubv(int fontid, const unsigned char rgb[3])
Definition blf.cc:478
@ GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
Definition BLI_rect.hh:215
bool BLI_rctf_isect_pt(const struct rctf *rect, float x, float y)
void BKE_main_ensure_invariants(Main &bmain, std::optional< Span< ID * > > modified_ids=std::nullopt)
void BLI_rctf_init_minmax(struct rctf *rect)
Definition rct.cc:494
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
void BLF_clipping(int fontid, int xmin, int ymin, int xmax, int ymax)
Definition blf.cc:945
SpaceNode * CTX_wm_space_node(const bContext *C)
wmOperatorStatus WM_operator_name_call(bContext *C, const char *opstring, wm::OpCallContext context, PointerRNA *properties, const wmEvent *event)
void GPU_framebuffer_bind_no_srgb(gpu::FrameBuffer *fb)
void GPU_matrix_projection_set(const float m[4][4])
void BLF_draw(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_NONNULL(2)
Definition blf.cc:587
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition BLI_rect.hh:203
@ NODE_FRAME_RESIZEABLE
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
bool BKE_scene_uses_shader_previews(const Scene *scene)
Definition scene.cc:3092
void BLI_rctf_union(struct rctf *rct_a, const struct rctf *rct_b)
void hsl_to_rgb_v(const float hsl[3], float r_rgb[3])
Definition math_color.cc:66
void BLI_rcti_init(struct rcti *rect, int xmin, int xmax, int ymin, int ymax)
Definition rct.cc:428
ImBuf * BKE_image_acquire_ibuf(Image *ima, ImageUser *iuser, void **r_lock)
BLI_INLINE float BLI_rcti_cent_x_fl(const struct rcti *rct)
Definition BLI_rect.hh:178
void id_us_ensure_real(ID *id)
Definition lib_id.cc:388
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
void immVertex3fv(uint attr_id, const float data[3])
gpu::FrameBuffer * GPU_viewport_framebuffer_overlay_get(GPUViewport *viewport)
int BLF_height_max(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:883
float BLI_rctf_length_x(const rctf *rect, float x)
Definition rct.cc:173
@ WM_CURSOR_Y_MOVE
Definition wm_cursors.hh:42
@ WM_CURSOR_EDIT
Definition wm_cursors.hh:21
@ WM_CURSOR_NSEW_SCROLL
Definition wm_cursors.hh:54
@ WM_CURSOR_DEFAULT
Definition wm_cursors.hh:17
@ WM_CURSOR_X_MOVE
Definition wm_cursors.hh:41
void immUniform4f(const char *name, float x, float y, float z, float w)
Main * CTX_data_main(const bContext *C)
void GPU_matrix_pop_projection()
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
Definition BLI_rect.hh:211
@ NODE_VIEWER_SHORCTUT_SLOT_9
@ NODE_VIEWER_SHORCTUT_SLOT_8
@ NODE_VIEWER_SHORCTUT_SLOT_1
@ NODE_VIEWER_SHORCTUT_SLOT_5
@ NODE_VIEWER_SHORCTUT_SLOT_6
@ NODE_VIEWER_SHORTCUT_NONE
@ NODE_VIEWER_SHORCTUT_SLOT_4
@ NODE_VIEWER_SHORCTUT_SLOT_3
@ NODE_VIEWER_SHORCTUT_SLOT_2
@ NODE_VIEWER_SHORCTUT_SLOT_7
bool BLI_rctf_isect(const struct rctf *src1, const struct rctf *src2, struct rctf *dest)
Image * BKE_image_ensure_viewer(Main *bmain, int type, const char *name)
BLI_INLINE float BLI_rctf_cent_y(const struct rctf *rct)
Definition BLI_rect.hh:198
void WM_gizmomap_draw(wmGizmoMap *gzmap, const bContext *C, const eWM_GizmoFlagMapDrawStep drawstep)
@ ID_TAG_MISSING
Definition DNA_ID.h:870
@ SOCK_PANEL_COLLAPSED
Scene * CTX_data_scene(const bContext *C)
void immUniform2fv(const char *name, const float data[2])
void WM_cursor_set(wmWindow *win, int curs)
void ED_annotation_draw_view2d(const bContext *C, bool onlyv2d)
MINLINE void copy_v4_v4(float r[4], const float a[4])
ColorTheme4< float > ColorTheme4f
void GPU_blend(GPUBlend blend)
Definition gpu_state.cc:44
void immUniform1i(const char *name, int x)
VecBase< float, 3 > float3
const float(* GPU_matrix_projection_get(float m[4][4]))[4]
void GPU_matrix_pop()
void GPU_matrix_push_projection()
@ NODE_PANEL_COLLAPSED
GPUViewport * WM_draw_region_get_viewport(ARegion *region)
Definition wm_draw.cc:954
MINLINE int min_ii(int a, int b)
void GPU_depth_test(GPUDepthTest test)
Definition gpu_state.cc:70
void immRectf(uint pos, float x1, float y1, float x2, float y2)
BLI_INLINE float BLI_rcti_cent_y_fl(const struct rcti *rct)
Definition BLI_rect.hh:182
ARegion * CTX_wm_region(const bContext *C)
BLI_INLINE float BLI_rctf_cent_x(const struct rctf *rct)
Definition BLI_rect.hh:194
void BLI_rctf_pad(struct rctf *rect, float pad_x, float pad_y)
Definition rct.cc:651
void BLF_enable(int fontid, FontFlags flag)
Definition blf.cc:322
void ED_region_render_region_draw(int x, int y, const rcti *frame, float zoomx, float zoomy, float passepartout_alpha)
Definition ed_draw.cc:991
@ BLF_ASPECT
Definition BLF_enums.hh:41
@ BLF_CLIPPING
Definition BLF_enums.hh:37
@ BLF_WORD_WRAP
Definition BLF_enums.hh:42
void GPU_matrix_push()
@ WM_GIZMOMAP_DRAWSTEP_2D
@ SN_OVERLAY_SHOW_TEXT_INFO
@ SN_OVERLAY_SHOW_OVERLAYS
@ SN_OVERLAY_SHOW_TIMINGS
@ SN_OVERLAY_SHOW_REROUTE_AUTO_LABELS
@ SN_OVERLAY_SHOW_PREVIEWS
@ SN_OVERLAY_SHOW_RENDER_REGION
@ SN_OVERLAY_SHOW_NAMED_ATTRIBUTES
void BKE_image_release_ibuf(Image *ima, ImBuf *ibuf, void *lock)
MINLINE void rgba_float_args_set(float col[4], float r, float g, float b, float a)
#define NODE_HEADER_ICON_SIZE
#define NODE_SOCKET_OUTLINE
#define ZONE_ZONE_PADDING
Definition node_draw.cc:122
#define EXTRA_INFO_ROW_HEIGHT
Definition node_draw.cc:123
#define NODE_ZONE_PADDING
Definition node_draw.cc:121
#define NODE_TREE_SCALE_SMALL
#define NODE_MULTI_INPUT_LINK_GAP
#define BASIS_RAD
#define NODE_SOCKSIZE
#define NODE_WIDTH(node)
#define NODE_DYS
#define NODE_ITEM_SPACING_Y
#define NODE_MARGIN_X
#define NODE_DY
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
#define min(a, b)
Definition sort.cc:38
bke::ARegionRuntime * runtime
eRegion_Alignment alignment
char name[258]
Definition DNA_ID.h:433
StructRNA * type
Definition RNA_types.hh:63
ColorManagedViewSettings view_settings
ColorManagedDisplaySettings display_settings
struct RenderData r
ListBaseT< ARegion > regionbase
eSpaceNodeOverlay_Flag flag
SpaceNodeOverlay overlay
struct bNodeTree * edittree
struct bNodeTree * nodetree
ListBaseT< bNodeTreePath > treepath
ed::space_node::SpaceNode_Runtime * runtime
eSpaceNode_Flag flag
eView2D_Scroll scroll
bke::bNodeSocketType * typeinfo
eNodeSocketDatatype type
bke::bNodeSocketRuntime * runtime
eNodeSocketInOut in_out
eNodeSocketDisplayShape display_shape
struct bNodeTree * nodetree
bNodeInstanceKey parent_key
eNodeTree_Type type
bke::bNodeTreeRuntime * runtime
struct bNode * parent
bke::bNodeRuntime * runtime
void(*) draw_color(bContext *C, PointerRNA *ptr, PointerRNA *node_ptr, float *r_color)
Definition BKE_node.hh:176
void(*) draw_color_simple(const bNodeSocketType *socket_type, float *r_color)
Definition BKE_node.hh:177
std::variant< flat_item::Socket, flat_item::Separator, flat_item::PanelHeader, flat_item::PanelContentBegin, flat_item::PanelContentEnd, flat_item::Layout > item
Definition node_draw.cc:621
Map< StringRefNull, nodes::eval_log::NamedAttributeUsage > usage_by_attribute
std::optional< int > frame_identifier_to_highlight
std::unique_ptr< bNodeLinkDrag > linkdrag
Array< Vector< NodeExtraInfoRow > > extra_info_rows_per_node
Definition node_draw.cc:167
nodes::eval_log::ContextualNodeTreeLogs tree_logs
Definition node_draw.cc:147
Map< const bNode *, const bNode * > menu_switch_source_by_index_switch
Definition node_draw.cc:161
Map< const bNode *, StringRef > reroute_auto_labels
Definition node_draw.cc:154
Map< int32_t, VectorSet< nodes::NodeWarning > > shader_node_errors
Definition node_draw.cc:169
const nodes::LayoutDeclaration * decl
Definition node_draw.cc:609
const nodes::PanelDeclaration * decl
Definition node_draw.cc:595
const nodes::PanelDeclaration * panel_decl
Definition node_draw.cc:588
void draw_standard(ui::Layout &layout, std::optional< StringRefNull > label_override=std::nullopt)
std::function< void(ui::Button &)> set_execute_fn
void enabled_set(bool enabled)
void alignment_set(LayoutAlign alignment)
void active_set(bool active)
void separator(float factor=1.0f, LayoutSeparatorType type=LayoutSeparatorType::Auto)
void label_markdown(StringRef text)
Layout & row(bool align)
void context_ptr_set(StringRef name, const PointerRNA *ptr)
bke::WindowRuntime * runtime
uiFontStyle widget