summaryrefslogtreecommitdiff
path: root/src/common/emu_window.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2015-03-11 21:28:57 -0400
committerGravatar bunnei2015-03-11 21:28:57 -0400
commited5b275d21612906e6eeb4b1f344aa0f1eb31c10 (patch)
tree54ffc1fe7163996fdaed1cb5cd948015409dcac6 /src/common/emu_window.cpp
parentMerge pull request #629 from archshift/lcdfb (diff)
parenthid_user: Removed unnecessary includes. (diff)
downloadyuzu-ed5b275d21612906e6eeb4b1f344aa0f1eb31c10.tar.gz
yuzu-ed5b275d21612906e6eeb4b1f344aa0f1eb31c10.tar.xz
yuzu-ed5b275d21612906e6eeb4b1f344aa0f1eb31c10.zip
Merge pull request #642 from bunnei/touchpad
Touchpad support
Diffstat (limited to 'src/common/emu_window.cpp')
-rw-r--r--src/common/emu_window.cpp55
1 files changed, 49 insertions, 6 deletions
diff --git a/src/common/emu_window.cpp b/src/common/emu_window.cpp
index 6459d2f32..6516fc633 100644
--- a/src/common/emu_window.cpp
+++ b/src/common/emu_window.cpp
@@ -6,18 +6,61 @@
6#include "video_core/video_core.h" 6#include "video_core/video_core.h"
7 7
8void EmuWindow::KeyPressed(KeyMap::HostDeviceKey key) { 8void EmuWindow::KeyPressed(KeyMap::HostDeviceKey key) {
9 Service::HID::PadState mapped_key = KeyMap::GetPadKey(key); 9 pad_state.hex |= KeyMap::GetPadKey(key).hex;
10
11 Service::HID::PadButtonPress(mapped_key);
12} 10}
13 11
14void EmuWindow::KeyReleased(KeyMap::HostDeviceKey key) { 12void EmuWindow::KeyReleased(KeyMap::HostDeviceKey key) {
15 Service::HID::PadState mapped_key = KeyMap::GetPadKey(key); 13 pad_state.hex &= ~KeyMap::GetPadKey(key).hex;
14}
15
16/**
17 * Check if the given x/y coordinates are within the touchpad specified by the framebuffer layout
18 * @param layout FramebufferLayout object describing the framebuffer size and screen positions
19 * @param framebuffer_x Framebuffer x-coordinate to check
20 * @param framebuffer_y Framebuffer y-coordinate to check
21 * @return True if the coordinates are within the touchpad, otherwise false
22 */
23static bool IsWithinTouchscreen(const EmuWindow::FramebufferLayout& layout, unsigned framebuffer_x,
24 unsigned framebuffer_y) {
25 return (framebuffer_y >= layout.bottom_screen.top &&
26 framebuffer_y < layout.bottom_screen.bottom &&
27 framebuffer_x >= layout.bottom_screen.left &&
28 framebuffer_x < layout.bottom_screen.right);
29}
30
31void EmuWindow::TouchPressed(unsigned framebuffer_x, unsigned framebuffer_y) {
32 if (!IsWithinTouchscreen(framebuffer_layout, framebuffer_x, framebuffer_y))
33 return;
34
35 touch_x = VideoCore::kScreenBottomWidth * (framebuffer_x - framebuffer_layout.bottom_screen.left) /
36 (framebuffer_layout.bottom_screen.right - framebuffer_layout.bottom_screen.left);
37 touch_y = VideoCore::kScreenBottomHeight * (framebuffer_y - framebuffer_layout.bottom_screen.top) /
38 (framebuffer_layout.bottom_screen.bottom - framebuffer_layout.bottom_screen.top);
16 39
17 Service::HID::PadButtonRelease(mapped_key); 40 touch_pressed = true;
41 pad_state.touch = 1;
18} 42}
19 43
20EmuWindow::FramebufferLayout EmuWindow::FramebufferLayout::DefaultScreenLayout(unsigned width, unsigned height) { 44void EmuWindow::TouchReleased() {
45 touch_pressed = false;
46 touch_x = 0;
47 touch_y = 0;
48 pad_state.touch = 0;
49}
50
51void EmuWindow::TouchMoved(unsigned framebuffer_x, unsigned framebuffer_y) {
52 if (!touch_pressed)
53 return;
54
55 if (IsWithinTouchscreen(framebuffer_layout, framebuffer_x, framebuffer_y))
56 TouchPressed(framebuffer_x, framebuffer_y);
57 else
58 TouchReleased();
59}
60
61EmuWindow::FramebufferLayout EmuWindow::FramebufferLayout::DefaultScreenLayout(unsigned width,
62 unsigned height) {
63
21 ASSERT(width > 0); 64 ASSERT(width > 0);
22 ASSERT(height > 0); 65 ASSERT(height > 0);
23 66