diff --git a/Source/Plugins/Plugin_GCPadNew/Src/ConfigDiag.cpp b/Source/Plugins/Plugin_GCPadNew/Src/ConfigDiag.cpp index 7b6b661310..b7356d3631 100644 --- a/Source/Plugins/Plugin_GCPadNew/Src/ConfigDiag.cpp +++ b/Source/Plugins/Plugin_GCPadNew/Src/ConfigDiag.cpp @@ -1,9 +1,27 @@ #include "ConfigDiag.h" -SettingCBox::SettingCBox( wxWindow* const parent, ControlState& _value, int min, int max ) +PadSettingCheckBox::PadSettingCheckBox( wxWindow* const parent, ControlState& _value, const char* const label ) + : wxCheckBox( parent, -1, wxString::FromAscii( label ), wxDefaultPosition ) + , PadSetting(_value) +{ + UpdateGUI(); +} + +void PadSettingCheckBox::UpdateGUI() +{ + SetValue( value > 0 ); +} + +void PadSettingCheckBox::UpdateValue() +{ + // 0.01 so its saved to the ini file as just 1. :( + value = 0.01 * GetValue(); +} + +PadSettingChoice::PadSettingChoice( wxWindow* const parent, ControlState& _value, int min, int max ) : wxChoice( parent, -1, wxDefaultPosition, wxSize( 48, -1 ) ) - , value(_value) + , PadSetting(_value) { Append( wxT("0") ); for ( ; min<=max; ++min ) @@ -13,10 +31,19 @@ SettingCBox::SettingCBox( wxWindow* const parent, ControlState& _value, int min, Append( wxString::FromAscii( ss.str().c_str() ) ); } + UpdateGUI(); +} + +void PadSettingChoice::UpdateGUI() +{ std::ostringstream ss; ss << int(value * 100); SetSelection( FindString( wxString::FromAscii( ss.str().c_str() ) ) ); +} +void PadSettingChoice::UpdateValue() +{ + value = float( atoi( GetStringSelection().mb_str() ) ) / 100; } ControlDialog::ControlDialog( wxWindow* const parent, ControllerInterface::ControlReference* const ref, const std::vector& devs ) @@ -160,25 +187,24 @@ void GamepadPage::UpdateGUI() { device_cbox->SetLabel( wxString::FromAscii( controller->default_device.ToString().c_str() ) ); - std::vector< ControlGroupBox* >::const_iterator g = control_groups.begin(), + std::vector< ControlGroupBox* >::const_iterator + g = control_groups.begin(), ge = control_groups.end(); for ( ; g!=ge; ++g ) { // buttons - std::vector::const_iterator i = (*g)->control_buttons.begin() - , e = (*g)->control_buttons.end(); + std::vector::const_iterator + i = (*g)->control_buttons.begin(), + e = (*g)->control_buttons.end(); for ( ; i!=e; ++i ) (*i)->SetLabel( wxString::FromAscii( (*i)->control_reference->control_qualifier.name.c_str() ) ); - // cboxes - std::vector::const_iterator si = (*g)->options.begin() - , se = (*g)->options.end(); + // settings + std::vector::const_iterator + si = (*g)->options.begin(), + se = (*g)->options.end(); for ( ; si!=se; ++si ) - { - std::ostringstream ss; - ss << int((*si)->value * 100); - (*si)->SetSelection( (*si)->FindString( wxString::FromAscii( ss.str().c_str() ) ) ); - } + (*si)->UpdateGUI(); } } @@ -261,8 +287,8 @@ void GamepadPage::AdjustSetting( wxCommandEvent& event ) { m_plugin.controls_crit.Enter(); // enter - float setting = atoi( ((SettingCBox*)event.GetEventObject())->GetStringSelection().mb_str() ); - ((SettingCBox*)event.GetEventObject())->value = setting / 100; + // updates the setting value from the GUI control + (dynamic_cast(event.GetEventObject()))->UpdateValue(); m_plugin.controls_crit.Leave(); // leave } @@ -572,8 +598,8 @@ ControlGroupBox::ControlGroupBox( ControllerEmu::ControlGroup* const group, wxWi static_bitmap = new wxStaticBitmap( parent, -1, bitmap, wxDefaultPosition, wxDefaultSize, wxBITMAP_TYPE_BMP ); - SettingCBox* deadzone_cbox = new SettingCBox( parent, group->settings[0]->value, 1, 50 ); - SettingCBox* diagonal_cbox = new SettingCBox( parent, group->settings[1]->value, 1, 100 ); + PadSettingChoice* deadzone_cbox = new PadSettingChoice( parent, group->settings[0]->value, 1, 50 ); + PadSettingChoice* diagonal_cbox = new PadSettingChoice( parent, group->settings[1]->value, 1, 100 ); deadzone_cbox->Connect( wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( GamepadPage::AdjustSetting ), (wxObject*)0, (wxEvtHandler*)parent ); diagonal_cbox->Connect( wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( GamepadPage::AdjustSetting ), (wxObject*)0, (wxEvtHandler*)parent ); @@ -603,7 +629,7 @@ ControlGroupBox::ControlGroupBox( ControllerEmu::ControlGroup* const group, wxWi dc.SelectObject(wxNullBitmap); static_bitmap = new wxStaticBitmap( parent, -1, bitmap, wxDefaultPosition, wxDefaultSize, wxBITMAP_TYPE_BMP ); - SettingCBox* threshold_cbox = new SettingCBox( parent, group->settings[0]->value, 1, 99 ); + PadSettingChoice* threshold_cbox = new PadSettingChoice( parent, group->settings[0]->value, 1, 99 ); threshold_cbox->Connect( wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( GamepadPage::AdjustSetting ), (wxObject*)0, (wxEvtHandler*)parent ); options.push_back( threshold_cbox ); @@ -625,7 +651,7 @@ ControlGroupBox::ControlGroupBox( ControllerEmu::ControlGroup* const group, wxWi dc.SelectObject(wxNullBitmap); static_bitmap = new wxStaticBitmap( parent, -1, bitmap, wxDefaultPosition, wxDefaultSize, wxBITMAP_TYPE_BMP ); - SettingCBox* threshold_cbox = new SettingCBox( parent, group->settings[0]->value, 1, 99 ); + PadSettingChoice* threshold_cbox = new PadSettingChoice( parent, group->settings[0]->value, 1, 99 ); threshold_cbox->Connect( wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( GamepadPage::AdjustSetting ), (wxObject*)0, (wxEvtHandler*)parent ); options.push_back( threshold_cbox ); @@ -639,6 +665,20 @@ ControlGroupBox::ControlGroupBox( ControllerEmu::ControlGroup* const group, wxWi } break; default : + { + std::vector::const_iterator + i = group->settings.begin(), + e = group->settings.end(); + for ( ; i!=e; ++i ) + { + PadSettingCheckBox* setting_cbox = new PadSettingCheckBox( parent, (*i)->value, (*i)->name ); + setting_cbox->Connect( wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( GamepadPage::AdjustSetting ), (wxObject*)0, (wxEvtHandler*)parent ); + options.push_back( setting_cbox ); + + Add( setting_cbox, 0, wxALL|wxCENTER, 5 ); + + } + } break; } @@ -660,16 +700,16 @@ GamepadPage::GamepadPage( wxWindow* parent, Plugin& plugin, const unsigned int p { ControlGroupBox* control_group = new ControlGroupBox( m_plugin.controllers[pad_num]->groups[i], this ); - if ( control_group->control_buttons.size() > 3 ) + if ( control_group->control_buttons.size() > 2 ) { if ( stacked_groups ) control_group_sizer->Add( stacked_groups, 0, /*wxEXPAND|*/wxBOTTOM|wxRIGHT, 5 ); stacked_groups = new wxBoxSizer( wxVERTICAL ); - stacked_groups->Add( control_group, 1 ); + stacked_groups->Add( control_group, 0, wxEXPAND ); } else - stacked_groups->Add( control_group ); + stacked_groups->Add( control_group, 0, wxEXPAND ); control_groups.push_back( control_group ); } diff --git a/Source/Plugins/Plugin_GCPadNew/Src/ConfigDiag.h b/Source/Plugins/Plugin_GCPadNew/Src/ConfigDiag.h index 2ddfbbd4d5..48002f493b 100644 --- a/Source/Plugins/Plugin_GCPadNew/Src/ConfigDiag.h +++ b/Source/Plugins/Plugin_GCPadNew/Src/ConfigDiag.h @@ -25,14 +25,35 @@ #include "Config.h" #include "FileSearch.h" -class SettingCBox : public wxChoice +class PadSetting { +protected: + PadSetting( ControlState& _value ) : value(_value) {} + public: - SettingCBox( wxWindow* const parent, ControlState& _value, int min, int max ); + virtual void UpdateGUI() = 0; + virtual void UpdateValue() = 0; ControlState& value; }; +class PadSettingChoice : public PadSetting, public wxChoice +{ +public: + PadSettingChoice( wxWindow* const parent, ControlState& _value, int min, int max ); + void UpdateGUI(); + void UpdateValue(); +}; + +class PadSettingCheckBox : public PadSetting, public wxCheckBox +{ +public: + PadSettingCheckBox( wxWindow* const parent, ControlState& _value, const char* const label ); + void UpdateGUI(); + void UpdateValue(); +}; + + class ControlChooser : public wxStaticBoxSizer { public: @@ -87,7 +108,7 @@ public: ControllerEmu::ControlGroup* control_group; wxStaticBitmap* static_bitmap; - std::vector< SettingCBox* > options; + std::vector< PadSetting* > options; std::vector< wxButton* > controls; std::vector control_buttons; }; diff --git a/Source/Plugins/Plugin_GCPadNew/Src/ConfigDiagBitmaps.cpp b/Source/Plugins/Plugin_GCPadNew/Src/ConfigDiagBitmaps.cpp index 970147bdca..476f2e4e75 100644 --- a/Source/Plugins/Plugin_GCPadNew/Src/ConfigDiagBitmaps.cpp +++ b/Source/Plugins/Plugin_GCPadNew/Src/ConfigDiagBitmaps.cpp @@ -18,7 +18,8 @@ void ConfigDialog::UpdateBitmaps(wxTimerEvent& WXUNUSED(event)) if ( false == m_plugin.interface_crit.TryEnter() ) return; - if ( false == is_game_running ) + //if ( false == is_game_running ) + // just always update m_plugin.controller_interface.UpdateInput(); switch ( (*g)->control_group->type ) diff --git a/Source/Plugins/Plugin_GCPadNew/Src/ControllerEmu.h b/Source/Plugins/Plugin_GCPadNew/Src/ControllerEmu.h index c0de3046f7..24e758d24b 100644 --- a/Source/Plugins/Plugin_GCPadNew/Src/ControllerEmu.h +++ b/Source/Plugins/Plugin_GCPadNew/Src/ControllerEmu.h @@ -215,6 +215,7 @@ public: std::vector< ControlGroup* > groups; + ControlGroup* options; ControllerInterface::DeviceQualifier default_device; diff --git a/Source/Plugins/Plugin_GCPadNew/Src/ControllerEmu/GCPad/GCPad.cpp b/Source/Plugins/Plugin_GCPadNew/Src/ControllerEmu/GCPad/GCPad.cpp index e32dfb2680..d2a50499b2 100644 --- a/Source/Plugins/Plugin_GCPadNew/Src/ControllerEmu/GCPad/GCPad.cpp +++ b/Source/Plugins/Plugin_GCPadNew/Src/ControllerEmu/GCPad/GCPad.cpp @@ -55,14 +55,18 @@ GCPad::GCPad( const unsigned int index ) : m_index(index) for ( unsigned int i=0; i < sizeof(named_triggers)/sizeof(*named_triggers); ++i ) m_triggers->controls.push_back( new ControlGroup::Input( named_triggers[i] ) ); + // rumble + groups.push_back( m_rumble = new ControlGroup( "Rumble" ) ); + m_rumble->controls.push_back( new ControlGroup::Output( "Motor" ) ); + // dpad groups.push_back( m_dpad = new Buttons( "D-Pad" ) ); for ( unsigned int i=0; i < 4; ++i ) m_dpad->controls.push_back( new ControlGroup::Input( named_directions[i] ) ); - // rumble - groups.push_back( m_rumble = new ControlGroup( "Rumble" ) ); - m_rumble->controls.push_back( new ControlGroup::Output( "Motor" ) ); + // options + groups.push_back( options = new ControlGroup( "Options" ) ); + options->settings.push_back( new ControlGroup::Setting( "Background Input", false ) ); } diff --git a/Source/Plugins/Plugin_GCPadNew/Src/ControllerInterface/DirectInput/DirectInputJoystick.cpp b/Source/Plugins/Plugin_GCPadNew/Src/ControllerInterface/DirectInput/DirectInputJoystick.cpp index 3e129132ba..5fd209b7c2 100644 --- a/Source/Plugins/Plugin_GCPadNew/Src/ControllerInterface/DirectInput/DirectInputJoystick.cpp +++ b/Source/Plugins/Plugin_GCPadNew/Src/ControllerInterface/DirectInput/DirectInputJoystick.cpp @@ -217,7 +217,7 @@ Joystick::Joystick( /*const LPCDIDEVICEINSTANCE lpddi, */const LPDIRECTINPUTDEVI js_caps.dwButtons = std::min((DWORD)32, js_caps.dwButtons); js_caps.dwPOVs = std::min((DWORD)4, js_caps.dwPOVs); - m_must_poll = (bool)( js_caps.dwFlags & DIDC_POLLEDDATAFORMAT ); + m_must_poll = ( ( js_caps.dwFlags & DIDC_POLLEDDATAFORMAT ) > 0 ); // buttons for ( unsigned int i = 0; i < js_caps.dwButtons; ++i ) @@ -387,7 +387,7 @@ bool Joystick::UpdateInput() HRESULT hr = m_device->GetDeviceState( sizeof(m_state_in), &m_state_in ); // try reacquire if input lost - while ( DIERR_INPUTLOST == hr ) + if ( DIERR_INPUTLOST == hr ) hr = m_device->Acquire(); return ( DI_OK == hr ); diff --git a/Source/Plugins/Plugin_GCPadNew/Src/ControllerInterface/DirectInput/DirectInputKeyboardMouse.cpp b/Source/Plugins/Plugin_GCPadNew/Src/ControllerInterface/DirectInput/DirectInputKeyboardMouse.cpp index 9767f3c94e..6f79af95e3 100644 --- a/Source/Plugins/Plugin_GCPadNew/Src/ControllerInterface/DirectInput/DirectInputKeyboardMouse.cpp +++ b/Source/Plugins/Plugin_GCPadNew/Src/ControllerInterface/DirectInput/DirectInputKeyboardMouse.cpp @@ -189,8 +189,11 @@ bool KeyboardMouse::UpdateOutput() m_current_state_out[i] ^= 1; } } - - return ( kbinputs.size() == SendInput( (UINT)kbinputs.size(), &kbinputs[0], sizeof( kbinputs[0] ) ) ); + + if ( kbinputs.size() ) + return ( kbinputs.size() == SendInput( (UINT)kbinputs.size(), &kbinputs[0], sizeof( kbinputs[0] ) ) ); + else + return true; } std::string KeyboardMouse::GetName() const diff --git a/Source/Plugins/Plugin_GCPadNew/Src/GCPadNew.cpp b/Source/Plugins/Plugin_GCPadNew/Src/GCPadNew.cpp index a80fecf980..1aff348da6 100644 --- a/Source/Plugins/Plugin_GCPadNew/Src/GCPadNew.cpp +++ b/Source/Plugins/Plugin_GCPadNew/Src/GCPadNew.cpp @@ -15,14 +15,18 @@ Display* GCdisplay; #endif -#define CIFACE_PLUGIN_VERSION 0x0100 +#define PLUGIN_VERSION 0x0100 -#define CIFACE_PLUGIN_BRANDING /*"Billiard's"//*/"Dolphin" -#define CIFACE_PLUGIN_TYPE "GCPad" -#define CIFACE_PLUGIN_NAME "New" -//#define CIFACE_PLUGIN_VERSTR "v1.0" +#ifdef DEBUGFAST +#define PLUGIN_FULL_NAME "Dolphin GCPad New (DebugFast)" +#else +#ifdef _DEBUG +#define PLUGIN_FULL_NAME "Dolphin GCPad New (Debug)" +#else +#define PLUGIN_FULL_NAME "Dolphin GCPad New" +#endif +#endif -#define CIFACE_PLUGIN_FULL_NAME CIFACE_PLUGIN_BRANDING" "CIFACE_PLUGIN_TYPE" "CIFACE_PLUGIN_NAME//" "CIFACE_PLUGIN_VERSTR #ifdef _WIN32 class wxDLLApp : public wxApp @@ -160,16 +164,6 @@ EXPORT void CALL PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus) // wtf is this? _pPADStatus->button |= PAD_USE_ORIGIN; - // TODO: this will need changing - // need focus ? - // i'm not inside CritSec when I access this bool - //if ( false == (g_plugin.pads[_numPAD].options.allow_background_input || IsFocus()) ) - //{ - // // center axes and return - // memset( &_pPADStatus->stickX, 0x80, 4 ); - // return; - //} - // try lock if ( false == g_plugin.controls_crit.TryEnter() ) { @@ -189,8 +183,17 @@ EXPORT void CALL PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus) } _last_numPAD = _numPAD; - // get input - ((GCPad*)g_plugin.controllers[ _numPAD ])->GetInput( _pPADStatus ); + // if we want background input or have focus + if ( g_plugin.controllers[_numPAD]->options[0].settings[0]->value || IsFocus() ) + // get input + ((GCPad*)g_plugin.controllers[ _numPAD ])->GetInput( _pPADStatus ); + else + { + // center sticks + memset( &_pPADStatus->stickX, 0x80, 4 ); + // stop rumble + ((GCPad*)g_plugin.controllers[ _numPAD ])->SetOutput( false ); + } // leave g_plugin.controls_crit.Leave(); @@ -219,8 +222,9 @@ EXPORT void CALL PAD_Rumble(u8 _numPAD, unsigned int _uType, unsigned int _uStre // enter if ( g_plugin.controls_crit.TryEnter() ) { - // only on/off rumble - ((GCPad*)g_plugin.controllers[ _numPAD ])->SetOutput( 1 == _uType && _uStrength > 2 ); + // only on/off rumble, if we have focus or background input on + if ( g_plugin.controllers[_numPAD]->options[0].settings[0]->value || IsFocus() ) + ((GCPad*)g_plugin.controllers[ _numPAD ])->SetOutput( 1 == _uType && _uStrength > 2 ); // leave g_plugin.controls_crit.Leave(); @@ -241,9 +245,9 @@ EXPORT void CALL GetDllInfo(PLUGIN_INFO* _pPluginInfo) // don't feel like messing around with all those strcpy functions and warnings //char *s1 = CIFACE_PLUGIN_FULL_NAME, *s2 = _pPluginInfo->Name; //while ( *s2++ = *s1++ ); - memcpy( _pPluginInfo->Name, CIFACE_PLUGIN_FULL_NAME, sizeof(CIFACE_PLUGIN_FULL_NAME) ); + memcpy( _pPluginInfo->Name, PLUGIN_FULL_NAME, sizeof(PLUGIN_FULL_NAME) ); _pPluginInfo->Type = PLUGIN_TYPE_PAD; - _pPluginInfo->Version = CIFACE_PLUGIN_VERSION; + _pPluginInfo->Version = PLUGIN_VERSION; } // ___________________________________________________________________________ @@ -264,7 +268,7 @@ EXPORT void CALL DllConfig(HWND _hParent) // copied from GCPad #if defined(HAVE_WX) && HAVE_WX wxWindow *frame = GetParentedWxWindow(_hParent); - ConfigDialog* m_ConfigFrame = new ConfigDialog( frame, g_plugin, CIFACE_PLUGIN_FULL_NAME, was_init ); + ConfigDialog* m_ConfigFrame = new ConfigDialog( frame, g_plugin, PLUGIN_FULL_NAME, was_init ); #ifdef _WIN32 frame->Disable();