summaryrefslogtreecommitdiff
path: root/scene/main
diff options
context:
space:
mode:
authorAnsraer <jacky2611@gmail.com>2021-12-17 13:11:19 +0100
committerAnsraer <jacky2611@gmail.com>2021-12-17 19:19:41 +0100
commitc7a03412acd3338663281268ac38217e92df6a65 (patch)
tree5fd7647a627822eed96c2662c90cefadfa55ac55 /scene/main
parent58712e96aea12bda2d5111d96961f529d15a693c (diff)
add 2d scale factor property
Diffstat (limited to 'scene/main')
-rw-r--r--scene/main/window.cpp23
-rw-r--r--scene/main/window.h4
2 files changed, 24 insertions, 3 deletions
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;