Pad: Don't `Destroy()` modals

On macOS it prevents the parent window from regaining focus
Also remove OK/Cancel buttons JoystickConfiguration, they already obey the Cancel/Apply/OK of the parent
This commit is contained in:
TellowKrinkle 2021-02-03 19:08:49 -06:00 committed by tellowkrinkle
parent 1470315356
commit 4890a26ae0
4 changed files with 36 additions and 116 deletions

View File

@ -49,9 +49,6 @@ GamepadConfiguration::GamepadConfiguration(int pad, wxWindow* parent)
gamepad_box->Add(rumble_box, wxSizerFlags().Expand().Border(wxALL, 5)); gamepad_box->Add(rumble_box, wxSizerFlags().Expand().Border(wxALL, 5));
gamepad_box->Add(joy_box, wxSizerFlags().Expand().Border(wxALL, 5)); gamepad_box->Add(joy_box, wxSizerFlags().Expand().Border(wxALL, 5));
gamepad_box->Add(CreateSeparatedButtonSizer(wxOK), wxSizerFlags().Right().Border(wxALL, 5));
Bind(wxEVT_BUTTON, &GamepadConfiguration::OnOk, this, wxID_OK);
Bind(wxEVT_SCROLL_THUMBRELEASE, &GamepadConfiguration::OnSliderReleased, this); Bind(wxEVT_SCROLL_THUMBRELEASE, &GamepadConfiguration::OnSliderReleased, this);
Bind(wxEVT_CHECKBOX, &GamepadConfiguration::OnCheckboxChange, this); Bind(wxEVT_CHECKBOX, &GamepadConfiguration::OnCheckboxChange, this);
Bind(wxEVT_CHOICE, &GamepadConfiguration::OnChoiceChange, this); Bind(wxEVT_CHOICE, &GamepadConfiguration::OnChoiceChange, this);
@ -99,11 +96,6 @@ void GamepadConfiguration::InitGamepadConfiguration()
} }
} }
void GamepadConfiguration::OnOk(wxCommandEvent& event)
{
Destroy();
}
/** /**
* Slider event, called when the use release the slider button * Slider event, called when the use release the slider button
* @FIXME The current solution can't change the joystick sensibility and the rumble intensity * @FIXME The current solution can't change the joystick sensibility and the rumble intensity

View File

@ -40,7 +40,6 @@ class GamepadConfiguration : public wxDialog
void repopulate(); void repopulate();
// Events // Events
void OnOk(wxCommandEvent&);
void OnSliderReleased(wxCommandEvent&); void OnSliderReleased(wxCommandEvent&);
void OnCheckboxChange(wxCommandEvent&); void OnCheckboxChange(wxCommandEvent&);
void OnChoiceChange(wxCommandEvent&); void OnChoiceChange(wxCommandEvent&);

View File

@ -15,15 +15,15 @@
#include "JoystickConfiguration.h" #include "JoystickConfiguration.h"
static const s32 x_check_id = wxID_HIGHEST + 100 + 1;
static const s32 y_check_id = wxID_HIGHEST + 100 + 2;
static const s32 joy_check_id = wxID_HIGHEST + 100 + 3;
// Constructor of JoystickConfiguration // Constructor of JoystickConfiguration
JoystickConfiguration::JoystickConfiguration(int pad, bool left, wxWindow* parent) JoystickConfiguration::JoystickConfiguration(int pad, bool left, wxWindow* parent)
: wxDialog(parent, wxID_ANY, _T("Joystick configuration"), wxDefaultPosition, wxDefaultSize, : wxDialog(parent, wxID_ANY, _T("Joystick configuration"), wxDefaultPosition, wxDefaultSize,
wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX | wxCLIP_CHILDREN) wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX | wxCLIP_CHILDREN)
{ {
m_init_reverse_Lx = m_init_reverse_Ly =
m_init_reverse_Rx = m_init_reverse_Ry =
m_init_mouse_Ljoy = m_init_mouse_Rjoy = false;
m_pad_id = pad; m_pad_id = pad;
m_isForLeftJoystick = left; m_isForLeftJoystick = left;
@ -31,33 +31,21 @@ JoystickConfiguration::JoystickConfiguration(int pad, bool left, wxWindow* paren
if (m_isForLeftJoystick) if (m_isForLeftJoystick)
{ {
m_cb_reverse_Lx = new wxCheckBox(this, Lx_check_id, _T("Reverse Lx")); m_cb_reverse_x = new wxCheckBox(this, x_check_id, _T("Reverse Lx"));
m_cb_reverse_Ly = new wxCheckBox(this, Ly_check_id, _T("Reverse Ly")); m_cb_reverse_y = new wxCheckBox(this, y_check_id, _T("Reverse Ly"));
m_cb_mouse_Ljoy = new wxCheckBox(this, Ljoy_check_id, _T("Use mouse for left analog joystick")); m_cb_mouse_joy = new wxCheckBox(this, joy_check_id, _T("Use mouse for left analog joystick"));
joy_conf_box->Add(m_cb_reverse_Lx, wxSizerFlags().Expand().Border(wxLEFT | wxRIGHT, 5));
joy_conf_box->Add(m_cb_reverse_Ly, wxSizerFlags().Expand().Border(wxLEFT | wxRIGHT, 5));
joy_conf_box->Add(m_cb_mouse_Ljoy, wxSizerFlags().Expand().Border(wxLEFT | wxRIGHT, 5));
m_cb_reverse_Rx = m_cb_reverse_Ry = m_cb_mouse_Rjoy = nullptr;
} }
else else
{ {
m_cb_reverse_Rx = new wxCheckBox(this, Rx_check_id, _T("Reverse Rx")); m_cb_reverse_x = new wxCheckBox(this, x_check_id, _T("Reverse Rx"));
m_cb_reverse_Ry = new wxCheckBox(this, Ry_check_id, _T("Reverse Ry")); m_cb_reverse_y = new wxCheckBox(this, y_check_id, _T("Reverse Ry"));
m_cb_mouse_Rjoy = new wxCheckBox(this, Rjoy_check_id, _T("Use mouse for right analog joystick")); m_cb_mouse_joy = new wxCheckBox(this, joy_check_id, _T("Use mouse for right analog joystick"));
joy_conf_box->Add(m_cb_reverse_Rx, wxSizerFlags().Expand().Border(wxLEFT | wxRIGHT, 5));
joy_conf_box->Add(m_cb_reverse_Ry, wxSizerFlags().Expand().Border(wxLEFT | wxRIGHT, 5));
joy_conf_box->Add(m_cb_mouse_Rjoy, wxSizerFlags().Expand().Border(wxLEFT | wxRIGHT, 5));
m_cb_reverse_Lx = m_cb_reverse_Ly = m_cb_mouse_Ljoy = nullptr;
} }
joy_conf_box->Add(CreateSeparatedButtonSizer(wxOK | wxCANCEL), wxSizerFlags().Border(wxALL, 5).Right()); joy_conf_box->Add(m_cb_reverse_x, wxSizerFlags().Expand().Border(wxLEFT | wxRIGHT, 5));
joy_conf_box->Add(m_cb_reverse_y, wxSizerFlags().Expand().Border(wxLEFT | wxRIGHT, 5));
joy_conf_box->Add(m_cb_mouse_joy, wxSizerFlags().Expand().Border(wxLEFT | wxRIGHT, 5));
Bind(wxEVT_BUTTON, &JoystickConfiguration::OnOk, this, wxID_OK);
Bind(wxEVT_BUTTON, &JoystickConfiguration::OnCancel, this, wxID_CANCEL);
Bind(wxEVT_CHECKBOX, &JoystickConfiguration::OnCheckboxChange, this); Bind(wxEVT_CHECKBOX, &JoystickConfiguration::OnCheckboxChange, this);
SetSizerAndFit(joy_conf_box); SetSizerAndFit(joy_conf_box);
@ -84,30 +72,11 @@ void JoystickConfiguration::InitJoystickConfiguration()
wxMessageBox(L"No second gamepad detected."); wxMessageBox(L"No second gamepad detected.");
// disable all checkboxes // disable all checkboxes
if (m_isForLeftJoystick) m_cb_reverse_y->Disable();
{ m_cb_reverse_x->Disable();
m_cb_reverse_Lx->Disable();
m_cb_reverse_Ly->Disable();
}
else
{
m_cb_reverse_Rx->Disable();
m_cb_reverse_Ry->Disable();
}
} }
} }
void JoystickConfiguration::OnOk(wxCommandEvent& event)
{
Destroy();
}
void JoystickConfiguration::OnCancel(wxCommandEvent& event)
{
reset();
Destroy();
}
/** /**
* Checkbox event, called when the value of the checkbox change * Checkbox event, called when the value of the checkbox change
*/ */
@ -120,16 +89,16 @@ void JoystickConfiguration::OnCheckboxChange(wxCommandEvent& event)
{ {
switch (cb_id) switch (cb_id)
{ {
case Lx_check_id: case x_check_id:
g_conf.pad_options[m_pad_id].reverse_lx = m_cb_reverse_Lx->GetValue(); g_conf.pad_options[m_pad_id].reverse_lx = m_cb_reverse_x->GetValue();
break; break;
case Ly_check_id: case y_check_id:
g_conf.pad_options[m_pad_id].reverse_ly = m_cb_reverse_Ly->GetValue(); g_conf.pad_options[m_pad_id].reverse_ly = m_cb_reverse_y->GetValue();
break; break;
case Ljoy_check_id: case joy_check_id:
g_conf.pad_options[m_pad_id].mouse_l = m_cb_mouse_Ljoy->GetValue(); g_conf.pad_options[m_pad_id].mouse_l = m_cb_mouse_joy->GetValue();
break; break;
default: default:
@ -140,16 +109,16 @@ void JoystickConfiguration::OnCheckboxChange(wxCommandEvent& event)
{ {
switch (cb_id) switch (cb_id)
{ {
case Rx_check_id: case x_check_id:
g_conf.pad_options[m_pad_id].reverse_rx = m_cb_reverse_Rx->GetValue(); g_conf.pad_options[m_pad_id].reverse_rx = m_cb_reverse_x->GetValue();
break; break;
case Ry_check_id: case y_check_id:
g_conf.pad_options[m_pad_id].reverse_ry = m_cb_reverse_Ry->GetValue(); g_conf.pad_options[m_pad_id].reverse_ry = m_cb_reverse_y->GetValue();
break; break;
case Rjoy_check_id: case joy_check_id:
g_conf.pad_options[m_pad_id].mouse_r = m_cb_mouse_Rjoy->GetValue(); g_conf.pad_options[m_pad_id].mouse_r = m_cb_mouse_joy->GetValue();
break; break;
default: default:
@ -162,46 +131,19 @@ void JoystickConfiguration::OnCheckboxChange(wxCommandEvent& event)
/*********** Methods functions **********/ /*********** Methods functions **********/
/****************************************/ /****************************************/
// Reset checkbox and slider values
void JoystickConfiguration::reset()
{
if (m_isForLeftJoystick)
{
m_cb_reverse_Lx->SetValue(m_init_reverse_Lx);
m_cb_reverse_Ly->SetValue(m_init_reverse_Ly);
m_cb_mouse_Ljoy->SetValue(m_init_mouse_Ljoy);
}
else
{
m_cb_reverse_Rx->SetValue(m_init_reverse_Rx);
m_cb_reverse_Ry->SetValue(m_init_reverse_Ry);
m_cb_mouse_Rjoy->SetValue(m_init_mouse_Rjoy);
}
}
// Set button values // Set button values
void JoystickConfiguration::repopulate() void JoystickConfiguration::repopulate()
{ {
if (m_isForLeftJoystick) if (m_isForLeftJoystick)
{ {
m_init_reverse_Lx = g_conf.pad_options[m_pad_id].reverse_lx; m_cb_reverse_x->SetValue(g_conf.pad_options[m_pad_id].reverse_lx);
m_cb_reverse_Lx->SetValue(m_init_reverse_Lx); m_cb_reverse_y->SetValue(g_conf.pad_options[m_pad_id].reverse_ly);
m_cb_mouse_joy->SetValue(g_conf.pad_options[m_pad_id].mouse_l);
m_init_reverse_Ly = g_conf.pad_options[m_pad_id].reverse_ly;
m_cb_reverse_Ly->SetValue(m_init_reverse_Ly);
m_init_mouse_Ljoy = g_conf.pad_options[m_pad_id].mouse_l;
m_cb_mouse_Ljoy->SetValue(m_init_mouse_Ljoy);
} }
else else
{ {
m_init_reverse_Rx = g_conf.pad_options[m_pad_id].reverse_rx; m_cb_reverse_x->SetValue(g_conf.pad_options[m_pad_id].reverse_rx);
m_cb_reverse_Rx->SetValue(m_init_reverse_Rx); m_cb_reverse_y->SetValue(g_conf.pad_options[m_pad_id].reverse_ry);
m_cb_mouse_joy->SetValue(g_conf.pad_options[m_pad_id].mouse_r);
m_init_reverse_Ry = g_conf.pad_options[m_pad_id].reverse_ry;
m_cb_reverse_Ry->SetValue(m_init_reverse_Ry);
m_init_mouse_Rjoy = g_conf.pad_options[m_pad_id].mouse_r;
m_cb_mouse_Rjoy->SetValue(m_init_mouse_Rjoy);
} }
} }

View File

@ -24,33 +24,20 @@
#include "../keyboard.h" #include "../keyboard.h"
#include "../PAD.h" #include "../PAD.h"
static const s32 Lx_check_id = wxID_HIGHEST + 100 + 1;
static const s32 Ly_check_id = wxID_HIGHEST + 100 + 2;
static const s32 Ljoy_check_id = wxID_HIGHEST + 100 + 3;
static const s32 Rx_check_id = wxID_HIGHEST + 100 + 4;
static const s32 Ry_check_id = wxID_HIGHEST + 100 + 5;
static const s32 Rjoy_check_id = wxID_HIGHEST + 100 + 6;
class JoystickConfiguration : public wxDialog class JoystickConfiguration : public wxDialog
{ {
wxCheckBox *m_cb_reverse_Lx, *m_cb_reverse_Ly, *m_cb_reverse_Rx, *m_cb_reverse_Ry, wxCheckBox *m_cb_reverse_x, *m_cb_reverse_y,
*m_cb_mouse_Ljoy, // Use mouse for left joystick *m_cb_mouse_joy; // Use mouse for joystick
*m_cb_mouse_Rjoy; // Use mouse for right joystick
u32 m_pad_id; u32 m_pad_id;
// isForLeftJoystick -> true is for Left Joystick, false is for Right Joystick // isForLeftJoystick -> true is for Left Joystick, false is for Right Joystick
bool m_init_reverse_Lx, m_init_reverse_Ly, m_init_reverse_Rx, m_init_reverse_Ry, bool m_isForLeftJoystick;
m_init_mouse_Ljoy, m_init_mouse_Rjoy, m_isForLeftJoystick;
// Methods // Methods
void repopulate(); void repopulate();
void reset();
// Events // Events
void OnCheckboxChange(wxCommandEvent&); void OnCheckboxChange(wxCommandEvent&);
void OnOk(wxCommandEvent&);
void OnCancel(wxCommandEvent&);
public: public:
JoystickConfiguration(int, bool, wxWindow*); JoystickConfiguration(int, bool, wxWindow*);