Skip to content

Commit 0f7bf29

Browse files
committed
Merge pull request #111249 from HolonProduction/owner-node
Store `ThemeOwner` owner directly as `Node*`
2 parents 5626f0b + db9a0d8 commit 0f7bf29

File tree

2 files changed

+29
-55
lines changed

2 files changed

+29
-55
lines changed

scene/theme/theme_owner.cpp

Lines changed: 26 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -37,33 +37,8 @@
3737
// Theme owner node.
3838

3939
void ThemeOwner::set_owner_node(Node *p_node) {
40-
owner_control = nullptr;
41-
owner_window = nullptr;
42-
43-
Control *c = Object::cast_to<Control>(p_node);
44-
if (c) {
45-
owner_control = c;
46-
return;
47-
}
48-
49-
Window *w = Object::cast_to<Window>(p_node);
50-
if (w) {
51-
owner_window = w;
52-
return;
53-
}
54-
}
55-
56-
Node *ThemeOwner::get_owner_node() const {
57-
if (owner_control) {
58-
return owner_control;
59-
} else if (owner_window) {
60-
return owner_window;
61-
}
62-
return nullptr;
63-
}
64-
65-
bool ThemeOwner::has_owner_node() const {
66-
return bool(owner_control || owner_window);
40+
ERR_FAIL_COND(p_node && !Object::cast_to<Control>(p_node) && !Object::cast_to<Window>(p_node));
41+
owner_node = p_node;
6742
}
6843

6944
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
219194
// and eventually the chain must lead to native types).
220195

221196
// First, look through themes owned by nodes in the tree.
222-
Node *owner_node = get_owner_node();
197+
Node *current_owner = owner_node;
223198

224-
while (owner_node) {
225-
Ref<Theme> owner_theme = _get_owner_node_theme(owner_node);
199+
while (current_owner) {
200+
Ref<Theme> owner_theme = _get_owner_node_theme(current_owner);
226201
if (owner_theme.is_valid() && owner_theme->get_type_variation_base(type_variation) != StringName()) {
227202
owner_theme->get_type_dependencies(type_name, type_variation, r_result);
228203
return;
229204
}
230205

231-
owner_node = _get_next_owner_node(owner_node);
206+
current_owner = _get_next_owner_node(current_owner);
232207
}
233208

234209
// Second, check global contexts.
@@ -254,19 +229,19 @@ Variant ThemeOwner::get_theme_item_in_types(Theme::DataType p_data_type, const S
254229

255230
// First, look through each control or window node in the branch, until no valid parent can be found.
256231
// Only nodes with a theme resource attached are considered.
257-
Node *owner_node = get_owner_node();
232+
Node *current_owner = owner_node;
258233

259-
while (owner_node) {
234+
while (current_owner) {
260235
// For each theme resource check the theme types provided and see if p_name exists with any of them.
261236
for (const StringName &E : p_theme_types) {
262-
Ref<Theme> owner_theme = _get_owner_node_theme(owner_node);
237+
Ref<Theme> owner_theme = _get_owner_node_theme(current_owner);
263238

264239
if (owner_theme.is_valid() && owner_theme->has_theme_item(p_data_type, p_name, E)) {
265240
return owner_theme->get_theme_item(p_data_type, p_name, E);
266241
}
267242
}
268243

269-
owner_node = _get_next_owner_node(owner_node);
244+
current_owner = _get_next_owner_node(current_owner);
270245
}
271246

272247
// 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
290265

291266
// First, look through each control or window node in the branch, until no valid parent can be found.
292267
// Only nodes with a theme resource attached are considered.
293-
Node *owner_node = get_owner_node();
268+
Node *current_owner = owner_node;
294269

295-
while (owner_node) {
270+
while (current_owner) {
296271
// For each theme resource check the theme types provided and see if p_name exists with any of them.
297272
for (const StringName &E : p_theme_types) {
298-
Ref<Theme> owner_theme = _get_owner_node_theme(owner_node);
273+
Ref<Theme> owner_theme = _get_owner_node_theme(current_owner);
299274

300275
if (owner_theme.is_valid() && owner_theme->has_theme_item(p_data_type, p_name, E)) {
301276
return true;
302277
}
303278
}
304279

305-
owner_node = _get_next_owner_node(owner_node);
280+
current_owner = _get_next_owner_node(current_owner);
306281
}
307282

308283
// Second, check global themes from the appropriate context.
@@ -325,16 +300,16 @@ float ThemeOwner::get_theme_default_base_scale() {
325300
// First, look through each control or window node in the branch, until no valid parent can be found.
326301
// Only nodes with a theme resource attached are considered.
327302
// For each theme resource see if their assigned theme has the default value defined and valid.
328-
Node *owner_node = get_owner_node();
303+
Node *current_owner = owner_node;
329304

330-
while (owner_node) {
331-
Ref<Theme> owner_theme = _get_owner_node_theme(owner_node);
305+
while (current_owner) {
306+
Ref<Theme> owner_theme = _get_owner_node_theme(current_owner);
332307

333308
if (owner_theme.is_valid() && owner_theme->has_default_base_scale()) {
334309
return owner_theme->get_default_base_scale();
335310
}
336311

337-
owner_node = _get_next_owner_node(owner_node);
312+
current_owner = _get_next_owner_node(current_owner);
338313
}
339314

340315
// Second, check global themes from the appropriate context.
@@ -355,16 +330,16 @@ Ref<Font> ThemeOwner::get_theme_default_font() {
355330
// First, look through each control or window node in the branch, until no valid parent can be found.
356331
// Only nodes with a theme resource attached are considered.
357332
// For each theme resource see if their assigned theme has the default value defined and valid.
358-
Node *owner_node = get_owner_node();
333+
Node *current_owner = owner_node;
359334

360-
while (owner_node) {
361-
Ref<Theme> owner_theme = _get_owner_node_theme(owner_node);
335+
while (current_owner) {
336+
Ref<Theme> owner_theme = _get_owner_node_theme(current_owner);
362337

363338
if (owner_theme.is_valid() && owner_theme->has_default_font()) {
364339
return owner_theme->get_default_font();
365340
}
366341

367-
owner_node = _get_next_owner_node(owner_node);
342+
current_owner = _get_next_owner_node(current_owner);
368343
}
369344

370345
// Second, check global themes from the appropriate context.
@@ -385,16 +360,16 @@ int ThemeOwner::get_theme_default_font_size() {
385360
// First, look through each control or window node in the branch, until no valid parent can be found.
386361
// Only nodes with a theme resource attached are considered.
387362
// For each theme resource see if their assigned theme has the default value defined and valid.
388-
Node *owner_node = get_owner_node();
363+
Node *current_owner = owner_node;
389364

390-
while (owner_node) {
391-
Ref<Theme> owner_theme = _get_owner_node_theme(owner_node);
365+
while (current_owner) {
366+
Ref<Theme> owner_theme = _get_owner_node_theme(current_owner);
392367

393368
if (owner_theme.is_valid() && owner_theme->has_default_font_size()) {
394369
return owner_theme->get_default_font_size();
395370
}
396371

397-
owner_node = _get_next_owner_node(owner_node);
372+
current_owner = _get_next_owner_node(current_owner);
398373
}
399374

400375
// Second, check global themes from the appropriate context.

scene/theme/theme_owner.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ class ThemeOwner : public Object {
4343

4444
Node *holder = nullptr;
4545

46-
Control *owner_control = nullptr;
47-
Window *owner_window = nullptr;
46+
Node *owner_node = nullptr;
4847
ThemeContext *owner_context = nullptr;
4948

5049
void _owner_context_changed();
@@ -57,8 +56,8 @@ class ThemeOwner : public Object {
5756
// Theme owner node.
5857

5958
void set_owner_node(Node *p_node);
60-
Node *get_owner_node() const;
61-
bool has_owner_node() const;
59+
Node *get_owner_node() const { return owner_node; }
60+
bool has_owner_node() const { return owner_node != nullptr; }
6261

6362
void set_owner_context(ThemeContext *p_context, bool p_propagate = true);
6463

0 commit comments

Comments
 (0)