theme.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*************************************************************************/
  2. /* theme.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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_loader.h"
  33. #include "core/resource.h"
  34. #include "scene/resources/font.h"
  35. #include "scene/resources/shader.h"
  36. #include "scene/resources/style_box.h"
  37. #include "scene/resources/texture.h"
  38. /**
  39. @author Juan Linietsky <reduzio@gmail.com>
  40. */
  41. class Theme : public Resource {
  42. GDCLASS(Theme, Resource);
  43. RES_BASE_EXTENSION("theme");
  44. static Ref<Theme> default_theme;
  45. void _emit_theme_changed();
  46. HashMap<StringName, HashMap<StringName, Ref<Texture> > > icon_map;
  47. HashMap<StringName, HashMap<StringName, Ref<StyleBox> > > style_map;
  48. HashMap<StringName, HashMap<StringName, Ref<Font> > > font_map;
  49. HashMap<StringName, HashMap<StringName, Ref<Shader> > > shader_map;
  50. HashMap<StringName, HashMap<StringName, Color> > color_map;
  51. HashMap<StringName, HashMap<StringName, int> > constant_map;
  52. protected:
  53. bool _set(const StringName &p_name, const Variant &p_value);
  54. bool _get(const StringName &p_name, Variant &r_ret) const;
  55. void _get_property_list(List<PropertyInfo> *p_list) const;
  56. static Ref<Texture> default_icon;
  57. static Ref<StyleBox> default_style;
  58. static Ref<Font> default_font;
  59. Ref<Font> default_theme_font;
  60. PoolVector<String> _get_icon_list(const String &p_type) const {
  61. PoolVector<String> ilret;
  62. List<StringName> il;
  63. get_icon_list(p_type, &il);
  64. for (List<StringName>::Element *E = il.front(); E; E = E->next()) {
  65. ilret.push_back(E->get());
  66. }
  67. return ilret;
  68. }
  69. PoolVector<String> _get_stylebox_list(const String &p_type) const {
  70. PoolVector<String> ilret;
  71. List<StringName> il;
  72. get_stylebox_list(p_type, &il);
  73. for (List<StringName>::Element *E = il.front(); E; E = E->next()) {
  74. ilret.push_back(E->get());
  75. }
  76. return ilret;
  77. }
  78. PoolVector<String> _get_stylebox_types(void) const {
  79. PoolVector<String> ilret;
  80. List<StringName> il;
  81. get_stylebox_types(&il);
  82. for (List<StringName>::Element *E = il.front(); E; E = E->next()) {
  83. ilret.push_back(E->get());
  84. }
  85. return ilret;
  86. }
  87. PoolVector<String> _get_font_list(const String &p_type) const {
  88. PoolVector<String> ilret;
  89. List<StringName> il;
  90. get_font_list(p_type, &il);
  91. for (List<StringName>::Element *E = il.front(); E; E = E->next()) {
  92. ilret.push_back(E->get());
  93. }
  94. return ilret;
  95. }
  96. PoolVector<String> _get_color_list(const String &p_type) const {
  97. PoolVector<String> ilret;
  98. List<StringName> il;
  99. get_color_list(p_type, &il);
  100. for (List<StringName>::Element *E = il.front(); E; E = E->next()) {
  101. ilret.push_back(E->get());
  102. }
  103. return ilret;
  104. }
  105. PoolVector<String> _get_constant_list(const String &p_type) const {
  106. PoolVector<String> ilret;
  107. List<StringName> il;
  108. get_constant_list(p_type, &il);
  109. for (List<StringName>::Element *E = il.front(); E; E = E->next()) {
  110. ilret.push_back(E->get());
  111. }
  112. return ilret;
  113. }
  114. PoolVector<String> _get_type_list(const String &p_type) const {
  115. PoolVector<String> ilret;
  116. List<StringName> il;
  117. get_type_list(&il);
  118. for (List<StringName>::Element *E = il.front(); E; E = E->next()) {
  119. ilret.push_back(E->get());
  120. }
  121. return ilret;
  122. }
  123. static void _bind_methods();
  124. public:
  125. static Ref<Theme> get_default();
  126. static void set_default(const Ref<Theme> &p_default);
  127. static void set_default_icon(const Ref<Texture> &p_icon);
  128. static void set_default_style(const Ref<StyleBox> &p_style);
  129. static void set_default_font(const Ref<Font> &p_font);
  130. void set_default_theme_font(const Ref<Font> &p_default_font);
  131. Ref<Font> get_default_theme_font() const;
  132. void set_icon(const StringName &p_name, const StringName &p_type, const Ref<Texture> &p_icon);
  133. Ref<Texture> get_icon(const StringName &p_name, const StringName &p_type) const;
  134. bool has_icon(const StringName &p_name, const StringName &p_type) const;
  135. void clear_icon(const StringName &p_name, const StringName &p_type);
  136. void get_icon_list(StringName p_type, List<StringName> *p_list) const;
  137. void set_shader(const StringName &p_name, const StringName &p_type, const Ref<Shader> &p_shader);
  138. Ref<Shader> get_shader(const StringName &p_name, const StringName &p_type) const;
  139. bool has_shader(const StringName &p_name, const StringName &p_type) const;
  140. void clear_shader(const StringName &p_name, const StringName &p_type);
  141. void get_shader_list(const StringName &p_type, List<StringName> *p_list) const;
  142. void set_stylebox(const StringName &p_name, const StringName &p_type, const Ref<StyleBox> &p_style);
  143. Ref<StyleBox> get_stylebox(const StringName &p_name, const StringName &p_type) const;
  144. bool has_stylebox(const StringName &p_name, const StringName &p_type) const;
  145. void clear_stylebox(const StringName &p_name, const StringName &p_type);
  146. void get_stylebox_list(StringName p_type, List<StringName> *p_list) const;
  147. void get_stylebox_types(List<StringName> *p_list) const;
  148. void set_font(const StringName &p_name, const StringName &p_type, const Ref<Font> &p_font);
  149. Ref<Font> get_font(const StringName &p_name, const StringName &p_type) const;
  150. bool has_font(const StringName &p_name, const StringName &p_type) const;
  151. void clear_font(const StringName &p_name, const StringName &p_type);
  152. void get_font_list(StringName p_type, List<StringName> *p_list) const;
  153. void set_color(const StringName &p_name, const StringName &p_type, const Color &p_color);
  154. Color get_color(const StringName &p_name, const StringName &p_type) const;
  155. bool has_color(const StringName &p_name, const StringName &p_type) const;
  156. void clear_color(const StringName &p_name, const StringName &p_type);
  157. void get_color_list(StringName p_type, List<StringName> *p_list) const;
  158. void set_constant(const StringName &p_name, const StringName &p_type, int p_constant);
  159. int get_constant(const StringName &p_name, const StringName &p_type) const;
  160. bool has_constant(const StringName &p_name, const StringName &p_type) const;
  161. void clear_constant(const StringName &p_name, const StringName &p_type);
  162. void get_constant_list(StringName p_type, List<StringName> *p_list) const;
  163. void get_type_list(List<StringName> *p_list) const;
  164. void copy_default_theme();
  165. void clear();
  166. Theme();
  167. ~Theme();
  168. };
  169. #endif