diff options
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/emu_window.cpp | 55 | ||||
| -rw-r--r-- | src/common/emu_window.h | 65 |
2 files changed, 101 insertions, 19 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 | ||
| 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; |
| 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 | */ | ||
| 23 | static 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 | |||
| 31 | void 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 | ||
| 20 | EmuWindow::FramebufferLayout EmuWindow::FramebufferLayout::DefaultScreenLayout(unsigned width, unsigned height) { | 44 | void EmuWindow::TouchReleased() { |
| 45 | touch_pressed = false; | ||
| 46 | touch_x = 0; | ||
| 47 | touch_y = 0; | ||
| 48 | pad_state.touch = 0; | ||
| 49 | } | ||
| 50 | |||
| 51 | void 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 | |||
| 61 | EmuWindow::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 | ||
diff --git a/src/common/emu_window.h b/src/common/emu_window.h index f6099fdb6..2be7517bc 100644 --- a/src/common/emu_window.h +++ b/src/common/emu_window.h | |||
| @@ -71,10 +71,48 @@ public: | |||
| 71 | virtual void ReloadSetKeymaps() = 0; | 71 | virtual void ReloadSetKeymaps() = 0; |
| 72 | 72 | ||
| 73 | /// Signals a key press action to the HID module | 73 | /// Signals a key press action to the HID module |
| 74 | static void KeyPressed(KeyMap::HostDeviceKey key); | 74 | void KeyPressed(KeyMap::HostDeviceKey key); |
| 75 | 75 | ||
| 76 | /// Signals a key release action to the HID module | 76 | /// Signals a key release action to the HID module |
| 77 | static void KeyReleased(KeyMap::HostDeviceKey key); | 77 | void KeyReleased(KeyMap::HostDeviceKey key); |
| 78 | |||
| 79 | /** | ||
| 80 | * Signal that a touch pressed event has occurred (e.g. mouse click pressed) | ||
| 81 | * @param framebuffer_x Framebuffer x-coordinate that was pressed | ||
| 82 | * @param framebuffer_y Framebuffer y-coordinate that was pressed | ||
| 83 | */ | ||
| 84 | void TouchPressed(unsigned framebuffer_x, unsigned framebuffer_y); | ||
| 85 | |||
| 86 | /// Signal that a touch released event has occurred (e.g. mouse click released) | ||
| 87 | void TouchReleased(); | ||
| 88 | |||
| 89 | /** | ||
| 90 | * Signal that a touch movement event has occurred (e.g. mouse was moved over the emu window) | ||
| 91 | * @param framebuffer_x Framebuffer x-coordinate | ||
| 92 | * @param framebuffer_y Framebuffer y-coordinate | ||
| 93 | */ | ||
| 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 | } | ||
| 78 | 116 | ||
| 79 | /** | 117 | /** |
| 80 | * Returns currently active configuration. | 118 | * Returns currently active configuration. |
| @@ -100,21 +138,15 @@ public: | |||
| 100 | return framebuffer_layout; | 138 | return framebuffer_layout; |
| 101 | } | 139 | } |
| 102 | 140 | ||
| 103 | /** | ||
| 104 | * Gets window client area width in logical coordinates. | ||
| 105 | * @note For high-DPI systems, this is smaller than the framebuffer size. | ||
| 106 | * @note This method is thread-safe | ||
| 107 | */ | ||
| 108 | std::pair<unsigned,unsigned> GetClientAreaSize() const { | ||
| 109 | return std::make_pair(client_area_width, client_area_height); | ||
| 110 | } | ||
| 111 | |||
| 112 | protected: | 141 | protected: |
| 113 | EmuWindow() | 142 | EmuWindow() { |
| 114 | { | ||
| 115 | // TODO: Find a better place to set this. | 143 | // TODO: Find a better place to set this. |
| 116 | config.min_client_area_size = std::make_pair(400u, 480u); | 144 | config.min_client_area_size = std::make_pair(400u, 480u); |
| 117 | active_config = config; | 145 | active_config = config; |
| 146 | pad_state.hex = 0; | ||
| 147 | touch_x = 0; | ||
| 148 | touch_y = 0; | ||
| 149 | touch_pressed = false; | ||
| 118 | } | 150 | } |
| 119 | virtual ~EmuWindow() {} | 151 | virtual ~EmuWindow() {} |
| 120 | 152 | ||
| @@ -168,4 +200,11 @@ private: | |||
| 168 | 200 | ||
| 169 | WindowConfig config; ///< Internal configuration (changes pending for being applied in ProcessConfigurationChanges) | 201 | WindowConfig config; ///< Internal configuration (changes pending for being applied in ProcessConfigurationChanges) |
| 170 | WindowConfig active_config; ///< Internal active configuration | 202 | WindowConfig active_config; ///< Internal active configuration |
| 203 | |||
| 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; | ||
| 171 | }; | 210 | }; |