Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TASInputDlg: Minor changes #5196

Merged
merged 7 commits into from
Apr 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
152 changes: 76 additions & 76 deletions Source/Core/DolphinWX/TASInputDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,28 @@ struct TASWiimoteReport
const wiimote_key key;
};

constexpr std::array<int, 12> s_gc_pad_buttons_bitmask{{
PAD_BUTTON_DOWN, PAD_BUTTON_UP, PAD_BUTTON_LEFT, PAD_BUTTON_RIGHT, PAD_BUTTON_A, PAD_BUTTON_B,
PAD_BUTTON_X, PAD_BUTTON_Y, PAD_TRIGGER_Z, PAD_TRIGGER_L, PAD_TRIGGER_R, PAD_BUTTON_START,
}};

constexpr std::array<int, 11> s_wii_buttons_bitmask{{
WiimoteEmu::Wiimote::PAD_DOWN, WiimoteEmu::Wiimote::PAD_UP, WiimoteEmu::Wiimote::PAD_LEFT,
WiimoteEmu::Wiimote::PAD_RIGHT, WiimoteEmu::Wiimote::BUTTON_A, WiimoteEmu::Wiimote::BUTTON_B,
WiimoteEmu::Wiimote::BUTTON_ONE, WiimoteEmu::Wiimote::BUTTON_TWO,
WiimoteEmu::Wiimote::BUTTON_PLUS, WiimoteEmu::Wiimote::BUTTON_MINUS,
WiimoteEmu::Wiimote::BUTTON_HOME,
}};

constexpr std::array<int, 15> s_cc_buttons_bitmask{{
WiimoteEmu::Classic::PAD_DOWN, WiimoteEmu::Classic::PAD_UP, WiimoteEmu::Classic::PAD_LEFT,
WiimoteEmu::Classic::PAD_RIGHT, WiimoteEmu::Classic::BUTTON_A, WiimoteEmu::Classic::BUTTON_B,
WiimoteEmu::Classic::BUTTON_X, WiimoteEmu::Classic::BUTTON_Y, WiimoteEmu::Classic::BUTTON_PLUS,
WiimoteEmu::Classic::BUTTON_MINUS, WiimoteEmu::Classic::TRIGGER_L,
WiimoteEmu::Classic::TRIGGER_R, WiimoteEmu::Classic::BUTTON_ZR, WiimoteEmu::Classic::BUTTON_ZL,
WiimoteEmu::Classic::BUTTON_HOME,
}};

TASInputDlg::TASInputDlg(wxWindow* parent, wxWindowID id, const wxString& title,
const wxPoint& position, const wxSize& size, long style)
: wxDialog(parent, id, title, position, size, style)
Expand All @@ -51,12 +73,9 @@ TASInputDlg::TASInputDlg(wxWindow* parent, wxWindowID id, const wxString& title,

void TASInputDlg::CreateBaseLayout()
{
for (unsigned int i = 0; i < ArraySize(m_controls); ++i)
m_controls[i] = nullptr;
for (unsigned int i = 0; i < ArraySize(m_buttons); ++i)
m_buttons[i] = nullptr;
for (unsigned int i = 0; i < ArraySize(m_cc_controls); ++i)
m_cc_controls[i] = nullptr;
m_controls = {};
m_buttons = {};
m_cc_controls = {};

m_buttons[0] = &m_dpad_down;
m_buttons[1] = &m_dpad_up;
Expand Down Expand Up @@ -93,31 +112,6 @@ void TASInputDlg::CreateBaseLayout()
m_buttons_dpad->Add(space20, space20);
}

static constexpr int s_gc_pad_buttons_bitmask[12] = {
PAD_BUTTON_DOWN, PAD_BUTTON_UP, PAD_BUTTON_LEFT, PAD_BUTTON_RIGHT,
PAD_BUTTON_A, PAD_BUTTON_B, PAD_BUTTON_X, PAD_BUTTON_Y,
PAD_TRIGGER_Z, PAD_TRIGGER_L, PAD_TRIGGER_R, PAD_BUTTON_START};

static constexpr int s_wii_buttons_bitmask[11] = {
WiimoteEmu::Wiimote::PAD_DOWN, WiimoteEmu::Wiimote::PAD_UP,
WiimoteEmu::Wiimote::PAD_LEFT, WiimoteEmu::Wiimote::PAD_RIGHT,
WiimoteEmu::Wiimote::BUTTON_A, WiimoteEmu::Wiimote::BUTTON_B,
WiimoteEmu::Wiimote::BUTTON_ONE, WiimoteEmu::Wiimote::BUTTON_TWO,
WiimoteEmu::Wiimote::BUTTON_PLUS, WiimoteEmu::Wiimote::BUTTON_MINUS,
WiimoteEmu::Wiimote::BUTTON_HOME,
};

static constexpr int s_cc_buttons_bitmask[15] = {
WiimoteEmu::Classic::PAD_DOWN, WiimoteEmu::Classic::PAD_UP,
WiimoteEmu::Classic::PAD_LEFT, WiimoteEmu::Classic::PAD_RIGHT,
WiimoteEmu::Classic::BUTTON_A, WiimoteEmu::Classic::BUTTON_B,
WiimoteEmu::Classic::BUTTON_X, WiimoteEmu::Classic::BUTTON_Y,
WiimoteEmu::Classic::BUTTON_PLUS, WiimoteEmu::Classic::BUTTON_MINUS,
WiimoteEmu::Classic::TRIGGER_L, WiimoteEmu::Classic::TRIGGER_R,
WiimoteEmu::Classic::BUTTON_ZR, WiimoteEmu::Classic::BUTTON_ZL,
WiimoteEmu::Classic::BUTTON_HOME,
};

void TASInputDlg::CreateWiiLayout(int num)
{
if (m_has_layout)
Expand Down Expand Up @@ -209,13 +203,16 @@ void TASInputDlg::CreateWiiLayout(int num)
m_ext_szr->AddSpacer(space5);
m_ext_szr->Add(nunchukaxisBox, 0, wxBOTTOM, space5);

wxGridSizer* const buttons_grid = new wxGridSizer(4);
for (unsigned int i = 4; i < ArraySize(m_buttons); ++i)
// Add non-DPad related buttons first.
auto* const buttons_grid = new wxGridSizer(4);
for (size_t i = 4; i < m_buttons.size(); ++i)
{
if (m_buttons[i] != nullptr)
buttons_grid->Add(m_buttons[i]->checkbox);
}
buttons_grid->Add(space5, space5);

wxStaticBoxSizer* const buttons_box = new wxStaticBoxSizer(wxVERTICAL, this, _("Buttons"));
auto* const buttons_box = new wxStaticBoxSizer(wxVERTICAL, this, _("Buttons"));
buttons_box->Add(buttons_grid);
buttons_box->Add(m_buttons_dpad, 0, wxTOP, space5);

Expand Down Expand Up @@ -278,14 +275,13 @@ wxBoxSizer* TASInputDlg::CreateCCLayout()
const int space5 = FromDIP(5);
const int space20 = FromDIP(20);

wxStaticBoxSizer* const shoulder_box =
new wxStaticBoxSizer(wxHORIZONTAL, this, _("Shoulder Buttons"));
auto* const shoulder_box = new wxStaticBoxSizer(wxHORIZONTAL, this, _("Shoulder Buttons"));
shoulder_box->Add(m_cc_l.slider, 0, wxALIGN_CENTER_VERTICAL);
shoulder_box->Add(m_cc_l.text, 0, wxALIGN_CENTER_VERTICAL);
shoulder_box->Add(m_cc_r.slider, 0, wxALIGN_CENTER_VERTICAL);
shoulder_box->Add(m_cc_r.text, 0, wxALIGN_CENTER_VERTICAL);

wxGridSizer* const cc_buttons_dpad = new wxGridSizer(3);
auto* const cc_buttons_dpad = new wxGridSizer(3);
cc_buttons_dpad->Add(space20, space20);
cc_buttons_dpad->Add(m_cc_buttons[1].checkbox);
cc_buttons_dpad->Add(space20, space20);
Expand All @@ -296,17 +292,17 @@ wxBoxSizer* TASInputDlg::CreateCCLayout()
cc_buttons_dpad->Add(m_cc_buttons[0].checkbox);
cc_buttons_dpad->Add(space20, space20);

wxGridSizer* const cc_buttons_grid = new wxGridSizer(4);
auto* const cc_buttons_grid = new wxGridSizer(4);
for (auto& button : m_cc_buttons)
if (!button.checkbox->GetContainingSizer())
cc_buttons_grid->Add(button.checkbox);
cc_buttons_grid->Add(space5, space5);

wxStaticBoxSizer* const cc_buttons_box = new wxStaticBoxSizer(wxVERTICAL, this, _("Buttons"));
auto* const cc_buttons_box = new wxStaticBoxSizer(wxVERTICAL, this, _("Buttons"));
cc_buttons_box->Add(cc_buttons_grid);
cc_buttons_box->Add(cc_buttons_dpad, 0, wxTOP, space5);

wxBoxSizer* const szr = new wxBoxSizer(wxHORIZONTAL);
auto* const szr = new wxBoxSizer(wxHORIZONTAL);
szr->AddSpacer(space5);
szr->Add(m_cc_l_stick_szr, 0, wxTOP | wxBOTTOM, space5);
szr->AddSpacer(space5);
Expand Down Expand Up @@ -375,8 +371,7 @@ void TASInputDlg::CreateGCLayout()
m_c_stick = CreateStick(ID_C_STICK, 255, 255, 128, 128, false, true);
wxStaticBoxSizer* const c_box = CreateStickLayout(&m_c_stick, _("C Stick"));

wxStaticBoxSizer* const shoulder_box =
new wxStaticBoxSizer(wxHORIZONTAL, this, _("Shoulder Buttons"));
auto* const shoulder_box = new wxStaticBoxSizer(wxHORIZONTAL, this, _("Shoulder Buttons"));
m_l_cont = CreateControl(wxSL_VERTICAL, -1, 100, false, 255, 0);
m_r_cont = CreateControl(wxSL_VERTICAL, -1, 100, false, 255, 0);
shoulder_box->Add(m_l_cont.slider, 0, wxALIGN_CENTER_VERTICAL);
Expand Down Expand Up @@ -405,25 +400,28 @@ void TASInputDlg::CreateGCLayout()

const int space5 = FromDIP(5);

wxGridSizer* const buttons_grid = new wxGridSizer(4);
for (unsigned int i = 4; i < ArraySize(m_buttons); ++i)
// Add non-DPad related buttons first.
auto* const buttons_grid = new wxGridSizer(4);
for (size_t i = 4; i < m_buttons.size(); ++i)
{
if (m_buttons[i] != nullptr)
buttons_grid->Add(m_buttons[i]->checkbox, false);
}
buttons_grid->Add(space5, space5);

wxStaticBoxSizer* const buttons_box = new wxStaticBoxSizer(wxVERTICAL, this, _("Buttons"));
auto* const buttons_box = new wxStaticBoxSizer(wxVERTICAL, this, _("Buttons"));
buttons_box->Add(buttons_grid);
buttons_box->Add(m_buttons_dpad);

wxBoxSizer* const top_box = new wxBoxSizer(wxHORIZONTAL);
auto* const top_box = new wxBoxSizer(wxHORIZONTAL);
top_box->Add(main_box);
top_box->Add(c_box, 0, wxLEFT, space5);

wxBoxSizer* const bottom_box = new wxBoxSizer(wxHORIZONTAL);
auto* const bottom_box = new wxBoxSizer(wxHORIZONTAL);
bottom_box->Add(shoulder_box);
bottom_box->Add(buttons_box, 0, wxLEFT, space5);

wxBoxSizer* const main_szr = new wxBoxSizer(wxVERTICAL);
auto* const main_szr = new wxBoxSizer(wxVERTICAL);
main_szr->AddSpacer(space5);
main_szr->Add(top_box, 0, wxLEFT | wxRIGHT, space5);
main_szr->AddSpacer(space5);
Expand Down Expand Up @@ -473,8 +471,8 @@ wxStaticBoxSizer* TASInputDlg::CreateStickLayout(Stick* stick, const wxString& t
{
const int space3 = FromDIP(3);

wxStaticBoxSizer* const temp_box = new wxStaticBoxSizer(wxVERTICAL, this, title);
wxFlexGridSizer* const layout = new wxFlexGridSizer(2, space3, space3);
auto* const temp_box = new wxStaticBoxSizer(wxVERTICAL, this, title);
auto* const layout = new wxFlexGridSizer(2, space3, space3);

layout->Add(stick->x_cont.slider, 0, wxEXPAND);
layout->Add(stick->x_cont.text, 0, wxALIGN_CENTER);
Expand All @@ -492,10 +490,10 @@ wxStaticBoxSizer* TASInputDlg::CreateStickLayout(Stick* stick, const wxString& t
wxStaticBoxSizer* TASInputDlg::CreateAccelLayout(Control* x, Control* y, Control* z,
const wxString& title)
{
wxStaticBoxSizer* const temp_box = new wxStaticBoxSizer(wxHORIZONTAL, this, title);
wxStaticBoxSizer* const xBox = new wxStaticBoxSizer(wxVERTICAL, this, _("X"));
wxStaticBoxSizer* const yBox = new wxStaticBoxSizer(wxVERTICAL, this, _("Y"));
wxStaticBoxSizer* const zBox = new wxStaticBoxSizer(wxVERTICAL, this, _("Z"));
auto* const temp_box = new wxStaticBoxSizer(wxHORIZONTAL, this, title);
auto* const xBox = new wxStaticBoxSizer(wxVERTICAL, this, _("X"));
auto* const yBox = new wxStaticBoxSizer(wxVERTICAL, this, _("Y"));
auto* const zBox = new wxStaticBoxSizer(wxVERTICAL, this, _("Z"));
const int space5 = FromDIP(5);

xBox->Add(x->slider, 0, wxALIGN_CENTER_HORIZONTAL);
Expand All @@ -518,7 +516,7 @@ TASInputDlg::Button TASInputDlg::CreateButton(const wxString& name)
{
Button temp;
temp.id = m_eleID++;
wxCheckBox* checkbox = new wxCheckBox(this, temp.id, name);
auto* checkbox = new wxCheckBox(this, temp.id, name);
checkbox->Bind(wxEVT_RIGHT_DOWN, &TASInputDlg::SetTurbo, this);
checkbox->Bind(wxEVT_LEFT_DOWN, &TASInputDlg::SetTurbo, this);
checkbox->Bind(wxEVT_CHECKBOX, &TASInputDlg::OnCheckboxToggle, this);
Expand Down Expand Up @@ -636,7 +634,7 @@ void TASInputDlg::SetButtonValue(Button* button, bool CurrentState)
// NOTE: Host / CPU Thread
void TASInputDlg::SetWiiButtons(u16* butt)
{
for (unsigned int i = 0; i < 11; ++i)
for (size_t i = 0; i < s_wii_buttons_bitmask.size(); ++i)
{
if (m_buttons[i] != nullptr)
*butt |= (m_buttons[i]->is_checked) ? s_wii_buttons_bitmask[i] : 0;
Expand All @@ -655,7 +653,7 @@ void TASInputDlg::GetKeyBoardInput(GCPadStatus* PadStatus)
SetSliderValue(&m_l_cont, PadStatus->triggerLeft);
SetSliderValue(&m_r_cont, PadStatus->triggerRight);

for (unsigned int i = 0; i < ArraySize(m_buttons); ++i)
for (size_t i = 0; i < m_buttons.size(); ++i)
{
if (m_buttons[i] != nullptr)
SetButtonValue(m_buttons[i], ((PadStatus->button & s_gc_pad_buttons_bitmask[i]) != 0));
Expand All @@ -677,7 +675,7 @@ void TASInputDlg::GetKeyBoardInput(u8* data, WiimoteEmu::ReportFeatures rptf, in

if (coreData)
{
for (unsigned int i = 0; i < 11; ++i)
for (size_t i = 0; i < s_wii_buttons_bitmask.size(); ++i)
{
if (m_buttons[i] != nullptr)
SetButtonValue(m_buttons[i],
Expand Down Expand Up @@ -719,7 +717,7 @@ void TASInputDlg::GetKeyBoardInput(u8* data, WiimoteEmu::ReportFeatures rptf, in
wm_classic_extension& cc = *(wm_classic_extension*)extData;
WiimoteDecrypt(&key, (u8*)&cc, 0, sizeof(wm_classic_extension));
cc.bt.hex = cc.bt.hex ^ 0xFFFF;
for (unsigned int i = 0; i < 15; ++i)
for (size_t i = 0; i < m_cc_buttons.size(); ++i)
{
SetButtonValue(&m_cc_buttons[i], ((cc.bt.hex & s_cc_buttons_bitmask[i]) != 0));
}
Expand Down Expand Up @@ -776,11 +774,10 @@ void TASInputDlg::GetValues(u8* data, WiimoteEmu::ReportFeatures rptf, int ext,
}
if (irData)
{
u16 x[4];
u16 y;
std::array<u16, 4> x;
u16 y = m_main_stick.y_cont.value;

x[0] = m_main_stick.x_cont.value;
y = m_main_stick.y_cont.value;
x[1] = x[0] + 100;
x[2] = x[0] - 10;
x[3] = x[1] + 10;
Expand Down Expand Up @@ -820,7 +817,7 @@ void TASInputDlg::GetValues(u8* data, WiimoteEmu::ReportFeatures rptf, int ext,
{
memset(data, 0xFF, sizeof(wm_ir_extended) * 4);
wm_ir_extended* const ir_data = (wm_ir_extended*)irData;
for (unsigned int i = 0; i < 4; ++i)
for (size_t i = 0; i < x.size(); ++i)
{
if (x[i] < 1024 && y < 768)
{
Expand Down Expand Up @@ -866,7 +863,7 @@ void TASInputDlg::GetValues(u8* data, WiimoteEmu::ReportFeatures rptf, int ext,
WiimoteDecrypt(&key, (u8*)&cc, 0, sizeof(wm_classic_extension));
cc.bt.hex = 0;

for (unsigned int i = 0; i < ArraySize(m_cc_buttons); ++i)
for (size_t i = 0; i < m_cc_buttons.size(); ++i)
{
cc.bt.hex |= (m_cc_buttons[i].is_checked) ? s_cc_buttons_bitmask[i] : 0;
}
Expand Down Expand Up @@ -905,7 +902,7 @@ void TASInputDlg::GetValues(GCPadStatus* PadStatus)
PadStatus->triggerLeft = m_l.is_checked ? 255 : m_l_cont.value;
PadStatus->triggerRight = m_r.is_checked ? 255 : m_r_cont.value;

for (unsigned int i = 0; i < ArraySize(m_buttons); ++i)
for (size_t i = 0; i < m_buttons.size(); ++i)
{
if (m_buttons[i] != nullptr)
{
Expand Down Expand Up @@ -944,16 +941,19 @@ void TASInputDlg::UpdateFromSliders(wxCommandEvent& event)
if (control != nullptr && event.GetId() == control->slider_id)
text = control->text;
}
int value = ((wxSlider*)event.GetEventObject())->GetValue();
if (text)
text->SetValue(std::to_string(value));

if (!text)
return;

const int slider_value = event.GetInt();
text->SetValue(std::to_string(slider_value));
}

void TASInputDlg::UpdateFromText(wxCommandEvent& event)
{
unsigned long value;

if (!((wxTextCtrl*)event.GetEventObject())->GetValue().ToULong(&value))
if (!event.GetString().ToULong(&value))
return;

for (Control* const control : m_controls)
Expand Down Expand Up @@ -1157,9 +1157,9 @@ void TASInputDlg::InvalidateButton(Button* button)
{
if (!wxIsMainThread())
{
wxCommandEvent* evt = new wxCommandEvent(INVALIDATE_BUTTON_EVENT, button->id);
auto* evt = new wxCommandEvent(INVALIDATE_BUTTON_EVENT, button->id);
evt->SetClientData(button);
wxQueueEvent(this, evt);
QueueEvent(evt);
return;
}

Expand All @@ -1171,9 +1171,9 @@ void TASInputDlg::InvalidateControl(Control* control)
{
if (!wxIsMainThread())
{
wxCommandEvent* evt = new wxCommandEvent(INVALIDATE_CONTROL_EVENT, control->text_id);
auto* evt = new wxCommandEvent(INVALIDATE_CONTROL_EVENT, control->text_id);
evt->SetClientData(control);
wxQueueEvent(this, evt);
QueueEvent(evt);
return;
}

Expand All @@ -1184,7 +1184,7 @@ void TASInputDlg::InvalidateExtension()
{
if (!wxIsMainThread())
{
GetEventHandler()->QueueEvent(new wxThreadEvent(INVALIDATE_EXTENSION_EVENT));
QueueEvent(new wxThreadEvent(INVALIDATE_EXTENSION_EVENT));
return;
}

Expand All @@ -1193,7 +1193,7 @@ void TASInputDlg::InvalidateExtension()

void TASInputDlg::UpdateFromInvalidatedButton(wxCommandEvent& event)
{
Button* button = static_cast<Button*>(event.GetClientData());
auto* button = static_cast<Button*>(event.GetClientData());
_assert_msg_(PAD, button->id == button->checkbox->GetId(), "Button ids do not match: %i != %i",
button->id, button->checkbox->GetId());
button->checkbox->SetValue(button->value);
Expand All @@ -1202,7 +1202,7 @@ void TASInputDlg::UpdateFromInvalidatedButton(wxCommandEvent& event)

void TASInputDlg::UpdateFromInvalidatedControl(wxCommandEvent& event)
{
Control* control = static_cast<Control*>(event.GetClientData());
auto* control = static_cast<Control*>(event.GetClientData());
_assert_msg_(PAD, control->text_id == control->text->GetId(),
"Control ids do not match: %i != %i", control->text_id, control->text->GetId());
control->text->SetValue(std::to_string(control->value));
Expand Down