Skip to content
Permalink
Browse files

ControllerEmu: code cleanup.

  • Loading branch information...
jordan-woyak committed Dec 30, 2018
1 parent 1c24bef commit 7efa96eda979f5e717813e7c76cefb0720bc239a
@@ -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 <typename F>
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<ControllerEmu::MixedTriggers*>(m_group);
const auto& triggers = *static_cast<ControllerEmu::MixedTriggers*>(m_group);
const ControlState threshold = triggers.GetThreshold();
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);
}

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();
@@ -13,12 +13,12 @@ namespace ControllerEmu
class AnalogStick : public ReshapableInput
{
public:
typedef ReshapeData StateData;
using StateData = ReshapeData;

AnalogStick(const char* 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;

StateData GetState();
@@ -43,7 +43,7 @@ Cursor::Cursor(const std::string& name_)
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 x = controls[3]->control_ref->State() - controls[2]->control_ref->State();
@@ -57,7 +57,7 @@ class Cursor : public ReshapableInput

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
@@ -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();
@@ -13,17 +13,19 @@ namespace ControllerEmu
class MixedTriggers : public ControlGroup
{
public:
enum
{
SETTING_THRESHOLD,
SETTING_DEADZONE,
};

explicit MixedTriggers(const std::string& name);

void GetState(u16* digital, const u16* bitmasks, ControlState* analog, bool adjusted = true);
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,
};
};
} // 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));
}

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();
@@ -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

0 comments on commit 7efa96e

Please sign in to comment.
You can’t perform that action at this time.