UI: Themeable RedAlert, Error, Warning, Info Colors

The "Red Alert" color is currently hard-coded, which causes problems in
themes.  It also has an Enum value of 0, which precludes using this
value as "unset". We also use Error, Warning, and Info colors that are
part of the Info Editor.  This PR moves these out of the Info Editor
and into the "State" part of the theme. And then makes TH_REDALERT use
the TH_ERROR color.

Pull Request: https://projects.blender.org/blender/blender/pulls/131127
This commit is contained in:
Harley Acheson
2025-02-12 20:59:47 +01:00
committed by Harley Acheson
parent 497f2884e8
commit 5956752eb7
14 changed files with 95 additions and 56 deletions

View File

@@ -206,6 +206,10 @@ const bTheme U_theme_default = {
.roundness = 0.2f,
},
.wcol_state = {
.error = RGBA(0x771111ff),
.warning = RGBA(0xac8737ff),
.info = RGBA(0x28487dff),
.success = RGBA(0x188625ff),
.inner_anim = RGBA(0x53992eff),
.inner_anim_sel = RGBA(0x38a600ff),
.inner_key = RGBA(0xb3ae36ff),
@@ -496,11 +500,8 @@ const bTheme U_theme_default = {
.facedot_size = 4,
.info_selected = RGBA(0x3b5689ff),
.info_selected_text = RGBA(0xffffffff),
.info_error = RGBA(0xb34c34ff),
.info_error_text = RGBA(0xffffffff),
.info_warning = RGBA(0xac8737ff),
.info_warning_text = RGBA(0xffffffff),
.info_info = RGBA(0x1f3862ff),
.info_info_text = RGBA(0xffffffff),
.info_debug = RGBA(0x6b3293ff),
.info_debug_text = RGBA(0xffffffff),

View File

@@ -1119,6 +1119,13 @@ class USERPREF_PT_theme_interface_state(ThemePanel, CenterAlignMixIn, Panel):
flow = layout.grid_flow(row_major=False, columns=0, even_columns=True, even_rows=False, align=False)
col = flow.column(align=True)
col.prop(ui_state, "error")
col.prop(ui_state, "warning")
col.prop(ui_state, "info")
col.prop(ui_state, "success")
col = flow.column(align=True)
col.prop(ui_state, "inner_anim")
col.prop(ui_state, "inner_anim_sel", text="Selected")

View File

@@ -31,7 +31,7 @@ extern "C" {
/* Blender file format version. */
#define BLENDER_FILE_VERSION BLENDER_VERSION
#define BLENDER_FILE_SUBVERSION 2
#define BLENDER_FILE_SUBVERSION 3
/* Minimum Blender version that supports reading file written with the current
* version. Older Blender versions will test this and cancel loading the file, showing a warning to

View File

@@ -218,6 +218,14 @@ static void do_versions_theme(const UserDef *userdef, bTheme *btheme)
FROM_DEFAULT_V4_UCHAR(space_sequencer.text_strip_cursor);
FROM_DEFAULT_V4_UCHAR(space_sequencer.selected_text);
}
if (!USER_VERSION_ATLEAST(405, 3)) {
FROM_DEFAULT_V4_UCHAR(tui.wcol_state.error);
FROM_DEFAULT_V4_UCHAR(tui.wcol_state.warning);
FROM_DEFAULT_V4_UCHAR(tui.wcol_state.info);
FROM_DEFAULT_V4_UCHAR(tui.wcol_state.success);
}
/**
* Always bump subversion in BKE_blender_version.h when adding versioning
* code here, and wrap it inside a USER_VERSION_ATLEAST check.

View File

@@ -39,7 +39,14 @@ BLI_STATIC_ASSERT(sizeof(BIFIconID_Static) <= sizeof(BIFIconID),
#define TH_UNDEFINED -1
enum ThemeColorID {
TH_NONE,
TH_BLACK,
TH_WHITE,
TH_REDALERT,
TH_ERROR,
TH_WARNING,
TH_INFO,
TH_SUCCESS,
TH_THEMEUI,
/* Common colors among spaces. */
@@ -341,11 +348,8 @@ enum ThemeColorID {
TH_INFO_SELECTED,
TH_INFO_SELECTED_TEXT,
TH_INFO_ERROR,
TH_INFO_ERROR_TEXT,
TH_INFO_WARNING,
TH_INFO_WARNING_TEXT,
TH_INFO_INFO,
TH_INFO_INFO_TEXT,
TH_INFO_DEBUG,
TH_INFO_DEBUG_TEXT,

View File

@@ -1360,10 +1360,10 @@ static void svg_replace_color_attributes(std::string &svg,
{"blender_back", nullptr, TH_BACK},
{"blender_text", nullptr, TH_TEXT},
{"blender_text_hi", nullptr, TH_TEXT_HI},
{"blender_red_alert", nullptr, TH_REDALERT},
{"blender_error", nullptr, TH_INFO_ERROR, SPACE_INFO},
{"blender_warning", nullptr, TH_INFO_WARNING, SPACE_INFO},
{"blender_info", nullptr, TH_INFO_INFO, SPACE_INFO},
{"blender_red_alert", nullptr, TH_ERROR},
{"blender_error", nullptr, TH_ERROR},
{"blender_warning", nullptr, TH_WARNING},
{"blender_info", nullptr, TH_INFO},
{"blender_scene", nullptr, TH_ICON_SCENE},
{"blender_collection", nullptr, TH_ICON_COLLECTION},
{"blender_object", nullptr, TH_ICON_OBJECT},

View File

@@ -603,13 +603,13 @@ int UI_icon_from_report_type(int type)
int UI_icon_colorid_from_report_type(int type)
{
if (type & RPT_ERROR_ALL) {
return TH_INFO_ERROR;
return TH_ERROR;
}
if (type & RPT_WARNING_ALL) {
return TH_INFO_WARNING;
return TH_WARNING;
}
if (type & RPT_INFO_ALL) {
return TH_INFO_INFO;
return TH_INFO;
}
if (type & RPT_DEBUG_ALL) {
return TH_INFO_DEBUG;
@@ -620,7 +620,7 @@ int UI_icon_colorid_from_report_type(int type)
if (type & RPT_OPERATOR) {
return TH_INFO_OPERATOR;
}
return TH_INFO_WARNING;
return TH_WARNING;
}
int UI_text_colorid_from_report_type(int type)

View File

@@ -2537,12 +2537,11 @@ static void widget_state(uiWidgetType *wt, const uiWidgetStateInfo *state, eUIEm
}
if (state->but_flag & UI_BUT_REDALERT) {
const uchar red[4] = {255, 0, 0};
if (wt->draw && emboss != UI_EMBOSS_NONE) {
color_blend_v3_v3(wt->wcol.inner, red, 0.4f);
UI_GetThemeColor3ubv(TH_REDALERT, wt->wcol.inner);
}
else {
color_blend_v3_v3(wt->wcol.text, red, 0.4f);
UI_GetThemeColor3ubv(TH_REDALERT, wt->wcol.text);
}
}
@@ -4352,8 +4351,7 @@ static void widget_state_label(uiWidgetType *wt,
}
if (state->but_flag & UI_BUT_REDALERT) {
const uchar red[4] = {255, 0, 0};
color_blend_v3_v3(wt->wcol.text, red, 0.4f);
UI_GetThemeColor3ubv(TH_REDALERT, wt->wcol.text);
}
}

View File

@@ -208,9 +208,7 @@ static void ui_tooltip_region_draw_cb(const bContext * /*C*/, ARegion *region)
color_blend_f3_f3(active_color, main_color, 0.3f);
/* `alert_color` is red, push a bit toward text color. */
alert_color[0] = 0.7f;
alert_color[1] = 0.0f;
alert_color[2] = 0.0f;
UI_GetThemeColor3fv(TH_REDALERT, alert_color);
color_blend_f3_f3(alert_color, main_color, 0.3f);
/* Draw text. */

View File

@@ -60,8 +60,10 @@ const uchar *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colorid)
{
ThemeSpace *ts = nullptr;
static uchar error[4] = {240, 0, 240, 255};
static uchar alert[4] = {240, 60, 60, 255};
static uchar back[4] = {0, 0, 0, 255};
static uchar none[4] = {0, 0, 0, 0};
static uchar white[4] = {255, 255, 255, 255};
static uchar black[4] = {0, 0, 0, 255};
static uchar setting = 0;
const uchar *cp = error;
@@ -75,9 +77,27 @@ const uchar *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colorid)
if (colorid < TH_THEMEUI) {
switch (colorid) {
case TH_NONE:
cp = none;
break;
case TH_BLACK:
cp = black;
break;
case TH_WHITE:
cp = white;
break;
case TH_REDALERT:
cp = alert;
case TH_ERROR:
cp = btheme->tui.wcol_state.error;
break;
case TH_WARNING:
cp = btheme->tui.wcol_state.warning;
break;
case TH_INFO:
cp = btheme->tui.wcol_state.info;
break;
case TH_SUCCESS:
cp = btheme->tui.wcol_state.success;
break;
}
}
@@ -1034,21 +1054,12 @@ const uchar *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colorid)
case TH_INFO_SELECTED_TEXT:
cp = ts->info_selected_text;
break;
case TH_INFO_ERROR:
cp = ts->info_error;
break;
case TH_INFO_ERROR_TEXT:
cp = ts->info_error_text;
break;
case TH_INFO_WARNING:
cp = ts->info_warning;
break;
case TH_INFO_WARNING_TEXT:
cp = ts->info_warning_text;
break;
case TH_INFO_INFO:
cp = ts->info_info;
break;
case TH_INFO_INFO_TEXT:
cp = ts->info_info_text;
break;

View File

@@ -532,7 +532,7 @@ void uiTemplateStatusInfo(uiLayout *layout, bContext *C)
0.0f,
"");
/*# UI_BTYPE_ROUNDBOX's background color is set in `but->col`. */
UI_GetThemeColorType4ubv(TH_INFO_WARNING, SPACE_INFO, but->col);
UI_GetThemeColor4ubv(TH_WARNING, but->col);
if (!warning_message.is_empty()) {
/* Background for the rest of the message. */
@@ -550,7 +550,7 @@ void uiTemplateStatusInfo(uiLayout *layout, bContext *C)
"");
/* Use icon background at low opacity to highlight, but still contrasting with area TH_TEXT. */
UI_GetThemeColorType4ubv(TH_INFO_WARNING, SPACE_INFO, but->col);
UI_GetThemeColor4ubv(TH_WARNING, but->col);
but->col[3] = 64;
}

View File

@@ -2742,7 +2742,9 @@ void ED_scene_draw_fps(const Scene *scene, int xoffset, int *yoffset)
if (state.fps_average + 0.5f < state.fps_target) {
/* Always show fractional when under performing. */
show_fractional = true;
BLF_color4ub(font_id, 225, 36, 36, 255);
float alert_color[4];
UI_GetThemeColorBlend4f(TH_REDALERT, TH_TEXT_HI, 0.5f, alert_color);
BLF_color4fv(font_id, alert_color);
}
if (show_fractional) {

View File

@@ -128,6 +128,10 @@ typedef struct uiWidgetColors {
} uiWidgetColors;
typedef struct uiWidgetStateColors {
unsigned char error[4];
unsigned char warning[4];
unsigned char info[4];
unsigned char success[4];
unsigned char inner_anim[4];
unsigned char inner_anim_sel[4];
unsigned char inner_key[4];
@@ -437,12 +441,13 @@ typedef struct ThemeSpace {
/* info */
unsigned char info_selected[4], info_selected_text[4];
unsigned char info_error[4], info_error_text[4];
unsigned char info_warning[4], info_warning_text[4];
unsigned char info_info[4], info_info_text[4];
unsigned char info_error_text[4];
unsigned char info_warning_text[4];
unsigned char info_info_text[4];
unsigned char info_debug[4], info_debug_text[4];
unsigned char info_property[4], info_property_text[4];
unsigned char info_operator[4], info_operator_text[4];
char _pad6[4];
unsigned char paint_curve_pivot[4];
unsigned char paint_curve_handle[4];

View File

@@ -1678,6 +1678,26 @@ static void rna_def_userdef_theme_ui_wcol_state(BlenderRNA *brna)
RNA_def_struct_ui_text(
srna, "Theme Widget State Color", "Theme settings for widget state colors");
prop = RNA_def_property(srna, "error", PROP_FLOAT, PROP_COLOR_GAMMA);
RNA_def_property_array(prop, 4);
RNA_def_property_ui_text(prop, "Error", "Color for error items");
RNA_def_property_update(prop, 0, "rna_userdef_theme_update");
prop = RNA_def_property(srna, "warning", PROP_FLOAT, PROP_COLOR_GAMMA);
RNA_def_property_array(prop, 4);
RNA_def_property_ui_text(prop, "Warning", "Color for warning items");
RNA_def_property_update(prop, 0, "rna_userdef_theme_update");
prop = RNA_def_property(srna, "info", PROP_FLOAT, PROP_COLOR_GAMMA);
RNA_def_property_array(prop, 4);
RNA_def_property_ui_text(prop, "Info", "Color for informational items");
RNA_def_property_update(prop, 0, "rna_userdef_theme_update");
prop = RNA_def_property(srna, "success", PROP_FLOAT, PROP_COLOR_GAMMA);
RNA_def_property_array(prop, 4);
RNA_def_property_ui_text(prop, "Success", "Color for successful items");
RNA_def_property_update(prop, 0, "rna_userdef_theme_update");
prop = RNA_def_property(srna, "inner_anim", PROP_FLOAT, PROP_COLOR_GAMMA);
RNA_def_property_array(prop, 3);
RNA_def_property_ui_text(prop, "Animated", "");
@@ -3134,31 +3154,16 @@ static void rna_def_userdef_theme_space_info(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Selected Line Text Color", "Text color of selected line");
RNA_def_property_update(prop, 0, "rna_userdef_theme_update");
prop = RNA_def_property(srna, "info_error", PROP_FLOAT, PROP_COLOR_GAMMA);
RNA_def_property_array(prop, 4);
RNA_def_property_ui_text(prop, "Error Icon Background", "Background color of Error icon");
RNA_def_property_update(prop, 0, "rna_userdef_theme_update");
prop = RNA_def_property(srna, "info_error_text", PROP_FLOAT, PROP_COLOR_GAMMA);
RNA_def_property_array(prop, 3);
RNA_def_property_ui_text(prop, "Error Icon Foreground", "Foreground color of Error icon");
RNA_def_property_update(prop, 0, "rna_userdef_theme_update");
prop = RNA_def_property(srna, "info_warning", PROP_FLOAT, PROP_COLOR_GAMMA);
RNA_def_property_array(prop, 4);
RNA_def_property_ui_text(prop, "Warning Icon Background", "Background color of Warning icon");
RNA_def_property_update(prop, 0, "rna_userdef_theme_update");
prop = RNA_def_property(srna, "info_warning_text", PROP_FLOAT, PROP_COLOR_GAMMA);
RNA_def_property_array(prop, 3);
RNA_def_property_ui_text(prop, "Warning Icon Foreground", "Foreground color of Warning icon");
RNA_def_property_update(prop, 0, "rna_userdef_theme_update");
prop = RNA_def_property(srna, "info_info", PROP_FLOAT, PROP_COLOR_GAMMA);
RNA_def_property_array(prop, 4);
RNA_def_property_ui_text(prop, "Info Icon Background", "Background color of Info icon");
RNA_def_property_update(prop, 0, "rna_userdef_theme_update");
prop = RNA_def_property(srna, "info_info_text", PROP_FLOAT, PROP_COLOR_GAMMA);
RNA_def_property_array(prop, 3);
RNA_def_property_ui_text(prop, "Info Icon Foreground", "Foreground color of Info icon");