frontend: Added Hybrid Screen screen layout option (#4542) (#6600)

Signed-off-by: elim <e_sliwka@tuta.io>
This commit is contained in:
esliwka 2023-06-29 00:42:57 +02:00 committed by GitHub
parent 2d6aca4563
commit 0d516f6da5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 124 additions and 0 deletions

View file

@ -299,6 +299,80 @@ FramebufferLayout LargeFrameLayout(u32 width, u32 height, bool swapped, bool upr
return res;
}
FramebufferLayout HybridScreenLayout(u32 width, u32 height, bool swapped, bool upright) {
ASSERT(width > 0);
ASSERT(height > 0);
FramebufferLayout res{width, height, true, true, {}, {}, !upright, true, {}};
// Split the window into two parts. Give 2.25x width to the main screen,
// and make a bar on the right side with 1x width top screen and 1.25x width bottom screen
// To do that, find the total emulation box and maximize that based on window size
const float window_aspect_ratio = static_cast<float>(height) / width;
const float scale_factor = 2.25f;
float main_screen_aspect_ratio = TOP_SCREEN_ASPECT_RATIO;
float hybrid_area_aspect_ratio = 27.f / 65;
float top_screen_aspect_ratio = TOP_SCREEN_ASPECT_RATIO;
float bot_screen_aspect_ratio = BOT_SCREEN_ASPECT_RATIO;
if (swapped) {
main_screen_aspect_ratio = BOT_SCREEN_ASPECT_RATIO;
hybrid_area_aspect_ratio =
Core::kScreenBottomHeight * scale_factor /
(Core::kScreenBottomWidth * scale_factor + Core::kScreenTopWidth);
}
if (upright) {
hybrid_area_aspect_ratio = 1.f / hybrid_area_aspect_ratio;
main_screen_aspect_ratio = 1.f / main_screen_aspect_ratio;
top_screen_aspect_ratio = TOP_SCREEN_UPRIGHT_ASPECT_RATIO;
bot_screen_aspect_ratio = BOT_SCREEN_UPRIGHT_ASPECT_RATIO;
}
Common::Rectangle<u32> screen_window_area{0, 0, width, height};
Common::Rectangle<u32> total_rect = maxRectangle(screen_window_area, hybrid_area_aspect_ratio);
Common::Rectangle<u32> large_main_screen = maxRectangle(total_rect, main_screen_aspect_ratio);
Common::Rectangle<u32> side_rect = total_rect.Scale(1.f / scale_factor);
Common::Rectangle<u32> small_top_screen = maxRectangle(side_rect, top_screen_aspect_ratio);
Common::Rectangle<u32> small_bottom_screen = maxRectangle(side_rect, bot_screen_aspect_ratio);
if (window_aspect_ratio < hybrid_area_aspect_ratio) {
large_main_screen = large_main_screen.TranslateX((width - total_rect.GetWidth()) / 2);
} else {
large_main_screen = large_main_screen.TranslateY((height - total_rect.GetHeight()) / 2);
}
// Scale the bottom screen so it's width is the same as top screen
small_bottom_screen = small_bottom_screen.Scale(1.25f);
if (upright) {
large_main_screen = large_main_screen.TranslateY(small_bottom_screen.GetHeight());
// Shift small bottom screen to upper right corner
small_bottom_screen =
small_bottom_screen.TranslateX(large_main_screen.right - small_bottom_screen.GetWidth())
.TranslateY(large_main_screen.top - small_bottom_screen.GetHeight());
// Shift small top screen to upper left corner
small_top_screen = small_top_screen.TranslateX(large_main_screen.left)
.TranslateY(large_main_screen.top - small_bottom_screen.GetHeight());
} else {
// Shift the small bottom screen to the bottom right corner
small_bottom_screen =
small_bottom_screen.TranslateX(large_main_screen.right)
.TranslateY(large_main_screen.GetHeight() + large_main_screen.top -
small_bottom_screen.GetHeight());
// Shift small top screen to upper right corner
small_top_screen =
small_top_screen.TranslateX(large_main_screen.right).TranslateY(large_main_screen.top);
}
res.top_screen = small_top_screen;
res.additional_screen = swapped ? small_bottom_screen : large_main_screen;
res.bottom_screen = swapped ? large_main_screen : small_bottom_screen;
return res;
}
FramebufferLayout SideFrameLayout(u32 width, u32 height, bool swapped, bool upright) {
ASSERT(width > 0);
ASSERT(height > 0);