| e8555c89 Andy McCall |
1 |
#ifndef ANALOG_INPUT_HH |
| 2 |
#define ANALOG_INPUT_HH |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
#include "Event.hh" |
| 11 |
#include "JoystickId.hh" |
| 12 |
|
| 13 |
#include "function_ref.hh" |
| 14 |
|
| 15 |
#include <SDL.h> |
| 16 |
|
| 17 |
#include <cstdint> |
| 18 |
#include <optional> |
| 19 |
#include <string> |
| 20 |
#include <string_view> |
| 21 |
#include <variant> |
| 22 |
|
| 23 |
namespace openmsx { |
| 24 |
|
| 25 |
class AnalogMouseAxis |
| 26 |
{ |
| 27 |
public: |
| 28 |
|
| 29 |
explicit AnalogMouseAxis(uint8_t axis_) |
| 30 |
: axis(axis_) {} |
| 31 |
|
| 32 |
[[nodiscard]] auto getAxis() const { return axis; } |
| 33 |
|
| 34 |
private: |
| 35 |
uint8_t axis; |
| 36 |
}; |
| 37 |
|
| 38 |
class AnalogJoystickAxis |
| 39 |
{ |
| 40 |
public: |
| 41 |
explicit AnalogJoystickAxis(JoystickId joystick_, uint8_t axis_) |
| 42 |
: joystick(joystick_), axis(axis_) {} |
| 43 |
|
| 44 |
[[nodiscard]] auto getJoystick() const { return joystick; } |
| 45 |
[[nodiscard]] auto getAxis() const { return axis; } |
| 46 |
|
| 47 |
private: |
| 48 |
JoystickId joystick; |
| 49 |
uint8_t axis; |
| 50 |
}; |
| 51 |
|
| 52 |
|
| 53 |
using AnalogInput = std::variant< |
| 54 |
AnalogMouseAxis, |
| 55 |
AnalogJoystickAxis>; |
| 56 |
|
| 57 |
|
| 58 |
[[nodiscard]] std::string toString(const AnalogInput& input); |
| 59 |
[[nodiscard]] std::optional<AnalogInput> parseAnalogInput(std::string_view text); |
| 60 |
[[nodiscard]] std::optional<AnalogInput> captureAnalogInput(const Event& event, function_ref<int(JoystickId)> getJoyDeadThreshold); |
| 61 |
|
| 62 |
[[nodiscard]] bool operator==(const AnalogInput& x, const AnalogInput& y); |
| 63 |
|
| 64 |
[[nodiscard]] std::optional<float> match( |
| 65 |
const AnalogInput& binding, const Event& event, |
| 66 |
function_ref<float(JoystickId, const JoystickAxisMotionEvent&)> getJoyValue); |
| 67 |
|
| 68 |
} |
| 69 |
|
| 70 |
#endif |