diff options
| author | Artemis Tosini <me@artem.ist> | 2019-04-12 20:26:34 +0000 |
|---|---|---|
| committer | Artemis Tosini <me@artem.ist> | 2019-05-18 14:45:16 +0000 |
| commit | 49e46c8aff1db605c5456997d5d94ac40d6e7869 (patch) | |
| tree | 8a3fe8253e5d1b10473b0a5f2692f83ef825d8f3 /Source/Core/InputCommon/ControllerEmu/StickGate.cpp | |
| parent | d60b0c6b3732ef567a74f168020a25f5c87cd69a (diff) | |
ControllerEmu: Add support for setting the center of a ReshapableInput
This is useful in far out-of-calibration controllers, such as the
Switch Pro controller. This also adds support for configuring the center
in the Mapping widget.
Diffstat (limited to 'Source/Core/InputCommon/ControllerEmu/StickGate.cpp')
| -rw-r--r-- | Source/Core/InputCommon/ControllerEmu/StickGate.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/Source/Core/InputCommon/ControllerEmu/StickGate.cpp b/Source/Core/InputCommon/ControllerEmu/StickGate.cpp index 70ed383398..6fc0a4ea4f 100644 --- a/Source/Core/InputCommon/ControllerEmu/StickGate.cpp +++ b/Source/Core/InputCommon/ControllerEmu/StickGate.cpp @@ -20,6 +20,9 @@ constexpr auto CALIBRATION_CONFIG_NAME = "Calibration"; constexpr auto CALIBRATION_DEFAULT_VALUE = 1.0; constexpr auto CALIBRATION_CONFIG_SCALE = 100; +constexpr auto CENTER_CONFIG_NAME = "Center"; +constexpr auto CENTER_CONFIG_SCALE = 100; + // Calculate distance to intersection of a ray with a line defined by two points. double GetRayLineIntersection(Common::DVec2 ray, Common::DVec2 point1, Common::DVec2 point2) { @@ -214,6 +217,16 @@ void ReshapableInput::SetCalibrationData(CalibrationData data) m_calibration = std::move(data); } +const ReshapableInput::ReshapeData& ReshapableInput::GetCenter() const +{ + return m_center; +} + +void ReshapableInput::SetCenter(ReshapableInput::ReshapeData center) +{ + m_center = center; +} + void ReshapableInput::LoadConfig(IniFile::Section* section, const std::string& default_device, const std::string& base_name) { @@ -232,6 +245,20 @@ void ReshapableInput::LoadConfig(IniFile::Section* section, const std::string& d if (TryParse(*(it++), &sample)) sample /= CALIBRATION_CONFIG_SCALE; } + + section->Get(group + CENTER_CONFIG_NAME, &load_str, ""); + const auto center_data = SplitString(load_str, ' '); + + m_center = Common::DVec2(); + + if (center_data.size() == 2) + { + if (TryParse(center_data[0], &m_center.x)) + m_center.x /= CENTER_CONFIG_SCALE; + + if (TryParse(center_data[1], &m_center.y)) + m_center.y /= CENTER_CONFIG_SCALE; + } } void ReshapableInput::SaveConfig(IniFile::Section* section, const std::string& default_device, @@ -245,11 +272,19 @@ void ReshapableInput::SaveConfig(IniFile::Section* section, const std::string& d m_calibration.begin(), m_calibration.end(), save_data.begin(), [](ControlState val) { return StringFromFormat("%.2f", val * CALIBRATION_CONFIG_SCALE); }); section->Set(group + CALIBRATION_CONFIG_NAME, JoinStrings(save_data, " "), ""); + + const auto center_data = StringFromFormat("%.2f %.2f", m_center.x * CENTER_CONFIG_SCALE, + m_center.y * CENTER_CONFIG_SCALE); + + section->Set(group + CENTER_CONFIG_NAME, center_data, ""); } ReshapableInput::ReshapeData ReshapableInput::Reshape(ControlState x, ControlState y, ControlState modifier) { + x -= m_center.x; + y -= m_center.y; + // TODO: make the AtAngle functions work with negative angles: const ControlState angle = std::atan2(y, x) + MathUtil::TAU; |
