[Bf-blender-cvs] [3371a4c472e] master: UI: Improve node editor breadcrumbs display

Hans Goudey noreply at git.blender.org
Tue Oct 26 18:05:23 CEST 2021


Commit: 3371a4c472eef06d1c9e15451b245cb4575d667f
Author: Hans Goudey
Date:   Tue Oct 26 11:05:01 2021 -0500
Branches: master
https://developer.blender.org/rB3371a4c472eef06d1c9e15451b245cb4575d667f

UI: Improve node editor breadcrumbs display

This patch upgrades node editor breadcrumbs to have slightly more
visual weight, to including the base path of object/modifier/world,
etc, have more visually pleasing spacing, and contain icons.

In the code, a generic "context path" is added to interface code.
The idea is that this could be used to draw other breadcrumbs in areas
like the property editor or the spreadsheet, and features could be added
to all of those areas at the same time.

Ideally we would be able to control the color of the breadcrumbs with a
specific theme color, but since they are drawn with the regular layout
system, that is not easily possible.

Thanks to @fabian_schempp for the original patch.

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

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

M	source/blender/editors/include/ED_node.h
M	source/blender/editors/include/UI_interface.hh
M	source/blender/editors/interface/CMakeLists.txt
A	source/blender/editors/interface/interface_context_path.cc
M	source/blender/editors/space_node/CMakeLists.txt
A	source/blender/editors/space_node/node_context_path.cc
M	source/blender/editors/space_node/node_draw.cc
M	source/blender/editors/space_node/node_intern.h
M	source/blender/editors/space_node/space_node.c
M	source/blender/makesrna/intern/rna_gpencil_modifier.c

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

diff --git a/source/blender/editors/include/ED_node.h b/source/blender/editors/include/ED_node.h
index 1ba52552902..e68617f7867 100644
--- a/source/blender/editors/include/ED_node.h
+++ b/source/blender/editors/include/ED_node.h
@@ -64,7 +64,6 @@ void ED_node_cursor_location_set(struct SpaceNode *snode, const float value[2]);
 
 int ED_node_tree_path_length(struct SpaceNode *snode);
 void ED_node_tree_path_get(struct SpaceNode *snode, char *value);
-void ED_node_tree_path_get_fixedbuf(struct SpaceNode *snode, char *value, int max_length);
 
 void ED_node_tree_start(struct SpaceNode *snode,
                         struct bNodeTree *ntree,
diff --git a/source/blender/editors/include/UI_interface.hh b/source/blender/editors/include/UI_interface.hh
index 5edccfa8c88..b14ee6c4a59 100644
--- a/source/blender/editors/include/UI_interface.hh
+++ b/source/blender/editors/include/UI_interface.hh
@@ -23,15 +23,40 @@
 #include <memory>
 
 #include "BLI_string_ref.hh"
+#include "BLI_vector.hh"
+
+#include "UI_resources.h"
 
 namespace blender::nodes::geometry_nodes_eval_log {
 struct GeometryAttributeInfo;
 }
 
 struct uiBlock;
+struct StructRNA;
+struct uiSearchItems;
+
 namespace blender::ui {
+
 class AbstractTreeView;
 
+/**
+ * An item in a breadcrumb-like context. Currently this struct is very simple, but more
+ * could be added to it in the future, to support interactivity or tooltips, for example.
+ */
+struct ContextPathItem {
+  /* Text to display in the UI. */
+  std::string name;
+  /* #BIFIconID */
+  int icon;
+};
+
+void context_path_add_generic(Vector<ContextPathItem> &path,
+                              StructRNA &rna_type,
+                              void *ptr,
+                              const BIFIconID icon_override = ICON_NONE);
+
+void template_breadcrumbs(uiLayout &layout, Span<ContextPathItem> context_path);
+
 void attribute_search_add_items(
     StringRefNull str,
     const bool is_output,
diff --git a/source/blender/editors/interface/CMakeLists.txt b/source/blender/editors/interface/CMakeLists.txt
index b2659f5ed52..84172c7efce 100644
--- a/source/blender/editors/interface/CMakeLists.txt
+++ b/source/blender/editors/interface/CMakeLists.txt
@@ -43,6 +43,7 @@ set(SRC
   interface_anim.c
   interface_button_group.c
   interface_context_menu.c
+  interface_context_path.cc
   interface_draw.c
   interface_dropboxes.cc
   interface_eyedropper.c
diff --git a/source/blender/editors/interface/interface_context_path.cc b/source/blender/editors/interface/interface_context_path.cc
new file mode 100644
index 00000000000..b0f8d186afa
--- /dev/null
+++ b/source/blender/editors/interface/interface_context_path.cc
@@ -0,0 +1,85 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2021 Blender Foundation.
+ * All rights reserved.
+ */
+
+/** \file
+ * \ingroup edinterface
+ */
+
+#include "BLI_vector.hh"
+
+#include "BKE_screen.h"
+
+#include "RNA_access.h"
+
+#include "ED_screen.h"
+
+#include "UI_interface.h"
+#include "UI_interface.hh"
+#include "UI_resources.h"
+
+#include "WM_api.h"
+
+namespace blender::ui {
+
+void context_path_add_generic(Vector<ContextPathItem> &path,
+                              StructRNA &rna_type,
+                              void *ptr,
+                              const BIFIconID icon_override)
+{
+  /* Add the null check here to make calling functions less verbose. */
+  if (!ptr) {
+    return;
+  }
+
+  PointerRNA rna_ptr;
+  RNA_pointer_create(nullptr, &rna_type, ptr, &rna_ptr);
+  char name[128];
+  RNA_struct_name_get_alloc(&rna_ptr, name, sizeof(name), nullptr);
+
+  /* Use a blank icon by default to check whether to retrieve it automatically from the type. */
+  const BIFIconID icon = icon_override == ICON_NONE ?
+                             static_cast<BIFIconID>(RNA_struct_ui_icon(rna_ptr.type)) :
+                             icon_override;
+
+  path.append({name, static_cast<int>(icon)});
+}
+
+/* -------------------------------------------------------------------- */
+/** \name Breadcrumb Template
+ * \{ */
+
+void template_breadcrumbs(uiLayout &layout, Span<ContextPathItem> context_path)
+{
+  uiLayout *row = uiLayoutRow(&layout, true);
+  uiLayoutSetAlignment(&layout, UI_LAYOUT_ALIGN_LEFT);
+
+  for (const int i : context_path.index_range()) {
+    uiLayout *sub_row = uiLayoutRow(row, true);
+    uiLayoutSetAlignment(sub_row, UI_LAYOUT_ALIGN_LEFT);
+
+    if (i > 0) {
+      uiItemL(sub_row, "", ICON_RIGHTARROW_THIN);
+    }
+    uiItemL(sub_row, context_path[i].name.c_str(), context_path[i].icon);
+  }
+}
+
+}  // namespace blender::ui
+
+/** \} */
\ No newline at end of file
diff --git a/source/blender/editors/space_node/CMakeLists.txt b/source/blender/editors/space_node/CMakeLists.txt
index 80d3b43bf6b..600309c2c86 100644
--- a/source/blender/editors/space_node/CMakeLists.txt
+++ b/source/blender/editors/space_node/CMakeLists.txt
@@ -40,6 +40,7 @@ set(INC
 set(SRC
   drawnode.cc
   node_add.cc
+  node_context_path.cc
   node_draw.cc
   node_edit.cc
   node_geometry_attribute_search.cc
diff --git a/source/blender/editors/space_node/node_context_path.cc b/source/blender/editors/space_node/node_context_path.cc
new file mode 100644
index 00000000000..a0ff7f3ce25
--- /dev/null
+++ b/source/blender/editors/space_node/node_context_path.cc
@@ -0,0 +1,184 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2008 Blender Foundation.
+ * All rights reserved.
+ */
+
+/** \file
+ * \ingroup spnode
+ * \brief Node breadcrumbs drawing
+ */
+
+#include "BLI_vector.hh"
+
+#include "DNA_node_types.h"
+
+#include "BKE_context.h"
+#include "BKE_material.h"
+#include "BKE_modifier.h"
+#include "BKE_object.h"
+
+#include "BKE_screen.h"
+
+#include "RNA_access.h"
+
+#include "ED_screen.h"
+
+#include "UI_interface.h"
+#include "UI_interface.hh"
+#include "UI_resources.h"
+
+#include "UI_interface.hh"
+
+#include "node_intern.h"
+
+struct Mesh;
+struct Curve;
+struct Light;
+struct World;
+struct Material;
+
+namespace blender::ed::space_node {
+
+static void context_path_add_object_data(Vector<ui::ContextPathItem> &path, Object &object)
+{
+  if (object.type == OB_MESH && object.data) {
+    Mesh *mesh = (Mesh *)object.data;
+    ui::context_path_add_generic(path, RNA_Mesh, mesh);
+  }
+  if (object.type == OB_LAMP && object.data) {
+    Light *light = (Light *)object.data;
+    ui::context_path_add_generic(path, RNA_Light, light);
+  }
+  if (ELEM(object.type, OB_CURVE, OB_FONT, OB_SURF) && object.data) {
+    Curve *curve = (Curve *)object.data;
+    ui::context_path_add_generic(path, RNA_Curve, curve);
+  }
+}
+
+static void context_path_add_node_tree_and_node_groups(const SpaceNode &snode,
+                                                       Vector<ui::ContextPathItem> &path,
+                                                       const bool skip_base = false)
+{
+  Vector<const bNodeTreePath *> tree_path = snode.treepath;
+  for (const bNodeTreePath *path_item : tree_path.as_span().drop_front(int(skip_base))) {
+    ui::context_path_add_generic(path, RNA_NodeTree, path_item->nodetree, ICON_NODETREE);
+  }
+}
+
+static void get_context_path_node_shader(const bContext &C,
+                                         SpaceNode &snode,
+                                         Vector<ui::ContextPathItem> &path)
+{
+  if (snode.flag & SNODE_PIN) {
+    if (snode.shaderfrom == SNODE_SHADER_WORLD) {
+      Scene *scene = CTX_data_scene(&C);
+      ui::context_path_add_generic(path, RNA_Scene, scene);
+      if (scene != nullptr) {
+        World *world = scene->world;
+        ui::context_path_add_generic(path, RNA_World, world);
+      }
+      /* Skip the base node tree here, because the world contains a node tree already. */
+      context_path_add_node_tree_and_node_groups(snode, path, true);
+    }
+    else {
+      context_path_add_node_tree_and_node_groups(snode, path);
+    }
+  }
+  else {
+    Object *object = CTX_data_active_object(&C);
+    if (snode.shaderfrom == SNODE_SHADER_OBJECT && object != nullptr) {
+      ui::context_path_add_generic(path, RNA_Object, object);
+      if (!(object->matbits && object->matbits[object->actcol - 1])) {
+        context_path_add_object_data(path, *object);
+      }
+      Material *material = BKE_object_material_get(object, object->actcol);
+      ui::context_path_add_generic(path, RNA_Material, material);
+    }
+    else if (snode.shaderfrom == SNODE_SHADER_WORLD) {
+      Scene *scene = CTX_data_scene(&C);
+      ui::context_path_add_generic(path, RNA_Scene, scene);
+      if (scene != nullptr) {
+        World *world = scene->world;
+        ui::context_path_add_generic(path, RNA_World, world);
+      }
+    }
+#ifdef WITH_FREESTYLE
+    else if (snode.shaderfrom == SNODE_SHADER_LINESTYLE) {
+      ViewLayer *viewlayer = CTX_da

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list