diff options
-rw-r--r-- | doc/classes/Window.xml | 2 | ||||
-rw-r--r-- | main/main.cpp | 2 | ||||
-rw-r--r-- | scene/main/window.cpp | 23 | ||||
-rw-r--r-- | scene/main/window.h | 4 |
4 files changed, 28 insertions, 3 deletions
diff --git a/doc/classes/Window.xml b/doc/classes/Window.xml index c7ca6a20be..75161d3c5b 100644 --- a/doc/classes/Window.xml +++ b/doc/classes/Window.xml @@ -287,6 +287,8 @@ </member> <member name="content_scale_aspect" type="int" setter="set_content_scale_aspect" getter="get_content_scale_aspect" enum="Window.ContentScaleAspect" default="0"> </member> + <member name="content_scale_factor" type="float" setter="set_content_scale_factor" getter="get_content_scale_factor" default="1.0"> + </member> <member name="content_scale_mode" type="int" setter="set_content_scale_mode" getter="get_content_scale_mode" enum="Window.ContentScaleMode" default="0"> </member> <member name="content_scale_size" type="Vector2i" setter="set_content_scale_size" getter="get_content_scale_size" default="Vector2i(0, 0)"> diff --git a/main/main.cpp b/main/main.cpp index 21e5935adc..805c8c2c84 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -2321,6 +2321,7 @@ bool Main::start() { String stretch_aspect = GLOBAL_DEF_BASIC("display/window/stretch/aspect", "keep"); Size2i stretch_size = Size2i(GLOBAL_DEF_BASIC("display/window/size/width", 0), GLOBAL_DEF_BASIC("display/window/size/height", 0)); + real_t stretch_scale = GLOBAL_DEF_BASIC("display/window/stretch/scale", 1.0); Window::ContentScaleMode cs_sm = Window::CONTENT_SCALE_MODE_DISABLED; if (stretch_mode == "canvas_items") { @@ -2343,6 +2344,7 @@ bool Main::start() { sml->get_root()->set_content_scale_mode(cs_sm); sml->get_root()->set_content_scale_aspect(cs_aspect); sml->get_root()->set_content_scale_size(stretch_size); + sml->get_root()->set_content_scale_factor(stretch_scale); sml->set_auto_accept_quit(GLOBAL_DEF("application/config/auto_accept_quit", true)); sml->set_quit_on_go_back(GLOBAL_DEF("application/config/quit_on_go_back", true)); diff --git a/scene/main/window.cpp b/scene/main/window.cpp index 20f8b30dc6..7784fa1094 100644 --- a/scene/main/window.cpp +++ b/scene/main/window.cpp @@ -560,9 +560,12 @@ void Window::_update_viewport_size() { float font_oversampling = 1.0; if (content_scale_mode == CONTENT_SCALE_MODE_DISABLED || content_scale_size.x == 0 || content_scale_size.y == 0) { - stretch_transform = Transform2D(); + font_oversampling = content_scale_factor; final_size = size; + final_size_override = Size2(size) / content_scale_factor; + stretch_transform = Transform2D(); + stretch_transform.scale(Size2(content_scale_factor, content_scale_factor)); } else { //actual screen video mode Size2 video_mode = size; @@ -634,9 +637,9 @@ void Window::_update_viewport_size() { } break; case CONTENT_SCALE_MODE_CANVAS_ITEMS: { final_size = screen_size; - final_size_override = viewport_size; + final_size_override = viewport_size / content_scale_factor; attach_to_screen_rect = Rect2(margin, screen_size); - font_oversampling = screen_size.x / viewport_size.x; + font_oversampling = (screen_size.x / viewport_size.x) * content_scale_factor; Size2 scale = Vector2(screen_size) / Vector2(final_size_override); stretch_transform.scale(scale); @@ -825,6 +828,16 @@ Window::ContentScaleAspect Window::get_content_scale_aspect() const { return content_scale_aspect; } +void Window::set_content_scale_factor(real_t p_factor) { + ERR_FAIL_COND(p_factor <= 0); + content_scale_factor = p_factor; + _update_viewport_size(); +} + +real_t Window::get_content_scale_factor() const { + return content_scale_factor; +} + void Window::set_use_font_oversampling(bool p_oversampling) { if (is_inside_tree() && window_id != DisplayServer::MAIN_WINDOW_ID) { ERR_FAIL_MSG("Only the root window can set and use font oversampling."); @@ -1468,6 +1481,9 @@ void Window::_bind_methods() { ClassDB::bind_method(D_METHOD("set_content_scale_aspect", "aspect"), &Window::set_content_scale_aspect); ClassDB::bind_method(D_METHOD("get_content_scale_aspect"), &Window::get_content_scale_aspect); + ClassDB::bind_method(D_METHOD("set_content_scale_factor", "factor"), &Window::set_content_scale_factor); + ClassDB::bind_method(D_METHOD("get_content_scale_factor"), &Window::get_content_scale_factor); + ClassDB::bind_method(D_METHOD("set_use_font_oversampling", "enable"), &Window::set_use_font_oversampling); ClassDB::bind_method(D_METHOD("is_using_font_oversampling"), &Window::is_using_font_oversampling); @@ -1539,6 +1555,7 @@ void Window::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "content_scale_size"), "set_content_scale_size", "get_content_scale_size"); ADD_PROPERTY(PropertyInfo(Variant::INT, "content_scale_mode", PROPERTY_HINT_ENUM, "Disabled,Canvas Items,Viewport"), "set_content_scale_mode", "get_content_scale_mode"); ADD_PROPERTY(PropertyInfo(Variant::INT, "content_scale_aspect", PROPERTY_HINT_ENUM, "Ignore,Keep,Keep Width,Keep Height,Expand"), "set_content_scale_aspect", "get_content_scale_aspect"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "content_scale_factor"), "set_content_scale_factor", "get_content_scale_factor"); ADD_GROUP("Theme", "theme_"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "theme", PROPERTY_HINT_RESOURCE_TYPE, "Theme"), "set_theme", "get_theme"); diff --git a/scene/main/window.h b/scene/main/window.h index 0b1075ff76..f511f6df29 100644 --- a/scene/main/window.h +++ b/scene/main/window.h @@ -112,6 +112,7 @@ private: Size2i content_scale_size; ContentScaleMode content_scale_mode = CONTENT_SCALE_MODE_DISABLED; ContentScaleAspect content_scale_aspect = CONTENT_SCALE_ASPECT_IGNORE; + real_t content_scale_factor = 1.0; void _make_window(); void _clear_window(); @@ -230,6 +231,9 @@ public: void set_content_scale_aspect(ContentScaleAspect p_aspect); ContentScaleAspect get_content_scale_aspect() const; + void set_content_scale_factor(real_t p_factor); + real_t get_content_scale_factor() const; + void set_use_font_oversampling(bool p_oversampling); bool is_using_font_oversampling() const; |