summaryrefslogtreecommitdiff
path: root/src/common/emu_window.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2015-03-08 03:13:26 -0400
committerGravatar bunnei2015-03-10 18:05:17 -0400
commit543232436fae8d1d0f9fdd94baf0ca88d4eea067 (patch)
tree8104a34a4d34fe42a3054967677b13667670a540 /src/common/emu_window.cpp
parentHID: Added functions to emulate the touchpad. (diff)
downloadyuzu-543232436fae8d1d0f9fdd94baf0ca88d4eea067.tar.gz
yuzu-543232436fae8d1d0f9fdd94baf0ca88d4eea067.tar.xz
yuzu-543232436fae8d1d0f9fdd94baf0ca88d4eea067.zip
EmuWindow: Added infrastructure code to enable touchpad support.
Diffstat (limited to 'src/common/emu_window.cpp')
-rw-r--r--src/common/emu_window.cpp65
1 files changed, 64 insertions, 1 deletions
diff --git a/src/common/emu_window.cpp b/src/common/emu_window.cpp
index 6459d2f32..11e6ad76b 100644
--- a/src/common/emu_window.cpp
+++ b/src/common/emu_window.cpp
@@ -5,6 +5,8 @@
5#include "emu_window.h" 5#include "emu_window.h"
6#include "video_core/video_core.h" 6#include "video_core/video_core.h"
7 7
8bool EmuWindow::touch_pressed = false;
9
8void EmuWindow::KeyPressed(KeyMap::HostDeviceKey key) { 10void EmuWindow::KeyPressed(KeyMap::HostDeviceKey key) {
9 Service::HID::PadState mapped_key = KeyMap::GetPadKey(key); 11 Service::HID::PadState mapped_key = KeyMap::GetPadKey(key);
10 12
@@ -17,7 +19,68 @@ void EmuWindow::KeyReleased(KeyMap::HostDeviceKey key) {
17 Service::HID::PadButtonRelease(mapped_key); 19 Service::HID::PadButtonRelease(mapped_key);
18} 20}
19 21
20EmuWindow::FramebufferLayout EmuWindow::FramebufferLayout::DefaultScreenLayout(unsigned width, unsigned height) { 22/**
23 * Check if the given x/y coordinates are within the touchpad specified by the framebuffer layout
24 * @param layout FramebufferLayout object describing the framebuffer size and screen positions
25 * @param framebuffer_x Framebuffer x-coordinate to check
26 * @param framebuffer_y Framebuffer y-coordinate to check
27 * @return True if the coordinates are within the touchpad, otherwise false
28 */
29static bool IsWithinTouchscreen(const EmuWindow::FramebufferLayout& layout, unsigned framebuffer_x,
30 unsigned framebuffer_y) {
31
32 return (framebuffer_y >= layout.bottom_screen.top &&
33 framebuffer_y < layout.bottom_screen.bottom &&
34 framebuffer_x >= layout.bottom_screen.left &&
35 framebuffer_x < layout.bottom_screen.right);
36}
37
38void EmuWindow::TouchPressed(const FramebufferLayout& layout, unsigned framebuffer_x,
39 unsigned framebuffer_y) {
40
41 if (IsWithinTouchscreen(layout, framebuffer_x, framebuffer_y)) {
42 u16 touch_x = VideoCore::kScreenBottomWidth * (framebuffer_x - layout.bottom_screen.left) /
43 (layout.bottom_screen.right - layout.bottom_screen.left);
44 u16 touch_y = VideoCore::kScreenBottomHeight * (framebuffer_y - layout.bottom_screen.top) /
45 (layout.bottom_screen.bottom - layout.bottom_screen.top);
46
47 Service::HID::TouchPress(touch_x, touch_y);
48 Service::HID::TouchUpdateComplete();
49
50 touch_pressed = true;
51 }
52}
53
54void EmuWindow::TouchReleased(const FramebufferLayout& layout, unsigned framebuffer_x,
55 unsigned framebuffer_y) {
56
57 if (IsWithinTouchscreen(layout, framebuffer_x, framebuffer_y)) {
58
59 Service::HID::TouchRelease();
60 Service::HID::TouchUpdateComplete();
61
62 touch_pressed = false;
63 }
64}
65
66void EmuWindow::TouchMoved(const FramebufferLayout& layout, unsigned framebuffer_x,
67 unsigned framebuffer_y) {
68
69 if (touch_pressed) {
70 if (IsWithinTouchscreen(layout, framebuffer_x, framebuffer_y)) {
71 EmuWindow::TouchPressed(layout, framebuffer_x, framebuffer_y);
72 } else {
73 Service::HID::TouchRelease();
74 Service::HID::TouchUpdateComplete();
75
76 touch_pressed = false;
77 }
78 }
79}
80
81EmuWindow::FramebufferLayout EmuWindow::FramebufferLayout::DefaultScreenLayout(unsigned width,
82 unsigned height) {
83
21 ASSERT(width > 0); 84 ASSERT(width > 0);
22 ASSERT(height > 0); 85 ASSERT(height > 0);
23 86