mirror of
https://github.com/WinampDesktop/winamp.git
synced 2025-06-10 20:05:47 -04:00
Controller: Support general axis input events
This commit is contained in:
@ -21,6 +21,8 @@ bool Controller::Transfer(const u8 data_in, u8* data_out)
|
||||
return false;
|
||||
}
|
||||
|
||||
void Controller::SetAxisState(s32 axis_code, float value) {}
|
||||
|
||||
void Controller::SetButtonState(s32 button_code, bool pressed) {}
|
||||
|
||||
std::unique_ptr<Controller> Controller::Create(ControllerType type)
|
||||
@ -38,6 +40,24 @@ std::unique_ptr<Controller> Controller::Create(ControllerType type)
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<s32> Controller::GetAxisCodeByName(std::string_view button_name) const
|
||||
{
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<s32> Controller::GetAxisCodeByName(ControllerType type, std::string_view axis_name)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case ControllerType::DigitalController:
|
||||
return DigitalController::StaticGetAxisCodeByName(axis_name);
|
||||
|
||||
case ControllerType::None:
|
||||
default:
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<s32> Controller::GetButtonCodeByName(ControllerType type, std::string_view button_name)
|
||||
{
|
||||
switch (type)
|
||||
|
@ -15,6 +15,9 @@ public:
|
||||
/// Returns the type of controller.
|
||||
virtual ControllerType GetType() const = 0;
|
||||
|
||||
/// Gets the integer code for an axis in the specified controller type.
|
||||
virtual std::optional<s32> GetAxisCodeByName(std::string_view axis_name) const;
|
||||
|
||||
/// Gets the integer code for a button in the specified controller type.
|
||||
virtual std::optional<s32> GetButtonCodeByName(std::string_view button_name) const;
|
||||
|
||||
@ -27,12 +30,18 @@ public:
|
||||
// Returns the value of ACK, as well as filling out_data.
|
||||
virtual bool Transfer(const u8 data_in, u8* data_out);
|
||||
|
||||
/// Changes the specified axis state. Values are normalized from -1..1.
|
||||
virtual void SetAxisState(s32 axis_code, float value);
|
||||
|
||||
/// Changes the specified button state.
|
||||
virtual void SetButtonState(s32 button_code, bool pressed);
|
||||
|
||||
/// Creates a new controller of the specified type.
|
||||
static std::unique_ptr<Controller> Create(ControllerType type);
|
||||
|
||||
/// Gets the integer code for an axis in the specified controller type.
|
||||
static std::optional<s32> GetAxisCodeByName(ControllerType type, std::string_view axis_name);
|
||||
|
||||
/// Gets the integer code for a button in the specified controller type.
|
||||
static std::optional<s32> GetButtonCodeByName(ControllerType type, std::string_view button_name);
|
||||
};
|
||||
|
@ -11,11 +11,18 @@ ControllerType DigitalController::GetType() const
|
||||
return ControllerType::DigitalController;
|
||||
}
|
||||
|
||||
std::optional<s32> DigitalController::GetAxisCodeByName(std::string_view axis_name) const
|
||||
{
|
||||
return StaticGetAxisCodeByName(axis_name);
|
||||
}
|
||||
|
||||
std::optional<s32> DigitalController::GetButtonCodeByName(std::string_view button_name) const
|
||||
{
|
||||
return StaticGetButtonCodeByName(button_name);
|
||||
}
|
||||
|
||||
void DigitalController::SetAxisState(s32 axis_code, float value) {}
|
||||
|
||||
void DigitalController::SetButtonState(Button button, bool pressed)
|
||||
{
|
||||
if (pressed)
|
||||
@ -91,6 +98,11 @@ std::unique_ptr<DigitalController> DigitalController::Create()
|
||||
return std::make_unique<DigitalController>();
|
||||
}
|
||||
|
||||
std::optional<s32> DigitalController::StaticGetAxisCodeByName(std::string_view button_name)
|
||||
{
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<s32> DigitalController::StaticGetButtonCodeByName(std::string_view button_name)
|
||||
{
|
||||
#define BUTTON(name) \
|
||||
|
@ -32,17 +32,21 @@ public:
|
||||
~DigitalController() override;
|
||||
|
||||
static std::unique_ptr<DigitalController> Create();
|
||||
static std::optional<s32> StaticGetAxisCodeByName(std::string_view button_name);
|
||||
static std::optional<s32> StaticGetButtonCodeByName(std::string_view button_name);
|
||||
|
||||
ControllerType GetType() const override;
|
||||
std::optional<s32> GetAxisCodeByName(std::string_view axis_name) const override;
|
||||
std::optional<s32> GetButtonCodeByName(std::string_view button_name) const override;
|
||||
|
||||
void SetButtonState(Button button, bool pressed);
|
||||
void SetButtonState(s32 button_code, bool pressed);
|
||||
void SetAxisState(s32 axis_code, float value) override;
|
||||
void SetButtonState(s32 button_code, bool pressed) override;
|
||||
|
||||
void ResetTransferState() override;
|
||||
bool Transfer(const u8 data_in, u8* data_out) override;
|
||||
|
||||
void SetButtonState(Button button, bool pressed);
|
||||
|
||||
private:
|
||||
enum class TransferState : u8
|
||||
{
|
||||
|
Reference in New Issue
Block a user