From 2b1654ad9bbd8af53f22434d350704a1a1d0a285 Mon Sep 17 00:00:00 2001
From: James Rowe <jroweboy@gmail.com>
Date: Tue, 3 May 2016 00:07:17 -0600
Subject: Support additional screen layouts.

Allows users to choose a single screen layout or a large screen layout.
Adds a configuration option to change the prominent screen.
---
 src/common/emu_window.cpp | 68 +++++++++++------------------------------------
 1 file changed, 15 insertions(+), 53 deletions(-)

(limited to 'src/common/emu_window.cpp')

diff --git a/src/common/emu_window.cpp b/src/common/emu_window.cpp
index 122f1c212e..e3a9e08e60 100644
--- a/src/common/emu_window.cpp
+++ b/src/common/emu_window.cpp
@@ -40,7 +40,7 @@ void EmuWindow::CirclePadUpdated(float x, float y) {
  * @param framebuffer_y Framebuffer y-coordinate to check
  * @return True if the coordinates are within the touchpad, otherwise false
  */
-static bool IsWithinTouchscreen(const EmuWindow::FramebufferLayout& layout, unsigned framebuffer_x,
+static bool IsWithinTouchscreen(const Layout::FramebufferLayout& layout, unsigned framebuffer_x,
                                 unsigned framebuffer_y) {
     return (
         framebuffer_y >= layout.bottom_screen.top && framebuffer_y < layout.bottom_screen.bottom &&
@@ -89,57 +89,19 @@ void EmuWindow::TouchMoved(unsigned framebuffer_x, unsigned framebuffer_y) {
     TouchPressed(framebuffer_x, framebuffer_y);
 }
 
-EmuWindow::FramebufferLayout EmuWindow::FramebufferLayout::DefaultScreenLayout(unsigned width,
-                                                                               unsigned height) {
-    // When hiding the widget, the function receives a size of 0
-    if (width == 0)
-        width = 1;
-    if (height == 0)
-        height = 1;
-
-    EmuWindow::FramebufferLayout res = {width, height, {}, {}};
-
-    float window_aspect_ratio = static_cast<float>(height) / width;
-    float emulation_aspect_ratio =
-        static_cast<float>(VideoCore::kScreenTopHeight * 2) / VideoCore::kScreenTopWidth;
-
-    if (window_aspect_ratio > emulation_aspect_ratio) {
-        // Window is narrower than the emulation content => apply borders to the top and bottom
-        int viewport_height = static_cast<int>(std::round(emulation_aspect_ratio * width));
-
-        res.top_screen.left = 0;
-        res.top_screen.right = res.top_screen.left + width;
-        res.top_screen.top = (height - viewport_height) / 2;
-        res.top_screen.bottom = res.top_screen.top + viewport_height / 2;
-
-        int bottom_width = static_cast<int>(
-            (static_cast<float>(VideoCore::kScreenBottomWidth) / VideoCore::kScreenTopWidth) *
-            (res.top_screen.right - res.top_screen.left));
-        int bottom_border = ((res.top_screen.right - res.top_screen.left) - bottom_width) / 2;
-
-        res.bottom_screen.left = bottom_border;
-        res.bottom_screen.right = res.bottom_screen.left + bottom_width;
-        res.bottom_screen.top = res.top_screen.bottom;
-        res.bottom_screen.bottom = res.bottom_screen.top + viewport_height / 2;
-    } else {
-        // Otherwise, apply borders to the left and right sides of the window.
-        int viewport_width = static_cast<int>(std::round(height / emulation_aspect_ratio));
-
-        res.top_screen.left = (width - viewport_width) / 2;
-        res.top_screen.right = res.top_screen.left + viewport_width;
-        res.top_screen.top = 0;
-        res.top_screen.bottom = res.top_screen.top + height / 2;
-
-        int bottom_width = static_cast<int>(
-            (static_cast<float>(VideoCore::kScreenBottomWidth) / VideoCore::kScreenTopWidth) *
-            (res.top_screen.right - res.top_screen.left));
-        int bottom_border = ((res.top_screen.right - res.top_screen.left) - bottom_width) / 2;
-
-        res.bottom_screen.left = res.top_screen.left + bottom_border;
-        res.bottom_screen.right = res.bottom_screen.left + bottom_width;
-        res.bottom_screen.top = res.top_screen.bottom;
-        res.bottom_screen.bottom = res.bottom_screen.top + height / 2;
+void EmuWindow::UpdateCurrentFramebufferLayout(unsigned width, unsigned height) {
+    Layout::FramebufferLayout layout;
+    switch (Settings::values.layout_option) {
+    case Settings::LayoutOption::SingleScreen:
+        layout = Layout::SingleFrameLayout(width, height, Settings::values.swap_screen);
+        break;
+    case Settings::LayoutOption::LargeScreen:
+        layout = Layout::LargeFrameLayout(width, height, Settings::values.swap_screen);
+        break;
+    case Settings::LayoutOption::Default:
+    default:
+        layout = Layout::DefaultFrameLayout(width, height, Settings::values.swap_screen);
+        break;
     }
-
-    return res;
+    NotifyFramebufferLayoutChanged(layout);
 }
-- 
cgit v1.2.3-70-g09d2