Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/themes/editor_theme_manager.h
9902 views
1
/**************************************************************************/
2
/* editor_theme_manager.h */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#pragma once
32
33
#include "editor/themes/editor_theme.h"
34
#include "scene/resources/style_box_flat.h"
35
36
class EditorThemeManager {
37
static int benchmark_run;
38
static inline bool outdated_cache = false;
39
static inline bool outdated_cache_dirty = true;
40
41
static String get_benchmark_key();
42
43
enum ColorMode {
44
AUTO_COLOR,
45
DARK_COLOR,
46
LIGHT_COLOR,
47
};
48
49
struct ThemeConfiguration {
50
// Basic properties.
51
52
String preset;
53
String spacing_preset;
54
55
Color base_color;
56
Color accent_color;
57
float contrast = 1.0;
58
float icon_saturation = 1.0;
59
60
// Extra properties.
61
62
int base_spacing = 4;
63
int extra_spacing = 0;
64
Size2 dialogs_buttons_min_size = Size2(105, 34);
65
int border_width = 0;
66
int corner_radius = 3;
67
68
bool draw_extra_borders = false;
69
float relationship_line_opacity = 1.0;
70
int thumb_size = 16;
71
int class_icon_size = 16;
72
bool enable_touch_optimizations = false;
73
float gizmo_handle_scale = 1.0;
74
int color_picker_button_height = 28;
75
float subresource_hue_tint = 0.0;
76
77
float default_contrast = 1.0;
78
79
// Generated properties.
80
81
bool dark_theme = false;
82
83
int base_margin = 4;
84
int increased_margin = 4;
85
int separation_margin = 4;
86
int popup_margin = 12;
87
int window_border_margin = 8;
88
int top_bar_separation = 8;
89
int forced_even_separation = 0;
90
91
Color mono_color;
92
Color dark_color_1;
93
Color dark_color_2;
94
Color dark_color_3;
95
Color contrast_color_1;
96
Color contrast_color_2;
97
Color highlight_color;
98
Color highlight_disabled_color;
99
Color success_color;
100
Color warning_color;
101
Color error_color;
102
Color extra_border_color_1;
103
Color extra_border_color_2;
104
105
Color font_color;
106
Color font_focus_color;
107
Color font_hover_color;
108
Color font_pressed_color;
109
Color font_hover_pressed_color;
110
Color font_disabled_color;
111
Color font_readonly_color;
112
Color font_placeholder_color;
113
Color font_outline_color;
114
115
Color icon_normal_color;
116
Color icon_focus_color;
117
Color icon_hover_color;
118
Color icon_pressed_color;
119
Color icon_disabled_color;
120
121
Color shadow_color;
122
Color selection_color;
123
Color disabled_border_color;
124
Color disabled_bg_color;
125
Color separator_color;
126
127
Ref<StyleBoxFlat> base_style;
128
Ref<StyleBoxEmpty> base_empty_style;
129
130
Ref<StyleBoxFlat> button_style;
131
Ref<StyleBoxFlat> button_style_disabled;
132
Ref<StyleBoxFlat> button_style_focus;
133
Ref<StyleBoxFlat> button_style_pressed;
134
Ref<StyleBoxFlat> button_style_hover;
135
136
Ref<StyleBoxFlat> circle_style_focus;
137
138
Ref<StyleBoxFlat> popup_style;
139
Ref<StyleBoxFlat> popup_border_style;
140
Ref<StyleBoxFlat> window_style;
141
Ref<StyleBoxFlat> dialog_style;
142
Ref<StyleBoxFlat> panel_container_style;
143
Ref<StyleBoxFlat> content_panel_style;
144
Ref<StyleBoxFlat> tree_panel_style;
145
146
Vector2 widget_margin;
147
148
uint32_t hash();
149
uint32_t hash_fonts();
150
uint32_t hash_icons();
151
};
152
153
static Ref<EditorTheme> _create_base_theme(const Ref<EditorTheme> &p_old_theme = nullptr);
154
static ThemeConfiguration _create_theme_config(const Ref<EditorTheme> &p_theme);
155
156
static void _create_shared_styles(const Ref<EditorTheme> &p_theme, ThemeConfiguration &p_config);
157
static void _populate_standard_styles(const Ref<EditorTheme> &p_theme, ThemeConfiguration &p_config);
158
static void _populate_editor_styles(const Ref<EditorTheme> &p_theme, ThemeConfiguration &p_config);
159
160
static void _populate_text_editor_styles(const Ref<EditorTheme> &p_theme, ThemeConfiguration &p_config);
161
static void _populate_visual_shader_styles(const Ref<EditorTheme> &p_theme, ThemeConfiguration &p_config);
162
163
static void _reset_dirty_flag();
164
165
public:
166
static Ref<EditorTheme> generate_theme(const Ref<EditorTheme> &p_old_theme = nullptr);
167
static bool is_generated_theme_outdated();
168
169
static bool is_dark_theme();
170
171
static void initialize();
172
static void finalize();
173
};
174
175