From 7efa96eda979f5e717813e7c76cefb0720bc239a Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Sun, 30 Dec 2018 10:52:45 -0600 Subject: [PATCH] ControllerEmu: code cleanup. --- .../Config/Mapping/MappingIndicator.cpp | 31 ++++++++++--------- .../ControlGroup/AnalogStick.cpp | 2 +- .../ControllerEmu/ControlGroup/AnalogStick.h | 4 +-- .../ControllerEmu/ControlGroup/Cursor.cpp | 2 +- .../ControllerEmu/ControlGroup/Cursor.h | 2 +- .../ControlGroup/MixedTriggers.cpp | 2 +- .../ControlGroup/MixedTriggers.h | 16 +++++----- .../ControllerEmu/ControlGroup/Tilt.cpp | 2 +- .../ControllerEmu/ControlGroup/Tilt.h | 16 +++++----- 9 files changed, 41 insertions(+), 36 deletions(-) diff --git a/Source/Core/DolphinQt/Config/Mapping/MappingIndicator.cpp b/Source/Core/DolphinQt/Config/Mapping/MappingIndicator.cpp index c9da612b00..e0b44a2895 100644 --- a/Source/Core/DolphinQt/Config/Mapping/MappingIndicator.cpp +++ b/Source/Core/DolphinQt/Config/Mapping/MappingIndicator.cpp @@ -23,24 +23,24 @@ // Color constants to keep things looking consistent: // TODO: could we maybe query theme colors from Qt for the bounding box? -static const QColor BBOX_PEN_COLOR = Qt::darkGray; -static const QColor BBOX_BRUSH_COLOR = Qt::white; +const QColor BBOX_PEN_COLOR = Qt::darkGray; +const QColor BBOX_BRUSH_COLOR = Qt::white; -static const QColor RAW_INPUT_COLOR = Qt::darkGray; -static const QColor ADJ_INPUT_COLOR = Qt::red; -static const QPen INPUT_SHAPE_PEN(RAW_INPUT_COLOR, 1.0, Qt::DashLine); +const QColor RAW_INPUT_COLOR = Qt::darkGray; +const QColor ADJ_INPUT_COLOR = Qt::red; +const QPen INPUT_SHAPE_PEN(RAW_INPUT_COLOR, 1.0, Qt::DashLine); -static const QColor DEADZONE_COLOR = Qt::darkGray; -static const QBrush DEADZONE_BRUSH(DEADZONE_COLOR, Qt::BDiagPattern); +const QColor DEADZONE_COLOR = Qt::darkGray; +const QBrush DEADZONE_BRUSH(DEADZONE_COLOR, Qt::BDiagPattern); -static const QColor TEXT_COLOR = Qt::darkGray; +const QColor TEXT_COLOR = Qt::darkGray; // Text color that is visible atop ADJ_INPUT_COLOR: -static const QColor TEXT_ALT_COLOR = Qt::white; +const QColor TEXT_ALT_COLOR = Qt::white; -static const QColor STICK_GATE_COLOR = Qt::lightGray; -static const QColor C_STICK_GATE_COLOR = Qt::yellow; -static const QColor CURSOR_TV_COLOR = 0xaed6f1; -static const QColor TILT_GATE_COLOR = 0xa2d9ce; +const QColor STICK_GATE_COLOR = Qt::lightGray; +const QColor C_STICK_GATE_COLOR = Qt::yellow; +const QColor CURSOR_TV_COLOR = 0xaed6f1; +const QColor TILT_GATE_COLOR = 0xa2d9ce; constexpr int INPUT_DOT_RADIUS = 2; @@ -53,6 +53,8 @@ MappingIndicator::MappingIndicator(ControllerEmu::ControlGroup* group) : m_group m_timer->start(1000 / 30); } +namespace +{ // Constructs a polygon by querying a radius at varying angles: template QPolygonF GetPolygonFromRadiusGetter(F&& radius_getter, double scale) @@ -73,6 +75,7 @@ QPolygonF GetPolygonFromRadiusGetter(F&& radius_getter, double scale) return shape; } +} // namespace void MappingIndicator::DrawCursor(ControllerEmu::Cursor& cursor) { @@ -250,7 +253,7 @@ void MappingIndicator::DrawMixedTriggers() QPainter p(this); p.setRenderHint(QPainter::TextAntialiasing, true); - auto& triggers = *static_cast(m_group); + const auto& triggers = *static_cast(m_group); const ControlState threshold = triggers.GetThreshold(); const ControlState deadzone = triggers.GetDeadzone(); diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp index de9a75dd23..0cd5da6ba0 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp @@ -37,7 +37,7 @@ AnalogStick::AnalogStick(const char* const name_, const char* const ui_name_, AddReshapingSettings(GetGateRadiusAtAngle(0.0), 0.0, 50); } -AnalogStick::StateData AnalogStick::GetReshapableState(bool adjusted) +AnalogStick::ReshapeData AnalogStick::GetReshapableState(bool adjusted) { const ControlState y = controls[0]->control_ref->State() - controls[1]->control_ref->State(); const ControlState x = controls[3]->control_ref->State() - controls[2]->control_ref->State(); diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.h b/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.h index bbf8236066..cafb1dad51 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.h +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.h @@ -13,12 +13,12 @@ namespace ControllerEmu class AnalogStick : public ReshapableInput { public: - typedef ReshapeData StateData; + using StateData = ReshapeData; AnalogStick(const char* name, std::unique_ptr&& stick_gate); AnalogStick(const char* name, const char* ui_name, std::unique_ptr&& stick_gate); - StateData GetReshapableState(bool adjusted) final override; + ReshapeData GetReshapableState(bool adjusted) final override; ControlState GetGateRadiusAtAngle(double ang) const override; StateData GetState(); diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Cursor.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Cursor.cpp index fc373f647c..0af6efc734 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Cursor.cpp +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Cursor.cpp @@ -43,7 +43,7 @@ Cursor::Cursor(const std::string& name_) boolean_settings.emplace_back(std::make_unique(_trans("Auto-Hide"), false)); } -ReshapableInput::ReshapeData Cursor::GetReshapableState(bool adjusted) +Cursor::ReshapeData Cursor::GetReshapableState(bool adjusted) { const ControlState y = controls[0]->control_ref->State() - controls[1]->control_ref->State(); const ControlState x = controls[3]->control_ref->State() - controls[2]->control_ref->State(); diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Cursor.h b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Cursor.h index fcd82a7d50..c66b2b896c 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Cursor.h +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Cursor.h @@ -57,7 +57,7 @@ private: int m_auto_hide_timer = AUTO_HIDE_MS; - typedef std::chrono::steady_clock Clock; + using Clock = std::chrono::steady_clock; Clock::time_point m_last_update; }; } // namespace ControllerEmu diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/MixedTriggers.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/MixedTriggers.cpp index 4928127604..6ae4dfd668 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/MixedTriggers.cpp +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/MixedTriggers.cpp @@ -26,7 +26,7 @@ MixedTriggers::MixedTriggers(const std::string& name_) } void MixedTriggers::GetState(u16* const digital, const u16* bitmasks, ControlState* analog, - bool adjusted) + bool adjusted) const { const ControlState threshold = numeric_settings[SETTING_THRESHOLD]->GetValue(); ControlState deadzone = numeric_settings[SETTING_DEADZONE]->GetValue(); diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/MixedTriggers.h b/Source/Core/InputCommon/ControllerEmu/ControlGroup/MixedTriggers.h index 1733394223..4e7b2adafe 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/MixedTriggers.h +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/MixedTriggers.h @@ -13,17 +13,19 @@ namespace ControllerEmu class MixedTriggers : public ControlGroup { public: + explicit MixedTriggers(const std::string& name); + + void GetState(u16* digital, const u16* bitmasks, ControlState* analog, + bool adjusted = true) const; + + ControlState GetDeadzone() const; + ControlState GetThreshold() const; + +private: enum { SETTING_THRESHOLD, SETTING_DEADZONE, }; - - explicit MixedTriggers(const std::string& name); - - void GetState(u16* digital, const u16* bitmasks, ControlState* analog, bool adjusted = true); - - ControlState GetDeadzone() const; - ControlState GetThreshold() const; }; } // namespace ControllerEmu diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Tilt.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Tilt.cpp index 998cce17ee..2fec9c7bd0 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Tilt.cpp +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Tilt.cpp @@ -37,7 +37,7 @@ Tilt::Tilt(const std::string& name_) numeric_settings.emplace_back(std::make_unique(_trans("Angle"), 0.9, 0, 180)); } -Tilt::StateData Tilt::GetReshapableState(bool adjusted) +Tilt::ReshapeData Tilt::GetReshapableState(bool adjusted) { const ControlState y = controls[0]->control_ref->State() - controls[1]->control_ref->State(); const ControlState x = controls[3]->control_ref->State() - controls[2]->control_ref->State(); diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Tilt.h b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Tilt.h index 965151ea29..55afd43ba3 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Tilt.h +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Tilt.h @@ -15,26 +15,26 @@ namespace ControllerEmu class Tilt : public ReshapableInput { public: - typedef ReshapeData StateData; - - enum - { - SETTING_MAX_ANGLE = ReshapableInput::SETTING_COUNT, - }; + using StateData = ReshapeData; explicit Tilt(const std::string& name); - StateData GetReshapableState(bool adjusted) final override; + ReshapeData GetReshapableState(bool adjusted) final override; ControlState GetGateRadiusAtAngle(double ang) const override; StateData GetState(); private: + enum + { + SETTING_MAX_ANGLE = ReshapableInput::SETTING_COUNT, + }; + static constexpr int MAX_DEG_PER_SEC = 360 * 6; StateData m_tilt; - typedef std::chrono::steady_clock Clock; + using Clock = std::chrono::steady_clock; Clock::time_point m_last_update; }; } // namespace ControllerEmu