summaryrefslogtreecommitdiff
path: root/src/common/emu_window.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/emu_window.cpp')
-rw-r--r--src/common/emu_window.cpp50
1 files changed, 27 insertions, 23 deletions
diff --git a/src/common/emu_window.cpp b/src/common/emu_window.cpp
index fd728c109..122f1c212 100644
--- a/src/common/emu_window.cpp
+++ b/src/common/emu_window.cpp
@@ -4,10 +4,8 @@
4 4
5#include <algorithm> 5#include <algorithm>
6#include <cmath> 6#include <cmath>
7
8#include "common/assert.h" 7#include "common/assert.h"
9#include "common/key_map.h" 8#include "common/key_map.h"
10
11#include "emu_window.h" 9#include "emu_window.h"
12#include "video_core/video_core.h" 10#include "video_core/video_core.h"
13 11
@@ -44,18 +42,17 @@ void EmuWindow::CirclePadUpdated(float x, float y) {
44 */ 42 */
45static bool IsWithinTouchscreen(const EmuWindow::FramebufferLayout& layout, unsigned framebuffer_x, 43static bool IsWithinTouchscreen(const EmuWindow::FramebufferLayout& layout, unsigned framebuffer_x,
46 unsigned framebuffer_y) { 44 unsigned framebuffer_y) {
47 return (framebuffer_y >= layout.bottom_screen.top && 45 return (
48 framebuffer_y < layout.bottom_screen.bottom && 46 framebuffer_y >= layout.bottom_screen.top && framebuffer_y < layout.bottom_screen.bottom &&
49 framebuffer_x >= layout.bottom_screen.left && 47 framebuffer_x >= layout.bottom_screen.left && framebuffer_x < layout.bottom_screen.right);
50 framebuffer_x < layout.bottom_screen.right);
51} 48}
52 49
53std::tuple<unsigned,unsigned> EmuWindow::ClipToTouchScreen(unsigned new_x, unsigned new_y) { 50std::tuple<unsigned, unsigned> EmuWindow::ClipToTouchScreen(unsigned new_x, unsigned new_y) {
54 new_x = std::max(new_x, framebuffer_layout.bottom_screen.left); 51 new_x = std::max(new_x, framebuffer_layout.bottom_screen.left);
55 new_x = std::min(new_x, framebuffer_layout.bottom_screen.right-1); 52 new_x = std::min(new_x, framebuffer_layout.bottom_screen.right - 1);
56 53
57 new_y = std::max(new_y, framebuffer_layout.bottom_screen.top); 54 new_y = std::max(new_y, framebuffer_layout.bottom_screen.top);
58 new_y = std::min(new_y, framebuffer_layout.bottom_screen.bottom-1); 55 new_y = std::min(new_y, framebuffer_layout.bottom_screen.bottom - 1);
59 56
60 return std::make_tuple(new_x, new_y); 57 return std::make_tuple(new_x, new_y);
61} 58}
@@ -64,10 +61,12 @@ void EmuWindow::TouchPressed(unsigned framebuffer_x, unsigned framebuffer_y) {
64 if (!IsWithinTouchscreen(framebuffer_layout, framebuffer_x, framebuffer_y)) 61 if (!IsWithinTouchscreen(framebuffer_layout, framebuffer_x, framebuffer_y))
65 return; 62 return;
66 63
67 touch_x = VideoCore::kScreenBottomWidth * (framebuffer_x - framebuffer_layout.bottom_screen.left) / 64 touch_x = VideoCore::kScreenBottomWidth *
68 (framebuffer_layout.bottom_screen.right - framebuffer_layout.bottom_screen.left); 65 (framebuffer_x - framebuffer_layout.bottom_screen.left) /
69 touch_y = VideoCore::kScreenBottomHeight * (framebuffer_y - framebuffer_layout.bottom_screen.top) / 66 (framebuffer_layout.bottom_screen.right - framebuffer_layout.bottom_screen.left);
70 (framebuffer_layout.bottom_screen.bottom - framebuffer_layout.bottom_screen.top); 67 touch_y = VideoCore::kScreenBottomHeight *
68 (framebuffer_y - framebuffer_layout.bottom_screen.top) /
69 (framebuffer_layout.bottom_screen.bottom - framebuffer_layout.bottom_screen.top);
71 70
72 touch_pressed = true; 71 touch_pressed = true;
73 pad_state.touch.Assign(1); 72 pad_state.touch.Assign(1);
@@ -90,16 +89,19 @@ void EmuWindow::TouchMoved(unsigned framebuffer_x, unsigned framebuffer_y) {
90 TouchPressed(framebuffer_x, framebuffer_y); 89 TouchPressed(framebuffer_x, framebuffer_y);
91} 90}
92 91
93EmuWindow::FramebufferLayout EmuWindow::FramebufferLayout::DefaultScreenLayout(unsigned width, unsigned height) { 92EmuWindow::FramebufferLayout EmuWindow::FramebufferLayout::DefaultScreenLayout(unsigned width,
93 unsigned height) {
94 // When hiding the widget, the function receives a size of 0 94 // When hiding the widget, the function receives a size of 0
95 if (width == 0) width = 1; 95 if (width == 0)
96 if (height == 0) height = 1; 96 width = 1;
97 if (height == 0)
98 height = 1;
97 99
98 EmuWindow::FramebufferLayout res = { width, height, {}, {} }; 100 EmuWindow::FramebufferLayout res = {width, height, {}, {}};
99 101
100 float window_aspect_ratio = static_cast<float>(height) / width; 102 float window_aspect_ratio = static_cast<float>(height) / width;
101 float emulation_aspect_ratio = static_cast<float>(VideoCore::kScreenTopHeight * 2) / 103 float emulation_aspect_ratio =
102 VideoCore::kScreenTopWidth; 104 static_cast<float>(VideoCore::kScreenTopHeight * 2) / VideoCore::kScreenTopWidth;
103 105
104 if (window_aspect_ratio > emulation_aspect_ratio) { 106 if (window_aspect_ratio > emulation_aspect_ratio) {
105 // Window is narrower than the emulation content => apply borders to the top and bottom 107 // Window is narrower than the emulation content => apply borders to the top and bottom
@@ -110,8 +112,9 @@ EmuWindow::FramebufferLayout EmuWindow::FramebufferLayout::DefaultScreenLayout(u
110 res.top_screen.top = (height - viewport_height) / 2; 112 res.top_screen.top = (height - viewport_height) / 2;
111 res.top_screen.bottom = res.top_screen.top + viewport_height / 2; 113 res.top_screen.bottom = res.top_screen.top + viewport_height / 2;
112 114
113 int bottom_width = static_cast<int>((static_cast<float>(VideoCore::kScreenBottomWidth) / 115 int bottom_width = static_cast<int>(
114 VideoCore::kScreenTopWidth) * (res.top_screen.right - res.top_screen.left)); 116 (static_cast<float>(VideoCore::kScreenBottomWidth) / VideoCore::kScreenTopWidth) *
117 (res.top_screen.right - res.top_screen.left));
115 int bottom_border = ((res.top_screen.right - res.top_screen.left) - bottom_width) / 2; 118 int bottom_border = ((res.top_screen.right - res.top_screen.left) - bottom_width) / 2;
116 119
117 res.bottom_screen.left = bottom_border; 120 res.bottom_screen.left = bottom_border;
@@ -127,8 +130,9 @@ EmuWindow::FramebufferLayout EmuWindow::FramebufferLayout::DefaultScreenLayout(u
127 res.top_screen.top = 0; 130 res.top_screen.top = 0;
128 res.top_screen.bottom = res.top_screen.top + height / 2; 131 res.top_screen.bottom = res.top_screen.top + height / 2;
129 132
130 int bottom_width = static_cast<int>((static_cast<float>(VideoCore::kScreenBottomWidth) / 133 int bottom_width = static_cast<int>(
131 VideoCore::kScreenTopWidth) * (res.top_screen.right - res.top_screen.left)); 134 (static_cast<float>(VideoCore::kScreenBottomWidth) / VideoCore::kScreenTopWidth) *
135 (res.top_screen.right - res.top_screen.left));
132 int bottom_border = ((res.top_screen.right - res.top_screen.left) - bottom_width) / 2; 136 int bottom_border = ((res.top_screen.right - res.top_screen.left) - bottom_width) / 2;
133 137
134 res.bottom_screen.left = res.top_screen.left + bottom_border; 138 res.bottom_screen.left = res.top_screen.left + bottom_border;