editor_theme_manager.cpp 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. /**************************************************************************/
  2. /* editor_theme_manager.cpp */
  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. #include "editor_theme_manager.h"
  31. #include "core/error/error_macros.h"
  32. #include "core/io/resource_loader.h"
  33. #include "editor/editor_string_names.h"
  34. #include "editor/file_system/editor_paths.h"
  35. #include "editor/settings/editor_settings.h"
  36. #include "editor/themes/editor_color_map.h"
  37. #include "editor/themes/editor_fonts.h"
  38. #include "editor/themes/editor_icons.h"
  39. #include "editor/themes/editor_scale.h"
  40. #include "editor/themes/editor_theme.h"
  41. #include "editor/themes/theme_classic.h"
  42. #include "editor/themes/theme_modern.h"
  43. #include "scene/resources/style_box_flat.h"
  44. #include "scene/resources/style_box_line.h"
  45. #include "scene/resources/style_box_texture.h"
  46. #include "scene/resources/texture.h"
  47. #include "scene/scene_string_names.h"
  48. #include "servers/display/display_server.h"
  49. // Theme configuration.
  50. uint32_t EditorThemeManager::ThemeConfiguration::hash() {
  51. uint32_t hash = hash_murmur3_one_float(EDSCALE);
  52. // Basic properties.
  53. hash = hash_murmur3_one_32(style.hash(), hash);
  54. hash = hash_murmur3_one_32(preset.hash(), hash);
  55. hash = hash_murmur3_one_32(spacing_preset.hash(), hash);
  56. hash = hash_murmur3_one_32(base_color.to_rgba32(), hash);
  57. hash = hash_murmur3_one_32(accent_color.to_rgba32(), hash);
  58. hash = hash_murmur3_one_float(contrast, hash);
  59. hash = hash_murmur3_one_float(icon_saturation, hash);
  60. // Extra properties.
  61. hash = hash_murmur3_one_32(base_spacing, hash);
  62. hash = hash_murmur3_one_32(extra_spacing, hash);
  63. hash = hash_murmur3_one_32(border_width, hash);
  64. hash = hash_murmur3_one_32(corner_radius, hash);
  65. hash = hash_murmur3_one_32((int)draw_extra_borders, hash);
  66. hash = hash_murmur3_one_float(relationship_line_opacity, hash);
  67. hash = hash_murmur3_one_32(thumb_size, hash);
  68. hash = hash_murmur3_one_32(class_icon_size, hash);
  69. hash = hash_murmur3_one_32((int)enable_touch_optimizations, hash);
  70. hash = hash_murmur3_one_float(gizmo_handle_scale, hash);
  71. hash = hash_murmur3_one_32(inspector_property_height, hash);
  72. hash = hash_murmur3_one_float(subresource_hue_tint, hash);
  73. hash = hash_murmur3_one_float(default_contrast, hash);
  74. // Generated properties.
  75. hash = hash_murmur3_one_32((int)dark_theme, hash);
  76. hash = hash_murmur3_one_32((int)dark_icon_and_font, hash);
  77. return hash;
  78. }
  79. uint32_t EditorThemeManager::ThemeConfiguration::hash_fonts() {
  80. uint32_t hash = hash_murmur3_one_float(EDSCALE);
  81. // TODO: Implement the hash based on what editor_register_fonts() uses.
  82. return hash;
  83. }
  84. uint32_t EditorThemeManager::ThemeConfiguration::hash_icons() {
  85. uint32_t hash = hash_murmur3_one_float(EDSCALE);
  86. hash = hash_murmur3_one_32(accent_color.to_rgba32(), hash);
  87. hash = hash_murmur3_one_float(icon_saturation, hash);
  88. hash = hash_murmur3_one_32(thumb_size, hash);
  89. hash = hash_murmur3_one_float(gizmo_handle_scale, hash);
  90. hash = hash_murmur3_one_32((int)dark_icon_and_font, hash);
  91. return hash;
  92. }
  93. // Benchmarks.
  94. int EditorThemeManager::benchmark_run = 0;
  95. String EditorThemeManager::get_benchmark_key() {
  96. if (benchmark_run == 0) {
  97. return "EditorTheme (Startup)";
  98. }
  99. return vformat("EditorTheme (Run %d)", benchmark_run);
  100. }
  101. // Generation helper methods.
  102. Ref<StyleBoxTexture> EditorThemeManager::make_stylebox(Ref<Texture2D> p_texture, float p_left, float p_top, float p_right, float p_bottom, float p_margin_left, float p_margin_top, float p_margin_right, float p_margin_bottom, bool p_draw_center) {
  103. Ref<StyleBoxTexture> style(memnew(StyleBoxTexture));
  104. style->set_texture(p_texture);
  105. style->set_texture_margin_individual(p_left * EDSCALE, p_top * EDSCALE, p_right * EDSCALE, p_bottom * EDSCALE);
  106. style->set_content_margin_individual((p_left + p_margin_left) * EDSCALE, (p_top + p_margin_top) * EDSCALE, (p_right + p_margin_right) * EDSCALE, (p_bottom + p_margin_bottom) * EDSCALE);
  107. style->set_draw_center(p_draw_center);
  108. return style;
  109. }
  110. Ref<StyleBoxEmpty> EditorThemeManager::make_empty_stylebox(float p_margin_left, float p_margin_top, float p_margin_right, float p_margin_bottom) {
  111. Ref<StyleBoxEmpty> style(memnew(StyleBoxEmpty));
  112. style->set_content_margin_individual(p_margin_left * EDSCALE, p_margin_top * EDSCALE, p_margin_right * EDSCALE, p_margin_bottom * EDSCALE);
  113. return style;
  114. }
  115. Ref<StyleBoxFlat> EditorThemeManager::make_flat_stylebox(Color p_color, float p_margin_left, float p_margin_top, float p_margin_right, float p_margin_bottom, int p_corner_width) {
  116. Ref<StyleBoxFlat> style(memnew(StyleBoxFlat));
  117. style->set_bg_color(p_color);
  118. // Adjust level of detail based on the corners' effective sizes.
  119. style->set_corner_detail(Math::ceil(0.8 * p_corner_width * EDSCALE));
  120. style->set_corner_radius_all(p_corner_width * EDSCALE);
  121. style->set_content_margin_individual(p_margin_left * EDSCALE, p_margin_top * EDSCALE, p_margin_right * EDSCALE, p_margin_bottom * EDSCALE);
  122. return style;
  123. }
  124. Ref<StyleBoxLine> EditorThemeManager::make_line_stylebox(Color p_color, int p_thickness, float p_grow_begin, float p_grow_end, bool p_vertical) {
  125. Ref<StyleBoxLine> style(memnew(StyleBoxLine));
  126. style->set_color(p_color);
  127. style->set_grow_begin(p_grow_begin);
  128. style->set_grow_end(p_grow_end);
  129. style->set_thickness(p_thickness);
  130. style->set_vertical(p_vertical);
  131. return style;
  132. }
  133. // Theme generation and population routines.
  134. Ref<EditorTheme> EditorThemeManager::_create_base_theme(const Ref<EditorTheme> &p_old_theme) {
  135. OS::get_singleton()->benchmark_begin_measure(get_benchmark_key(), "Create Base Theme");
  136. Ref<EditorTheme> theme = memnew(EditorTheme);
  137. ThemeConfiguration config = _create_theme_config();
  138. theme->set_generated_hash(config.hash());
  139. theme->set_generated_fonts_hash(config.hash_fonts());
  140. theme->set_generated_icons_hash(config.hash_icons());
  141. print_verbose(vformat("EditorTheme: Generating new theme for the config '%d'.", theme->get_generated_hash()));
  142. bool is_default_style = config.style == "Modern";
  143. if (is_default_style) {
  144. ThemeModern::populate_shared_styles(theme, config);
  145. } else {
  146. ThemeClassic::populate_shared_styles(theme, config);
  147. }
  148. // Register icons.
  149. {
  150. OS::get_singleton()->benchmark_begin_measure(get_benchmark_key(), "Register Icons");
  151. // External functions, see editor_icons.cpp.
  152. editor_configure_icons(config.dark_icon_and_font);
  153. // If settings are comparable to the old theme, then just copy existing icons over.
  154. // Otherwise, regenerate them.
  155. bool keep_old_icons = (p_old_theme.is_valid() && theme->get_generated_icons_hash() == p_old_theme->get_generated_icons_hash());
  156. if (keep_old_icons) {
  157. print_verbose("EditorTheme: Can keep old icons, copying.");
  158. editor_copy_icons(theme, p_old_theme);
  159. } else {
  160. print_verbose("EditorTheme: Generating new icons.");
  161. editor_register_icons(theme, config.dark_icon_and_font, config.icon_saturation, config.thumb_size, config.gizmo_handle_scale);
  162. }
  163. OS::get_singleton()->benchmark_end_measure(get_benchmark_key(), "Register Icons");
  164. }
  165. // Register fonts.
  166. {
  167. OS::get_singleton()->benchmark_begin_measure(get_benchmark_key(), "Register Fonts");
  168. // TODO: Check if existing font definitions from the old theme are usable and copy them.
  169. // External function, see editor_fonts.cpp.
  170. print_verbose("EditorTheme: Generating new fonts.");
  171. editor_register_fonts(theme);
  172. OS::get_singleton()->benchmark_end_measure(get_benchmark_key(), "Register Fonts");
  173. }
  174. // TODO: Check if existing style definitions from the old theme are usable and copy them.
  175. print_verbose("EditorTheme: Generating new styles.");
  176. if (is_default_style) {
  177. ThemeModern::populate_standard_styles(theme, config);
  178. ThemeModern::populate_editor_styles(theme, config);
  179. } else {
  180. ThemeClassic::populate_standard_styles(theme, config);
  181. ThemeClassic::populate_editor_styles(theme, config);
  182. }
  183. _populate_text_editor_styles(theme, config);
  184. _populate_visual_shader_styles(theme, config);
  185. OS::get_singleton()->benchmark_end_measure(get_benchmark_key(), "Create Base Theme");
  186. return theme;
  187. }
  188. EditorThemeManager::ThemeConfiguration EditorThemeManager::_create_theme_config() {
  189. ThemeConfiguration config;
  190. // Basic properties.
  191. config.style = EDITOR_GET("interface/theme/style");
  192. config.preset = EDITOR_GET("interface/theme/color_preset");
  193. config.spacing_preset = EDITOR_GET("interface/theme/spacing_preset");
  194. config.base_color = EDITOR_GET("interface/theme/base_color");
  195. config.accent_color = EDITOR_GET("interface/theme/accent_color");
  196. config.contrast = EDITOR_GET("interface/theme/contrast");
  197. config.icon_saturation = EDITOR_GET("interface/theme/icon_saturation");
  198. config.corner_radius = EDITOR_GET("interface/theme/corner_radius");
  199. // Extra properties.
  200. config.base_spacing = EDITOR_GET("interface/theme/base_spacing");
  201. config.extra_spacing = EDITOR_GET("interface/theme/additional_spacing");
  202. // Ensure borders are visible when using an editor scale below 100%.
  203. config.border_width = CLAMP((int)EDITOR_GET("interface/theme/border_size"), 0, 2) * MAX(1, EDSCALE);
  204. config.draw_extra_borders = EDITOR_GET("interface/theme/draw_extra_borders");
  205. config.draw_relationship_lines = EDITOR_GET("interface/theme/draw_relationship_lines");
  206. config.relationship_line_opacity = EDITOR_GET("interface/theme/relationship_line_opacity");
  207. config.thumb_size = EDITOR_GET("filesystem/file_dialog/thumbnail_size");
  208. config.class_icon_size = 16 * EDSCALE;
  209. config.enable_touch_optimizations = EDITOR_GET("interface/touchscreen/enable_touch_optimizations");
  210. config.gizmo_handle_scale = EDITOR_GET("interface/touchscreen/scale_gizmo_handles");
  211. config.subresource_hue_tint = EDITOR_GET("docks/property_editor/subresource_hue_tint");
  212. config.dragging_hover_wait_msec = (float)EDITOR_GET("interface/editor/dragging_hover_wait_seconds") * 1000;
  213. // Handle theme style.
  214. if (config.preset != "Custom") {
  215. if (config.style == "Classic") {
  216. config.draw_relationship_lines = RELATIONSHIP_ALL;
  217. config.corner_radius = 3;
  218. } else { // Default
  219. config.draw_relationship_lines = config.default_relationship_lines;
  220. config.corner_radius = config.default_corner_radius;
  221. }
  222. EditorSettings::get_singleton()->set_initial_value("interface/theme/draw_relationship_lines", config.draw_relationship_lines);
  223. EditorSettings::get_singleton()->set_initial_value("interface/theme/corner_radius", config.corner_radius);
  224. // Enforce values in case they were adjusted or overridden.
  225. EditorSettings::get_singleton()->set_manually("interface/theme/draw_relationship_lines", config.draw_relationship_lines);
  226. EditorSettings::get_singleton()->set_manually("interface/theme/corner_radius", config.corner_radius);
  227. }
  228. // Handle color preset.
  229. {
  230. const bool follow_system_theme = EDITOR_GET("interface/theme/follow_system_theme");
  231. const bool use_system_accent_color = EDITOR_GET("interface/theme/use_system_accent_color");
  232. DisplayServer *display_server = DisplayServer::get_singleton();
  233. Color system_base_color = display_server->get_base_color();
  234. Color system_accent_color = display_server->get_accent_color();
  235. if (follow_system_theme) {
  236. String dark_theme = "Default";
  237. String light_theme = "Light";
  238. config.preset = light_theme; // Assume light theme if we can't detect system theme attributes.
  239. if (system_base_color == Color(0, 0, 0, 0)) {
  240. if (display_server->is_dark_mode_supported() && display_server->is_dark_mode()) {
  241. config.preset = dark_theme;
  242. }
  243. } else {
  244. if (system_base_color.get_luminance() < 0.5) {
  245. config.preset = dark_theme;
  246. }
  247. }
  248. }
  249. if (config.preset != "Custom") {
  250. Color preset_accent_color;
  251. Color preset_base_color;
  252. float preset_contrast = config.default_contrast;
  253. bool preset_draw_extra_borders = false;
  254. float preset_icon_saturation = config.default_icon_saturation;
  255. // A negative contrast rate looks better for light themes, since it better follows the natural order of UI "elevation".
  256. const float light_contrast = -0.06;
  257. // Please use alphabetical order if you're adding a new color preset here.
  258. if (config.preset == "Black (OLED)") {
  259. preset_accent_color = Color(0.45, 0.75, 1.0);
  260. preset_base_color = Color(0, 0, 0);
  261. // The contrast rate value is irrelevant on a fully black theme.
  262. preset_contrast = 0.0;
  263. preset_draw_extra_borders = true;
  264. } else if (config.preset == "Breeze Dark") {
  265. preset_accent_color = Color(0.239, 0.682, 0.914);
  266. preset_base_color = Color(0.1255, 0.1373, 0.149);
  267. } else if (config.preset == "Godot 2") {
  268. preset_accent_color = Color(0.53, 0.67, 0.89);
  269. preset_base_color = Color(0.24, 0.23, 0.27);
  270. preset_icon_saturation = 1;
  271. } else if (config.preset == "Godot 3") {
  272. preset_accent_color = Color(0.44, 0.73, 0.98);
  273. preset_base_color = Color(0.21, 0.24, 0.29);
  274. preset_icon_saturation = 1;
  275. } else if (config.preset == "Gray") {
  276. preset_accent_color = Color(0.44, 0.73, 0.98);
  277. preset_base_color = Color(0.24, 0.24, 0.24);
  278. } else if (config.preset == "Light") {
  279. preset_accent_color = Color(0.18, 0.50, 1.00);
  280. preset_base_color = Color(0.9, 0.9, 0.9);
  281. preset_contrast = light_contrast;
  282. preset_icon_saturation = 1;
  283. } else if (config.preset == "Solarized (Dark)") {
  284. preset_accent_color = Color(0.15, 0.55, 0.82);
  285. preset_base_color = Color(0.03, 0.21, 0.26);
  286. preset_contrast = 0.23;
  287. } else if (config.preset == "Solarized (Light)") {
  288. preset_accent_color = Color(0.15, 0.55, 0.82);
  289. preset_base_color = Color(0.89, 0.86, 0.79);
  290. preset_contrast = light_contrast;
  291. } else { // Default
  292. preset_accent_color = Color(0.337, 0.62, 1.0);
  293. preset_base_color = Color(0.161, 0.161, 0.161);
  294. }
  295. config.accent_color = preset_accent_color;
  296. config.base_color = preset_base_color;
  297. config.contrast = preset_contrast;
  298. config.draw_extra_borders = preset_draw_extra_borders;
  299. config.icon_saturation = preset_icon_saturation;
  300. EditorSettings::get_singleton()->set_initial_value("interface/theme/accent_color", config.accent_color);
  301. EditorSettings::get_singleton()->set_initial_value("interface/theme/base_color", config.base_color);
  302. EditorSettings::get_singleton()->set_initial_value("interface/theme/contrast", config.contrast);
  303. EditorSettings::get_singleton()->set_initial_value("interface/theme/draw_extra_borders", config.draw_extra_borders);
  304. EditorSettings::get_singleton()->set_initial_value("interface/theme/icon_saturation", config.icon_saturation);
  305. }
  306. if (follow_system_theme && system_base_color != Color(0, 0, 0, 0)) {
  307. config.base_color = system_base_color;
  308. config.preset = "Custom";
  309. }
  310. if (use_system_accent_color && system_accent_color != Color(0, 0, 0, 0)) {
  311. config.accent_color = system_accent_color;
  312. config.preset = "Custom";
  313. }
  314. // Enforce values in case they were adjusted or overridden.
  315. EditorSettings::get_singleton()->set_manually("interface/theme/color_preset", config.preset);
  316. EditorSettings::get_singleton()->set_manually("interface/theme/accent_color", config.accent_color);
  317. EditorSettings::get_singleton()->set_manually("interface/theme/base_color", config.base_color);
  318. EditorSettings::get_singleton()->set_manually("interface/theme/contrast", config.contrast);
  319. EditorSettings::get_singleton()->set_manually("interface/theme/draw_extra_borders", config.draw_extra_borders);
  320. EditorSettings::get_singleton()->set_manually("interface/theme/icon_saturation", config.icon_saturation);
  321. }
  322. // Handle theme spacing preset.
  323. {
  324. if (config.spacing_preset != "Custom") {
  325. int preset_base_spacing = 0;
  326. int preset_extra_spacing = 0;
  327. Size2 preset_dialogs_buttons_min_size;
  328. if (config.spacing_preset == "Compact") {
  329. preset_base_spacing = 2;
  330. preset_extra_spacing = 2;
  331. preset_dialogs_buttons_min_size = Size2(90, 26);
  332. } else if (config.spacing_preset == "Spacious") {
  333. preset_base_spacing = 6;
  334. preset_extra_spacing = 2;
  335. preset_dialogs_buttons_min_size = Size2(112, 36);
  336. } else { // Default
  337. preset_base_spacing = 4;
  338. preset_extra_spacing = 0;
  339. preset_dialogs_buttons_min_size = Size2(105, 34);
  340. }
  341. config.base_spacing = preset_base_spacing;
  342. config.extra_spacing = preset_extra_spacing;
  343. config.dialogs_buttons_min_size = preset_dialogs_buttons_min_size;
  344. EditorSettings::get_singleton()->set_initial_value("interface/theme/base_spacing", config.base_spacing);
  345. EditorSettings::get_singleton()->set_initial_value("interface/theme/additional_spacing", config.extra_spacing);
  346. }
  347. // Enforce values in case they were adjusted or overridden.
  348. EditorSettings::get_singleton()->set_manually("interface/theme/spacing_preset", config.spacing_preset);
  349. EditorSettings::get_singleton()->set_manually("interface/theme/base_spacing", config.base_spacing);
  350. EditorSettings::get_singleton()->set_manually("interface/theme/additional_spacing", config.extra_spacing);
  351. }
  352. // Generated properties.
  353. config.dark_theme = is_dark_theme();
  354. config.dark_icon_and_font = is_dark_icon_and_font();
  355. config.base_margin = config.base_spacing;
  356. config.increased_margin = config.base_spacing + config.extra_spacing * 0.75;
  357. config.separation_margin = (config.base_spacing + config.extra_spacing / 2) * EDSCALE;
  358. config.popup_margin = config.base_margin * 2.4 * EDSCALE;
  359. // Make sure content doesn't stick to window decorations; this can be fixed in future with layout changes.
  360. config.window_border_margin = MAX(1, config.base_margin * EDSCALE);
  361. config.top_bar_separation = MAX(1, config.base_margin * EDSCALE);
  362. // Force the v_separation to be even so that the spacing on top and bottom is even.
  363. // If the vsep is odd and cannot be split into 2 even groups (of pixels), then it will be lopsided.
  364. // We add 2 to the vsep to give it some extra spacing which looks a bit more modern (see Windows, for example).
  365. const int separation_base = config.increased_margin + 6;
  366. config.forced_even_separation = separation_base + (separation_base % 2);
  367. return config;
  368. }
  369. void _load_text_editor_theme() {
  370. EditorSettings *settings = EditorSettings::get_singleton();
  371. const String theme_name = settings->get_setting("text_editor/theme/color_theme");
  372. ERR_FAIL_COND(EditorSettings::is_default_text_editor_theme(theme_name.get_file().to_lower()));
  373. const String theme_path = EditorPaths::get_singleton()->get_text_editor_themes_dir().path_join(theme_name + ".tet");
  374. Ref<ConfigFile> cf;
  375. cf.instantiate();
  376. Error err = cf->load(theme_path);
  377. ERR_FAIL_COND_MSG(err != OK, vformat("Failed to load text editor theme file '%s': %s", theme_name, error_names[err]));
  378. const PackedStringArray keys = cf->get_section_keys("color_theme");
  379. for (const String &key : keys) {
  380. const String setting_key = "text_editor/theme/highlighting/" + key;
  381. // Don't load if it's not an actual setting, or if it isn't a color setting.
  382. if (!settings->has_setting(setting_key) || !key.contains("color")) {
  383. continue;
  384. }
  385. const String val = cf->get_value("color_theme", key);
  386. // Make sure it is actually a color.
  387. if (val.is_valid_html_color()) {
  388. const Color color_value = Color::html(val);
  389. // Change manually to prevent settings_changed spam.
  390. settings->set_initial_value(setting_key, color_value);
  391. settings->set_manually(setting_key, color_value);
  392. }
  393. }
  394. // If it doesn't load a setting just use what is currently loaded.
  395. }
  396. void EditorThemeManager::_populate_text_editor_styles(const Ref<EditorTheme> &p_theme, ThemeConfiguration &p_config) {
  397. const String text_editor_color_theme = EDITOR_GET("text_editor/theme/color_theme");
  398. const bool is_default_theme = text_editor_color_theme == "Default";
  399. const bool is_godot2_theme = text_editor_color_theme == "Godot 2";
  400. const bool is_custom_theme = text_editor_color_theme == "Custom";
  401. if (is_default_theme || is_godot2_theme || is_custom_theme) {
  402. HashMap<StringName, Color> colors;
  403. if (is_default_theme || is_custom_theme) {
  404. // Adaptive colors for comments and elements with lower relevance.
  405. const Color dim_color = Color(p_config.font_color, 0.5);
  406. const float mono_value = p_config.mono_color.r;
  407. const Color alpha1 = Color(mono_value, mono_value, mono_value, 0.07);
  408. const Color alpha2 = Color(mono_value, mono_value, mono_value, 0.14);
  409. const Color alpha3 = Color(mono_value, mono_value, mono_value, 0.27);
  410. // Syntax highlight token colors.
  411. colors["text_editor/theme/highlighting/symbol_color"] = p_config.dark_icon_and_font ? Color(0.67, 0.79, 1) : Color(0, 0, 0.61);
  412. colors["text_editor/theme/highlighting/keyword_color"] = p_config.dark_icon_and_font ? Color(1.0, 0.44, 0.52) : Color(0.9, 0.135, 0.51);
  413. colors["text_editor/theme/highlighting/control_flow_keyword_color"] = p_config.dark_icon_and_font ? Color(1.0, 0.55, 0.8) : Color(0.743, 0.12, 0.8);
  414. colors["text_editor/theme/highlighting/base_type_color"] = p_config.dark_icon_and_font ? Color(0.26, 1.0, 0.76) : Color(0, 0.6, 0.2);
  415. colors["text_editor/theme/highlighting/engine_type_color"] = p_config.dark_icon_and_font ? Color(0.56, 1, 0.86) : Color(0.11, 0.55, 0.4);
  416. colors["text_editor/theme/highlighting/user_type_color"] = p_config.dark_icon_and_font ? Color(0.78, 1, 0.93) : Color(0.18, 0.45, 0.4);
  417. colors["text_editor/theme/highlighting/comment_color"] = p_config.dark_icon_and_font ? dim_color : Color(0.08, 0.08, 0.08, 0.5);
  418. colors["text_editor/theme/highlighting/doc_comment_color"] = p_config.dark_icon_and_font ? Color(0.6, 0.7, 0.8, 0.8) : Color(0.15, 0.15, 0.4, 0.7);
  419. colors["text_editor/theme/highlighting/string_color"] = p_config.dark_icon_and_font ? Color(1, 0.93, 0.63) : Color(0.6, 0.42, 0);
  420. colors["text_editor/theme/highlighting/string_placeholder_color"] = p_config.dark_icon_and_font ? Color(1, 0.75, 0.4) : Color(0.93, 0.6, 0.33);
  421. // Use the brightest background color on a light theme (which generally uses a negative contrast rate).
  422. colors["text_editor/theme/highlighting/background_color"] = p_config.base_color.lerp(Color(0, 0, 0), p_config.contrast * (p_config.dark_icon_and_font ? 1.2 : 1.8)).clamp();
  423. colors["text_editor/theme/highlighting/completion_background_color"] = p_config.base_color.lerp(Color(0, 0, 0), p_config.contrast * 0.3).clamp();
  424. colors["text_editor/theme/highlighting/completion_selected_color"] = alpha1;
  425. colors["text_editor/theme/highlighting/completion_existing_color"] = alpha2;
  426. // Same opacity as the scroll grabber editor icon.
  427. colors["text_editor/theme/highlighting/completion_scroll_color"] = Color(mono_value, mono_value, mono_value, 0.29);
  428. colors["text_editor/theme/highlighting/completion_scroll_hovered_color"] = Color(mono_value, mono_value, mono_value, 0.4);
  429. colors["text_editor/theme/highlighting/completion_font_color"] = p_config.font_color;
  430. colors["text_editor/theme/highlighting/text_color"] = p_config.font_color;
  431. colors["text_editor/theme/highlighting/line_number_color"] = dim_color;
  432. colors["text_editor/theme/highlighting/safe_line_number_color"] = p_config.dark_icon_and_font ? (dim_color * Color(1, 1.2, 1, 1.5)) : Color(0, 0.4, 0, 0.75);
  433. colors["text_editor/theme/highlighting/caret_color"] = p_config.mono_color;
  434. colors["text_editor/theme/highlighting/caret_background_color"] = p_config.mono_color.inverted();
  435. colors["text_editor/theme/highlighting/text_selected_color"] = Color(0, 0, 0, 0);
  436. colors["text_editor/theme/highlighting/selection_color"] = p_config.selection_color;
  437. colors["text_editor/theme/highlighting/brace_mismatch_color"] = p_config.dark_icon_and_font ? p_config.error_color : Color(1, 0.08, 0, 1);
  438. colors["text_editor/theme/highlighting/current_line_color"] = alpha1;
  439. colors["text_editor/theme/highlighting/line_length_guideline_color"] = p_config.dark_icon_and_font ? p_config.base_color : p_config.dark_color_2;
  440. colors["text_editor/theme/highlighting/word_highlighted_color"] = alpha1;
  441. colors["text_editor/theme/highlighting/number_color"] = p_config.dark_icon_and_font ? Color(0.63, 1, 0.88) : Color(0, 0.55, 0.28, 1);
  442. colors["text_editor/theme/highlighting/function_color"] = p_config.dark_icon_and_font ? Color(0.34, 0.7, 1.0) : Color(0, 0.225, 0.9, 1);
  443. colors["text_editor/theme/highlighting/member_variable_color"] = p_config.dark_icon_and_font ? Color(0.34, 0.7, 1.0).lerp(p_config.mono_color, 0.6) : Color(0, 0.4, 0.68, 1);
  444. colors["text_editor/theme/highlighting/mark_color"] = Color(p_config.error_color.r, p_config.error_color.g, p_config.error_color.b, 0.3);
  445. colors["text_editor/theme/highlighting/warning_color"] = Color(p_config.warning_color.r, p_config.warning_color.g, p_config.warning_color.b, 0.15);
  446. colors["text_editor/theme/highlighting/bookmark_color"] = Color(0.08, 0.49, 0.98);
  447. colors["text_editor/theme/highlighting/breakpoint_color"] = p_config.dark_icon_and_font ? p_config.error_color : Color(1, 0.27, 0.2, 1);
  448. colors["text_editor/theme/highlighting/executing_line_color"] = Color(0.98, 0.89, 0.27);
  449. colors["text_editor/theme/highlighting/code_folding_color"] = alpha3;
  450. colors["text_editor/theme/highlighting/folded_code_region_color"] = Color(0.68, 0.46, 0.77, 0.2);
  451. colors["text_editor/theme/highlighting/search_result_color"] = alpha1;
  452. colors["text_editor/theme/highlighting/search_result_border_color"] = p_config.dark_icon_and_font ? Color(0.41, 0.61, 0.91, 0.38) : Color(0, 0.4, 1, 0.38);
  453. if (p_config.dark_icon_and_font) {
  454. colors["text_editor/theme/highlighting/gdscript/function_definition_color"] = Color(0.4, 0.9, 1.0);
  455. colors["text_editor/theme/highlighting/gdscript/global_function_color"] = Color(0.64, 0.64, 0.96);
  456. colors["text_editor/theme/highlighting/gdscript/node_path_color"] = Color(0.72, 0.77, 0.49);
  457. colors["text_editor/theme/highlighting/gdscript/node_reference_color"] = Color(0.39, 0.76, 0.35);
  458. colors["text_editor/theme/highlighting/gdscript/annotation_color"] = Color(1.0, 0.7, 0.45);
  459. colors["text_editor/theme/highlighting/gdscript/string_name_color"] = Color(1.0, 0.76, 0.65);
  460. colors["text_editor/theme/highlighting/comment_markers/critical_color"] = Color(0.77, 0.35, 0.35);
  461. colors["text_editor/theme/highlighting/comment_markers/warning_color"] = Color(0.72, 0.61, 0.48);
  462. colors["text_editor/theme/highlighting/comment_markers/notice_color"] = Color(0.56, 0.67, 0.51);
  463. } else {
  464. colors["text_editor/theme/highlighting/gdscript/function_definition_color"] = Color(0, 0.6, 0.6);
  465. colors["text_editor/theme/highlighting/gdscript/global_function_color"] = Color(0.36, 0.18, 0.72);
  466. colors["text_editor/theme/highlighting/gdscript/node_path_color"] = Color(0.18, 0.55, 0);
  467. colors["text_editor/theme/highlighting/gdscript/node_reference_color"] = Color(0.0, 0.5, 0);
  468. colors["text_editor/theme/highlighting/gdscript/annotation_color"] = Color(0.8, 0.37, 0);
  469. colors["text_editor/theme/highlighting/gdscript/string_name_color"] = Color(0.8, 0.56, 0.45);
  470. colors["text_editor/theme/highlighting/comment_markers/critical_color"] = Color(0.8, 0.14, 0.14);
  471. colors["text_editor/theme/highlighting/comment_markers/warning_color"] = Color(0.75, 0.39, 0.03);
  472. colors["text_editor/theme/highlighting/comment_markers/notice_color"] = Color(0.24, 0.54, 0.09);
  473. }
  474. } else if (is_godot2_theme) {
  475. colors = EditorSettings::get_godot2_text_editor_theme();
  476. }
  477. EditorSettings *settings = EditorSettings::get_singleton();
  478. for (const KeyValue<StringName, Color> &setting : colors) {
  479. settings->set_initial_value(setting.key, setting.value);
  480. if (is_default_theme || is_godot2_theme) {
  481. settings->set_manually(setting.key, setting.value);
  482. }
  483. }
  484. } else {
  485. // Custom user theme.
  486. _load_text_editor_theme();
  487. }
  488. // Now theme is loaded, apply it to CodeEdit.
  489. p_theme->set_font(SceneStringName(font), "CodeEdit", p_theme->get_font(SNAME("source"), EditorStringName(EditorFonts)));
  490. p_theme->set_font_size(SceneStringName(font_size), "CodeEdit", p_theme->get_font_size(SNAME("source_size"), EditorStringName(EditorFonts)));
  491. /* clang-format off */
  492. p_theme->set_icon("tab", "CodeEdit", p_theme->get_icon(SNAME("GuiTab"), EditorStringName(EditorIcons)));
  493. p_theme->set_icon("space", "CodeEdit", p_theme->get_icon(SNAME("GuiSpace"), EditorStringName(EditorIcons)));
  494. p_theme->set_icon("folded", "CodeEdit", p_theme->get_icon(SNAME("CodeFoldedRightArrow"), EditorStringName(EditorIcons)));
  495. p_theme->set_icon("can_fold", "CodeEdit", p_theme->get_icon(SNAME("CodeFoldDownArrow"), EditorStringName(EditorIcons)));
  496. p_theme->set_icon("folded_code_region", "CodeEdit", p_theme->get_icon(SNAME("CodeRegionFoldedRightArrow"), EditorStringName(EditorIcons)));
  497. p_theme->set_icon("can_fold_code_region", "CodeEdit", p_theme->get_icon(SNAME("CodeRegionFoldDownArrow"), EditorStringName(EditorIcons)));
  498. p_theme->set_icon("executing_line", "CodeEdit", p_theme->get_icon(SNAME("TextEditorPlay"), EditorStringName(EditorIcons)));
  499. p_theme->set_icon("breakpoint", "CodeEdit", p_theme->get_icon(SNAME("Breakpoint"), EditorStringName(EditorIcons)));
  500. /* clang-format on */
  501. p_theme->set_constant("line_spacing", "CodeEdit", EDITOR_GET("text_editor/appearance/whitespace/line_spacing"));
  502. const Color background_color = EDITOR_GET("text_editor/theme/highlighting/background_color");
  503. Ref<StyleBoxFlat> code_edit_stylebox = make_flat_stylebox(background_color, p_config.widget_margin.x, p_config.widget_margin.y, p_config.widget_margin.x, p_config.widget_margin.y, p_config.corner_radius);
  504. p_theme->set_stylebox(CoreStringName(normal), "CodeEdit", code_edit_stylebox);
  505. p_theme->set_stylebox("read_only", "CodeEdit", code_edit_stylebox);
  506. p_theme->set_stylebox("focus", "CodeEdit", memnew(StyleBoxEmpty));
  507. /* clang-format off */
  508. p_theme->set_color("completion_background_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/completion_background_color"));
  509. p_theme->set_color("completion_selected_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/completion_selected_color"));
  510. p_theme->set_color("completion_existing_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/completion_existing_color"));
  511. p_theme->set_color("completion_scroll_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/completion_scroll_color"));
  512. p_theme->set_color("completion_scroll_hovered_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/completion_scroll_hovered_color"));
  513. p_theme->set_color(SceneStringName(font_color), "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/text_color"));
  514. p_theme->set_color("line_number_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/line_number_color"));
  515. p_theme->set_color("caret_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/caret_color"));
  516. p_theme->set_color("font_selected_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/text_selected_color"));
  517. p_theme->set_color("selection_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/selection_color"));
  518. p_theme->set_color("brace_mismatch_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/brace_mismatch_color"));
  519. p_theme->set_color("current_line_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/current_line_color"));
  520. p_theme->set_color("line_length_guideline_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/line_length_guideline_color"));
  521. p_theme->set_color("word_highlighted_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/word_highlighted_color"));
  522. p_theme->set_color("bookmark_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/bookmark_color"));
  523. p_theme->set_color("breakpoint_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/breakpoint_color"));
  524. p_theme->set_color("executing_line_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/executing_line_color"));
  525. p_theme->set_color("code_folding_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/code_folding_color"));
  526. p_theme->set_color("folded_code_region_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/folded_code_region_color"));
  527. p_theme->set_color("search_result_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/search_result_color"));
  528. p_theme->set_color("search_result_border_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/search_result_border_color"));
  529. /* clang-format on */
  530. }
  531. void EditorThemeManager::_populate_visual_shader_styles(const Ref<EditorTheme> &p_theme, ThemeConfiguration &p_config) {
  532. EditorSettings *ed_settings = EditorSettings::get_singleton();
  533. String visual_shader_color_theme = ed_settings->get("editors/visual_editors/color_theme");
  534. if (visual_shader_color_theme == "Default") {
  535. // Connection type colors
  536. ed_settings->set_initial_value("editors/visual_editors/connection_colors/scalar_color", Color(0.55, 0.55, 0.55), true);
  537. ed_settings->set_initial_value("editors/visual_editors/connection_colors/vector2_color", Color(0.44, 0.43, 0.64), true);
  538. ed_settings->set_initial_value("editors/visual_editors/connection_colors/vector3_color", Color(0.337, 0.314, 0.71), true);
  539. ed_settings->set_initial_value("editors/visual_editors/connection_colors/vector4_color", Color(0.7, 0.65, 0.147), true);
  540. ed_settings->set_initial_value("editors/visual_editors/connection_colors/boolean_color", Color(0.243, 0.612, 0.349), true);
  541. ed_settings->set_initial_value("editors/visual_editors/connection_colors/transform_color", Color(0.71, 0.357, 0.64), true);
  542. ed_settings->set_initial_value("editors/visual_editors/connection_colors/sampler_color", Color(0.659, 0.4, 0.137), true);
  543. // Node category colors (used for the node headers)
  544. ed_settings->set_initial_value("editors/visual_editors/category_colors/output_color", Color(0.26, 0.10, 0.15), true);
  545. ed_settings->set_initial_value("editors/visual_editors/category_colors/color_color", Color(0.5, 0.5, 0.1), true);
  546. ed_settings->set_initial_value("editors/visual_editors/category_colors/conditional_color", Color(0.208, 0.522, 0.298), true);
  547. ed_settings->set_initial_value("editors/visual_editors/category_colors/input_color", Color(0.502, 0.2, 0.204), true);
  548. ed_settings->set_initial_value("editors/visual_editors/category_colors/scalar_color", Color(0.1, 0.5, 0.6), true);
  549. ed_settings->set_initial_value("editors/visual_editors/category_colors/textures_color", Color(0.5, 0.3, 0.1), true);
  550. ed_settings->set_initial_value("editors/visual_editors/category_colors/transform_color", Color(0.5, 0.3, 0.5), true);
  551. ed_settings->set_initial_value("editors/visual_editors/category_colors/utility_color", Color(0.2, 0.2, 0.2), true);
  552. ed_settings->set_initial_value("editors/visual_editors/category_colors/vector_color", Color(0.2, 0.2, 0.5), true);
  553. ed_settings->set_initial_value("editors/visual_editors/category_colors/special_color", Color(0.098, 0.361, 0.294), true);
  554. ed_settings->set_initial_value("editors/visual_editors/category_colors/particle_color", Color(0.12, 0.358, 0.8), true);
  555. } else if (visual_shader_color_theme == "Legacy") {
  556. // Connection type colors
  557. ed_settings->set_initial_value("editors/visual_editors/connection_colors/scalar_color", Color(0.38, 0.85, 0.96), true);
  558. ed_settings->set_initial_value("editors/visual_editors/connection_colors/vector2_color", Color(0.74, 0.57, 0.95), true);
  559. ed_settings->set_initial_value("editors/visual_editors/connection_colors/vector3_color", Color(0.84, 0.49, 0.93), true);
  560. ed_settings->set_initial_value("editors/visual_editors/connection_colors/vector4_color", Color(1.0, 0.125, 0.95), true);
  561. ed_settings->set_initial_value("editors/visual_editors/connection_colors/boolean_color", Color(0.55, 0.65, 0.94), true);
  562. ed_settings->set_initial_value("editors/visual_editors/connection_colors/transform_color", Color(0.96, 0.66, 0.43), true);
  563. ed_settings->set_initial_value("editors/visual_editors/connection_colors/sampler_color", Color(1.0, 1.0, 0.0), true);
  564. // Node category colors (used for the node headers)
  565. Ref<StyleBoxFlat> gn_panel_style = p_theme->get_stylebox(SceneStringName(panel), "GraphNode");
  566. Color gn_bg_color = gn_panel_style->get_bg_color();
  567. ed_settings->set_initial_value("editors/visual_editors/category_colors/output_color", gn_bg_color, true);
  568. ed_settings->set_initial_value("editors/visual_editors/category_colors/color_color", gn_bg_color, true);
  569. ed_settings->set_initial_value("editors/visual_editors/category_colors/conditional_color", gn_bg_color, true);
  570. ed_settings->set_initial_value("editors/visual_editors/category_colors/input_color", gn_bg_color, true);
  571. ed_settings->set_initial_value("editors/visual_editors/category_colors/scalar_color", gn_bg_color, true);
  572. ed_settings->set_initial_value("editors/visual_editors/category_colors/textures_color", gn_bg_color, true);
  573. ed_settings->set_initial_value("editors/visual_editors/category_colors/transform_color", gn_bg_color, true);
  574. ed_settings->set_initial_value("editors/visual_editors/category_colors/utility_color", gn_bg_color, true);
  575. ed_settings->set_initial_value("editors/visual_editors/category_colors/vector_color", gn_bg_color, true);
  576. ed_settings->set_initial_value("editors/visual_editors/category_colors/special_color", gn_bg_color, true);
  577. ed_settings->set_initial_value("editors/visual_editors/category_colors/particle_color", gn_bg_color, true);
  578. }
  579. }
  580. void EditorThemeManager::_reset_dirty_flag() {
  581. outdated_cache_dirty = true;
  582. }
  583. // Public interface for theme generation.
  584. Ref<EditorTheme> EditorThemeManager::generate_theme(const Ref<EditorTheme> &p_old_theme) {
  585. OS::get_singleton()->benchmark_begin_measure(get_benchmark_key(), "Generate Theme");
  586. Ref<EditorTheme> theme = _create_base_theme(p_old_theme);
  587. OS::get_singleton()->benchmark_begin_measure(get_benchmark_key(), "Merge Custom Theme");
  588. const String custom_theme_path = EDITOR_GET("interface/theme/custom_theme");
  589. if (!custom_theme_path.is_empty()) {
  590. Ref<Theme> custom_theme = ResourceLoader::load(custom_theme_path);
  591. if (custom_theme.is_valid()) {
  592. theme->merge_with(custom_theme);
  593. }
  594. }
  595. OS::get_singleton()->benchmark_end_measure(get_benchmark_key(), "Merge Custom Theme");
  596. OS::get_singleton()->benchmark_end_measure(get_benchmark_key(), "Generate Theme");
  597. benchmark_run++;
  598. return theme;
  599. }
  600. bool EditorThemeManager::is_generated_theme_outdated() {
  601. // This list includes settings used by files in the editor/themes folder.
  602. // Note that the editor scale is purposefully omitted because it cannot be changed
  603. // without a restart, so there is no point regenerating the theme.
  604. if (outdated_cache_dirty) {
  605. // TODO: We can use this information more intelligently to do partial theme updates and speed things up.
  606. outdated_cache = EditorSettings::get_singleton()->check_changed_settings_in_group("interface/theme") ||
  607. EditorSettings::get_singleton()->check_changed_settings_in_group("interface/editor/font") ||
  608. EditorSettings::get_singleton()->check_changed_settings_in_group("interface/editor/main_font") ||
  609. EditorSettings::get_singleton()->check_changed_settings_in_group("interface/editor/code_font") ||
  610. EditorSettings::get_singleton()->check_changed_settings_in_group("editors/visual_editors") ||
  611. EditorSettings::get_singleton()->check_changed_settings_in_group("text_editor/theme") ||
  612. EditorSettings::get_singleton()->check_changed_settings_in_group("text_editor/help/help") ||
  613. EditorSettings::get_singleton()->check_changed_settings_in_group("docks/property_editor/subresource_hue_tint") ||
  614. EditorSettings::get_singleton()->check_changed_settings_in_group("filesystem/file_dialog/thumbnail_size") ||
  615. EditorSettings::get_singleton()->check_changed_settings_in_group("run/output/font_size");
  616. // The outdated flag is relevant at the moment of changing editor settings.
  617. callable_mp_static(&EditorThemeManager::_reset_dirty_flag).call_deferred();
  618. outdated_cache_dirty = false;
  619. }
  620. return outdated_cache;
  621. }
  622. bool EditorThemeManager::is_dark_theme() {
  623. Color base_color = EDITOR_GET("interface/theme/base_color");
  624. return base_color.get_luminance() < 0.5;
  625. }
  626. bool EditorThemeManager::is_dark_icon_and_font() {
  627. int icon_font_color_setting = EDITOR_GET("interface/theme/icon_and_font_color");
  628. if (icon_font_color_setting == ColorMode::AUTO_COLOR) {
  629. return is_dark_theme();
  630. }
  631. return icon_font_color_setting == ColorMode::LIGHT_COLOR;
  632. }
  633. void EditorThemeManager::initialize() {
  634. EditorColorMap::create();
  635. EditorTheme::initialize();
  636. }
  637. void EditorThemeManager::finalize() {
  638. EditorColorMap::finish();
  639. EditorTheme::finalize();
  640. }