GCPadNew: Added option to disable input when Dolphin window isn't active. Some other minor fixes/cleanups.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5290 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Jordan Woyak 2010-04-08 03:33:16 +00:00
parent eada74b74e
commit b0e8a67cf2
8 changed files with 130 additions and 56 deletions

View File

@ -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<ControllerInterface::Device*>& 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<ControlButton*>::const_iterator i = (*g)->control_buttons.begin()
, e = (*g)->control_buttons.end();
std::vector<ControlButton*>::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<SettingCBox*>::const_iterator si = (*g)->options.begin()
, se = (*g)->options.end();
// settings
std::vector<PadSetting*>::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<PadSetting*>(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<ControllerEmu::ControlGroup::Setting*>::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 );
}

View File

@ -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<ControlButton*> control_buttons;
};

View File

@ -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 )

View File

@ -215,6 +215,7 @@ public:
std::vector< ControlGroup* > groups;
ControlGroup* options;
ControllerInterface::DeviceQualifier default_device;

View File

@ -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 ) );
}

View File

@ -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 );

View File

@ -190,7 +190,10 @@ bool KeyboardMouse::UpdateOutput()
}
}
if ( kbinputs.size() )
return ( kbinputs.size() == SendInput( (UINT)kbinputs.size(), &kbinputs[0], sizeof( kbinputs[0] ) ) );
else
return true;
}
std::string KeyboardMouse::GetName() const

View File

@ -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;
// 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,7 +222,8 @@ EXPORT void CALL PAD_Rumble(u8 _numPAD, unsigned int _uType, unsigned int _uStre
// enter
if ( g_plugin.controls_crit.TryEnter() )
{
// only on/off rumble
// 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
@ -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();