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