|
|
|
@ -5,14 +5,15 @@
|
|
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
|
#include <cmath>
|
|
|
|
|
#include <numbers>
|
|
|
|
|
|
|
|
|
|
#include <fmt/format.h>
|
|
|
|
|
|
|
|
|
|
#include <QAction>
|
|
|
|
|
#include <QDateTime>
|
|
|
|
|
#include <QEasingCurve>
|
|
|
|
|
#include <QPainter>
|
|
|
|
|
#include <QPainterPath>
|
|
|
|
|
#include <QTimer>
|
|
|
|
|
|
|
|
|
|
#include "Common/MathUtil.h"
|
|
|
|
|
|
|
|
|
@ -23,9 +24,10 @@
|
|
|
|
|
#include "InputCommon/ControllerEmu/ControlGroup/Force.h"
|
|
|
|
|
#include "InputCommon/ControllerEmu/ControlGroup/MixedTriggers.h"
|
|
|
|
|
#include "InputCommon/ControllerInterface/CoreDevice.h"
|
|
|
|
|
#include "InputCommon/ControllerInterface/MappingCommon.h"
|
|
|
|
|
|
|
|
|
|
#include "DolphinQt/Config/Mapping/MappingWidget.h"
|
|
|
|
|
#include "DolphinQt/QtUtils/ModalMessageBox.h"
|
|
|
|
|
#include "DolphinQt/Config/Mapping/MappingWindow.h"
|
|
|
|
|
#include "DolphinQt/Settings.h"
|
|
|
|
|
|
|
|
|
|
namespace
|
|
|
|
@ -238,34 +240,6 @@ QPolygonF GetPolygonSegmentFromRadiusGetter(F&& radius_getter, double direction,
|
|
|
|
|
return shape;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Used to check if the user seems to have attempted proper calibration.
|
|
|
|
|
bool IsCalibrationDataSensible(const ControllerEmu::ReshapableInput::CalibrationData& data)
|
|
|
|
|
{
|
|
|
|
|
// Test that the average input radius is not below a threshold.
|
|
|
|
|
// This will make sure the user has actually moved their stick from neutral.
|
|
|
|
|
|
|
|
|
|
// Even the GC controller's small range would pass this test.
|
|
|
|
|
constexpr double REASONABLE_AVERAGE_RADIUS = 0.6;
|
|
|
|
|
|
|
|
|
|
MathUtil::RunningVariance<ControlState> stats;
|
|
|
|
|
|
|
|
|
|
for (auto& x : data)
|
|
|
|
|
stats.Push(x);
|
|
|
|
|
|
|
|
|
|
if (stats.Mean() < REASONABLE_AVERAGE_RADIUS)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test that the standard deviation is below a threshold.
|
|
|
|
|
// This will make sure the user has not just filled in one side of their input.
|
|
|
|
|
|
|
|
|
|
// Approx. deviation of a square input gate, anything much more than that would be unusual.
|
|
|
|
|
constexpr double REASONABLE_DEVIATION = 0.14;
|
|
|
|
|
|
|
|
|
|
return stats.StandardDeviation() < REASONABLE_DEVIATION;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Used to test for a miscalibrated stick so the user can be informed.
|
|
|
|
|
bool IsPointOutsideCalibration(Common::DVec2 point, ControllerEmu::ReshapableInput& input)
|
|
|
|
|
{
|
|
|
|
@ -313,6 +287,23 @@ void GenerateFibonacciSphere(int point_count, F&& callback)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Draws an analog stick pushed to the right by the provided amount.
|
|
|
|
|
void DrawPushedStick(QPainter& p, ReshapableInputIndicator& indicator, double value)
|
|
|
|
|
{
|
|
|
|
|
auto stick_color = indicator.GetGateBrushColor();
|
|
|
|
|
indicator.AdjustGateColor(&stick_color);
|
|
|
|
|
const auto stick_pen_color = stick_color.darker(125);
|
|
|
|
|
p.setPen(QPen{stick_pen_color, 0});
|
|
|
|
|
p.setBrush(stick_color);
|
|
|
|
|
constexpr float circle_radius = 0.65f;
|
|
|
|
|
p.drawEllipse(QPointF{value * 0.35f, 0.f}, circle_radius, circle_radius);
|
|
|
|
|
|
|
|
|
|
p.setPen(QPen{indicator.GetRawInputColor(), 0});
|
|
|
|
|
p.setBrush(Qt::NoBrush);
|
|
|
|
|
constexpr float alt_circle_radius = 0.45f;
|
|
|
|
|
p.drawEllipse(QPointF{value * 0.45f, 0.f}, alt_circle_radius, alt_circle_radius);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
void MappingIndicator::paintEvent(QPaintEvent*)
|
|
|
|
@ -328,11 +319,16 @@ void MappingIndicator::paintEvent(QPaintEvent*)
|
|
|
|
|
Draw();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QColor CursorIndicator::GetGateBrushColor() const
|
|
|
|
|
{
|
|
|
|
|
return CURSOR_TV_COLOR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CursorIndicator::Draw()
|
|
|
|
|
{
|
|
|
|
|
const auto adj_coord = m_cursor_group.GetState(true);
|
|
|
|
|
|
|
|
|
|
DrawReshapableInput(m_cursor_group, CURSOR_TV_COLOR,
|
|
|
|
|
DrawReshapableInput(m_cursor_group,
|
|
|
|
|
adj_coord.IsVisible() ?
|
|
|
|
|
std::make_optional(Common::DVec2(adj_coord.x, adj_coord.y)) :
|
|
|
|
|
std::nullopt);
|
|
|
|
@ -362,7 +358,7 @@ void SquareIndicator::TransformPainter(QPainter& p)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ReshapableInputIndicator::DrawReshapableInput(
|
|
|
|
|
ControllerEmu::ReshapableInput& stick, QColor gate_brush_color,
|
|
|
|
|
ControllerEmu::ReshapableInput& stick,
|
|
|
|
|
std::optional<ControllerEmu::ReshapableInput::ReshapeData> adj_coord)
|
|
|
|
|
{
|
|
|
|
|
QPainter p(this);
|
|
|
|
@ -378,13 +374,14 @@ void ReshapableInputIndicator::DrawReshapableInput(
|
|
|
|
|
|
|
|
|
|
if (IsCalibrating())
|
|
|
|
|
{
|
|
|
|
|
DrawCalibration(p, raw_coord);
|
|
|
|
|
m_calibration_widget->Draw(p, raw_coord);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DrawUnderGate(p);
|
|
|
|
|
|
|
|
|
|
QColor gate_pen_color = gate_brush_color.darker(125);
|
|
|
|
|
auto gate_brush_color = GetGateBrushColor();
|
|
|
|
|
auto gate_pen_color = gate_brush_color.darker(125);
|
|
|
|
|
|
|
|
|
|
AdjustGateColor(&gate_brush_color);
|
|
|
|
|
AdjustGateColor(&gate_pen_color);
|
|
|
|
@ -435,24 +432,33 @@ void ReshapableInputIndicator::DrawReshapableInput(
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AnalogStickIndicator::Draw()
|
|
|
|
|
QColor AnalogStickIndicator::GetGateBrushColor() const
|
|
|
|
|
{
|
|
|
|
|
// Some hacks for pretty colors:
|
|
|
|
|
const bool is_c_stick = m_group.name == "C-Stick";
|
|
|
|
|
|
|
|
|
|
const auto gate_brush_color = is_c_stick ? C_STICK_GATE_COLOR : STICK_GATE_COLOR;
|
|
|
|
|
return is_c_stick ? C_STICK_GATE_COLOR : STICK_GATE_COLOR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AnalogStickIndicator::Draw()
|
|
|
|
|
{
|
|
|
|
|
const auto adj_coord = m_group.GetReshapableState(true);
|
|
|
|
|
|
|
|
|
|
DrawReshapableInput(m_group, gate_brush_color,
|
|
|
|
|
DrawReshapableInput(m_group,
|
|
|
|
|
(adj_coord.x || adj_coord.y) ? std::make_optional(adj_coord) : std::nullopt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TiltIndicator::Update(float elapsed_seconds)
|
|
|
|
|
{
|
|
|
|
|
ReshapableInputIndicator::Update(elapsed_seconds);
|
|
|
|
|
WiimoteEmu::EmulateTilt(&m_motion_state, &m_group, elapsed_seconds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QColor TiltIndicator::GetGateBrushColor() const
|
|
|
|
|
{
|
|
|
|
|
return TILT_GATE_COLOR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TiltIndicator::Draw()
|
|
|
|
|
{
|
|
|
|
|
auto adj_coord = Common::DVec2{-m_motion_state.angle.y, m_motion_state.angle.x} / MathUtil::PI;
|
|
|
|
@ -468,7 +474,7 @@ void TiltIndicator::Draw()
|
|
|
|
|
adj_coord.x = std::fmod(adj_coord.x + norm_360_deg + norm_180_deg, norm_360_deg) - norm_180_deg;
|
|
|
|
|
adj_coord.y = std::fmod(adj_coord.y + norm_360_deg + norm_180_deg, norm_360_deg) - norm_180_deg;
|
|
|
|
|
|
|
|
|
|
DrawReshapableInput(m_group, TILT_GATE_COLOR,
|
|
|
|
|
DrawReshapableInput(m_group,
|
|
|
|
|
(adj_coord.x || adj_coord.y) ? std::make_optional(adj_coord) : std::nullopt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -604,12 +610,18 @@ void SwingIndicator::DrawUnderGate(QPainter& p)
|
|
|
|
|
|
|
|
|
|
void SwingIndicator::Update(float elapsed_seconds)
|
|
|
|
|
{
|
|
|
|
|
ReshapableInputIndicator::Update(elapsed_seconds);
|
|
|
|
|
WiimoteEmu::EmulateSwing(&m_motion_state, &m_swing_group, elapsed_seconds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QColor SwingIndicator::GetGateBrushColor() const
|
|
|
|
|
{
|
|
|
|
|
return SWING_GATE_COLOR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SwingIndicator::Draw()
|
|
|
|
|
{
|
|
|
|
|
DrawReshapableInput(m_swing_group, SWING_GATE_COLOR,
|
|
|
|
|
DrawReshapableInput(m_swing_group,
|
|
|
|
|
Common::DVec2{-m_motion_state.position.x, m_motion_state.position.z});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -915,42 +927,103 @@ void IRPassthroughMappingIndicator::Draw()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ReshapableInputIndicator::DrawCalibration(QPainter& p, Common::DVec2 point)
|
|
|
|
|
void CalibrationWidget::Draw(QPainter& p, Common::DVec2 point)
|
|
|
|
|
{
|
|
|
|
|
const auto center = m_calibration_widget->GetCenter();
|
|
|
|
|
DrawInProgressMapping(p);
|
|
|
|
|
DrawInProgressCalibration(p, point);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double CalibrationWidget::GetAnimationElapsedSeconds() const
|
|
|
|
|
{
|
|
|
|
|
return DT_s{Clock::now() - m_animation_start_time}.count();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CalibrationWidget::RestartAnimation()
|
|
|
|
|
{
|
|
|
|
|
m_animation_start_time = Clock::now();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CalibrationWidget::DrawInProgressMapping(QPainter& p)
|
|
|
|
|
{
|
|
|
|
|
if (!IsMapping())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
p.rotate(qRadiansToDegrees(m_mapper->GetCurrentAngle()));
|
|
|
|
|
|
|
|
|
|
const auto ping_pong = 1 - std::abs(1 - (2 * std::fmod(GetAnimationElapsedSeconds(), 1)));
|
|
|
|
|
|
|
|
|
|
// Stick.
|
|
|
|
|
DrawPushedStick(p, m_indicator,
|
|
|
|
|
QEasingCurve(QEasingCurve::OutBounce).valueForProgress(ping_pong));
|
|
|
|
|
|
|
|
|
|
// Arrow.
|
|
|
|
|
p.save();
|
|
|
|
|
const auto triangle_x =
|
|
|
|
|
(QEasingCurve(QEasingCurve::InOutQuart).valueForProgress(ping_pong) * 0.3) + 0.1;
|
|
|
|
|
p.translate(triangle_x, 0.0);
|
|
|
|
|
|
|
|
|
|
// An equilateral triangle.
|
|
|
|
|
constexpr auto triangle_h = 0.2f;
|
|
|
|
|
constexpr auto triangle_w_2 = triangle_h / std::numbers::sqrt3_v<float>;
|
|
|
|
|
|
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
|
p.setBrush(m_indicator.GetRawInputColor());
|
|
|
|
|
p.drawPolygon(QPolygonF{{triangle_h, 0.f}, {0.f, -triangle_w_2}, {0.f, +triangle_w_2}});
|
|
|
|
|
|
|
|
|
|
p.restore();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CalibrationWidget::DrawInProgressCalibration(QPainter& p, Common::DVec2 point)
|
|
|
|
|
{
|
|
|
|
|
if (!IsCalibrating())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const auto elapsed_seconds = GetAnimationElapsedSeconds();
|
|
|
|
|
|
|
|
|
|
// Clockwise spinning stick starting from center.
|
|
|
|
|
p.save();
|
|
|
|
|
p.rotate(elapsed_seconds * -360.0);
|
|
|
|
|
DrawPushedStick(
|
|
|
|
|
p, m_indicator,
|
|
|
|
|
-QEasingCurve(QEasingCurve::OutCirc).valueForProgress(std::min(elapsed_seconds * 2, 1.0)));
|
|
|
|
|
p.restore();
|
|
|
|
|
|
|
|
|
|
const auto center = m_calibrator->GetCenter();
|
|
|
|
|
p.save();
|
|
|
|
|
p.translate(center.x, center.y);
|
|
|
|
|
|
|
|
|
|
// Input shape.
|
|
|
|
|
p.setPen(GetInputShapePen());
|
|
|
|
|
p.setPen(m_indicator.GetInputShapePen());
|
|
|
|
|
p.setBrush(Qt::NoBrush);
|
|
|
|
|
p.drawPolygon(GetPolygonFromRadiusGetter(
|
|
|
|
|
[this](double angle) { return m_calibration_widget->GetCalibrationRadiusAtAngle(angle); }));
|
|
|
|
|
[this](double angle) { return m_calibrator->GetCalibrationRadiusAtAngle(angle); }));
|
|
|
|
|
|
|
|
|
|
// Center.
|
|
|
|
|
// Calibrated center.
|
|
|
|
|
if (center.x || center.y)
|
|
|
|
|
{
|
|
|
|
|
p.setPen(GetInputDotPen(GetCenterColor()));
|
|
|
|
|
p.setPen(GetInputDotPen(m_indicator.GetCenterColor()));
|
|
|
|
|
p.drawPoint(QPointF{});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p.restore();
|
|
|
|
|
|
|
|
|
|
// Stick position.
|
|
|
|
|
p.setPen(GetInputDotPen(GetAdjustedInputColor()));
|
|
|
|
|
p.drawPoint(QPointF{point.x, point.y});
|
|
|
|
|
// Show the red dot only if the input is at least halfway pressed.
|
|
|
|
|
// The cool spinning stick is otherwise uglified by the red dot always being shown.
|
|
|
|
|
if (Common::DVec2{point.x, point.y}.LengthSquared() > (0.5 * 0.5))
|
|
|
|
|
{
|
|
|
|
|
p.setPen(GetInputDotPen(m_indicator.GetAdjustedInputColor()));
|
|
|
|
|
p.drawPoint(QPointF{point.x, point.y});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ReshapableInputIndicator::UpdateCalibrationWidget(Common::DVec2 point)
|
|
|
|
|
{
|
|
|
|
|
if (m_calibration_widget)
|
|
|
|
|
if (m_calibration_widget != nullptr)
|
|
|
|
|
m_calibration_widget->Update(point);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ReshapableInputIndicator::IsCalibrating() const
|
|
|
|
|
{
|
|
|
|
|
return m_calibration_widget && m_calibration_widget->IsCalibrating();
|
|
|
|
|
return m_calibration_widget != nullptr && m_calibration_widget->IsActive();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ReshapableInputIndicator::SetCalibrationWidget(CalibrationWidget* widget)
|
|
|
|
@ -958,110 +1031,172 @@ void ReshapableInputIndicator::SetCalibrationWidget(CalibrationWidget* widget)
|
|
|
|
|
m_calibration_widget = widget;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CalibrationWidget::CalibrationWidget(ControllerEmu::ReshapableInput& input,
|
|
|
|
|
CalibrationWidget::~CalibrationWidget() = default;
|
|
|
|
|
|
|
|
|
|
CalibrationWidget::CalibrationWidget(MappingWidget& mapping_widget,
|
|
|
|
|
ControllerEmu::ReshapableInput& input,
|
|
|
|
|
ReshapableInputIndicator& indicator)
|
|
|
|
|
: m_input(input), m_indicator(indicator), m_completion_action{}
|
|
|
|
|
: m_mapping_widget(mapping_widget), m_input(input), m_indicator(indicator)
|
|
|
|
|
{
|
|
|
|
|
connect(mapping_widget.GetParent(), &MappingWindow::CancelMapping, this,
|
|
|
|
|
&CalibrationWidget::ResetActions);
|
|
|
|
|
connect(mapping_widget.GetParent(), &MappingWindow::ConfigChanged, this,
|
|
|
|
|
&CalibrationWidget::ResetActions);
|
|
|
|
|
|
|
|
|
|
m_indicator.SetCalibrationWidget(this);
|
|
|
|
|
|
|
|
|
|
// Make it more apparent that this is a menu with more options.
|
|
|
|
|
setPopupMode(ToolButtonPopupMode::MenuButtonPopup);
|
|
|
|
|
|
|
|
|
|
SetupActions();
|
|
|
|
|
|
|
|
|
|
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
|
|
|
|
|
|
|
|
|
|
m_informative_timer = new QTimer(this);
|
|
|
|
|
connect(m_informative_timer, &QTimer::timeout, this, [this] {
|
|
|
|
|
// If the user has started moving we'll assume they know what they are doing.
|
|
|
|
|
if (*std::ranges::max_element(m_calibration_data) > 0.5)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ModalMessageBox::information(
|
|
|
|
|
this, tr("Calibration"),
|
|
|
|
|
tr("For best results please slowly move your input to all possible regions."));
|
|
|
|
|
});
|
|
|
|
|
m_informative_timer->setSingleShot(true);
|
|
|
|
|
ResetActions();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CalibrationWidget::SetupActions()
|
|
|
|
|
void CalibrationWidget::DeleteAllActions()
|
|
|
|
|
{
|
|
|
|
|
const auto calibrate_action = new QAction(tr("Calibrate"), this);
|
|
|
|
|
const auto center_action = new QAction(tr("Center and Calibrate"), this);
|
|
|
|
|
const auto reset_action = new QAction(tr("Reset"), this);
|
|
|
|
|
|
|
|
|
|
connect(calibrate_action, &QAction::triggered, [this] {
|
|
|
|
|
StartCalibration();
|
|
|
|
|
m_new_center = Common::DVec2{};
|
|
|
|
|
});
|
|
|
|
|
connect(center_action, &QAction::triggered, [this] {
|
|
|
|
|
StartCalibration();
|
|
|
|
|
m_new_center = std::nullopt;
|
|
|
|
|
});
|
|
|
|
|
connect(reset_action, &QAction::triggered, [this] {
|
|
|
|
|
m_input.SetCalibrationToDefault();
|
|
|
|
|
m_input.SetCenter({0, 0});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
for (auto* action : actions())
|
|
|
|
|
removeAction(action);
|
|
|
|
|
delete action;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CalibrationWidget::ResetActions()
|
|
|
|
|
{
|
|
|
|
|
m_calibrator.reset();
|
|
|
|
|
m_mapper.reset();
|
|
|
|
|
|
|
|
|
|
// i18n: A button to start the process of game controller analog stick mapping and calibration.
|
|
|
|
|
auto* const map_and_calibrate_action = new QAction(tr("Map and Calibrate"), this);
|
|
|
|
|
|
|
|
|
|
// i18n: A button to start the process of game controller analog stick calibration.
|
|
|
|
|
auto* const calibrate_action = new QAction(tr("Calibrate"), this);
|
|
|
|
|
|
|
|
|
|
// i18n: A button to calibrate the center and extremities of a game controller analog stick.
|
|
|
|
|
auto* const center_action = new QAction(tr("Center and Calibrate"), this);
|
|
|
|
|
|
|
|
|
|
// i18n: A button to reset game controller analog stick calibration.
|
|
|
|
|
auto* const reset_action = new QAction(tr("Reset Calibration"), this);
|
|
|
|
|
|
|
|
|
|
connect(map_and_calibrate_action, &QAction::triggered, this,
|
|
|
|
|
&CalibrationWidget::StartMappingAndCalibration);
|
|
|
|
|
connect(calibrate_action, &QAction::triggered, this, [this]() { StartCalibration(); });
|
|
|
|
|
connect(center_action, &QAction::triggered, this, [this]() { StartCalibration(std::nullopt); });
|
|
|
|
|
connect(reset_action, &QAction::triggered, this, [this]() {
|
|
|
|
|
const auto lock = m_mapping_widget.GetController()->GetStateLock();
|
|
|
|
|
m_input.SetCalibrationToDefault();
|
|
|
|
|
m_input.SetCenter({});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
DeleteAllActions();
|
|
|
|
|
|
|
|
|
|
addAction(map_and_calibrate_action);
|
|
|
|
|
addAction(calibrate_action);
|
|
|
|
|
addAction(center_action);
|
|
|
|
|
addAction(reset_action);
|
|
|
|
|
setDefaultAction(calibrate_action);
|
|
|
|
|
|
|
|
|
|
m_completion_action = new QAction(tr("Finish Calibration"), this);
|
|
|
|
|
connect(m_completion_action, &QAction::triggered, [this] {
|
|
|
|
|
m_input.SetCenter(GetCenter());
|
|
|
|
|
m_input.SetCalibrationData(std::move(m_calibration_data));
|
|
|
|
|
m_informative_timer->stop();
|
|
|
|
|
SetupActions();
|
|
|
|
|
});
|
|
|
|
|
setDefaultAction(map_and_calibrate_action);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CalibrationWidget::StartCalibration()
|
|
|
|
|
void CalibrationWidget::StartMappingAndCalibration()
|
|
|
|
|
{
|
|
|
|
|
m_prev_point = {};
|
|
|
|
|
m_calibration_data.assign(m_input.CALIBRATION_SAMPLE_COUNT, 0.0);
|
|
|
|
|
RestartAnimation();
|
|
|
|
|
|
|
|
|
|
// Cancel calibration.
|
|
|
|
|
const auto cancel_action = new QAction(tr("Cancel Calibration"), this);
|
|
|
|
|
connect(cancel_action, &QAction::triggered, [this] {
|
|
|
|
|
m_calibration_data.clear();
|
|
|
|
|
m_informative_timer->stop();
|
|
|
|
|
SetupActions();
|
|
|
|
|
});
|
|
|
|
|
// i18n: A button to stop a game controller button mapping process.
|
|
|
|
|
auto* const cancel_action = new QAction(tr("Cancel Mapping"), this);
|
|
|
|
|
connect(cancel_action, &QAction::triggered, this, &CalibrationWidget::ResetActions);
|
|
|
|
|
|
|
|
|
|
for (auto* action : actions())
|
|
|
|
|
removeAction(action);
|
|
|
|
|
DeleteAllActions();
|
|
|
|
|
|
|
|
|
|
addAction(cancel_action);
|
|
|
|
|
addAction(m_completion_action);
|
|
|
|
|
setDefaultAction(cancel_action);
|
|
|
|
|
|
|
|
|
|
// If the user doesn't seem to know what they are doing after a bit inform them.
|
|
|
|
|
m_informative_timer->start(2000);
|
|
|
|
|
auto* const window = m_mapping_widget.GetParent();
|
|
|
|
|
const auto& default_device = window->GetController()->GetDefaultDevice();
|
|
|
|
|
|
|
|
|
|
std::vector device_strings{default_device.ToString()};
|
|
|
|
|
if (window->IsCreateOtherDeviceMappingsEnabled())
|
|
|
|
|
device_strings = g_controller_interface.GetAllDeviceStrings();
|
|
|
|
|
|
|
|
|
|
const auto lock = window->GetController()->GetStateLock();
|
|
|
|
|
m_mapper = std::make_unique<ciface::MappingCommon::ReshapableInputMapper>(g_controller_interface,
|
|
|
|
|
device_strings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CalibrationWidget::StartCalibration(std::optional<Common::DVec2> center)
|
|
|
|
|
{
|
|
|
|
|
RestartAnimation();
|
|
|
|
|
m_calibrator = std::make_unique<ciface::MappingCommon::CalibrationBuilder>(center);
|
|
|
|
|
|
|
|
|
|
// i18n: A button to abort a game controller calibration process.
|
|
|
|
|
auto* const cancel_action = new QAction(tr("Cancel Calibration"), this);
|
|
|
|
|
connect(cancel_action, &QAction::triggered, this, &CalibrationWidget::ResetActions);
|
|
|
|
|
|
|
|
|
|
// i18n: A button to finalize a game controller calibration process.
|
|
|
|
|
auto* const finish_action = new QAction(tr("Finish Calibration"), this);
|
|
|
|
|
connect(finish_action, &QAction::triggered, this, [this]() {
|
|
|
|
|
const auto lock = m_mapping_widget.GetController()->GetStateLock();
|
|
|
|
|
m_calibrator->ApplyResults(&m_input);
|
|
|
|
|
ResetActions();
|
|
|
|
|
});
|
|
|
|
|
connect(this, &CalibrationWidget::CalibrationIsSensible, finish_action,
|
|
|
|
|
[this, finish_action]() { setDefaultAction(finish_action); });
|
|
|
|
|
|
|
|
|
|
DeleteAllActions();
|
|
|
|
|
|
|
|
|
|
addAction(finish_action);
|
|
|
|
|
addAction(cancel_action);
|
|
|
|
|
setDefaultAction(cancel_action);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CalibrationWidget::Update(Common::DVec2 point)
|
|
|
|
|
{
|
|
|
|
|
// FYI: The "StateLock" is always held when this is called.
|
|
|
|
|
|
|
|
|
|
QFont f = parentWidget()->font();
|
|
|
|
|
QPalette p = parentWidget()->palette();
|
|
|
|
|
|
|
|
|
|
// Use current point if center is being calibrated.
|
|
|
|
|
if (!m_new_center.has_value())
|
|
|
|
|
m_new_center = point;
|
|
|
|
|
|
|
|
|
|
if (IsCalibrating())
|
|
|
|
|
if (IsMapping())
|
|
|
|
|
{
|
|
|
|
|
const auto new_point = point - *m_new_center;
|
|
|
|
|
m_input.UpdateCalibrationData(m_calibration_data, m_prev_point, new_point);
|
|
|
|
|
m_prev_point = new_point;
|
|
|
|
|
|
|
|
|
|
if (IsCalibrationDataSensible(m_calibration_data))
|
|
|
|
|
if (m_mapper->Update())
|
|
|
|
|
{
|
|
|
|
|
setDefaultAction(m_completion_action);
|
|
|
|
|
// Restart the animation for the next direction when progress is made.
|
|
|
|
|
RestartAnimation();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_mapper->IsComplete())
|
|
|
|
|
{
|
|
|
|
|
const bool needs_calibration = m_mapper->IsCalibrationNeeded();
|
|
|
|
|
|
|
|
|
|
if (m_mapper->ApplyResults(m_mapping_widget.GetController(), &m_input))
|
|
|
|
|
{
|
|
|
|
|
emit m_mapping_widget.ConfigChanged();
|
|
|
|
|
|
|
|
|
|
if (needs_calibration)
|
|
|
|
|
{
|
|
|
|
|
StartCalibration();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Load square calibration for digital inputs.
|
|
|
|
|
m_input.SetCalibrationFromGate(ControllerEmu::SquareStickGate{1});
|
|
|
|
|
m_input.SetCenter({});
|
|
|
|
|
|
|
|
|
|
ResetActions();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ResetActions();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_mapper.reset();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (IsCalibrating())
|
|
|
|
|
{
|
|
|
|
|
m_calibrator->Update(point);
|
|
|
|
|
if (m_calibrator->IsCalibrationDataSensible())
|
|
|
|
|
{
|
|
|
|
|
emit CalibrationIsSensible();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (IsPointOutsideCalibration(point, m_input))
|
|
|
|
@ -1075,17 +1210,17 @@ void CalibrationWidget::Update(Common::DVec2 point)
|
|
|
|
|
setPalette(p);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CalibrationWidget::IsActive() const
|
|
|
|
|
{
|
|
|
|
|
return IsMapping() || IsCalibrating();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CalibrationWidget::IsMapping() const
|
|
|
|
|
{
|
|
|
|
|
return m_mapper != nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CalibrationWidget::IsCalibrating() const
|
|
|
|
|
{
|
|
|
|
|
return !m_calibration_data.empty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double CalibrationWidget::GetCalibrationRadiusAtAngle(double angle) const
|
|
|
|
|
{
|
|
|
|
|
return m_input.GetCalibrationDataRadiusAtAngle(m_calibration_data, angle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Common::DVec2 CalibrationWidget::GetCenter() const
|
|
|
|
|
{
|
|
|
|
|
return m_new_center.value_or(Common::DVec2{});
|
|
|
|
|
return m_calibrator != nullptr;
|
|
|
|
|
}
|
|
|
|
|