diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2022-12-21 18:27:17 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2022-12-21 18:27:17 +0100 |
commit | 8c703962674e2aaef6066a96a7c4666e1818ecf4 (patch) | |
tree | b7ba64817a9c898c004547fcdb22115f0e4fdd92 /scene | |
parent | 1df71f89a812db8666e6ea88a87e93ceedc69e94 (diff) | |
parent | 501c317ae13dba0f003e57b28c7243a4d86a3a03 (diff) |
Merge pull request #70215 from quentinguidee/refactor/get-owner-node-theme
ThemeOwner: Extract get_owner_node_theme
Diffstat (limited to 'scene')
-rw-r--r-- | scene/theme/theme_owner.cpp | 69 | ||||
-rw-r--r-- | scene/theme/theme_owner.h | 1 |
2 files changed, 20 insertions, 50 deletions
diff --git a/scene/theme/theme_owner.cpp b/scene/theme/theme_owner.cpp index e89aa1b28d..44e0c5d0c8 100644 --- a/scene/theme/theme_owner.cpp +++ b/scene/theme/theme_owner.cpp @@ -205,16 +205,7 @@ Variant ThemeOwner::get_theme_item_in_types(Theme::DataType p_data_type, const S while (owner_node) { // For each theme resource check the theme types provided and see if p_name exists with any of them. for (const StringName &E : p_theme_types) { - Ref<Theme> owner_theme; - - Control *owner_c = Object::cast_to<Control>(owner_node); - if (owner_c) { - owner_theme = owner_c->get_theme(); - } - Window *owner_w = Object::cast_to<Window>(owner_node); - if (owner_w) { - owner_theme = owner_w->get_theme(); - } + Ref<Theme> owner_theme = _get_owner_node_theme(owner_node); if (owner_theme.is_valid() && owner_theme->has_theme_item(p_data_type, p_name, E)) { return owner_theme->get_theme_item(p_data_type, p_name, E); @@ -254,16 +245,7 @@ bool ThemeOwner::has_theme_item_in_types(Theme::DataType p_data_type, const Stri while (owner_node) { // For each theme resource check the theme types provided and see if p_name exists with any of them. for (const StringName &E : p_theme_types) { - Ref<Theme> owner_theme; - - Control *owner_c = Object::cast_to<Control>(owner_node); - if (owner_c) { - owner_theme = owner_c->get_theme(); - } - Window *owner_w = Object::cast_to<Window>(owner_node); - if (owner_w) { - owner_theme = owner_w->get_theme(); - } + Ref<Theme> owner_theme = _get_owner_node_theme(owner_node); if (owner_theme.is_valid() && owner_theme->has_theme_item(p_data_type, p_name, E)) { return true; @@ -299,16 +281,7 @@ float ThemeOwner::get_theme_default_base_scale() { Node *owner_node = get_owner_node(); while (owner_node) { - Ref<Theme> owner_theme; - - Control *owner_c = Object::cast_to<Control>(owner_node); - if (owner_c) { - owner_theme = owner_c->get_theme(); - } - Window *owner_w = Object::cast_to<Window>(owner_node); - if (owner_w) { - owner_theme = owner_w->get_theme(); - } + Ref<Theme> owner_theme = _get_owner_node_theme(owner_node); if (owner_theme.is_valid() && owner_theme->has_default_base_scale()) { return owner_theme->get_default_base_scale(); @@ -338,16 +311,7 @@ Ref<Font> ThemeOwner::get_theme_default_font() { Node *owner_node = get_owner_node(); while (owner_node) { - Ref<Theme> owner_theme; - - Control *owner_c = Object::cast_to<Control>(owner_node); - if (owner_c) { - owner_theme = owner_c->get_theme(); - } - Window *owner_w = Object::cast_to<Window>(owner_node); - if (owner_w) { - owner_theme = owner_w->get_theme(); - } + Ref<Theme> owner_theme = _get_owner_node_theme(owner_node); if (owner_theme.is_valid() && owner_theme->has_default_font()) { return owner_theme->get_default_font(); @@ -377,16 +341,7 @@ int ThemeOwner::get_theme_default_font_size() { Node *owner_node = get_owner_node(); while (owner_node) { - Ref<Theme> owner_theme; - - Control *owner_c = Object::cast_to<Control>(owner_node); - if (owner_c) { - owner_theme = owner_c->get_theme(); - } - Window *owner_w = Object::cast_to<Window>(owner_node); - if (owner_w) { - owner_theme = owner_w->get_theme(); - } + Ref<Theme> owner_theme = _get_owner_node_theme(owner_node); if (owner_theme.is_valid() && owner_theme->has_default_font_size()) { return owner_theme->get_default_font_size(); @@ -408,3 +363,17 @@ int ThemeOwner::get_theme_default_font_size() { } return ThemeDB::get_singleton()->get_fallback_font_size(); } + +Ref<Theme> ThemeOwner::_get_owner_node_theme(Node *p_owner_node) const { + const Control *owner_c = Object::cast_to<Control>(p_owner_node); + if (owner_c) { + return owner_c->get_theme(); + } + + const Window *owner_w = Object::cast_to<Window>(p_owner_node); + if (owner_w) { + return owner_w->get_theme(); + } + + return Ref<Theme>(); +} diff --git a/scene/theme/theme_owner.h b/scene/theme/theme_owner.h index 59b72c1627..60d60f525c 100644 --- a/scene/theme/theme_owner.h +++ b/scene/theme/theme_owner.h @@ -43,6 +43,7 @@ class ThemeOwner : public Object { Window *owner_window = nullptr; Node *_get_next_owner_node(Node *p_from_node) const; + Ref<Theme> _get_owner_node_theme(Node *p_owner_node) const; public: // Theme owner node. |