From 3401ca680303686057c3b77d4ca2bc9f64096a5b Mon Sep 17 00:00:00 2001 From: Yakov Borevich Date: Wed, 9 Aug 2017 10:53:38 +0300 Subject: [PATCH] [2.1] Add expand stretch/ascpect - no more black bars --- main/main.cpp | 4 +++- scene/main/scene_main_loop.cpp | 9 ++++----- scene/main/scene_main_loop.h | 1 + 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/main/main.cpp b/main/main.cpp index 457388b4146..78239e60e77 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -1223,6 +1223,8 @@ bool Main::start() { sml_aspect = SceneTree::STRETCH_ASPECT_KEEP_WIDTH; else if (stretch_aspect == "keep_height") sml_aspect = SceneTree::STRETCH_ASPECT_KEEP_HEIGHT; + else if (stretch_aspect == "expand") + sml_aspect = SceneTree::STRETCH_ASPECT_EXPAND; sml->set_screen_stretch(sml_sm, sml_aspect, stretch_size); @@ -1235,7 +1237,7 @@ bool Main::start() { GLOBAL_DEF("display/stretch_mode", "disabled"); Globals::get_singleton()->set_custom_property_info("display/stretch_mode", PropertyInfo(Variant::STRING, "display/stretch_mode", PROPERTY_HINT_ENUM, "disabled,2d,viewport")); GLOBAL_DEF("display/stretch_aspect", "ignore"); - Globals::get_singleton()->set_custom_property_info("display/stretch_aspect", PropertyInfo(Variant::STRING, "display/stretch_aspect", PROPERTY_HINT_ENUM, "ignore,keep,keep_width,keep_height")); + Globals::get_singleton()->set_custom_property_info("display/stretch_aspect", PropertyInfo(Variant::STRING, "display/stretch_aspect", PROPERTY_HINT_ENUM, "ignore,keep,keep_width,keep_height,expand")); sml->set_auto_accept_quit(GLOBAL_DEF("application/auto_accept_quit", true)); } diff --git a/scene/main/scene_main_loop.cpp b/scene/main/scene_main_loop.cpp index 3c14b48cab3..fbecf02a6bc 100644 --- a/scene/main/scene_main_loop.cpp +++ b/scene/main/scene_main_loop.cpp @@ -1027,7 +1027,7 @@ void SceneTree::_update_root_rect() { } else if (viewport_aspect < video_mode_aspect) { // screen ratio is smaller vertically - if (stretch_aspect == STRETCH_ASPECT_KEEP_HEIGHT) { + if (stretch_aspect == STRETCH_ASPECT_KEEP_HEIGHT || stretch_aspect == STRETCH_ASPECT_EXPAND) { //will stretch horizontally viewport_size.x = desired_res.y * video_mode_aspect; @@ -1042,7 +1042,7 @@ void SceneTree::_update_root_rect() { } } else { //screen ratio is smaller horizontally - if (stretch_aspect == STRETCH_ASPECT_KEEP_WIDTH) { + if (stretch_aspect == STRETCH_ASPECT_KEEP_WIDTH || stretch_aspect == STRETCH_ASPECT_EXPAND) { //will stretch horizontally viewport_size.x = desired_res.x; @@ -1063,12 +1063,11 @@ void SceneTree::_update_root_rect() { Size2 margin; Size2 offset; //black bars and margin - if (screen_size.x < video_mode.x) { + if (stretch_aspect != STRETCH_ASPECT_EXPAND && screen_size.x < video_mode.x) { margin.x = Math::round((video_mode.x - screen_size.x) / 2.0); VisualServer::get_singleton()->black_bars_set_margins(margin.x, 0, margin.x, 0); offset.x = Math::round(margin.x * viewport_size.y / screen_size.y); - } else if (screen_size.y < video_mode.y) { - + } else if (stretch_aspect != STRETCH_ASPECT_EXPAND && screen_size.y < video_mode.y) { margin.y = Math::round((video_mode.y - screen_size.y) / 2.0); VisualServer::get_singleton()->black_bars_set_margins(0, margin.y, 0, margin.y); offset.y = Math::round(margin.y * viewport_size.x / screen_size.x); diff --git a/scene/main/scene_main_loop.h b/scene/main/scene_main_loop.h index d7152deb08f..18f80f462f6 100644 --- a/scene/main/scene_main_loop.h +++ b/scene/main/scene_main_loop.h @@ -66,6 +66,7 @@ public: STRETCH_ASPECT_KEEP, STRETCH_ASPECT_KEEP_WIDTH, STRETCH_ASPECT_KEEP_HEIGHT, + STRETCH_ASPECT_EXPAND, }; private: