theme.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*************************************************************************/
  2. /* theme.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  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 THEME_H
  31. #define THEME_H
  32. #include "core/io/resource.h"
  33. #include "core/io/resource_loader.h"
  34. #include "scene/resources/font.h"
  35. #include "scene/resources/style_box.h"
  36. #include "scene/resources/texture.h"
  37. class Theme : public Resource {
  38. GDCLASS(Theme, Resource);
  39. RES_BASE_EXTENSION("theme");
  40. void _emit_theme_changed();
  41. HashMap<StringName, HashMap<StringName, Ref<Texture2D>>> icon_map;
  42. HashMap<StringName, HashMap<StringName, Ref<StyleBox>>> style_map;
  43. HashMap<StringName, HashMap<StringName, Ref<Font>>> font_map;
  44. HashMap<StringName, HashMap<StringName, int>> font_size_map;
  45. HashMap<StringName, HashMap<StringName, Color>> color_map;
  46. HashMap<StringName, HashMap<StringName, int>> constant_map;
  47. Vector<String> _get_icon_list(const String &p_node_type) const;
  48. Vector<String> _get_icon_type_list() const;
  49. Vector<String> _get_stylebox_list(const String &p_node_type) const;
  50. Vector<String> _get_stylebox_type_list() const;
  51. Vector<String> _get_font_list(const String &p_node_type) const;
  52. Vector<String> _get_font_type_list() const;
  53. Vector<String> _get_font_size_list(const String &p_node_type) const;
  54. Vector<String> _get_color_list(const String &p_node_type) const;
  55. Vector<String> _get_color_type_list() const;
  56. Vector<String> _get_constant_list(const String &p_node_type) const;
  57. Vector<String> _get_constant_type_list() const;
  58. Vector<String> _get_type_list() const;
  59. protected:
  60. bool _set(const StringName &p_name, const Variant &p_value);
  61. bool _get(const StringName &p_name, Variant &r_ret) const;
  62. void _get_property_list(List<PropertyInfo> *p_list) const;
  63. static Ref<Theme> project_default_theme;
  64. static Ref<Theme> default_theme;
  65. static Ref<Texture2D> default_icon;
  66. static Ref<StyleBox> default_style;
  67. static Ref<Font> default_font;
  68. static int default_font_size;
  69. Ref<Font> default_theme_font;
  70. int default_theme_font_size = -1;
  71. static void _bind_methods();
  72. virtual void reset_state() override;
  73. public:
  74. static Ref<Theme> get_default();
  75. static void set_default(const Ref<Theme> &p_default);
  76. static Ref<Theme> get_project_default();
  77. static void set_project_default(const Ref<Theme> &p_project_default);
  78. static void set_default_icon(const Ref<Texture2D> &p_icon);
  79. static void set_default_style(const Ref<StyleBox> &p_style);
  80. static void set_default_font(const Ref<Font> &p_font);
  81. static void set_default_font_size(int p_font_size);
  82. void set_default_theme_font(const Ref<Font> &p_default_font);
  83. Ref<Font> get_default_theme_font() const;
  84. void set_default_theme_font_size(int p_font_size);
  85. int get_default_theme_font_size() const;
  86. void set_icon(const StringName &p_name, const StringName &p_node_type, const Ref<Texture2D> &p_icon);
  87. Ref<Texture2D> get_icon(const StringName &p_name, const StringName &p_node_type) const;
  88. bool has_icon(const StringName &p_name, const StringName &p_node_type) const;
  89. void clear_icon(const StringName &p_name, const StringName &p_node_type);
  90. void get_icon_list(StringName p_node_type, List<StringName> *p_list) const;
  91. void get_icon_type_list(List<StringName> *p_list) const;
  92. void set_stylebox(const StringName &p_name, const StringName &p_node_type, const Ref<StyleBox> &p_style);
  93. Ref<StyleBox> get_stylebox(const StringName &p_name, const StringName &p_node_type) const;
  94. bool has_stylebox(const StringName &p_name, const StringName &p_node_type) const;
  95. void clear_stylebox(const StringName &p_name, const StringName &p_node_type);
  96. void get_stylebox_list(StringName p_node_type, List<StringName> *p_list) const;
  97. void get_stylebox_type_list(List<StringName> *p_list) const;
  98. void set_font(const StringName &p_name, const StringName &p_node_type, const Ref<Font> &p_font);
  99. Ref<Font> get_font(const StringName &p_name, const StringName &p_node_type) const;
  100. bool has_font(const StringName &p_name, const StringName &p_node_type) const;
  101. void clear_font(const StringName &p_name, const StringName &p_node_type);
  102. void get_font_list(StringName p_node_type, List<StringName> *p_list) const;
  103. void get_font_type_list(List<StringName> *p_list) const;
  104. void set_font_size(const StringName &p_name, const StringName &p_node_type, int p_font_size);
  105. int get_font_size(const StringName &p_name, const StringName &p_node_type) const;
  106. bool has_font_size(const StringName &p_name, const StringName &p_node_type) const;
  107. void clear_font_size(const StringName &p_name, const StringName &p_node_type);
  108. void get_font_size_list(StringName p_node_type, List<StringName> *p_list) const;
  109. void set_color(const StringName &p_name, const StringName &p_node_type, const Color &p_color);
  110. Color get_color(const StringName &p_name, const StringName &p_node_type) const;
  111. bool has_color(const StringName &p_name, const StringName &p_node_type) const;
  112. void clear_color(const StringName &p_name, const StringName &p_node_type);
  113. void get_color_list(StringName p_node_type, List<StringName> *p_list) const;
  114. void get_color_type_list(List<StringName> *p_list) const;
  115. void set_constant(const StringName &p_name, const StringName &p_node_type, int p_constant);
  116. int get_constant(const StringName &p_name, const StringName &p_node_type) const;
  117. bool has_constant(const StringName &p_name, const StringName &p_node_type) const;
  118. void clear_constant(const StringName &p_name, const StringName &p_node_type);
  119. void get_constant_list(StringName p_node_type, List<StringName> *p_list) const;
  120. void get_constant_type_list(List<StringName> *p_list) const;
  121. void get_type_list(List<StringName> *p_list) const;
  122. void copy_default_theme();
  123. void copy_theme(const Ref<Theme> &p_other);
  124. void clear();
  125. Theme();
  126. ~Theme();
  127. };
  128. #endif