diff options
Diffstat (limited to '')
| -rw-r--r-- | src/input_common/sdl/sdl_impl.cpp | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/input_common/sdl/sdl_impl.cpp b/src/input_common/sdl/sdl_impl.cpp index 7827e324c..0b531f698 100644 --- a/src/input_common/sdl/sdl_impl.cpp +++ b/src/input_common/sdl/sdl_impl.cpp | |||
| @@ -352,13 +352,20 @@ private: | |||
| 352 | class SDLAnalog final : public Input::AnalogDevice { | 352 | class SDLAnalog final : public Input::AnalogDevice { |
| 353 | public: | 353 | public: |
| 354 | explicit SDLAnalog(std::shared_ptr<SDLJoystick> joystick_, int axis_x_, int axis_y_, | 354 | explicit SDLAnalog(std::shared_ptr<SDLJoystick> joystick_, int axis_x_, int axis_y_, |
| 355 | float deadzone_, float range_) | 355 | bool invert_x_, bool invert_y_, float deadzone_, float range_) |
| 356 | : joystick(std::move(joystick_)), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_), | 356 | : joystick(std::move(joystick_)), axis_x(axis_x_), axis_y(axis_y_), invert_x(invert_x_), |
| 357 | range(range_) {} | 357 | invert_y(invert_y_), deadzone(deadzone_), range(range_) {} |
| 358 | 358 | ||
| 359 | std::tuple<float, float> GetStatus() const override { | 359 | std::tuple<float, float> GetStatus() const override { |
| 360 | const auto [x, y] = joystick->GetAnalog(axis_x, axis_y, range); | 360 | auto [x, y] = joystick->GetAnalog(axis_x, axis_y, range); |
| 361 | const float r = std::sqrt((x * x) + (y * y)); | 361 | const float r = std::sqrt((x * x) + (y * y)); |
| 362 | if (invert_x) { | ||
| 363 | x = -x; | ||
| 364 | } | ||
| 365 | if (invert_y) { | ||
| 366 | y = -y; | ||
| 367 | } | ||
| 368 | |||
| 362 | if (r > deadzone) { | 369 | if (r > deadzone) { |
| 363 | return std::make_tuple(x / r * (r - deadzone) / (1 - deadzone), | 370 | return std::make_tuple(x / r * (r - deadzone) / (1 - deadzone), |
| 364 | y / r * (r - deadzone) / (1 - deadzone)); | 371 | y / r * (r - deadzone) / (1 - deadzone)); |
| @@ -386,6 +393,8 @@ private: | |||
| 386 | std::shared_ptr<SDLJoystick> joystick; | 393 | std::shared_ptr<SDLJoystick> joystick; |
| 387 | const int axis_x; | 394 | const int axis_x; |
| 388 | const int axis_y; | 395 | const int axis_y; |
| 396 | const bool invert_x; | ||
| 397 | const bool invert_y; | ||
| 389 | const float deadzone; | 398 | const float deadzone; |
| 390 | const float range; | 399 | const float range; |
| 391 | }; | 400 | }; |
| @@ -572,12 +581,17 @@ public: | |||
| 572 | const int axis_y = params.Get("axis_y", 1); | 581 | const int axis_y = params.Get("axis_y", 1); |
| 573 | const float deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f); | 582 | const float deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f); |
| 574 | const float range = std::clamp(params.Get("range", 1.0f), 0.50f, 1.50f); | 583 | const float range = std::clamp(params.Get("range", 1.0f), 0.50f, 1.50f); |
| 584 | const std::string invert_x_value = params.Get("invert_x", "+"); | ||
| 585 | const std::string invert_y_value = params.Get("invert_y", "+"); | ||
| 586 | const bool invert_x = invert_x_value == "-"; | ||
| 587 | const bool invert_y = invert_y_value == "-"; | ||
| 575 | auto joystick = state.GetSDLJoystickByGUID(guid, port); | 588 | auto joystick = state.GetSDLJoystickByGUID(guid, port); |
| 576 | 589 | ||
| 577 | // This is necessary so accessing GetAxis with axis_x and axis_y won't crash | 590 | // This is necessary so accessing GetAxis with axis_x and axis_y won't crash |
| 578 | joystick->SetAxis(axis_x, 0); | 591 | joystick->SetAxis(axis_x, 0); |
| 579 | joystick->SetAxis(axis_y, 0); | 592 | joystick->SetAxis(axis_y, 0); |
| 580 | return std::make_unique<SDLAnalog>(joystick, axis_x, axis_y, deadzone, range); | 593 | return std::make_unique<SDLAnalog>(joystick, axis_x, axis_y, invert_x, invert_y, deadzone, |
| 594 | range); | ||
| 581 | } | 595 | } |
| 582 | 596 | ||
| 583 | private: | 597 | private: |
| @@ -886,6 +900,8 @@ Common::ParamPackage BuildParamPackageForAnalog(int port, const std::string& gui | |||
| 886 | params.Set("guid", guid); | 900 | params.Set("guid", guid); |
| 887 | params.Set("axis_x", axis_x); | 901 | params.Set("axis_x", axis_x); |
| 888 | params.Set("axis_y", axis_y); | 902 | params.Set("axis_y", axis_y); |
| 903 | params.Set("invert_x", "+"); | ||
| 904 | params.Set("invert_y", "+"); | ||
| 889 | return params; | 905 | return params; |
| 890 | } | 906 | } |
| 891 | } // Anonymous namespace | 907 | } // Anonymous namespace |