ControlGroup: Convert group type enum into an enum class

Gets some constants out of the ControllerEmu namespace, and modifies
ControlGroup so that it uses the enum type itself to represent the
underlying type, rather than a u32 value.
This commit is contained in:
Lioncash 2017-02-25 00:35:02 -05:00
parent 51136681df
commit 26f17a1723
14 changed files with 61 additions and 59 deletions

View File

@ -942,10 +942,10 @@ ControlGroupBox::~ControlGroupBox()
bool ControlGroupBox::HasBitmapHeading() const bool ControlGroupBox::HasBitmapHeading() const
{ {
return control_group->type == ControllerEmu::GROUP_TYPE_STICK || return control_group->type == ControllerEmu::GroupType::Stick ||
control_group->type == ControllerEmu::GROUP_TYPE_TILT || control_group->type == ControllerEmu::GroupType::Tilt ||
control_group->type == ControllerEmu::GROUP_TYPE_CURSOR || control_group->type == ControllerEmu::GroupType::Cursor ||
control_group->type == ControllerEmu::GROUP_TYPE_FORCE; control_group->type == ControllerEmu::GroupType::Force;
} }
ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWindow* const parent, ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWindow* const parent,
@ -1000,10 +1000,10 @@ ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWin
switch (group->type) switch (group->type)
{ {
case ControllerEmu::GROUP_TYPE_STICK: case ControllerEmu::GroupType::Stick:
case ControllerEmu::GROUP_TYPE_TILT: case ControllerEmu::GroupType::Tilt:
case ControllerEmu::GROUP_TYPE_CURSOR: case ControllerEmu::GroupType::Cursor:
case ControllerEmu::GROUP_TYPE_FORCE: case ControllerEmu::GroupType::Force:
{ {
wxSize bitmap_size = parent->FromDIP(wxSize(64, 64)); wxSize bitmap_size = parent->FromDIP(wxSize(64, 64));
m_scale = bitmap_size.GetWidth() / 64.0; m_scale = bitmap_size.GetWidth() / 64.0;
@ -1045,7 +1045,7 @@ ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWin
Add(h_szr, 0, wxEXPAND | wxLEFT | wxRIGHT, space3); Add(h_szr, 0, wxEXPAND | wxLEFT | wxRIGHT, space3);
} }
break; break;
case ControllerEmu::GROUP_TYPE_BUTTONS: case ControllerEmu::GroupType::Buttons:
{ {
// Draw buttons in rows of 8 // Draw buttons in rows of 8
unsigned int button_cols = group->controls.size() > 8 ? 8 : group->controls.size(); unsigned int button_cols = group->controls.size() > 8 ? 8 : group->controls.size();
@ -1083,17 +1083,17 @@ ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWin
Add(static_bitmap, 0, wxALIGN_CENTER_HORIZONTAL | wxLEFT | wxRIGHT, space3); Add(static_bitmap, 0, wxALIGN_CENTER_HORIZONTAL | wxLEFT | wxRIGHT, space3);
} }
break; break;
case ControllerEmu::GROUP_TYPE_MIXED_TRIGGERS: case ControllerEmu::GroupType::MixedTriggers:
case ControllerEmu::GROUP_TYPE_TRIGGERS: case ControllerEmu::GroupType::Triggers:
case ControllerEmu::GROUP_TYPE_SLIDER: case ControllerEmu::GroupType::Slider:
{ {
int height = (int)(12 * group->controls.size()); int height = (int)(12 * group->controls.size());
int width = 64; int width = 64;
if (ControllerEmu::GROUP_TYPE_MIXED_TRIGGERS == group->type) if (group->type == ControllerEmu::GroupType::MixedTriggers)
width = 64 + 12 + 1; width = 64 + 12 + 1;
if (ControllerEmu::GROUP_TYPE_TRIGGERS != group->type) if (group->type != ControllerEmu::GroupType::Triggers)
height /= 2; height /= 2;
height += 1; height += 1;
@ -1127,7 +1127,7 @@ ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWin
Add(static_bitmap, 0, wxALIGN_CENTER_HORIZONTAL | wxLEFT | wxRIGHT, space3); Add(static_bitmap, 0, wxALIGN_CENTER_HORIZONTAL | wxLEFT | wxRIGHT, space3);
} }
break; break;
case ControllerEmu::GROUP_TYPE_EXTENSION: case ControllerEmu::GroupType::Extension:
{ {
PadSettingExtension* const attachments = PadSettingExtension* const attachments =
new PadSettingExtension(parent, (ControllerEmu::Extension*)group); new PadSettingExtension(parent, (ControllerEmu::Extension*)group);

View File

@ -159,9 +159,9 @@ static void DrawControlGroupBox(wxGraphicsContext* gc, ControlGroupBox* g)
switch (g->control_group->type) switch (g->control_group->type)
{ {
case ControllerEmu::GROUP_TYPE_TILT: case ControllerEmu::GroupType::Tilt:
case ControllerEmu::GROUP_TYPE_STICK: case ControllerEmu::GroupType::Stick:
case ControllerEmu::GROUP_TYPE_CURSOR: case ControllerEmu::GroupType::Cursor:
{ {
// this is starting to be a mess combining all these in one case // this is starting to be a mess combining all these in one case
@ -169,19 +169,19 @@ static void DrawControlGroupBox(wxGraphicsContext* gc, ControlGroupBox* g)
switch (g->control_group->type) switch (g->control_group->type)
{ {
case ControllerEmu::GROUP_TYPE_STICK: case ControllerEmu::GroupType::Stick:
((ControllerEmu::AnalogStick*)g->control_group)->GetState(&x, &y); ((ControllerEmu::AnalogStick*)g->control_group)->GetState(&x, &y);
break; break;
case ControllerEmu::GROUP_TYPE_TILT: case ControllerEmu::GroupType::Tilt:
((ControllerEmu::Tilt*)g->control_group)->GetState(&x, &y); ((ControllerEmu::Tilt*)g->control_group)->GetState(&x, &y);
break; break;
case ControllerEmu::GROUP_TYPE_CURSOR: case ControllerEmu::GroupType::Cursor:
((ControllerEmu::Cursor*)g->control_group)->GetState(&x, &y, &z); ((ControllerEmu::Cursor*)g->control_group)->GetState(&x, &y, &z);
break; break;
} }
// ir cursor forward movement // ir cursor forward movement
if (ControllerEmu::GROUP_TYPE_CURSOR == g->control_group->type) if (g->control_group->type == ControllerEmu::GroupType::Cursor)
{ {
gc->SetBrush(z ? *wxRED_BRUSH : *wxGREY_BRUSH); gc->SetBrush(z ? *wxRED_BRUSH : *wxGREY_BRUSH);
wxGraphicsPath path = gc->CreatePath(); wxGraphicsPath path = gc->CreatePath();
@ -191,7 +191,7 @@ static void DrawControlGroupBox(wxGraphicsContext* gc, ControlGroupBox* g)
// input zone // input zone
gc->SetPen(*wxLIGHT_GREY_PEN); gc->SetPen(*wxLIGHT_GREY_PEN);
if (ControllerEmu::GROUP_TYPE_STICK == g->control_group->type) if (g->control_group->type == ControllerEmu::GroupType::Stick)
{ {
gc->SetBrush(wxColour(0xDDDDDD)); // Light Gray gc->SetBrush(wxColour(0xDDDDDD)); // Light Gray
@ -231,9 +231,9 @@ static void DrawControlGroupBox(wxGraphicsContext* gc, ControlGroupBox* g)
gc->DrawRectangle(16, 16, 32, 32); gc->DrawRectangle(16, 16, 32, 32);
} }
if (ControllerEmu::GROUP_TYPE_CURSOR != g->control_group->type) if (g->control_group->type != ControllerEmu::GroupType::Cursor)
{ {
const int deadzone_idx = g->control_group->type == ControllerEmu::GROUP_TYPE_STICK ? const int deadzone_idx = g->control_group->type == ControllerEmu::GroupType::Stick ?
ControllerEmu::AnalogStick::SETTING_DEADZONE : ControllerEmu::AnalogStick::SETTING_DEADZONE :
0; 0;
@ -267,7 +267,7 @@ static void DrawControlGroupBox(wxGraphicsContext* gc, ControlGroupBox* g)
} }
break; break;
case ControllerEmu::GROUP_TYPE_FORCE: case ControllerEmu::GroupType::Force:
{ {
ControlState raw_dot[3]; ControlState raw_dot[3];
ControlState adj_dot[3]; ControlState adj_dot[3];
@ -332,7 +332,7 @@ static void DrawControlGroupBox(wxGraphicsContext* gc, ControlGroupBox* g)
} }
break; break;
case ControllerEmu::GROUP_TYPE_BUTTONS: case ControllerEmu::GroupType::Buttons:
{ {
const unsigned int button_count = static_cast<unsigned int>(g->control_group->controls.size()); const unsigned int button_count = static_cast<unsigned int>(g->control_group->controls.size());
std::vector<unsigned int> bitmasks(button_count); std::vector<unsigned int> bitmasks(button_count);
@ -361,7 +361,7 @@ static void DrawControlGroupBox(wxGraphicsContext* gc, ControlGroupBox* g)
} }
break; break;
case ControllerEmu::GROUP_TYPE_TRIGGERS: case ControllerEmu::GroupType::Triggers:
{ {
const unsigned int trigger_count = static_cast<unsigned int>(g->control_group->controls.size()); const unsigned int trigger_count = static_cast<unsigned int>(g->control_group->controls.size());
std::vector<ControlState> trigs(trigger_count); std::vector<ControlState> trigs(trigger_count);
@ -403,7 +403,7 @@ static void DrawControlGroupBox(wxGraphicsContext* gc, ControlGroupBox* g)
} }
break; break;
case ControllerEmu::GROUP_TYPE_MIXED_TRIGGERS: case ControllerEmu::GroupType::MixedTriggers:
{ {
const unsigned int trigger_count = ((unsigned int)(g->control_group->controls.size() / 2)); const unsigned int trigger_count = ((unsigned int)(g->control_group->controls.size() / 2));
@ -443,7 +443,7 @@ static void DrawControlGroupBox(wxGraphicsContext* gc, ControlGroupBox* g)
} }
break; break;
case ControllerEmu::GROUP_TYPE_SLIDER: case ControllerEmu::GroupType::Slider:
{ {
const ControlState deadzone = g->control_group->numeric_settings[0]->GetValue(); const ControlState deadzone = g->control_group->numeric_settings[0]->GetValue();

View File

@ -24,7 +24,7 @@ AnalogStick::AnalogStick(const char* const name_, ControlState default_radius)
AnalogStick::AnalogStick(const char* const name_, const char* const ui_name_, AnalogStick::AnalogStick(const char* const name_, const char* const ui_name_,
ControlState default_radius) ControlState default_radius)
: ControlGroup(name_, ui_name_, GROUP_TYPE_STICK) : ControlGroup(name_, ui_name_, GroupType::Stick)
{ {
for (auto& named_direction : named_directions) for (auto& named_direction : named_directions)
controls.emplace_back(std::make_unique<Input>(named_direction)); controls.emplace_back(std::make_unique<Input>(named_direction));

View File

@ -16,7 +16,7 @@ Buttons::Buttons(const std::string& name_) : Buttons(name_, name_)
} }
Buttons::Buttons(const std::string& ini_name, const std::string& group_name) Buttons::Buttons(const std::string& ini_name, const std::string& group_name)
: ControlGroup(ini_name, group_name, GROUP_TYPE_BUTTONS) : ControlGroup(ini_name, group_name, GroupType::Buttons)
{ {
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Threshold"), 0.5)); numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Threshold"), 0.5));
} }

View File

@ -14,12 +14,13 @@
namespace ControllerEmu namespace ControllerEmu
{ {
ControlGroup::ControlGroup(const std::string& name_, const u32 type_) ControlGroup::ControlGroup(const std::string& name_, const GroupType type_)
: name(name_), ui_name(name_), type(type_) : name(name_), ui_name(name_), type(type_)
{ {
} }
ControlGroup::ControlGroup(const std::string& name_, const std::string& ui_name_, const u32 type_) ControlGroup::ControlGroup(const std::string& name_, const std::string& ui_name_,
const GroupType type_)
: name(name_), ui_name(ui_name_), type(type_) : name(name_), ui_name(ui_name_), type(type_)
{ {
} }
@ -62,7 +63,7 @@ void ControlGroup::LoadConfig(IniFile::Section* sec, const std::string& defdev,
} }
// extensions // extensions
if (type == GROUP_TYPE_EXTENSION) if (type == GroupType::Extension)
{ {
Extension* const ext = (Extension*)this; Extension* const ext = (Extension*)this;
@ -115,7 +116,7 @@ void ControlGroup::SaveConfig(IniFile::Section* sec, const std::string& defdev,
} }
// extensions // extensions
if (type == GROUP_TYPE_EXTENSION) if (type == GroupType::Extension)
{ {
Extension* const ext = (Extension*)this; Extension* const ext = (Extension*)this;
sec->Set(base + name, ext->attachments[ext->switch_extension]->GetName(), "None"); sec->Set(base + name, ext->attachments[ext->switch_extension]->GetName(), "None");

View File

@ -17,18 +17,18 @@ namespace ControllerEmu
{ {
class Control; class Control;
enum enum class GroupType
{ {
GROUP_TYPE_OTHER, Other,
GROUP_TYPE_STICK, Stick,
GROUP_TYPE_MIXED_TRIGGERS, MixedTriggers,
GROUP_TYPE_BUTTONS, Buttons,
GROUP_TYPE_FORCE, Force,
GROUP_TYPE_EXTENSION, Extension,
GROUP_TYPE_TILT, Tilt,
GROUP_TYPE_CURSOR, Cursor,
GROUP_TYPE_TRIGGERS, Triggers,
GROUP_TYPE_SLIDER Slider
}; };
class ControlGroup class ControlGroup
@ -102,8 +102,9 @@ public:
} }
}; };
explicit ControlGroup(const std::string& name, u32 type = GROUP_TYPE_OTHER); explicit ControlGroup(const std::string& name, GroupType type = GroupType::Other);
ControlGroup(const std::string& name, const std::string& ui_name, u32 type = GROUP_TYPE_OTHER); ControlGroup(const std::string& name, const std::string& ui_name,
GroupType type = GroupType::Other);
virtual ~ControlGroup(); virtual ~ControlGroup();
virtual void LoadConfig(IniFile::Section* sec, const std::string& defdev = "", virtual void LoadConfig(IniFile::Section* sec, const std::string& defdev = "",
@ -115,7 +116,7 @@ public:
const std::string name; const std::string name;
const std::string ui_name; const std::string ui_name;
const u32 type; const GroupType type;
std::vector<std::unique_ptr<Control>> controls; std::vector<std::unique_ptr<Control>> controls;
std::vector<std::unique_ptr<NumericSetting>> numeric_settings; std::vector<std::unique_ptr<NumericSetting>> numeric_settings;

View File

@ -19,7 +19,7 @@
namespace ControllerEmu namespace ControllerEmu
{ {
Cursor::Cursor(const std::string& name_) : ControlGroup(name_, GROUP_TYPE_CURSOR) Cursor::Cursor(const std::string& name_) : ControlGroup(name_, GroupType::Cursor)
{ {
for (auto& named_direction : named_directions) for (auto& named_direction : named_directions)
controls.emplace_back(std::make_unique<Input>(named_direction)); controls.emplace_back(std::make_unique<Input>(named_direction));

View File

@ -10,7 +10,7 @@
namespace ControllerEmu namespace ControllerEmu
{ {
Extension::Extension(const std::string& name_) : ControlGroup(name_, GROUP_TYPE_EXTENSION) Extension::Extension(const std::string& name_) : ControlGroup(name_, GroupType::Extension)
{ {
} }
} // namespace ControllerEmu } // namespace ControllerEmu

View File

@ -16,7 +16,7 @@
namespace ControllerEmu namespace ControllerEmu
{ {
Force::Force(const std::string& name_) : ControlGroup(name_, GROUP_TYPE_FORCE) Force::Force(const std::string& name_) : ControlGroup(name_, GroupType::Force)
{ {
controls.emplace_back(std::make_unique<Input>(_trans("Up"))); controls.emplace_back(std::make_unique<Input>(_trans("Up")));
controls.emplace_back(std::make_unique<Input>(_trans("Down"))); controls.emplace_back(std::make_unique<Input>(_trans("Down")));

View File

@ -17,7 +17,7 @@
namespace ControllerEmu namespace ControllerEmu
{ {
MixedTriggers::MixedTriggers(const std::string& name_) MixedTriggers::MixedTriggers(const std::string& name_)
: ControlGroup(name_, GROUP_TYPE_MIXED_TRIGGERS) : ControlGroup(name_, GroupType::MixedTriggers)
{ {
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Threshold"), 0.9)); numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Threshold"), 0.9));
} }

View File

@ -16,7 +16,7 @@
namespace ControllerEmu namespace ControllerEmu
{ {
Slider::Slider(const std::string& name_) : ControlGroup(name_, GROUP_TYPE_SLIDER) Slider::Slider(const std::string& name_) : ControlGroup(name_, GroupType::Slider)
{ {
controls.emplace_back(std::make_unique<Input>("Left")); controls.emplace_back(std::make_unique<Input>("Left"));
controls.emplace_back(std::make_unique<Input>("Right")); controls.emplace_back(std::make_unique<Input>("Right"));

View File

@ -16,7 +16,7 @@
namespace ControllerEmu namespace ControllerEmu
{ {
Tilt::Tilt(const std::string& name_) : ControlGroup(name_, GROUP_TYPE_TILT) Tilt::Tilt(const std::string& name_) : ControlGroup(name_, GroupType::Tilt)
{ {
controls.emplace_back(std::make_unique<Input>("Forward")); controls.emplace_back(std::make_unique<Input>("Forward"));
controls.emplace_back(std::make_unique<Input>("Backward")); controls.emplace_back(std::make_unique<Input>("Backward"));

View File

@ -15,7 +15,7 @@
namespace ControllerEmu namespace ControllerEmu
{ {
Triggers::Triggers(const std::string& name_) : ControlGroup(name_, GROUP_TYPE_TRIGGERS) Triggers::Triggers(const std::string& name_) : ControlGroup(name_, GroupType::Triggers)
{ {
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Dead Zone"), 0, 0, 50)); numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Dead Zone"), 0, 0, 50));
} }

View File

@ -39,7 +39,7 @@ void EmulatedController::UpdateReferences(const ControllerInterface& devi)
control->control_ref.get()->UpdateReference(devi, default_device); control->control_ref.get()->UpdateReference(devi, default_device);
// extension // extension
if (ctrlGroup->type == GROUP_TYPE_EXTENSION) if (ctrlGroup->type == GroupType::Extension)
{ {
for (auto& attachment : ((Extension*)ctrlGroup.get())->attachments) for (auto& attachment : ((Extension*)ctrlGroup.get())->attachments)
attachment->UpdateReferences(devi); attachment->UpdateReferences(devi);
@ -52,7 +52,7 @@ void EmulatedController::UpdateDefaultDevice()
for (auto& ctrlGroup : groups) for (auto& ctrlGroup : groups)
{ {
// extension // extension
if (ctrlGroup->type == GROUP_TYPE_EXTENSION) if (ctrlGroup->type == GroupType::Extension)
{ {
for (auto& ai : ((Extension*)ctrlGroup.get())->attachments) for (auto& ai : ((Extension*)ctrlGroup.get())->attachments)
{ {