diff --git a/source/blender/editors/include/UI_resources.hh b/source/blender/editors/include/UI_resources.hh index 31711ecf73d..8313e08cf90 100644 --- a/source/blender/editors/include/UI_resources.hh +++ b/source/blender/editors/include/UI_resources.hh @@ -464,6 +464,13 @@ void UI_GetThemeColorType4ubv(int colorid, int spacetype, unsigned char col[4]); */ bool UI_GetIconThemeColor4ubv(int colorid, unsigned char col[4]); +/** + * Get four color values, range 0.0-1.0, blended between two other float color pointers, + * complete with offset for the alpha component. + */ +void UI_GetColorPtrBlendAlpha4fv( + const float cp1[4], const float cp2[4], float fac, float alphaoffset, float r_col[4]); + /** * Shade a 3 byte color (same as UI_GetColorPtrBlendShade3ubv with 0.0 factor). */ diff --git a/source/blender/editors/interface/resources.cc b/source/blender/editors/interface/resources.cc index ac9aa9a73a4..e28ad2e05aa 100644 --- a/source/blender/editors/interface/resources.cc +++ b/source/blender/editors/interface/resources.cc @@ -1486,6 +1486,28 @@ bool UI_GetIconThemeColor4ubv(int colorid, uchar col[4]) return true; } +void UI_GetColorPtrBlendAlpha4fv( + const float cp1[4], const float cp2[4], float fac, const float alphaoffset, float r_col[4]) +{ + float r, g, b, a; + + CLAMP(fac, 0.0f, 1.0f); + r = (1.0f - fac) * cp1[0] + fac * cp2[0]; + g = (1.0f - fac) * cp1[1] + fac * cp2[1]; + b = (1.0f - fac) * cp1[2] + fac * cp2[2]; + a = (1.0f - fac) * cp1[3] + fac * cp2[3] + alphaoffset; + + CLAMP(r, 0.0f, 1.0f); + CLAMP(g, 0.0f, 1.0f); + CLAMP(b, 0.0f, 1.0f); + CLAMP(a, 0.0f, 1.0f); + + r_col[0] = r; + r_col[1] = g; + r_col[2] = b; + r_col[3] = a; +} + void UI_GetColorPtrShade3ubv(const uchar cp[3], int offset, uchar r_col[3]) { int r, g, b; diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc index c47456107d8..9fd75611efc 100644 --- a/source/blender/editors/space_node/node_draw.cc +++ b/source/blender/editors/space_node/node_draw.cc @@ -2873,6 +2873,41 @@ static bool node_undefined_or_unsupported(const bNodeTree &node_tree, const bNod return false; } +static ColorTheme4f node_header_color_get(const bNodeTree &ntree, + const bNode &node, + const int color_id) +{ + ColorTheme4f color_header; + + /* The base color of the node header. */ + if (node_undefined_or_unsupported(ntree, node)) { + /* Use warning color to indicate undefined types. */ + UI_GetThemeColorBlendShade4fv(TH_REDALERT, color_id, 0.1f, -40, color_header); + } + else if ((node.flag & NODE_COLLAPSED) && (node.flag & NODE_CUSTOM_COLOR)) { + rgba_float_args_set(color_header, node.color[0], node.color[1], node.color[2], 1.0f); + } + else { + UI_GetThemeColor4fv(color_id, color_header); + } + + /* Draw selected nodes fully opaque. */ + if (node.flag & SELECT) { + color_header.a = 1.0f; + } + + /* Muted nodes get a mix of the background with the node color and are drawn slightly + * transparent so the wires inside are visible. */ + if (node.is_muted()) { + ColorTheme4f color_background; + UI_GetThemeColor4fv(TH_BACK, color_background); + + UI_GetColorPtrBlendAlpha4fv(color_header, color_background, 0.6f, -0.2f, color_header); + } + + return color_header; +} + static void node_header_custom_tooltip(const bNode &node, uiBut &but) { UI_but_func_tooltip_custom_set( @@ -2985,18 +3020,7 @@ static void node_draw_basis(const bContext &C, rct.ymax + padding, }; - float color_header[4]; - - /* Muted nodes get a mix of the background with the node color. */ - if (node_undefined_or_unsupported(ntree, node)) { - UI_GetThemeColorShade4fv(TH_REDALERT, -20, color_header); - } - else if (node.is_muted()) { - UI_GetThemeColorBlendShade4fv(TH_BACK, color_id, 0.4f, 0, color_header); - } - else { - UI_GetThemeColor4fv(color_id, color_header); - } + const ColorTheme4f color_header = node_header_color_get(ntree, node, color_id); UI_draw_roundbox_corner_set(UI_CNR_TOP_LEFT | UI_CNR_TOP_RIGHT); UI_draw_roundbox_4fv(&rect, true, corner_radius, color_header); @@ -3213,10 +3237,6 @@ static void node_draw_basis(const bContext &C, if (node_undefined_or_unsupported(ntree, node)) { UI_GetThemeColorShade4fv(TH_REDALERT, -40, color); } - /* Muted nodes get a mix of the background with the node color. */ - else if (node.is_muted()) { - UI_GetThemeColorBlend4f(TH_BACK, TH_NODE, 0.2f, color); - } else if (node.flag & NODE_CUSTOM_COLOR) { rgba_float_args_set(color, node.color[0], node.color[1], node.color[2], 1.0f); } @@ -3229,9 +3249,13 @@ static void node_draw_basis(const bContext &C, color[3] = 1.0f; } - /* Draw muted nodes slightly transparent so the wires inside are visible. */ + /* Muted nodes get a mix of the background with the node color and are drawn slightly + * transparent so the wires inside are visible. */ if (node.is_muted()) { - color[3] -= 0.2f; + float color_background[4]; + UI_GetThemeColor4fv(TH_BACK, color_background); + + UI_GetColorPtrBlendAlpha4fv(color, color_background, 0.8f, -0.2f, color); } /* Add some padding to prevent transparent gaps with the outline. */ @@ -3369,33 +3393,8 @@ static void node_draw_collapsed(const bContext &C, } /* Body. */ - float color[4]; + ColorTheme4f color = node_header_color_get(ntree, node, color_id); { - if (node_undefined_or_unsupported(ntree, node)) { - /* Use warning color to indicate undefined types. */ - UI_GetThemeColorBlendShade4fv(TH_REDALERT, color_id, 0.1f, -40, color); - } - else if (node.is_muted()) { - /* Muted nodes get a mix of the background with the node color. */ - UI_GetThemeColorBlendShade4fv(TH_BACK, color_id, 0.4f, 0, color); - } - else if (node.flag & NODE_CUSTOM_COLOR) { - rgba_float_args_set(color, node.color[0], node.color[1], node.color[2], 1.0f); - } - else { - UI_GetThemeColor4fv(color_id, color); - } - - /* Draw selected nodes fully opaque. */ - if (node.flag & SELECT) { - color[3] = 1.0f; - } - - /* Draw muted nodes slightly transparent so the wires inside are visible. */ - if (node.is_muted()) { - color[3] -= 0.2f; - } - /* Add some padding to prevent transparent gaps with the outline. */ const float padding = 0.5f; const rctf rect = {