2020-12-28 19:15:37 +04:00
|
|
|
// Copyright 2017 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace Common {
|
|
|
|
class ParamPackage;
|
|
|
|
}
|
|
|
|
|
2021-11-22 01:14:21 +04:00
|
|
|
namespace Common::Input {
|
|
|
|
enum class ButtonNames;
|
|
|
|
}
|
|
|
|
|
2020-12-28 19:15:37 +04:00
|
|
|
namespace Settings::NativeAnalog {
|
|
|
|
enum Values : int;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace Settings::NativeButton {
|
|
|
|
enum Values : int;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace Settings::NativeMotion {
|
|
|
|
enum Values : int;
|
|
|
|
}
|
|
|
|
|
2021-11-15 05:13:48 +04:00
|
|
|
namespace InputCommon {
|
|
|
|
class Keyboard;
|
2020-12-28 19:15:37 +04:00
|
|
|
class Mouse;
|
2021-11-15 05:13:48 +04:00
|
|
|
class TouchScreen;
|
|
|
|
struct MappingData;
|
|
|
|
} // namespace InputCommon
|
2020-12-28 19:15:37 +04:00
|
|
|
|
2021-11-15 05:13:48 +04:00
|
|
|
namespace InputCommon::TasInput {
|
2021-07-26 05:00:19 +04:00
|
|
|
class Tas;
|
2021-11-15 05:13:48 +04:00
|
|
|
} // namespace InputCommon::TasInput
|
2021-07-26 05:00:19 +04:00
|
|
|
|
2020-12-28 19:15:37 +04:00
|
|
|
namespace InputCommon {
|
|
|
|
namespace Polling {
|
2021-11-15 05:13:48 +04:00
|
|
|
/// Type of input desired for mapping purposes
|
|
|
|
enum class InputType { None, Button, Stick, Motion, Touch };
|
2020-12-28 19:15:37 +04:00
|
|
|
} // namespace Polling
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given a ParamPackage for a Device returned from `GetInputDevices`, attempt to get the default
|
2021-11-15 05:13:48 +04:00
|
|
|
* mapping for the device.
|
2020-12-28 19:15:37 +04:00
|
|
|
*/
|
|
|
|
using AnalogMapping = std::unordered_map<Settings::NativeAnalog::Values, Common::ParamPackage>;
|
|
|
|
using ButtonMapping = std::unordered_map<Settings::NativeButton::Values, Common::ParamPackage>;
|
|
|
|
using MotionMapping = std::unordered_map<Settings::NativeMotion::Values, Common::ParamPackage>;
|
|
|
|
|
|
|
|
class InputSubsystem {
|
|
|
|
public:
|
|
|
|
explicit InputSubsystem();
|
|
|
|
~InputSubsystem();
|
|
|
|
|
|
|
|
InputSubsystem(const InputSubsystem&) = delete;
|
|
|
|
InputSubsystem& operator=(const InputSubsystem&) = delete;
|
|
|
|
|
|
|
|
InputSubsystem(InputSubsystem&&) = delete;
|
|
|
|
InputSubsystem& operator=(InputSubsystem&&) = delete;
|
|
|
|
|
|
|
|
/// Initializes and registers all built-in input device factories.
|
|
|
|
void Initialize();
|
|
|
|
|
|
|
|
/// Unregisters all built-in input device factories and shuts them down.
|
|
|
|
void Shutdown();
|
|
|
|
|
|
|
|
/// Retrieves the underlying keyboard device.
|
|
|
|
[[nodiscard]] Keyboard* GetKeyboard();
|
|
|
|
|
|
|
|
/// Retrieves the underlying keyboard device.
|
|
|
|
[[nodiscard]] const Keyboard* GetKeyboard() const;
|
|
|
|
|
|
|
|
/// Retrieves the underlying mouse device.
|
2021-11-15 05:13:48 +04:00
|
|
|
[[nodiscard]] Mouse* GetMouse();
|
2020-12-28 19:15:37 +04:00
|
|
|
|
|
|
|
/// Retrieves the underlying mouse device.
|
2021-11-15 05:13:48 +04:00
|
|
|
[[nodiscard]] const Mouse* GetMouse() const;
|
2020-12-28 19:15:37 +04:00
|
|
|
|
2021-11-15 05:13:48 +04:00
|
|
|
/// Retrieves the underlying touch screen device.
|
|
|
|
[[nodiscard]] TouchScreen* GetTouchScreen();
|
|
|
|
|
|
|
|
/// Retrieves the underlying touch screen device.
|
|
|
|
[[nodiscard]] const TouchScreen* GetTouchScreen() const;
|
|
|
|
|
|
|
|
/// Retrieves the underlying tas input device.
|
2021-07-26 05:00:19 +04:00
|
|
|
[[nodiscard]] TasInput::Tas* GetTas();
|
|
|
|
|
2021-11-15 05:13:48 +04:00
|
|
|
/// Retrieves the underlying tas input device.
|
2021-07-26 05:00:19 +04:00
|
|
|
[[nodiscard]] const TasInput::Tas* GetTas() const;
|
2021-11-15 05:13:48 +04:00
|
|
|
|
2020-12-28 19:15:37 +04:00
|
|
|
/**
|
|
|
|
* Returns all available input devices that this Factory can create a new device with.
|
2021-11-15 05:13:48 +04:00
|
|
|
* Each returned ParamPackage should have a `display` field used for display, a `engine` field
|
|
|
|
* for backends to determine if this backend is meant to service the request and any other
|
2020-12-28 19:15:37 +04:00
|
|
|
* information needed to identify this in the backend later.
|
|
|
|
*/
|
|
|
|
[[nodiscard]] std::vector<Common::ParamPackage> GetInputDevices() const;
|
|
|
|
|
|
|
|
/// Retrieves the analog mappings for the given device.
|
|
|
|
[[nodiscard]] AnalogMapping GetAnalogMappingForDevice(const Common::ParamPackage& device) const;
|
|
|
|
|
|
|
|
/// Retrieves the button mappings for the given device.
|
|
|
|
[[nodiscard]] ButtonMapping GetButtonMappingForDevice(const Common::ParamPackage& device) const;
|
|
|
|
|
|
|
|
/// Retrieves the motion mappings for the given device.
|
|
|
|
[[nodiscard]] MotionMapping GetMotionMappingForDevice(const Common::ParamPackage& device) const;
|
|
|
|
|
2021-11-22 01:14:21 +04:00
|
|
|
/// Returns an enum contaning the name to be displayed from the input engine.
|
|
|
|
[[nodiscard]] Common::Input::ButtonNames GetButtonName(
|
|
|
|
const Common::ParamPackage& params) const;
|
2020-12-28 19:15:37 +04:00
|
|
|
|
2021-11-15 05:13:48 +04:00
|
|
|
/// Returns true if device is a controller.
|
|
|
|
[[nodiscard]] bool IsController(const Common::ParamPackage& params) const;
|
2021-07-26 05:00:19 +04:00
|
|
|
|
2021-11-15 05:13:48 +04:00
|
|
|
/// Reloads the input devices.
|
|
|
|
void ReloadInputDevices();
|
2021-11-15 02:19:09 +04:00
|
|
|
|
2021-11-15 05:13:48 +04:00
|
|
|
/// Start polling from all backends for a desired input type.
|
|
|
|
void BeginMapping(Polling::InputType type);
|
2021-11-15 02:19:09 +04:00
|
|
|
|
2021-11-15 05:13:48 +04:00
|
|
|
/// Returns an input event with mapping information.
|
|
|
|
[[nodiscard]] const Common::ParamPackage GetNextInput() const;
|
2021-11-15 02:19:09 +04:00
|
|
|
|
2021-11-15 05:13:48 +04:00
|
|
|
/// Stop polling from all backends.
|
|
|
|
void StopMapping() const;
|
2020-12-28 19:15:37 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
struct Impl;
|
|
|
|
std::unique_ptr<Impl> impl;
|
|
|
|
};
|
|
|
|
|
2021-11-15 05:13:48 +04:00
|
|
|
/// Generates a serialized param package for creating a keyboard button device.
|
2020-12-28 19:15:37 +04:00
|
|
|
std::string GenerateKeyboardParam(int key_code);
|
|
|
|
|
2021-11-15 05:13:48 +04:00
|
|
|
/// Generates a serialized param package for creating an analog device taking input from keyboard.
|
2020-12-28 19:15:37 +04:00
|
|
|
std::string GenerateAnalogParamFromKeys(int key_up, int key_down, int key_left, int key_right,
|
|
|
|
int key_modifier, float modifier_scale);
|
|
|
|
} // namespace InputCommon
|