Skip to content

Commit

Permalink
ControllerEmu: Do not change center when closing window
Browse files Browse the repository at this point in the history
  • Loading branch information
artemist committed May 19, 2019
1 parent e568398 commit 4bbbd02
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
26 changes: 16 additions & 10 deletions Source/Core/DolphinQt/Config/Mapping/MappingIndicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ void MappingIndicator::DrawReshapableInput(ControllerEmu::ReshapableInput& stick

if (IsCalibrating())
{
DrawCalibration(p, raw_coord, center);
DrawCalibration(p, raw_coord);
return;
}

Expand Down Expand Up @@ -703,10 +703,12 @@ void ShakeMappingIndicator::DrawShake()
p.drawPolyline(polyline);
}
}
void MappingIndicator::DrawCalibration(QPainter& p, Common::DVec2 point, Common::DVec2 center)

void MappingIndicator::DrawCalibration(QPainter& p, Common::DVec2 point)
{
// Bounding box size:
const double scale = GetScale();
const auto center = m_calibration_widget->GetCenter();

// Input shape.
p.setPen(GetInputShapePen());
Expand Down Expand Up @@ -778,8 +780,8 @@ void CalibrationWidget::SetupActions()
const auto reset_action = new QAction(tr("Reset"), this);

connect(calibrate_action, &QAction::triggered, [this]() {
StartCalibration();
m_input.SetCenter({0, 0});
StartCalibration();
m_input.SetCenter({0, 0});
});
connect(center_action, &QAction::triggered, [this]() {
StartCalibration();
Expand All @@ -800,6 +802,7 @@ void CalibrationWidget::SetupActions()

m_completion_action = new QAction(tr("Finish Calibration"), this);
connect(m_completion_action, &QAction::triggered, [this]() {
m_input.SetCenter(m_new_center);
m_input.SetCalibrationData(std::move(m_calibration_data));
m_informative_timer->stop();
SetupActions();
Expand All @@ -808,15 +811,13 @@ void CalibrationWidget::SetupActions()

void CalibrationWidget::StartCalibration()
{
// Set the old center so we can revert
m_old_center = m_input.GetCenter();

m_calibration_data.assign(m_input.CALIBRATION_SAMPLE_COUNT, 0.0);

m_new_center = {0, 0};

// Cancel calibration.
const auto cancel_action = new QAction(tr("Cancel Calibration"), this);
connect(cancel_action, &QAction::triggered, [this]() {
m_input.SetCenter(m_old_center);
m_calibration_data.clear();
m_informative_timer->stop();
SetupActions();
Expand All @@ -840,12 +841,12 @@ void CalibrationWidget::Update(Common::DVec2 point)

if (m_is_centering)
{
m_input.SetCenter(point);
m_new_center = point;
m_is_centering = false;
}
else if (IsCalibrating())
{
m_input.UpdateCalibrationData(m_calibration_data, point - m_input.GetCenter());
m_input.UpdateCalibrationData(m_calibration_data, point - m_new_center);

if (IsCalibrationDataSensible(m_calibration_data))
{
Expand Down Expand Up @@ -875,3 +876,8 @@ double CalibrationWidget::GetCalibrationRadiusAtAngle(double angle) const
{
return m_input.GetCalibrationDataRadiusAtAngle(m_calibration_data, angle);
}

Common::DVec2 CalibrationWidget::GetCenter() const
{
return m_new_center;
}
6 changes: 4 additions & 2 deletions Source/Core/DolphinQt/Config/Mapping/MappingIndicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class MappingIndicator : public QWidget
void DrawReshapableInput(ControllerEmu::ReshapableInput& stick);
void DrawMixedTriggers();
void DrawForce(ControllerEmu::Force&);
void DrawCalibration(QPainter& p, Common::DVec2 point, Common::DVec2 center = {0, 0});
void DrawCalibration(QPainter& p, Common::DVec2 point);

void paintEvent(QPaintEvent*) override;

Expand Down Expand Up @@ -91,6 +91,8 @@ class CalibrationWidget : public QToolButton

double GetCalibrationRadiusAtAngle(double angle) const;

Common::DVec2 GetCenter() const;

bool IsCalibrating() const;

private:
Expand All @@ -104,5 +106,5 @@ class CalibrationWidget : public QToolButton
QTimer* m_informative_timer;

bool m_is_centering = false;
ControllerEmu::ReshapableInput::ReshapeData m_old_center;
Common::DVec2 m_new_center;
};

0 comments on commit 4bbbd02

Please sign in to comment.