diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2019-07-25 14:54:27 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-25 14:54:27 +0200 |
commit | 4c74f50d1adfea1ebba208b980fe85018a8bfa1c (patch) | |
tree | bc1303a2767d099eca9e39e6503d0c911026cb13 | |
parent | 27d1e63dd461d6a61c2ef4f784e14ad7b9dfdc24 (diff) | |
parent | 17901da1a8a3f8351524db9b415459c17a00c1eb (diff) |
Merge pull request #30351 from bojidar-bg/30288-override-global-theme
Keep track of default theme and project custom default theme seperatelly
-rw-r--r-- | scene/gui/control.cpp | 55 | ||||
-rw-r--r-- | scene/register_scene_types.cpp | 2 | ||||
-rw-r--r-- | scene/resources/theme.cpp | 30 | ||||
-rw-r--r-- | scene/resources/theme.h | 6 |
4 files changed, 81 insertions, 12 deletions
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 26be17f6c1..1d6f3dc782 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -850,6 +850,12 @@ Ref<Texture> Control::get_icon(const StringName &p_name, const StringName &p_typ theme_owner = NULL; } + if (Theme::get_project_default().is_valid()) { + if (Theme::get_project_default()->has_icon(p_name, type)) { + return Theme::get_project_default()->get_icon(p_name, type); + } + } + return Theme::get_default()->get_icon(p_name, type); } @@ -886,6 +892,12 @@ Ref<Shader> Control::get_shader(const StringName &p_name, const StringName &p_ty theme_owner = NULL; } + if (Theme::get_project_default().is_valid()) { + if (Theme::get_project_default()->has_shader(p_name, type)) { + return Theme::get_project_default()->get_shader(p_name, type); + } + } + return Theme::get_default()->get_shader(p_name, type); } @@ -925,6 +937,9 @@ Ref<StyleBox> Control::get_stylebox(const StringName &p_name, const StringName & } while (class_name != StringName()) { + if (Theme::get_project_default().is_valid() && Theme::get_project_default()->has_stylebox(p_name, type)) + return Theme::get_project_default()->get_stylebox(p_name, type); + if (Theme::get_default()->has_stylebox(p_name, class_name)) return Theme::get_default()->get_stylebox(p_name, class_name); @@ -1001,6 +1016,11 @@ Color Control::get_color(const StringName &p_name, const StringName &p_type) con theme_owner = NULL; } + if (Theme::get_project_default().is_valid()) { + if (Theme::get_project_default()->has_color(p_name, type)) { + return Theme::get_project_default()->get_color(p_name, type); + } + } return Theme::get_default()->get_color(p_name, type); } @@ -1036,6 +1056,11 @@ int Control::get_constant(const StringName &p_name, const StringName &p_type) co theme_owner = NULL; } + if (Theme::get_project_default().is_valid()) { + if (Theme::get_project_default()->has_constant(p_name, type)) { + return Theme::get_project_default()->get_constant(p_name, type); + } + } return Theme::get_default()->get_constant(p_name, type); } @@ -1106,6 +1131,11 @@ bool Control::has_icon(const StringName &p_name, const StringName &p_type) const theme_owner = NULL; } + if (Theme::get_project_default().is_valid()) { + if (Theme::get_project_default()->has_color(p_name, type)) { + return true; + } + } return Theme::get_default()->has_icon(p_name, type); } @@ -1140,6 +1170,11 @@ bool Control::has_shader(const StringName &p_name, const StringName &p_type) con theme_owner = NULL; } + if (Theme::get_project_default().is_valid()) { + if (Theme::get_project_default()->has_shader(p_name, type)) { + return true; + } + } return Theme::get_default()->has_shader(p_name, type); } bool Control::has_stylebox(const StringName &p_name, const StringName &p_type) const { @@ -1173,6 +1208,11 @@ bool Control::has_stylebox(const StringName &p_name, const StringName &p_type) c theme_owner = NULL; } + if (Theme::get_project_default().is_valid()) { + if (Theme::get_project_default()->has_stylebox(p_name, type)) { + return true; + } + } return Theme::get_default()->has_stylebox(p_name, type); } bool Control::has_font(const StringName &p_name, const StringName &p_type) const { @@ -1206,6 +1246,11 @@ bool Control::has_font(const StringName &p_name, const StringName &p_type) const theme_owner = NULL; } + if (Theme::get_project_default().is_valid()) { + if (Theme::get_project_default()->has_font(p_name, type)) { + return true; + } + } return Theme::get_default()->has_font(p_name, type); } @@ -1240,6 +1285,11 @@ bool Control::has_color(const StringName &p_name, const StringName &p_type) cons theme_owner = NULL; } + if (Theme::get_project_default().is_valid()) { + if (Theme::get_project_default()->has_color(p_name, type)) { + return true; + } + } return Theme::get_default()->has_color(p_name, type); } @@ -1274,6 +1324,11 @@ bool Control::has_constant(const StringName &p_name, const StringName &p_type) c theme_owner = NULL; } + if (Theme::get_project_default().is_valid()) { + if (Theme::get_project_default()->has_constant(p_name, type)) { + return true; + } + } return Theme::get_default()->has_constant(p_name, type); } diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index 245fe3856a..974c9771e0 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -752,7 +752,7 @@ void register_scene_types() { if (theme_path != String()) { Ref<Theme> theme = ResourceLoader::load(theme_path); if (theme.is_valid()) { - Theme::set_default(theme); + Theme::set_project_default(theme); if (font.is_valid()) { Theme::set_default_font(font); } diff --git a/scene/resources/theme.cpp b/scene/resources/theme.cpp index 69258bc834..ae18be1695 100644 --- a/scene/resources/theme.cpp +++ b/scene/resources/theme.cpp @@ -32,8 +32,6 @@ #include "core/os/file_access.h" #include "core/print_string.h" -Ref<Theme> Theme::default_theme; - void Theme::_emit_theme_changed() { emit_changed(); @@ -186,11 +184,6 @@ void Theme::_get_property_list(List<PropertyInfo> *p_list) const { } } -Ref<Theme> Theme::get_default() { - - return default_theme; -} - void Theme::set_default_theme_font(const Ref<Font> &p_default_font) { if (default_theme_font == p_default_font) @@ -215,14 +208,31 @@ Ref<Font> Theme::get_default_theme_font() const { return default_theme_font; } +Ref<Theme> Theme::project_default_theme; +Ref<Theme> Theme::default_theme; +Ref<Texture> Theme::default_icon; +Ref<StyleBox> Theme::default_style; +Ref<Font> Theme::default_font; + +Ref<Theme> Theme::get_default() { + + return default_theme; +} + void Theme::set_default(const Ref<Theme> &p_default) { default_theme = p_default; } -Ref<Texture> Theme::default_icon; -Ref<StyleBox> Theme::default_style; -Ref<Font> Theme::default_font; +Ref<Theme> Theme::get_project_default() { + + return project_default_theme; +} + +void Theme::set_project_default(const Ref<Theme> &p_project_default) { + + project_default_theme = p_project_default; +} void Theme::set_default_icon(const Ref<Texture> &p_icon) { diff --git a/scene/resources/theme.h b/scene/resources/theme.h index fb59073cbe..4c4f9b5aba 100644 --- a/scene/resources/theme.h +++ b/scene/resources/theme.h @@ -46,7 +46,6 @@ class Theme : public Resource { GDCLASS(Theme, Resource); RES_BASE_EXTENSION("theme"); - static Ref<Theme> default_theme; void _emit_theme_changed(); HashMap<StringName, HashMap<StringName, Ref<Texture> > > icon_map; @@ -61,6 +60,8 @@ protected: bool _get(const StringName &p_name, Variant &r_ret) const; void _get_property_list(List<PropertyInfo> *p_list) const; + static Ref<Theme> project_default_theme; + static Ref<Theme> default_theme; static Ref<Texture> default_icon; static Ref<StyleBox> default_style; static Ref<Font> default_font; @@ -137,6 +138,9 @@ public: static Ref<Theme> get_default(); static void set_default(const Ref<Theme> &p_default); + static Ref<Theme> get_project_default(); + static void set_project_default(const Ref<Theme> &p_default); + static void set_default_icon(const Ref<Texture> &p_icon); static void set_default_style(const Ref<StyleBox> &p_style); static void set_default_font(const Ref<Font> &p_font); |