2022-04-23 09:59:50 +01:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2021-09-20 23:20:56 +01:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2022-05-23 02:34:32 +01:00
|
|
|
#include <optional>
|
|
|
|
|
2021-09-20 23:20:56 +01:00
|
|
|
#include "input_common/input_engine.h"
|
|
|
|
|
|
|
|
namespace InputCommon {
|
|
|
|
|
|
|
|
/**
|
2022-05-23 02:34:32 +01:00
|
|
|
* A touch device factory representing a touch screen. It receives touch events and forward them
|
|
|
|
* to all touch devices it created.
|
2021-09-20 23:20:56 +01:00
|
|
|
*/
|
2021-12-13 14:05:23 +00:00
|
|
|
class TouchScreen final : public InputEngine {
|
2021-09-20 23:20:56 +01:00
|
|
|
public:
|
2021-12-13 14:05:23 +00:00
|
|
|
explicit TouchScreen(std::string input_engine_);
|
2021-09-20 23:20:56 +01:00
|
|
|
|
|
|
|
/**
|
2022-05-23 02:34:32 +01:00
|
|
|
* Signals that touch has moved and marks this touch point as active
|
|
|
|
* @param x new horizontal position
|
|
|
|
* @param y new vertical position
|
|
|
|
* @param finger_id of the touch point to be updated
|
2021-09-20 23:20:56 +01:00
|
|
|
*/
|
2022-05-23 02:34:32 +01:00
|
|
|
void TouchMoved(float x, float y, std::size_t finger_id);
|
2021-09-20 23:20:56 +01:00
|
|
|
|
|
|
|
/**
|
2022-05-23 02:34:32 +01:00
|
|
|
* Signals and creates a new touch point with this finger id
|
|
|
|
* @param x starting horizontal position
|
|
|
|
* @param y starting vertical position
|
|
|
|
* @param finger_id to be assigned to the new touch point
|
2021-09-20 23:20:56 +01:00
|
|
|
*/
|
2022-05-23 02:34:32 +01:00
|
|
|
void TouchPressed(float x, float y, std::size_t finger_id);
|
2021-09-20 23:20:56 +01:00
|
|
|
|
|
|
|
/**
|
2022-05-23 02:34:32 +01:00
|
|
|
* Signals and resets the touch point related to the this finger id
|
|
|
|
* @param finger_id to be released
|
2021-09-20 23:20:56 +01:00
|
|
|
*/
|
2022-05-23 02:34:32 +01:00
|
|
|
void TouchReleased(std::size_t finger_id);
|
|
|
|
|
|
|
|
/// Resets the active flag for each touch point
|
|
|
|
void ClearActiveFlag();
|
|
|
|
|
|
|
|
/// Releases all touch that haven't been marked as active
|
|
|
|
void ReleaseInactiveTouch();
|
2021-09-20 23:20:56 +01:00
|
|
|
|
2021-11-01 20:17:53 +00:00
|
|
|
/// Resets all inputs to their initial value
|
2021-09-20 23:20:56 +01:00
|
|
|
void ReleaseAllTouch();
|
2022-05-23 02:34:32 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
static constexpr std::size_t MAX_FINGER_COUNT = 16;
|
|
|
|
|
|
|
|
struct TouchStatus {
|
|
|
|
std::size_t finger_id{};
|
|
|
|
bool is_enabled{};
|
|
|
|
bool is_active{};
|
|
|
|
};
|
|
|
|
|
|
|
|
std::optional<std::size_t> GetIndexFromFingerId(std::size_t finger_id) const;
|
|
|
|
|
|
|
|
std::optional<std::size_t> GetNextFreeIndex() const;
|
|
|
|
|
|
|
|
std::array<TouchStatus, MAX_FINGER_COUNT> fingers{};
|
2021-09-20 23:20:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace InputCommon
|