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