[Bf-blender-cvs] [85d966808fc] temp-gpu-image-engine: Cleanup: Remove runtime uiBlock pointer from nodes

Hans Goudey noreply at git.blender.org
Wed Dec 15 14:37:51 CET 2021


Commit: 85d966808fc9521ee69a7469f642fd74ea595e4d
Author: Hans Goudey
Date:   Tue Dec 14 11:19:47 2021 -0600
Branches: temp-gpu-image-engine
https://developer.blender.org/rB85d966808fc9521ee69a7469f642fd74ea595e4d

Cleanup: Remove runtime uiBlock pointer from nodes

Code is simpler when the uiBlocks used during drawing are simply
stored in an array. Additionally, looping can be simpler when we use
an vector to hold a temporary copy of the tree's linked list of nodes.

This patch also slightly changes how uiBlocks are "named" in
`node_uiblocks_init`. Now it uses the node name instead of the
pointer, which is helpful so we rely less on the node's address.

Differential Revision: https://developer.blender.org/D13540

===================================================================

M	source/blender/editors/space_node/node_draw.cc
M	source/blender/editors/space_node/node_intern.hh
M	source/blender/makesdna/DNA_node_types.h

===================================================================

diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc
index 5990462191e..ce9a6e3c5e0 100644
--- a/source/blender/editors/space_node/node_draw.cc
+++ b/source/blender/editors/space_node/node_draw.cc
@@ -36,6 +36,7 @@
 #include "DNA_texture_types.h"
 #include "DNA_world_types.h"
 
+#include "BLI_array.hh"
 #include "BLI_map.hh"
 #include "BLI_set.hh"
 #include "BLI_span.hh"
@@ -87,6 +88,7 @@
 
 #include "node_intern.hh" /* own include */
 
+using blender::Array;
 using blender::float2;
 using blender::Map;
 using blender::Set;
@@ -314,19 +316,18 @@ void ED_node_sort(bNodeTree *ntree)
   }
 }
 
-static void node_uiblocks_init(const bContext &C, bNodeTree &ntree)
+static Array<uiBlock *> node_uiblocks_init(const bContext &C, Span<bNode *> nodes)
 {
+  Array<uiBlock *> blocks(nodes.size());
   /* Add node uiBlocks in drawing order - prevents events going to overlapping nodes. */
-
-  LISTBASE_FOREACH (bNode *, node, &ntree.nodes) {
-    /* ui block */
-    char uiblockstr[32];
-    BLI_snprintf(uiblockstr, sizeof(uiblockstr), "node buttons %p", (void *)node);
-    node->block = UI_block_begin(&C, CTX_wm_region(&C), uiblockstr, UI_EMBOSS);
-
+  for (const int i : nodes.index_range()) {
+    const std::string block_name = "node_" + std::string(nodes[i]->name);
+    blocks[i] = UI_block_begin(&C, CTX_wm_region(&C), block_name.c_str(), UI_EMBOSS);
     /* this cancels events for background nodes */
-    UI_block_flag_enable(node->block, UI_BLOCK_CLIP_EVENTS);
+    UI_block_flag_enable(blocks[i], UI_BLOCK_CLIP_EVENTS);
   }
+
+  return blocks;
 }
 
 float2 node_to_view(const bNode &node, const float2 &co)
@@ -359,7 +360,7 @@ float2 node_from_view(const bNode &node, const float2 &co)
 /**
  * Based on settings and sockets in node, set drawing rect info.
  */
-static void node_update_basis(const bContext &C, bNodeTree &ntree, bNode &node)
+static void node_update_basis(const bContext &C, bNodeTree &ntree, bNode &node, uiBlock &block)
 {
   PointerRNA nodeptr;
   RNA_pointer_create(&ntree.id, &RNA_Node, &node, &nodeptr);
@@ -392,7 +393,7 @@ static void node_update_basis(const bContext &C, bNodeTree &ntree, bNode &node)
     PointerRNA sockptr;
     RNA_pointer_create(&ntree.id, &RNA_NodeSocket, nsock, &sockptr);
 
-    uiLayout *layout = UI_block_layout(node.block,
+    uiLayout *layout = UI_block_layout(&block,
                                        UI_LAYOUT_VERTICAL,
                                        UI_LAYOUT_PANEL,
                                        loc.x + NODE_DYS,
@@ -416,8 +417,8 @@ static void node_update_basis(const bContext &C, bNodeTree &ntree, bNode &node)
     const char *socket_label = nodeSocketLabel(nsock);
     nsock->typeinfo->draw((bContext *)&C, row, &sockptr, &nodeptr, IFACE_(socket_label));
 
-    UI_block_align_end(node.block);
-    UI_block_layout_resolve(node.block, nullptr, &buty);
+    UI_block_align_end(&block);
+    UI_block_layout_resolve(&block, nullptr, &buty);
 
     /* Ensure minimum socket height in case layout is empty. */
     buty = min_ii(buty, dy - NODE_DY);
@@ -480,7 +481,7 @@ static void node_update_basis(const bContext &C, bNodeTree &ntree, bNode &node)
   if (node.typeinfo->draw_buttons && (node.flag & NODE_OPTIONS)) {
     dy -= NODE_DYS / 2;
 
-    uiLayout *layout = UI_block_layout(node.block,
+    uiLayout *layout = UI_block_layout(&block,
                                        UI_LAYOUT_VERTICAL,
                                        UI_LAYOUT_PANEL,
                                        loc.x + NODE_DYS,
@@ -498,8 +499,8 @@ static void node_update_basis(const bContext &C, bNodeTree &ntree, bNode &node)
 
     node.typeinfo->draw_buttons(layout, (bContext *)&C, &nodeptr);
 
-    UI_block_align_end(node.block);
-    UI_block_layout_resolve(node.block, nullptr, &buty);
+    UI_block_align_end(&block);
+    UI_block_layout_resolve(&block, nullptr, &buty);
 
     dy = buty - NODE_DYS / 2;
   }
@@ -523,7 +524,7 @@ static void node_update_basis(const bContext &C, bNodeTree &ntree, bNode &node)
     }
     dy -= multi_input_socket_offset * 0.5f;
 
-    uiLayout *layout = UI_block_layout(node.block,
+    uiLayout *layout = UI_block_layout(&block,
                                        UI_LAYOUT_VERTICAL,
                                        UI_LAYOUT_PANEL,
                                        loc.x + NODE_DYS,
@@ -546,8 +547,8 @@ static void node_update_basis(const bContext &C, bNodeTree &ntree, bNode &node)
     const char *socket_label = nodeSocketLabel(nsock);
     nsock->typeinfo->draw((bContext *)&C, row, &sockptr, &nodeptr, IFACE_(socket_label));
 
-    UI_block_align_end(node.block);
-    UI_block_layout_resolve(node.block, nullptr, &buty);
+    UI_block_align_end(&block);
+    UI_block_layout_resolve(&block, nullptr, &buty);
 
     /* Ensure minimum socket height in case layout is empty. */
     buty = min_ii(buty, dy - NODE_DY);
@@ -574,7 +575,7 @@ static void node_update_basis(const bContext &C, bNodeTree &ntree, bNode &node)
 
   /* Set the block bounds to clip mouse events from underlying nodes.
    * Add a margin for sockets on each side. */
-  UI_block_bounds_set_explicit(node.block,
+  UI_block_bounds_set_explicit(&block,
                                node.totr.xmin - NODE_SOCKSIZE,
                                node.totr.ymin,
                                node.totr.xmax + NODE_SOCKSIZE,
@@ -584,7 +585,7 @@ static void node_update_basis(const bContext &C, bNodeTree &ntree, bNode &node)
 /**
  * Based on settings in node, sets drawing rect info.
  */
-static void node_update_hidden(bNode &node)
+static void node_update_hidden(bNode &node, uiBlock &block)
 {
   int totin = 0, totout = 0;
 
@@ -644,7 +645,7 @@ static void node_update_hidden(bNode &node)
 
   /* Set the block bounds to clip mouse events from underlying nodes.
    * Add a margin for sockets on each side. */
-  UI_block_bounds_set_explicit(node.block,
+  UI_block_bounds_set_explicit(&block,
                                node.totr.xmin - NODE_SOCKSIZE,
                                node.totr.ymin,
                                node.totr.xmax + NODE_SOCKSIZE,
@@ -1009,6 +1010,7 @@ static std::optional<std::string> create_socket_inspection_string(bContext *C,
 static void node_socket_draw_nested(const bContext &C,
                                     bNodeTree &ntree,
                                     PointerRNA &node_ptr,
+                                    uiBlock &block,
                                     bNodeSocket &sock,
                                     const uint pos_id,
                                     const uint col_id,
@@ -1041,14 +1043,11 @@ static void node_socket_draw_nested(const bContext &C,
     return;
   }
 
-  bNode *node = (bNode *)node_ptr.data;
-  uiBlock *block = node->block;
-
   /* Ideally sockets themselves should be buttons, but they aren't currently. So add an invisible
    * button on top of them for the tooltip. */
-  const eUIEmbossType old_emboss = UI_block_emboss_get(block);
-  UI_block_emboss_set(block, UI_EMBOSS_NONE);
-  uiBut *but = uiDefIconBut(block,
+  const eUIEmbossType old_emboss = UI_block_emboss_get(&block);
+  UI_block_emboss_set(&block, UI_EMBOSS_NONE);
+  uiBut *but = uiDefIconBut(&block,
                             UI_BTYPE_BUT,
                             0,
                             ICON_NONE,
@@ -1095,7 +1094,7 @@ static void node_socket_draw_nested(const bContext &C,
       MEM_freeN);
   /* Disable the button so that clicks on it are ignored the the link operator still works. */
   UI_but_flag_enable(but, UI_BUT_DISABLED);
-  UI_block_emboss_set(block, old_emboss);
+  UI_block_emboss_set(&block, old_emboss);
 }
 
 void ED_node_socket_draw(bNodeSocket *sock, const rcti *rect, const float color[4], float scale)
@@ -1243,6 +1242,7 @@ static void node_draw_sockets(const View2D &v2d,
                               const bContext &C,
                               bNodeTree &ntree,
                               bNode &node,
+                              uiBlock &block,
                               const bool draw_outputs,
                               const bool select_all)
 {
@@ -1299,6 +1299,7 @@ static void node_draw_sockets(const View2D &v2d,
     node_socket_draw_nested(C,
                             ntree,
                             node_ptr,
+                            block,
                             *sock,
                             pos_id,
                             col_id,
@@ -1324,6 +1325,7 @@ static void node_draw_sockets(const View2D &v2d,
       node_socket_draw_nested(C,
                               ntree,
                               node_ptr,
+                              block,
                               *sock,
                               pos_id,
                               col_id,
@@ -1357,6 +1359,7 @@ static void node_draw_sockets(const View2D &v2d,
           node_socket_draw_nested(C,
                                   ntree,
                                   node_ptr,
+                                  block,
                                   *sock,
                                   pos_id,
                                   col_id,
@@ -1382,6 +1385,7 @@ static void node_draw_sockets(const View2D &v2d,
           node_socket_draw_nested(C,
                                   ntree,
                                   node_ptr,
+                                  block,
                                   *sock,
                                   pos_id,
                                   col_id,
@@ -1502,10 +1506,8 @@ static char *node_errors_tooltip_fn(bContext *UNUSED(C), void *argN, const char
 
 #define NODE_HEADER_ICON_SIZE (0.8f * U.widget_unit)
 
-static void node_add_error_message_button(const bContext &C,
-                                          bNode &node,
-                                          const rctf &rect,
-                                          float &icon_offset)
+static void node_add_error_message_button(
+    const bContext &C, bNode &node, uiBlock &block, const rctf &rect, float &icon_offset)
 {
   SpaceNode *snode = CTX_wm_space_node(&C);
   const geo_log::NodeLog *node_log = geo_log::ModifierLog::fin

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list