summaryrefslogtreecommitdiffstats
path: root/scene/resources/primitive_meshes.cpp
diff options
context:
space:
mode:
authorYuri Sizov <yuris@humnom.net>2023-09-06 16:11:05 +0200
committerYuri Sizov <yuris@humnom.net>2023-09-06 19:40:43 +0200
commit58126e479cd7341ec2ae306131e14868bcff06ca (patch)
treec0e965296b435f908a18401717b337fcbafc3e2f /scene/resources/primitive_meshes.cpp
parent8449592d92eaeef990f5502b419d491ee3eeb7a6 (diff)
downloadredot-engine-58126e479cd7341ec2ae306131e14868bcff06ca.tar.gz
Introduce the concept of global theme contexts
This commit adds the default theme context, which replaces the need to manually check the project and the default theme all the time; simplifies related code. It also adds framework for custom theme contexts, to be used by the editor. Custom contexts can be attached to any node, and not necessarily a GUI/Window node. Contexts do no break theme inheritance and only define which global themes a node uses as a fallback. Contexts propagate NOTIFICATION_THEME_CHANGED when one of their global themes changes. This ensures that global themes act just like themes assigned to individual nodes and can be previewed live in the editor.
Diffstat (limited to 'scene/resources/primitive_meshes.cpp')
-rw-r--r--scene/resources/primitive_meshes.cpp30
1 files changed, 11 insertions, 19 deletions
diff --git a/scene/resources/primitive_meshes.cpp b/scene/resources/primitive_meshes.cpp
index a64ae07f05..6d848f5494 100644
--- a/scene/resources/primitive_meshes.cpp
+++ b/scene/resources/primitive_meshes.cpp
@@ -3466,32 +3466,24 @@ Ref<Font> TextMesh::_get_font_or_default() const {
return font_override;
}
- // 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);
-
- for (const StringName &E : theme_types) {
- if (ThemeDB::get_singleton()->get_project_theme()->has_theme_item(Theme::DATA_TYPE_FONT, "font", E)) {
- return ThemeDB::get_singleton()->get_project_theme()->get_theme_item(Theme::DATA_TYPE_FONT, "font", E);
- }
+ StringName theme_name = "font";
+ List<StringName> theme_types;
+ ThemeDB::get_singleton()->get_native_type_dependencies(get_class_name(), &theme_types);
+
+ 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.
- {
- 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)) {
- return ThemeDB::get_singleton()->get_default_theme()->get_theme_item(Theme::DATA_TYPE_FONT, "font", E);
+ if (theme->has_font(theme_name, E)) {
+ return theme->get_font(theme_name, E);
}
}
}
- // If they don't exist, use any type to return the default/empty value.
- return ThemeDB::get_singleton()->get_default_theme()->get_theme_item(Theme::DATA_TYPE_FONT, "font", StringName());
+ return global_context->get_fallback_theme()->get_font(theme_name, StringName());
}
void TextMesh::set_font_size(int p_size) {