DolphinQt: Clean up calibration drawing a bit.

This commit is contained in:
Jordan Woyak 2020-02-25 17:19:39 -06:00
parent ed24f32c5b
commit 2c843ae06b

View File

@ -149,7 +149,7 @@ constexpr int SPHERE_POINT_COUNT = 200;
// Constructs a polygon by querying a radius at varying angles:
template <typename F>
QPolygonF GetPolygonFromRadiusGetter(F&& radius_getter, Common::DVec2 center = {0.0, 0.0})
QPolygonF GetPolygonFromRadiusGetter(F&& radius_getter)
{
// A multiple of 8 (octagon) and enough points to be visibly pleasing:
constexpr int shape_point_count = 32;
@ -161,7 +161,7 @@ QPolygonF GetPolygonFromRadiusGetter(F&& radius_getter, Common::DVec2 center = {
const double angle = MathUtil::TAU * p / shape.size();
const double radius = radius_getter(angle);
point = {std::cos(angle) * radius + center.x, std::sin(angle) * radius + center.y};
point = {std::cos(angle) * radius, std::sin(angle) * radius};
++p;
}
@ -302,25 +302,30 @@ void ReshapableInputIndicator::DrawReshapableInput(
const auto center = stick.GetCenter();
p.save();
p.translate(center.x, center.y);
// Deadzone.
p.setPen(GetDeadZonePen());
p.setBrush(GetDeadZoneBrush(p));
p.drawPolygon(GetPolygonFromRadiusGetter(
[&stick](double ang) { return stick.GetDeadzoneRadiusAtAngle(ang); }, center));
[&stick](double ang) { return stick.GetDeadzoneRadiusAtAngle(ang); }));
// Input shape.
p.setPen(GetInputShapePen());
p.setBrush(Qt::NoBrush);
p.drawPolygon(GetPolygonFromRadiusGetter(
[&stick](double ang) { return stick.GetInputRadiusAtAngle(ang); }, center));
[&stick](double ang) { return stick.GetInputRadiusAtAngle(ang); }));
// Center.
if (center.x || center.y)
{
p.setPen(GetInputDotPen(GetCenterColor()));
p.drawPoint(QPointF{center.x, center.y});
p.drawPoint(QPointF{});
}
p.restore();
// Raw stick position.
p.setPen(GetInputDotPen(GetRawInputColor()));
p.drawPoint(QPointF{raw_coord.x, raw_coord.y});
@ -745,23 +750,26 @@ void GyroMappingIndicator::Draw()
void ReshapableInputIndicator::DrawCalibration(QPainter& p, Common::DVec2 point)
{
// Bounding box size:
const auto center = m_calibration_widget->GetCenter();
p.save();
p.translate(center.x, center.y);
// Input shape.
p.setPen(GetInputShapePen());
p.setBrush(Qt::NoBrush);
p.drawPolygon(GetPolygonFromRadiusGetter(
[this](double angle) { return m_calibration_widget->GetCalibrationRadiusAtAngle(angle); },
center));
[this](double angle) { return m_calibration_widget->GetCalibrationRadiusAtAngle(angle); }));
// Center.
if (center.x || center.y)
{
p.setPen(GetInputDotPen(GetCenterColor()));
p.drawPoint(QPointF{center.x, center.y});
p.drawPoint(QPointF{});
}
p.restore();
// Stick position.
p.setPen(GetInputDotPen(GetAdjustedInputColor()));
p.drawPoint(QPointF{point.x, point.y});