From ac7e9479ce7f622af02985960b824ff0b0e7be8f Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Thu, 2 Jul 2020 17:15:11 -0300 Subject: [PATCH] Fix content scale mode, closes #37941 --- main/main.cpp | 10 +++++----- scene/gui/control.cpp | 10 ++++++++++ scene/main/window.cpp | 19 +++++++++---------- scene/main/window.h | 4 ++-- 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/main/main.cpp b/main/main.cpp index 76175780a36..96b71c16631 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -1895,10 +1895,10 @@ bool Main::start() { Size2i stretch_size = Size2(GLOBAL_DEF("display/window/size/width", 0), GLOBAL_DEF("display/window/size/height", 0)); Window::ContentScaleMode cs_sm = Window::CONTENT_SCALE_MODE_DISABLED; - if (stretch_mode == "objects") { - cs_sm = Window::CONTENT_SCALE_MODE_OBJECTS; - } else if (stretch_mode == "pixels") { - cs_sm = Window::CONTENT_SCALE_MODE_PIXELS; + if (stretch_mode == "canvas_items") { + cs_sm = Window::CONTENT_SCALE_MODE_CANVAS_ITEMS; + } else if (stretch_mode == "viewport") { + cs_sm = Window::CONTENT_SCALE_MODE_VIEWPORT; } Window::ContentScaleAspect cs_aspect = Window::CONTENT_SCALE_ASPECT_IGNORE; @@ -1954,7 +1954,7 @@ bool Main::start() { } else { GLOBAL_DEF("display/window/stretch/mode", "disabled"); - ProjectSettings::get_singleton()->set_custom_property_info("display/window/stretch/mode", PropertyInfo(Variant::STRING, "display/window/stretch/mode", PROPERTY_HINT_ENUM, "disabled,2d,viewport")); + ProjectSettings::get_singleton()->set_custom_property_info("display/window/stretch/mode", PropertyInfo(Variant::STRING, "display/window/stretch/mode", PROPERTY_HINT_ENUM, "disabled,canvas_items,viewport")); GLOBAL_DEF("display/window/stretch/aspect", "ignore"); ProjectSettings::get_singleton()->set_custom_property_info("display/window/stretch/aspect", PropertyInfo(Variant::STRING, "display/window/stretch/aspect", PROPERTY_HINT_ENUM, "ignore,keep,keep_width,keep_height,expand")); GLOBAL_DEF("display/window/stretch/shrink", 1.0); diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 97daeceda91..2cdee4641e4 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -1173,7 +1173,17 @@ Rect2 Control::get_parent_anchorable_rect() const { if (data.parent_canvas_item) { parent_rect = data.parent_canvas_item->get_anchorable_rect(); } else { +#ifdef TOOLS_ENABLED + Node *edited_root = get_tree()->get_edited_scene_root(); + if (edited_root && (this == edited_root || edited_root->is_a_parent_of(this))) { + parent_rect.size = Size2(ProjectSettings::get_singleton()->get("display/window/size/width"), ProjectSettings::get_singleton()->get("display/window/size/height")); + } else { + parent_rect = get_viewport()->get_visible_rect(); + } + +#else parent_rect = get_viewport()->get_visible_rect(); +#endif } return parent_rect; diff --git a/scene/main/window.cpp b/scene/main/window.cpp index 0463615d4d7..c9d072c6d7b 100644 --- a/scene/main/window.cpp +++ b/scene/main/window.cpp @@ -624,26 +624,25 @@ void Window::_update_viewport_size() { // Already handled above //_update_font_oversampling(1.0); } break; - case CONTENT_SCALE_MODE_OBJECTS: { + case CONTENT_SCALE_MODE_CANVAS_ITEMS: { final_size = screen_size; final_size_override = viewport_size; attach_to_screen_rect = Rect2(margin, screen_size); font_oversampling = screen_size.x / viewport_size.x; + + Size2 scale = Vector2(screen_size) / Vector2(final_size_override); + stretch_transform.scale(scale); + } break; - case CONTENT_SCALE_MODE_PIXELS: { + case CONTENT_SCALE_MODE_VIEWPORT: { final_size = viewport_size; attach_to_screen_rect = Rect2(margin, screen_size); } break; } - - Size2 scale = size / (Vector2(final_size) + margin * 2); - stretch_transform.scale(scale); - stretch_transform.elements[2] = margin * scale; } bool allocate = is_inside_tree() && visible && (window_id != DisplayServer::INVALID_WINDOW_ID || embedder != nullptr); - _set_size(final_size, final_size_override, attach_to_screen_rect, stretch_transform, allocate); if (window_id != DisplayServer::INVALID_WINDOW_ID) { @@ -1372,7 +1371,7 @@ void Window::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "max_size"), "set_max_size", "get_max_size"); ADD_GROUP("Content Scale", "content_scale_"); 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,Object,Pixels"), "set_content_scale_mode", "get_content_scale_mode"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "content_scale_mode", PROPERTY_HINT_ENUM, "Disabled,CanvasItems,Viewport"), "set_content_scale_mode", "get_content_scale_mode"); ADD_PROPERTY(PropertyInfo(Variant::INT, "content_scale_aspect", PROPERTY_HINT_ENUM, "Ignore,Keep,KeepWidth,KeepHeight,Expand"), "set_content_scale_aspect", "get_content_scale_aspect"); ADD_GROUP("Theme", ""); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "theme", PROPERTY_HINT_RESOURCE_TYPE, "Theme"), "set_theme", "get_theme"); @@ -1403,8 +1402,8 @@ void Window::_bind_methods() { BIND_ENUM_CONSTANT(FLAG_MAX); BIND_ENUM_CONSTANT(CONTENT_SCALE_MODE_DISABLED); - BIND_ENUM_CONSTANT(CONTENT_SCALE_MODE_OBJECTS); - BIND_ENUM_CONSTANT(CONTENT_SCALE_MODE_PIXELS); + BIND_ENUM_CONSTANT(CONTENT_SCALE_MODE_CANVAS_ITEMS); + BIND_ENUM_CONSTANT(CONTENT_SCALE_MODE_VIEWPORT); BIND_ENUM_CONSTANT(CONTENT_SCALE_ASPECT_IGNORE); BIND_ENUM_CONSTANT(CONTENT_SCALE_ASPECT_KEEP); diff --git a/scene/main/window.h b/scene/main/window.h index 5fd59e06f51..c8c02b89843 100644 --- a/scene/main/window.h +++ b/scene/main/window.h @@ -57,8 +57,8 @@ public: enum ContentScaleMode { CONTENT_SCALE_MODE_DISABLED, - CONTENT_SCALE_MODE_OBJECTS, - CONTENT_SCALE_MODE_PIXELS, + CONTENT_SCALE_MODE_CANVAS_ITEMS, + CONTENT_SCALE_MODE_VIEWPORT, }; enum ContentScaleAspect {