nJoy: Preparation for fixing the digital pad and the analog triggers

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1928 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
John Peterson
2009-01-19 05:49:25 +00:00
parent c981d64ee4
commit 4a88f31ddb
12 changed files with 364 additions and 283 deletions

View File

@ -128,6 +128,43 @@ void ConfigBox::PadGetStatus()
}
// Show the current pad status
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
std::string ShowStatus()
{
SDL_Joystick *joy = SDL_JoystickOpen(0);
int axes = SDL_JoystickNumAxes(joy);
int hats = SDL_JoystickNumHats(joy);
int but = SDL_JoystickNumButtons(joy);
std::string StrAxes, StrHats, StrBut;
int value;
// Go through all axes and read out their values
SDL_JoystickUpdate();
for(int i = 0; i < axes; i++)
{
value = SDL_JoystickGetAxis(joy, i);
StrAxes += StringFromFormat(" %i:%05i", i, value);
}
for(int i = 0;i < hats; i++)
{
value = SDL_JoystickGetHat(joy, i);
StrHats += StringFromFormat(" %i:%i", i, value);
}
for(int i = 0;i < but; i++)
{
value = SDL_JoystickGetButton(joy, i);
StrBut += StringFromFormat(" %i:%i", i+1, value);
}
return StringFromFormat(
"Axes: %s\nHats: %s\nBut: %s\nDevice: Ax: %i Balls:%i But:%i Hats:%i",
StrAxes.c_str(), StrHats.c_str(), StrBut.c_str(),
joyinfo[joysticks[0].ID].NumAxes, joyinfo[joysticks[0].ID].NumBalls,
joyinfo[joysticks[0].ID].NumButtons, joyinfo[joysticks[0].ID].NumHats
);
}
// Populate the advanced tab
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void ConfigBox::Update()
@ -135,11 +172,11 @@ void ConfigBox::Update()
if(StrangeHack) PadGetStatus();
if(!g_Config.bShowAdvanced) StrangeHack = false; else StrangeHack = true;
/*
// Show the current status
/**/
m_pStatusBar->SetLabel(wxString::Format(
"Id: %i",
joysticks[0].ID
));*/
"%s", ShowStatus().c_str()
));
}

View File

@ -45,7 +45,7 @@ extern bool emulator_running;
static const char* ControllerType[] =
{
"Joystick (default)",
"Joystick (with hat)",
"Joystick (no hat)",
// "Joytstick (xbox360)", // Shoulder buttons -> axis
// "Keyboard" // Not supported yet, sorry F|RES ;( ...
@ -85,11 +85,10 @@ BEGIN_EVENT_TABLE(ConfigBox,wxDialog)
EVT_BUTTON(IDB_DPAD_DOWN, ConfigBox::GetButtons)
EVT_BUTTON(IDB_DPAD_LEFT, ConfigBox::GetButtons)
EVT_BUTTON(IDB_DPAD_RIGHT, ConfigBox::GetButtons)
EVT_BUTTON(IDB_ANALOG_MAIN_X, ConfigBox::GetAxis)
EVT_BUTTON(IDB_ANALOG_MAIN_Y, ConfigBox::GetAxis)
EVT_BUTTON(IDB_ANALOG_SUB_X, ConfigBox::GetAxis)
EVT_BUTTON(IDB_ANALOG_SUB_Y, ConfigBox::GetAxis)
EVT_BUTTON(IDB_ANALOG_MAIN_X, ConfigBox::GetButtons)
EVT_BUTTON(IDB_ANALOG_MAIN_Y, ConfigBox::GetButtons)
EVT_BUTTON(IDB_ANALOG_SUB_X, ConfigBox::GetButtons)
EVT_BUTTON(IDB_ANALOG_SUB_Y, ConfigBox::GetButtons)
#if wxUSE_TIMER
EVT_TIMER(wxID_ANY, ConfigBox::OnTimer)
@ -238,26 +237,30 @@ void ConfigBox::EnableDisable(wxCommandEvent& event)
g_Config.Save();
// Update the enable / disable status
DoEnableDisable(notebookpage);
UpdateGUI(notebookpage);
}
void ConfigBox::DoEnableDisable(int _notebookpage)
{
// Update GUI
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// Called from: SetControllerAll(), ChangeControllertype()
void ConfigBox::UpdateGUI(int _notebookpage)
{
// Update the enable / disable status
joysticks[_notebookpage].enabled = m_Joyattach[_notebookpage]->GetValue();
#ifdef _WIN32 // There is no FindItem in linux so this doesn't work
// Enable or disable all buttons
for(int i = IDB_SHOULDER_L; i < (IDB_SHOULDER_L + 13 + 4); i++)
{
m_Controller[_notebookpage]->FindItem(i)->Enable(joysticks[_notebookpage].enabled);
}
// Enable or disable settings controls
m_Controller[_notebookpage]->FindItem(IDC_DEADZONE)->Enable(joysticks[_notebookpage].enabled);
m_Controller[_notebookpage]->FindItem(IDC_CONTROLTYPE)->Enable(joysticks[_notebookpage].enabled);
#endif
// Controller type settings
bool HasHat = (joysticks[_notebookpage].controllertype == CTL_TYPE_JOYSTICK);
m_JoyDpadDown[_notebookpage]->Show(HasHat);
m_JoyDpadLeft[_notebookpage]->Show(HasHat);
m_JoyDpadRight[_notebookpage]->Show(HasHat);
m_bJoyDpadDown[_notebookpage]->Show(HasHat);
m_bJoyDpadLeft[_notebookpage]->Show(HasHat);
m_bJoyDpadRight[_notebookpage]->Show(HasHat);
m_textDpadUp[_notebookpage]->Show(HasHat);
m_textDpadDown[_notebookpage]->Show(HasHat);
m_textDpadLeft[_notebookpage]->Show(HasHat);
m_textDpadRight[_notebookpage]->Show(HasHat);
// General settings
m_CBSaveByID[_notebookpage]->SetValue(g_Config.bSaveByID.at(_notebookpage));
@ -268,8 +271,22 @@ void ConfigBox::DoEnableDisable(int _notebookpage)
m_CoBDiagonal[_notebookpage]->SetValue(wxString::FromAscii(g_Config.SDiagonal.c_str()));
m_CBS_to_C[_notebookpage]->SetValue(g_Config.bSquareToCircle.at(_notebookpage));
m_Controller[_notebookpage]->Refresh(); // Repaint the background
// There is no FindItem in linux so this doesn't work
#ifdef _WIN32
// Enable or disable all buttons
for(int i = IDB_ANALOG_MAIN_X; i < (IDB_ANALOG_MAIN_X + 13 + 4); i++)
{
m_Controller[_notebookpage]->FindItem(i)->Enable(joysticks[_notebookpage].enabled);
}
// Controller type settings
m_Controller[_notebookpage]->FindItem(IDC_DEADZONE)->Enable(joysticks[_notebookpage].enabled);
//m_Controller[_notebookpage]->FindItem(IDC_CONTROLTYPE)->Enable(joysticks[_notebookpage].enabled);
#endif
m_Controltype[_notebookpage]->SetSelection(HasHat ? 0 : 1);
// Repaint the background
m_Controller[_notebookpage]->Refresh();
}
@ -281,14 +298,16 @@ void ConfigBox::NotebookPageChanged(wxNotebookEvent& event)
}
// Change Joystick. Load saved settings.
// Change Joystick.
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/* Function: When changing the joystick we save and load the settings and update the joysticks
and joystate array */
void ConfigBox::ChangeJoystick(wxCommandEvent& event)
{
// Save potential changes to support SaveByID
int Tmp = joysticks[notebookpage].ID; // Don't update the ID
// Before chaning the pad we save potential changes (to support SaveByID)
int TmpID = joysticks[notebookpage].ID; // Don't update the ID
GetControllerAll(notebookpage);
joysticks[notebookpage].ID = Tmp;
joysticks[notebookpage].ID = TmpID;
g_Config.Save();
//PanicAlert("%i", m_Joyname[notebookpage]->GetSelection());
@ -296,14 +315,18 @@ void ConfigBox::ChangeJoystick(wxCommandEvent& event)
// Update the ID for the virtual device to a new physical device
joysticks[notebookpage].ID = m_Joyname[notebookpage]->GetSelection();
// Update the controller type
if(joyinfo[joysticks[notebookpage].ID].NumHats > 0)
joysticks[notebookpage].controllertype = CTL_TYPE_JOYSTICK;
//PanicAlert("%i %i", joysticks[notebookpage].ID, notebookpage);
// Load device settings to support SaveByID
g_Config.Load(true); // Then load the current
SetControllerAll(notebookpage); // Update joystick dialog items
DoEnableDisable(notebookpage); // Update other dialog items
UpdateGUI(notebookpage); // Update other dialog items
// Remap the controller to
// Remap the controller
if (joysticks[notebookpage].enabled)
{
if (SDL_JoystickOpened(notebookpage)) SDL_JoystickClose(joystate[notebookpage].joy);
@ -455,11 +478,14 @@ void ConfigBox::CreateGUIControls()
// --------------------------------------------------------------------
// Keys objects
// -----------------------------
// Left shoulder
// Left and right shoulder buttons
m_JoyShoulderL[i] = new wxTextCtrl(m_pKeys[i], ID_SHOULDER_L, wxT("0"), wxPoint(l + 6, t + 80), wxSize(59, 19), wxTE_READONLY | wxTE_CENTRE, wxDefaultValidator, wxT("0"));
m_JoyShoulderL[i]->Enable(false);
m_bJoyShoulderL[i] = new wxButton(m_pKeys[i], IDB_SHOULDER_L, wxEmptyString, wxPoint(l + 70, t + 82), wxSize(21, 14), 0, wxDefaultValidator, wxEmptyString);
m_JoyShoulderR[i] = new wxTextCtrl(m_pKeys[i], ID_SHOULDER_R, wxT("0"), wxPoint(l + 552, t + 106), wxSize(59, 19), wxTE_READONLY | wxTE_CENTRE, wxDefaultValidator, wxT("0"));
m_JoyShoulderR[i]->Enable(false);
m_bJoyShoulderR[i] = new wxButton(m_pKeys[i], IDB_SHOULDER_R, wxEmptyString, wxPoint(l + 526, t + 108), wxSize(21, 14), 0, wxDefaultValidator, wxEmptyString);
// Left analog
int ALt = 170; int ALw = ALt + 14; int ALb = ALw + 2; // Set offset
m_JoyAnalogMainX[i] = new wxTextCtrl(m_pKeys[i], ID_ANALOG_MAIN_X, wxT("0"), wxPoint(l + 6, t + ALw), wxSize(59, 19), wxTE_READONLY | wxTE_CENTRE, wxDefaultValidator, wxT("0"));
@ -473,13 +499,13 @@ void ConfigBox::CreateGUIControls()
// D-Pad
int DPt = 255; int DPw = DPt + 14; int DPb = DPw + 2; // Set offset
m_JoyDpadUp[i] = new wxTextCtrl(m_pKeys[i], ID_DPAD_UP, wxT("0"), wxPoint(l + 6, t + DPw), wxSize(59, t + 19), wxTE_READONLY | wxTE_CENTRE, wxDefaultValidator, wxT("0"));
m_JoyDpadUp[i] = new wxTextCtrl(m_pKeys[i], ID_DPAD_UP, wxT("0"), wxPoint(l + 6, t + DPw), wxSize(59, 19), wxTE_READONLY | wxTE_CENTRE, wxDefaultValidator, wxT("0"));
m_JoyDpadDown[i] = new wxTextCtrl(m_pKeys[i], ID_DPAD_DOWN, wxT("0"), wxPoint(l + 6, t + DPw + 36*1), wxSize(59, 19), wxTE_READONLY | wxTE_CENTRE, wxDefaultValidator, wxT("0"));
m_JoyDpadLeft[i] = new wxTextCtrl(m_pKeys[i], ID_DPAD_LEFT, wxT("0"), wxPoint(l + 6, t + DPw + 36*2), wxSize(59, 19), wxTE_READONLY | wxTE_CENTRE, wxDefaultValidator, wxT("0"));
m_JoyDpadRight[i] = new wxTextCtrl(m_pKeys[i], ID_DPAD_RIGHT, wxT("0"), wxPoint(l + 6, t + DPw + 36*3), wxSize(59, 19), wxTE_READONLY | wxTE_CENTRE, wxDefaultValidator, wxT("0"));
m_JoyDpadUp[i]->Enable(false);
m_JoyDpadDown[i] = new wxTextCtrl(m_pKeys[i], ID_DPAD_DOWN, wxT("0"), wxPoint(l + 6, t + DPw + 36*1), wxSize(59, t + 19), wxTE_READONLY | wxTE_CENTRE, wxDefaultValidator, wxT("0"));
m_JoyDpadDown[i]->Enable(false);
m_JoyDpadLeft[i] = new wxTextCtrl(m_pKeys[i], ID_DPAD_LEFT, wxT("0"), wxPoint(l + 6, t + DPw + 36*2), wxSize(59, t + 19), wxTE_READONLY | wxTE_CENTRE, wxDefaultValidator, wxT("0"));
m_JoyDpadLeft[i]->Enable(false);
m_JoyDpadRight[i] = new wxTextCtrl(m_pKeys[i], ID_DPAD_RIGHT, wxT("0"), wxPoint(l + 6, t + DPw + 36*3), wxSize(59, t + 19), wxTE_READONLY | wxTE_CENTRE, wxDefaultValidator, wxT("0"));
m_JoyDpadRight[i]->Enable(false);
m_bJoyDpadUp[i] = new wxButton(m_pKeys[i], IDB_DPAD_UP, wxEmptyString, wxPoint(l + 70, t + DPb + 36*0), wxSize(21, 14), 0, wxDefaultValidator, wxEmptyString);
m_bJoyDpadDown[i] = new wxButton(m_pKeys[i], IDB_DPAD_DOWN, wxEmptyString, wxPoint(l + 70, t + DPb + 36*1), wxSize(21, 14), 0, wxDefaultValidator, wxEmptyString);
@ -490,9 +516,7 @@ void ConfigBox::CreateGUIControls()
m_textDpadLeft[i] = new wxStaticText(m_pKeys[i], IDT_DPAD_LEFT, wxT("Left"), wxPoint(l + 6, t + DPt + 36*2), wxDefaultSize, 0, wxT("Left"));
m_textDpadRight[i] = new wxStaticText(m_pKeys[i], IDT_DPAD_RIGHT, wxT("Right"), wxPoint(l + 6, t + DPt + 36*3), wxDefaultSize, 0, wxT("Right"));
// Right side buttons
m_JoyShoulderR[i] = new wxTextCtrl(m_pKeys[i], ID_SHOULDER_R, wxT("0"), wxPoint(l + 552, t + 106), wxSize(59, 19), wxTE_READONLY | wxTE_CENTRE, wxDefaultValidator, wxT("0"));
m_JoyShoulderR[i]->Enable(false);
// Buttons
m_JoyButtonA[i] = new wxTextCtrl(m_pKeys[i], ID_BUTTON_A, wxT("0"), wxPoint(l + 552, t + 280), wxSize(59, 19), wxTE_READONLY | wxTE_CENTRE, wxDefaultValidator, wxT("0"));
m_JoyButtonA[i]->Enable(false);
m_JoyButtonB[i] = new wxTextCtrl(m_pKeys[i], ID_BUTTON_B, wxT("0"), wxPoint(l + 552, t + 80), wxSize(59, 19), wxTE_READONLY | wxTE_CENTRE, wxDefaultValidator, wxT("0"));
@ -503,7 +527,6 @@ void ConfigBox::CreateGUIControls()
m_JoyButtonY[i]->Enable(false);
m_JoyButtonZ[i] = new wxTextCtrl(m_pKeys[i], ID_BUTTON_Z, wxT("0"), wxPoint(l + 552, t + 145), wxSize(59, 19), wxTE_READONLY | wxTE_CENTRE, wxDefaultValidator, wxT("0"));
m_JoyButtonZ[i]->Enable(false);
m_bJoyShoulderR[i] = new wxButton(m_pKeys[i], IDB_SHOULDER_R, wxEmptyString, wxPoint(l + 526, t + 108), wxSize(21, 14), 0, wxDefaultValidator, wxEmptyString);
m_bJoyButtonA[i] = new wxButton(m_pKeys[i], IDB_BUTTON_A, wxEmptyString, wxPoint(l + 526, t + 282), wxSize(21, 14), 0, wxDefaultValidator, wxEmptyString);
m_bJoyButtonB[i] = new wxButton(m_pKeys[i], IDB_BUTTON_B, wxEmptyString, wxPoint(l + 526, t + 82), wxSize(21, 14), 0, wxDefaultValidator, wxEmptyString);
m_bJoyButtonX[i] = new wxButton(m_pKeys[i], IDB_BUTTON_X, wxEmptyString, wxPoint(l + 526, t + 244), wxSize(21, 14), 0, wxDefaultValidator, wxEmptyString);
@ -581,10 +604,14 @@ void ConfigBox::CreateGUIControls()
m_gGBExtrasettings[i]->Add(m_bJoyButtonHalfpress[i], wxGBPosition(1, 2), wxGBSpan(1, 1), (wxLEFT | wxTOP), 2);
m_gExtrasettings[i]->Add(m_gGBExtrasettings[i], 0, wxEXPAND | wxALL, 3);
// Why is there a setting for this? Is it to replaced the analog stick with the digital pad?
// Populate controller typ
m_gControllertype[i] = new wxStaticBoxSizer( wxVERTICAL, m_Controller[i], wxT("Controller type"));
m_Controltype[i] = new wxComboBox(m_Controller[i], IDC_CONTROLTYPE, arrayStringFor_Controltype[0], wxDefaultPosition, wxDefaultSize, arrayStringFor_Controltype, wxCB_READONLY);
m_gControllertype[i]->Add(m_Controltype[i], 0, wxEXPAND | wxALL, 3);
m_gControllertype[i]->Add(m_Controltype[i], 0, wxEXPAND | wxALL, 3);
m_Controltype[i]->Enable(false);
// Create objects for general settings
m_gGenSettings[i] = new wxStaticBoxSizer( wxVERTICAL, m_Controller[i], wxT("Settings") );
@ -706,12 +733,12 @@ void ConfigBox::CreateGUIControls()
m_Joyattach[i]->Enable(false);
m_Controltype[i]->Enable(false);
}
// Set dialog items from saved values
SetControllerAll(i);
// Update GUI
DoEnableDisable(i);
UpdateGUI(i);
} // end of loop
@ -736,7 +763,7 @@ void ConfigBox::CreateGUIControls()
// --------------------------------------------------------------------
// Debugging
// -----------------------------
//m_pStatusBar = new wxStaticText(this, IDT_DEBUGGING, wxT("Debugging"), wxPoint(100, 510), wxDefaultSize);
m_pStatusBar = new wxStaticText(this, IDT_DEBUGGING, wxT("Debugging"), wxPoint(100, 490), wxDefaultSize);
//m_pStatusBar2 = new wxStaticText(this, IDT_DEBUGGING2, wxT("Debugging2"), wxPoint(100, 530), wxDefaultSize);
//m_pStatusBar->SetLabel(wxString::Format("Debugging text"));

View File

@ -235,28 +235,28 @@ class ConfigBox : public wxDialog
ID_DPAD_LEFT,
ID_DPAD_RIGHT,
// Buttons controls
IDB_SHOULDER_L = 3000,
// Buttons controls (it's important that they are placed in this order)
IDB_ANALOG_MAIN_X = 3000,
IDB_ANALOG_MAIN_Y,
IDB_ANALOG_SUB_X,
IDB_ANALOG_SUB_Y,
IDB_SHOULDER_L,
IDB_SHOULDER_R,
IDB_DPAD_UP,
IDB_DPAD_DOWN,
IDB_DPAD_LEFT,
IDB_DPAD_RIGHT,
IDB_BUTTON_A,
IDB_BUTTON_B,
IDB_BUTTON_X,
IDB_BUTTON_Y,
IDB_BUTTON_Z,
IDB_BUTTONSTART,
IDB_BUTTONHALFPRESS,
IDB_ANALOG_MAIN_X,
IDB_ANALOG_MAIN_Y,
IDB_ANALOG_SUB_X,
IDB_ANALOG_SUB_Y,
IDB_DPAD_UP,
IDB_DPAD_DOWN,
IDB_DPAD_LEFT,
IDB_DPAD_RIGHT,
// Text controls
IDT_ANALOG_MAIN_X = 4000,
IDT_ANALOG_MAIN_Y,
@ -281,7 +281,7 @@ class ConfigBox : public wxDialog
void ChangeJoystick(wxCommandEvent& event);
void ChangeControllertype(wxCommandEvent& event);
void EnableDisable(wxCommandEvent& event); void DoEnableDisable(int _notebookpage);
void EnableDisable(wxCommandEvent& event); void UpdateGUI(int _notebookpage);
void ChangeSettings(wxCommandEvent& event); // Settings
void ComboChange(wxCommandEvent& event);
@ -293,7 +293,6 @@ class ConfigBox : public wxDialog
void PadGetStatus(); void Update();
void SetControllerAll(int controller);
void UpdateVisibleItems(int controller);
void GetControllerAll(int controller);
void NotebookPageChanged(wxNotebookEvent& event);

View File

@ -76,10 +76,11 @@ void ConfigBox::SetControllerAll(int controller)
else
m_Joyattach[controller]->SetValue(FALSE);
// Update the deadzone and controller type controls
m_Controltype[controller]->SetSelection(joysticks[controller].controllertype);
m_Deadzone[controller]->SetSelection(joysticks[controller].deadzone);
UpdateVisibleItems(controller);
UpdateGUI(controller);
if(joysticks[controller].controllertype == CTL_TYPE_JOYSTICK)
{
@ -103,6 +104,7 @@ void ConfigBox::GetControllerAll(int controller)
long value;
joysticks[controller].ID = m_Joyname[controller]->GetSelection();
if(joyinfo[joysticks[controller].ID].NumHats > 0) joysticks[controller].controllertype = CTL_TYPE_JOYSTICK;
m_JoyShoulderL[controller]->GetValue().ToLong(&value); joysticks[controller].buttons[CTL_L_SHOULDER] = value; tmp.clear();
m_JoyShoulderR[controller]->GetValue().ToLong(&value); joysticks[controller].buttons[CTL_R_SHOULDER] = value; tmp.clear();
@ -140,41 +142,6 @@ void ConfigBox::GetControllerAll(int controller)
}
void ConfigBox::UpdateVisibleItems(int controller)
{
if(joysticks[controller].controllertype)
{
m_JoyDpadDown[controller]->Show(TRUE);
m_JoyDpadLeft[controller]->Show(TRUE);
m_JoyDpadRight[controller]->Show(TRUE);
m_bJoyDpadDown[controller]->Show(TRUE);
m_bJoyDpadLeft[controller]->Show(TRUE);
m_bJoyDpadRight[controller]->Show(TRUE);
m_textDpadUp[controller]->Show(TRUE);
m_textDpadDown[controller]->Show(TRUE);
m_textDpadLeft[controller]->Show(TRUE);
m_textDpadRight[controller]->Show(TRUE);
}
else
{
m_JoyDpadDown[controller]->Show(FALSE);
m_JoyDpadLeft[controller]->Show(FALSE);
m_JoyDpadRight[controller]->Show(FALSE);
m_bJoyDpadDown[controller]->Show(FALSE);
m_bJoyDpadLeft[controller]->Show(FALSE);
m_bJoyDpadRight[controller]->Show(FALSE);
m_textDpadUp[controller]->Show(FALSE);
m_textDpadDown[controller]->Show(FALSE);
m_textDpadLeft[controller]->Show(FALSE);
m_textDpadRight[controller]->Show(FALSE);
}
}
// Change controller type
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void ConfigBox::ChangeControllertype(wxCommandEvent& event)
@ -184,7 +151,7 @@ void ConfigBox::ChangeControllertype(wxCommandEvent& event)
joysticks[2].controllertype = m_Controltype[2]->GetSelection();
joysticks[3].controllertype = m_Controltype[3]->GetSelection();
for(int i=0; i<4 ;i++) UpdateVisibleItems(i);
for(int i=0; i<4 ;i++) UpdateGUI(i);
}
@ -195,22 +162,13 @@ void ConfigBox::SetButtonText(int id, char text[128])
switch(id)
{
case IDB_SHOULDER_L:
{
m_JoyShoulderL[controller]->SetValue(wxString::FromAscii(text));
}
break;
m_JoyShoulderL[controller]->SetValue(wxString::FromAscii(text)); break;
case IDB_SHOULDER_R:
{
m_JoyShoulderR[controller]->SetValue(wxString::FromAscii(text));
}
break;
m_JoyShoulderR[controller]->SetValue(wxString::FromAscii(text)); break;
case IDB_BUTTON_A:
{
m_JoyButtonA[controller]->SetValue(wxString::FromAscii(text));
}
break;
m_JoyButtonA[controller]->SetValue(wxString::FromAscii(text)); break;
case IDB_BUTTON_B:
{
@ -225,16 +183,10 @@ void ConfigBox::SetButtonText(int id, char text[128])
break;
case IDB_BUTTON_Y:
{
m_JoyButtonY[controller]->SetValue(wxString::FromAscii(text));
}
break;
m_JoyButtonY[controller]->SetValue(wxString::FromAscii(text)); break;
case IDB_BUTTON_Z:
{
m_JoyButtonZ[controller]->SetValue(wxString::FromAscii(text));
}
break;
m_JoyButtonZ[controller]->SetValue(wxString::FromAscii(text)); break;
case IDB_BUTTONSTART:
{
@ -267,34 +219,19 @@ void ConfigBox::SetButtonText(int id, char text[128])
break;
case IDB_DPAD_RIGHT:
{
m_JoyDpadRight[controller]->SetValue(wxString::FromAscii(text));
}
break;
m_JoyDpadRight[controller]->SetValue(wxString::FromAscii(text)); break;
case IDB_ANALOG_MAIN_X:
{
m_JoyAnalogMainX[controller]->SetValue(wxString::FromAscii(text));
}
break;
m_JoyAnalogMainX[controller]->SetValue(wxString::FromAscii(text)); break;
case IDB_ANALOG_MAIN_Y:
{
m_JoyAnalogMainY[controller]->SetValue(wxString::FromAscii(text));
}
break;
m_JoyAnalogMainY[controller]->SetValue(wxString::FromAscii(text)); break;
case IDB_ANALOG_SUB_X:
{
m_JoyAnalogSubX[controller]->SetValue(wxString::FromAscii(text));
}
break;
m_JoyAnalogSubX[controller]->SetValue(wxString::FromAscii(text)); break;
case IDB_ANALOG_SUB_Y:
{
m_JoyAnalogSubY[controller]->SetValue(wxString::FromAscii(text));
}
break;
m_JoyAnalogSubY[controller]->SetValue(wxString::FromAscii(text)); break;
default:
break;
@ -302,6 +239,26 @@ void ConfigBox::SetButtonText(int id, char text[128])
}
//////////////////////////////////////////////////////////////////////////////////////////
// Condifigure button mapping
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// Avoid extreme axis values
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/* Function: We have to avoid very big values to becuse some triggers are -0x8000 in the
unpressed state (and then go from -0x8000 to 0x8000 as they are fully pressed) */
bool AvoidValues(int value)
{
// Avoid detecting very small or very big (for triggers) values
if( (value > -0x1000 && value < 0x1000) // Small values
|| (value < -0x7000 || value > 0x7000)) // Big values
return true; // Avoid
else
return false; // Keep
}
// Wait for button press
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void ConfigBox::GetButtons(wxCommandEvent& event)
@ -312,44 +269,85 @@ void ConfigBox::GetButtons(wxCommandEvent& event)
// Get the ID for the wxWidgets button that was pressed
int ID = event.GetId();
// DPAD type check
if(ID == IDB_DPAD_UP)
if(joysticks[controller].controllertype == 0)
{
GetHats(ID);
return;
}
// Collect the accepted buttons for this slot
bool Axis = (event.GetId() >= IDB_ANALOG_MAIN_X && event.GetId() <= IDB_SHOULDER_R);
bool Button = (event.GetId() >= IDB_BUTTON_A && event.GetId() <= IDB_BUTTONSTART)
|| (event.GetId() == IDB_SHOULDER_L || event.GetId() == IDB_SHOULDER_R);
bool Hat = (event.GetId() >= IDB_DPAD_UP && event.GetId() <= IDB_DPAD_RIGHT);
/* Open a new joystick. Joysticks[controller].ID is the system ID of the physicaljoystick
/* Open a new joystick. Joysticks[controller].ID is the system ID of the physical joystick
that is mapped to controller, for example 0, 1, 2, 3 for the first four joysticks */
SDL_Joystick *joy = SDL_JoystickOpen(joysticks[controller].ID);
// Get the number of axes, hats and buttons
int buttons = SDL_JoystickNumButtons(joy);
int axes = SDL_JoystickNumAxes(joy);
int hats = SDL_JoystickNumHats(joy);
// Declare values
char format[128];
int buttons = SDL_JoystickNumButtons(joy); // Get number of buttons
int value; // Axis value
bool waiting = true;
bool succeed = false;
int pressed = 0;
int counter1 = 0; // Waiting limits
int counter2 = 30; // Iterations to wait for
// Update the text box
sprintf(format, "[%d]", counter2);
SetButtonText(ID, format);
wxWindow::Update(); // win only? doesnt seem to work in linux...
wxWindow::Update(); // Win only? doesnt seem to work in linux...
while(waiting)
{
// Go through all axes and read out their values
{
// Update the internal status
SDL_JoystickUpdate();
for(int b = 0; b < buttons; b++)
{
if(SDL_JoystickGetButton(joy, b))
// For the triggers we accept both a digital or an analog button
if(Axis)
{
for(int i = 0; i < axes; i++)
{
pressed = b;
value = SDL_JoystickGetAxis(joy, i);
if(AvoidValues(value)) continue; // Avoid values
pressed = i;
waiting = false;
succeed = true;
break;
}
break; // Stop this loop
}
}
// Check for a hat
if(Hat)
{
for(int i = 0; i < hats; i++)
{
value = SDL_JoystickGetHat(joy, i);
if(value)
{
pressed = value;
waiting = false;
succeed = true;
break;
}
}
}
// Check for a button
if(Button)
{
for(int i = 0; i < buttons; i++)
{
if(SDL_JoystickGetButton(joy, i))
{
pressed = i;
waiting = false;
succeed = true;
break;
}
}
}
// Check for keyboard action
@ -409,22 +407,92 @@ void ConfigBox::GetButtons(wxCommandEvent& event)
sprintf(format, "%d", succeed ? pressed : -1);
SetButtonText(ID, format);
// We don't need this any more
// We don't need thisgamepad handle any more
if(SDL_JoystickOpened(joysticks[controller].ID)) SDL_JoystickClose(joy);
}
// Wait for Analog
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void ConfigBox::GetAxis(wxCommandEvent& event)
{
int ID = event.GetId();
int controller = notebookpage;
SDL_Joystick *joy = SDL_JoystickOpen(joysticks[controller].ID);
char format[128];
int axes = SDL_JoystickNumAxes(joy); // Get number of axes
bool waiting = true;
bool succeed = false;
int pressed = 0;
Sint16 value;
int counter1 = 0;
int counter2 = 10;
sprintf(format, "[%d]", counter2);
SetButtonText(ID, format);
wxWindow::Update(); // Win only? doesnt seem to work in linux...
while(waiting)
{
// Go through all axes and read out their values
SDL_JoystickUpdate();
for(int i = 0; i < axes; i++)
{
value = SDL_JoystickGetAxis(joy, i);
if(AvoidValues(value)) continue; // Avoid values
pressed = i;
waiting = false;
succeed = true;
break; // Stop this loop
}
// Stop waiting for a button
counter1++;
if(counter1 == 100)
{
counter1 = 0;
counter2--;
sprintf(format, "[%d]", counter2);
SetButtonText(ID, format);
wxWindow::Update(); // win only? doesnt seem to work in linux...
wxYieldIfNeeded(); // Let through debugging events
if(counter2<0)
waiting = false;
}
SLEEP(10);
}
sprintf(format, "%d", succeed ? pressed : -1); // Update the status text box
SetButtonText(ID, format);
if(SDL_JoystickOpened(joysticks[controller].ID)) // Close the handle
SDL_JoystickClose(joy);
// Update the axises for the advanced settings status
GetControllerAll(controller);
}
// Wait for D-Pad
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void ConfigBox::GetHats(int ID)
{
// Get the active controller
int controller = notebookpage;
SDL_Joystick *joy;
joy = SDL_JoystickOpen(joysticks[controller].ID);
/* Open a new joystick. Joysticks[controller].ID is the system ID of the physical joystick
that is mapped to controller, for example 0, 1, 2, 3 for the first four joysticks */
SDL_Joystick *joy = SDL_JoystickOpen(joysticks[controller].ID);
char format[128];
int hats = SDL_JoystickNumHats(joy);
int hats = SDL_JoystickNumHats(joy); // Get the number of sticks
bool waiting = true;
bool succeed = false;
int pressed = 0;
@ -439,16 +507,6 @@ void ConfigBox::GetHats(int ID)
while(waiting)
{
SDL_JoystickUpdate();
for(int b = 0; b < hats; b++)
{
if(SDL_JoystickGetHat(joy, b))
{
pressed = b;
waiting = false;
succeed = true;
break;
}
}
counter1++;
if(counter1==100)
@ -473,69 +531,4 @@ void ConfigBox::GetHats(int ID)
SDL_JoystickClose(joy);
}
// Wait for Analog
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void ConfigBox::GetAxis(wxCommandEvent& event)
{
int ID = event.GetId();
int controller = notebookpage;
SDL_Joystick *joy;
joy=SDL_JoystickOpen(joysticks[controller].ID);
char format[128];
int axes = SDL_JoystickNumAxes(joy);
bool waiting = true;
bool succeed = false;
int pressed = 0;
Sint16 value;
int counter1 = 0;
int counter2 = 10;
sprintf(format, "[%d]", counter2);
SetButtonText(ID, format);
wxWindow::Update(); // win only? doesnt seem to work in linux...
while(waiting)
{
// Go through all axes and read out their values
SDL_JoystickUpdate();
for(int b = 0; b < axes; b++)
{
value = SDL_JoystickGetAxis(joy, b);
if(value < -10000 || value > 10000) // Avoid detecting small values
{
pressed = b;
waiting = false;
succeed = true;
break;
}
}
// Stop waiting for a button
counter1++;
if(counter1 == 100)
{
counter1=0;
counter2--;
sprintf(format, "[%d]", counter2);
SetButtonText(ID, format);
wxWindow::Update(); // win only? doesnt seem to work in linux...
if(counter2<0)
waiting = false;
}
SLEEP(10);
}
sprintf(format, "%d", succeed ? pressed : -1); // Update the status text box
SetButtonText(ID, format);
if(SDL_JoystickOpened(joysticks[controller].ID)) // Close the handle
SDL_JoystickClose(joy);
// Update the axises for the advanced settings status
GetControllerAll(controller);
}
/////////////////////////////////////////////////////////// Configure button mapping