diff options
| author | 2015-03-09 00:14:59 -0400 | |
|---|---|---|
| committer | 2015-03-10 23:58:07 -0400 | |
| commit | d61b26b79f889603a084e148626bba3c267cf75f (patch) | |
| tree | d793edd22e25a99aa5c13cc2455a5ec2167afee7 /src/common/emu_window.cpp | |
| parent | EmuWindow: Made pad/touch functions non-static. (diff) | |
| download | yuzu-d61b26b79f889603a084e148626bba3c267cf75f.tar.gz yuzu-d61b26b79f889603a084e148626bba3c267cf75f.tar.xz yuzu-d61b26b79f889603a084e148626bba3c267cf75f.zip | |
HID: Complete refactor of pad/touch input to fix threading issues.
Diffstat (limited to 'src/common/emu_window.cpp')
| -rw-r--r-- | src/common/emu_window.cpp | 74 |
1 files changed, 28 insertions, 46 deletions
diff --git a/src/common/emu_window.cpp b/src/common/emu_window.cpp index 89bb89481..6516fc633 100644 --- a/src/common/emu_window.cpp +++ b/src/common/emu_window.cpp | |||
| @@ -6,15 +6,11 @@ | |||
| 6 | #include "video_core/video_core.h" | 6 | #include "video_core/video_core.h" |
| 7 | 7 | ||
| 8 | void EmuWindow::KeyPressed(KeyMap::HostDeviceKey key) { | 8 | void 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 | ||
| 14 | void EmuWindow::KeyReleased(KeyMap::HostDeviceKey key) { | 12 | void EmuWindow::KeyReleased(KeyMap::HostDeviceKey key) { |
| 15 | Service::HID::PadState mapped_key = KeyMap::GetPadKey(key); | 13 | pad_state.hex &= ~KeyMap::GetPadKey(key).hex; |
| 16 | |||
| 17 | Service::HID::PadButtonRelease(mapped_key); | ||
| 18 | } | 14 | } |
| 19 | 15 | ||
| 20 | /** | 16 | /** |
| @@ -25,55 +21,41 @@ void EmuWindow::KeyReleased(KeyMap::HostDeviceKey key) { | |||
| 25 | * @return True if the coordinates are within the touchpad, otherwise false | 21 | * @return True if the coordinates are within the touchpad, otherwise false |
| 26 | */ | 22 | */ |
| 27 | static bool IsWithinTouchscreen(const EmuWindow::FramebufferLayout& layout, unsigned framebuffer_x, | 23 | static bool IsWithinTouchscreen(const EmuWindow::FramebufferLayout& layout, unsigned framebuffer_x, |
| 28 | unsigned framebuffer_y) { | 24 | unsigned framebuffer_y) { |
| 29 | 25 | return (framebuffer_y >= layout.bottom_screen.top && | |
| 30 | return (framebuffer_y >= layout.bottom_screen.top && | 26 | framebuffer_y < layout.bottom_screen.bottom && |
| 31 | framebuffer_y < layout.bottom_screen.bottom && | 27 | framebuffer_x >= layout.bottom_screen.left && |
| 32 | framebuffer_x >= layout.bottom_screen.left && | 28 | framebuffer_x < layout.bottom_screen.right); |
| 33 | framebuffer_x < layout.bottom_screen.right); | ||
| 34 | } | 29 | } |
| 35 | 30 | ||
| 36 | void EmuWindow::TouchPressed(const FramebufferLayout& layout, unsigned framebuffer_x, | 31 | void EmuWindow::TouchPressed(unsigned framebuffer_x, unsigned framebuffer_y) { |
| 37 | unsigned framebuffer_y) { | 32 | if (!IsWithinTouchscreen(framebuffer_layout, framebuffer_x, framebuffer_y)) |
| 33 | return; | ||
| 38 | 34 | ||
| 39 | if (IsWithinTouchscreen(layout, framebuffer_x, framebuffer_y)) { | 35 | touch_x = VideoCore::kScreenBottomWidth * (framebuffer_x - framebuffer_layout.bottom_screen.left) / |
| 40 | u16 touch_x = VideoCore::kScreenBottomWidth * (framebuffer_x - layout.bottom_screen.left) / | 36 | (framebuffer_layout.bottom_screen.right - framebuffer_layout.bottom_screen.left); |
| 41 | (layout.bottom_screen.right - layout.bottom_screen.left); | 37 | touch_y = VideoCore::kScreenBottomHeight * (framebuffer_y - framebuffer_layout.bottom_screen.top) / |
| 42 | u16 touch_y = VideoCore::kScreenBottomHeight * (framebuffer_y - layout.bottom_screen.top) / | 38 | (framebuffer_layout.bottom_screen.bottom - framebuffer_layout.bottom_screen.top); |
| 43 | (layout.bottom_screen.bottom - layout.bottom_screen.top); | ||
| 44 | 39 | ||
| 45 | Service::HID::TouchPress(touch_x, touch_y); | 40 | touch_pressed = true; |
| 46 | Service::HID::TouchUpdateComplete(); | 41 | pad_state.touch = 1; |
| 47 | |||
| 48 | touch_pressed = true; | ||
| 49 | } | ||
| 50 | } | 42 | } |
| 51 | 43 | ||
| 52 | void EmuWindow::TouchReleased(const FramebufferLayout& layout, unsigned framebuffer_x, | 44 | void EmuWindow::TouchReleased() { |
| 53 | unsigned framebuffer_y) { | 45 | touch_pressed = false; |
| 54 | 46 | touch_x = 0; | |
| 55 | if (IsWithinTouchscreen(layout, framebuffer_x, framebuffer_y)) { | 47 | touch_y = 0; |
| 56 | 48 | pad_state.touch = 0; | |
| 57 | Service::HID::TouchRelease(); | ||
| 58 | Service::HID::TouchUpdateComplete(); | ||
| 59 | |||
| 60 | touch_pressed = false; | ||
| 61 | } | ||
| 62 | } | 49 | } |
| 63 | 50 | ||
| 64 | void EmuWindow::TouchMoved(const FramebufferLayout& layout, unsigned framebuffer_x, | 51 | void EmuWindow::TouchMoved(unsigned framebuffer_x, unsigned framebuffer_y) { |
| 65 | unsigned framebuffer_y) { | 52 | if (!touch_pressed) |
| 53 | return; | ||
| 66 | 54 | ||
| 67 | if (touch_pressed) { | 55 | if (IsWithinTouchscreen(framebuffer_layout, framebuffer_x, framebuffer_y)) |
| 68 | if (IsWithinTouchscreen(layout, framebuffer_x, framebuffer_y)) { | 56 | TouchPressed(framebuffer_x, framebuffer_y); |
| 69 | EmuWindow::TouchPressed(layout, framebuffer_x, framebuffer_y); | 57 | else |
| 70 | } else { | 58 | TouchReleased(); |
| 71 | Service::HID::TouchRelease(); | ||
| 72 | Service::HID::TouchUpdateComplete(); | ||
| 73 | |||
| 74 | touch_pressed = false; | ||
| 75 | } | ||
| 76 | } | ||
| 77 | } | 59 | } |
| 78 | 60 | ||
| 79 | EmuWindow::FramebufferLayout EmuWindow::FramebufferLayout::DefaultScreenLayout(unsigned width, | 61 | EmuWindow::FramebufferLayout EmuWindow::FramebufferLayout::DefaultScreenLayout(unsigned width, |