[Bf-blender-cvs] [52487367e8d] temp-node-error-messages: Move to header with red icon, add a type switch
Hans Goudey
noreply at git.blender.org
Thu Jan 21 20:52:46 CET 2021
Commit: 52487367e8d9e871cce90752ef1bcf962d616438
Author: Hans Goudey
Date: Thu Jan 21 13:52:39 2021 -0600
Branches: temp-node-error-messages
https://developer.blender.org/rB52487367e8d9e871cce90752ef1bcf962d616438
Move to header with red icon, add a type switch
===================================================================
M source/blender/blenkernel/BKE_node.h
M source/blender/blenkernel/intern/node.cc
M source/blender/editors/space_node/node_draw.c
M source/blender/nodes/NOD_geometry_exec.hh
M source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
M source/blender/nodes/geometry/nodes/node_geo_point_instance.cc
M source/blender/nodes/intern/node_geometry_exec.cc
===================================================================
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index 90574bc72a9..0447349f2b3 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -938,13 +938,25 @@ void BKE_nodetree_remove_layer_n(struct bNodeTree *ntree,
struct Scene *scene,
const int layer_index);
+typedef enum eNodeWarningType {
+ NODE_WARNING_ERROR,
+ NODE_WARNING_INFO,
+} eNodeWarningType;
+
+typedef struct NodeWarning {
+ eNodeWarningType type;
+ char *message;
+} NodeWarning;
+
void BKE_nodetree_error_message_add(struct bNodeTree *ntree,
const struct bNode *node,
+ const eNodeWarningType type,
const char *message);
void BKE_nodetree_error_messages_clear(struct bNodeTree *ntree);
-const char *BKE_nodetree_error_message_get(const struct bNodeTree *ntree, const bNode *node);
+const NodeWarning *BKE_nodetree_error_message_get(const struct bNodeTree *ntree,
+ const bNode *node);
/* -------------------------------------------------------------------- */
/** \name Shader Nodes
diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc
index 4bd043256f4..47aac158eff 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -105,7 +105,7 @@ static CLG_LogRef LOG = {"bke.node"};
class bNodeTreeRuntime {
public:
- blender::Map<const std::string, const std::string> error_messages;
+ blender::Map<const std::string, NodeWarning> error_messages;
};
static void nodetree_runtime_ensure(bNodeTree *ntree)
@@ -115,14 +115,17 @@ static void nodetree_runtime_ensure(bNodeTree *ntree)
}
}
-void BKE_nodetree_error_message_add(bNodeTree *ntree, const bNode *node, const char *message)
+void BKE_nodetree_error_message_add(bNodeTree *ntree,
+ const bNode *node,
+ const eNodeWarningType type,
+ const char *message)
{
nodetree_runtime_ensure(ntree);
bNodeTreeRuntime *runtime = ntree->runtime;
- const std::string message_string(message);
+ NodeWarning warning = {type, BLI_strdup(message)};
- runtime->error_messages.add(node->name, std::move(message_string));
+ runtime->error_messages.add(node->name, warning);
}
void BKE_nodetree_error_messages_clear(bNodeTree *ntree)
@@ -133,7 +136,7 @@ void BKE_nodetree_error_messages_clear(bNodeTree *ntree)
}
}
-const char *BKE_nodetree_error_message_get(const bNodeTree *ntree, const bNode *node)
+const NodeWarning *BKE_nodetree_error_message_get(const bNodeTree *ntree, const bNode *node)
{
bNodeTreeRuntime *runtime = ntree->runtime;
if (runtime == nullptr) {
@@ -142,7 +145,7 @@ const char *BKE_nodetree_error_message_get(const bNodeTree *ntree, const bNode *
const std::string node_name = std::string(node->name);
if (runtime->error_messages.contains(node_name)) {
- return runtime->error_messages.lookup(node_name).data();
+ return &runtime->error_messages.lookup(node_name);
}
return nullptr;
diff --git a/source/blender/editors/space_node/node_draw.c b/source/blender/editors/space_node/node_draw.c
index 5bb2667e2bb..13ddf31894e 100644
--- a/source/blender/editors/space_node/node_draw.c
+++ b/source/blender/editors/space_node/node_draw.c
@@ -22,6 +22,8 @@
* \brief higher level node drawing for the node editor.
*/
+#include "MEM_guardedalloc.h"
+
#include "DNA_light_types.h"
#include "DNA_linestyle_types.h"
#include "DNA_material_types.h"
@@ -539,31 +541,6 @@ static void node_update_basis(const bContext *C, bNodeTree *ntree, bNode *node)
}
}
- {
- const char *message = BKE_nodetree_error_message_get(ntree, node);
- if (message != NULL) {
- uiLayout *layout = UI_block_layout(node->block,
- UI_LAYOUT_VERTICAL,
- UI_LAYOUT_PANEL,
- locx + NODE_DYS,
- dy,
- NODE_WIDTH(node) - NODE_DY,
- NODE_DY,
- 0,
- UI_style_get_dpi());
-
- if (node->flag & NODE_MUTED) {
- uiLayoutSetActive(layout, false);
- }
-
- uiItemL(layout, message, ICON_ERROR);
- UI_block_layout_resolve(node->block, NULL, &buty);
-
- buty = min_ii(buty, dy - NODE_DY);
- dy = buty;
- }
- }
-
/* little bit space in end */
if (node->inputs.first || (node->flag & (NODE_OPTIONS | NODE_PREVIEW)) == 0) {
dy -= NODE_DYS / 2;
@@ -1142,6 +1119,65 @@ void node_draw_sockets(const View2D *v2d,
GPU_blend(GPU_BLEND_NONE);
}
+static int node_error_type_to_icon(const eNodeWarningType type)
+{
+ switch (type) {
+ case NODE_WARNING_ERROR:
+ return ICON_ERROR;
+ case NODE_WARNING_INFO:
+ return ICON_INFO;
+ }
+
+ BLI_assert(false);
+ return ICON_ERROR;
+}
+
+static char *node_errros_tooltip_fn(bContext *UNUSED(C), void *argN, const char *UNUSED(tip))
+{
+ NodeWarning *message = (NodeWarning *)argN;
+
+ return BLI_strdup(message->message);
+}
+
+#define NODE_HEADER_ICON_SIZE 0.8f * U.widget_unit
+
+static int node_add_error_message_button(bNodeTree *ntree,
+ bNode *node,
+ const rctf *rect,
+ int icon_offset)
+{
+ const NodeWarning *message = BKE_nodetree_error_message_get(ntree, node);
+ if (message == NULL) {
+ return icon_offset;
+ }
+
+ icon_offset -= NODE_HEADER_ICON_SIZE;
+
+ UI_block_emboss_set(node->block, UI_EMBOSS_NONE);
+ NodeWarning *warning_alloc = MEM_mallocN(sizeof(NodeWarning), __func__);
+ warning_alloc->type = message->type;
+ warning_alloc->message = message->message;
+ uiBut *but = uiDefIconBut(node->block,
+ UI_BTYPE_BUT,
+ 0,
+ node_error_type_to_icon(message->type),
+ icon_offset,
+ rect->ymax - NODE_DY,
+ NODE_HEADER_ICON_SIZE,
+ UI_UNIT_Y,
+ NULL,
+ 0,
+ 0,
+ 0,
+ 0,
+ NULL);
+ UI_but_func_tooltip_set(but, node_errros_tooltip_fn, warning_alloc);
+ UI_but_flag_enable(but, UI_BUT_REDALERT);
+ UI_block_emboss_set(node->block, UI_EMBOSS);
+
+ return icon_offset;
+}
+
static void node_draw_basis(const bContext *C,
const View2D *v2d,
const SpaceNode *snode,
@@ -1150,7 +1186,7 @@ static void node_draw_basis(const bContext *C,
bNodeInstanceKey key)
{
/* float socket_size = NODE_SOCKSIZE*U.dpi/72; */ /* UNUSED */
- float iconbutw = 0.8f * UI_UNIT_X;
+ const float iconbutw = NODE_HEADER_ICON_SIZE;
/* skip if out of view */
if (BLI_rctf_isect(&node->totr, &v2d->cur, NULL) == false) {
@@ -1253,6 +1289,8 @@ static void node_draw_basis(const bContext *C,
UI_block_emboss_set(node->block, UI_EMBOSS);
}
+ iconofs = node_add_error_message_button(ntree, node, rct, iconofs);
+
/* title */
if (node->flag & SELECT) {
UI_GetThemeColor4fv(TH_SELECT, color);
@@ -1360,26 +1398,6 @@ static void node_draw_basis(const bContext *C,
}
}
- // {
- // const char *message = BKE_nodetree_error_message_get(ntree, node);
- // if (message != NULL) {
- // uiDefBut(block,
- // UI_BTYPE_LABEL,
- // 1,
- // message,
- // 0,
- // 0,
- // 2 * UI_UNIT_X,
- // UI_UNIT_Y,
- // NULL,
- // 0.0,
- // 0.0,
- // 0,
- // 0,
- // "");
- // }
- // }
-
UI_block_end(C, node->block);
UI_block_draw(C, node->block);
node->block = NULL;
diff --git a/source/blender/nodes/NOD_geometry_exec.hh b/source/blender/nodes/NOD_geometry_exec.hh
index df77a891aa2..0e8b723af64 100644
--- a/source/blender/nodes/NOD_geometry_exec.hh
+++ b/source/blender/nodes/NOD_geometry_exec.hh
@@ -183,7 +183,7 @@ class GeoNodeExecParams {
* Add an error message displayed at the bottom of the node when displaying the node tree,
* and potentially elsewhere in Blender.
*/
- void error_message_add(const std::string message) const;
+ void error_message_add(const eNodeWarningType type, const std::string message) const;
/**
* Creates a read-only attribute based on node inputs. The method automatically detects which
diff --git a/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc b/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
index 7fdcfd616d5..b30d75ec63c 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
@@ -413,7 +413,7 @@ static void geo_node_point_distribute_exec(GeoNodeExecParams params)
static_cast<GeometryNodePointDistributeMethod>(params.node().custom1);
if (!geometry_set.has_mesh()) {
- params.error_message_add("Geometry must contain a mesh");
+ params.error_message_add(NODE_WARNING_ERROR, "Geometry must contain a mesh");
params.set_output("Geometry", std::move(geometry_set_out));
return;
}
@@ -430,7 +430,7 @@ static void geo_node_point_distribute_exec(GeoNodeExecParams params)
const Mesh *mesh_in = mesh_component.get_for_read();
if (mesh_in->mpoly == nullptr) {
- params.error_message_add("Mesh has no faces");
+ params.error_message_add(NODE_WARNING_ERROR, "Mesh has no faces");
params.set_output("Geometry", std::move(geometry_set_out));
return;
}
diff --git a/source/blender/nodes/geometry/nodes/
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list