mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-22 22:00:39 -06:00
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.
This commit is contained in:
@ -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;
|
||||
|
||||
|
@ -97,6 +97,9 @@ public:
|
||||
const CalibrationData& GetCalibrationData() const;
|
||||
void SetCalibrationData(CalibrationData data);
|
||||
|
||||
const ReshapeData& GetCenter() const;
|
||||
void SetCenter(ReshapeData center);
|
||||
|
||||
protected:
|
||||
ReshapeData Reshape(ControlState x, ControlState y, ControlState modifier = 0.0);
|
||||
|
||||
@ -106,6 +109,7 @@ private:
|
||||
|
||||
CalibrationData m_calibration;
|
||||
SettingValue<double> m_deadzone_setting;
|
||||
ReshapeData m_center;
|
||||
};
|
||||
|
||||
} // namespace ControllerEmu
|
||||
|
Reference in New Issue
Block a user