[Bf-blender-cvs] [48bd6962c21] temp-geometry-nodes-timings: Adds backdrop, icon, tooltip, and refactored.

Erik noreply at git.blender.org
Sun Nov 14 04:04:51 CET 2021


Commit: 48bd6962c21b62bdb59ca1d219297e8862d976d5
Author: Erik
Date:   Sun Nov 14 04:04:07 2021 +0100
Branches: temp-geometry-nodes-timings
https://developer.blender.org/rB48bd6962c21b62bdb59ca1d219297e8862d976d5

Adds backdrop, icon, tooltip, and refactored.

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

M	source/blender/editors/space_node/drawnode.cc
M	source/blender/editors/space_node/node_draw.cc
M	source/blender/editors/space_node/node_intern.h

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

diff --git a/source/blender/editors/space_node/drawnode.cc b/source/blender/editors/space_node/drawnode.cc
index a6d0acfabf2..fba7bd8e737 100644
--- a/source/blender/editors/space_node/drawnode.cc
+++ b/source/blender/editors/space_node/drawnode.cc
@@ -370,24 +370,6 @@ static void node_draw_frame_label(bNodeTree *ntree, bNode *node, SpaceNode *snod
   float x = BLI_rctf_cent_x(rct) - (0.5f * width);
   float y = rct->ymax - label_height;
 
-  /* Draw execution time. */
-  if (snode->flag & SNODE_SHOW_TIMING) {
-    uint64_t exec_time_us = node_get_execution_time(ntree, node, snode);
-
-    if (exec_time_us > 0) {
-      std::string timing_str;
-      if (exec_time_us < 1000) {
-        timing_str = "<1 ms";
-      }
-      else {
-        int exec_time_ms = static_cast<int>((exec_time_us / 1000.0f) + 0.5f);
-        timing_str = std::to_string(exec_time_ms) + " ms";
-      }
-      BLF_position(fontid, rct->xmin + U.widget_unit * 0.5f, y, 0);
-      BLF_draw(fontid, timing_str.c_str(), timing_str.length());
-    }
-  }
-
   /* label */
   const bool has_label = node->label[0] != '\0';
   if (has_label) {
@@ -489,6 +471,8 @@ static void node_draw_frame(const bContext *C,
   /* label and text */
   node_draw_frame_label(ntree, node, snode);
 
+  node_draw_extra_info_panel(snode, node);
+
   UI_block_end(C, node->block);
   UI_block_draw(C, node->block);
   node->block = nullptr;
diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc
index 9bca6c3592c..823e3e83f37 100644
--- a/source/blender/editors/space_node/node_draw.cc
+++ b/source/blender/editors/space_node/node_draw.cc
@@ -1579,7 +1579,9 @@ static void node_add_error_message_button(
   UI_block_emboss_set(node.block, UI_EMBOSS);
 }
 
-uint64_t node_get_execution_time(bNodeTree *ntree, bNode *node, SpaceNode *snode)
+static uint64_t node_get_execution_time(const bNodeTree *ntree,
+                                        const bNode *node,
+                                        const SpaceNode *snode)
 {
   uint64_t exec_time_us = 0;
 
@@ -1640,34 +1642,57 @@ uint64_t node_get_execution_time(bNodeTree *ntree, bNode *node, SpaceNode *snode
   return exec_time_us;
 }
 
-static void node_add_execution_time_label(const bContext *C, bNode &node, const rctf &rect)
+static std::string node_get_execution_time_label(const SpaceNode *snode, const bNode *node)
 {
-  SpaceNode *snode = CTX_wm_space_node(C);
+  uint64_t exec_time_us = node_get_execution_time(snode->nodetree, node, snode);
 
-  uint64_t exec_time_us = node_get_execution_time(nullptr, &node, snode);
-  short precision = 0;
+  std::string timing_str;
 
-  /* Don't show the label if execution time is 0 microseconds. */
+  /* Don't show time if execution time is 0 microseconds. */
   if (exec_time_us == 0) {
-    return;
+    timing_str = "-";
   }
+  else {
+    short precision = 0;
+    /* Show decimal if value is below 1ms */
+    if (exec_time_us < 1000) {
+      precision = 1;
+    }
 
-  /* Show decimal if value is below 1ms */
-  if (exec_time_us < 1000) {
-    precision = 1;
+    std::stringstream stream;
+    stream << std::fixed << std::setprecision(precision) << (exec_time_us / 1000.0f);
+    timing_str = stream.str() + " ms";
   }
+  return timing_str;
+}
 
-  std::stringstream stream;
-  stream << std::fixed << std::setprecision(precision) << (exec_time_us / 1000.0f);
-  std::string timing_str = stream.str() + " ms";
+static int node_get_extra_info_count(const SpaceNode *snode, const bNode *node)
+{
+  int extra_info_count = 0;
+
+  if (snode->flag & SNODE_SHOW_TIMING &&
+      (ELEM(node->typeinfo->nclass, NODE_CLASS_GEOMETRY, NODE_CLASS_GROUP) ||
+       ELEM(node->type, NODE_FRAME, NODE_GROUP_OUTPUT))) {
+    extra_info_count++;
+  }
 
-  uiBut *but_timing = uiDefBut(node.block,
+  return extra_info_count;
+}
+
+static void node_draw_extra_info_row(const bNode *node,
+                                     const rctf *rect,
+                                     const int row,
+                                     const std::string &text,
+                                     const char *tooltip,
+                                     const int icon)
+{
+  uiBut *but_timing = uiDefBut(node->block,
                                UI_BTYPE_LABEL,
                                0,
-                               timing_str.c_str(),
-                               (int)(rect.xmin + NODE_MARGIN_X + 0.4f),
-                               (int)(rect.ymax - NODE_DY + (20.0f * U.dpi_fac)),
-                               (short)(rect.xmax - rect.xmin),
+                               text.c_str(),
+                               (int)(rect->xmin + 4.0f * U.dpi_fac + NODE_MARGIN_X + 0.4f),
+                               (int)(rect->ymin + row * (20.0f * U.dpi_fac)),
+                               (short)(rect->xmax - rect->xmin),
                                (short)NODE_DY,
                                nullptr,
                                0,
@@ -1675,9 +1700,73 @@ static void node_add_execution_time_label(const bContext *C, bNode &node, const
                                0,
                                0,
                                "");
-  if (node.flag & NODE_MUTED) {
+  if (node->flag & NODE_MUTED) {
     UI_but_flag_enable(but_timing, UI_BUT_INACTIVE);
   }
+  UI_block_emboss_set(node->block, UI_EMBOSS_NONE);
+  uiBut *but_icon = uiDefIconBut(node->block,
+                                 UI_BTYPE_BUT,
+                                 0,
+                                 icon,
+                                 (int)(rect->xmin + 6.0f * U.dpi_fac),
+                                 (int)(rect->ymin + row * (20.0f * U.dpi_fac)),
+                                 NODE_HEADER_ICON_SIZE * 0.8f,
+                                 UI_UNIT_Y,
+                                 nullptr,
+                                 0,
+                                 0,
+                                 0,
+                                 0,
+                                 tooltip);
+  UI_block_emboss_set(node->block, UI_EMBOSS);
+}
+
+void node_draw_extra_info_panel(const SpaceNode *snode, const bNode *node)
+{
+  int extra_info_count = node_get_extra_info_count(snode, node);
+
+  if (extra_info_count == 0) {
+    return;
+  }
+
+  const rctf *rct = &node->totr;
+  float color[4];
+  rctf extra_info_rect;
+
+  if (node->type == NODE_FRAME) {
+    extra_info_rect.xmin = rct->xmin + 6.0f * U.dpi_fac;
+    extra_info_rect.xmax = rct->xmin + 105.0f * U.dpi_fac;
+    extra_info_rect.ymin = rct->ymin;
+    extra_info_rect.ymax = rct->ymin;
+  }
+  else {
+    extra_info_rect.xmin = rct->xmin + 3.0f * U.dpi_fac;
+    extra_info_rect.xmax = rct->xmin + 105.0f * U.dpi_fac;
+    extra_info_rect.ymin = rct->ymax;
+    extra_info_rect.ymax = rct->ymax + extra_info_count * (20.0f * U.dpi_fac) + 2.0f * U.dpi_fac;
+
+    ui_draw_dropshadow(
+        &extra_info_rect, BASIS_RAD, snode->runtime->aspect, 1.0f, node->flag & SELECT);
+    UI_GetThemeColorBlend4f(TH_BACK, TH_NODE, 0.7f, color);
+    color[3] -= 0.35f;
+    UI_draw_roundbox_corner_set(
+        UI_CNR_ALL & ~UI_CNR_BOTTOM_LEFT &
+        ((rct->xmax) > extra_info_rect.xmax ? ~UI_CNR_BOTTOM_RIGHT : UI_CNR_ALL));
+    UI_draw_roundbox_4fv(&extra_info_rect, true, BASIS_RAD, color);
+  }
+
+  int extra_info_row = 0;
+
+  if (snode->flag & SNODE_SHOW_TIMING &&
+      (ELEM(node->typeinfo->nclass, NODE_CLASS_GEOMETRY, NODE_CLASS_GROUP) ||
+       ELEM(node->type, NODE_FRAME, NODE_GROUP_OUTPUT))) {
+    std::string str = node_get_execution_time_label(snode, node);
+    const char *tooltip = "Execution time";
+
+    node_draw_extra_info_row(
+        node, &extra_info_rect, extra_info_row, str, tooltip, ICON_PREVIEW_RANGE);
+    extra_info_row++;
+  }
 }
 
 static void node_draw_basis(const bContext *C,
@@ -1705,6 +1794,8 @@ static void node_draw_basis(const bContext *C,
 
   GPU_line_width(1.0f);
 
+  node_draw_extra_info_panel(snode, node);
+
   /* Header. */
   {
     const rctf rect = {
@@ -1853,10 +1944,6 @@ static void node_draw_basis(const bContext *C,
     UI_but_flag_enable(but, UI_BUT_INACTIVE);
   }
 
-  /* Execution time. */
-  if (snode->flag & SNODE_SHOW_TIMING) {
-    node_add_execution_time_label(C, *node, *rct);
-  }
   /* Wire across the node when muted/disabled. */
   if (node->flag & NODE_MUTED) {
     node_draw_mute_line(C, v2d, snode, node);
@@ -1986,11 +2073,6 @@ static void node_draw_hidden(const bContext *C,
   /* Shadow. */
   node_draw_shadow(snode, node, hiddenrad, 1.0f);
 
-  /* Execution time. */
-  if (snode->flag & SNODE_SHOW_TIMING) {
-    node_add_execution_time_label(C, *node, *rct);
-  }
-
   /* Wire across the node when muted/disabled. */
   if (node->flag & NODE_MUTED) {
     node_draw_mute_line(C, v2d, snode, node);
diff --git a/source/blender/editors/space_node/node_intern.h b/source/blender/editors/space_node/node_intern.h
index 168bbc87180..892c81d6ecf 100644
--- a/source/blender/editors/space_node/node_intern.h
+++ b/source/blender/editors/space_node/node_intern.h
@@ -101,9 +101,7 @@ void node_link_calculate_multi_input_position(const float socket_x,
                                               float r[2]);
 
 int node_get_colorid(struct bNode *node);
-uint64_t node_get_execution_time(struct bNodeTree *ntree,
-                                 struct bNode *node,
-                                 struct SpaceNode *snode);
+void node_draw_extra_info_panel(const SpaceNode *snode, const bNode *node);
 int node_get_resize_cursor(int directions);
 void node_draw_shadow(const struct SpaceNode *snode,
                       const struct bNode *node,



More information about the Bf-blender-cvs mailing list