diff options
Diffstat (limited to 'src/input_common/drivers/touch_screen.h')
| -rw-r--r-- | src/input_common/drivers/touch_screen.h | 52 |
1 files changed, 38 insertions, 14 deletions
diff --git a/src/input_common/drivers/touch_screen.h b/src/input_common/drivers/touch_screen.h index 193478ead..f46036ffd 100644 --- a/src/input_common/drivers/touch_screen.h +++ b/src/input_common/drivers/touch_screen.h | |||
| @@ -3,41 +3,65 @@ | |||
| 3 | 3 | ||
| 4 | #pragma once | 4 | #pragma once |
| 5 | 5 | ||
| 6 | #include <optional> | ||
| 7 | |||
| 6 | #include "input_common/input_engine.h" | 8 | #include "input_common/input_engine.h" |
| 7 | 9 | ||
| 8 | namespace InputCommon { | 10 | namespace InputCommon { |
| 9 | 11 | ||
| 10 | /** | 12 | /** |
| 11 | * A button device factory representing a keyboard. It receives keyboard events and forward them | 13 | * A touch device factory representing a touch screen. It receives touch events and forward them |
| 12 | * to all button devices it created. | 14 | * to all touch devices it created. |
| 13 | */ | 15 | */ |
| 14 | class TouchScreen final : public InputEngine { | 16 | class TouchScreen final : public InputEngine { |
| 15 | public: | 17 | public: |
| 16 | explicit TouchScreen(std::string input_engine_); | 18 | explicit TouchScreen(std::string input_engine_); |
| 17 | 19 | ||
| 18 | /** | 20 | /** |
| 19 | * Signals that mouse has moved. | 21 | * Signals that touch has moved and marks this touch point as active |
| 20 | * @param x the x-coordinate of the cursor | 22 | * @param x new horizontal position |
| 21 | * @param y the y-coordinate of the cursor | 23 | * @param y new vertical position |
| 22 | * @param center_x the x-coordinate of the middle of the screen | 24 | * @param finger_id of the touch point to be updated |
| 23 | * @param center_y the y-coordinate of the middle of the screen | ||
| 24 | */ | 25 | */ |
| 25 | void TouchMoved(float x, float y, std::size_t finger); | 26 | void TouchMoved(float x, float y, std::size_t finger_id); |
| 26 | 27 | ||
| 27 | /** | 28 | /** |
| 28 | * Sets the status of all buttons bound with the key to pressed | 29 | * Signals and creates a new touch point with this finger id |
| 29 | * @param key_code the code of the key to press | 30 | * @param x starting horizontal position |
| 31 | * @param y starting vertical position | ||
| 32 | * @param finger_id to be assigned to the new touch point | ||
| 30 | */ | 33 | */ |
| 31 | void TouchPressed(float x, float y, std::size_t finger); | 34 | void TouchPressed(float x, float y, std::size_t finger_id); |
| 32 | 35 | ||
| 33 | /** | 36 | /** |
| 34 | * Sets the status of all buttons bound with the key to released | 37 | * Signals and resets the touch point related to the this finger id |
| 35 | * @param key_code the code of the key to release | 38 | * @param finger_id to be released |
| 36 | */ | 39 | */ |
| 37 | void TouchReleased(std::size_t finger); | 40 | void TouchReleased(std::size_t finger_id); |
| 41 | |||
| 42 | /// Resets the active flag for each touch point | ||
| 43 | void ClearActiveFlag(); | ||
| 44 | |||
| 45 | /// Releases all touch that haven't been marked as active | ||
| 46 | void ReleaseInactiveTouch(); | ||
| 38 | 47 | ||
| 39 | /// Resets all inputs to their initial value | 48 | /// Resets all inputs to their initial value |
| 40 | void ReleaseAllTouch(); | 49 | void ReleaseAllTouch(); |
| 50 | |||
| 51 | private: | ||
| 52 | static constexpr std::size_t MAX_FINGER_COUNT = 16; | ||
| 53 | |||
| 54 | struct TouchStatus { | ||
| 55 | std::size_t finger_id{}; | ||
| 56 | bool is_enabled{}; | ||
| 57 | bool is_active{}; | ||
| 58 | }; | ||
| 59 | |||
| 60 | std::optional<std::size_t> GetIndexFromFingerId(std::size_t finger_id) const; | ||
| 61 | |||
| 62 | std::optional<std::size_t> GetNextFreeIndex() const; | ||
| 63 | |||
| 64 | std::array<TouchStatus, MAX_FINGER_COUNT> fingers{}; | ||
| 41 | }; | 65 | }; |
| 42 | 66 | ||
| 43 | } // namespace InputCommon | 67 | } // namespace InputCommon |