theme.h
1 /*************************************************************************/
2 /* theme.h */
3 /*************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* http://www.godotengine.org */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2016 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 
32 #include "resource.h"
33 #include "scene/resources/font.h"
34 #include "scene/resources/style_box.h"
35 #include "scene/resources/texture.h"
36 #include "scene/resources/shader.h"
37 #include "io/resource_loader.h"
38 
42 class Theme : public Resource {
43 
44  OBJ_TYPE( Theme, Resource );
45  RES_BASE_EXTENSION("thm");
46 
47  static Ref<Theme> default_theme;
48 
50  HashMap<StringName,HashMap<StringName,Ref<StyleBox>,StringNameHasher >,StringNameHasher > style_map;
51  HashMap<StringName,HashMap<StringName,Ref<Font>,StringNameHasher >,StringNameHasher > font_map;
52  HashMap<StringName,HashMap<StringName,Ref<Shader>,StringNameHasher >, StringNameHasher > shader_map;
55 protected:
56  bool _set(const StringName& p_name, const Variant& p_value);
57  bool _get(const StringName& p_name,Variant &r_ret) const;
58  void _get_property_list( List<PropertyInfo> *p_list) const;
59 
60  static Ref<Texture> default_icon;
61  static Ref<StyleBox> default_style;
62  static Ref<Font> default_font;
63 
64  Ref<Font> default_theme_font;
65 
66  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; }
67  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; }
68  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; }
69  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; }
70  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; }
71  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; }
72 
73  static void _bind_methods();
74 public:
75 
76  static Ref<Theme> get_default();
77  static void set_default(const Ref<Theme>& p_default);
78 
79  static void set_default_icon( const Ref<Texture>& p_icon );
80  static void set_default_style( const Ref<StyleBox>& p_default_style);
81  static void set_default_font( const Ref<Font>& p_default_font );
82 
83  void set_default_theme_font( const Ref<Font>& p_default_font );
84  Ref<Font> get_default_theme_font() const;
85 
86  void set_icon(const StringName& p_name,const StringName& p_type,const Ref<Texture>& p_icon);
87  Ref<Texture> get_icon(const StringName& p_name,const StringName& p_type) const;
88  bool has_icon(const StringName& p_name,const StringName& p_type) const;
89  void clear_icon(const StringName& p_name,const StringName& p_type);
90  void get_icon_list(StringName p_type, List<StringName> *p_list) const;
91 
92  void set_shader(const StringName& p_name,const StringName& p_type,const Ref<Shader>& p_shader);
93  Ref<Shader> get_shader(const StringName& p_name,const StringName& p_type) const;
94  bool has_shader(const StringName& p_name,const StringName& p_type) const;
95  void clear_shader(const StringName& p_name,const StringName& p_type);
96  void get_shader_list(const StringName& p_name, List<StringName> *p_list) const;
97 
98  void set_stylebox(const StringName& p_name,const StringName& p_type,const Ref<StyleBox>& p_style);
99  Ref<StyleBox> get_stylebox(const StringName& p_name,const StringName& p_type) const;
100  bool has_stylebox(const StringName& p_name,const StringName& p_type) const;
101  void clear_stylebox(const StringName& p_name,const StringName& p_type);
102  void get_stylebox_list(StringName p_type, List<StringName> *p_list) const;
103 
104  void set_font(const StringName& p_name,const StringName& p_type,const Ref<Font>& p_font);
105  Ref<Font> get_font(const StringName& p_name,const StringName& p_type) const;
106  bool has_font(const StringName& p_name,const StringName& p_type) const;
107  void clear_font(const StringName& p_name,const StringName& p_type);
108  void get_font_list(StringName p_type, List<StringName> *p_list) const;
109 
110  void set_color(const StringName& p_name,const StringName& p_type,const Color& p_color);
111  Color get_color(const StringName& p_name,const StringName& p_type) const;
112  bool has_color(const StringName& p_name,const StringName& p_type) const;
113  void clear_color(const StringName& p_name,const StringName& p_type);
114  void get_color_list(StringName p_type, List<StringName> *p_list) const;
115 
116  void set_constant(const StringName& p_name,const StringName& p_type,int p_constant);
117  int get_constant(const StringName& p_name,const StringName& p_type) const;
118  bool has_constant(const StringName& p_name,const StringName& p_type) const;
119  void clear_constant(const StringName& p_name,const StringName& p_type);
120  void get_constant_list(StringName p_type, List<StringName> *p_list) const;
121 
122  void get_type_list(List<StringName> *p_list) const;
123 
124 
125  void copy_default_theme();
126 
127  Theme();
128  ~Theme();
129 
130 };
131 
132 
134 public:
135  virtual RES load(const String &p_path,const String& p_original_path="",Error *r_error=NULL);
136  virtual void get_recognized_extensions(List<String> *p_extensions) const;
137  virtual bool handles_type(const String& p_type) const;
138  virtual String get_resource_type(const String &p_path) const;
139 
140 };
141 
142 
143 
144 #endif
Definition: variant.h:74
Definition: string_db.h:150
Definition: theme.h:133
Definition: theme.h:42
_FORCE_INLINE_ const Element * front() const
Definition: list.h:189
Definition: color.h:37
Definition: string_db.h:48
Definition: hash_map.h:84
Definition: resource.h:89
Definition: resource_loader.h:57
Definition: dvector.h:43
Definition: ustring.h:64