diff --git a/modules/freetype/dynamic_font.cpp b/modules/freetype/dynamic_font.cpp index c7860ed..c2ac8c6 100644 --- a/modules/freetype/dynamic_font.cpp +++ b/modules/freetype/dynamic_font.cpp @@ -28,7 +28,6 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ - #include "dynamic_font.h" #include "core/os/file_access.h" @@ -1460,3 +1459,12 @@ String ResourceFormatLoaderDynamicFont::get_resource_type(const String &p_path) } return ""; } + +void ResourceFormatLoaderDynamicFont::_scene_tree_update_font_oversampling(float p_ratio) { + DynamicFontAtSize::font_oversampling = p_ratio; + DynamicFont::update_oversampling(); +} + +void ResourceFormatLoaderDynamicFont::_bind_methods() { + ClassDB::bind_method(D_METHOD("_scene_tree_update_font_oversampling"), &ResourceFormatLoaderDynamicFont::_scene_tree_update_font_oversampling); +} \ No newline at end of file diff --git a/modules/freetype/dynamic_font.h b/modules/freetype/dynamic_font.h index 0f96ac1..a8dd8c1 100644 --- a/modules/freetype/dynamic_font.h +++ b/modules/freetype/dynamic_font.h @@ -30,10 +30,10 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ +#include "core/containers/pair.h" #include "core/io/resource_loader.h" #include "core/os/mutex.h" #include "core/os/thread_safe.h" -#include "core/containers/pair.h" #include "scene/resources/font/font.h" #include "scene/resources/texture.h" @@ -387,11 +387,18 @@ VARIANT_ENUM_CAST(DynamicFont::SpacingType); ///////////// class ResourceFormatLoaderDynamicFont : public ResourceFormatLoader { + GDCLASS(ResourceFormatLoaderDynamicFont, ResourceFormatLoader); + public: virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL, bool p_no_subresource_cache = false); virtual void get_recognized_extensions(List *p_extensions) const; virtual bool handles_type(const String &p_type) const; virtual String get_resource_type(const String &p_path) const; + + void _scene_tree_update_font_oversampling(float p_ratio); + +protected: + static void _bind_methods(); }; #endif // DYNAMIC_FONT_H diff --git a/modules/freetype/register_types.cpp b/modules/freetype/register_types.cpp index bc9acd8..7ac141a 100644 --- a/modules/freetype/register_types.cpp +++ b/modules/freetype/register_types.cpp @@ -31,6 +31,7 @@ #include "register_types.h" #include "dynamic_font.h" +#include "scene/main/scene_tree.h" static Ref resource_loader_dynamic_font; @@ -46,6 +47,12 @@ void register_freetype_types(ModuleRegistrationLevel p_level) { DynamicFont::initialize_dynamic_fonts(); } + + if (p_level == MODULE_REGISTRATION_LEVEL_FINALIZE) { + if (SceneTree::get_singleton()) { + SceneTree::get_singleton()->connect("update_font_oversampling_request", resource_loader_dynamic_font.ptr(), "_scene_tree_update_font_oversampling"); + } + } } void unregister_freetype_types(ModuleRegistrationLevel p_level) { diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index 7e3a265..d773710 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -55,12 +55,6 @@ #include "servers/physics_2d_server.h" #include "viewport.h" -#include "modules/modules_enabled.gen.h" // For freetype. - -#ifdef MODULE_FREETYPE_ENABLED -#include "modules/freetype/dynamic_font.h" -#endif - #include #include @@ -597,12 +591,9 @@ void SceneTree::iteration_end() { } void SceneTree::_update_font_oversampling(float p_ratio) { -#ifdef MODULE_FREETYPE_ENABLED if (use_font_oversampling) { - DynamicFontAtSize::font_oversampling = p_ratio; - DynamicFont::update_oversampling(); + emit_signal("update_font_oversampling_request", p_ratio); } -#endif // MODULE_FREETYPE_ENABLED } bool SceneTree::idle(float p_time) { @@ -1860,6 +1851,7 @@ void SceneTree::_bind_methods() { ADD_SIGNAL(MethodInfo("connected_to_server")); ADD_SIGNAL(MethodInfo("connection_failed")); ADD_SIGNAL(MethodInfo("server_disconnected")); + ADD_SIGNAL(MethodInfo("update_font_oversampling_request", PropertyInfo(Variant::REAL, "ratio"))); BIND_ENUM_CONSTANT(GROUP_CALL_DEFAULT); BIND_ENUM_CONSTANT(GROUP_CALL_REVERSE);