2
1
Fork 0
mirror of https://github.com/yuzu-emu/yuzu.git synced 2024-07-04 23:31:19 +01:00
yuzu/src/input_common/drivers/touch_screen.h

68 lines
1.8 KiB
C++
Raw Normal View History

// 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
#include <optional>
2021-09-20 23:20:56 +01:00
#include "input_common/input_engine.h"
namespace InputCommon {
/**
* 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
*/
class TouchScreen final : public InputEngine {
2021-09-20 23:20:56 +01:00
public:
explicit TouchScreen(std::string input_engine_);
2021-09-20 23:20:56 +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
*/
void TouchMoved(float x, float y, std::size_t finger_id);
2021-09-20 23:20:56 +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
*/
void TouchPressed(float x, float y, std::size_t finger_id);
2021-09-20 23:20:56 +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
*/
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();
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