theme.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*************************************************************************/
  2. /* theme.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #ifndef THEME_H
  30. #define THEME_H
  31. #include "resource.h"
  32. #include "scene/resources/font.h"
  33. #include "scene/resources/style_box.h"
  34. #include "scene/resources/texture.h"
  35. #include "io/resource_loader.h"
  36. /**
  37. @author Juan Linietsky <[email protected]>
  38. */
  39. class Theme : public Resource {
  40. OBJ_TYPE( Theme, Resource );
  41. RES_BASE_EXTENSION("thm");
  42. static Ref<Theme> default_theme;
  43. HashMap<StringName,HashMap<StringName,Ref<Texture>,StringNameHasher >, StringNameHasher > icon_map;
  44. HashMap<StringName,HashMap<StringName,Ref<StyleBox>,StringNameHasher >,StringNameHasher > style_map;
  45. HashMap<StringName,HashMap<StringName,Ref<Font>,StringNameHasher >,StringNameHasher > font_map;
  46. HashMap<StringName,HashMap<StringName,Color,StringNameHasher >,StringNameHasher > color_map;
  47. HashMap<StringName,HashMap<StringName,int,StringNameHasher>,StringNameHasher > constant_map;
  48. protected:
  49. bool _set(const StringName& p_name, const Variant& p_value);
  50. bool _get(const StringName& p_name,Variant &r_ret) const;
  51. void _get_property_list( List<PropertyInfo> *p_list) const;
  52. static Ref<Texture> default_icon;
  53. static Ref<StyleBox> default_style;
  54. static Ref<Font> default_font;
  55. Ref<Font> default_theme_font;
  56. DVector<String> _get_icon_list(const String& p_type) const { DVector<String> ilret; List<StringName> il; get_icon_list(p_type,&il); for(List<StringName>::Element *E=il.front();E;E=E->next()) { ilret.push_back(E->get()); } return ilret; }
  57. DVector<String> _get_stylebox_list(const String& p_type) const { DVector<String> ilret; List<StringName> il; get_stylebox_list(p_type,&il); for(List<StringName>::Element *E=il.front();E;E=E->next()) { ilret.push_back(E->get()); } return ilret; }
  58. DVector<String> _get_font_list(const String& p_type) const { DVector<String> ilret; List<StringName> il; get_font_list(p_type,&il); for(List<StringName>::Element *E=il.front();E;E=E->next()) { ilret.push_back(E->get()); } return ilret; }
  59. DVector<String> _get_color_list(const String& p_type) const { DVector<String> ilret; List<StringName> il; get_color_list(p_type,&il); for(List<StringName>::Element *E=il.front();E;E=E->next()) { ilret.push_back(E->get()); } return ilret; }
  60. DVector<String> _get_constant_list(const String& p_type) const { DVector<String> ilret; List<StringName> il; get_constant_list(p_type,&il); for(List<StringName>::Element *E=il.front();E;E=E->next()) { ilret.push_back(E->get()); } return ilret; }
  61. DVector<String> _get_type_list(const String& p_type) const { DVector<String> ilret; List<StringName> il; get_type_list(&il); for(List<StringName>::Element *E=il.front();E;E=E->next()) { ilret.push_back(E->get()); } return ilret; }
  62. static void _bind_methods();
  63. public:
  64. static Ref<Theme> get_default();
  65. static void set_default(const Ref<Theme>& p_default);
  66. static void set_default_icon( const Ref<Texture>& p_icon );
  67. static void set_default_style( const Ref<StyleBox>& p_default_style);
  68. static void set_default_font( const Ref<Font>& p_default_font );
  69. void set_default_theme_font( const Ref<Font>& p_default_font );
  70. Ref<Font> get_default_theme_font() const;
  71. void set_icon(const StringName& p_name,const StringName& p_type,const Ref<Texture>& p_icon);
  72. Ref<Texture> get_icon(const StringName& p_name,const StringName& p_type) const;
  73. bool has_icon(const StringName& p_name,const StringName& p_type) const;
  74. void clear_icon(const StringName& p_name,const StringName& p_type);
  75. void get_icon_list(StringName p_type, List<StringName> *p_list) const;
  76. void set_stylebox(const StringName& p_name,const StringName& p_type,const Ref<StyleBox>& p_style);
  77. Ref<StyleBox> get_stylebox(const StringName& p_name,const StringName& p_type) const;
  78. bool has_stylebox(const StringName& p_name,const StringName& p_type) const;
  79. void clear_stylebox(const StringName& p_name,const StringName& p_type);
  80. void get_stylebox_list(StringName p_type, List<StringName> *p_list) const;
  81. void set_font(const StringName& p_name,const StringName& p_type,const Ref<Font>& p_font);
  82. Ref<Font> get_font(const StringName& p_name,const StringName& p_type) const;
  83. bool has_font(const StringName& p_name,const StringName& p_type) const;
  84. void clear_font(const StringName& p_name,const StringName& p_type);
  85. void get_font_list(StringName p_type, List<StringName> *p_list) const;
  86. void set_color(const StringName& p_name,const StringName& p_type,const Color& p_color);
  87. Color get_color(const StringName& p_name,const StringName& p_type) const;
  88. bool has_color(const StringName& p_name,const StringName& p_type) const;
  89. void clear_color(const StringName& p_name,const StringName& p_type);
  90. void get_color_list(StringName p_type, List<StringName> *p_list) const;
  91. void set_constant(const StringName& p_name,const StringName& p_type,int p_constant);
  92. int get_constant(const StringName& p_name,const StringName& p_type) const;
  93. bool has_constant(const StringName& p_name,const StringName& p_type) const;
  94. void clear_constant(const StringName& p_name,const StringName& p_type);
  95. void get_constant_list(StringName p_type, List<StringName> *p_list) const;
  96. void get_type_list(List<StringName> *p_list) const;
  97. void copy_default_theme();
  98. Theme();
  99. ~Theme();
  100. };
  101. class ResourceFormatLoaderTheme : public ResourceFormatLoader {
  102. public:
  103. virtual RES load(const String &p_path,const String& p_original_path="");
  104. virtual void get_recognized_extensions(List<String> *p_extensions) const;
  105. virtual bool handles_type(const String& p_type) const;
  106. virtual String get_resource_type(const String &p_path) const;
  107. };
  108. #endif