[Bf-blender-cvs] [69ab1bd73ca] temp-geometry-nodes-evaluator-refactor: cleanup

Jacques Lucke noreply at git.blender.org
Thu Sep 8 17:22:30 CEST 2022


Commit: 69ab1bd73ca7957cf7bb42fd534c3c65e7dab02a
Author: Jacques Lucke
Date:   Thu Sep 8 11:01:37 2022 +0200
Branches: temp-geometry-nodes-evaluator-refactor
https://developer.blender.org/rB69ab1bd73ca7957cf7bb42fd534c3c65e7dab02a

cleanup

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

M	source/blender/editors/space_node/node_draw.cc

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

diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc
index 9d5ce17a9be..f5a39bfd631 100644
--- a/source/blender/editors/space_node/node_draw.cc
+++ b/source/blender/editors/space_node/node_draw.cc
@@ -180,6 +180,12 @@ void ED_node_tag_update_id(ID *id)
 
 namespace blender::ed::space_node {
 
+static void node_socket_add_tooltip_in_node_editor(TreeDrawContext *UNUSED(tree_draw_ctx),
+                                                   const bNodeTree *ntree,
+                                                   const bNode *node,
+                                                   const bNodeSocket *sock,
+                                                   uiLayout *layout);
+
 static bool compare_nodes(const bNode *a, const bNode *b)
 {
   /* These tell if either the node or any of the parent nodes is selected.
@@ -333,390 +339,182 @@ float2 node_from_view(const bNode &node, const float2 &co)
   return result;
 }
 
-struct SocketTooltipData {
-  const bNodeTree *ntree;
-  const bNode *node;
-  const bNodeSocket *socket;
-};
-
-static bool node_socket_has_tooltip(const bNodeTree *ntree, const bNodeSocket *socket)
+/**
+ * Based on settings and sockets in node, set drawing rect info.
+ */
+static void node_update_basis(const bContext &C,
+                              TreeDrawContext &tree_draw_ctx,
+                              bNodeTree &ntree,
+                              bNode &node,
+                              uiBlock &block)
 {
-  if (ntree->type == NTREE_GEOMETRY) {
-    return true;
-  }
+  PointerRNA nodeptr;
+  RNA_pointer_create(&ntree.id, &RNA_Node, &node, &nodeptr);
 
-  if (socket->runtime->declaration != nullptr) {
-    const nodes::SocketDeclaration &socket_decl = *socket->runtime->declaration;
-    return !socket_decl.description().is_empty();
-  }
+  const bool node_options = node.typeinfo->draw_buttons && (node.flag & NODE_OPTIONS);
+  const bool inputs_first = node.inputs.first &&
+                            !(node.outputs.first || (node.flag & NODE_PREVIEW) || node_options);
 
-  return false;
-}
+  /* Get "global" coordinates. */
+  float2 loc = node_to_view(node, float2(0));
+  /* Round the node origin because text contents are always pixel-aligned. */
+  loc.x = round(loc.x);
+  loc.y = round(loc.y);
 
-static void create_inspection_string_for_generic_value(const GPointer value, std::stringstream &ss)
-{
-  auto id_to_inspection_string = [&](const ID *id, const short idcode) {
-    ss << (id ? id->name + 2 : TIP_("None")) << " (" << TIP_(BKE_idtype_idcode_to_name(idcode))
-       << ")";
-  };
+  int dy = loc.y;
 
-  const CPPType &type = *value.type();
-  const void *buffer = value.get();
-  if (type.is<Object *>()) {
-    id_to_inspection_string(*static_cast<const ID *const *>(buffer), ID_OB);
-  }
-  else if (type.is<Material *>()) {
-    id_to_inspection_string(*static_cast<const ID *const *>(buffer), ID_MA);
-  }
-  else if (type.is<Tex *>()) {
-    id_to_inspection_string(*static_cast<const ID *const *>(buffer), ID_TE);
-  }
-  else if (type.is<Image *>()) {
-    id_to_inspection_string(*static_cast<const ID *const *>(buffer), ID_IM);
-  }
-  else if (type.is<Collection *>()) {
-    id_to_inspection_string(*static_cast<const ID *const *>(buffer), ID_GR);
-  }
-  else if (type.is<int>()) {
-    ss << *(int *)buffer << TIP_(" (Integer)");
-  }
-  else if (type.is<float>()) {
-    ss << *(float *)buffer << TIP_(" (Float)");
-  }
-  else if (type.is<blender::float3>()) {
-    ss << *(blender::float3 *)buffer << TIP_(" (Vector)");
-  }
-  else if (type.is<bool>()) {
-    ss << ((*(bool *)buffer) ? TIP_("True") : TIP_("False")) << TIP_(" (Boolean)");
-  }
-  else if (type.is<std::string>()) {
-    ss << *(std::string *)buffer << TIP_(" (String)");
+  /* Header. */
+  dy -= NODE_DY;
+
+  /* Add a little bit of padding above the top socket. */
+  if (node.outputs.first || inputs_first) {
+    dy -= NODE_DYS / 2;
   }
-}
 
-static void create_inspection_string_for_field_info(const geo_log::FieldInfoLog &value_log,
-                                                    std::stringstream &ss)
-{
-  const CPPType &type = value_log.type;
-  const Span<std::string> input_tooltips = value_log.input_tooltips;
+  /* Output sockets. */
+  bool add_output_space = false;
 
-  if (input_tooltips.is_empty()) {
-    /* Should have been logged as constant value. */
-    BLI_assert_unreachable();
-    ss << "Value has not been logged";
-  }
-  else {
-    if (type.is<int>()) {
-      ss << TIP_("Integer field");
+  int buty;
+  LISTBASE_FOREACH (bNodeSocket *, socket, &node.outputs) {
+    if (nodeSocketIsHidden(socket)) {
+      continue;
     }
-    else if (type.is<float>()) {
-      ss << TIP_("Float field");
+
+    PointerRNA sockptr;
+    RNA_pointer_create(&ntree.id, &RNA_NodeSocket, socket, &sockptr);
+
+    uiLayout *layout = UI_block_layout(&block,
+                                       UI_LAYOUT_VERTICAL,
+                                       UI_LAYOUT_PANEL,
+                                       loc.x + NODE_DYS,
+                                       dy,
+                                       NODE_WIDTH(node) - NODE_DY,
+                                       NODE_DY,
+                                       0,
+                                       UI_style_get_dpi());
+
+    if (node.flag & NODE_MUTED) {
+      uiLayoutSetActive(layout, false);
     }
-    else if (type.is<blender::float3>()) {
-      ss << TIP_("Vector field");
+
+    /* Context pointers for current node and socket. */
+    uiLayoutSetContextPointer(layout, "node", &nodeptr);
+    uiLayoutSetContextPointer(layout, "socket", &sockptr);
+
+    /* Align output buttons to the right. */
+    uiLayout *row = uiLayoutRow(layout, true);
+    uiLayoutSetAlignment(row, UI_LAYOUT_ALIGN_RIGHT);
+    const char *socket_label = nodeSocketLabel(socket);
+    socket->typeinfo->draw((bContext *)&C, row, &sockptr, &nodeptr, IFACE_(socket_label));
+
+    node_socket_add_tooltip_in_node_editor(&tree_draw_ctx, &ntree, &node, socket, row);
+
+    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);
+
+    /* Round the socket location to stop it from jiggling. */
+    socket->locx = round(loc.x + NODE_WIDTH(node));
+    socket->locy = round(dy - NODE_DYS);
+
+    dy = buty;
+    if (socket->next) {
+      dy -= NODE_SOCKDY;
     }
-    else if (type.is<bool>()) {
-      ss << TIP_("Boolean field");
+
+    add_output_space = true;
+  }
+
+  if (add_output_space) {
+    dy -= NODE_DY / 4;
+  }
+
+  node.prvr.xmin = loc.x + NODE_DYS;
+  node.prvr.xmax = loc.x + NODE_WIDTH(node) - NODE_DYS;
+
+  /* preview rect? */
+  if (node.flag & NODE_PREVIEW) {
+    float aspect = 1.0f;
+
+    if (node.preview_xsize && node.preview_ysize) {
+      aspect = (float)node.preview_ysize / (float)node.preview_xsize;
     }
-    else if (type.is<std::string>()) {
-      ss << TIP_("String field");
+
+    dy -= NODE_DYS / 2;
+    node.prvr.ymax = dy;
+
+    if (aspect <= 1.0f) {
+      node.prvr.ymin = dy - aspect * (NODE_WIDTH(node) - NODE_DY);
     }
-    else if (type.is<blender::ColorGeometry4f>()) {
-      ss << TIP_("Color field");
+    else {
+      /* Width correction of image. XXX huh? (ton) */
+      float dx = (NODE_WIDTH(node) - NODE_DYS) - (NODE_WIDTH(node) - NODE_DYS) / aspect;
+
+      node.prvr.ymin = dy - (NODE_WIDTH(node) - NODE_DY);
+
+      node.prvr.xmin += 0.5f * dx;
+      node.prvr.xmax -= 0.5f * dx;
     }
-    ss << TIP_(" based on:\n");
 
-    for (const int i : input_tooltips.index_range()) {
-      const blender::StringRef tooltip = input_tooltips[i];
-      ss << "\u2022 " << tooltip;
-      if (i < input_tooltips.size() - 1) {
-        ss << ".\n";
-      }
+    dy = node.prvr.ymin - NODE_DYS / 2;
+
+    /* Make sure that maximums are bigger or equal to minimums. */
+    if (node.prvr.xmax < node.prvr.xmin) {
+      SWAP(float, node.prvr.xmax, node.prvr.xmin);
+    }
+    if (node.prvr.ymax < node.prvr.ymin) {
+      SWAP(float, node.prvr.ymax, node.prvr.ymin);
     }
   }
-}
 
-static void create_inspection_string_for_geometry_info(const geo_log::GeometryInfoLog &value_log,
-                                                       std::stringstream &ss,
-                                                       const nodes::decl::Geometry *socket_decl)
-{
-  Span<GeometryComponentType> component_types = value_log.component_types;
-  if (component_types.is_empty()) {
-    ss << TIP_("Empty Geometry");
-    return;
+  /* Buttons rect? */
+  if (node_options) {
+    dy -= NODE_DYS / 2;
+
+    uiLayout *layout = UI_block_layout(&block,
+                                       UI_LAYOUT_VERTICAL,
+                                       UI_LAYOUT_PANEL,
+                                       loc.x + NODE_DYS,
+                                       dy,
+                                       NODE_WIDTH(node) - NODE_DY,
+                                       0,
+                                       0,
+                                       UI_style_get_dpi());
+
+    if (node.flag & NODE_MUTED) {
+      uiLayoutSetActive(layout, false);
+    }
+
+    uiLayoutSetContextPointer(layout, "node", &nodeptr);
+
+    node.typeinfo->draw_buttons(layout, (bContext *)&C, &nodeptr);
+
+    UI_block_align_end(&block);
+    UI_block_layout_resolve(&block, nullptr, &buty);
+
+    dy = buty - NODE_DYS / 2;
   }
 
-  auto to_string = [](int value) {
-    char str[16];
-    BLI_str_format_int_grouped(str, value);
-    return std::string(str);
-  };
+  /* Input sockets. */
+  LISTBASE_FOREACH (bNodeSocket *, socket, &node.inputs) {
+    if (nodeSocketIsHidden(socket)) {
+      continue;
+    }
 
-  ss << TIP_("Geometry:\n");
-  for (GeometryComponentType type : component_types) {
-    const char *line_end = (type == component_types.last()) ? "" : ".\n";
-    switch (type) {
-      case GEO_COMPONENT_TYPE_MESH: {
-        const geo_log::GeometryInfoLog::MeshInfo &mesh_info = *value_log.mesh_info;
-        char line[256];
-        BLI_snprintf(line,
-                     sizeof(line),
-                  

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list