mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 07:53:26 +00:00
Merge pull request #111249 from HolonProduction/owner-node
Store `ThemeOwner` owner directly as `Node*`
This commit is contained in:
commit
0f7bf2913f
2 changed files with 29 additions and 55 deletions
|
@ -37,33 +37,8 @@
|
|||
// Theme owner node.
|
||||
|
||||
void ThemeOwner::set_owner_node(Node *p_node) {
|
||||
owner_control = nullptr;
|
||||
owner_window = nullptr;
|
||||
|
||||
Control *c = Object::cast_to<Control>(p_node);
|
||||
if (c) {
|
||||
owner_control = c;
|
||||
return;
|
||||
}
|
||||
|
||||
Window *w = Object::cast_to<Window>(p_node);
|
||||
if (w) {
|
||||
owner_window = w;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Node *ThemeOwner::get_owner_node() const {
|
||||
if (owner_control) {
|
||||
return owner_control;
|
||||
} else if (owner_window) {
|
||||
return owner_window;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool ThemeOwner::has_owner_node() const {
|
||||
return bool(owner_control || owner_window);
|
||||
ERR_FAIL_COND(p_node && !Object::cast_to<Control>(p_node) && !Object::cast_to<Window>(p_node));
|
||||
owner_node = p_node;
|
||||
}
|
||||
|
||||
void ThemeOwner::set_owner_context(ThemeContext *p_context, bool p_propagate) {
|
||||
|
@ -219,16 +194,16 @@ void ThemeOwner::get_theme_type_dependencies(const Node *p_for_node, const Strin
|
|||
// and eventually the chain must lead to native types).
|
||||
|
||||
// First, look through themes owned by nodes in the tree.
|
||||
Node *owner_node = get_owner_node();
|
||||
Node *current_owner = owner_node;
|
||||
|
||||
while (owner_node) {
|
||||
Ref<Theme> owner_theme = _get_owner_node_theme(owner_node);
|
||||
while (current_owner) {
|
||||
Ref<Theme> owner_theme = _get_owner_node_theme(current_owner);
|
||||
if (owner_theme.is_valid() && owner_theme->get_type_variation_base(type_variation) != StringName()) {
|
||||
owner_theme->get_type_dependencies(type_name, type_variation, r_result);
|
||||
return;
|
||||
}
|
||||
|
||||
owner_node = _get_next_owner_node(owner_node);
|
||||
current_owner = _get_next_owner_node(current_owner);
|
||||
}
|
||||
|
||||
// Second, check global contexts.
|
||||
|
@ -254,19 +229,19 @@ Variant ThemeOwner::get_theme_item_in_types(Theme::DataType p_data_type, const S
|
|||
|
||||
// First, look through each control or window node in the branch, until no valid parent can be found.
|
||||
// Only nodes with a theme resource attached are considered.
|
||||
Node *owner_node = get_owner_node();
|
||||
Node *current_owner = owner_node;
|
||||
|
||||
while (owner_node) {
|
||||
while (current_owner) {
|
||||
// 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 = _get_owner_node_theme(owner_node);
|
||||
Ref<Theme> owner_theme = _get_owner_node_theme(current_owner);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
owner_node = _get_next_owner_node(owner_node);
|
||||
current_owner = _get_next_owner_node(current_owner);
|
||||
}
|
||||
|
||||
// Second, check global themes from the appropriate context.
|
||||
|
@ -290,19 +265,19 @@ bool ThemeOwner::has_theme_item_in_types(Theme::DataType p_data_type, const Stri
|
|||
|
||||
// First, look through each control or window node in the branch, until no valid parent can be found.
|
||||
// Only nodes with a theme resource attached are considered.
|
||||
Node *owner_node = get_owner_node();
|
||||
Node *current_owner = owner_node;
|
||||
|
||||
while (owner_node) {
|
||||
while (current_owner) {
|
||||
// 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 = _get_owner_node_theme(owner_node);
|
||||
Ref<Theme> owner_theme = _get_owner_node_theme(current_owner);
|
||||
|
||||
if (owner_theme.is_valid() && owner_theme->has_theme_item(p_data_type, p_name, E)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
owner_node = _get_next_owner_node(owner_node);
|
||||
current_owner = _get_next_owner_node(current_owner);
|
||||
}
|
||||
|
||||
// Second, check global themes from the appropriate context.
|
||||
|
@ -325,16 +300,16 @@ float ThemeOwner::get_theme_default_base_scale() {
|
|||
// First, look through each control or window node in the branch, until no valid parent can be found.
|
||||
// Only nodes with a theme resource attached are considered.
|
||||
// For each theme resource see if their assigned theme has the default value defined and valid.
|
||||
Node *owner_node = get_owner_node();
|
||||
Node *current_owner = owner_node;
|
||||
|
||||
while (owner_node) {
|
||||
Ref<Theme> owner_theme = _get_owner_node_theme(owner_node);
|
||||
while (current_owner) {
|
||||
Ref<Theme> owner_theme = _get_owner_node_theme(current_owner);
|
||||
|
||||
if (owner_theme.is_valid() && owner_theme->has_default_base_scale()) {
|
||||
return owner_theme->get_default_base_scale();
|
||||
}
|
||||
|
||||
owner_node = _get_next_owner_node(owner_node);
|
||||
current_owner = _get_next_owner_node(current_owner);
|
||||
}
|
||||
|
||||
// Second, check global themes from the appropriate context.
|
||||
|
@ -355,16 +330,16 @@ Ref<Font> ThemeOwner::get_theme_default_font() {
|
|||
// First, look through each control or window node in the branch, until no valid parent can be found.
|
||||
// Only nodes with a theme resource attached are considered.
|
||||
// For each theme resource see if their assigned theme has the default value defined and valid.
|
||||
Node *owner_node = get_owner_node();
|
||||
Node *current_owner = owner_node;
|
||||
|
||||
while (owner_node) {
|
||||
Ref<Theme> owner_theme = _get_owner_node_theme(owner_node);
|
||||
while (current_owner) {
|
||||
Ref<Theme> owner_theme = _get_owner_node_theme(current_owner);
|
||||
|
||||
if (owner_theme.is_valid() && owner_theme->has_default_font()) {
|
||||
return owner_theme->get_default_font();
|
||||
}
|
||||
|
||||
owner_node = _get_next_owner_node(owner_node);
|
||||
current_owner = _get_next_owner_node(current_owner);
|
||||
}
|
||||
|
||||
// Second, check global themes from the appropriate context.
|
||||
|
@ -385,16 +360,16 @@ int ThemeOwner::get_theme_default_font_size() {
|
|||
// First, look through each control or window node in the branch, until no valid parent can be found.
|
||||
// Only nodes with a theme resource attached are considered.
|
||||
// For each theme resource see if their assigned theme has the default value defined and valid.
|
||||
Node *owner_node = get_owner_node();
|
||||
Node *current_owner = owner_node;
|
||||
|
||||
while (owner_node) {
|
||||
Ref<Theme> owner_theme = _get_owner_node_theme(owner_node);
|
||||
while (current_owner) {
|
||||
Ref<Theme> owner_theme = _get_owner_node_theme(current_owner);
|
||||
|
||||
if (owner_theme.is_valid() && owner_theme->has_default_font_size()) {
|
||||
return owner_theme->get_default_font_size();
|
||||
}
|
||||
|
||||
owner_node = _get_next_owner_node(owner_node);
|
||||
current_owner = _get_next_owner_node(current_owner);
|
||||
}
|
||||
|
||||
// Second, check global themes from the appropriate context.
|
||||
|
|
|
@ -43,8 +43,7 @@ class ThemeOwner : public Object {
|
|||
|
||||
Node *holder = nullptr;
|
||||
|
||||
Control *owner_control = nullptr;
|
||||
Window *owner_window = nullptr;
|
||||
Node *owner_node = nullptr;
|
||||
ThemeContext *owner_context = nullptr;
|
||||
|
||||
void _owner_context_changed();
|
||||
|
@ -57,8 +56,8 @@ public:
|
|||
// Theme owner node.
|
||||
|
||||
void set_owner_node(Node *p_node);
|
||||
Node *get_owner_node() const;
|
||||
bool has_owner_node() const;
|
||||
Node *get_owner_node() const { return owner_node; }
|
||||
bool has_owner_node() const { return owner_node != nullptr; }
|
||||
|
||||
void set_owner_context(ThemeContext *p_context, bool p_propagate = true);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue