diff options
| author | 2021-01-02 22:04:50 -0600 | |
|---|---|---|
| committer | 2021-01-15 09:05:17 -0600 | |
| commit | 8495e1bd8373fed993975e40c360c87409455e9e (patch) | |
| tree | fffff1304673212280dc0e927b69efa3ca4fc8b3 /src/core/frontend/emu_window.cpp | |
| parent | Allow to return up to 16 touch inputs per engine (diff) | |
| download | yuzu-8495e1bd8373fed993975e40c360c87409455e9e.tar.gz yuzu-8495e1bd8373fed993975e40c360c87409455e9e.tar.xz yuzu-8495e1bd8373fed993975e40c360c87409455e9e.zip | |
Add mutitouch support for touch screens
Diffstat (limited to 'src/core/frontend/emu_window.cpp')
| -rw-r--r-- | src/core/frontend/emu_window.cpp | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/src/core/frontend/emu_window.cpp b/src/core/frontend/emu_window.cpp index 589842917..af6c1633a 100644 --- a/src/core/frontend/emu_window.cpp +++ b/src/core/frontend/emu_window.cpp | |||
| @@ -21,21 +21,17 @@ public: | |||
| 21 | 21 | ||
| 22 | std::mutex mutex; | 22 | std::mutex mutex; |
| 23 | 23 | ||
| 24 | bool touch_pressed = false; ///< True if touchpad area is currently pressed, otherwise false | 24 | Input::TouchStatus status; |
| 25 | |||
| 26 | float touch_x = 0.0f; ///< Touchpad X-position | ||
| 27 | float touch_y = 0.0f; ///< Touchpad Y-position | ||
| 28 | 25 | ||
| 29 | private: | 26 | private: |
| 30 | class Device : public Input::TouchDevice { | 27 | class Device : public Input::TouchDevice { |
| 31 | public: | 28 | public: |
| 32 | explicit Device(std::weak_ptr<TouchState>&& touch_state) : touch_state(touch_state) {} | 29 | explicit Device(std::weak_ptr<TouchState>&& touch_state) : touch_state(touch_state) {} |
| 33 | Input::TouchStatus GetStatus() const override { | 30 | Input::TouchStatus GetStatus() const override { |
| 34 | Input::TouchStatus touch_status = {}; | 31 | Input::TouchStatus touch_status{}; |
| 35 | if (auto state = touch_state.lock()) { | 32 | if (auto state = touch_state.lock()) { |
| 36 | std::lock_guard guard{state->mutex}; | 33 | std::lock_guard guard{state->mutex}; |
| 37 | touch_status[0] = | 34 | touch_status = state->status; |
| 38 | std::make_tuple(state->touch_x, state->touch_y, state->touch_pressed); | ||
| 39 | } | 35 | } |
| 40 | return touch_status; | 36 | return touch_status; |
| 41 | } | 37 | } |
| @@ -81,36 +77,44 @@ std::tuple<unsigned, unsigned> EmuWindow::ClipToTouchScreen(unsigned new_x, unsi | |||
| 81 | return std::make_tuple(new_x, new_y); | 77 | return std::make_tuple(new_x, new_y); |
| 82 | } | 78 | } |
| 83 | 79 | ||
| 84 | void EmuWindow::TouchPressed(unsigned framebuffer_x, unsigned framebuffer_y) { | 80 | void EmuWindow::TouchPressed(unsigned framebuffer_x, unsigned framebuffer_y, std::size_t id) { |
| 85 | if (!IsWithinTouchscreen(framebuffer_layout, framebuffer_x, framebuffer_y)) | 81 | if (!IsWithinTouchscreen(framebuffer_layout, framebuffer_x, framebuffer_y)) { |
| 86 | return; | 82 | return; |
| 83 | } | ||
| 84 | if (id >= touch_state->status.size()) { | ||
| 85 | return; | ||
| 86 | } | ||
| 87 | 87 | ||
| 88 | std::lock_guard guard{touch_state->mutex}; | 88 | std::lock_guard guard{touch_state->mutex}; |
| 89 | touch_state->touch_x = | 89 | const float x = |
| 90 | static_cast<float>(framebuffer_x - framebuffer_layout.screen.left) / | 90 | static_cast<float>(framebuffer_x - framebuffer_layout.screen.left) / |
| 91 | static_cast<float>(framebuffer_layout.screen.right - framebuffer_layout.screen.left); | 91 | static_cast<float>(framebuffer_layout.screen.right - framebuffer_layout.screen.left); |
| 92 | touch_state->touch_y = | 92 | const float y = |
| 93 | static_cast<float>(framebuffer_y - framebuffer_layout.screen.top) / | 93 | static_cast<float>(framebuffer_y - framebuffer_layout.screen.top) / |
| 94 | static_cast<float>(framebuffer_layout.screen.bottom - framebuffer_layout.screen.top); | 94 | static_cast<float>(framebuffer_layout.screen.bottom - framebuffer_layout.screen.top); |
| 95 | 95 | ||
| 96 | touch_state->touch_pressed = true; | 96 | touch_state->status[id] = std::make_tuple(x, y, true); |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | void EmuWindow::TouchReleased() { | 99 | void EmuWindow::TouchReleased(std::size_t id) { |
| 100 | if (id >= touch_state->status.size()) { | ||
| 101 | return; | ||
| 102 | } | ||
| 100 | std::lock_guard guard{touch_state->mutex}; | 103 | std::lock_guard guard{touch_state->mutex}; |
| 101 | touch_state->touch_pressed = false; | 104 | touch_state->status[id] = std::make_tuple(0.0f, 0.0f, false); |
| 102 | touch_state->touch_x = 0; | ||
| 103 | touch_state->touch_y = 0; | ||
| 104 | } | 105 | } |
| 105 | 106 | ||
| 106 | void EmuWindow::TouchMoved(unsigned framebuffer_x, unsigned framebuffer_y) { | 107 | void EmuWindow::TouchMoved(unsigned framebuffer_x, unsigned framebuffer_y, std::size_t id) { |
| 107 | if (!touch_state->touch_pressed) | 108 | if (id >= touch_state->status.size()) { |
| 109 | return; | ||
| 110 | } | ||
| 111 | if (!std::get<2>(touch_state->status[id])) | ||
| 108 | return; | 112 | return; |
| 109 | 113 | ||
| 110 | if (!IsWithinTouchscreen(framebuffer_layout, framebuffer_x, framebuffer_y)) | 114 | if (!IsWithinTouchscreen(framebuffer_layout, framebuffer_x, framebuffer_y)) |
| 111 | std::tie(framebuffer_x, framebuffer_y) = ClipToTouchScreen(framebuffer_x, framebuffer_y); | 115 | std::tie(framebuffer_x, framebuffer_y) = ClipToTouchScreen(framebuffer_x, framebuffer_y); |
| 112 | 116 | ||
| 113 | TouchPressed(framebuffer_x, framebuffer_y); | 117 | TouchPressed(framebuffer_x, framebuffer_y, id); |
| 114 | } | 118 | } |
| 115 | 119 | ||
| 116 | void EmuWindow::UpdateCurrentFramebufferLayout(unsigned width, unsigned height) { | 120 | void EmuWindow::UpdateCurrentFramebufferLayout(unsigned width, unsigned height) { |