[Bf-blender-cvs] [88dcfd17326] temp-node-error-messages: Merge branch 'master' into temp-node-error-messages

Hans Goudey noreply at git.blender.org
Tue Feb 16 18:36:03 CET 2021


Commit: 88dcfd17326fc1e65dbd18a4e62f24e5a3ef4d26
Author: Hans Goudey
Date:   Tue Feb 16 11:02:55 2021 -0600
Branches: temp-node-error-messages
https://developer.blender.org/rB88dcfd17326fc1e65dbd18a4e62f24e5a3ef4d26

Merge branch 'master' into temp-node-error-messages

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



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

diff --cc source/blender/editors/space_node/node_draw.cc
index b71652ea58f,044f3882d07..bf2f9ac0718
--- a/source/blender/editors/space_node/node_draw.cc
+++ b/source/blender/editors/space_node/node_draw.cc
@@@ -1186,124 -1178,6 +1186,124 @@@ void node_draw_sockets(const View2D *v2
    }
  }
  
 +static int node_error_type_to_icon(const NodeWarningType type)
 +{
 +  switch (type) {
 +    case NodeWarningType::Error:
 +      return ICON_ERROR;
 +    case NodeWarningType::Warning:
 +      return ICON_ERROR;
 +    case NodeWarningType::Info:
 +      return ICON_INFO;
 +  }
 +
 +  BLI_assert(false);
 +  return ICON_ERROR;
 +}
 +
 +static uint8_t node_error_type_priority(const NodeWarningType type)
 +{
 +  switch (type) {
 +    case NodeWarningType::Error:
 +      return 3;
 +    case NodeWarningType::Warning:
 +      return 2;
 +    case NodeWarningType::Info:
 +      return 1;
 +  }
 +
 +  BLI_assert(false);
 +  return 0;
 +}
 +
 +static char *node_errrors_tooltip_fn(bContext *UNUSED(C), void *argN, const char *UNUSED(tip))
 +{
 +  char *message = static_cast<char *>(argN);
 +
 +  return BLI_strdup(message);
 +}
 +
 +#define NODE_HEADER_ICON_SIZE 0.8f * U.widget_unit
 +
 +static const NodeUIStorage *node_ui_storage_get_from_context(const bContext *C,
 +                                                             const bNodeTree &ntree,
 +                                                             const bNode &node)
 +{
 +  const NodeTreeUIStorage *node_tree_ui_storage = ntree.runtime;
 +  if (node_tree_ui_storage == nullptr) {
 +    return nullptr;
 +  }
 +  const Map<NodeUIStorageContextModifier, NodeUIStorage> *node_ui_storage =
 +      node_tree_ui_storage->node_map.lookup_ptr(node.name);
 +  if (node_ui_storage == nullptr) {
 +    return nullptr;
 +  }
 +
 +  const Object *active_object = CTX_data_active_object(C);
 +  const ModifierData *active_modifier = BKE_object_active_modifier(active_object);
 +  if (active_object == nullptr || active_modifier == nullptr) {
 +    return nullptr;
 +  }
 +  const NodeUIStorageContextModifier context = NodeUIStorageContextModifier(*active_object,
 +                                                                            *active_modifier);
 +
 +  return node_ui_storage->lookup_ptr(context);
 +}
 +
 +static void node_add_error_message_button(
 +    const bContext *C, bNodeTree &ntree, bNode &node, const rctf &rect, float &icon_offset)
 +{
 +  const NodeUIStorage *node_ui_storage = node_ui_storage_get_from_context(C, ntree, node);
 +  if (node_ui_storage == nullptr) {
 +    return;
 +  }
 +
 +  /* TODO: The UI API forces us to allocate memory for each error message we pass.
 +   * The ownership of #UI_but_func_tooltip_set's argument is transferred to the button.
 +   * We shouldn't need to do this though, investigate improving this. */
 +  int total_str_len = node_ui_storage->warnings.size(); /* Leave room for new line characters. */
 +  for (const NodeWarning &warning : node_ui_storage->warnings) {
 +    total_str_len += warning.message.size();
 +  }
 +  char *tooltip_alloc = (char *)MEM_mallocN(sizeof(char) * total_str_len, __func__);
 +  int tooltip_offest = 0;
 +  for (const NodeWarning &warning : node_ui_storage->warnings) {
 +    BLI_strncpy(tooltip_alloc + tooltip_offest, warning.message.c_str(), warning.message.size());
 +    tooltip_offest += warning.message.size();
 +    BLI_strncpy(tooltip_alloc + tooltip_offest, "\n", 1);
 +    tooltip_offest++;
 +  }
 +
 +  uint8_t highest_priority = 0;
 +  NodeWarningType highest_priority_type = NodeWarningType::Info;
 +  for (const NodeWarning &warning : node_ui_storage->warnings) {
 +    const uint8_t priority = node_error_type_priority(warning.type);
 +    if (priority > highest_priority) {
 +      highest_priority = priority;
 +      highest_priority_type = warning.type;
 +    }
 +  }
 +
 +  icon_offset -= NODE_HEADER_ICON_SIZE;
 +  UI_block_emboss_set(node.block, UI_EMBOSS_NONE);
 +  uiBut *but = uiDefIconBut(node.block,
 +                            UI_BTYPE_BUT,
 +                            0,
 +                            node_error_type_to_icon(highest_priority_type),
 +                            icon_offset,
 +                            rect.ymax - NODE_DY,
 +                            NODE_HEADER_ICON_SIZE,
 +                            UI_UNIT_Y,
-                             NULL,
++                            nullptr,
 +                            0,
 +                            0,
 +                            0,
 +                            0,
-                             NULL);
++                            nullptr);
 +  UI_but_func_tooltip_set(but, node_errrors_tooltip_fn, tooltip_alloc);
 +  UI_block_emboss_set(node.block, UI_EMBOSS);
 +}
 +
  static void node_draw_basis(const bContext *C,
                              const View2D *v2d,
                              const SpaceNode *snode,



More information about the Bf-blender-cvs mailing list