diff options
Diffstat (limited to 'scene/resources/font.cpp')
-rw-r--r-- | scene/resources/font.cpp | 116 |
1 files changed, 44 insertions, 72 deletions
diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp index 9d546c90c7..c8a98a6831 100644 --- a/scene/resources/font.cpp +++ b/scene/resources/font.cpp @@ -2779,48 +2779,25 @@ Ref<Font> FontVariation::_get_base_font_or_default() const { return base_font; } - // Check the project-defined Theme resource. - if (ThemeDB::get_singleton()->get_project_theme().is_valid()) { - List<StringName> theme_types; - ThemeDB::get_singleton()->get_project_theme()->get_type_dependencies(get_class_name(), StringName(), &theme_types); + StringName theme_name = "font"; + List<StringName> theme_types; + ThemeDB::get_singleton()->get_native_type_dependencies(get_class_name(), &theme_types); - for (const StringName &E : theme_types) { - if (ThemeDB::get_singleton()->get_project_theme()->has_theme_item(Theme::DATA_TYPE_FONT, "font", E)) { - Ref<Font> f = ThemeDB::get_singleton()->get_project_theme()->get_theme_item(Theme::DATA_TYPE_FONT, "font", E); - if (f == this) { - continue; - } - if (f.is_valid()) { - theme_font = f; - theme_font->connect_changed(callable_mp(reinterpret_cast<Font *>(const_cast<FontVariation *>(this)), &Font::_invalidate_rids), CONNECT_REFERENCE_COUNTED); - } - return f; - } + ThemeContext *global_context = ThemeDB::get_singleton()->get_default_theme_context(); + for (const Ref<Theme> &theme : global_context->get_themes()) { + if (theme.is_null()) { + continue; } - } - - // Lastly, fall back on the items defined in the default Theme, if they exist. - if (ThemeDB::get_singleton()->get_default_theme().is_valid()) { - List<StringName> theme_types; - ThemeDB::get_singleton()->get_default_theme()->get_type_dependencies(get_class_name(), StringName(), &theme_types); for (const StringName &E : theme_types) { - if (ThemeDB::get_singleton()->get_default_theme()->has_theme_item(Theme::DATA_TYPE_FONT, "font", E)) { - Ref<Font> f = ThemeDB::get_singleton()->get_default_theme()->get_theme_item(Theme::DATA_TYPE_FONT, "font", E); - if (f == this) { - continue; - } - if (f.is_valid()) { - theme_font = f; - theme_font->connect_changed(callable_mp(reinterpret_cast<Font *>(const_cast<FontVariation *>(this)), &Font::_invalidate_rids), CONNECT_REFERENCE_COUNTED); - } - return f; + if (!theme->has_font(theme_name, E)) { + continue; } - } - // If they don't exist, use any type to return the default/empty value. - Ref<Font> f = ThemeDB::get_singleton()->get_default_theme()->get_theme_item(Theme::DATA_TYPE_FONT, "font", StringName()); - if (f != this) { + Ref<Font> f = theme->get_font(theme_name, E); + if (f == this) { + continue; + } if (f.is_valid()) { theme_font = f; theme_font->connect_changed(callable_mp(reinterpret_cast<Font *>(const_cast<FontVariation *>(this)), &Font::_invalidate_rids), CONNECT_REFERENCE_COUNTED); @@ -2829,6 +2806,15 @@ Ref<Font> FontVariation::_get_base_font_or_default() const { } } + Ref<Font> f = global_context->get_fallback_theme()->get_font(theme_name, StringName()); + if (f != this) { + if (f.is_valid()) { + theme_font = f; + theme_font->connect_changed(callable_mp(reinterpret_cast<Font *>(const_cast<FontVariation *>(this)), &Font::_invalidate_rids), CONNECT_REFERENCE_COUNTED); + } + return f; + } + return Ref<Font>(); } @@ -3131,48 +3117,25 @@ Ref<Font> SystemFont::_get_base_font_or_default() const { return base_font; } - // Check the project-defined Theme resource. - if (ThemeDB::get_singleton()->get_project_theme().is_valid()) { - List<StringName> theme_types; - ThemeDB::get_singleton()->get_project_theme()->get_type_dependencies(get_class_name(), StringName(), &theme_types); + StringName theme_name = "font"; + List<StringName> theme_types; + ThemeDB::get_singleton()->get_native_type_dependencies(get_class_name(), &theme_types); - for (const StringName &E : theme_types) { - if (ThemeDB::get_singleton()->get_project_theme()->has_theme_item(Theme::DATA_TYPE_FONT, "font", E)) { - Ref<Font> f = ThemeDB::get_singleton()->get_project_theme()->get_theme_item(Theme::DATA_TYPE_FONT, "font", E); - if (f == this) { - continue; - } - if (f.is_valid()) { - theme_font = f; - theme_font->connect_changed(callable_mp(reinterpret_cast<Font *>(const_cast<SystemFont *>(this)), &Font::_invalidate_rids), CONNECT_REFERENCE_COUNTED); - } - return f; - } + ThemeContext *global_context = ThemeDB::get_singleton()->get_default_theme_context(); + for (const Ref<Theme> &theme : global_context->get_themes()) { + if (theme.is_null()) { + continue; } - } - - // Lastly, fall back on the items defined in the default Theme, if they exist. - if (ThemeDB::get_singleton()->get_default_theme().is_valid()) { - List<StringName> theme_types; - ThemeDB::get_singleton()->get_default_theme()->get_type_dependencies(get_class_name(), StringName(), &theme_types); for (const StringName &E : theme_types) { - if (ThemeDB::get_singleton()->get_default_theme()->has_theme_item(Theme::DATA_TYPE_FONT, "font", E)) { - Ref<Font> f = ThemeDB::get_singleton()->get_default_theme()->get_theme_item(Theme::DATA_TYPE_FONT, "font", E); - if (f == this) { - continue; - } - if (f.is_valid()) { - theme_font = f; - theme_font->connect_changed(callable_mp(reinterpret_cast<Font *>(const_cast<SystemFont *>(this)), &Font::_invalidate_rids), CONNECT_REFERENCE_COUNTED); - } - return f; + if (!theme->has_font(theme_name, E)) { + continue; } - } - // If they don't exist, use any type to return the default/empty value. - Ref<Font> f = ThemeDB::get_singleton()->get_default_theme()->get_theme_item(Theme::DATA_TYPE_FONT, "font", StringName()); - if (f != this) { + Ref<Font> f = theme->get_font(theme_name, E); + if (f == this) { + continue; + } if (f.is_valid()) { theme_font = f; theme_font->connect_changed(callable_mp(reinterpret_cast<Font *>(const_cast<SystemFont *>(this)), &Font::_invalidate_rids), CONNECT_REFERENCE_COUNTED); @@ -3181,6 +3144,15 @@ Ref<Font> SystemFont::_get_base_font_or_default() const { } } + Ref<Font> f = global_context->get_fallback_theme()->get_font(theme_name, StringName()); + if (f != this) { + if (f.is_valid()) { + theme_font = f; + theme_font->connect_changed(callable_mp(reinterpret_cast<Font *>(const_cast<SystemFont *>(this)), &Font::_invalidate_rids), CONNECT_REFERENCE_COUNTED); + } + return f; + } + return Ref<Font>(); } |