| 52 | // Default engine theme creation and configuration. |
| 53 | |
| 54 | void ThemeDB::initialize_theme() { |
| 55 | // Default theme-related project settings. |
| 56 | |
| 57 | // Allow creating the default theme at a different scale to suit higher/lower base resolutions. |
| 58 | float default_theme_scale = GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "gui/theme/default_theme_scale", PROPERTY_HINT_RANGE, "0.5,8,0.01", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED), 1.0); |
| 59 | |
| 60 | String project_theme_path = GLOBAL_DEF_RST_BASIC(PropertyInfo(Variant::STRING, "gui/theme/custom", PROPERTY_HINT_FILE, "*.tres,*.res,*.theme", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED), ""); |
| 61 | String project_font_path = GLOBAL_DEF_RST_BASIC(PropertyInfo(Variant::STRING, "gui/theme/custom_font", PROPERTY_HINT_FILE, "*.tres,*.res,*.otf,*.ttf,*.woff,*.woff2,*.fnt,*.font,*.pfb,*.pfm", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED), ""); |
| 62 | |
| 63 | TextServer::FontAntialiasing font_antialiasing = (TextServer::FontAntialiasing)(int)GLOBAL_GET("gui/theme/default_font_antialiasing"); |
| 64 | TextServer::Hinting font_hinting = (TextServer::Hinting)(int)GLOBAL_GET("gui/theme/default_font_hinting"); |
| 65 | TextServer::SubpixelPositioning font_subpixel_positioning = (TextServer::SubpixelPositioning)(int)GLOBAL_GET("gui/theme/default_font_subpixel_positioning"); |
| 66 | |
| 67 | const bool font_msdf = GLOBAL_GET("gui/theme/default_font_multichannel_signed_distance_field"); |
| 68 | const bool font_generate_mipmaps = GLOBAL_GET("gui/theme/default_font_generate_mipmaps"); |
| 69 | |
| 70 | // Attempt to load custom project theme and font. |
| 71 | |
| 72 | if (!project_theme_path.is_empty()) { |
| 73 | Ref<Theme> theme = ResourceLoader::load(project_theme_path); |
| 74 | if (theme.is_valid()) { |
| 75 | set_project_theme(theme); |
| 76 | } else { |
| 77 | ERR_PRINT("Error loading custom project theme '" + project_theme_path + "'"); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | Ref<Font> project_font; |
| 82 | if (!project_font_path.is_empty()) { |
| 83 | project_font = ResourceLoader::load(project_font_path); |
| 84 | if (project_font.is_valid()) { |
| 85 | set_fallback_font(project_font); |
| 86 | } else { |
| 87 | ERR_PRINT("Error loading custom project font '" + project_font_path + "'"); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | // Always generate the default theme to serve as a fallback for all required theme definitions. |
| 92 | |
| 93 | if (RenderingServer::get_singleton()) { |
| 94 | make_default_theme(default_theme_scale, project_font, font_subpixel_positioning, font_hinting, font_antialiasing, font_msdf, font_generate_mipmaps); |
| 95 | } |
| 96 | |
| 97 | _init_default_theme_context(); |
| 98 | } |
| 99 | |
| 100 | void ThemeDB::initialize_theme_noproject() { |
| 101 | if (RenderingServer::get_singleton()) { |