Onepad : Fix compilation with wx2.8

Feedback fix, when more than two gamepad are used simultaneously.
Change all 'this->' by 'm_'
fix on the hack sixaxis pressure
Modification of the size (1000x760 -> 1000x730)
This commit is contained in:
kust2708 2015-11-29 15:42:42 +01:00
parent 02b5d80bb9
commit 0b0e2a3f34
7 changed files with 414 additions and 360 deletions

View File

@ -25,7 +25,7 @@ GamepadConfiguration::GamepadConfiguration(int pad, wxWindow *parent) : wxFrame(
wxID_ANY, // ID wxID_ANY, // ID
_T("Gamepad configuration"), // Title _T("Gamepad configuration"), // Title
wxDefaultPosition, // Position wxDefaultPosition, // Position
wxSize(400, 200), // Width + Lenght wxSize(400, 230), // Width + Lenght
// Style // Style
wxSYSTEM_MENU | wxSYSTEM_MENU |
wxCAPTION | wxCAPTION |
@ -34,45 +34,45 @@ GamepadConfiguration::GamepadConfiguration(int pad, wxWindow *parent) : wxFrame(
) )
{ {
this->pad_id = pad; m_pad_id = pad;
this->pan_gamepad_config = new wxPanel( m_pan_gamepad_config = new wxPanel(
this, // Parent this, // Parent
wxID_ANY, // ID wxID_ANY, // ID
wxDefaultPosition, // Prosition wxDefaultPosition, // Prosition
wxSize(300, 200) // Size wxSize(300, 200) // Size
); );
this->cb_rumble = new wxCheckBox( m_cb_rumble = new wxCheckBox(
this->pan_gamepad_config, // Parent m_pan_gamepad_config, // Parent
wxID_ANY, // ID wxID_ANY, // ID
_T("&Enable rumble"), // Label _T("&Enable rumble"), // Label
wxPoint(20, 20) // Position wxPoint(20, 20) // Position
); );
this->cb_hack_sixaxis_usb = new wxCheckBox( m_cb_hack_sixaxis_usb = new wxCheckBox(
this->pan_gamepad_config, // Parent m_pan_gamepad_config, // Parent
wxID_ANY, // ID wxID_ANY, // ID
_T("&Hack: Sixaxis/DS3 plugged in USB"), // Label _T("&Hack: Sixaxis/DS3 plugged in USB"), // Label
wxPoint(20, 40) // Position wxPoint(20, 40) // Position
); );
this->cb_hack_sixaxis_pressure = new wxCheckBox( m_cb_hack_sixaxis_pressure = new wxCheckBox(
this->pan_gamepad_config, // Parent m_pan_gamepad_config, // Parent
wxID_ANY, // ID wxID_ANY, // ID
_T("&Hack: Sixaxis/DS3 pressure"), // Label _T("&Hack: Sixaxis/DS3 pressure"), // Label
wxPoint(20, 60) // Position wxPoint(20, 60) // Position
); );
wxString txt_rumble = wxT("Rumble intensity"); wxString txt_rumble = wxT("Rumble intensity");
this->lbl_rumble_intensity = new wxStaticText( m_lbl_rumble_intensity = new wxStaticText(
this->pan_gamepad_config, // Parent m_pan_gamepad_config, // Parent
wxID_ANY, // ID wxID_ANY, // ID
txt_rumble, // Text which must be displayed txt_rumble, // Text which must be displayed
wxPoint(20, 90), // Position wxPoint(20, 90), // Position
wxDefaultSize // Size wxDefaultSize // Size
); );
this->sl_rumble_intensity = new wxSlider( m_sl_rumble_intensity = new wxSlider(
this->pan_gamepad_config, // Parent m_pan_gamepad_config, // Parent
wxID_ANY, // ID wxID_ANY, // ID
0, // value 0, // value
0, // min value 0x0000 0, // min value 0x0000
@ -82,16 +82,16 @@ GamepadConfiguration::GamepadConfiguration(int pad, wxWindow *parent) : wxFrame(
); );
wxString txt_joystick = wxT("Joystick sensibility"); wxString txt_joystick = wxT("Joystick sensibility");
this->lbl_rumble_intensity = new wxStaticText( m_lbl_rumble_intensity = new wxStaticText(
this->pan_gamepad_config, // Parent m_pan_gamepad_config, // Parent
wxID_ANY, // ID wxID_ANY, // ID
txt_joystick, // Text which must be displayed txt_joystick, // Text which must be displayed
wxPoint(20, 120), // Position wxPoint(20, 120), // Position
wxDefaultSize // Size wxDefaultSize // Size
); );
this->sl_joystick_sensibility = new wxSlider( m_sl_joystick_sensibility = new wxSlider(
this->pan_gamepad_config, // Parent m_pan_gamepad_config, // Parent
wxID_ANY, // ID wxID_ANY, // ID
0, // value 0, // value
0, // min value 0, // min value
@ -100,16 +100,16 @@ GamepadConfiguration::GamepadConfiguration(int pad, wxWindow *parent) : wxFrame(
wxSize(200, 30) // Size wxSize(200, 30) // Size
); );
this->bt_ok = new wxButton( m_bt_ok = new wxButton(
this->pan_gamepad_config, // Parent m_pan_gamepad_config, // Parent
wxID_ANY, // ID wxID_ANY, // ID
_T("&OK"), // Label _T("&OK"), // Label
wxPoint(250, 160), // Position wxPoint(250, 160), // Position
wxSize(60,25) // Size wxSize(60,25) // Size
); );
this->bt_cancel = new wxButton( m_bt_cancel = new wxButton(
this->pan_gamepad_config, // Parent m_pan_gamepad_config, // Parent
wxID_ANY, // ID wxID_ANY, // ID
_T("&Cancel"), // Label _T("&Cancel"), // Label
wxPoint(320, 160), // Position wxPoint(320, 160), // Position
@ -117,20 +117,28 @@ GamepadConfiguration::GamepadConfiguration(int pad, wxWindow *parent) : wxFrame(
); );
// Connect the buttons to the OnButtonClicked Event // Connect the buttons to the OnButtonClicked Event
this->Connect( Connect(
wxEVT_COMMAND_BUTTON_CLICKED, wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(GamepadConfiguration::OnButtonClicked) wxCommandEventHandler(GamepadConfiguration::OnButtonClicked)
); );
// Connect the sliders to the OnSliderReleased Event // Connect the sliders to the OnSliderReleased Event
this->Connect( Connect(
wxEVT_SCROLL_THUMBRELEASE, wxEVT_SCROLL_THUMBRELEASE,
wxCommandEventHandler(GamepadConfiguration::OnSliderReleased) wxCommandEventHandler(GamepadConfiguration::OnSliderReleased)
); );
// Connect the checkboxes to the OnCheckboxClicked Event // Connect the checkboxes to the OnCheckboxClicked Event
this->Connect( #if wxMAJOR_VERSION >= 3
Connect(
wxEVT_CHECKBOX, wxEVT_CHECKBOX,
wxCommandEventHandler(GamepadConfiguration::OnCheckboxChange) wxCommandEventHandler(GamepadConfiguration::OnCheckboxChange)
); );
#else
Connect(
wxEVT_COMMAND_CHECKBOX_CLICKED,
wxCommandEventHandler(GamepadConfiguration::OnCheckboxChange)
);
#endif
} }
/** /**
@ -140,14 +148,14 @@ GamepadConfiguration::GamepadConfiguration(int pad, wxWindow *parent) : wxFrame(
*/ */
void GamepadConfiguration::InitGamepadConfiguration() void GamepadConfiguration::InitGamepadConfiguration()
{ {
this->repopulate(); // Set label and fit simulated key array repopulate(); // Set label and fit simulated key array
/* /*
* Check if there exist at least one pad available * Check if there exist at least one pad available
* if the pad id is 0, you need at least 1 gamepad connected, * if the pad id is 0, you need at least 1 gamepad connected,
* if the pad id is 1, you need at least 2 gamepad connected, * if the pad id is 1, you need at least 2 gamepad connected,
* Prevent to use a none initialized value on s_vgamePad (core dump) * Prevent to use a none initialized value on s_vgamePad (core dump)
*/ */
if(s_vgamePad.size() >= this->pad_id+1) if(s_vgamePad.size() >= m_pad_id+1)
{ {
/* /*
* Determine if the device can use rumble * Determine if the device can use rumble
@ -155,19 +163,19 @@ void GamepadConfiguration::InitGamepadConfiguration()
* May be better to create a new function in order to check only that * May be better to create a new function in order to check only that
*/ */
if(!s_vgamePad[this->pad_id]->TestForce(0.001f)) if(!s_vgamePad[m_pad_id]->TestForce(0.001f))
{ {
wxMessageBox("Rumble is not available for your device."); wxMessageBox(L"Rumble is not available for your device.");
this->cb_rumble->Disable(); // disable the rumble checkbox m_cb_rumble->Disable(); // disable the rumble checkbox
this->sl_rumble_intensity->Disable(); // disable the rumble intensity slider m_sl_rumble_intensity->Disable(); // disable the rumble intensity slider
} }
} }
else else
{ {
wxMessageBox("No gamepad detected."); wxMessageBox(L"No gamepad detected.");
this->sl_joystick_sensibility->Disable(); // disable the joystick sensibility slider m_sl_joystick_sensibility->Disable(); // disable the joystick sensibility slider
this->cb_rumble->Disable(); // disable the rumble checkbox m_cb_rumble->Disable(); // disable the rumble checkbox
this->sl_rumble_intensity->Disable(); // disable the rumble intensity slider m_sl_rumble_intensity->Disable(); // disable the rumble intensity slider
} }
} }
@ -183,14 +191,14 @@ void GamepadConfiguration::OnButtonClicked(wxCommandEvent &event)
// Affichage d'un message à chaque clic sur le bouton // Affichage d'un message à chaque clic sur le bouton
wxButton* bt_tmp = (wxButton*)event.GetEventObject(); // get the button object wxButton* bt_tmp = (wxButton*)event.GetEventObject(); // get the button object
int bt_id = bt_tmp->GetId(); // get the real ID int bt_id = bt_tmp->GetId(); // get the real ID
if(bt_id == this->bt_ok->GetId()) // If the button ID is equals to the Ok button ID if(bt_id == m_bt_ok->GetId()) // If the button ID is equals to the Ok button ID
{ {
this->Close(); // Close the window Close(); // Close the window
} }
else if(bt_id == this->bt_cancel->GetId()) // If the button ID is equals to the cancel button ID else if(bt_id == m_bt_cancel->GetId()) // If the button ID is equals to the cancel button ID
{ {
this->reset(); // reinitialize the value of each parameters reset(); // reinitialize the value of each parameters
this->Close(); // Close the window Close(); // Close the window
} }
} }
@ -203,12 +211,12 @@ void GamepadConfiguration::OnSliderReleased(wxCommandEvent &event)
{ {
wxSlider* sl_tmp = (wxSlider*)event.GetEventObject(); // get the slider object wxSlider* sl_tmp = (wxSlider*)event.GetEventObject(); // get the slider object
int sl_id = sl_tmp->GetId(); // slider id int sl_id = sl_tmp->GetId(); // slider id
if(sl_id == this->sl_rumble_intensity->GetId()) // if this is the rumble intensity slider if(sl_id == m_sl_rumble_intensity->GetId()) // if this is the rumble intensity slider
{ {
u32 intensity = this->sl_rumble_intensity->GetValue(); // get the new value u32 intensity = m_sl_rumble_intensity->GetValue(); // get the new value
conf->set_ff_intensity(intensity); // and set the force feedback intensity value with it conf->set_ff_intensity(intensity); // and set the force feedback intensity value with it
// get the rumble intensity // get the rumble intensity
float strength = this->sl_rumble_intensity->GetValue(); float strength = m_sl_rumble_intensity->GetValue();
/* /*
* convert in a float value between 0 and 1, and run rumble feedback * convert in a float value between 0 and 1, and run rumble feedback
* 1 -> 0x7FFF * 1 -> 0x7FFF
@ -220,11 +228,11 @@ void GamepadConfiguration::OnSliderReleased(wxCommandEvent &event)
* 0x7FFF : maximum intensity * 0x7FFF : maximum intensity
* 1 : maximum value of the intensity for the sdl rumble test * 1 : maximum value of the intensity for the sdl rumble test
*/ */
s_vgamePad[this->pad_id]->TestForce(strength/0x7FFF); s_vgamePad[m_pad_id]->TestForce(strength/0x7FFF);
} }
else if(sl_id == this->sl_joystick_sensibility->GetId()) else if(sl_id == m_sl_joystick_sensibility->GetId())
{ {
u32 sensibility = this->sl_joystick_sensibility->GetValue(); // get the new value u32 sensibility = m_sl_joystick_sensibility->GetValue(); // get the new value
conf->set_sensibility(sensibility); // and set the joystick sensibility conf->set_sensibility(sensibility); // and set the joystick sensibility
} }
} }
@ -236,26 +244,26 @@ void GamepadConfiguration::OnCheckboxChange(wxCommandEvent& event)
{ {
wxCheckBox* cb_tmp = (wxCheckBox*) event.GetEventObject(); // get the slider object wxCheckBox* cb_tmp = (wxCheckBox*) event.GetEventObject(); // get the slider object
int cb_id = cb_tmp->GetId(); int cb_id = cb_tmp->GetId();
if(cb_id == this->cb_rumble->GetId()) if(cb_id == m_cb_rumble->GetId())
{ {
conf->pad_options[this->pad_id].forcefeedback = (this->cb_rumble->GetValue())?(u32)1:(u32)0; conf->pad_options[m_pad_id].forcefeedback = (m_cb_rumble->GetValue())?(u32)1:(u32)0;
if(this->cb_rumble->GetValue()) if(m_cb_rumble->GetValue())
{ {
s_vgamePad[this->pad_id]->TestForce(); s_vgamePad[m_pad_id]->TestForce();
this->sl_rumble_intensity->Enable(); m_sl_rumble_intensity->Enable();
} }
else else
{ {
this->sl_rumble_intensity->Disable(); m_sl_rumble_intensity->Disable();
} }
} }
else if(cb_id == this->cb_hack_sixaxis_usb->GetId()) else if(cb_id == m_cb_hack_sixaxis_usb->GetId())
{ {
conf->pad_options[this->pad_id].sixaxis_usb = (this->cb_hack_sixaxis_usb->GetValue())?(u32)1:(u32)0; conf->pad_options[m_pad_id].sixaxis_usb = (m_cb_hack_sixaxis_usb->GetValue())?(u32)1:(u32)0;
} }
else if(cb_id == this->cb_hack_sixaxis_pressure->GetId()) else if(cb_id == m_cb_hack_sixaxis_pressure->GetId())
{ {
conf->pad_options[this->pad_id].sixaxis_pressure = (this->cb_hack_sixaxis_pressure->GetValue())?(u32)1:(u32)0; conf->pad_options[m_pad_id].sixaxis_pressure = (m_cb_hack_sixaxis_pressure->GetValue())?(u32)1:(u32)0;
} }
} }
@ -266,31 +274,35 @@ void GamepadConfiguration::OnCheckboxChange(wxCommandEvent& event)
// Reset checkbox and slider values // Reset checkbox and slider values
void GamepadConfiguration::reset() void GamepadConfiguration::reset()
{ {
this->cb_rumble->SetValue(this->init_rumble); m_cb_rumble->SetValue(m_init_rumble);
this->cb_hack_sixaxis_usb->SetValue(this->init_hack_sixaxis); m_cb_hack_sixaxis_usb->SetValue(m_init_hack_sixaxis);
this->sl_rumble_intensity->SetValue(this->init_rumble_intensity); m_cb_hack_sixaxis_pressure->SetValue(m_init_hack_sixaxis_pressure);
this->sl_joystick_sensibility->SetValue(this->init_joystick_sensibility); m_sl_rumble_intensity->SetValue(m_init_rumble_intensity);
m_sl_joystick_sensibility->SetValue(m_init_joystick_sensibility);
} }
// Set button values // Set button values
void GamepadConfiguration::repopulate() void GamepadConfiguration::repopulate()
{ {
bool val = conf->pad_options[this->pad_id].forcefeedback; bool val = conf->pad_options[m_pad_id].forcefeedback;
this->init_rumble = val; m_init_rumble = val;
this->cb_rumble->SetValue(val); m_cb_rumble->SetValue(val);
val = conf->pad_options[this->pad_id].sixaxis_usb; val = conf->pad_options[m_pad_id].sixaxis_usb;
this->init_hack_sixaxis = val; m_init_hack_sixaxis = val;
this->cb_hack_sixaxis_usb->SetValue(val); m_cb_hack_sixaxis_usb->SetValue(val);
val = conf->pad_options[m_pad_id].sixaxis_pressure;
m_init_hack_sixaxis_pressure = val;
m_cb_hack_sixaxis_pressure->SetValue(val);
int tmp = conf->get_ff_intensity(); int tmp = conf->get_ff_intensity();
this->sl_rumble_intensity->SetValue(tmp); m_sl_rumble_intensity->SetValue(tmp);
this->init_rumble_intensity = tmp; m_init_rumble_intensity = tmp;
tmp = conf->get_sensibility(); tmp = conf->get_sensibility();
this->sl_joystick_sensibility->SetValue(tmp); m_sl_joystick_sensibility->SetValue(tmp);
this->init_joystick_sensibility = tmp; m_init_joystick_sensibility = tmp;
// enable rumble intensity slider if the checkbox is checked // enable rumble intensity slider if the checkbox is checked
if(this->cb_rumble->GetValue()) if(m_cb_rumble->GetValue())
this->sl_rumble_intensity->Enable(); m_sl_rumble_intensity->Enable();
else // disable otherwise else // disable otherwise
this->sl_rumble_intensity->Disable(); m_sl_rumble_intensity->Disable();
} }

View File

@ -34,15 +34,15 @@
class GamepadConfiguration : public wxFrame class GamepadConfiguration : public wxFrame
{ {
wxPanel* pan_gamepad_config; wxPanel* m_pan_gamepad_config;
wxCheckBox *cb_rumble, *cb_hack_sixaxis_usb, *cb_hack_sixaxis_pressure; wxCheckBox *m_cb_rumble, *m_cb_hack_sixaxis_usb, *m_cb_hack_sixaxis_pressure;
wxSlider *sl_rumble_intensity, *sl_joystick_sensibility; wxSlider *m_sl_rumble_intensity, *m_sl_joystick_sensibility;
wxButton *bt_ok, *bt_cancel; wxButton *m_bt_ok, *m_bt_cancel;
wxStaticText *lbl_rumble_intensity, *lbl_joystick_sensibility; wxStaticText *m_lbl_rumble_intensity, *m_lbl_joystick_sensibility;
int pad_id; int m_pad_id;
u32 init_rumble_intensity, init_joystick_sensibility; u32 m_init_rumble_intensity, m_init_joystick_sensibility;
bool init_rumble, init_hack_sixaxis; bool m_init_rumble, m_init_hack_sixaxis, m_init_hack_sixaxis_pressure;
// methods // methods
void repopulate(); void repopulate();

View File

@ -34,33 +34,33 @@ JoystickConfiguration::JoystickConfiguration(int pad, bool left, wxWindow *paren
) )
{ {
this->pad_id = pad; m_pad_id = pad;
this->isForLeftJoystick = left; m_isForLeftJoystick = left;
this->pan_joystick_config = new wxPanel( m_pan_joystick_config = new wxPanel(
this, // Parent this, // Parent
wxID_ANY, // ID wxID_ANY, // ID
wxDefaultPosition, // Prosition wxDefaultPosition, // Prosition
wxSize(300, 200) // Size wxSize(300, 200) // Size
); );
if(this->isForLeftJoystick) if(m_isForLeftJoystick)
{ {
this->cb_reverse_Lx = new wxCheckBox( m_cb_reverse_Lx = new wxCheckBox(
this->pan_joystick_config, // Parent m_pan_joystick_config, // Parent
wxID_ANY, // ID wxID_ANY, // ID
_T("Reverse Lx"), // Label _T("Reverse Lx"), // Label
wxPoint(20, 20) // Position wxPoint(20, 20) // Position
); );
this->cb_reverse_Ly = new wxCheckBox( m_cb_reverse_Ly = new wxCheckBox(
this->pan_joystick_config, // Parent m_pan_joystick_config, // Parent
wxID_ANY, // ID wxID_ANY, // ID
_T("Reverse Ly"), // Label _T("Reverse Ly"), // Label
wxPoint(20, 40) // Position wxPoint(20, 40) // Position
); );
this->cb_mouse_Ljoy = new wxCheckBox( m_cb_mouse_Ljoy = new wxCheckBox(
this->pan_joystick_config, // Parent m_pan_joystick_config, // Parent
wxID_ANY, // ID wxID_ANY, // ID
_T("Use mouse for left analog joystick"), // Label _T("Use mouse for left analog joystick"), // Label
wxPoint(20, 60) // Position wxPoint(20, 60) // Position
@ -68,38 +68,38 @@ JoystickConfiguration::JoystickConfiguration(int pad, bool left, wxWindow *paren
} }
else else
{ {
this->cb_reverse_Rx = new wxCheckBox( m_cb_reverse_Rx = new wxCheckBox(
this->pan_joystick_config, // Parent m_pan_joystick_config, // Parent
wxID_ANY, // ID wxID_ANY, // ID
_T("Reverse Rx"), // Label _T("Reverse Rx"), // Label
wxPoint(20, 20) // Position wxPoint(20, 20) // Position
); );
this->cb_reverse_Ry = new wxCheckBox( m_cb_reverse_Ry = new wxCheckBox(
this->pan_joystick_config, // Parent m_pan_joystick_config, // Parent
wxID_ANY, // ID wxID_ANY, // ID
_T("Reverse Ry"), // Label _T("Reverse Ry"), // Label
wxPoint(20, 40) // Position wxPoint(20, 40) // Position
); );
this->cb_mouse_Rjoy = new wxCheckBox( m_cb_mouse_Rjoy = new wxCheckBox(
this->pan_joystick_config, // Parent m_pan_joystick_config, // Parent
wxID_ANY, // ID wxID_ANY, // ID
_T("Use mouse for right analog joystick"), // Label _T("Use mouse for right analog joystick"), // Label
wxPoint(20, 60) // Position wxPoint(20, 60) // Position
); );
} }
this->bt_ok = new wxButton( m_bt_ok = new wxButton(
this->pan_joystick_config, // Parent m_pan_joystick_config, // Parent
wxID_ANY, // ID wxID_ANY, // ID
_T("&OK"), // Label _T("&OK"), // Label
wxPoint(250, 130), // Position wxPoint(250, 130), // Position
wxSize(60,25) // Size wxSize(60,25) // Size
); );
this->bt_cancel = new wxButton( m_bt_cancel = new wxButton(
this->pan_joystick_config, // Parent m_pan_joystick_config, // Parent
wxID_ANY, // ID wxID_ANY, // ID
_T("&Cancel"), // Label _T("&Cancel"), // Label
wxPoint(320, 130), // Position wxPoint(320, 130), // Position
@ -107,16 +107,23 @@ JoystickConfiguration::JoystickConfiguration(int pad, bool left, wxWindow *paren
); );
// Connect the buttons to the OnButtonClicked Event // Connect the buttons to the OnButtonClicked Event
this->Connect( Connect(
wxEVT_COMMAND_BUTTON_CLICKED, wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(JoystickConfiguration::OnButtonClicked) wxCommandEventHandler(JoystickConfiguration::OnButtonClicked)
); );
// Connect the checkboxes to the OnCheckboxClicked Event // Connect the checkboxes to the OnCheckboxClicked Event
this->Connect( #if wxMAJOR_VERSION >= 3
Connect(
wxEVT_CHECKBOX, wxEVT_CHECKBOX,
wxCommandEventHandler(JoystickConfiguration::OnCheckboxChange) wxCommandEventHandler(JoystickConfiguration::OnCheckboxChange)
); );
#else
Connect(
wxEVT_COMMAND_CHECKBOX_CLICKED,
wxCommandEventHandler(JoystickConfiguration::OnCheckboxChange)
);
#endif
} }
/** /**
@ -125,26 +132,26 @@ JoystickConfiguration::JoystickConfiguration(int pad, bool left, wxWindow *paren
*/ */
void JoystickConfiguration::InitJoystickConfiguration() void JoystickConfiguration::InitJoystickConfiguration()
{ {
this->repopulate(); // Set label and fit simulated key array repopulate(); // Set label and fit simulated key array
/* /*
* Check if there exist at least one pad available * Check if there exist at least one pad available
* if the pad id is 0, you need at least 1 gamepad connected, * if the pad id is 0, you need at least 1 gamepad connected,
* if the pad id is 1, you need at least 2 gamepad connected, * if the pad id is 1, you need at least 2 gamepad connected,
* Prevent to use a none initialized value on s_vgamePad (core dump) * Prevent to use a none initialized value on s_vgamePad (core dump)
*/ */
if(s_vgamePad.size() < this->pad_id+1) if(s_vgamePad.size() < m_pad_id+1)
{ {
wxMessageBox("No gamepad detected."); wxMessageBox(L"No gamepad detected.");
// disable all checkbox // disable all checkbox
if(this->isForLeftJoystick) if(m_isForLeftJoystick)
{ {
this->cb_reverse_Lx->Disable(); m_cb_reverse_Lx->Disable();
this->cb_reverse_Ly->Disable(); m_cb_reverse_Ly->Disable();
} }
else else
{ {
this->cb_reverse_Rx->Disable(); m_cb_reverse_Rx->Disable();
this->cb_reverse_Ry->Disable(); m_cb_reverse_Ry->Disable();
} }
} }
} }
@ -161,14 +168,14 @@ void JoystickConfiguration::OnButtonClicked(wxCommandEvent &event)
// Affichage d'un message à chaque clic sur le bouton // Affichage d'un message à chaque clic sur le bouton
wxButton* bt_tmp = (wxButton*)event.GetEventObject(); // get the button object wxButton* bt_tmp = (wxButton*)event.GetEventObject(); // get the button object
int bt_id = bt_tmp->GetId(); // get the real ID int bt_id = bt_tmp->GetId(); // get the real ID
if(bt_id == this->bt_ok->GetId()) // If the button ID is equals to the Ok button ID if(bt_id == m_bt_ok->GetId()) // If the button ID is equals to the Ok button ID
{ {
this->Close(); // Close the window Close(); // Close the window
} }
else if(bt_id == this->bt_cancel->GetId()) // If the button ID is equals to the cancel button ID else if(bt_id == m_bt_cancel->GetId()) // If the button ID is equals to the cancel button ID
{ {
this->reset(); // reinitialize the value of each parameters reset(); // reinitialize the value of each parameters
this->Close(); // Close the window Close(); // Close the window
} }
} }
@ -180,40 +187,40 @@ void JoystickConfiguration::OnCheckboxChange(wxCommandEvent& event)
wxCheckBox* cb_tmp = (wxCheckBox*) event.GetEventObject(); // get the slider object wxCheckBox* cb_tmp = (wxCheckBox*) event.GetEventObject(); // get the slider object
int cb_id = cb_tmp->GetId(); int cb_id = cb_tmp->GetId();
bool val; bool val;
if(this->isForLeftJoystick) if(m_isForLeftJoystick)
{ {
if(cb_id == this->cb_reverse_Ly->GetId()) if(cb_id == m_cb_reverse_Ly->GetId())
{ {
val = this->cb_reverse_Ly->GetValue(); val = m_cb_reverse_Ly->GetValue();
conf->pad_options[this->pad_id].reverse_ly = val; conf->pad_options[m_pad_id].reverse_ly = val;
} }
else if(cb_id == this->cb_reverse_Lx->GetId()) else if(cb_id == m_cb_reverse_Lx->GetId())
{ {
val = this->cb_reverse_Lx->GetValue(); val = m_cb_reverse_Lx->GetValue();
conf->pad_options[this->pad_id].reverse_lx = val; conf->pad_options[m_pad_id].reverse_lx = val;
} }
else if(cb_id == this->cb_mouse_Ljoy->GetId()) else if(cb_id == m_cb_mouse_Ljoy->GetId())
{ {
val = this->cb_mouse_Ljoy->GetValue(); val = m_cb_mouse_Ljoy->GetValue();
conf->pad_options[this->pad_id].mouse_l = val; conf->pad_options[m_pad_id].mouse_l = val;
} }
} }
else else
{ {
if(cb_id == this->cb_reverse_Ry->GetId()) if(cb_id == m_cb_reverse_Ry->GetId())
{ {
val = this->cb_reverse_Ry->GetValue(); val = m_cb_reverse_Ry->GetValue();
conf->pad_options[this->pad_id].reverse_ry = val; conf->pad_options[m_pad_id].reverse_ry = val;
} }
else if(cb_id == this->cb_reverse_Rx->GetId()) else if(cb_id == m_cb_reverse_Rx->GetId())
{ {
val = this->cb_reverse_Rx->GetValue(); val = m_cb_reverse_Rx->GetValue();
conf->pad_options[this->pad_id].reverse_rx = val; conf->pad_options[m_pad_id].reverse_rx = val;
} }
else if(cb_id == this->cb_mouse_Rjoy->GetId()) else if(cb_id == m_cb_mouse_Rjoy->GetId())
{ {
val = this->cb_mouse_Rjoy->GetValue(); val = m_cb_mouse_Rjoy->GetValue();
conf->pad_options[this->pad_id].mouse_r = val; conf->pad_options[m_pad_id].mouse_r = val;
} }
} }
} }
@ -225,17 +232,17 @@ void JoystickConfiguration::OnCheckboxChange(wxCommandEvent& event)
// Reset checkbox and slider values // Reset checkbox and slider values
void JoystickConfiguration::reset() void JoystickConfiguration::reset()
{ {
if(this->isForLeftJoystick) if(m_isForLeftJoystick)
{ {
this->cb_reverse_Lx->SetValue(this->init_reverse_Lx); m_cb_reverse_Lx->SetValue(m_init_reverse_Lx);
this->cb_reverse_Ly->SetValue(this->init_reverse_Ly); m_cb_reverse_Ly->SetValue(m_init_reverse_Ly);
this->cb_mouse_Ljoy->SetValue(this->init_mouse_Ljoy); m_cb_mouse_Ljoy->SetValue(m_init_mouse_Ljoy);
} }
else else
{ {
this->cb_reverse_Rx->SetValue(this->init_reverse_Rx); m_cb_reverse_Rx->SetValue(m_init_reverse_Rx);
this->cb_reverse_Ry->SetValue(this->init_reverse_Ry); m_cb_reverse_Ry->SetValue(m_init_reverse_Ry);
this->cb_mouse_Rjoy->SetValue(this->init_mouse_Rjoy); m_cb_mouse_Rjoy->SetValue(m_init_mouse_Rjoy);
} }
} }
@ -243,32 +250,32 @@ void JoystickConfiguration::reset()
void JoystickConfiguration::repopulate() void JoystickConfiguration::repopulate()
{ {
bool val; bool val;
if(this->isForLeftJoystick) if(m_isForLeftJoystick)
{ {
val = conf->pad_options[this->pad_id].reverse_lx; val = conf->pad_options[m_pad_id].reverse_lx;
this->init_reverse_Lx = val; m_init_reverse_Lx = val;
this->cb_reverse_Lx->SetValue(val); m_cb_reverse_Lx->SetValue(val);
val = conf->pad_options[this->pad_id].reverse_ly; val = conf->pad_options[m_pad_id].reverse_ly;
this->init_reverse_Ly = val; m_init_reverse_Ly = val;
this->cb_reverse_Ly->SetValue(val); m_cb_reverse_Ly->SetValue(val);
val = conf->pad_options[this->pad_id].mouse_l; val = conf->pad_options[m_pad_id].mouse_l;
this->init_mouse_Ljoy = val; m_init_mouse_Ljoy = val;
this->cb_mouse_Ljoy->SetValue(val); m_cb_mouse_Ljoy->SetValue(val);
} }
else else
{ {
val = conf->pad_options[this->pad_id].reverse_rx; val = conf->pad_options[m_pad_id].reverse_rx;
this->init_reverse_Rx = val; m_init_reverse_Rx = val;
this->cb_reverse_Rx->SetValue(val); m_cb_reverse_Rx->SetValue(val);
val = conf->pad_options[this->pad_id].reverse_ry; val = conf->pad_options[m_pad_id].reverse_ry;
this->init_reverse_Ry = val; m_init_reverse_Ry = val;
this->cb_reverse_Ry->SetValue(val); m_cb_reverse_Ry->SetValue(val);
val = conf->pad_options[this->pad_id].mouse_r; val = conf->pad_options[m_pad_id].mouse_r;
this->init_mouse_Rjoy = val; m_init_mouse_Rjoy = val;
this->cb_mouse_Rjoy->SetValue(val); m_cb_mouse_Rjoy->SetValue(val);
} }
} }

View File

@ -34,16 +34,16 @@
class JoystickConfiguration : public wxFrame class JoystickConfiguration : public wxFrame
{ {
wxPanel* pan_joystick_config; wxPanel* m_pan_joystick_config;
wxCheckBox *cb_reverse_Lx, *cb_reverse_Ly, *cb_reverse_Rx, *cb_reverse_Ry, wxCheckBox *m_cb_reverse_Lx, *m_cb_reverse_Ly, *m_cb_reverse_Rx, *m_cb_reverse_Ry,
*cb_mouse_Ljoy, // Use mouse for left joystick *m_cb_mouse_Ljoy, // Use mouse for left joystick
*cb_mouse_Rjoy; // Use mouse for right joystick *m_cb_mouse_Rjoy; // Use mouse for right joystick
wxButton *bt_ok, *bt_cancel; wxButton *m_bt_ok, *m_bt_cancel;
int pad_id; int 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 init_reverse_Lx, init_reverse_Ly, init_reverse_Rx, init_reverse_Ry, bool m_init_reverse_Lx, m_init_reverse_Ly, m_init_reverse_Rx, m_init_reverse_Ry,
init_mouse_Ljoy, init_mouse_Rjoy, isForLeftJoystick; m_init_mouse_Ljoy, m_init_mouse_Rjoy, m_isForLeftJoystick;
// methods // methods
void repopulate(); void repopulate();

View File

@ -24,7 +24,7 @@ Dialog::Dialog() : wxFrame( NULL, // Parent
wxID_ANY, // ID wxID_ANY, // ID
_T("OnePad configuration"), // Title _T("OnePad configuration"), // Title
wxDefaultPosition, // Position wxDefaultPosition, // Position
wxSize(1000, 760), // Width + Lenght wxSize(DEFAULT_WIDTH, DEFAULT_HEIGHT), // Width + Lenght
// Style // Style
wxSYSTEM_MENU | wxSYSTEM_MENU |
wxCAPTION | wxCAPTION |
@ -235,15 +235,15 @@ Dialog::Dialog() : wxFrame( NULL, // Parent
padding[Cancel][3] = 642; // Y padding[Cancel][3] = 642; // Y
// create a new Notebook // create a new Notebook
this->tab_gamepad = new wxNotebook(this, wxID_ANY); m_tab_gamepad = new wxNotebook(this, wxID_ANY);
for(int i=0; i<GAMEPAD_NUMBER; ++i) for(int i=0; i<GAMEPAD_NUMBER; ++i)
{ {
// Tabs panels // Tabs panels
this->pan_tabs[i] = new opPanel( m_pan_tabs[i] = new opPanel(
this->tab_gamepad, m_tab_gamepad,
wxID_ANY, wxID_ANY,
wxDefaultPosition, wxDefaultPosition,
wxSize(1000, 760) wxSize(DEFAULT_WIDTH, DEFAULT_HEIGHT)
); );
// Add new page // Add new page
// Define label // Define label
@ -251,16 +251,16 @@ Dialog::Dialog() : wxFrame( NULL, // Parent
std::string label = "Gamepad "; std::string label = "Gamepad ";
sstm << label << i; sstm << label << i;
// New page creation // New page creation
this->tab_gamepad->AddPage( m_tab_gamepad->AddPage(
this->pan_tabs[i], // Parent m_pan_tabs[i], // Parent
sstm.str() // Title wxString(sstm.str().c_str(), wxConvUTF8) // Title
); );
for(int j=0; j<BUTTONS_LENGHT; ++j) for(int j=0; j<BUTTONS_LENGHT; ++j)
{ {
// Gamepad buttons // Gamepad buttons
this->bt_gamepad[i][j] = new wxButton( m_bt_gamepad[i][j] = new wxButton(
this->pan_tabs[i], // Parent m_pan_tabs[i], // Parent
wxID_HIGHEST+j+1, // ID wxID_HIGHEST+j+1, // ID
_T("Undefined"), // Label _T("Undefined"), // Label
wxPoint(padding[j][2], padding[j][3]), // Position wxPoint(padding[j][2], padding[j][3]), // Position
@ -268,36 +268,36 @@ Dialog::Dialog() : wxFrame( NULL, // Parent
); );
} }
// Redefine others gui buttons label // Redefine others gui buttons label
this->bt_gamepad[i][JoyL_config]->SetLabel(_T("&Left Joystick Config")); m_bt_gamepad[i][JoyL_config]->SetLabel(_T("&Left Joystick Config"));
this->bt_gamepad[i][JoyR_config]->SetLabel(_T("&Right Joystick Config")); m_bt_gamepad[i][JoyR_config]->SetLabel(_T("&Right Joystick Config"));
this->bt_gamepad[i][Gamepad_config]->SetLabel(_T("&Gamepad Configuration")); m_bt_gamepad[i][Gamepad_config]->SetLabel(_T("&Gamepad Configuration"));
this->bt_gamepad[i][Set_all]->SetLabel(_T("&Set All Buttons")); m_bt_gamepad[i][Set_all]->SetLabel(_T("&Set All Buttons"));
this->bt_gamepad[i][Cancel]->SetLabel(_T("&Cancel")); m_bt_gamepad[i][Cancel]->SetLabel(_T("&Cancel"));
this->bt_gamepad[i][Apply]->SetLabel(_T("&Apply")); m_bt_gamepad[i][Apply]->SetLabel(_T("&Apply"));
this->bt_gamepad[i][Ok]->SetLabel(_T("&Ok")); m_bt_gamepad[i][Ok]->SetLabel(_T("&Ok"));
// Disable analog button (not yet supported) // Disable analog button (not yet supported)
this->bt_gamepad[i][Analog]->Disable(); m_bt_gamepad[i][Analog]->Disable();
} }
// Connect the buttons to the OnButtonClicked Event // Connect the buttons to the OnButtonClicked Event
this->Connect( Connect(
wxEVT_COMMAND_BUTTON_CLICKED, wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(Dialog::OnButtonClicked) wxCommandEventHandler(Dialog::OnButtonClicked)
); );
time_update_gui.SetOwner(this); m_time_update_gui.SetOwner(this);
this->Connect( Connect(
wxEVT_TIMER, wxEVT_TIMER,
wxCommandEventHandler(Dialog::JoystickEvent) wxCommandEventHandler(Dialog::JoystickEvent)
); );
time_update_gui.Start(UPDATE_TIME, wxTIMER_CONTINUOUS); m_time_update_gui.Start(UPDATE_TIME, wxTIMER_CONTINUOUS);
for(int i=0; i<GAMEPAD_NUMBER; ++i) for(int i=0; i<GAMEPAD_NUMBER; ++i)
{ {
for(int j=0; j<NB_IMG; ++j) for(int j=0; j<NB_IMG; ++j)
{ {
this->pressed[i][j] = false; m_pressed[i][j] = false;
} }
} }
} }
@ -306,7 +306,7 @@ void Dialog::InitDialog()
{ {
GamePad::EnumerateGamePads(s_vgamePad); // activate gamepads GamePad::EnumerateGamePads(s_vgamePad); // activate gamepads
LoadConfig(); // Load configuration from the ini file LoadConfig(); // Load configuration from the ini file
this->repopulate(); // Set label and fit simulated key array repopulate(); // Set label and fit simulated key array
} }
/****************************************/ /****************************************/
@ -318,101 +318,101 @@ void Dialog::OnButtonClicked(wxCommandEvent &event)
// Affichage d'un message à chaque clic sur le bouton // Affichage d'un message à chaque clic sur le bouton
wxButton* bt_tmp = (wxButton*)event.GetEventObject(); // get the button object wxButton* bt_tmp = (wxButton*)event.GetEventObject(); // get the button object
int bt_id = bt_tmp->GetId()-wxID_HIGHEST-1; // get the real ID int bt_id = bt_tmp->GetId()-wxID_HIGHEST-1; // get the real ID
int gamepad_id = this->tab_gamepad->GetSelection(); // get the tab ID (equivalent to the gamepad id) int gamepad_id = m_tab_gamepad->GetSelection(); // get the tab ID (equivalent to the gamepad id)
if(bt_id >= 0 && bt_id <= PAD_R_LEFT) // if the button ID is a gamepad button if(bt_id >= 0 && bt_id <= PAD_R_LEFT) // if the button ID is a gamepad button
{ {
bt_tmp->Disable(); // switch the button state to "Disable" bt_tmp->Disable(); // switch the button state to "Disable"
this->config_key(gamepad_id, bt_id); config_key(gamepad_id, bt_id);
bt_tmp->Enable(); // switch the button state to "Enable" bt_tmp->Enable(); // switch the button state to "Enable"
} }
else if(bt_id == Gamepad_config) // If the button ID is equals to the Gamepad_config button ID else if(bt_id == Gamepad_config) // If the button ID is equals to the Gamepad_config button ID
{ {
this->frm_gamepad_config = new GamepadConfiguration(gamepad_id, this); m_frm_gamepad_config = new GamepadConfiguration(gamepad_id, this);
this->frm_gamepad_config->InitGamepadConfiguration(); m_frm_gamepad_config->InitGamepadConfiguration();
this->frm_gamepad_config->Show(true); m_frm_gamepad_config->Show(true);
} }
else if(bt_id == JoyL_config) // If the button ID is equals to the JoyL_config button ID else if(bt_id == JoyL_config) // If the button ID is equals to the JoyL_config button ID
{ {
this->frm_joystick_config = new JoystickConfiguration(gamepad_id, true, this); m_frm_joystick_config = new JoystickConfiguration(gamepad_id, true, this);
this->frm_joystick_config->InitJoystickConfiguration(); m_frm_joystick_config->InitJoystickConfiguration();
this->frm_joystick_config->Show(true); m_frm_joystick_config->Show(true);
} }
else if(bt_id == JoyR_config) // If the button ID is equals to the JoyR_config button ID else if(bt_id == JoyR_config) // If the button ID is equals to the JoyR_config button ID
{ {
this->frm_joystick_config = new JoystickConfiguration(gamepad_id, false, this); m_frm_joystick_config = new JoystickConfiguration(gamepad_id, false, this);
this->frm_joystick_config->InitJoystickConfiguration(); m_frm_joystick_config->InitJoystickConfiguration();
this->frm_joystick_config->Show(true); m_frm_joystick_config->Show(true);
} }
else if(bt_id == Set_all) // If the button ID is equals to the Set_all button ID else if(bt_id == Set_all) // If the button ID is equals to the Set_all button ID
{ {
for(int i=0; i<MAX_KEYS; ++i) for(int i=0; i<MAX_KEYS; ++i)
{ {
bt_tmp = this->bt_gamepad[gamepad_id][i]; bt_tmp = m_bt_gamepad[gamepad_id][i];
switch(i) switch(i)
{ {
case PAD_L_UP: // Left joystick (Up) ↑ case PAD_L_UP: // Left joystick (Up) ↑
this->pan_tabs[gamepad_id]->ShowImg(img_l_arrow_up); m_pan_tabs[gamepad_id]->ShowImg(img_l_arrow_up);
break; break;
case PAD_L_RIGHT: // Left joystick (Right) → case PAD_L_RIGHT: // Left joystick (Right) →
this->pan_tabs[gamepad_id]->ShowImg(img_l_arrow_right); m_pan_tabs[gamepad_id]->ShowImg(img_l_arrow_right);
break; break;
case PAD_L_DOWN: // Left joystick (Down) ↓ case PAD_L_DOWN: // Left joystick (Down) ↓
this->pan_tabs[gamepad_id]->ShowImg(img_l_arrow_bottom); m_pan_tabs[gamepad_id]->ShowImg(img_l_arrow_bottom);
break; break;
case PAD_L_LEFT: // Left joystick (Left) ← case PAD_L_LEFT: // Left joystick (Left) ←
this->pan_tabs[gamepad_id]->ShowImg(img_l_arrow_left); m_pan_tabs[gamepad_id]->ShowImg(img_l_arrow_left);
break; break;
case PAD_R_UP: // Right joystick (Up) ↑ case PAD_R_UP: // Right joystick (Up) ↑
this->pan_tabs[gamepad_id]->ShowImg(img_r_arrow_up); m_pan_tabs[gamepad_id]->ShowImg(img_r_arrow_up);
break; break;
case PAD_R_RIGHT: // Right joystick (Right) → case PAD_R_RIGHT: // Right joystick (Right) →
this->pan_tabs[gamepad_id]->ShowImg(img_r_arrow_right); m_pan_tabs[gamepad_id]->ShowImg(img_r_arrow_right);
break; break;
case PAD_R_DOWN: // Right joystick (Down) ↓ case PAD_R_DOWN: // Right joystick (Down) ↓
this->pan_tabs[gamepad_id]->ShowImg(img_r_arrow_bottom); m_pan_tabs[gamepad_id]->ShowImg(img_r_arrow_bottom);
break; break;
case PAD_R_LEFT: // Right joystick (Left) ← case PAD_R_LEFT: // Right joystick (Left) ←
this->pan_tabs[gamepad_id]->ShowImg(img_r_arrow_left); m_pan_tabs[gamepad_id]->ShowImg(img_r_arrow_left);
break; break;
default: default:
this->pan_tabs[gamepad_id]->ShowImg(i); m_pan_tabs[gamepad_id]->ShowImg(i);
break; break;
} }
this->pan_tabs[gamepad_id]->Refresh(); m_pan_tabs[gamepad_id]->Refresh();
this->pan_tabs[gamepad_id]->Update(); m_pan_tabs[gamepad_id]->Update();
this->config_key(gamepad_id, i); config_key(gamepad_id, i);
switch(i) switch(i)
{ {
case PAD_L_UP: // Left joystick (Up) ↑ case PAD_L_UP: // Left joystick (Up) ↑
this->pan_tabs[gamepad_id]->HideImg(img_l_arrow_up); m_pan_tabs[gamepad_id]->HideImg(img_l_arrow_up);
break; break;
case PAD_L_RIGHT: // Left joystick (Right) → case PAD_L_RIGHT: // Left joystick (Right) →
this->pan_tabs[gamepad_id]->HideImg(img_l_arrow_right); m_pan_tabs[gamepad_id]->HideImg(img_l_arrow_right);
break; break;
case PAD_L_DOWN: // Left joystick (Down) ↓ case PAD_L_DOWN: // Left joystick (Down) ↓
this->pan_tabs[gamepad_id]->HideImg(img_l_arrow_bottom); m_pan_tabs[gamepad_id]->HideImg(img_l_arrow_bottom);
break; break;
case PAD_L_LEFT: // Left joystick (Left) ← case PAD_L_LEFT: // Left joystick (Left) ←
this->pan_tabs[gamepad_id]->HideImg(img_l_arrow_left); m_pan_tabs[gamepad_id]->HideImg(img_l_arrow_left);
break; break;
case PAD_R_UP: // Right joystick (Up) ↑ case PAD_R_UP: // Right joystick (Up) ↑
this->pan_tabs[gamepad_id]->HideImg(img_r_arrow_up); m_pan_tabs[gamepad_id]->HideImg(img_r_arrow_up);
break; break;
case PAD_R_RIGHT: // Right joystick (Right) → case PAD_R_RIGHT: // Right joystick (Right) →
this->pan_tabs[gamepad_id]->HideImg(img_r_arrow_right); m_pan_tabs[gamepad_id]->HideImg(img_r_arrow_right);
break; break;
case PAD_R_DOWN: // Right joystick (Down) ↓ case PAD_R_DOWN: // Right joystick (Down) ↓
this->pan_tabs[gamepad_id]->HideImg(img_r_arrow_bottom); m_pan_tabs[gamepad_id]->HideImg(img_r_arrow_bottom);
break; break;
case PAD_R_LEFT: // Right joystick (Left) ← case PAD_R_LEFT: // Right joystick (Left) ←
this->pan_tabs[gamepad_id]->HideImg(img_r_arrow_left); m_pan_tabs[gamepad_id]->HideImg(img_r_arrow_left);
break; break;
default: default:
this->pan_tabs[gamepad_id]->HideImg(i); m_pan_tabs[gamepad_id]->HideImg(i);
break; break;
} }
this->pan_tabs[gamepad_id]->Refresh(); m_pan_tabs[gamepad_id]->Refresh();
this->pan_tabs[gamepad_id]->Update(); m_pan_tabs[gamepad_id]->Update();
usleep(500000); // give enough time to the user to release the button usleep(500000); // give enough time to the user to release the button
} }
} }
@ -448,107 +448,122 @@ void Dialog::JoystickEvent(wxCommandEvent& event)
case SDL_KEYUP: case SDL_KEYUP:
break; break;
case SDL_JOYAXISMOTION: case SDL_JOYAXISMOTION:
key = axis_to_key(false, (events.jaxis.value<0), events.jaxis.axis); if(events.jaxis.which < GAMEPAD_NUMBER)
it=this->map_images[events.jaxis.which].find(key);
if(it != this->map_images[events.jaxis.which].end())
{ {
map = this->map_images[events.jaxis.which][key]; key = axis_to_key(false, (events.jaxis.value<0), events.jaxis.axis);
it=m_map_images[events.jaxis.which].find(key);
if(it != m_map_images[events.jaxis.which].end())
{
map = m_map_images[events.jaxis.which][key];
if(events.jaxis.value == 0) if(events.jaxis.value == 0)
{ {
if(map >= PAD_L_UP && map <= PAD_L_LEFT) if(map >= PAD_L_UP && map <= PAD_L_LEFT)
this->pan_tabs[events.jaxis.which]->HideImg(img_left_cursor); m_pan_tabs[events.jaxis.which]->HideImg(img_left_cursor);
else if(map >= PAD_R_UP && map <= PAD_R_LEFT) else if(map >= PAD_R_UP && map <= PAD_R_LEFT)
this->pan_tabs[events.jaxis.which]->HideImg(img_right_cursor); m_pan_tabs[events.jaxis.which]->HideImg(img_right_cursor);
else if(map < PAD_L_UP)
m_pan_tabs[events.jaxis.which]->HideImg(map);
} }
else else
{ {
if(map >= PAD_L_UP && map <= PAD_L_LEFT) if(map >= PAD_L_UP && map <= PAD_L_LEFT)
{ {
this->pan_tabs[events.jaxis.which]->MoveJoystick(events.jaxis.axis, events.jaxis.value); m_pan_tabs[events.jaxis.which]->MoveJoystick(events.jaxis.axis, events.jaxis.value);
this->pan_tabs[events.jaxis.which]->ShowImg(img_left_cursor); m_pan_tabs[events.jaxis.which]->ShowImg(img_left_cursor);
} }
else if(map >= PAD_R_UP && map <= PAD_R_LEFT) else if(map >= PAD_R_UP && map <= PAD_R_LEFT)
{ {
this->pan_tabs[events.jaxis.which]->MoveJoystick(events.jaxis.axis, events.jaxis.value); m_pan_tabs[events.jaxis.which]->MoveJoystick(events.jaxis.axis, events.jaxis.value);
this->pan_tabs[events.jaxis.which]->ShowImg(img_right_cursor); m_pan_tabs[events.jaxis.which]->ShowImg(img_right_cursor);
} }
else if(map < PAD_L_UP) // if this is not a joystick else if(map < PAD_L_UP) // if this is not a joystick
{ {
this->pan_tabs[events.jaxis.which]->ShowImg(map); m_pan_tabs[events.jaxis.which]->ShowImg(map);
} }
} }
break; break;
} }
// Hack Dualshock 4 (L2, R2) // Hack Dualshock 4 (L2, R2)
key = axis_to_key(false, (events.jaxis.value>0), events.jaxis.axis); key = axis_to_key(false, (events.jaxis.value>0), events.jaxis.axis);
it2=this->map_images[events.jaxis.which].find(key); it2=m_map_images[events.jaxis.which].find(key);
if(it2 != this->map_images[events.jaxis.which].end()) if(it2 != m_map_images[events.jaxis.which].end())
{ {
map = this->map_images[events.jaxis.which][key]; map = m_map_images[events.jaxis.which][key];
if(map < PAD_L_UP) // if this is not a joystick if(map < PAD_L_UP) // if this is not a joystick
{ {
this->pan_tabs[events.jaxis.which]->HideImg(map); m_pan_tabs[events.jaxis.which]->HideImg(map);
} }
break; break;
} }
}
break; break;
case SDL_JOYBUTTONDOWN: case SDL_JOYBUTTONDOWN:
key = button_to_key(events.jbutton.button); if(events.jbutton.which < GAMEPAD_NUMBER)
it=this->map_images[events.jaxis.which].find(key);
if(it != this->map_images[events.jaxis.which].end())
{ {
map = this->map_images[events.jaxis.which][key]; key = button_to_key(events.jbutton.button);
this->pan_tabs[events.jaxis.which]->ShowImg(map); it=m_map_images[events.jbutton.which].find(key);
if(it != m_map_images[events.jbutton.which].end())
{
map = m_map_images[events.jbutton.which][key];
m_pan_tabs[events.jbutton.which]->ShowImg(map);
}
} }
break; break;
case SDL_JOYBUTTONUP: case SDL_JOYBUTTONUP:
key = button_to_key(events.jbutton.button); if(events.jbutton.which < GAMEPAD_NUMBER)
it=this->map_images[events.jaxis.which].find(key);
if(it != this->map_images[events.jaxis.which].end())
{ {
map = this->map_images[events.jaxis.which][key]; key = button_to_key(events.jbutton.button);
this->pan_tabs[events.jaxis.which]->HideImg(map); it=m_map_images[events.jbutton.which].find(key);
if(it != m_map_images[events.jbutton.which].end())
{
map = m_map_images[events.jbutton.which][key];
m_pan_tabs[events.jbutton.which]->HideImg(map);
} }
}
break;
case SDL_JOYHATMOTION: case SDL_JOYHATMOTION:
if(events.jhat.which < GAMEPAD_NUMBER)
{
switch(events.jhat.value) switch(events.jhat.value)
{ {
case SDL_HAT_UP: case SDL_HAT_UP:
key = hat_to_key(events.jhat.value, events.jhat.hat); key = hat_to_key(events.jhat.value, events.jhat.hat);
it=this->map_images[events.jaxis.which].find(key); it=m_map_images[events.jhat.which].find(key);
if(it != this->map_images[events.jaxis.which].end()) if(it != m_map_images[events.jhat.which].end())
{ {
this->pan_tabs[events.jaxis.which]->ShowImg(img_dp_up); m_pan_tabs[events.jhat.which]->ShowImg(img_dp_up);
} }
break; break;
case SDL_HAT_DOWN: case SDL_HAT_DOWN:
key = hat_to_key(events.jhat.value, events.jhat.hat); key = hat_to_key(events.jhat.value, events.jhat.hat);
it=this->map_images[events.jaxis.which].find(key); it=m_map_images[events.jhat.which].find(key);
if(it != this->map_images[events.jaxis.which].end()) if(it != m_map_images[events.jhat.which].end())
{ {
this->pan_tabs[events.jaxis.which]->ShowImg(img_dp_bottom); m_pan_tabs[events.jhat.which]->ShowImg(img_dp_bottom);
} }
break; break;
case SDL_HAT_RIGHT: case SDL_HAT_RIGHT:
key = hat_to_key(events.jhat.value, events.jhat.hat); key = hat_to_key(events.jhat.value, events.jhat.hat);
it=this->map_images[events.jaxis.which].find(key); it=m_map_images[events.jhat.which].find(key);
if(it != this->map_images[events.jaxis.which].end()) if(it != m_map_images[events.jhat.which].end())
{ {
this->pan_tabs[events.jaxis.which]->ShowImg(img_dp_right); m_pan_tabs[events.jhat.which]->ShowImg(img_dp_right);
} }
break; break;
case SDL_HAT_LEFT: case SDL_HAT_LEFT:
key = hat_to_key(events.jhat.value, events.jhat.hat); key = hat_to_key(events.jhat.value, events.jhat.hat);
it=this->map_images[events.jaxis.which].find(key); it=m_map_images[events.jhat.which].find(key);
if(it != this->map_images[events.jaxis.which].end()) if(it != m_map_images[events.jhat.which].end())
{ {
this->pan_tabs[events.jaxis.which]->ShowImg(img_dp_left); m_pan_tabs[events.jhat.which]->ShowImg(img_dp_left);
} }
break; break;
case SDL_HAT_CENTERED: case SDL_HAT_CENTERED:
this->pan_tabs[events.jaxis.which]->HideImg(img_dp_up); m_pan_tabs[events.jhat.which]->HideImg(img_dp_up);
this->pan_tabs[events.jaxis.which]->HideImg(img_dp_bottom); m_pan_tabs[events.jhat.which]->HideImg(img_dp_bottom);
this->pan_tabs[events.jaxis.which]->HideImg(img_dp_right); m_pan_tabs[events.jhat.which]->HideImg(img_dp_right);
this->pan_tabs[events.jaxis.which]->HideImg(img_dp_left); m_pan_tabs[events.jhat.which]->HideImg(img_dp_left);
}
} }
break; break;
default: default:
@ -578,10 +593,10 @@ void Dialog::config_key(int pad, int key)
// Note: key_pressed == 0 when ESC is hit to abort the capture // Note: key_pressed == 0 when ESC is hit to abort the capture
if (key_pressed > 0) if (key_pressed > 0)
{ {
this->clear_key(pad, key); clear_key(pad, key);
set_keyboad_key(pad, key_pressed, key); set_keyboad_key(pad, key_pressed, key);
this->simulatedKeys[pad][key] = key_pressed; m_simulatedKeys[pad][key] = key_pressed;
this->map_images[pad][key_pressed] = key; m_map_images[pad][key_pressed] = key;
} }
captured = true; captured = true;
} }
@ -594,40 +609,45 @@ void Dialog::config_key(int pad, int key)
{ {
if ((*itjoy)->PollButtons(key_pressed)) if ((*itjoy)->PollButtons(key_pressed))
{ {
this->clear_key(pad, key); clear_key(pad, key);
set_key(pad, key, key_pressed); set_key(pad, key, key_pressed);
this->map_images[pad][key_pressed] = key; m_map_images[pad][key_pressed] = key;
captured = true; captured = true;
} }
else if((*itjoy)->PollAxes(key_pressed)) else if((*itjoy)->PollAxes(key_pressed))
{ {
clear_key(pad, key);
this->clear_key(pad, key);
set_key(pad, key, key_pressed); set_key(pad, key, key_pressed);
this->map_images[pad][key_pressed] = key; m_map_images[pad][key_pressed] = key;
captured = true; captured = true;
} }
else if((*itjoy)->PollHats(key_pressed)) else if((*itjoy)->PollHats(key_pressed))
{ {
this->clear_key(pad, key); clear_key(pad, key);
set_key(pad, key, key_pressed); set_key(pad, key, key_pressed);
this->map_images[pad][key_pressed] = key; m_map_images[pad][key_pressed] = key;
captured = true; captured = true;
} }
itjoy++; itjoy++;
} }
} }
} }
this->bt_gamepad[pad][key]->SetLabel( #if wxMAJOR_VERSION >= 3
KeyName(pad, key, this->simulatedKeys[pad][key]).c_str() m_bt_gamepad[pad][key]->SetLabel(
KeyName(pad, key, m_simulatedKeys[pad][key]).c_str()
); );
#else
m_bt_gamepad[pad][key]->SetLabel(
wxString(KeyName(pad, key, m_simulatedKeys[pad][key]).c_str(), wxConvUTF8)
);
#endif
} }
void Dialog::clear_key(int pad, int key) void Dialog::clear_key(int pad, int key)
{ {
// Erase the keyboard binded key // Erase the keyboard binded key
u32 keysim = this->simulatedKeys[pad][key]; u32 keysim = m_simulatedKeys[pad][key];
this->simulatedKeys[pad][key] = 0; m_simulatedKeys[pad][key] = 0;
// erase gamepad entry (keysim map) // erase gamepad entry (keysim map)
std::map<u32,u32>::iterator it1; std::map<u32,u32>::iterator it1;
@ -638,14 +658,14 @@ void Dialog::clear_key(int pad, int key)
// erase gamepad entry (image map) // erase gamepad entry (image map)
int val = get_key(pad, key); int val = get_key(pad, key);
std::map<u32,int>::iterator it2; std::map<u32,int>::iterator it2;
it2=this->map_images[pad].find(val); it2=m_map_images[pad].find(val);
if(it2 != this->map_images[pad].end()) if(it2 != m_map_images[pad].end())
{ {
this->map_images[pad].erase(it2); m_map_images[pad].erase(it2);
} }
// Erase the keyboard image map // Erase the keyboard image map
//this->map_images[pad].erase(keysim); //m_map_images[pad].erase(keysim);
// Erase the Gamepad binded key // Erase the Gamepad binded key
set_key(pad, key, 0); set_key(pad, key, 0);
} }
@ -660,10 +680,17 @@ void Dialog::repopulate()
{ {
if (get_key(gamepad_id, key) != 0) if (get_key(gamepad_id, key) != 0)
{ {
this->bt_gamepad[gamepad_id][key]->SetLabel( #if wxMAJOR_VERSION >= 3
m_bt_gamepad[gamepad_id][key]->SetLabel(
KeyName(gamepad_id, key).c_str() KeyName(gamepad_id, key).c_str()
); );
this->map_images[gamepad_id][get_key(gamepad_id, key)] = key; #else
m_bt_gamepad[gamepad_id][key]->SetLabel(
wxString(KeyName(gamepad_id, key).c_str(), wxConvUTF8)
);
#endif
m_map_images[gamepad_id][get_key(gamepad_id, key)] = key;
} }
} }
@ -674,11 +701,17 @@ void Dialog::repopulate()
{ {
int keysym = it->first; int keysym = it->first;
int key = it->second; int key = it->second;
this->bt_gamepad[gamepad_id][key]->SetLabel( #if wxMAJOR_VERSION >= 3
m_bt_gamepad[gamepad_id][key]->SetLabel(
KeyName(gamepad_id, key, keysym).c_str() KeyName(gamepad_id, key, keysym).c_str()
); );
this->simulatedKeys[gamepad_id][key] = keysym; #else
this->map_images[gamepad_id][keysym] = key; m_bt_gamepad[gamepad_id][key]->SetLabel(
wxString(KeyName(gamepad_id, key, keysym).c_str(), wxConvUTF8)
);
#endif
m_simulatedKeys[gamepad_id][key] = keysym;
m_map_images[gamepad_id][keysym] = key;
} }
} }
} }

View File

@ -61,27 +61,29 @@ enum gui_buttons {
#define BUTTONS_LENGHT 32 // numbers of buttons on the gamepad #define BUTTONS_LENGHT 32 // numbers of buttons on the gamepad
#define GAMEPAD_NUMBER 2 // numbers of gamepad #define GAMEPAD_NUMBER 2 // numbers of gamepad
#define UPDATE_TIME 5 #define UPDATE_TIME 5
#define DEFAULT_WIDTH 1000
#define DEFAULT_HEIGHT 740
class Dialog : public wxFrame class Dialog : public wxFrame
{ {
// Panels // Panels
opPanel* pan_tabs[GAMEPAD_NUMBER]; // Gamepad Tabs box opPanel* m_pan_tabs[GAMEPAD_NUMBER]; // Gamepad Tabs box
// Notebooks // Notebooks
wxNotebook* tab_gamepad; // Joysticks Tabs wxNotebook* m_tab_gamepad; // Joysticks Tabs
// Buttons // Buttons
wxButton* bt_gamepad[GAMEPAD_NUMBER][BUTTONS_LENGHT]; // Joystick button use to modify the button mapping wxButton* m_bt_gamepad[GAMEPAD_NUMBER][BUTTONS_LENGHT]; // Joystick button use to modify the button mapping
// Contain all simulated key // Contain all simulated key
u32 simulatedKeys[GAMEPAD_NUMBER][MAX_KEYS]; u32 m_simulatedKeys[GAMEPAD_NUMBER][MAX_KEYS];
// Timer // Timer
wxTimer time_update_gui; wxTimer m_time_update_gui;
// Check if the gui must display feddback image // Check if the gui must display feddback image
bool pressed[GAMEPAD_NUMBER][NB_IMG]; bool m_pressed[GAMEPAD_NUMBER][NB_IMG];
// Map the key pressed with the feedback image id // Map the key pressed with the feedback image id
std::map<u32,int> map_images[GAMEPAD_NUMBER]; std::map<u32,int> m_map_images[GAMEPAD_NUMBER];
// Frame // Frame
GamepadConfiguration* frm_gamepad_config; // Gamepad Configuration frame GamepadConfiguration* m_frm_gamepad_config; // Gamepad Configuration frame
JoystickConfiguration* frm_joystick_config; // Joystick Configuration frame JoystickConfiguration* m_frm_joystick_config; // Joystick Configuration frame
// methods // methods
void config_key(int, int); void config_key(int, int);