diff options
| author | Léo Lam <leo@innovatetechnologi.es> | 2019-05-20 18:29:31 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-05-20 18:29:31 +0200 |
| commit | e2c769a9c5afa9171f45d36ee39a0c176f24ee13 (patch) | |
| tree | 75169f15256598c785e39f615ba2b21c49b6f62b /Source/Core/InputCommon/ControllerEmu/StickGate.cpp | |
| parent | d2c7a6f2392c79fc447de825fb752305b04df41b (diff) | |
| parent | 4bbbd02de79973b8c69d3fa8a53ad90dd8695c16 (diff) | |
Merge pull request #7992 from artemist/centering
ControllerEmu: Add support for setting the center of a ReshapableInput
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; |
