2015-10-27 19:07:41 +00:00
|
|
|
/* JoystickConfiguration.cpp
|
|
|
|
* PCSX2 Dev Team
|
2015-10-17 16:57:28 +00:00
|
|
|
* Copyright (C) 2015
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "JoystickConfiguration.h"
|
|
|
|
|
|
|
|
// Construtor of JoystickConfiguration
|
2016-09-04 12:10:02 +00:00
|
|
|
JoystickConfiguration::JoystickConfiguration(int pad, bool left, wxWindow *parent)
|
|
|
|
: wxDialog(
|
2016-10-16 19:39:56 +00:00
|
|
|
parent, // Parent
|
|
|
|
wxID_ANY, // ID
|
|
|
|
_T("Gamepad configuration"), // Title
|
|
|
|
wxDefaultPosition, // Position
|
|
|
|
wxSize(400, 200), // Width + Lenght
|
2016-09-04 12:10:02 +00:00
|
|
|
// Style
|
|
|
|
wxSYSTEM_MENU |
|
|
|
|
wxCAPTION |
|
|
|
|
wxCLOSE_BOX |
|
|
|
|
wxCLIP_CHILDREN)
|
2015-10-17 16:57:28 +00:00
|
|
|
{
|
|
|
|
|
2015-11-29 14:42:42 +00:00
|
|
|
m_pad_id = pad;
|
|
|
|
m_isForLeftJoystick = left;
|
|
|
|
m_pan_joystick_config = new wxPanel(
|
2016-10-16 19:39:56 +00:00
|
|
|
this, // Parent
|
|
|
|
wxID_ANY, // ID
|
|
|
|
wxDefaultPosition, // Prosition
|
|
|
|
wxSize(300, 200) // Size
|
2016-09-04 12:10:02 +00:00
|
|
|
);
|
2015-10-17 16:57:28 +00:00
|
|
|
|
2016-09-04 12:10:02 +00:00
|
|
|
if (m_isForLeftJoystick) {
|
2015-11-29 14:42:42 +00:00
|
|
|
m_cb_reverse_Lx = new wxCheckBox(
|
2016-10-16 19:39:56 +00:00
|
|
|
m_pan_joystick_config, // Parent
|
|
|
|
wxID_ANY, // ID
|
|
|
|
_T("Reverse Lx"), // Label
|
|
|
|
wxPoint(20, 20) // Position
|
2016-09-04 12:10:02 +00:00
|
|
|
);
|
2015-10-17 16:57:28 +00:00
|
|
|
|
2015-11-29 14:42:42 +00:00
|
|
|
m_cb_reverse_Ly = new wxCheckBox(
|
2016-10-16 19:39:56 +00:00
|
|
|
m_pan_joystick_config, // Parent
|
|
|
|
wxID_ANY, // ID
|
|
|
|
_T("Reverse Ly"), // Label
|
|
|
|
wxPoint(20, 40) // Position
|
2016-09-04 12:10:02 +00:00
|
|
|
);
|
2015-10-17 16:57:28 +00:00
|
|
|
|
2015-11-29 14:42:42 +00:00
|
|
|
m_cb_mouse_Ljoy = new wxCheckBox(
|
2016-10-16 19:39:56 +00:00
|
|
|
m_pan_joystick_config, // Parent
|
|
|
|
wxID_ANY, // ID
|
|
|
|
_T("Use mouse for left analog joystick"), // Label
|
|
|
|
wxPoint(20, 60) // Position
|
2016-09-04 12:10:02 +00:00
|
|
|
);
|
|
|
|
} else {
|
2015-11-29 14:42:42 +00:00
|
|
|
m_cb_reverse_Rx = new wxCheckBox(
|
2016-10-16 19:39:56 +00:00
|
|
|
m_pan_joystick_config, // Parent
|
|
|
|
wxID_ANY, // ID
|
|
|
|
_T("Reverse Rx"), // Label
|
|
|
|
wxPoint(20, 20) // Position
|
2016-09-04 12:10:02 +00:00
|
|
|
);
|
2015-10-17 16:57:28 +00:00
|
|
|
|
2015-11-29 14:42:42 +00:00
|
|
|
m_cb_reverse_Ry = new wxCheckBox(
|
2016-10-16 19:39:56 +00:00
|
|
|
m_pan_joystick_config, // Parent
|
|
|
|
wxID_ANY, // ID
|
|
|
|
_T("Reverse Ry"), // Label
|
|
|
|
wxPoint(20, 40) // Position
|
2016-09-04 12:10:02 +00:00
|
|
|
);
|
2015-10-17 16:57:28 +00:00
|
|
|
|
2015-11-29 14:42:42 +00:00
|
|
|
m_cb_mouse_Rjoy = new wxCheckBox(
|
2016-10-16 19:39:56 +00:00
|
|
|
m_pan_joystick_config, // Parent
|
|
|
|
wxID_ANY, // ID
|
|
|
|
_T("Use mouse for right analog joystick"), // Label
|
|
|
|
wxPoint(20, 60) // Position
|
2016-09-04 12:10:02 +00:00
|
|
|
);
|
2015-10-17 16:57:28 +00:00
|
|
|
}
|
|
|
|
|
2015-11-29 14:42:42 +00:00
|
|
|
m_bt_ok = new wxButton(
|
2016-10-16 19:39:56 +00:00
|
|
|
m_pan_joystick_config, // Parent
|
|
|
|
wxID_ANY, // ID
|
|
|
|
_T("&OK"), // Label
|
|
|
|
wxPoint(250, 130), // Position
|
|
|
|
wxSize(60, 25) // Size
|
2016-09-04 12:10:02 +00:00
|
|
|
);
|
2015-10-17 16:57:28 +00:00
|
|
|
|
2015-11-29 14:42:42 +00:00
|
|
|
m_bt_cancel = new wxButton(
|
2016-10-16 19:39:56 +00:00
|
|
|
m_pan_joystick_config, // Parent
|
|
|
|
wxID_ANY, // ID
|
|
|
|
_T("&Cancel"), // Label
|
|
|
|
wxPoint(320, 130), // Position
|
|
|
|
wxSize(60, 25) // Size
|
2016-09-04 12:10:02 +00:00
|
|
|
);
|
2015-10-17 16:57:28 +00:00
|
|
|
|
2016-04-27 07:47:03 +00:00
|
|
|
Bind(wxEVT_BUTTON, &JoystickConfiguration::OnButtonClicked, this);
|
|
|
|
Bind(wxEVT_CHECKBOX, &JoystickConfiguration::OnCheckboxChange, this);
|
2015-10-17 16:57:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Initialize the frame
|
|
|
|
Check if a gamepad is detected
|
|
|
|
*/
|
|
|
|
void JoystickConfiguration::InitJoystickConfiguration()
|
|
|
|
{
|
2016-10-16 19:39:56 +00:00
|
|
|
repopulate(); // Set label and fit simulated key array
|
2015-10-17 16:57:28 +00:00
|
|
|
/*
|
|
|
|
* 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 1, you need at least 2 gamepad connected,
|
|
|
|
* Prevent to use a none initialized value on s_vgamePad (core dump)
|
|
|
|
*/
|
2016-09-04 12:10:02 +00:00
|
|
|
if (s_vgamePad.size() < m_pad_id + 1) {
|
2015-11-29 14:42:42 +00:00
|
|
|
wxMessageBox(L"No gamepad detected.");
|
2015-10-17 16:57:28 +00:00
|
|
|
// disable all checkbox
|
2016-09-04 12:10:02 +00:00
|
|
|
if (m_isForLeftJoystick) {
|
2015-11-29 14:42:42 +00:00
|
|
|
m_cb_reverse_Lx->Disable();
|
|
|
|
m_cb_reverse_Ly->Disable();
|
2016-09-04 12:10:02 +00:00
|
|
|
} else {
|
2015-11-29 14:42:42 +00:00
|
|
|
m_cb_reverse_Rx->Disable();
|
|
|
|
m_cb_reverse_Ry->Disable();
|
2015-10-17 16:57:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************/
|
|
|
|
/*********** Events functions ***********/
|
|
|
|
/****************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Button event, called when a button is clicked
|
|
|
|
*/
|
|
|
|
void JoystickConfiguration::OnButtonClicked(wxCommandEvent &event)
|
|
|
|
{
|
|
|
|
// Affichage d'un message à chaque clic sur le bouton
|
2016-10-16 19:39:56 +00:00
|
|
|
wxButton *bt_tmp = (wxButton *)event.GetEventObject(); // get the button object
|
|
|
|
int bt_id = bt_tmp->GetId(); // get the real ID
|
|
|
|
if (bt_id == m_bt_ok->GetId()) { // If the button ID is equals to the Ok button ID
|
|
|
|
Close(); // Close the window
|
|
|
|
} else if (bt_id == m_bt_cancel->GetId()) { // If the button ID is equals to the cancel button ID
|
|
|
|
reset(); // reinitialize the value of each parameters
|
|
|
|
Close(); // Close the window
|
2015-10-17 16:57:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checkbox event, called when the value of the checkbox change
|
|
|
|
*/
|
2016-09-04 12:10:02 +00:00
|
|
|
void JoystickConfiguration::OnCheckboxChange(wxCommandEvent &event)
|
2015-10-17 16:57:28 +00:00
|
|
|
{
|
2016-10-16 19:39:56 +00:00
|
|
|
wxCheckBox *cb_tmp = (wxCheckBox *)event.GetEventObject(); // get the slider object
|
2015-10-17 16:57:28 +00:00
|
|
|
int cb_id = cb_tmp->GetId();
|
|
|
|
bool val;
|
2016-09-04 12:10:02 +00:00
|
|
|
if (m_isForLeftJoystick) {
|
|
|
|
if (cb_id == m_cb_reverse_Ly->GetId()) {
|
2015-11-29 14:42:42 +00:00
|
|
|
val = m_cb_reverse_Ly->GetValue();
|
|
|
|
conf->pad_options[m_pad_id].reverse_ly = val;
|
2016-09-04 12:10:02 +00:00
|
|
|
} else if (cb_id == m_cb_reverse_Lx->GetId()) {
|
2015-11-29 14:42:42 +00:00
|
|
|
val = m_cb_reverse_Lx->GetValue();
|
|
|
|
conf->pad_options[m_pad_id].reverse_lx = val;
|
2016-09-04 12:10:02 +00:00
|
|
|
} else if (cb_id == m_cb_mouse_Ljoy->GetId()) {
|
2015-11-29 14:42:42 +00:00
|
|
|
val = m_cb_mouse_Ljoy->GetValue();
|
|
|
|
conf->pad_options[m_pad_id].mouse_l = val;
|
2015-10-17 16:57:28 +00:00
|
|
|
}
|
2016-09-04 12:10:02 +00:00
|
|
|
} else {
|
|
|
|
if (cb_id == m_cb_reverse_Ry->GetId()) {
|
2015-11-29 14:42:42 +00:00
|
|
|
val = m_cb_reverse_Ry->GetValue();
|
|
|
|
conf->pad_options[m_pad_id].reverse_ry = val;
|
2016-09-04 12:10:02 +00:00
|
|
|
} else if (cb_id == m_cb_reverse_Rx->GetId()) {
|
2015-11-29 14:42:42 +00:00
|
|
|
val = m_cb_reverse_Rx->GetValue();
|
|
|
|
conf->pad_options[m_pad_id].reverse_rx = val;
|
2016-09-04 12:10:02 +00:00
|
|
|
} else if (cb_id == m_cb_mouse_Rjoy->GetId()) {
|
2015-11-29 14:42:42 +00:00
|
|
|
val = m_cb_mouse_Rjoy->GetValue();
|
|
|
|
conf->pad_options[m_pad_id].mouse_r = val;
|
2015-10-17 16:57:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************/
|
|
|
|
/*********** Methods functions **********/
|
|
|
|
/****************************************/
|
|
|
|
|
|
|
|
// Reset checkbox and slider values
|
|
|
|
void JoystickConfiguration::reset()
|
|
|
|
{
|
2016-09-04 12:10:02 +00:00
|
|
|
if (m_isForLeftJoystick) {
|
2015-11-29 14:42:42 +00:00
|
|
|
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);
|
2016-09-04 12:10:02 +00:00
|
|
|
} else {
|
2015-11-29 14:42:42 +00:00
|
|
|
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);
|
2015-10-17 16:57:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set button values
|
|
|
|
void JoystickConfiguration::repopulate()
|
|
|
|
{
|
|
|
|
bool val;
|
2016-09-04 12:10:02 +00:00
|
|
|
if (m_isForLeftJoystick) {
|
2015-11-29 14:42:42 +00:00
|
|
|
val = conf->pad_options[m_pad_id].reverse_lx;
|
|
|
|
m_init_reverse_Lx = val;
|
|
|
|
m_cb_reverse_Lx->SetValue(val);
|
2015-10-17 16:57:28 +00:00
|
|
|
|
2015-11-29 14:42:42 +00:00
|
|
|
val = conf->pad_options[m_pad_id].reverse_ly;
|
|
|
|
m_init_reverse_Ly = val;
|
|
|
|
m_cb_reverse_Ly->SetValue(val);
|
2015-10-17 16:57:28 +00:00
|
|
|
|
2015-11-29 14:42:42 +00:00
|
|
|
val = conf->pad_options[m_pad_id].mouse_l;
|
|
|
|
m_init_mouse_Ljoy = val;
|
|
|
|
m_cb_mouse_Ljoy->SetValue(val);
|
2016-09-04 12:10:02 +00:00
|
|
|
} else {
|
2015-11-29 14:42:42 +00:00
|
|
|
val = conf->pad_options[m_pad_id].reverse_rx;
|
|
|
|
m_init_reverse_Rx = val;
|
|
|
|
m_cb_reverse_Rx->SetValue(val);
|
2015-10-17 16:57:28 +00:00
|
|
|
|
2015-11-29 14:42:42 +00:00
|
|
|
val = conf->pad_options[m_pad_id].reverse_ry;
|
|
|
|
m_init_reverse_Ry = val;
|
|
|
|
m_cb_reverse_Ry->SetValue(val);
|
2015-10-17 16:57:28 +00:00
|
|
|
|
2015-11-29 14:42:42 +00:00
|
|
|
val = conf->pad_options[m_pad_id].mouse_r;
|
|
|
|
m_init_mouse_Rjoy = val;
|
|
|
|
m_cb_mouse_Rjoy->SetValue(val);
|
2015-10-17 16:57:28 +00:00
|
|
|
}
|
|
|
|
}
|