UI: Use a red alert theme color for unsupported nodes
Undefined nodes are currently drawn using a red alert theme color to make it easier to spot them and replace them. On the other hand, nodes that are unsupported, that is, nodes whose poll method fail, are not reported to the user in any way. So this patch also uses the same red alert color for unsupported nodes. The node_type_is_undefined function is moved to the draw file since it seems to be specific to it and not used anywhere else. Pull Request: https://projects.blender.org/blender/blender/pulls/136451
This commit is contained in:
@@ -892,8 +892,6 @@ void node_tree_local_merge(Main *bmain, bNodeTree *localtree, bNodeTree *ntree);
|
||||
*/
|
||||
void node_tree_blend_read_data(BlendDataReader *reader, ID *owner_id, bNodeTree *ntree);
|
||||
|
||||
bool node_type_is_undefined(const bNode &node);
|
||||
|
||||
bool node_is_static_socket_type(const bNodeSocketType &stype);
|
||||
|
||||
StringRefNull node_socket_sub_type_label(int subtype);
|
||||
|
||||
@@ -1785,28 +1785,6 @@ void node_register_alias(bNodeType &nt, const StringRef alias)
|
||||
get_node_type_alias_map().add_new(alias, nt.idname);
|
||||
}
|
||||
|
||||
bool node_type_is_undefined(const bNode &node)
|
||||
{
|
||||
if (node.typeinfo == &NodeTypeUndefined) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (node.is_group()) {
|
||||
const ID *group_tree = node.id;
|
||||
if (group_tree == nullptr) {
|
||||
return false;
|
||||
}
|
||||
if (!ID_IS_LINKED(group_tree)) {
|
||||
return false;
|
||||
}
|
||||
if ((group_tree->tag & ID_TAG_MISSING) == 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Span<bNodeSocketType *> node_socket_types_get()
|
||||
{
|
||||
return get_socket_type_map().as_span();
|
||||
|
||||
@@ -3345,6 +3345,35 @@ static short get_viewer_shortcut_icon(const bNode &node)
|
||||
return node.typeinfo->ui_icon;
|
||||
}
|
||||
|
||||
/* Returns true if the given node has an undefined type, a missing group node tree, or is
|
||||
* unsupported in the given node tree. */
|
||||
static bool node_undefined_or_unsupported(const bNodeTree &node_tree, const bNode &node)
|
||||
{
|
||||
if (node.typeinfo == &bke::NodeTypeUndefined) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const char *disabled_hint = nullptr;
|
||||
if (!node.typeinfo->poll(node.typeinfo, &node_tree, &disabled_hint)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (node.is_group()) {
|
||||
const ID *group_tree = node.id;
|
||||
if (group_tree == nullptr) {
|
||||
return false;
|
||||
}
|
||||
if (!ID_IS_LINKED(group_tree)) {
|
||||
return false;
|
||||
}
|
||||
if ((group_tree->tag & ID_TAG_MISSING) == 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void node_draw_basis(const bContext &C,
|
||||
TreeDrawContext &tree_draw_ctx,
|
||||
const View2D &v2d,
|
||||
@@ -3646,7 +3675,7 @@ static void node_draw_basis(const bContext &C,
|
||||
const float outline_width = U.pixelsize;
|
||||
{
|
||||
/* Use warning color to indicate undefined types. */
|
||||
if (bke::node_type_is_undefined(node)) {
|
||||
if (node_undefined_or_unsupported(ntree, node)) {
|
||||
UI_GetThemeColorBlend4f(TH_REDALERT, TH_NODE, 0.4f, color);
|
||||
}
|
||||
/* Muted nodes get a mix of the background with the node color. */
|
||||
@@ -3724,7 +3753,7 @@ static void node_draw_basis(const bContext &C,
|
||||
if (node.flag & SELECT) {
|
||||
UI_GetThemeColor4fv((node.flag & NODE_ACTIVE) ? TH_ACTIVE : TH_SELECT, color_outline);
|
||||
}
|
||||
else if (bke::node_type_is_undefined(node)) {
|
||||
else if (node_undefined_or_unsupported(ntree, node)) {
|
||||
UI_GetThemeColor4fv(TH_REDALERT, color_outline);
|
||||
}
|
||||
else if (const bke::bNodeZoneType *zone_type = bke::zone_type_by_node_type(node.type_legacy)) {
|
||||
@@ -3788,7 +3817,7 @@ static void node_draw_hidden(const bContext &C,
|
||||
/* Body. */
|
||||
float color[4];
|
||||
{
|
||||
if (bke::node_type_is_undefined(node)) {
|
||||
if (node_undefined_or_unsupported(ntree, node)) {
|
||||
/* Use warning color to indicate undefined types. */
|
||||
UI_GetThemeColorBlend4f(TH_REDALERT, TH_NODE, 0.4f, color);
|
||||
}
|
||||
@@ -3889,7 +3918,7 @@ static void node_draw_hidden(const bContext &C,
|
||||
if (node.flag & SELECT) {
|
||||
UI_GetThemeColor4fv((node.flag & NODE_ACTIVE) ? TH_ACTIVE : TH_SELECT, color_outline);
|
||||
}
|
||||
else if (bke::node_type_is_undefined(node)) {
|
||||
else if (node_undefined_or_unsupported(ntree, node)) {
|
||||
UI_GetThemeColor4fv(TH_REDALERT, color_outline);
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user