editor_theme_manager.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. #ifndef EDITOR_THEME_MANAGER_H
  31. #define EDITOR_THEME_MANAGER_H
  32. #include "editor/themes/editor_theme.h"
  33. #include "scene/resources/style_box_flat.h"
  34. class EditorThemeManager {
  35. static int benchmark_run;
  36. static inline bool outdated_cache = false;
  37. static inline bool outdated_cache_dirty = true;
  38. static String get_benchmark_key();
  39. enum ColorMode {
  40. AUTO_COLOR,
  41. DARK_COLOR,
  42. LIGHT_COLOR,
  43. };
  44. struct ThemeConfiguration {
  45. // Basic properties.
  46. String preset;
  47. String spacing_preset;
  48. Color base_color;
  49. Color accent_color;
  50. float contrast = 1.0;
  51. float icon_saturation = 1.0;
  52. // Extra properties.
  53. int base_spacing = 4;
  54. int extra_spacing = 0;
  55. Size2 dialogs_buttons_min_size = Size2(105, 34);
  56. int border_width = 0;
  57. int corner_radius = 3;
  58. bool draw_extra_borders = false;
  59. float relationship_line_opacity = 1.0;
  60. int thumb_size = 16;
  61. int class_icon_size = 16;
  62. bool increase_scrollbar_touch_area = false;
  63. float gizmo_handle_scale = 1.0;
  64. int color_picker_button_height = 28;
  65. float subresource_hue_tint = 0.0;
  66. float default_contrast = 1.0;
  67. // Generated properties.
  68. bool dark_theme = false;
  69. int base_margin = 4;
  70. int increased_margin = 4;
  71. int separation_margin = 4;
  72. int popup_margin = 12;
  73. int window_border_margin = 8;
  74. int top_bar_separation = 8;
  75. int forced_even_separation = 0;
  76. Color mono_color;
  77. Color dark_color_1;
  78. Color dark_color_2;
  79. Color dark_color_3;
  80. Color contrast_color_1;
  81. Color contrast_color_2;
  82. Color highlight_color;
  83. Color highlight_disabled_color;
  84. Color success_color;
  85. Color warning_color;
  86. Color error_color;
  87. Color extra_border_color_1;
  88. Color extra_border_color_2;
  89. Color font_color;
  90. Color font_focus_color;
  91. Color font_hover_color;
  92. Color font_pressed_color;
  93. Color font_hover_pressed_color;
  94. Color font_disabled_color;
  95. Color font_readonly_color;
  96. Color font_placeholder_color;
  97. Color font_outline_color;
  98. Color icon_normal_color;
  99. Color icon_focus_color;
  100. Color icon_hover_color;
  101. Color icon_pressed_color;
  102. Color icon_disabled_color;
  103. Color shadow_color;
  104. Color selection_color;
  105. Color disabled_border_color;
  106. Color disabled_bg_color;
  107. Color separator_color;
  108. Ref<StyleBoxFlat> base_style;
  109. Ref<StyleBoxEmpty> base_empty_style;
  110. Ref<StyleBoxFlat> button_style;
  111. Ref<StyleBoxFlat> button_style_disabled;
  112. Ref<StyleBoxFlat> button_style_focus;
  113. Ref<StyleBoxFlat> button_style_pressed;
  114. Ref<StyleBoxFlat> button_style_hover;
  115. Ref<StyleBoxFlat> popup_style;
  116. Ref<StyleBoxFlat> popup_border_style;
  117. Ref<StyleBoxFlat> window_style;
  118. Ref<StyleBoxFlat> dialog_style;
  119. Ref<StyleBoxFlat> panel_container_style;
  120. Ref<StyleBoxFlat> content_panel_style;
  121. Ref<StyleBoxFlat> tree_panel_style;
  122. Vector2 widget_margin;
  123. uint32_t hash();
  124. uint32_t hash_fonts();
  125. uint32_t hash_icons();
  126. };
  127. static Ref<EditorTheme> _create_base_theme(const Ref<EditorTheme> &p_old_theme = nullptr);
  128. static ThemeConfiguration _create_theme_config(const Ref<EditorTheme> &p_theme);
  129. static void _create_shared_styles(const Ref<EditorTheme> &p_theme, ThemeConfiguration &p_config);
  130. static void _populate_standard_styles(const Ref<EditorTheme> &p_theme, ThemeConfiguration &p_config);
  131. static void _populate_editor_styles(const Ref<EditorTheme> &p_theme, ThemeConfiguration &p_config);
  132. static void _generate_text_editor_defaults(ThemeConfiguration &p_config);
  133. static void _populate_text_editor_styles(const Ref<EditorTheme> &p_theme, ThemeConfiguration &p_config);
  134. static void _populate_visual_shader_styles(const Ref<EditorTheme> &p_theme, ThemeConfiguration &p_config);
  135. static void _reset_dirty_flag();
  136. public:
  137. static Ref<EditorTheme> generate_theme(const Ref<EditorTheme> &p_old_theme = nullptr);
  138. static bool is_generated_theme_outdated();
  139. static bool is_dark_theme();
  140. static void initialize();
  141. static void finalize();
  142. };
  143. #endif // EDITOR_THEME_MANAGER_H