ControllerEmu: code cleanup.
This commit is contained in:
parent
1c24bef594
commit
7efa96eda9
|
@ -23,24 +23,24 @@
|
||||||
|
|
||||||
// Color constants to keep things looking consistent:
|
// Color constants to keep things looking consistent:
|
||||||
// TODO: could we maybe query theme colors from Qt for the bounding box?
|
// TODO: could we maybe query theme colors from Qt for the bounding box?
|
||||||
static const QColor BBOX_PEN_COLOR = Qt::darkGray;
|
const QColor BBOX_PEN_COLOR = Qt::darkGray;
|
||||||
static const QColor BBOX_BRUSH_COLOR = Qt::white;
|
const QColor BBOX_BRUSH_COLOR = Qt::white;
|
||||||
|
|
||||||
static const QColor RAW_INPUT_COLOR = Qt::darkGray;
|
const QColor RAW_INPUT_COLOR = Qt::darkGray;
|
||||||
static const QColor ADJ_INPUT_COLOR = Qt::red;
|
const QColor ADJ_INPUT_COLOR = Qt::red;
|
||||||
static const QPen INPUT_SHAPE_PEN(RAW_INPUT_COLOR, 1.0, Qt::DashLine);
|
const QPen INPUT_SHAPE_PEN(RAW_INPUT_COLOR, 1.0, Qt::DashLine);
|
||||||
|
|
||||||
static const QColor DEADZONE_COLOR = Qt::darkGray;
|
const QColor DEADZONE_COLOR = Qt::darkGray;
|
||||||
static const QBrush DEADZONE_BRUSH(DEADZONE_COLOR, Qt::BDiagPattern);
|
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:
|
// 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;
|
const QColor STICK_GATE_COLOR = Qt::lightGray;
|
||||||
static const QColor C_STICK_GATE_COLOR = Qt::yellow;
|
const QColor C_STICK_GATE_COLOR = Qt::yellow;
|
||||||
static const QColor CURSOR_TV_COLOR = 0xaed6f1;
|
const QColor CURSOR_TV_COLOR = 0xaed6f1;
|
||||||
static const QColor TILT_GATE_COLOR = 0xa2d9ce;
|
const QColor TILT_GATE_COLOR = 0xa2d9ce;
|
||||||
|
|
||||||
constexpr int INPUT_DOT_RADIUS = 2;
|
constexpr int INPUT_DOT_RADIUS = 2;
|
||||||
|
|
||||||
|
@ -53,6 +53,8 @@ MappingIndicator::MappingIndicator(ControllerEmu::ControlGroup* group) : m_group
|
||||||
m_timer->start(1000 / 30);
|
m_timer->start(1000 / 30);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
// Constructs a polygon by querying a radius at varying angles:
|
// Constructs a polygon by querying a radius at varying angles:
|
||||||
template <typename F>
|
template <typename F>
|
||||||
QPolygonF GetPolygonFromRadiusGetter(F&& radius_getter, double scale)
|
QPolygonF GetPolygonFromRadiusGetter(F&& radius_getter, double scale)
|
||||||
|
@ -73,6 +75,7 @@ QPolygonF GetPolygonFromRadiusGetter(F&& radius_getter, double scale)
|
||||||
|
|
||||||
return shape;
|
return shape;
|
||||||
}
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
void MappingIndicator::DrawCursor(ControllerEmu::Cursor& cursor)
|
void MappingIndicator::DrawCursor(ControllerEmu::Cursor& cursor)
|
||||||
{
|
{
|
||||||
|
@ -250,7 +253,7 @@ void MappingIndicator::DrawMixedTriggers()
|
||||||
QPainter p(this);
|
QPainter p(this);
|
||||||
p.setRenderHint(QPainter::TextAntialiasing, true);
|
p.setRenderHint(QPainter::TextAntialiasing, true);
|
||||||
|
|
||||||
auto& triggers = *static_cast<ControllerEmu::MixedTriggers*>(m_group);
|
const auto& triggers = *static_cast<ControllerEmu::MixedTriggers*>(m_group);
|
||||||
const ControlState threshold = triggers.GetThreshold();
|
const ControlState threshold = triggers.GetThreshold();
|
||||||
const ControlState deadzone = triggers.GetDeadzone();
|
const ControlState deadzone = triggers.GetDeadzone();
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ AnalogStick::AnalogStick(const char* const name_, const char* const ui_name_,
|
||||||
AddReshapingSettings(GetGateRadiusAtAngle(0.0), 0.0, 50);
|
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 y = controls[0]->control_ref->State() - controls[1]->control_ref->State();
|
||||||
const ControlState x = controls[3]->control_ref->State() - controls[2]->control_ref->State();
|
const ControlState x = controls[3]->control_ref->State() - controls[2]->control_ref->State();
|
||||||
|
|
|
@ -13,12 +13,12 @@ namespace ControllerEmu
|
||||||
class AnalogStick : public ReshapableInput
|
class AnalogStick : public ReshapableInput
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef ReshapeData StateData;
|
using StateData = ReshapeData;
|
||||||
|
|
||||||
AnalogStick(const char* name, std::unique_ptr<StickGate>&& stick_gate);
|
AnalogStick(const char* name, std::unique_ptr<StickGate>&& stick_gate);
|
||||||
AnalogStick(const char* name, const char* ui_name, std::unique_ptr<StickGate>&& stick_gate);
|
AnalogStick(const char* name, const char* ui_name, std::unique_ptr<StickGate>&& stick_gate);
|
||||||
|
|
||||||
StateData GetReshapableState(bool adjusted) final override;
|
ReshapeData GetReshapableState(bool adjusted) final override;
|
||||||
ControlState GetGateRadiusAtAngle(double ang) const override;
|
ControlState GetGateRadiusAtAngle(double ang) const override;
|
||||||
|
|
||||||
StateData GetState();
|
StateData GetState();
|
||||||
|
|
|
@ -43,7 +43,7 @@ Cursor::Cursor(const std::string& name_)
|
||||||
boolean_settings.emplace_back(std::make_unique<BooleanSetting>(_trans("Auto-Hide"), false));
|
boolean_settings.emplace_back(std::make_unique<BooleanSetting>(_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 y = controls[0]->control_ref->State() - controls[1]->control_ref->State();
|
||||||
const ControlState x = controls[3]->control_ref->State() - controls[2]->control_ref->State();
|
const ControlState x = controls[3]->control_ref->State() - controls[2]->control_ref->State();
|
||||||
|
|
|
@ -57,7 +57,7 @@ private:
|
||||||
|
|
||||||
int m_auto_hide_timer = AUTO_HIDE_MS;
|
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;
|
Clock::time_point m_last_update;
|
||||||
};
|
};
|
||||||
} // namespace ControllerEmu
|
} // namespace ControllerEmu
|
||||||
|
|
|
@ -26,7 +26,7 @@ MixedTriggers::MixedTriggers(const std::string& name_)
|
||||||
}
|
}
|
||||||
|
|
||||||
void MixedTriggers::GetState(u16* const digital, const u16* bitmasks, ControlState* analog,
|
void MixedTriggers::GetState(u16* const digital, const u16* bitmasks, ControlState* analog,
|
||||||
bool adjusted)
|
bool adjusted) const
|
||||||
{
|
{
|
||||||
const ControlState threshold = numeric_settings[SETTING_THRESHOLD]->GetValue();
|
const ControlState threshold = numeric_settings[SETTING_THRESHOLD]->GetValue();
|
||||||
ControlState deadzone = numeric_settings[SETTING_DEADZONE]->GetValue();
|
ControlState deadzone = numeric_settings[SETTING_DEADZONE]->GetValue();
|
||||||
|
|
|
@ -13,17 +13,19 @@ namespace ControllerEmu
|
||||||
class MixedTriggers : public ControlGroup
|
class MixedTriggers : public ControlGroup
|
||||||
{
|
{
|
||||||
public:
|
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
|
enum
|
||||||
{
|
{
|
||||||
SETTING_THRESHOLD,
|
SETTING_THRESHOLD,
|
||||||
SETTING_DEADZONE,
|
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
|
} // namespace ControllerEmu
|
||||||
|
|
|
@ -37,7 +37,7 @@ Tilt::Tilt(const std::string& name_)
|
||||||
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Angle"), 0.9, 0, 180));
|
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_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 y = controls[0]->control_ref->State() - controls[1]->control_ref->State();
|
||||||
const ControlState x = controls[3]->control_ref->State() - controls[2]->control_ref->State();
|
const ControlState x = controls[3]->control_ref->State() - controls[2]->control_ref->State();
|
||||||
|
|
|
@ -15,26 +15,26 @@ namespace ControllerEmu
|
||||||
class Tilt : public ReshapableInput
|
class Tilt : public ReshapableInput
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef ReshapeData StateData;
|
using StateData = ReshapeData;
|
||||||
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
SETTING_MAX_ANGLE = ReshapableInput::SETTING_COUNT,
|
|
||||||
};
|
|
||||||
|
|
||||||
explicit Tilt(const std::string& name);
|
explicit Tilt(const std::string& name);
|
||||||
|
|
||||||
StateData GetReshapableState(bool adjusted) final override;
|
ReshapeData GetReshapableState(bool adjusted) final override;
|
||||||
ControlState GetGateRadiusAtAngle(double ang) const override;
|
ControlState GetGateRadiusAtAngle(double ang) const override;
|
||||||
|
|
||||||
StateData GetState();
|
StateData GetState();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
SETTING_MAX_ANGLE = ReshapableInput::SETTING_COUNT,
|
||||||
|
};
|
||||||
|
|
||||||
static constexpr int MAX_DEG_PER_SEC = 360 * 6;
|
static constexpr int MAX_DEG_PER_SEC = 360 * 6;
|
||||||
|
|
||||||
StateData m_tilt;
|
StateData m_tilt;
|
||||||
|
|
||||||
typedef std::chrono::steady_clock Clock;
|
using Clock = std::chrono::steady_clock;
|
||||||
Clock::time_point m_last_update;
|
Clock::time_point m_last_update;
|
||||||
};
|
};
|
||||||
} // namespace ControllerEmu
|
} // namespace ControllerEmu
|
||||||
|
|
Loading…
Reference in New Issue