Use accent color for some editor icons

This commit is contained in:
FireForge 2022-03-22 16:01:45 -05:00
parent 9162f27836
commit 9544c46e3c
1 changed files with 31 additions and 8 deletions

View File

@ -288,9 +288,31 @@ void editor_register_and_generate_icons(Ref<Theme> p_theme, bool p_dark_theme =
dark_icon_color_dictionary[Color::html("#5fff97")] = success_color; dark_icon_color_dictionary[Color::html("#5fff97")] = success_color;
dark_icon_color_dictionary[Color::html("#ffdd65")] = warning_color; dark_icon_color_dictionary[Color::html("#ffdd65")] = warning_color;
// Use the accent color for some icons (checkbox, radio, toggle, etc.).
Dictionary accent_color_icon_color_dictionary;
Set<StringName> accent_color_icons;
const Color accent_color = p_theme->get_color(SNAME("accent_color"), SNAME("Editor"));
accent_color_icon_color_dictionary[Color::html("699ce8")] = accent_color;
if (accent_color.get_luminance() > 0.75) {
accent_color_icon_color_dictionary[Color::html("ffffff")] = Color(0.2, 0.2, 0.2);
}
accent_color_icons.insert("GuiChecked");
accent_color_icons.insert("GuiRadioChecked");
accent_color_icons.insert("GuiIndeterminate");
accent_color_icons.insert("GuiToggleOn");
accent_color_icons.insert("GuiToggleOnMirrored");
accent_color_icons.insert("PlayOverlay");
// Generate icons. // Generate icons.
if (!p_only_thumbs) { if (!p_only_thumbs) {
for (int i = 0; i < editor_icons_count; i++) { for (int i = 0; i < editor_icons_count; i++) {
Ref<ImageTexture> icon;
if (accent_color_icons.has(editor_icons_names[i])) {
icon = editor_generate_icon(i, true, EDSCALE, 1.0, accent_color_icon_color_dictionary);
} else {
float saturation = p_icon_saturation; float saturation = p_icon_saturation;
if (strcmp(editor_icons_names[i], "DefaultProjectIcon") == 0 || strcmp(editor_icons_names[i], "Godot") == 0 || strcmp(editor_icons_names[i], "Logo") == 0) { if (strcmp(editor_icons_names[i], "DefaultProjectIcon") == 0 || strcmp(editor_icons_names[i], "Godot") == 0 || strcmp(editor_icons_names[i], "Logo") == 0) {
@ -298,7 +320,8 @@ void editor_register_and_generate_icons(Ref<Theme> p_theme, bool p_dark_theme =
} }
const int is_exception = exceptions.has(editor_icons_names[i]); const int is_exception = exceptions.has(editor_icons_names[i]);
const Ref<ImageTexture> icon = editor_generate_icon(i, !is_exception, EDSCALE, saturation, dark_icon_color_dictionary); icon = editor_generate_icon(i, !is_exception, EDSCALE, saturation, dark_icon_color_dictionary);
}
p_theme->set_icon(editor_icons_names[i], SNAME("EditorIcons"), icon); p_theme->set_icon(editor_icons_names[i], SNAME("EditorIcons"), icon);
} }
@ -514,8 +537,8 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
// Register icons + font // Register icons + font
// The resolution and the icon color (dark_theme bool) has not changed, so we do not regenerate the icons. // The editor scale, icon color (dark_theme bool), icon saturation, and accent color has not changed, so we do not regenerate the icons.
if (p_theme != nullptr && fabs(p_theme->get_constant(SNAME("scale"), SNAME("Editor")) - EDSCALE) < 0.00001 && (bool)p_theme->get_constant(SNAME("dark_theme"), SNAME("Editor")) == dark_theme && prev_icon_saturation == icon_saturation) { if (p_theme != nullptr && fabs(p_theme->get_constant(SNAME("scale"), SNAME("Editor")) - EDSCALE) < 0.00001 && (bool)p_theme->get_constant(SNAME("dark_theme"), SNAME("Editor")) == dark_theme && prev_icon_saturation == icon_saturation && p_theme->get_color(SNAME("accent_color"), SNAME("Editor")) == accent_color) {
// Register already generated icons. // Register already generated icons.
for (int i = 0; i < editor_icons_count; i++) { for (int i = 0; i < editor_icons_count; i++) {
theme->set_icon(editor_icons_names[i], SNAME("EditorIcons"), p_theme->get_icon(editor_icons_names[i], SNAME("EditorIcons"))); theme->set_icon(editor_icons_names[i], SNAME("EditorIcons"), p_theme->get_icon(editor_icons_names[i], SNAME("EditorIcons")));