diff options
| author | 2016-11-15 19:57:08 -0500 | |
|---|---|---|
| committer | 2016-11-15 19:57:08 -0500 | |
| commit | 5a31552764dc8970253e642f4b829a8b785375c6 (patch) | |
| tree | 8186a82c37ae04c17bd1d6250c524fc097f9671c /src/common/emu_window.cpp | |
| parent | Merge pull request #2171 from jroweboy/fix-mac-build (diff) | |
| parent | Round the rectangle size to prevent float to int casting issues (diff) | |
| download | yuzu-5a31552764dc8970253e642f4b829a8b785375c6.tar.gz yuzu-5a31552764dc8970253e642f4b829a8b785375c6.tar.xz yuzu-5a31552764dc8970253e642f4b829a8b785375c6.zip | |
Merge pull request #1753 from jroweboy/frame_layouts
Support additional screen layouts.
Diffstat (limited to 'src/common/emu_window.cpp')
| -rw-r--r-- | src/common/emu_window.cpp | 68 |
1 files changed, 15 insertions, 53 deletions
diff --git a/src/common/emu_window.cpp b/src/common/emu_window.cpp index 122f1c212..e3a9e08e6 100644 --- a/src/common/emu_window.cpp +++ b/src/common/emu_window.cpp | |||
| @@ -40,7 +40,7 @@ void EmuWindow::CirclePadUpdated(float x, float y) { | |||
| 40 | * @param framebuffer_y Framebuffer y-coordinate to check | 40 | * @param framebuffer_y Framebuffer y-coordinate to check |
| 41 | * @return True if the coordinates are within the touchpad, otherwise false | 41 | * @return True if the coordinates are within the touchpad, otherwise false |
| 42 | */ | 42 | */ |
| 43 | static bool IsWithinTouchscreen(const EmuWindow::FramebufferLayout& layout, unsigned framebuffer_x, | 43 | static bool IsWithinTouchscreen(const Layout::FramebufferLayout& layout, unsigned framebuffer_x, |
| 44 | unsigned framebuffer_y) { | 44 | unsigned framebuffer_y) { |
| 45 | return ( | 45 | return ( |
| 46 | framebuffer_y >= layout.bottom_screen.top && framebuffer_y < layout.bottom_screen.bottom && | 46 | 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) { | |||
| 89 | TouchPressed(framebuffer_x, framebuffer_y); | 89 | TouchPressed(framebuffer_x, framebuffer_y); |
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | EmuWindow::FramebufferLayout EmuWindow::FramebufferLayout::DefaultScreenLayout(unsigned width, | 92 | void EmuWindow::UpdateCurrentFramebufferLayout(unsigned width, unsigned height) { |
| 93 | unsigned height) { | 93 | Layout::FramebufferLayout layout; |
| 94 | // When hiding the widget, the function receives a size of 0 | 94 | switch (Settings::values.layout_option) { |
| 95 | if (width == 0) | 95 | case Settings::LayoutOption::SingleScreen: |
| 96 | width = 1; | 96 | layout = Layout::SingleFrameLayout(width, height, Settings::values.swap_screen); |
| 97 | if (height == 0) | 97 | break; |
| 98 | height = 1; | 98 | case Settings::LayoutOption::LargeScreen: |
| 99 | 99 | layout = Layout::LargeFrameLayout(width, height, Settings::values.swap_screen); | |
| 100 | EmuWindow::FramebufferLayout res = {width, height, {}, {}}; | 100 | break; |
| 101 | 101 | case Settings::LayoutOption::Default: | |
| 102 | float window_aspect_ratio = static_cast<float>(height) / width; | 102 | default: |
| 103 | float emulation_aspect_ratio = | 103 | layout = Layout::DefaultFrameLayout(width, height, Settings::values.swap_screen); |
| 104 | static_cast<float>(VideoCore::kScreenTopHeight * 2) / VideoCore::kScreenTopWidth; | 104 | break; |
| 105 | |||
| 106 | if (window_aspect_ratio > emulation_aspect_ratio) { | ||
| 107 | // Window is narrower than the emulation content => apply borders to the top and bottom | ||
| 108 | int viewport_height = static_cast<int>(std::round(emulation_aspect_ratio * width)); | ||
| 109 | |||
| 110 | res.top_screen.left = 0; | ||
| 111 | res.top_screen.right = res.top_screen.left + width; | ||
| 112 | res.top_screen.top = (height - viewport_height) / 2; | ||
| 113 | res.top_screen.bottom = res.top_screen.top + viewport_height / 2; | ||
| 114 | |||
| 115 | int bottom_width = static_cast<int>( | ||
| 116 | (static_cast<float>(VideoCore::kScreenBottomWidth) / VideoCore::kScreenTopWidth) * | ||
| 117 | (res.top_screen.right - res.top_screen.left)); | ||
| 118 | int bottom_border = ((res.top_screen.right - res.top_screen.left) - bottom_width) / 2; | ||
| 119 | |||
| 120 | res.bottom_screen.left = bottom_border; | ||
| 121 | res.bottom_screen.right = res.bottom_screen.left + bottom_width; | ||
| 122 | res.bottom_screen.top = res.top_screen.bottom; | ||
| 123 | res.bottom_screen.bottom = res.bottom_screen.top + viewport_height / 2; | ||
| 124 | } else { | ||
| 125 | // Otherwise, apply borders to the left and right sides of the window. | ||
| 126 | int viewport_width = static_cast<int>(std::round(height / emulation_aspect_ratio)); | ||
| 127 | |||
| 128 | res.top_screen.left = (width - viewport_width) / 2; | ||
| 129 | res.top_screen.right = res.top_screen.left + viewport_width; | ||
| 130 | res.top_screen.top = 0; | ||
| 131 | res.top_screen.bottom = res.top_screen.top + height / 2; | ||
| 132 | |||
| 133 | int bottom_width = static_cast<int>( | ||
| 134 | (static_cast<float>(VideoCore::kScreenBottomWidth) / VideoCore::kScreenTopWidth) * | ||
| 135 | (res.top_screen.right - res.top_screen.left)); | ||
| 136 | int bottom_border = ((res.top_screen.right - res.top_screen.left) - bottom_width) / 2; | ||
| 137 | |||
| 138 | res.bottom_screen.left = res.top_screen.left + bottom_border; | ||
| 139 | res.bottom_screen.right = res.bottom_screen.left + bottom_width; | ||
| 140 | res.bottom_screen.top = res.top_screen.bottom; | ||
| 141 | res.bottom_screen.bottom = res.bottom_screen.top + height / 2; | ||
| 142 | } | 105 | } |
| 143 | 106 | NotifyFramebufferLayoutChanged(layout); | |
| 144 | return res; | ||
| 145 | } | 107 | } |