Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve editor theme generation after the refactor #87293

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions editor/debugger/editor_performance_profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
#include "editor_performance_profiler.h"

#include "editor/editor_property_name_processor.h"
#include "editor/editor_settings.h"
#include "editor/editor_string_names.h"
#include "editor/themes/editor_scale.h"
#include "editor/themes/editor_theme_manager.h"
#include "main/performance.h"

EditorPerformanceProfiler::Monitor::Monitor() {}
Expand Down Expand Up @@ -122,7 +122,7 @@ void EditorPerformanceProfiler::_monitor_draw() {
}
Size2i cell_size = Size2i(monitor_draw->get_size()) / Size2i(columns, rows);
float spacing = float(POINT_SEPARATION) / float(columns);
float value_multiplier = EditorSettings::get_singleton()->is_dark_theme() ? 1.4f : 0.55f;
float value_multiplier = EditorThemeManager::is_dark_theme() ? 1.4f : 0.55f;
float hue_shift = 1.0f / float(monitors.size());

for (int i = 0; i < active.size(); i++) {
Expand Down
7 changes: 4 additions & 3 deletions editor/editor_audio_buses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "editor/filesystem_dock.h"
#include "editor/gui/editor_file_dialog.h"
#include "editor/themes/editor_scale.h"
#include "editor/themes/editor_theme_manager.h"
#include "scene/gui/separator.h"
#include "scene/resources/font.h"
#include "servers/audio_server.h"
Expand Down Expand Up @@ -84,9 +85,9 @@ void EditorAudioBus::_notification(int p_what) {

disabled_vu = get_editor_theme_icon(SNAME("BusVuFrozen"));

Color solo_color = EditorSettings::get_singleton()->is_dark_theme() ? Color(1.0, 0.89, 0.22) : Color(1.0, 0.92, 0.44);
Color mute_color = EditorSettings::get_singleton()->is_dark_theme() ? Color(1.0, 0.16, 0.16) : Color(1.0, 0.44, 0.44);
Color bypass_color = EditorSettings::get_singleton()->is_dark_theme() ? Color(0.13, 0.8, 1.0) : Color(0.44, 0.87, 1.0);
Color solo_color = EditorThemeManager::is_dark_theme() ? Color(1.0, 0.89, 0.22) : Color(1.0, 0.92, 0.44);
Color mute_color = EditorThemeManager::is_dark_theme() ? Color(1.0, 0.16, 0.16) : Color(1.0, 0.44, 0.44);
Color bypass_color = EditorThemeManager::is_dark_theme() ? Color(0.13, 0.8, 1.0) : Color(0.44, 0.87, 1.0);

solo->set_icon(get_editor_theme_icon(SNAME("AudioBusSolo")));
solo->add_theme_color_override("icon_pressed_color", solo_color);
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ void EditorNode::_update_update_spinner() {
// as this feature should only be enabled for troubleshooting purposes.
// Make the icon modulate color overbright because icons are not completely white on a dark theme.
// On a light theme, icons are dark, so we need to modulate them with an even brighter color.
const bool dark_theme = EditorSettings::get_singleton()->is_dark_theme();
const bool dark_theme = EditorThemeManager::is_dark_theme();
update_spinner->set_self_modulate(theme->get_color(SNAME("error_color"), EditorStringName(Editor)) * (dark_theme ? Color(1.1, 1.1, 1.1) : Color(4.25, 4.25, 4.25)));
} else {
update_spinner->set_tooltip_text(TTR("Spins when the editor window redraws."));
Expand Down
8 changes: 0 additions & 8 deletions editor/editor_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1278,14 +1278,6 @@ void EditorSettings::load_favorites_and_recent_dirs() {
}
}

bool EditorSettings::is_dark_theme() {
int AUTO_COLOR = 0;
int LIGHT_COLOR = 2;
Color base_color = get("interface/theme/base_color");
int icon_font_color_setting = get("interface/theme/icon_and_font_color");
return (icon_font_color_setting == AUTO_COLOR && base_color.get_luminance() < 0.5) || icon_font_color_setting == LIGHT_COLOR;
}

void EditorSettings::list_text_editor_themes() {
String themes = "Default,Godot 2,Custom";

Expand Down
2 changes: 0 additions & 2 deletions editor/editor_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,6 @@ class EditorSettings : public Resource {
Vector<String> get_recent_dirs() const;
void load_favorites_and_recent_dirs();

bool is_dark_theme();

void list_text_editor_themes();
void load_text_editor_theme();
bool import_text_editor_theme(String p_file);
Expand Down
5 changes: 3 additions & 2 deletions editor/filesystem_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include "editor/scene_tree_dock.h"
#include "editor/shader_create_dialog.h"
#include "editor/themes/editor_scale.h"
#include "editor/themes/editor_theme_manager.h"
#include "scene/gui/item_list.h"
#include "scene/gui/label.h"
#include "scene/gui/line_edit.h"
Expand Down Expand Up @@ -625,7 +626,7 @@ void FileSystemDock::_notification(int p_what) {
// Update editor dark theme & always show folders states from editor settings, redraw if needed.
bool do_redraw = false;

bool new_editor_is_dark_theme = EditorSettings::get_singleton()->is_dark_theme();
bool new_editor_is_dark_theme = EditorThemeManager::is_dark_theme();
if (new_editor_is_dark_theme != editor_is_dark_theme) {
editor_is_dark_theme = new_editor_is_dark_theme;
do_redraw = true;
Expand Down Expand Up @@ -3763,7 +3764,7 @@ FileSystemDock::FileSystemDock() {

assigned_folder_colors = ProjectSettings::get_singleton()->get_setting("file_customization/folder_colors");

editor_is_dark_theme = EditorSettings::get_singleton()->is_dark_theme();
editor_is_dark_theme = EditorThemeManager::is_dark_theme();

VBoxContainer *top_vbc = memnew(VBoxContainer);
add_child(top_vbc);
Expand Down
6 changes: 3 additions & 3 deletions editor/import/resource_importer_texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
#include "core/version.h"
#include "editor/editor_file_system.h"
#include "editor/editor_node.h"
#include "editor/editor_settings.h"
#include "editor/gui/editor_toaster.h"
#include "editor/import/resource_importer_texture_settings.h"
#include "editor/themes/editor_scale.h"
#include "editor/themes/editor_theme_manager.h"
#include "scene/resources/compressed_texture.h"

void ResourceImporterTexture::_texture_reimport_roughness(const Ref<CompressedTexture2D> &p_tex, const String &p_normal_path, RS::TextureDetectRoughnessChannel p_channel) {
Expand Down Expand Up @@ -696,7 +696,7 @@ Error ResourceImporterTexture::import(const String &p_source_file, const String
editor_meta["editor_scale"] = EDSCALE;
}
if (convert_editor_colors) {
editor_meta["editor_dark_theme"] = EditorSettings::get_singleton()->is_dark_theme();
editor_meta["editor_dark_theme"] = EditorThemeManager::is_dark_theme();
}

_save_editor_meta(editor_meta, p_save_path + ".editor.meta");
Expand Down Expand Up @@ -755,7 +755,7 @@ bool ResourceImporterTexture::are_import_settings_valid(const String &p_path) co
if (editor_meta.has("editor_scale") && (float)editor_meta["editor_scale"] != EDSCALE) {
return false;
}
if (editor_meta.has("editor_dark_theme") && (bool)editor_meta["editor_dark_theme"] != EditorSettings::get_singleton()->is_dark_theme()) {
if (editor_meta.has("editor_dark_theme") && (bool)editor_meta["editor_dark_theme"] != EditorThemeManager::is_dark_theme()) {
return false;
}
}
Expand Down
3 changes: 2 additions & 1 deletion editor/plugins/bone_map_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "editor/import/3d/post_import_plugin_skeleton_track_organizer.h"
#include "editor/import/3d/scene_import_settings.h"
#include "editor/themes/editor_scale.h"
#include "editor/themes/editor_theme_manager.h"
#include "scene/gui/aspect_ratio_container.h"
#include "scene/gui/separator.h"
#include "scene/gui/texture_rect.h"
Expand All @@ -52,7 +53,7 @@ void BoneMapperButton::fetch_textures() {
set_offset(SIDE_BOTTOM, 0);

// Hack to avoid handle color darkening...
set_modulate(EditorSettings::get_singleton()->is_dark_theme() ? Color(1, 1, 1) : Color(4.25, 4.25, 4.25));
set_modulate(EditorThemeManager::is_dark_theme() ? Color(1, 1, 1) : Color(4.25, 4.25, 4.25));

circle = memnew(TextureRect);
circle->set_texture(get_editor_theme_icon(SNAME("BoneMapperHandleCircle")));
Expand Down
3 changes: 2 additions & 1 deletion editor/plugins/canvas_item_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "editor/plugins/script_editor_plugin.h"
#include "editor/scene_tree_dock.h"
#include "editor/themes/editor_scale.h"
#include "editor/themes/editor_theme_manager.h"
#include "scene/2d/polygon_2d.h"
#include "scene/2d/skeleton_2d.h"
#include "scene/2d/sprite_2d.h"
Expand Down Expand Up @@ -3898,7 +3899,7 @@ void CanvasItemEditor::_update_editor_settings() {
// to distinguish from the other key icons at the top. On a light theme,
// the icon will be dark, so we need to lighten it before blending it
// with the red color.
const Color key_auto_color = EditorSettings::get_singleton()->is_dark_theme() ? Color(1, 1, 1) : Color(4.25, 4.25, 4.25);
const Color key_auto_color = EditorThemeManager::is_dark_theme() ? Color(1, 1, 1) : Color(4.25, 4.25, 4.25);
key_auto_insert_button->add_theme_color_override("icon_pressed_color", key_auto_color.lerp(Color(1, 0, 0), 0.55));
animation_menu->set_icon(get_editor_theme_icon(SNAME("GuiTabMenuHl")));

Expand Down
3 changes: 2 additions & 1 deletion editor/plugins/particle_process_material_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "editor/editor_settings.h"
#include "editor/editor_string_names.h"
#include "editor/gui/editor_spin_slider.h"
#include "editor/themes/editor_theme_manager.h"
#include "scene/gui/box_container.h"
#include "scene/gui/button.h"
#include "scene/gui/label.h"
Expand Down Expand Up @@ -352,7 +353,7 @@ void ParticleProcessMaterialMinMaxPropertyEditor::_notification(int p_what) {
min_edit->add_theme_color_override(SNAME("label_color"), get_theme_color(SNAME("property_color_x"), EditorStringName(Editor)));
max_edit->add_theme_color_override(SNAME("label_color"), get_theme_color(SNAME("property_color_y"), EditorStringName(Editor)));

const bool dark_theme = EditorSettings::get_singleton()->is_dark_theme();
const bool dark_theme = EditorThemeManager::is_dark_theme();
const Color accent_color = get_theme_color(SNAME("accent_color"), EditorStringName(Editor));
background_color = dark_theme ? Color(0.3, 0.3, 0.3) : Color(0.7, 0.7, 0.7);
normal_color = dark_theme ? Color(0.5, 0.5, 0.5) : Color(0.8, 0.8, 0.8);
Expand Down
3 changes: 0 additions & 3 deletions editor/themes/editor_fonts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ Ref<FontVariation> make_bold_font(const Ref<Font> &p_font, double p_embolden, Ty
}

void editor_register_fonts(const Ref<Theme> &p_theme) {
OS::get_singleton()->benchmark_begin_measure("EditorTheme", "Register Fonts");
Ref<DirAccess> dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);

TextServer::FontAntialiasing font_antialiasing = (TextServer::FontAntialiasing)(int)EDITOR_GET("interface/editor/font_antialiasing");
Expand Down Expand Up @@ -444,6 +443,4 @@ void editor_register_fonts(const Ref<Theme> &p_theme) {

p_theme->set_font_size("status_source_size", EditorStringName(EditorFonts), default_font_size);
p_theme->set_font("status_source", EditorStringName(EditorFonts), mono_other_fc);

OS::get_singleton()->benchmark_end_measure("EditorTheme", "Register Fonts");
}
23 changes: 9 additions & 14 deletions editor/themes/editor_icons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ Ref<ImageTexture> editor_generate_icon(int p_index, float p_scale, float p_satur
return ImageTexture::create_from_image(img);
}

float get_gizmo_handle_scale(const String &gizmo_handle_name = "") {
const float scale_gizmo_handles_for_touch = EDITOR_GET("interface/touchscreen/scale_gizmo_handles");
if (scale_gizmo_handles_for_touch > 1.0f) {
float get_gizmo_handle_scale(const String &p_gizmo_handle_name, float p_gizmo_handle_scale) {
if (p_gizmo_handle_scale > 1.0f) {
// The names of the icons that require additional scaling.
static HashSet<StringName> gizmo_to_scale;
if (gizmo_to_scale.is_empty()) {
Expand All @@ -92,18 +91,15 @@ float get_gizmo_handle_scale(const String &gizmo_handle_name = "") {
gizmo_to_scale.insert("EditorPathSmoothHandle");
}

if (gizmo_to_scale.has(gizmo_handle_name)) {
return EDSCALE * scale_gizmo_handles_for_touch;
if (gizmo_to_scale.has(p_gizmo_handle_name)) {
return EDSCALE * p_gizmo_handle_scale;
}
}

return EDSCALE;
}

void editor_register_icons(const Ref<Theme> &p_theme, bool p_dark_theme, float p_icon_saturation, int p_thumb_size, bool p_only_thumbs) {
const String benchmark_key = vformat("Generate Icons (%s)", (p_only_thumbs ? "Only Thumbs" : "All"));
OS::get_singleton()->benchmark_begin_measure("EditorTheme", benchmark_key);

void editor_register_icons(const Ref<Theme> &p_theme, bool p_dark_theme, float p_icon_saturation, int p_thumb_size, float p_gizmo_handle_scale) {
// Before we register the icons, we adjust their colors and saturation.
// Most icons follow the standard rules for color conversion to follow the editor
// theme's polarity (dark/light). We also adjust the saturation for most icons,
Expand Down Expand Up @@ -158,23 +154,23 @@ void editor_register_icons(const Ref<Theme> &p_theme, bool p_dark_theme, float p
accent_color_icons.insert("PlayOverlay");

// Generate icons.
if (!p_only_thumbs) {
{
for (int i = 0; i < editor_icons_count; i++) {
Ref<ImageTexture> icon;

const String &editor_icon_name = editor_icons_names[i];
if (accent_color_icons.has(editor_icon_name)) {
icon = editor_generate_icon(i, get_gizmo_handle_scale(editor_icon_name), 1.0, accent_color_map);
icon = editor_generate_icon(i, get_gizmo_handle_scale(editor_icon_name, p_gizmo_handle_scale), 1.0, accent_color_map);
} else {
float saturation = p_icon_saturation;
if (saturation_exceptions.has(editor_icon_name)) {
saturation = 1.0;
}

if (conversion_exceptions.has(editor_icon_name)) {
icon = editor_generate_icon(i, get_gizmo_handle_scale(editor_icon_name), saturation);
icon = editor_generate_icon(i, get_gizmo_handle_scale(editor_icon_name, p_gizmo_handle_scale), saturation);
} else {
icon = editor_generate_icon(i, get_gizmo_handle_scale(editor_icon_name), saturation, color_conversion_map);
icon = editor_generate_icon(i, get_gizmo_handle_scale(editor_icon_name, p_gizmo_handle_scale), saturation, color_conversion_map);
}
}

Expand Down Expand Up @@ -231,7 +227,6 @@ void editor_register_icons(const Ref<Theme> &p_theme, bool p_dark_theme, float p
p_theme->set_icon(editor_icons_names[index], EditorStringName(EditorIcons), icon);
}
}
OS::get_singleton()->benchmark_end_measure("EditorTheme", benchmark_key);
}

void editor_copy_icons(const Ref<Theme> &p_theme, const Ref<Theme> &p_old_theme) {
Expand Down
2 changes: 1 addition & 1 deletion editor/themes/editor_icons.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "scene/resources/theme.h"

void editor_configure_icons(bool p_dark_theme);
void editor_register_icons(const Ref<Theme> &p_theme, bool p_dark_theme, float p_icon_saturation, int p_thumb_size, bool p_only_thumbs = false);
void editor_register_icons(const Ref<Theme> &p_theme, bool p_dark_theme, float p_icon_saturation, int p_thumb_size, float p_gizmo_handle_scale);
void editor_copy_icons(const Ref<Theme> &p_theme, const Ref<Theme> &p_old_theme);

String get_default_project_icon();
Expand Down
13 changes: 13 additions & 0 deletions editor/themes/editor_theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ class EditorTheme : public Theme {

static Vector<StringName> editor_theme_types;

uint32_t generated_hash = 0;
uint32_t generated_fonts_hash = 0;
uint32_t generated_icons_hash = 0;

public:
virtual Color get_color(const StringName &p_name, const StringName &p_theme_type) const override;
virtual int get_constant(const StringName &p_name, const StringName &p_theme_type) const override;
Expand All @@ -46,6 +50,15 @@ class EditorTheme : public Theme {
virtual Ref<Texture2D> get_icon(const StringName &p_name, const StringName &p_theme_type) const override;
virtual Ref<StyleBox> get_stylebox(const StringName &p_name, const StringName &p_theme_type) const override;

void set_generated_hash(uint32_t p_hash) { generated_hash = p_hash; }
uint32_t get_generated_hash() const { return generated_hash; }

void set_generated_fonts_hash(uint32_t p_hash) { generated_fonts_hash = p_hash; }
uint32_t get_generated_fonts_hash() const { return generated_fonts_hash; }

void set_generated_icons_hash(uint32_t p_hash) { generated_icons_hash = p_hash; }
uint32_t get_generated_icons_hash() const { return generated_icons_hash; }

static void initialize();
static void finalize();
};
Expand Down
Loading
Loading