Path: blob/master/editor/themes/editor_theme_manager.h
21217 views
/**************************************************************************/1/* editor_theme_manager.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "editor/themes/editor_theme.h"3334class StyleBoxFlat;35class StyleBoxLine;36class StyleBoxTexture;3738class EditorThemeManager {39static int benchmark_run;40static inline bool outdated_cache = false;41static inline bool outdated_cache_dirty = true;4243static String get_benchmark_key();4445enum ColorMode {46AUTO_COLOR,47DARK_COLOR,48LIGHT_COLOR,49};5051public:52struct ThemeConfiguration {53// Basic properties.5455String style;56String preset;57String spacing_preset;5859Color base_color;60Color accent_color;61float contrast = 1.0;62float icon_saturation = 1.0;6364// Extra properties.6566int base_spacing = 4;67int extra_spacing = 0;68Size2 dialogs_buttons_min_size = Size2(105, 34);69int border_width = 0;70int corner_radius = 3;7172bool draw_extra_borders = false;73int draw_relationship_lines;74float relationship_line_opacity = 1.0;75int thumb_size = 16;76int class_icon_size = 16;77bool enable_touch_optimizations = false;78float gizmo_handle_scale = 1.0;79int inspector_property_height = 28;80float subresource_hue_tint = 0.0;81float dragging_hover_wait_msec = 0;8283// Make sure to keep those in sync with the definitions in the editor settings.84const float default_icon_saturation = 2.0;85const int default_relationship_lines = RELATIONSHIP_SELECTED_ONLY;86const float default_contrast = 0.3;87const int default_corner_radius = 4;8889// Generated properties.9091bool dark_theme = false;92bool dark_icon_and_font = false;9394int base_margin = 4;95int increased_margin = 4;96int separation_margin = 4;97int popup_margin = 12;98int window_border_margin = 8;99int top_bar_separation = 8;100int forced_even_separation = 0;101102Color mono_color;103Color mono_color_font;104Color mono_color_inv;105Color dark_color_1;106Color dark_color_2;107Color dark_color_3;108Color contrast_color_1;109Color contrast_color_2;110Color highlight_color;111Color highlight_disabled_color;112Color success_color;113Color warning_color;114Color error_color;115Color extra_border_color_1;116Color extra_border_color_2;117118Color font_color;119Color font_secondary_color;120Color font_focus_color;121Color font_hover_color;122Color font_pressed_color;123Color font_hover_pressed_color;124Color font_disabled_color;125Color font_readonly_color;126Color font_placeholder_color;127Color font_outline_color;128129Color font_dark_background_color;130Color font_dark_background_focus_color;131Color font_dark_background_hover_color;132Color font_dark_background_pressed_color;133Color font_dark_background_hover_pressed_color;134135Color icon_normal_color;136Color icon_secondary_color;137Color icon_focus_color;138Color icon_hover_color;139Color icon_pressed_color;140Color icon_disabled_color;141142Color surface_popup_color;143Color surface_lowest_color;144Color surface_lower_color;145Color surface_low_color;146Color surface_base_color;147Color surface_high_color;148Color surface_higher_color;149Color surface_highest_color;150151Color button_normal_color;152Color button_hover_color;153Color button_pressed_color;154Color button_disabled_color;155Color button_border_normal_color;156Color button_border_hover_color;157Color button_border_pressed_color;158159Color flat_button_pressed_color;160Color flat_button_hover_pressed_color;161Color flat_button_hover_color;162163Color shadow_color;164Color selection_color;165Color disabled_border_color;166Color disabled_bg_color;167Color separator_color;168169Ref<StyleBoxFlat> base_style;170Ref<StyleBoxFlat> focus_style;171Ref<StyleBoxEmpty> base_empty_style;172Ref<StyleBoxEmpty> base_empty_wide_style;173174Ref<StyleBoxFlat> button_style;175Ref<StyleBoxFlat> button_style_disabled;176Ref<StyleBoxFlat> button_style_focus;177Ref<StyleBoxFlat> button_style_pressed;178Ref<StyleBoxFlat> button_style_hover;179180Ref<StyleBoxFlat> flat_button;181Ref<StyleBoxFlat> flat_button_pressed;182Ref<StyleBoxFlat> flat_button_hover_pressed;183Ref<StyleBoxFlat> flat_button_hover;184185Ref<StyleBoxFlat> popup_style;186Ref<StyleBoxFlat> popup_border_style;187Ref<StyleBoxFlat> popup_panel_style;188Ref<StyleBoxFlat> window_style;189Ref<StyleBoxFlat> window_complex_style;190Ref<StyleBoxFlat> dialog_style;191Ref<StyleBoxFlat> panel_container_style;192Ref<StyleBoxFlat> content_panel_style;193Ref<StyleBoxFlat> tree_panel_style;194Ref<StyleBoxFlat> tab_container_style;195Ref<StyleBoxFlat> foreground_panel;196197Vector2 widget_margin;198199uint32_t hash();200uint32_t hash_fonts();201uint32_t hash_icons();202};203204enum RelationshipLinesMode {205RELATIONSHIP_NONE,206RELATIONSHIP_SELECTED_ONLY,207RELATIONSHIP_ALL,208};209210private:211static Ref<EditorTheme> _create_base_theme(const Ref<EditorTheme> &p_old_theme = nullptr);212static ThemeConfiguration _create_theme_config();213214static void _populate_text_editor_styles(const Ref<EditorTheme> &p_theme, ThemeConfiguration &p_config);215static void _populate_visual_shader_styles(const Ref<EditorTheme> &p_theme, ThemeConfiguration &p_config);216217static void _reset_dirty_flag();218219public:220static Ref<StyleBoxFlat> make_flat_stylebox(Color p_color, float p_margin_left = -1, float p_margin_top = -1, float p_margin_right = -1, float p_margin_bottom = -1, int p_corner_width = 0);221static Ref<StyleBoxEmpty> make_empty_stylebox(float p_margin_left = -1, float p_margin_top = -1, float p_margin_right = -1, float p_margin_bottom = -1);222static Ref<StyleBoxTexture> make_stylebox(Ref<Texture2D> p_texture, float p_left, float p_top, float p_right, float p_bottom, float p_margin_left = -1, float p_margin_top = -1, float p_margin_right = -1, float p_margin_bottom = -1, bool p_draw_center = true);223static Ref<StyleBoxLine> make_line_stylebox(Color p_color, int p_thickness = 1, float p_grow_begin = 1, float p_grow_end = 1, bool p_vertical = false);224225static Ref<EditorTheme> generate_theme(const Ref<EditorTheme> &p_old_theme = nullptr);226static bool is_generated_theme_outdated();227228static bool is_dark_theme();229static bool is_dark_icon_and_font();230231static void initialize();232static void finalize();233};234235236