diff options
Diffstat (limited to 'editor/editor_themes.cpp')
-rw-r--r-- | editor/editor_themes.cpp | 53 |
1 files changed, 41 insertions, 12 deletions
diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp index 7b60c4a384..db4161fc3d 100644 --- a/editor/editor_themes.cpp +++ b/editor/editor_themes.cpp @@ -30,7 +30,9 @@ #include "editor_themes.h" +#include "core/error/error_macros.h" #include "core/io/resource_loader.h" +#include "core/variant/dictionary.h" #include "editor_fonts.h" #include "editor_icons.gen.h" #include "editor_scale.h" @@ -95,6 +97,7 @@ static Ref<Texture2D> flip_icon(Ref<Texture2D> p_texture, bool p_flip_y = false, Ref<ImageTexture> texture(memnew(ImageTexture)); Ref<Image> img = p_texture->get_image(); + ERR_FAIL_NULL_V(img, Ref<Texture2D>()); img = img->duplicate(); if (p_flip_y) { @@ -109,7 +112,8 @@ static Ref<Texture2D> flip_icon(Ref<Texture2D> p_texture, bool p_flip_y = false, } #ifdef MODULE_SVG_ENABLED -static Ref<ImageTexture> editor_generate_icon(int p_index, bool p_convert_color, float p_scale = EDSCALE, float p_saturation = 1.0) { +// See also `generate_icon()` in `scene/resources/default_theme.cpp`. +static Ref<ImageTexture> editor_generate_icon(int p_index, bool p_convert_color, float p_scale = EDSCALE, float p_saturation = 1.0, Dictionary p_convert_colors = Dictionary()) { Ref<ImageTexture> icon = memnew(ImageTexture); Ref<Image> img = memnew(Image); @@ -117,8 +121,9 @@ static Ref<ImageTexture> editor_generate_icon(int p_index, bool p_convert_color, // Generating upsampled icons is slower, and the benefit is hardly visible // with integer editor scales. const bool upsample = !Math::is_equal_approx(Math::round(p_scale), p_scale); - ImageLoaderSVG::create_image_from_string(img, editor_icons_sources[p_index], p_scale, upsample, p_convert_color); - + ImageLoaderSVG img_loader; + img_loader.set_replace_colors(p_convert_colors); + img_loader.create_image_from_string(img, editor_icons_sources[p_index], p_scale, upsample, p_convert_color); if (p_saturation != 1.0) { img->adjust_bcs(1.0, 1.0, p_saturation); } @@ -135,8 +140,10 @@ static Ref<ImageTexture> editor_generate_icon(int p_index, bool p_convert_color, void editor_register_and_generate_icons(Ref<Theme> p_theme, bool p_dark_theme = true, int p_thumb_size = 32, bool p_only_thumbs = false, float p_icon_saturation = 1.0) { #ifdef MODULE_SVG_ENABLED // The default icon theme is designed to be used for a dark theme. - // This dictionary stores color codes to convert to other colors + // This dictionary stores Color values to convert to other colors // for better readability on a light theme. + // Godot Color values are used to avoid the ambiguity of strings + // (where "#ffffff", "fff", and "white" are all equivalent). Dictionary dark_icon_color_dictionary; // The names of the icons to never convert, even if one of their colors @@ -243,8 +250,6 @@ void editor_register_and_generate_icons(Ref<Theme> p_theme, bool p_dark_theme = dark_icon_color_dictionary[Color::html("#45ff8b")] = success_color; dark_icon_color_dictionary[Color::html("#dbab09")] = warning_color; - ImageLoaderSVG::set_convert_colors(&dark_icon_color_dictionary); - // Generate icons. if (!p_only_thumbs) { for (int i = 0; i < editor_icons_count; i++) { @@ -255,7 +260,7 @@ 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 Ref<ImageTexture> icon = editor_generate_icon(i, !is_exception, EDSCALE, saturation); + const Ref<ImageTexture> icon = editor_generate_icon(i, !is_exception, EDSCALE, saturation, dark_icon_color_dictionary); p_theme->set_icon(editor_icons_names[i], "EditorIcons", icon); } @@ -269,7 +274,7 @@ void editor_register_and_generate_icons(Ref<Theme> p_theme, bool p_dark_theme = for (int i = 0; i < editor_bg_thumbs_count; i++) { const int index = editor_bg_thumbs_indices[i]; const int is_exception = exceptions.has(editor_icons_names[index]); - const Ref<ImageTexture> icon = editor_generate_icon(index, !p_dark_theme && !is_exception, scale, force_filter); + const Ref<ImageTexture> icon = editor_generate_icon(index, !p_dark_theme && !is_exception, scale, force_filter, dark_icon_color_dictionary); p_theme->set_icon(editor_icons_names[index], "EditorIcons", icon); } @@ -278,13 +283,11 @@ void editor_register_and_generate_icons(Ref<Theme> p_theme, bool p_dark_theme = for (int i = 0; i < editor_md_thumbs_count; i++) { const int index = editor_md_thumbs_indices[i]; const bool is_exception = exceptions.has(editor_icons_names[index]); - const Ref<ImageTexture> icon = editor_generate_icon(index, !p_dark_theme && !is_exception, scale, force_filter); + const Ref<ImageTexture> icon = editor_generate_icon(index, !p_dark_theme && !is_exception, scale, force_filter, dark_icon_color_dictionary); p_theme->set_icon(editor_icons_names[index], "EditorIcons", icon); } } - - ImageLoaderSVG::set_convert_colors(nullptr); #else WARN_PRINT("SVG support disabled, editor icons won't be rendered."); #endif @@ -294,7 +297,7 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { Ref<Theme> theme = Ref<Theme>(memnew(Theme)); // Controls may rely on the scale for their internal drawing logic. - theme->set_default_theme_base_scale(EDSCALE); + theme->set_default_base_scale(EDSCALE); // Theme settings Color accent_color = EDITOR_GET("interface/theme/accent_color"); @@ -1121,6 +1124,12 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { theme->set_constant("margin_bottom", "MarginContainer", 0); theme->set_constant("hseparation", "GridContainer", default_margin_size * EDSCALE); theme->set_constant("vseparation", "GridContainer", default_margin_size * EDSCALE); + theme->set_constant("hseparation", "FlowContainer", default_margin_size * EDSCALE); + theme->set_constant("vseparation", "FlowContainer", default_margin_size * EDSCALE); + theme->set_constant("hseparation", "HFlowContainer", default_margin_size * EDSCALE); + theme->set_constant("vseparation", "HFlowContainer", default_margin_size * EDSCALE); + theme->set_constant("hseparation", "VFlowContainer", default_margin_size * EDSCALE); + theme->set_constant("vseparation", "VFlowContainer", default_margin_size * EDSCALE); // Window @@ -1211,7 +1220,22 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { theme->set_stylebox("focus", "RichTextLabel", make_empty_stylebox()); theme->set_stylebox("normal", "RichTextLabel", style_tree_bg); + // Editor help. + theme->set_color("title_color", "EditorHelp", accent_color); theme->set_color("headline_color", "EditorHelp", mono_color); + theme->set_color("text_color", "EditorHelp", font_color); + theme->set_color("comment_color", "EditorHelp", font_color * Color(1, 1, 1, 0.6)); + theme->set_color("symbol_color", "EditorHelp", font_color * Color(1, 1, 1, 0.6)); + theme->set_color("value_color", "EditorHelp", font_color * Color(1, 1, 1, 0.6)); + theme->set_color("qualifier_color", "EditorHelp", font_color * Color(1, 1, 1, 0.8)); + theme->set_color("type_color", "EditorHelp", accent_color.lerp(font_color, 0.5)); + theme->set_color("selection_color", "EditorHelp", accent_color * Color(1, 1, 1, 0.4)); + theme->set_color("link_color", "EditorHelp", accent_color.lerp(mono_color, 0.8)); + theme->set_color("code_color", "EditorHelp", accent_color.lerp(mono_color, 0.6)); + theme->set_color("kbd_color", "EditorHelp", accent_color.lerp(property_color, 0.6)); + theme->set_constant("line_separation", "EditorHelp", Math::round(6 * EDSCALE)); + theme->set_constant("table_hseparation", "EditorHelp", 16 * EDSCALE); + theme->set_constant("table_vseparation", "EditorHelp", 6 * EDSCALE); // Panel theme->set_stylebox("panel", "Panel", make_flat_stylebox(dark_color_1, 6, 4, 6, 4, corner_width)); @@ -1419,6 +1443,11 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { style_info_3d_viewport->set_border_width_all(0); theme->set_stylebox("Information3dViewport", "EditorStyles", style_info_3d_viewport); + // Asset Library. + theme->set_stylebox("panel", "AssetLib", style_content_panel); + theme->set_color("status_color", "AssetLib", Color(0.5, 0.5, 0.5)); + theme->set_icon("dismiss", "AssetLib", theme->get_icon("Close", "EditorIcons")); + // Theme editor. theme->set_color("preview_picker_overlay_color", "ThemeEditor", Color(0.1, 0.1, 0.1, 0.25)); Color theme_preview_picker_bg_color = accent_color; |