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 | |
| 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')
| -rw-r--r-- | src/common/emu_window.cpp | 74 | ||||
| -rw-r--r-- | src/common/emu_window.h | 57 |
2 files changed, 63 insertions, 68 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, |
diff --git a/src/common/emu_window.h b/src/common/emu_window.h index 8e4b510e9..2be7517bc 100644 --- a/src/common/emu_window.h +++ b/src/common/emu_window.h | |||
| @@ -78,27 +78,41 @@ public: | |||
| 78 | 78 | ||
| 79 | /** | 79 | /** |
| 80 | * Signal that a touch pressed event has occurred (e.g. mouse click pressed) | 80 | * Signal that a touch pressed event has occurred (e.g. mouse click pressed) |
| 81 | * @param layout FramebufferLayout object describing the framebuffer size and screen positions | ||
| 82 | * @param framebuffer_x Framebuffer x-coordinate that was pressed | 81 | * @param framebuffer_x Framebuffer x-coordinate that was pressed |
| 83 | * @param framebuffer_y Framebuffer y-coordinate that was pressed | 82 | * @param framebuffer_y Framebuffer y-coordinate that was pressed |
| 84 | */ | 83 | */ |
| 85 | void TouchPressed(const FramebufferLayout& layout, unsigned framebuffer_x, unsigned framebuffer_y); | 84 | void TouchPressed(unsigned framebuffer_x, unsigned framebuffer_y); |
| 86 | 85 | ||
| 87 | /** | 86 | /// Signal that a touch released event has occurred (e.g. mouse click released) |
| 88 | * Signal that a touch released event has occurred (e.g. mouse click released) | 87 | void TouchReleased(); |
| 89 | * @param layout FramebufferLayout object describing the framebuffer size and screen positions | ||
| 90 | * @param framebuffer_x Framebuffer x-coordinate that was released | ||
| 91 | * @param framebuffer_y Framebuffer y-coordinate that was released | ||
| 92 | */ | ||
| 93 | void TouchReleased(const FramebufferLayout& layout, unsigned framebuffer_x, unsigned framebuffer_y); | ||
| 94 | 88 | ||
| 95 | /** | 89 | /** |
| 96 | * Signal that a touch movement event has occurred (e.g. mouse was moved over the emu window) | 90 | * Signal that a touch movement event has occurred (e.g. mouse was moved over the emu window) |
| 97 | * @param layout FramebufferLayout object describing the framebuffer size and screen positions | ||
| 98 | * @param framebuffer_x Framebuffer x-coordinate | 91 | * @param framebuffer_x Framebuffer x-coordinate |
| 99 | * @param framebuffer_y Framebuffer y-coordinate | 92 | * @param framebuffer_y Framebuffer y-coordinate |
| 100 | */ | 93 | */ |
| 101 | void TouchMoved(const FramebufferLayout& layout, unsigned framebuffer_x, unsigned framebuffer_y); | 94 | void TouchMoved(unsigned framebuffer_x, unsigned framebuffer_y); |
| 95 | |||
| 96 | /** | ||
| 97 | * Gets the current pad state (which buttons are pressed and the circle pad direction). | ||
| 98 | * @note This should be called by the core emu thread to get a state set by the window thread. | ||
| 99 | * @todo Fix this function to be thread-safe. | ||
| 100 | * @return PadState object indicating the current pad state | ||
| 101 | */ | ||
| 102 | const Service::HID::PadState GetPadState() const { | ||
| 103 | return pad_state; | ||
| 104 | } | ||
| 105 | |||
| 106 | /** | ||
| 107 | * Gets the current touch screen state (touch X/Y coordinates and whether or not it is pressed). | ||
| 108 | * @note This should be called by the core emu thread to get a state set by the window thread. | ||
| 109 | * @todo Fix this function to be thread-safe. | ||
| 110 | * @return std::tuple of (x, y, pressed) where `x` and `y` are the touch coordinates and | ||
| 111 | * `pressed` is true if the touch screen is currently being pressed | ||
| 112 | */ | ||
| 113 | const std::tuple<u16, u16, bool>& GetTouchState() const { | ||
| 114 | return std::make_tuple(touch_x, touch_y, touch_pressed); | ||
| 115 | } | ||
| 102 | 116 | ||
| 103 | /** | 117 | /** |
| 104 | * Returns currently active configuration. | 118 | * Returns currently active configuration. |
| @@ -124,21 +138,15 @@ public: | |||
| 124 | return framebuffer_layout; | 138 | return framebuffer_layout; |
| 125 | } | 139 | } |
| 126 | 140 | ||
| 127 | /** | ||
| 128 | * Gets window client area width in logical coordinates. | ||
| 129 | * @note For high-DPI systems, this is smaller than the framebuffer size. | ||
| 130 | * @note This method is thread-safe | ||
| 131 | */ | ||
| 132 | std::pair<unsigned,unsigned> GetClientAreaSize() const { | ||
| 133 | return std::make_pair(client_area_width, client_area_height); | ||
| 134 | } | ||
| 135 | |||
| 136 | protected: | 141 | protected: |
| 137 | EmuWindow() | 142 | EmuWindow() { |
| 138 | { | ||
| 139 | // TODO: Find a better place to set this. | 143 | // TODO: Find a better place to set this. |
| 140 | config.min_client_area_size = std::make_pair(400u, 480u); | 144 | config.min_client_area_size = std::make_pair(400u, 480u); |
| 141 | active_config = config; | 145 | active_config = config; |
| 146 | pad_state.hex = 0; | ||
| 147 | touch_x = 0; | ||
| 148 | touch_y = 0; | ||
| 149 | touch_pressed = false; | ||
| 142 | } | 150 | } |
| 143 | virtual ~EmuWindow() {} | 151 | virtual ~EmuWindow() {} |
| 144 | 152 | ||
| @@ -194,4 +202,9 @@ private: | |||
| 194 | WindowConfig active_config; ///< Internal active configuration | 202 | WindowConfig active_config; ///< Internal active configuration |
| 195 | 203 | ||
| 196 | bool touch_pressed; ///< True if touchpad area is currently pressed, otherwise false | 204 | bool touch_pressed; ///< True if touchpad area is currently pressed, otherwise false |
| 205 | |||
| 206 | u16 touch_x; ///< Touchpad X-position in native 3DS pixel coordinates (0-320) | ||
| 207 | u16 touch_y; ///< Touchpad Y-position in native 3DS pixel coordinates (0-240) | ||
| 208 | |||
| 209 | Service::HID::PadState pad_state; | ||
| 197 | }; | 210 | }; |