Merged PadSimple with nJoy

(Linux build could be broken, X360Pad support could be broken)

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4924 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
ayuanx
2010-01-22 23:19:16 +00:00
parent c09ec17bb2
commit 68a4eacb62
38 changed files with 3302 additions and 9319 deletions
+1 -1
View File
@@ -318,7 +318,7 @@ void Config::Load()
iniFile.Get(SectionName, "Trigger_R", &WiiMoteEmu::WiiMapping[i].AxisMapping.Tr, 1005);
iniFile.Get(SectionName, "DeadZoneL", &WiiMoteEmu::WiiMapping[i].DeadZoneL, 0);
iniFile.Get(SectionName, "DeadZoneR", &WiiMoteEmu::WiiMapping[i].DeadZoneR, 0);
iniFile.Get(SectionName, "Diagonal", &WiiMoteEmu::WiiMapping[i].Diagonal, "100%");
iniFile.Get(SectionName, "Diagonal", &WiiMoteEmu::WiiMapping[i].Diagonal, 100);
iniFile.Get(SectionName, "Circle2Square", &WiiMoteEmu::WiiMapping[i].bCircle2Square, false);
iniFile.Get(SectionName, "Rumble", &WiiMoteEmu::WiiMapping[i].Rumble, false);
iniFile.Get(SectionName, "RumbleStrength", &WiiMoteEmu::WiiMapping[i].RumbleStrength, 8); // x10
@@ -29,7 +29,7 @@
// Replace the harder to understand -1 with "" for the sake of user friendliness
void WiimotePadConfigDialog::ToBlank(bool ToBlank, int Id)
{
if (!ControlsCreated)
if (!m_ControlsCreated)
return;
if(ToBlank)
@@ -98,30 +98,6 @@ wxString WiimotePadConfigDialog::GetButtonText(int id)
return wxString();
}
// Configure button mapping
// Wait for button press
/* Loop or timer: There are basically two ways to do this. With a while() or
for() loop, or with a timer. The downside with the while() or for() loop is
that there is no way to stop it if the user should select to configure
another button while we are still in an old loop. What will happen then is
that we start another parallel loop (at least in Windows) that blocks the
old loop. And our only option to wait for the old loop to finish is with a
new loop, and that will block the old loop for as long as it's going
on. Therefore a timer is easier to control. */
void WiimotePadConfigDialog::GetButtons(wxCommandEvent& event)
{
if (event.GetEventType() != wxEVT_COMMAND_BUTTON_CLICKED)
return;
if (m_ButtonMappingTimer->IsRunning())
return;
wxButton* pButton = (wxButton *)event.GetEventObject();
OldLabel = pButton->GetLabel();
pButton->SetLabel(wxT("<Move Axis>"));
DoGetButtons(pButton->GetId());
}
void WiimotePadConfigDialog::DoGetButtons(int _GetId)
{
// Collect the starting values
@@ -309,7 +285,7 @@ void WiimotePadConfigDialog::UpdatePadInfo(wxTimerEvent& WXUNUSED(event))
// Produce square
if(WiiMoteEmu::WiiMapping[m_Page].bCircle2Square)
InputCommon::Square2Circle(main_x_after, main_y_after, 0, WiiMoteEmu::WiiMapping[m_Page].Diagonal, true);
InputCommon::Square2Circle(main_x_after, main_y_after, WiiMoteEmu::WiiMapping[m_Page].Diagonal, true);
// Check dead zone
float DeadZoneLeft = (float)WiiMoteEmu::WiiMapping[m_Page].DeadZoneL / 100.0;
@@ -325,38 +301,15 @@ void WiimotePadConfigDialog::UpdatePadInfo(wxTimerEvent& WXUNUSED(event))
right_y_after = 0;
}
// Show the adjusted angles in the status box
// Change 0x8000 to 180
/*
float x8000 = 0x8000;
main_x_after = main_x_after * (180 / x8000);
main_y_after = main_y_after * (180 / x8000);
float f_main_x_after = (float)main_x_after;
float f_main_y_after = (float)main_y_after;
WiiMoteEmu::AdjustAngles(f_main_x_after, f_main_y_after);
//WiiMoteEmu::AdjustAngles(f_main_x_after, f_main_y_after, true);
main_x_after = (int)f_main_x_after;
main_y_after = (int)f_main_y_after;
// Change back 180 to 0x8000
main_x_after = main_x_after * (x8000 / 180);
main_y_after = main_y_after * (x8000 / 180);
*/
int Lx = InputCommon::Pad_Convert(main_x); int Ly = InputCommon::Pad_Convert(main_y);
int Rx = InputCommon::Pad_Convert(right_x); int Ry = InputCommon::Pad_Convert(right_y);
int Lx_after = InputCommon::Pad_Convert(main_x_after); int Ly_after = InputCommon::Pad_Convert(main_y_after);
int Rx_after = InputCommon::Pad_Convert(right_x_after); int Ry_after = InputCommon::Pad_Convert(right_y_after);
// Convert the values to fractions
float f_x = main_x / 32767.0;
float f_y = main_y / 32767.0;
float f_x_aft = main_x_after / 32767.0;
float f_y_aft = main_y_after / 32767.0;
float f_Rx = right_x / 32767.0;
float f_Ry = right_y / 32767.0;
float f_Rx_aft = right_x_after / 32767.0;
float f_Ry_aft = right_y_after / 32767.0;
m_tStatusLeftIn[m_Page]->SetLabel(wxString::Format(wxT("x:%1.2f y:%1.2f"), f_x, f_y ));
m_tStatusLeftOut[m_Page]->SetLabel(wxString::Format(wxT("x:%1.2f y:%1.2f"), f_x_aft, f_y_aft));
m_tStatusRightIn[m_Page]->SetLabel(wxString::Format(wxT("x:%1.2f y:%1.2f"), f_Rx, f_Ry));
m_tStatusRightOut[m_Page]->SetLabel(wxString::Format(wxT("x:%1.2f y:%1.2f"), f_Rx_aft, f_Ry_aft));
m_tStatusLeftIn[m_Page]->SetLabel(wxString::Format(wxT("X:%03i Y:%03i"), Lx, Ly));
m_tStatusLeftOut[m_Page]->SetLabel(wxString::Format(wxT("X:%03i Y:%03i"), Lx_after, Ly_after));
m_tStatusRightIn[m_Page]->SetLabel(wxString::Format(wxT("X:%03i Y:%03i"), Rx, Ry));
m_tStatusRightOut[m_Page]->SetLabel(wxString::Format(wxT("X:%03i Y:%03i"), Rx_after, Ry_after));
// Adjust the values for the plot
Convert2Box(main_x); Convert2Box(main_y);
@@ -62,9 +62,9 @@ BEGIN_EVENT_TABLE(WiimotePadConfigDialog,wxDialog)
EVT_COMBOBOX(IDC_GH3_ANALOG, WiimotePadConfigDialog::GeneralSettingsChanged)
// Analog
EVT_BUTTON(IDB_ANALOG_LEFT_X, WiimotePadConfigDialog::GetButtons) EVT_BUTTON(IDB_ANALOG_LEFT_Y, WiimotePadConfigDialog::GetButtons)
EVT_BUTTON(IDB_ANALOG_RIGHT_X, WiimotePadConfigDialog::GetButtons) EVT_BUTTON(IDB_ANALOG_RIGHT_Y, WiimotePadConfigDialog::GetButtons)
EVT_BUTTON(IDB_TRIGGER_L, WiimotePadConfigDialog::GetButtons) EVT_BUTTON(IDB_TRIGGER_R, WiimotePadConfigDialog::GetButtons)
EVT_BUTTON(IDB_ANALOG_LEFT_X, WiimotePadConfigDialog::OnAxisClick) EVT_BUTTON(IDB_ANALOG_LEFT_Y, WiimotePadConfigDialog::OnAxisClick)
EVT_BUTTON(IDB_ANALOG_RIGHT_X, WiimotePadConfigDialog::OnAxisClick) EVT_BUTTON(IDB_ANALOG_RIGHT_Y, WiimotePadConfigDialog::OnAxisClick)
EVT_BUTTON(IDB_TRIGGER_L, WiimotePadConfigDialog::OnAxisClick) EVT_BUTTON(IDB_TRIGGER_R, WiimotePadConfigDialog::OnAxisClick)
// Wiimote
EVT_BUTTON(IDB_WM_A, WiimotePadConfigDialog::OnButtonClick) EVT_BUTTON(IDB_WM_B, WiimotePadConfigDialog::OnButtonClick)
@@ -116,6 +116,11 @@ WiimotePadConfigDialog::WiimotePadConfigDialog(wxWindow *parent, wxWindowID id,
const wxPoint &position, const wxSize& size, long style)
: wxDialog(parent, id, title, position, size, style)
{
m_ControlsCreated = false;;
m_Page = g_Config.CurrentPage;
CreatePadGUIControls();
m_Notebook->ChangeSelection(m_Page);
#if wxUSE_TIMER
m_ButtonMappingTimer = new wxTimer(this, IDTM_BUTTON);
m_UpdatePadTimer = new wxTimer(this, IDTM_UPDATE_PAD);
@@ -134,14 +139,6 @@ WiimotePadConfigDialog::WiimotePadConfigDialog(wxWindow *parent, wxWindowID id,
}
#endif
ControlsCreated = false;
//g_Config.Load();
CreatePadGUIControls();
m_Page = g_Config.CurrentPage;
m_Notebook->ChangeSelection(m_Page);
// Set control values
UpdateGUI();
@@ -164,6 +161,41 @@ WiimotePadConfigDialog::~WiimotePadConfigDialog()
}
}
// Notebook page changed
void WiimotePadConfigDialog::NotebookPageChanged(wxNotebookEvent& event)
{
// Update the global variable
m_Page = event.GetSelection();
// Update GUI
if (m_ControlsCreated)
UpdateGUI();
}
void WiimotePadConfigDialog::OnClose(wxCloseEvent& event)
{
if (m_UpdatePadTimer)
m_UpdatePadTimer->Stop();
if (m_ButtonMappingTimer)
m_ButtonMappingTimer->Stop();
g_Config.CurrentPage = m_Page;
EndModal(wxID_CLOSE);
}
void WiimotePadConfigDialog::CloseClick(wxCommandEvent& event)
{
switch(event.GetId())
{
case ID_CLOSE:
Close();
break;
case ID_APPLY:
break;
}
}
// Save keyboard key mapping
void WiimotePadConfigDialog::SaveButtonMapping(int Id, int Key)
{
@@ -247,28 +279,18 @@ void WiimotePadConfigDialog::OnButtonClick(wxCommandEvent& event)
DoGetButtons(ClickedButton->GetId());
}
void WiimotePadConfigDialog::OnClose(wxCloseEvent& event)
void WiimotePadConfigDialog::OnAxisClick(wxCommandEvent& event)
{
if (m_UpdatePadTimer)
m_UpdatePadTimer->Stop();
if (m_ButtonMappingTimer)
m_ButtonMappingTimer->Stop();
event.Skip();
g_Config.CurrentPage = m_Page;
if (m_ButtonMappingTimer->IsRunning()) return;
EndModal(wxID_CLOSE);
}
void WiimotePadConfigDialog::CloseClick(wxCommandEvent& event)
{
switch(event.GetId())
{
case ID_CLOSE:
Close();
break;
case ID_APPLY:
break;
}
ClickedButton = NULL;
wxButton* pButton = (wxButton *)event.GetEventObject();
OldLabel = pButton->GetLabel();
pButton->SetWindowStyle(wxWANTS_CHARS);
pButton->SetLabel(wxT("<Move Axis>"));
DoGetButtons(pButton->GetId());
}
// Bitmap box and dot
@@ -354,11 +376,8 @@ void WiimotePadConfigDialog::CreatePadGUIControls()
TextDeadZone.Add(wxString::Format(wxT("%i%%"), i));
wxArrayString StrDiagonal;
StrDiagonal.Add(wxT("100%"));
StrDiagonal.Add(wxT("95%"));
StrDiagonal.Add(wxT("90%"));
StrDiagonal.Add(wxT("85%"));
StrDiagonal.Add(wxT("80%"));
for (int i = 0; i <= 10; i++)
StrDiagonal.Add(wxString::Format(wxT("%i%%"), 100 - i * 5));
wxArrayString StrRumble;
for (int i = 0; i <= 10; i++)
@@ -929,18 +948,7 @@ void WiimotePadConfigDialog::CreatePadGUIControls()
Center();
#endif
ControlsCreated = true;
}
// Notebook page changed
void WiimotePadConfigDialog::NotebookPageChanged(wxNotebookEvent& event)
{
// Update the global variable
m_Page = event.GetSelection();
// Update GUI
if (ControlsCreated)
UpdateGUI();
m_ControlsCreated = true;
}
void WiimotePadConfigDialog::GeneralSettingsChanged(wxCommandEvent& event)
@@ -961,7 +969,7 @@ void WiimotePadConfigDialog::GeneralSettingsChanged(wxCommandEvent& event)
WiiMoteEmu::WiiMapping[m_Page].DeadZoneR = m_ComboDeadZoneRight[m_Page]->GetSelection();
break;
case IDC_STICK_DIAGONAL:
WiiMoteEmu::WiiMapping[m_Page].Diagonal = m_ComboDiagonal[m_Page]->GetLabel().mb_str();
WiiMoteEmu::WiiMapping[m_Page].Diagonal = 100 - m_ComboDiagonal[m_Page]->GetSelection() * 5;
break;
case IDC_STICK_C2S:
WiiMoteEmu::WiiMapping[m_Page].bCircle2Square = m_CheckC2S[m_Page]->IsChecked();
@@ -1022,7 +1030,7 @@ void WiimotePadConfigDialog::GeneralSettingsChanged(wxCommandEvent& event)
void WiimotePadConfigDialog::UpdateGUI()
{
if(!ControlsCreated)
if(!m_ControlsCreated)
return;
// Disable all pad items if no pads are detected
@@ -1044,7 +1052,7 @@ void WiimotePadConfigDialog::UpdateGUI()
m_Joyname[m_Page]->SetSelection(WiiMoteEmu::WiiMapping[m_Page].ID);
m_ComboDeadZoneLeft[m_Page]->SetSelection(WiiMoteEmu::WiiMapping[m_Page].DeadZoneL);
m_ComboDeadZoneRight[m_Page]->SetSelection(WiiMoteEmu::WiiMapping[m_Page].DeadZoneR);
m_ComboDiagonal[m_Page]->SetValue(wxString::FromAscii(WiiMoteEmu::WiiMapping[m_Page].Diagonal.c_str()));
m_ComboDiagonal[m_Page]->SetSelection((100 - WiiMoteEmu::WiiMapping[m_Page].Diagonal) / 5);
m_CheckC2S[m_Page]->SetValue(WiiMoteEmu::WiiMapping[m_Page].bCircle2Square);
m_CheckRumble[m_Page]->SetValue(WiiMoteEmu::WiiMapping[m_Page].Rumble);
m_RumbleStrength[m_Page]->SetSelection(WiiMoteEmu::WiiMapping[m_Page].RumbleStrength);
@@ -146,7 +146,7 @@ class WiimotePadConfigDialog : public wxDialog
IDC_GH3_ANALOG,
};
bool ControlsCreated;
bool m_ControlsCreated;
int m_Page, BoxW, BoxH;
wxString OldLabel;
@@ -281,13 +281,14 @@ class WiimotePadConfigDialog : public wxDialog
void OnButtonTimer(wxTimerEvent& WXUNUSED(event)) { DoGetButtons(GetButtonWaitingID); }
void OnKeyDown(wxKeyEvent& event);
void OnButtonClick(wxCommandEvent& event);
void OnAxisClick(wxCommandEvent& event);
void GeneralSettingsChanged(wxCommandEvent& event);
void SaveButtonMapping(int Id, int Key);
// Gamepad configuration
void SetButtonText(int id,const wxString &str);
wxString GetButtonText(int id);
void GetButtons(wxCommandEvent& btn_event);
void DoGetButtons(int id);
void UpdatePadInfo(wxTimerEvent& WXUNUSED(event));
void ToBlank(bool ToBlank, int Id);
@@ -282,7 +282,7 @@ struct CONTROLLER_MAPPING_WII // WII PAD MAPPING
int DeadZoneL; // Analog 1 Deadzone
int DeadZoneR; // Analog 2 Deadzone
bool bCircle2Square;
std::string Diagonal;
int Diagonal;
int Source; // 0: inactive, 1: emu, 2: real
bool bSideways;
@@ -665,7 +665,8 @@ void ReadLinuxKeyboard()
if ((key >= XK_F1 && key <= XK_F9) ||
key == XK_Shift_L || key == XK_Shift_R ||
key == XK_Control_L || key == XK_Control_R) {
key == XK_Control_L || key == XK_Control_R)
{
XPutBackEvent(WMdisplay, &E);
break;
}
+5 -7
View File
@@ -80,14 +80,12 @@ bool Search_Devices(std::vector<InputCommon::CONTROLLER_INFO> &_joyinfo, int &_N
bool WasGotten = InputCommon::SearchDevices(_joyinfo, _NumPads, _NumGoodPads);
// Warn the user if no gamepads are detected
if (_NumGoodPads == 0)
return false;
// Update the PadState[].joy handle
for (int i = 0; i < MAX_WIIMOTES; i++)
{
if (_NumPads > (u32)WiiMapping[i].ID)
if (_NumPads > WiiMapping[i].ID)
if(_joyinfo.at(WiiMapping[i].ID).Good)
WiiMapping[i].joy = _joyinfo.at(WiiMapping[i].ID).joy;
}
@@ -127,8 +125,8 @@ void GetAxisState(CONTROLLER_MAPPING_WII &_WiiMapping)
}
else
{
_WiiMapping.AxisState.Tl = XInput::GetXI(0, _WiiMapping.AxisMapping.Tl - 1000);
_WiiMapping.AxisState.Tr = XInput::GetXI(0, _WiiMapping.AxisMapping.Tr - 1000);
_WiiMapping.AxisState.Tl = XInput::GetXI(_WiiMapping.ID, _WiiMapping.AxisMapping.Tl - 1000);
_WiiMapping.AxisState.Tr = XInput::GetXI(_WiiMapping.ID, _WiiMapping.AxisMapping.Tr - 1000);
}
#endif
@@ -168,8 +166,8 @@ void UpdatePadState(CONTROLLER_MAPPING_WII &_WiiMapping)
// Check the circle to square option
if(_WiiMapping.bCircle2Square)
{
InputCommon::Square2Circle(Lx, Ly, 0, _WiiMapping.Diagonal, true);
InputCommon::Square2Circle(Rx, Ry, 0, _WiiMapping.Diagonal, true);
InputCommon::Square2Circle(Lx, Ly, _WiiMapping.Diagonal, true);
InputCommon::Square2Circle(Rx, Ry, _WiiMapping.Diagonal, true);
}
// Dead zone adjustment
@@ -68,8 +68,7 @@ void HidOutputReport(u16 _channelID, wm_report* sr)
switch(sr->wm)
{
case WM_RUMBLE: // 0x10
if (WiiMapping[g_ID].Rumble && WiiMapping[g_ID].ID < NumGoodPads)
PAD_Rumble(g_ID, sr->data[0]);
PAD_Rumble(g_ID, sr->data[0]);
break;
case WM_LEDS: // 0x11
+24 -40
View File
@@ -1,35 +1,22 @@
// Project description
// -------------------
// Name: nJoy
// Description: A Dolphin Compatible Input Plugin
//
// Author: Falcon4ever ([email protected])
// Site: www.multigesture.net
// Copyright (C) 2003 Dolphin Project.
//
//
// Licensetype: GNU General Public License (GPL)
//
// 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, version 2.0.
//
// 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 2.0 for more details.
//
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
//
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
//
// Include
// ---------
#include "../../../Core/InputCommon/Src/SDL.h" // Core
#include "EmuDefinitions.h"
@@ -80,19 +67,16 @@ RUMBLE pRumble[MAX_WIIMOTES];
void Pad_Use_Rumble(u8 _numPAD)
{
if (WiiMapping[_numPAD].Rumble)
if (!g_Rumble)
{
if (!g_Rumble)
{
// GetForegroundWindow() always sends the good HWND
if (FAILED(InitRumble(GetForegroundWindow())))
PanicAlert("Could not initialize Rumble!");
} else
{
// Acquire gamepad
if (pRumble[_numPAD].g_pDevice != NULL)
pRumble[_numPAD].g_pDevice->Acquire();
}
// GetForegroundWindow() always sends the good HWND
if (FAILED(InitRumble(GetForegroundWindow())))
PanicAlert("Could not initialize Rumble!");
} else
{
// Acquire gamepad
if (pRumble[_numPAD].g_pDevice != NULL)
pRumble[_numPAD].g_pDevice->Acquire();
}
}
@@ -102,23 +86,23 @@ void Pad_Use_Rumble(u8 _numPAD)
void PAD_Rumble(u8 _numPAD, unsigned int _uType)
{
if (WiiMapping[_numPAD].ID >= NumPads || !WiiMapping[_numPAD].Rumble)
return;
Pad_Use_Rumble(_numPAD);
int Strenght = 0;
if (WiiMapping[_numPAD].Rumble) // rumble activated
if (_uType == 1)
{
if (_uType == 1)
{
// it looks like _uStrength is equal to 3 everytime anyway...
Strenght = 1000 * (WiiMapping[_numPAD].RumbleStrength);
Strenght = Strenght > 10000 ? 10000 : Strenght;
}
else
Strenght = 0;
SetDeviceForcesXY(_numPAD, Strenght);
// it looks like _uStrength is equal to 3 everytime anyway...
Strenght = 1000 * (WiiMapping[_numPAD].RumbleStrength);
Strenght = Strenght > 10000 ? 10000 : Strenght;
}
else
Strenght = 0;
SetDeviceForcesXY(_numPAD, Strenght);
}
// Rumble stuff :D!