summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorhrydgard <hrydgard@gmail.com>2010-06-12 17:39:33 +0000
committerhrydgard <hrydgard@gmail.com>2010-06-12 17:39:33 +0000
commit1cd25e2406ea370cacfb82ec6dc164153052ca9d (patch)
tree29c06c64c49841b89a83f614c77fb59bda4f6008 /Source/Core
parent3e3aa2364e4ed6c3fe3be9331b7d0827adf9042f (diff)
(cleanup) InputPluginCommon is dead. Long live InputCommon and InputUICommon.
I hope I didn't break the mac+linux builds - if i did, fixing it should be a simple matter of adjusting the sconscripts. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5661 8ced0084-cf51-0410-be5f-012b33b47a6e
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/InputCommon/InputCommon.vcproj18
-rw-r--r--Source/Core/InputCommon/Src/ControllerEmu.cpp375
-rw-r--r--Source/Core/InputCommon/Src/ControllerEmu.h438
-rw-r--r--Source/Core/InputCommon/Src/InputConfig.cpp69
-rw-r--r--Source/Core/InputCommon/Src/InputConfig.h53
-rw-r--r--Source/Core/InputCommon/Src/SConscript2
-rw-r--r--Source/Core/InputUICommon/InputUICommon.vcproj425
-rw-r--r--Source/Core/InputUICommon/Src/ConfigDiag.cpp957
-rw-r--r--Source/Core/InputUICommon/Src/ConfigDiag.h245
-rw-r--r--Source/Core/InputUICommon/Src/ConfigDiagBitmaps.cpp318
-rw-r--r--Source/Core/InputUICommon/Src/SConscript14
11 files changed, 2913 insertions, 1 deletions
diff --git a/Source/Core/InputCommon/InputCommon.vcproj b/Source/Core/InputCommon/InputCommon.vcproj
index c6a11789e0..92849a1c27 100644
--- a/Source/Core/InputCommon/InputCommon.vcproj
+++ b/Source/Core/InputCommon/InputCommon.vcproj
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
- Version="9.00"
+ Version="9,00"
Name="InputCommon"
ProjectGUID="{C7E5D50A-2916-464B-86A7-E10B3CC88ADA}"
RootNamespace="VideoCommon"
@@ -481,6 +481,14 @@
>
</File>
<File
+ RelativePath=".\Src\ControllerEmu.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\Src\ControllerEmu.h"
+ >
+ </File>
+ <File
RelativePath=".\Src\DirectInputBase.cpp"
>
</File>
@@ -509,6 +517,14 @@
>
</File>
<File
+ RelativePath=".\Src\InputConfig.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\Src\InputConfig.h"
+ >
+ </File>
+ <File
RelativePath=".\Src\SDL_Util.cpp"
>
</File>
diff --git a/Source/Core/InputCommon/Src/ControllerEmu.cpp b/Source/Core/InputCommon/Src/ControllerEmu.cpp
new file mode 100644
index 0000000000..d696a55c96
--- /dev/null
+++ b/Source/Core/InputCommon/Src/ControllerEmu.cpp
@@ -0,0 +1,375 @@
+// Copyright (C) 2010 Dolphin Project.
+
+// 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 "ControllerEmu.h"
+
+#if defined(HAVE_X11) && HAVE_X11
+#include <X11/Xlib.h>
+#endif
+
+ControllerEmu::~ControllerEmu()
+{
+ // control groups
+ std::vector<ControlGroup*>::const_iterator
+ i = groups.begin(),
+ e = groups.end();
+ for ( ; i!=e; ++i )
+ delete *i;
+}
+
+ControllerEmu::ControlGroup::~ControlGroup()
+{
+ // controls
+ std::vector<Control*>::const_iterator
+ ci = controls.begin(),
+ ce = controls.end();
+ for ( ; ci!=ce; ++ci )
+ delete *ci;
+
+ // settings
+ std::vector<Setting*>::const_iterator
+ si = settings.begin(),
+ se = settings.end();
+ for ( ; si!=se; ++si )
+ delete *si;
+}
+
+ControllerEmu::Extension::~Extension()
+{
+ // attachments
+ std::vector<ControllerEmu*>::const_iterator
+ ai = attachments.begin(),
+ ae = attachments.end();
+ for ( ; ai!=ae; ++ai )
+ delete *ai;
+}
+ControllerEmu::ControlGroup::Control::~Control()
+{
+ delete control_ref;
+}
+
+void ControllerEmu::UpdateReferences( ControllerInterface& devi )
+{
+ std::vector<ControlGroup*>::const_iterator
+ i = groups.begin(),
+ e = groups.end();
+ for ( ; i!=e; ++i )
+ {
+ std::vector<ControlGroup::Control*>::const_iterator
+ ci = (*i)->controls.begin(),
+ ce = (*i)->controls.end();
+ for ( ; ci!=ce; ++ci )
+ devi.UpdateReference( (*ci)->control_ref );
+
+ // extension
+ if ( GROUP_TYPE_EXTENSION == (*i)->type )
+ {
+ std::vector<ControllerEmu*>::const_iterator
+ ai = ((Extension*)*i)->attachments.begin(),
+ ae = ((Extension*)*i)->attachments.end();
+ for ( ; ai!=ae; ++ai )
+ (*ai)->UpdateReferences( devi );
+ }
+ }
+}
+
+void ControllerEmu::UpdateDefaultDevice()
+{
+ std::vector<ControlGroup*>::const_iterator
+ i = groups.begin(),
+ e = groups.end();
+ for ( ; i!=e; ++i )
+ {
+ std::vector<ControlGroup::Control*>::const_iterator
+ ci = (*i)->controls.begin(),
+ ce = (*i)->controls.end();
+ for ( ; ci!=ce; ++ci )
+ (*ci)->control_ref->device_qualifier = default_device;
+
+ // extension
+ if ( GROUP_TYPE_EXTENSION == (*i)->type )
+ {
+ std::vector<ControllerEmu*>::const_iterator
+ ai = ((Extension*)*i)->attachments.begin(),
+ ae = ((Extension*)*i)->attachments.end();
+ for ( ; ai!=ae; ++ai )
+ {
+ (*ai)->default_device = default_device;
+ (*ai)->UpdateDefaultDevice();
+ }
+ }
+ }
+}
+
+void ControllerEmu::ControlGroup::LoadConfig(IniFile::Section *sec, const std::string& defdev, const std::string& base )
+{
+ std::string group( base + name ); group += "/";
+
+ // settings
+ std::vector<ControlGroup::Setting*>::const_iterator
+ si = settings.begin(),
+ se = settings.end();
+ for ( ; si!=se; ++si )
+ {
+ sec->Get((group+(*si)->name).c_str(), &(*si)->value, (*si)->default_value*100);
+ (*si)->value /= 100;
+ }
+
+ // controls
+ std::vector<ControlGroup::Control*>::const_iterator
+ ci = controls.begin(),
+ ce = controls.end();
+ for ( ; ci!=ce; ++ci )
+ {
+ // control and dev qualifier
+ sec->Get((group + (*ci)->name).c_str(), &(*ci)->control_ref->control_qualifier.name, "");
+ std::string dev;
+ sec->Get((group+(*ci)->name+"/Device").c_str(), &dev, defdev.c_str());
+ (*ci)->control_ref->device_qualifier.FromString(dev);
+
+ // range
+ sec->Get( (group+(*ci)->name+"/Range").c_str(), &(*ci)->control_ref->range, 100.0f);
+ (*ci)->control_ref->range /= 100;
+
+ // input mode
+ if ( (*ci)->control_ref->is_input )
+ sec->Get( (group+(*ci)->name+"/Mode").c_str(), &((ControllerInterface::InputReference*)((*ci)->control_ref))->mode, 0 );
+ }
+
+ // extensions
+ if ( GROUP_TYPE_EXTENSION == type )
+ {
+ Extension* const ex = ((Extension*)this);
+
+ ex->switch_extension = 0;
+ unsigned int n = 0;
+ std::string extname;
+ sec->Get((base + name).c_str(), &extname, "");
+
+ std::vector<ControllerEmu*>::const_iterator
+ ai = ((Extension*)this)->attachments.begin(),
+ ae = ((Extension*)this)->attachments.end();
+ for ( ; ai!=ae; ++ai,++n )
+ {
+ (*ai)->default_device.FromString( defdev );
+ (*ai)->LoadConfig( sec, base + (*ai)->GetName() + "/" );
+
+ if ( (*ai)->GetName() == extname )
+ ex->switch_extension = n;
+ }
+ }
+}
+
+void ControllerEmu::LoadConfig( IniFile::Section *sec, const std::string& base )
+{
+ std::string defdev = default_device.ToString();
+ if (base.empty())
+ {
+ sec->Get((base + "Device").c_str(), &defdev, "");
+ default_device.FromString(defdev);
+ }
+ std::vector<ControlGroup*>::const_iterator i = groups.begin(),
+ e = groups.end();
+ for ( ; i!=e; ++i )
+ (*i)->LoadConfig(sec, defdev, base);
+}
+
+void ControllerEmu::ControlGroup::SaveConfig( IniFile::Section *sec, const std::string& defdev, const std::string& base )
+{
+ std::string group( base + name ); group += "/";
+
+ // settings
+ std::vector<ControlGroup::Setting*>::const_iterator
+ si = settings.begin(),
+ se = settings.end();
+ for ( ; si!=se; ++si )
+ sec->Set( (group+(*si)->name).c_str(), (*si)->value*100.0f, (*si)->default_value*100.0f);
+
+ // controls
+ std::vector<ControlGroup::Control*>::const_iterator
+ ci = controls.begin(),
+ ce = controls.end();
+ for ( ; ci!=ce; ++ci )
+ {
+ // control and dev qualifier
+ sec->Set( (group+(*ci)->name).c_str(), (*ci)->control_ref->control_qualifier.name, "");
+ sec->Set( (group+(*ci)->name+"/Device").c_str(), (*ci)->control_ref->device_qualifier.ToString(), defdev);
+
+ // range
+ sec->Set( (group+(*ci)->name+"/Range").c_str(), (*ci)->control_ref->range*100.0f, 100.0f);
+
+ // input mode
+ if ( (*ci)->control_ref->is_input )
+ {
+ const int mode = ((ControllerInterface::InputReference*)((*ci)->control_ref))->mode;
+ if (mode)
+ sec->Set((group+(*ci)->name+"/Mode").c_str(), mode);
+ else
+ sec->Delete((group+(*ci)->name+"/Mode").c_str());
+ }
+ }
+
+ // extensions
+ if ( GROUP_TYPE_EXTENSION == type )
+ {
+ Extension* const ext = ((Extension*)this);
+ sec->Set((base + name).c_str(), ext->attachments[ext->switch_extension]->GetName(), "None");
+
+ std::vector<ControllerEmu*>::const_iterator
+ ai = ((Extension*)this)->attachments.begin(),
+ ae = ((Extension*)this)->attachments.end();
+ for ( ; ai!=ae; ++ai )
+ (*ai)->SaveConfig( sec, base + (*ai)->GetName() + "/" );
+ }
+}
+
+void ControllerEmu::SaveConfig( IniFile::Section *sec, const std::string& base )
+{
+ const std::string defdev = default_device.ToString();
+ if ( base.empty() )
+ sec->Set( (/*std::string(" ") +*/ base + "Device").c_str(), defdev, "");
+
+ std::vector<ControlGroup*>::const_iterator i = groups.begin(),
+ e = groups.end();
+ for ( ; i!=e; ++i )
+ (*i)->SaveConfig( sec, defdev, base );
+}
+
+ControllerEmu::AnalogStick::AnalogStick( const char* const _name ) : ControlGroup( _name, GROUP_TYPE_STICK )
+{
+ for ( unsigned int i = 0; i < 4; ++i )
+ controls.push_back( new Input( named_directions[i] ) );
+
+ controls.push_back( new Input( "Modifier" ) );
+
+ settings.push_back( new Setting("Dead Zone", 0, 0, 50 ) );
+ settings.push_back( new Setting("Square Stick", 0 ) );
+
+}
+
+ControllerEmu::Buttons::Buttons( const char* const _name ) : ControlGroup( _name, GROUP_TYPE_BUTTONS )
+{
+ settings.push_back( new Setting("Threshold", 0.5f ) );
+}
+
+ControllerEmu::MixedTriggers::MixedTriggers( const char* const _name ) : ControlGroup( _name, GROUP_TYPE_MIXED_TRIGGERS )
+{
+ settings.push_back( new Setting("Threshold", 0.9f ) );
+}
+
+ControllerEmu::Triggers::Triggers( const char* const _name ) : ControlGroup( _name, GROUP_TYPE_TRIGGERS )
+{
+ settings.push_back( new Setting("Dead Zone", 0, 0, 50 ) );
+}
+
+ControllerEmu::Force::Force( const char* const _name ) : ControlGroup( _name, GROUP_TYPE_FORCE )
+{
+ controls.push_back( new Input( "Up" ) );
+ controls.push_back( new Input( "Down" ) );
+ controls.push_back( new Input( "Left" ) );
+ controls.push_back( new Input( "Right" ) );
+ controls.push_back( new Input( "Forward" ) );
+ controls.push_back( new Input( "Backward" ) );
+ controls.push_back( new Input( "Modifier" ) );
+
+ settings.push_back( new Setting("Dead Zone", 0, 0, 50 ) );
+}
+
+ControllerEmu::Tilt::Tilt( const char* const _name )
+ : ControlGroup( _name, GROUP_TYPE_TILT )
+{
+ memset(m_tilt, 0, sizeof(m_tilt));
+
+ //for ( unsigned int i = 0; i < 4; ++i )
+ //controls.push_back( new Input( named_directions[i] ) );
+ controls.push_back( new Input( "Forward" ) );
+ controls.push_back( new Input( "Backward" ) );
+ controls.push_back( new Input( "Left" ) );
+ controls.push_back( new Input( "Right" ) );
+
+ controls.push_back( new Input( "Modifier" ) );
+
+ settings.push_back( new Setting("Dead Zone", 0, 0, 50 ) );
+ settings.push_back( new Setting("Circle Stick", 0 ) );
+}
+
+ControllerEmu::Cursor::Cursor( const char* const _name, const SWiimoteInitialize* const _wiimote_initialize )
+ : ControlGroup( _name, GROUP_TYPE_CURSOR )
+ , wiimote_initialize(_wiimote_initialize)
+ , m_z(0)
+{
+ for ( unsigned int i = 0; i < 4; ++i )
+ controls.push_back( new Input( named_directions[i] ) );
+ controls.push_back( new Input( "Forward" ) );
+ controls.push_back( new Input( "Backward" ) );
+ controls.push_back( new Input( "Hide" ) );
+
+ settings.push_back( new Setting("Center", 0.5f ) );
+ settings.push_back( new Setting("Width", 0.5f ) );
+ settings.push_back( new Setting("Height", 0.5f ) );
+
+}
+
+void GetMousePos(float& x, float& y, const SWiimoteInitialize* const wiimote_initialize)
+{
+#if ( defined(_WIN32) || (defined(HAVE_X11) && HAVE_X11))
+ unsigned int win_width = 2, win_height = 2;
+#endif
+
+#ifdef _WIN32
+ // Get the cursor position for the entire screen
+ POINT point = { 1, 1 };
+ GetCursorPos(&point);
+ // Get the cursor position relative to the upper left corner of the rendering window
+ ScreenToClient(wiimote_initialize->hWnd, &point);
+
+ // Get the size of the rendering window. (In my case Rect.top and Rect.left was zero.)
+ RECT Rect;
+ GetClientRect(wiimote_initialize->hWnd, &Rect);
+ // Width and height is the size of the rendering window
+ win_width = Rect.right - Rect.left;
+ win_height = Rect.bottom - Rect.top;
+
+#elif defined(HAVE_X11) && HAVE_X11
+ int root_x, root_y;
+ struct
+ {
+ int x, y;
+ } point = { 1, 1 };
+
+ Display* const wm_display = (Display*)wiimote_initialize->hWnd;
+ Window glwin = *(Window *)wiimote_initialize->pXWindow;
+
+ XWindowAttributes win_attribs;
+ XGetWindowAttributes (wm_display, glwin, &win_attribs);
+ win_width = win_attribs.width;
+ win_height = win_attribs.height;
+ Window root_dummy, child_win;
+ unsigned int mask;
+ XQueryPointer(wm_display, glwin, &root_dummy, &child_win, &root_x, &root_y, &point.x, &point.y, &mask);
+#endif
+
+#if ( defined(_WIN32) || (defined(HAVE_X11) && HAVE_X11))
+ // Return the mouse position as a range from -1 to 1
+ x = (float)point.x / (float)win_width * 2 - 1;
+ y = (float)point.y / (float)win_height * 2 - 1;
+#else
+ x = 0;
+ y = 0;
+#endif
+
+}
diff --git a/Source/Core/InputCommon/Src/ControllerEmu.h b/Source/Core/InputCommon/Src/ControllerEmu.h
new file mode 100644
index 0000000000..90170c21cd
--- /dev/null
+++ b/Source/Core/InputCommon/Src/ControllerEmu.h
@@ -0,0 +1,438 @@
+// Copyright (C) 2010 Dolphin Project.
+
+// 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/
+
+#ifndef _CONTROLLEREMU_H_
+#define _CONTROLLEREMU_H_
+
+// windows crap
+#define NOMINMAX
+
+#include "pluginspecs_pad.h"
+#include "pluginspecs_wiimote.h"
+#include <math.h>
+
+#include "ControllerInterface/ControllerInterface.h"
+#include "IniFile.h"
+
+#include <vector>
+#include <string>
+#include <algorithm>
+
+#define sign(x) ((x)?(x)<0?-1:1:0)
+
+enum
+{
+ GROUP_TYPE_OTHER,
+ GROUP_TYPE_STICK,
+ GROUP_TYPE_MIXED_TRIGGERS,
+ GROUP_TYPE_BUTTONS,
+ GROUP_TYPE_FORCE,
+ GROUP_TYPE_EXTENSION,
+ GROUP_TYPE_TILT,
+ GROUP_TYPE_CURSOR,
+ GROUP_TYPE_TRIGGERS,
+};
+
+const char * const named_directions[] =
+{
+ "Up",
+ "Down",
+ "Left",
+ "Right"
+};
+
+void GetMousePos(float& x, float& y, const SWiimoteInitialize* const wiimote_initialize);
+
+class ControllerEmu
+{
+public:
+
+ class ControlGroup
+ {
+ public:
+
+ class Control
+ {
+ protected:
+ Control( ControllerInterface::ControlReference* const _ref, const char * const _name )
+ : control_ref(_ref), name(_name){}
+ public:
+
+ virtual ~Control();
+ ControllerInterface::ControlReference* const control_ref;
+ const char * const name;
+
+ };
+
+ class Input : public Control
+ {
+ public:
+
+ Input( const char * const _name )
+ : Control( new ControllerInterface::InputReference, _name ) {}
+
+ };
+
+ class Output : public Control
+ {
+ public:
+
+ Output( const char * const _name )
+ : Control( new ControllerInterface::OutputReference, _name ) {}
+
+ };
+
+ class Setting
+ {
+ public:
+
+ Setting(const char* const _name, const ControlState def_value
+ , const unsigned int _low = 0, const unsigned int _high = 100 )
+ : name(_name)
+ , value(def_value)
+ , default_value(def_value)
+ , low(_low)
+ , high(_high){}
+
+ const char* const name;
+ ControlState value;
+ const ControlState default_value;
+ const unsigned int low, high;
+ };
+
+ ControlGroup( const char* const _name, const unsigned int _type = GROUP_TYPE_OTHER ) : name(_name), type(_type) {}
+ virtual ~ControlGroup();
+
+ void LoadConfig(IniFile::Section *sec, const std::string& defdev = "", const std::string& base = "" );
+ void SaveConfig(IniFile::Section *sec, const std::string& defdev = "", const std::string& base = "" );
+
+ const char* const name;
+ const unsigned int type;
+
+ std::vector< Control* > controls;
+ std::vector< Setting* > settings;
+
+ };
+
+ class AnalogStick : public ControlGroup
+ {
+ public:
+
+ template <typename C>
+ void GetState( C* const x, C* const y, const unsigned int base, const unsigned int range )
+ {
+ // this is all a mess
+
+ ControlState yy = controls[0]->control_ref->State() - controls[1]->control_ref->State();
+ ControlState xx = controls[3]->control_ref->State() - controls[2]->control_ref->State();
+
+ ControlState deadzone = settings[0]->value;
+ ControlState square = settings[1]->value;
+ ControlState m = controls[4]->control_ref->State();
+
+ // modifier code
+ if ( m )
+ {
+ yy = (abs(yy)>deadzone) * sign(yy) * (m + deadzone/2);
+ xx = (abs(xx)>deadzone) * sign(xx) * (m + deadzone/2);
+ }
+
+ // deadzone / square stick code
+ if ( deadzone || square )
+ {
+ // this section might be all wrong, but its working good enough, i think
+
+ ControlState ang = atan2( yy, xx );
+ ControlState ang_sin = sin(ang);
+ ControlState ang_cos = cos(ang);
+
+ // the amt a full square stick would have at current angle
+ ControlState square_full = std::min( ang_sin ? 1/abs(ang_sin) : 2, ang_cos ? 1/abs(ang_cos) : 2 );
+
+ // the amt a full stick would have that was ( user setting squareness) at current angle
+ // i think this is more like a pointed circle rather than a rounded square like it should be
+ ControlState stick_full = ( 1 + ( square_full - 1 ) * square );
+
+ ControlState dist = sqrt(xx*xx + yy*yy);
+
+ // dead zone code
+ dist = std::max( 0.0f, dist - deadzone * stick_full );
+ dist /= ( 1 - deadzone );
+
+ // square stick code
+ ControlState amt = dist / stick_full;
+ dist -= ((square_full - 1) * amt * square);
+
+ yy = std::max( -1.0f, std::min( 1.0f, ang_sin * dist ) );
+ xx = std::max( -1.0f, std::min( 1.0f, ang_cos * dist ) );
+ }
+
+ *y = C( yy * range + base );
+ *x = C( xx * range + base );
+ }
+
+ AnalogStick( const char* const _name );
+
+ };
+
+ class Buttons : public ControlGroup
+ {
+ public:
+ Buttons( const char* const _name );
+
+ template <typename C>
+ void GetState( C* const buttons, const C* bitmasks )
+ {
+ std::vector<Control*>::iterator i = controls.begin(),
+ e = controls.end();
+ for ( ; i!=e; ++i, ++bitmasks )
+ if ( (*i)->control_ref->State() > settings[0]->value ) // threshold
+ *buttons |= *bitmasks;
+ }
+
+ };
+
+ class MixedTriggers : public ControlGroup
+ {
+ public:
+
+ template <typename C, typename S>
+ void GetState( C* const digital, const C* bitmasks, S* analog, const unsigned int range )
+ {
+ const unsigned int trig_count = ((unsigned int) (controls.size() / 2));
+ for ( unsigned int i=0; i<trig_count; ++i,++bitmasks,++analog )
+ {
+ if ( controls[i]->control_ref->State() > settings[0]->value ) //threshold
+ {
+ *analog = range;
+ *digital |= *bitmasks;
+ }
+ else
+ *analog = S(controls[i+trig_count]->control_ref->State() * range);
+
+ }
+ }
+
+ MixedTriggers( const char* const _name );
+
+ };
+
+ class Triggers : public ControlGroup
+ {
+ public:
+
+ template <typename S>
+ void GetState( S* analog, const unsigned int range )
+ {
+ const unsigned int trig_count = ((unsigned int) (controls.size()));
+ const ControlState deadzone = settings[0]->value;
+ for ( unsigned int i=0; i<trig_count; ++i,++analog )
+ *analog = S( std::max(controls[i]->control_ref->State() - deadzone, 0.0f) / (1 - deadzone) * range );
+ }
+
+ Triggers( const char* const _name );
+
+ };
+
+ class Force : public ControlGroup
+ {
+ public:
+ Force( const char* const _name );
+
+ template <typename C, typename R>
+ void GetState( C* axis, const u8 base, const R range )
+ {
+ const float deadzone = settings[0]->value;
+ for ( unsigned int i=0; i<6; i+=2 )
+ {
+ const float state = controls[i+1]->control_ref->State() - controls[i]->control_ref->State();
+ if (abs(state) > deadzone)
+ *axis++ = (C)((state - (deadzone * sign(state))) / (1 - deadzone) * range + base);
+ //*axis++ = state * range + base;
+ else
+ *axis++ = (C)(base);
+ }
+ }
+ };
+
+ class Tilt : public ControlGroup
+ {
+ public:
+ Tilt( const char* const _name );
+
+ template <typename C, typename R>
+ void GetState( C* const x, C* const y, const unsigned int base, const R range )
+ {
+ // this is all a mess
+
+ ControlState yy = controls[0]->control_ref->State() - controls[1]->control_ref->State();
+ ControlState xx = controls[3]->control_ref->State() - controls[2]->control_ref->State();
+
+ ControlState deadzone = settings[0]->value;
+ ControlState circle = settings[1]->value;
+ ControlState m = controls[4]->control_ref->State();
+
+ // modifier code
+ if ( m )
+ {
+ yy = (abs(yy)>deadzone) * sign(yy) * (m + deadzone/2);
+ xx = (abs(xx)>deadzone) * sign(xx) * (m + deadzone/2);
+ }
+
+ // deadzone / circle stick code
+ if ( deadzone || circle )
+ {
+ // this section might be all wrong, but its working good enough, i think
+
+ ControlState ang = atan2( yy, xx );
+ ControlState ang_sin = sin(ang);
+ ControlState ang_cos = cos(ang);
+
+ // the amt a full square stick would have at current angle
+ ControlState square_full = std::min( ang_sin ? 1/abs(ang_sin) : 2, ang_cos ? 1/abs(ang_cos) : 2 );
+
+ // the amt a full stick would have that was ( user setting circular ) at current angle
+ // i think this is more like a pointed circle rather than a rounded square like it should be
+ ControlState stick_full = (square_full * (1 - circle)) + (circle);
+
+ ControlState dist = sqrt(xx*xx + yy*yy);
+
+ // dead zone code
+ dist = std::max( 0.0f, dist - deadzone * stick_full );
+ dist /= (1 - deadzone);
+
+ // circle stick code
+ ControlState amt = dist / stick_full;
+ dist += (square_full - 1) * amt * circle;
+
+ yy = std::max( -1.0f, std::min( 1.0f, ang_sin * dist ) );
+ xx = std::max( -1.0f, std::min( 1.0f, ang_cos * dist ) );
+ }
+
+ // this is kinda silly here
+ // gui being open will make this happen 2x as fast, o well
+ if (xx > m_tilt[0])
+ m_tilt[0] = std::min(m_tilt[0] + 0.1f, xx);
+ else if (xx < m_tilt[0])
+ m_tilt[0] = std::max(m_tilt[0] - 0.1f, xx);
+
+ if (yy > m_tilt[1])
+ m_tilt[1] = std::min(m_tilt[1] + 0.1f, yy);
+ else if (yy < m_tilt[1])
+ m_tilt[1] = std::max(m_tilt[1] - 0.1f, yy);
+
+ *y = C( m_tilt[1] * range + base );
+ *x = C( m_tilt[0] * range + base );
+ }
+ private:
+ float m_tilt[2];
+ };
+
+ class Cursor : public ControlGroup
+ {
+ public:
+ Cursor( const char* const _name, const SWiimoteInitialize* const _wiimote_initialize );
+
+ template <typename C>
+ void GetState( C* const x, C* const y, C* const z, const bool adjusted = false )
+ {
+ const float zz = controls[4]->control_ref->State() - controls[5]->control_ref->State();
+
+ // silly being here
+ if (zz > m_z)
+ m_z = std::min(m_z + 0.1f, zz);
+ else if (zz < m_z)
+ m_z = std::max(m_z - 0.1f, zz);
+
+ *z = m_z;
+
+ // hide
+ if (controls[6]->control_ref->State() > 0.5f)
+ {
+ *x = 10000; *y = 0;
+ }
+ else
+ {
+ float xx, yy;
+ GetMousePos(xx, yy, wiimote_initialize);
+
+ // use mouse cursor, or user defined mapping if they have something mapped
+ // this if seems horrible
+ if ( controls[0]->control_ref->control_qualifier.name.size() || controls[1]->control_ref->control_qualifier.name.size() )
+ yy = controls[0]->control_ref->State() - controls[1]->control_ref->State();
+ else
+ yy = -yy;
+
+ if ( controls[2]->control_ref->control_qualifier.name.size() || controls[3]->control_ref->control_qualifier.name.size() )
+ xx = controls[3]->control_ref->State() - controls[2]->control_ref->State();
+
+ // adjust cursor according to settings
+ if (adjusted)
+ {
+ xx *= ( settings[1]->value * 2 );
+ yy *= ( settings[2]->value * 2 );
+ yy += ( settings[0]->value - 0.5f );
+ }
+
+ *x = xx;
+ *y = yy;
+ }
+ }
+
+ private:
+ const SWiimoteInitialize* const wiimote_initialize;
+
+ float m_z;
+ };
+
+ class Extension : public ControlGroup
+ {
+ public:
+ Extension( const char* const _name )
+ : ControlGroup( _name, GROUP_TYPE_EXTENSION )
+ , switch_extension(0)
+ , active_extension(0) {}
+ ~Extension();
+
+ void GetState( u8* const data, const bool focus = true );
+
+ std::vector<ControllerEmu*> attachments;
+
+ int switch_extension;
+ int active_extension;
+ };
+
+ virtual ~ControllerEmu();
+
+ virtual std::string GetName() const = 0;
+
+ virtual void LoadDefaults() {}
+
+ void LoadConfig(IniFile::Section *sec, const std::string& base = "");
+ void SaveConfig(IniFile::Section *sec, const std::string& base = "");
+ void UpdateDefaultDevice();
+
+ void UpdateReferences( ControllerInterface& devi );
+
+ std::vector< ControlGroup* > groups;
+
+ ControllerInterface::DeviceQualifier default_device;
+
+};
+
+
+#endif
diff --git a/Source/Core/InputCommon/Src/InputConfig.cpp b/Source/Core/InputCommon/Src/InputConfig.cpp
new file mode 100644
index 0000000000..410aecb928
--- /dev/null
+++ b/Source/Core/InputCommon/Src/InputConfig.cpp
@@ -0,0 +1,69 @@
+// Copyright (C) 2010 Dolphin Project.
+
+// 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 "InputConfig.h"
+
+Plugin::Plugin( const char* const _ini_name, const char* const _gui_name, const char* const _profile_name )
+ : ini_name(_ini_name)
+ , gui_name(_gui_name)
+ , profile_name(_profile_name)
+{
+ // GCPads
+ //for ( unsigned int i = 0; i<4; ++i )
+ //controllers.push_back( new GCPad( i ) );
+ // Wiimotes / disabled, cause it only the GUI half is done
+ //for ( unsigned int i = 0; i<4; ++i )
+ // controllers.push_back( new Wiimote( i ) );
+};
+
+Plugin::~Plugin()
+{
+ // delete pads
+ std::vector<ControllerEmu*>::const_iterator i = controllers.begin(),
+ e = controllers.end();
+ for ( ; i != e; ++i )
+ delete *i;
+}
+
+bool Plugin::LoadConfig()
+{
+ IniFile inifile;
+ if (false == inifile.Load(std::string(File::GetUserPath(D_CONFIG_IDX)) + ini_name + ".ini"))
+ return false;
+
+ std::vector< ControllerEmu* >::const_iterator
+ i = controllers.begin(),
+ e = controllers.end();
+ for ( ; i!=e; ++i ) {
+ (*i)->LoadConfig(inifile.GetOrCreateSection((*i)->GetName().c_str()));
+ }
+}
+
+void Plugin::SaveConfig()
+{
+ std::string ini_filename = (std::string(File::GetUserPath(D_CONFIG_IDX)) + ini_name + ".ini" );
+
+ IniFile inifile;
+ inifile.Load(ini_filename);
+
+ std::vector< ControllerEmu* >::const_iterator i = controllers.begin(),
+ e = controllers.end();
+ for ( ; i!=e; ++i )
+ (*i)->SaveConfig(inifile.GetOrCreateSection((*i)->GetName().c_str()));
+
+ inifile.Save(ini_filename);
+}
diff --git a/Source/Core/InputCommon/Src/InputConfig.h b/Source/Core/InputCommon/Src/InputConfig.h
new file mode 100644
index 0000000000..6e8d8adef0
--- /dev/null
+++ b/Source/Core/InputCommon/Src/InputConfig.h
@@ -0,0 +1,53 @@
+// Copyright (C) 2010 Dolphin Project.
+
+// 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/
+
+#ifndef _CONFIG_H_
+#define _CONFIG_H_
+
+#include "Thread.h"
+#include "FileUtil.h"
+#include "IniFile.h"
+
+#include "ControllerInterface/ControllerInterface.h"
+#include "ControllerEmu.h"
+
+#include <string>
+#include <vector>
+#include <map>
+#include <sstream>
+
+class Plugin
+{
+public:
+
+ Plugin( const char* const _ini_name, const char* const _gui_name, const char* const _profile_name );
+ ~Plugin();
+
+ bool LoadConfig();
+ void SaveConfig();
+
+ std::vector< ControllerEmu* > controllers;
+
+ Common::CriticalSection controls_crit, interface_crit; // lock controls first
+ ControllerInterface controller_interface;
+
+ const char * const ini_name;
+ const char * const gui_name;
+ const char * const profile_name;
+};
+
+#endif
diff --git a/Source/Core/InputCommon/Src/SConscript b/Source/Core/InputCommon/Src/SConscript
index 426d877aac..fad361aadf 100644
--- a/Source/Core/InputCommon/Src/SConscript
+++ b/Source/Core/InputCommon/Src/SConscript
@@ -4,8 +4,10 @@ Import('env')
files = [
'Configuration.cpp',
+ 'ControllerEmu.cpp',
'EventHandler.cpp',
'InputCommon.cpp',
+ 'InputConfig.cpp',
'SDL_Util.cpp',
'ControllerInterface/ControllerInterface.cpp',
'ControllerInterface/SDL/SDL.cpp'
diff --git a/Source/Core/InputUICommon/InputUICommon.vcproj b/Source/Core/InputUICommon/InputUICommon.vcproj
new file mode 100644
index 0000000000..6e4b6c9a97
--- /dev/null
+++ b/Source/Core/InputUICommon/InputUICommon.vcproj
@@ -0,0 +1,425 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="9,00"
+ Name="InputUICommon"
+ ProjectGUID="{374E2DB7-42DF-4E59-8474-62B6687F4978}"
+ RootNamespace="InputUICommon"
+ Keyword="Win32Proj"
+ TargetFrameworkVersion="196613"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ <Platform
+ Name="x64"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="$(PlatformName)\$(ConfigurationName)"
+ IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
+ ConfigurationType="4"
+ CharacterSet="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\Common\Src;..\Core\Src;..\InputCommon\Src;..\..\PluginSpecs;..\..\..\Externals\Bochs_disasm;..\..\..\Externals\wxWidgets\Include;..\..\..\Externals\wxWidgets\Include\msvc"
+ PreprocessorDefinitions="WIN32;_DEBUG;_LIB;__WXMSW__;_SECURE_SCL=0;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ DebugInformationFormat="4"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLibrarianTool"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Debug|x64"
+ OutputDirectory="$(PlatformName)\$(ConfigurationName)"
+ IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
+ ConfigurationType="4"
+ CharacterSet="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ TargetEnvironment="3"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\Common\Src;..\Core\Src;..\InputCommon\Src;..\..\PluginSpecs;..\..\..\Externals\Bochs_disasm;..\..\..\Externals\wxWidgets\Include;..\..\..\Externals\wxWidgets\Include\msvc"
+ PreprocessorDefinitions="WIN32;_DEBUG;_LIB;__WXMSW__;_SECURE_SCL=0;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLibrarianTool"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="$(PlatformName)\$(ConfigurationName)"
+ IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
+ ConfigurationType="4"
+ CharacterSet="1"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ EnableIntrinsicFunctions="true"
+ AdditionalIncludeDirectories="..\Common\Src;..\Core\Src;..\InputCommon\Src;..\..\PluginSpecs;..\..\..\Externals\Bochs_disasm;..\..\..\Externals\wxWidgets\Include;..\..\..\Externals\wxWidgets\Include\msvc"
+ PreprocessorDefinitions="WIN32;NDEBUG;_LIB;__WXMSW__;_SECURE_SCL=0;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="true"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLibrarianTool"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|x64"
+ OutputDirectory="$(PlatformName)\$(ConfigurationName)"
+ IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
+ ConfigurationType="4"
+ CharacterSet="1"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ TargetEnvironment="3"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ EnableIntrinsicFunctions="true"
+ AdditionalIncludeDirectories="..\Common\Src;..\Core\Src;..\InputCommon\Src;..\..\PluginSpecs;..\..\..\Externals\Bochs_disasm;..\..\..\Externals\wxWidgets\Include;..\..\..\Externals\wxWidgets\Include\msvc"
+ PreprocessorDefinitions="WIN32;NDEBUG;_LIB;__WXMSW__;_SECURE_SCL=0;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="true"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLibrarianTool"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="DebugFast|Win32"
+ OutputDirectory="$(PlatformName)\$(ConfigurationName)"
+ IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
+ ConfigurationType="4"
+ CharacterSet="1"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ EnableIntrinsicFunctions="true"
+ AdditionalIncludeDirectories="..\Common\Src;..\Core\Src;..\InputCommon\Src;..\..\PluginSpecs;..\..\..\Externals\Bochs_disasm;..\..\..\Externals\wxWidgets\Include;..\..\..\Externals\wxWidgets\Include\msvc"
+ PreprocessorDefinitions="WIN32;NDEBUG;_LIB;__WXMSW__;_SECURE_SCL=0;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="true"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLibrarianTool"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="DebugFast|x64"
+ OutputDirectory="$(PlatformName)\$(ConfigurationName)"
+ IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
+ ConfigurationType="4"
+ CharacterSet="1"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ TargetEnvironment="3"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ EnableIntrinsicFunctions="true"
+ WholeProgramOptimization="false"
+ AdditionalIncludeDirectories="..\Common\Src;..\Core\Src;..\InputCommon\Src;..\..\PluginSpecs;..\..\..\Externals\Bochs_disasm;..\..\..\Externals\wxWidgets\Include;..\..\..\Externals\wxWidgets\Include\msvc"
+ PreprocessorDefinitions="WIN32;NDEBUG;_LIB;__WXMSW__;_SECURE_SCL=0;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="true"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLibrarianTool"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <File
+ RelativePath=".\Src\ConfigDiag.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\Src\ConfigDiag.h"
+ >
+ </File>
+ <File
+ RelativePath=".\Src\ConfigDiagBitmaps.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\Src\SConscript"
+ >
+ </File>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/Source/Core/InputUICommon/Src/ConfigDiag.cpp b/Source/Core/InputUICommon/Src/ConfigDiag.cpp
new file mode 100644
index 0000000000..981fd854a7
--- /dev/null
+++ b/Source/Core/InputUICommon/Src/ConfigDiag.cpp
@@ -0,0 +1,957 @@
+// Copyright (C) 2010 Dolphin Project.
+
+// 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 "ConfigDiag.h"
+
+#define _connect_macro_( b, f, c, s ) (b)->Connect( wxID_ANY, (c), wxCommandEventHandler( f ), (wxObject*)0, (wxEvtHandler*)s )
+
+static Plugin* g_plugin;
+
+void GamepadPage::ConfigExtension( wxCommandEvent& event )
+{
+ ControllerEmu::Extension* const ex = ((ExtensionButton*)event.GetEventObject())->extension;
+
+ // show config diag, if "none" isn't selected
+ if ( ex->switch_extension )
+ {
+ wxDialog* const dlg = new wxDialog( this, -1, wxString::FromAscii(ex->attachments[ex->switch_extension]->GetName().c_str()), wxDefaultPosition );
+ wxPanel* const pnl = new wxPanel( dlg, -1, wxDefaultPosition );
+ wxBoxSizer* const pnl_szr = new wxBoxSizer( wxHORIZONTAL );
+
+ const std::size_t orig_size = control_groups.size();
+
+ ControlGroupsSizer* const szr = new ControlGroupsSizer( ex->attachments[ex->switch_extension], pnl, this, &control_groups );
+ pnl->SetSizerAndFit( szr ); // needed
+ pnl_szr->Add( pnl, 0, wxLEFT, 5 );
+ dlg->SetSizerAndFit( pnl_szr ); // needed
+
+ dlg->Center();
+
+ dlg->ShowModal();
+ dlg->Destroy();
+
+ // remove the new groups that were just added, now that the window closed
+ control_groups.resize( orig_size );
+ }
+}
+
+PadSettingExtension::PadSettingExtension( wxWindow* const parent, ControllerEmu::Extension* const ext )
+ : wxChoice( parent, -1 )
+ , extension(ext)
+{
+
+ std::vector<ControllerEmu*>::const_iterator
+ i = extension->attachments.begin(),
+ e = extension->attachments.end();
+
+ for ( ; i!=e; ++i )
+ Append( wxString::FromAscii( (*i)->GetName().c_str() ) );
+
+ UpdateGUI();
+}
+
+void PadSettingExtension::UpdateGUI()
+{
+ Select( extension->switch_extension );
+}
+
+void PadSettingExtension::UpdateValue()
+{
+ extension->switch_extension = GetSelection();
+}
+
+PadSettingCheckBox::PadSettingCheckBox( wxWindow* const parent, ControlState& _value, const char* const label )
+ : wxCheckBox( parent, -1, wxString::FromAscii( label ), wxDefaultPosition )
+ , value(_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();
+}
+
+void PadSettingChoice::UpdateGUI()
+{
+ SetValue(value * 100);
+}
+
+void PadSettingChoice::UpdateValue()
+{
+ value = float(GetValue()) / 100;
+}
+
+ControlDialog::ControlDialog( wxWindow* const parent, ControllerInterface::ControlReference* const ref, const std::vector<ControllerInterface::Device*>& devs )
+ :wxDialog( parent, -1, wxT("Configure Control"), wxDefaultPosition )
+ ,control_reference(ref)
+{
+
+ device_cbox = new wxComboBox( this, -1, wxString::FromAscii( ref->device_qualifier.ToString().c_str() ), wxDefaultPosition, wxSize(256,-1), wxArrayString(), wxTE_PROCESS_ENTER );
+
+ _connect_macro_( device_cbox, ControlDialog::SetDevice, wxEVT_COMMAND_COMBOBOX_SELECTED, this );
+ _connect_macro_( device_cbox, ControlDialog::SetDevice, wxEVT_COMMAND_TEXT_ENTER, this );
+
+ std::vector< ControllerInterface::Device* >::const_iterator i = devs.begin(),
+ e = devs.end();
+ ControllerInterface::DeviceQualifier dq;
+ for ( ; i!=e; ++i )
+ {
+ dq.FromDevice( *i );
+ device_cbox->Append( wxString::FromAscii( dq.ToString().c_str() ) );
+ }
+
+ control_chooser = new ControlChooser( this, ref, parent );
+
+ wxStaticBoxSizer* const d_szr = new wxStaticBoxSizer( wxVERTICAL, this, wxT("Device") );
+ d_szr->Add( device_cbox, 0, wxEXPAND|wxALL, 5 );
+
+ wxBoxSizer* const szr = new wxBoxSizer( wxVERTICAL );
+ szr->Add( d_szr, 0, wxEXPAND|wxLEFT|wxRIGHT|wxTOP, 5 );
+ szr->Add( control_chooser, 0, wxEXPAND|wxALL, 5 );
+
+ SetSizerAndFit( szr ); // needed
+
+}
+
+ControlButton::ControlButton( wxWindow* const parent, ControllerInterface::ControlReference* const _ref, const unsigned int width, const std::string& label )
+: wxButton( parent, -1, wxT(""), wxDefaultPosition, wxSize( width,20) )
+, control_reference( _ref )
+{
+ if ( label.empty() )
+ SetLabel( wxString::FromAscii( _ref->control_qualifier.name.c_str() ) );
+ else
+ SetLabel( wxString::FromAscii( label.c_str() ) );
+}
+
+void ConfigDialog::UpdateProfileComboBox()
+{
+ std::string pname( File::GetUserPath(D_CONFIG_IDX) );
+ pname += PROFILES_PATH; pname += g_plugin->profile_name;
+
+ CFileSearch::XStringVector exts;
+ exts.push_back("*.ini");
+ CFileSearch::XStringVector dirs;
+ dirs.push_back( pname );
+ CFileSearch cfs( exts, dirs );
+ const CFileSearch::XStringVector& sv = cfs.GetFileNames();
+
+ wxArrayString strs;
+ CFileSearch::XStringVector::const_iterator si = sv.begin(),
+ se = sv.end();
+ for ( ; si!=se; ++si )
+ {
+ std::string str( si->begin() + si->find_last_of('/') + 1 , si->end() - 4 ) ;
+ strs.push_back( wxString::FromAscii( str.c_str() ) );
+ }
+
+ std::vector< GamepadPage* >::iterator i = m_padpages.begin(),
+ e = m_padpages.end();
+ for ( ; i != e; ++i )
+ {
+ (*i)->profile_cbox->Clear();
+ (*i)->profile_cbox->Append(strs);
+ }
+}
+
+void ConfigDialog::UpdateControlReferences()
+{
+ std::vector< GamepadPage* >::iterator i = m_padpages.begin(),
+ e = m_padpages.end();
+ for ( ; i != e; ++i )
+ (*i)->controller->UpdateReferences( g_plugin->controller_interface );
+}
+
+void ConfigDialog::ClickSave( wxCommandEvent& event )
+{
+ g_plugin->SaveConfig();
+ Close();
+}
+
+void ControlChooser::UpdateListContents()
+{
+ control_lbox->Clear();
+
+ // make sure it's a valid device
+ if ( control_reference->device )
+ {
+ if ( control_reference->is_input )
+ {
+ // for inputs
+ std::vector<ControllerInterface::Device::Input*>::const_iterator
+ i = control_reference->device->Inputs().begin(),
+ e = control_reference->device->Inputs().end();
+ for ( ; i!=e; ++i )
+ control_lbox->Append( wxString::FromAscii( (*i)->GetName().c_str() ) );
+ }
+ else
+ {
+ // for outputs
+ std::vector<ControllerInterface::Device::Output*>::const_iterator
+ i = control_reference->device->Outputs().begin(),
+ e = control_reference->device->Outputs().end();
+ for ( ; i!=e; ++i )
+ control_lbox->Append( wxString::FromAscii( (*i)->GetName().c_str() ) );
+ }
+ }
+
+ UpdateListSelection();
+}
+
+void ControlChooser::UpdateListSelection()
+{
+ UpdateGUI();
+
+ wxArrayString control_names = control_lbox->GetStrings();
+ const std::string cname = control_reference->control_qualifier.name;
+
+ control_lbox->DeselectAll();
+
+ // if text starts and ends with '|' it's multiple controls, otherwise just single one
+ if (cname.size() ? ((*cname.rbegin()=='|') && (*cname.begin()=='|')) : false)
+ {
+ for (int i = int(control_names.size()) - 1; i >= 0; --i)
+ if (cname.find( control_names[i].Prepend(wxT('|')).Append(wxT('|')).ToAscii()) != cname.npos)
+ control_lbox->Select( i );
+ }
+ else
+ {
+ const int n = control_lbox->FindString(wxString::FromAscii(cname.c_str()));
+ if (n >= 0)
+ control_lbox->Select(n);
+ }
+}
+
+void ControlChooser::UpdateGUI()
+{
+ // update textbox
+ textctrl->SetValue(wxString::FromAscii(control_reference->control_qualifier.name.c_str()));
+
+ // updates the "bound controls:" label
+ size_t bound = control_reference->controls.size();
+ std::ostringstream ss;
+ ss << "Bound Controls: ";
+ if ( bound ) ss << bound; else ss << "None";
+ m_bound_label->SetLabel( wxString::FromAscii(ss.str().c_str()) );
+};
+
+void GamepadPage::UpdateGUI()
+{
+ device_cbox->SetValue( wxString::FromAscii( controller->default_device.ToString().c_str() ) );
+
+ 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();
+ for ( ; i!=e; ++i )
+ (*i)->SetLabel( wxString::FromAscii( (*i)->control_reference->control_qualifier.name.c_str() ) );
+
+ // cboxes
+ std::vector<PadSetting*>::const_iterator si = (*g)->options.begin()
+ , se = (*g)->options.end();
+ for ( ; si!=se; ++si )
+ (*si)->UpdateGUI();
+ }
+}
+
+void GamepadPage::ClearAll( wxCommandEvent& event )
+{
+ g_plugin->controls_crit.Enter(); // enter
+
+ // just load an empty ini section to clear everything :P
+ IniFile::Section section;
+ controller->LoadConfig(&section);
+
+ // no point in using the real ControllerInterface i guess
+ ControllerInterface face;
+ controller->UpdateReferences(face);
+
+ UpdateGUI();
+
+ g_plugin->controls_crit.Leave(); // leave
+}
+
+void ControlDialog::SetControl( wxCommandEvent& event )
+{
+ control_reference->control_qualifier.name =
+ std::string( control_chooser->textctrl->GetValue().ToAscii() );
+
+ g_plugin->controls_crit.Enter(); // enter
+ control_reference->UpdateControls();
+ g_plugin->controls_crit.Leave(); // leave
+
+ control_chooser->UpdateListSelection();
+}
+
+void GamepadPage::SetDevice( wxCommandEvent& event )
+{
+ controller->default_device.FromString( std::string( device_cbox->GetValue().ToAscii() ) );
+
+ // show user what it was validated as
+ device_cbox->SetValue( wxString::FromAscii( controller->default_device.ToString().c_str() ) );
+
+ // this will set all the controls to this default device
+ controller->UpdateDefaultDevice();
+
+ // update references
+ g_plugin->controls_crit.Enter(); // enter
+ controller->UpdateReferences( g_plugin->controller_interface );
+ g_plugin->controls_crit.Leave(); // leave
+}
+
+void ControlDialog::SetDevice( wxCommandEvent& event )
+{
+ control_reference->device_qualifier.FromString( std::string( device_cbox->GetValue().ToAscii() ) );
+
+ // show user what it was validated as
+ device_cbox->SetValue( wxString::FromAscii( control_reference->device_qualifier.ToString().c_str() ) );
+
+ // update references
+ g_plugin->controls_crit.Enter(); // enter
+ g_plugin->controller_interface.UpdateReference( control_reference );
+ g_plugin->controls_crit.Leave(); // leave
+
+ // update gui
+ control_chooser->UpdateListContents();
+}
+
+void ControlDialog::ClearControl( wxCommandEvent& event )
+{
+ control_reference->control_qualifier.name.clear();
+
+ g_plugin->controls_crit.Leave(); // enter
+ control_reference->UpdateControls();
+ g_plugin->controls_crit.Leave(); // leave
+
+ control_chooser->UpdateListSelection();
+}
+
+void GamepadPage::AdjustSetting( wxCommandEvent& event )
+{
+ g_plugin->controls_crit.Enter(); // enter
+
+ // updates the setting value from the GUI control
+ (dynamic_cast<PadSetting*>(event.GetEventObject()))->UpdateValue();
+
+ g_plugin->controls_crit.Leave(); // leave
+}
+
+void GamepadPage::AdjustControlOption( wxCommandEvent& event )
+{
+ g_plugin->controls_crit.Enter(); // enter
+
+ m_control_dialog->control_reference->range = ControlState( m_control_dialog->control_chooser->range_slider->GetValue() ) / SLIDER_TICK_COUNT;
+
+ if ( m_control_dialog->control_reference->is_input )
+ ((ControllerInterface::InputReference*)m_control_dialog->control_reference)->mode =
+ m_control_dialog->control_chooser->mode_cbox->GetSelection();
+
+ g_plugin->controls_crit.Leave(); // leave
+}
+
+void GamepadPage::ConfigControl( wxCommandEvent& event )
+{
+ m_control_dialog = new ControlDialog( this, ((ControlButton*)event.GetEventObject())->control_reference, g_plugin->controller_interface.Devices() );
+ m_control_dialog->ShowModal();
+ m_control_dialog->Destroy();
+
+ // update changes that were made in the dialog
+ UpdateGUI();
+}
+
+void GamepadPage::ClearControl( wxCommandEvent& event )
+{
+ ControlButton* const btn = (ControlButton*)event.GetEventObject();
+ btn->control_reference->control_qualifier.name.clear();
+ btn->control_reference->device_qualifier = controller->default_device;
+
+ g_plugin->controls_crit.Enter();
+ if (btn->control_reference->is_input)
+ ((ControllerInterface::InputReference*)btn->control_reference)->mode = 0;
+ controller->UpdateReferences( g_plugin->controller_interface );
+ g_plugin->controls_crit.Leave();
+
+ // update changes
+ UpdateGUI();
+}
+
+void ControlDialog::DetectControl( wxCommandEvent& event )
+{
+ wxButton* const btn = (wxButton*)event.GetEventObject();
+
+ // some hacks
+ const wxString lbl = btn->GetLabel();
+ wxChar num = lbl[0];
+ if (num > '9')
+ {
+ num = 1;
+ btn->SetLabel(wxT("[ waiting ]"));
+ }
+ else
+ {
+ num -= 0x30;
+ btn->SetLabel(wxT("w"));
+ }
+
+ g_plugin->controls_crit.Enter(); // enter
+ if ( control_reference->Detect( DETECT_WAIT_TIME + (num - 1) * 500, num ) ) // if we got input, update gui
+ control_chooser->UpdateListSelection();
+ g_plugin->controls_crit.Leave(); // leave
+
+ btn->SetLabel(lbl);
+}
+
+void GamepadPage::DetectControl( wxCommandEvent& event )
+{
+ ControlButton* btn = (ControlButton*)event.GetEventObject();
+
+ btn->SetLabel(wxT("[ waiting ]"));
+
+ g_plugin->controls_crit.Enter(); // enter
+ btn->control_reference->Detect( DETECT_WAIT_TIME );
+ g_plugin->controls_crit.Leave(); // leave
+
+ btn->SetLabel(wxString::FromAscii(btn->control_reference->control_qualifier.name.c_str()));
+}
+
+void ControlDialog::SelectControl( wxCommandEvent& event )
+{
+ // needed for linux
+ if (IsBeingDeleted())
+ return;
+
+ wxListBox* const lb = (wxListBox*)event.GetEventObject();
+
+ wxArrayInt sels;
+ lb->GetSelections( sels );
+ wxArrayString names = lb->GetStrings();
+
+ wxString final_label;
+
+ if (sels.GetCount() == 1)
+ final_label = names[ sels[0] ];
+ else
+ {
+ final_label = wxT('|');
+ for ( unsigned int i=0; i<sels.GetCount(); ++i )
+ final_label += names[ sels[i] ] + wxT('|');
+ }
+
+ control_reference->control_qualifier.name =
+ std::string( final_label.ToAscii() );
+
+ g_plugin->controls_crit.Enter(); // enter
+ control_reference->UpdateControls();
+ g_plugin->controls_crit.Leave(); // leave
+
+ control_chooser->UpdateGUI();
+}
+
+ControlChooser::ControlChooser( wxWindow* const parent, ControllerInterface::ControlReference* const ref, wxWindow* const eventsink )
+: wxStaticBoxSizer( wxVERTICAL, parent, ref->is_input ? wxT("Input") : wxT("Output") )
+ , control_reference(ref)
+{
+ textctrl = new wxTextCtrl( parent, -1, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER );
+ _connect_macro_( textctrl, ControlDialog::SetControl, wxEVT_COMMAND_TEXT_ENTER, parent);
+
+ wxButton* const detect_button = new wxButton( parent, -1, ref->is_input ? wxT("Detect 1") : wxT("Test") );
+ wxButton* const clear_button = new wxButton( parent, -1, wxT("Clear"), wxDefaultPosition );
+ wxButton* const set_button = new wxButton( parent, -1, wxT("Set")/*, wxDefaultPosition, wxSize( 32, -1 )*/ );
+
+
+ control_lbox = new wxListBox( parent, -1, wxDefaultPosition, wxSize( 256, 128 ), wxArrayString(), wxLB_EXTENDED );
+ _connect_macro_( control_lbox, ControlDialog::SelectControl, wxEVT_COMMAND_LISTBOX_SELECTED, parent);
+
+ wxBoxSizer* const button_sizer = new wxBoxSizer( wxHORIZONTAL );
+ button_sizer->Add( detect_button, 1, 0, 5 );
+ if ( ref->is_input )
+ for ( unsigned int i = 2; i<5; ++i )
+ {
+ wxButton* d_btn = new wxButton( parent, -1, wxChar( '0'+i ), wxDefaultPosition, wxSize(20,-1) );
+ _connect_macro_( d_btn, ControlDialog::DetectControl, wxEVT_COMMAND_BUTTON_CLICKED, parent);
+ button_sizer->Add( d_btn );
+ }
+ button_sizer->Add( clear_button, 1, 0, 5 );
+ button_sizer->Add( set_button, 1, 0, 5 );
+
+ range_slider = new wxSlider( parent, -1, SLIDER_TICK_COUNT, 0, SLIDER_TICK_COUNT, wxDefaultPosition, wxDefaultSize, wxSL_TOP | wxSL_LABELS /*| wxSL_AUTOTICKS*/ );
+
+ range_slider->SetValue( control_reference->range * SLIDER_TICK_COUNT );
+
+ _connect_macro_( detect_button, ControlDialog::DetectControl, wxEVT_COMMAND_BUTTON_CLICKED, parent);
+ _connect_macro_( clear_button, ControlDialog::ClearControl, wxEVT_COMMAND_BUTTON_CLICKED, parent);
+ _connect_macro_( set_button, ControlDialog::SetControl, wxEVT_COMMAND_BUTTON_CLICKED, parent);
+
+ _connect_macro_( range_slider, GamepadPage::AdjustControlOption, wxEVT_SCROLL_CHANGED, eventsink);
+ wxStaticText* const range_label = new wxStaticText( parent, -1, wxT("Range"));
+ m_bound_label = new wxStaticText( parent, -1, wxT("") );
+
+ wxBoxSizer* const range_sizer = new wxBoxSizer( wxHORIZONTAL );
+ range_sizer->Add( range_label, 0, wxCENTER|wxLEFT, 5 );
+ range_sizer->Add( range_slider, 1, wxEXPAND|wxLEFT, 5 );
+
+ wxBoxSizer* const txtbox_szr = new wxBoxSizer( wxHORIZONTAL );
+
+ txtbox_szr->Add( textctrl, 1, wxEXPAND, 0 );
+
+
+ Add( range_sizer, 0, wxEXPAND|wxLEFT|wxRIGHT, 5 );
+ if ( control_reference->is_input )
+ {
+ mode_cbox = new wxChoice( parent, -1 );
+ mode_cbox->Append( wxT("OR") );
+ mode_cbox->Append( wxT("AND") );
+ mode_cbox->Append( wxT("NOT") );
+ mode_cbox->Select( ((ControllerInterface::InputReference*)control_reference)->mode );
+
+ _connect_macro_( mode_cbox, GamepadPage::AdjustControlOption, wxEVT_COMMAND_CHOICE_SELECTED, eventsink );
+
+ wxBoxSizer* const mode_szr = new wxBoxSizer( wxHORIZONTAL );
+ mode_szr->Add( new wxStaticText( parent, -1, wxT("Mode") ), 0, wxCENTER|wxLEFT|wxRIGHT, 5 );
+ mode_szr->Add( mode_cbox, 0, wxLEFT, 5 );
+
+ Add( mode_szr, 0, wxEXPAND|wxLEFT|wxRIGHT, 5 );
+ }
+ Add( txtbox_szr, 0, wxEXPAND|wxTOP|wxLEFT|wxRIGHT, 5 );
+ Add( button_sizer, 0, wxEXPAND|wxBOTTOM|wxLEFT|wxRIGHT, 5 );
+ Add( control_lbox, 0, wxEXPAND|wxLEFT|wxRIGHT|wxBOTTOM, 5 );
+ Add( m_bound_label, 0, wxEXPAND|wxLEFT, 80 );
+
+ UpdateListContents();
+}
+
+void GamepadPage::LoadProfile( wxCommandEvent& event )
+{
+ // TODO: check for dumb characters maybe
+ if ( profile_cbox->GetValue().empty() )
+ return;
+
+ g_plugin->controls_crit.Enter();
+
+ std::string fname( File::GetUserPath(D_CONFIG_IDX) );
+ fname += PROFILES_PATH; fname += g_plugin->profile_name; fname += '/';
+ fname += profile_cbox->GetValue().ToAscii(); fname += ".ini";
+
+ if ( false == File::Exists( fname.c_str() ) )
+ return;
+
+ IniFile inifile;
+ inifile.Load(fname);
+ controller->LoadConfig( inifile.GetOrCreateSection("Profile"));
+ controller->UpdateReferences( g_plugin->controller_interface );
+
+ g_plugin->controls_crit.Leave();
+ UpdateGUI();
+}
+
+void GamepadPage::SaveProfile( wxCommandEvent& event )
+{
+ // TODO: check for dumb characters
+ if ( profile_cbox->GetValue().empty() )
+ return;
+
+ std::string fname( File::GetUserPath(D_CONFIG_IDX) );
+ fname += PROFILES_PATH; fname += g_plugin->profile_name; fname += '/';
+ if ( false == File::Exists( fname.c_str() ) )
+ File::CreateFullPath( fname.c_str() );
+ fname += profile_cbox->GetValue().ToAscii(); fname += ".ini";
+
+ // don't need lock
+ IniFile inifile;
+ inifile.Load(fname);
+ controller->SaveConfig( inifile.GetOrCreateSection("Profile") );
+ inifile.Save(fname);
+
+ m_config_dialog->UpdateProfileComboBox();
+}
+
+void GamepadPage::DeleteProfile( wxCommandEvent& event )
+{
+ // TODO: check for dumb characters maybe
+ if ( profile_cbox->GetValue().empty() )
+ return;
+
+ // don't need lock
+ std::string fname( File::GetUserPath(D_CONFIG_IDX) );
+ fname += PROFILES_PATH; fname += g_plugin->profile_name; fname += '/';
+ fname += profile_cbox->GetValue().ToAscii(); fname += ".ini";
+ if ( File::Exists( fname.c_str() ) )
+ File::Delete( fname.c_str() );
+
+ m_config_dialog->UpdateProfileComboBox();
+}
+
+void ConfigDialog::UpdateDeviceComboBox()
+{
+ std::vector< GamepadPage* >::iterator i = m_padpages.begin(),
+ e = m_padpages.end();
+ ControllerInterface::DeviceQualifier dq;
+ for ( ; i != e; ++i )
+ {
+ (*i)->device_cbox->Clear();
+ std::vector<ControllerInterface::Device*>::const_iterator di = g_plugin->controller_interface.Devices().begin(),
+ de = g_plugin->controller_interface.Devices().end();
+ for ( ; di!=de; ++di )
+ {
+ dq.FromDevice( *di );
+ (*i)->device_cbox->Append( wxString::FromAscii( dq.ToString().c_str() ) );
+ }
+ (*i)->device_cbox->SetValue( wxString::FromAscii( (*i)->controller->default_device.ToString().c_str() ) );
+ }
+}
+
+void GamepadPage::RefreshDevices( wxCommandEvent& event )
+{
+ g_plugin->controls_crit.Enter(); // enter
+
+ // refresh devices
+ // TODO: remove hackery of not deinting SDL
+ g_plugin->controller_interface.DeInit(true);
+ g_plugin->controller_interface.Init();
+
+ // update all control references
+ m_config_dialog->UpdateControlReferences();
+
+ // update device cbox
+ m_config_dialog->UpdateDeviceComboBox();
+
+ g_plugin->controls_crit.Leave(); // leave
+}
+
+ControlGroupBox::ControlGroupBox( ControllerEmu::ControlGroup* const group, wxWindow* const parent, wxWindow* const eventsink )
+: wxStaticBoxSizer( wxVERTICAL, parent, wxString::FromAscii( group->name ) )
+{
+
+ control_group = group;
+ static_bitmap = NULL;
+
+ wxFont m_SmallFont(7, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
+ std::vector<ControllerEmu::ControlGroup::Control*>::iterator
+ ci = group->controls.begin(),
+ ce = group->controls.end();
+ for ( ; ci != ce; ++ci)
+ {
+
+ wxStaticText* const label = new wxStaticText(parent, -1, wxString::FromAscii((*ci)->name)/*.append(wxT(" :"))*/ );
+
+ ControlButton* const control_button = new ControlButton(parent, (*ci)->control_ref, 80);
+ control_button->SetFont(m_SmallFont);
+
+ controls.push_back(control_button);
+ control_buttons.push_back(control_button);
+
+ if ((*ci)->control_ref->is_input)
+ {
+ control_button->SetToolTip(wxT("Left-click to detect input.\nMiddle-click to clear.\nRight-click for more options."));
+ _connect_macro_( control_button, GamepadPage::DetectControl, wxEVT_COMMAND_BUTTON_CLICKED, eventsink );
+ }
+ else
+ {
+ control_button->SetToolTip(wxT("Left/Right-click for more options.\nMiddle-click to clear."));
+ _connect_macro_( control_button, GamepadPage::ConfigControl, wxEVT_COMMAND_BUTTON_CLICKED, eventsink );
+ }
+
+ _connect_macro_( control_button, GamepadPage::ClearControl, wxEVT_MIDDLE_DOWN, eventsink );
+ _connect_macro_( control_button, GamepadPage::ConfigControl, wxEVT_RIGHT_UP, eventsink );
+
+ wxBoxSizer* const control_sizer = new wxBoxSizer( wxHORIZONTAL );
+ control_sizer->AddStretchSpacer( 1 );
+ control_sizer->Add( label, 0, wxCENTER | wxRIGHT, 3 );
+ control_sizer->Add( control_button, 0, 0, 0 );
+
+ Add( control_sizer, 0, wxEXPAND|wxLEFT|wxRIGHT, 3 );
+
+ }
+
+ wxMemoryDC dc;
+
+ switch ( group->type )
+ {
+ case GROUP_TYPE_STICK :
+ case GROUP_TYPE_TILT :
+ case GROUP_TYPE_CURSOR :
+ case GROUP_TYPE_FORCE :
+ {
+ wxBitmap bitmap(64, 64);
+ dc.SelectObject(bitmap);
+ dc.Clear();
+ static_bitmap = new wxStaticBitmap( parent, -1, bitmap, wxDefaultPosition, wxDefaultSize, wxBITMAP_TYPE_BMP );
+
+ std::vector< ControllerEmu::ControlGroup::Setting* >::const_iterator
+ i = group->settings.begin(),
+ e = group->settings.end();
+
+ wxBoxSizer* const szr = new wxBoxSizer( wxVERTICAL );
+ for ( ; i!=e; ++i )
+ {
+ PadSettingChoice* cbox = new PadSettingChoice( parent, *i );
+ _connect_macro_( cbox, GamepadPage::AdjustSetting, wxEVT_COMMAND_SPINCTRL_UPDATED, eventsink );
+ options.push_back( cbox );
+ szr->Add( new wxStaticText( parent, -1, wxString::FromAscii( (*i)->name ) ) );
+ szr->Add( cbox, 0, wxLEFT, 0 );
+ }
+
+ wxBoxSizer* const h_szr = new wxBoxSizer( wxHORIZONTAL );
+ h_szr->Add( szr, 1, 0, 5 );
+ h_szr->Add( static_bitmap, 0, wxALL|wxCENTER, 3 );
+
+ Add( h_szr, 0, wxEXPAND|wxLEFT|wxCENTER|wxTOP, 3 );
+ }
+ break;
+ case GROUP_TYPE_BUTTONS :
+ {
+ wxBitmap bitmap(int(12*group->controls.size()+1), 12);
+ dc.SelectObject(bitmap);
+ dc.Clear();
+ static_bitmap = new wxStaticBitmap( parent, -1, bitmap, wxDefaultPosition, wxDefaultSize, wxBITMAP_TYPE_BMP );
+
+ PadSettingChoice* const threshold_cbox = new PadSettingChoice( parent, group->settings[0] );
+ _connect_macro_( threshold_cbox, GamepadPage::AdjustSetting, wxEVT_COMMAND_SPINCTRL_UPDATED, eventsink );
+
+ threshold_cbox->SetToolTip(wxT("Adjust the analog control pressure required to activate buttons."));
+
+ options.push_back( threshold_cbox );
+
+ wxBoxSizer* const szr = new wxBoxSizer( wxHORIZONTAL );
+ szr->Add( new wxStaticText( parent, -1, wxString::FromAscii( group->settings[0]->name ) ), 0, wxCENTER|wxRIGHT, 3 );
+ szr->Add( threshold_cbox, 0, wxRIGHT, 3 );
+
+ Add( szr, 0, wxALL|wxCENTER, 3 );
+ Add( static_bitmap, 0, wxALL|wxCENTER, 3 );
+ }
+ break;
+ case GROUP_TYPE_MIXED_TRIGGERS :
+ case GROUP_TYPE_TRIGGERS :
+ {
+ int height = (int)(6 * group->controls.size());
+ int width = 64+12+1;
+ if (GROUP_TYPE_TRIGGERS == group->type)
+ {
+ height *= 2;
+ width = 64;
+ }
+ wxBitmap bitmap(width, height+1);
+ dc.SelectObject(bitmap);
+ dc.Clear();
+ static_bitmap = new wxStaticBitmap( parent, -1, bitmap, wxDefaultPosition, wxDefaultSize, wxBITMAP_TYPE_BMP );
+
+ std::vector<ControllerEmu::ControlGroup::Setting*>::const_iterator
+ i = group->settings.begin(),
+ e = group->settings.end();
+ for ( ; i!=e; ++i )
+ {
+ PadSettingChoice* cbox = new PadSettingChoice( parent, *i );
+ _connect_macro_( cbox, GamepadPage::AdjustSetting, wxEVT_COMMAND_SPINCTRL_UPDATED, eventsink );
+ options.push_back( cbox );
+ wxBoxSizer* const szr = new wxBoxSizer( wxHORIZONTAL );
+ szr->Add( new wxStaticText( parent, -1, wxString::FromAscii( (*i)->name ) ), 0, wxCENTER|wxRIGHT, 3 );
+ szr->Add( cbox, 0, wxRIGHT, 3 );
+ Add( szr, 0, wxALL|wxCENTER, 3 );
+ }
+
+ Add( static_bitmap, 0, wxALL|wxCENTER, 3 );
+ }
+ break;
+ case GROUP_TYPE_EXTENSION :
+ {
+ PadSettingExtension* const attachments = new PadSettingExtension( parent, (ControllerEmu::Extension*)group );
+ wxButton* const configure = new ExtensionButton( parent, (ControllerEmu::Extension*)group );
+
+ options.push_back( attachments );
+
+ _connect_macro_( attachments, GamepadPage::AdjustSetting, wxEVT_COMMAND_CHOICE_SELECTED, eventsink );
+ _connect_macro_( configure, GamepadPage::ConfigExtension, wxEVT_COMMAND_BUTTON_CLICKED, eventsink );
+
+ Add( attachments, 0, wxTOP|wxLEFT|wxRIGHT|wxEXPAND, 3 );
+ Add( configure, 0, wxALL|wxEXPAND, 3 );
+ }
+ break;
+ default :
+ {
+ //options
+
+ 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 );
+ _connect_macro_( setting_cbox, GamepadPage::AdjustSetting, wxEVT_COMMAND_CHECKBOX_CLICKED, eventsink );
+ options.push_back( setting_cbox );
+
+ Add( setting_cbox, 0, wxALL|wxLEFT, 5 );
+
+ }
+ }
+ break;
+ }
+
+ dc.SelectObject(wxNullBitmap);
+
+ //AddStretchSpacer( 0 );
+}
+
+ControlGroupsSizer::ControlGroupsSizer( ControllerEmu* const controller, wxWindow* const parent, wxWindow* const eventsink, std::vector<ControlGroupBox*>* groups )
+ : wxBoxSizer( wxHORIZONTAL )
+{
+
+ wxBoxSizer* stacked_groups = NULL;
+ for ( unsigned int i = 0; i < controller->groups.size(); ++i )
+ {
+ ControlGroupBox* control_group = new ControlGroupBox( controller->groups[i], parent, eventsink );
+
+ if ( control_group->control_buttons.size() > 1 )
+ {
+ if ( stacked_groups )
+ Add( stacked_groups, 0, /*wxEXPAND|*/wxBOTTOM|wxRIGHT, 5 );
+
+ stacked_groups = new wxBoxSizer( wxVERTICAL );
+ stacked_groups->Add( control_group, 0, wxEXPAND );
+ }
+ else
+ stacked_groups->Add( control_group, 0, wxEXPAND );
+
+ if ( groups )
+ groups->push_back( control_group );
+ }
+
+ if ( stacked_groups )
+ Add( stacked_groups, 0, /*wxEXPAND|*/wxBOTTOM|wxRIGHT, 5 );
+
+}
+
+GamepadPage::GamepadPage( wxWindow* parent, const unsigned int pad_num, ConfigDialog* const config_dialog )
+ : wxNotebookPage( parent, -1 , wxDefaultPosition, wxDefaultSize )
+ ,controller(g_plugin->controllers[pad_num])
+ ,m_config_dialog(config_dialog)
+{
+
+ wxBoxSizer* control_group_sizer = new ControlGroupsSizer( g_plugin->controllers[pad_num], this, this, &control_groups );
+
+ wxStaticBoxSizer* profile_sbox = new wxStaticBoxSizer( wxHORIZONTAL, this, wxT("Profile") );
+
+ // device chooser
+
+ wxStaticBoxSizer* const device_sbox = new wxStaticBoxSizer( wxHORIZONTAL, this, wxT("Device") );
+
+ device_cbox = new wxComboBox( this, -1, wxT(""), wxDefaultPosition, wxSize(128,-1), 0, 0, wxTE_PROCESS_ENTER );
+
+ wxButton* refresh_button = new wxButton( this, -1, wxT("Refresh"), wxDefaultPosition, wxSize(60,-1) );
+
+ _connect_macro_( device_cbox, GamepadPage::SetDevice, wxEVT_COMMAND_COMBOBOX_SELECTED, this );
+ _connect_macro_( device_cbox, GamepadPage::SetDevice, wxEVT_COMMAND_TEXT_ENTER, this );
+ _connect_macro_( refresh_button, GamepadPage::RefreshDevices, wxEVT_COMMAND_BUTTON_CLICKED, this );
+
+ device_sbox->Add( device_cbox, 1, wxLEFT|wxRIGHT, 3 );
+ device_sbox->Add( refresh_button, 0, wxRIGHT|wxBOTTOM, 3 );
+
+ wxStaticBoxSizer* const clear_sbox = new wxStaticBoxSizer( wxHORIZONTAL, this, wxT("Clear") );
+ wxButton* all_button = new wxButton( this, -1, wxT("All"), wxDefaultPosition, wxSize(48,-1) );
+ clear_sbox->Add( all_button, 1, wxLEFT|wxRIGHT, 3 );
+
+ _connect_macro_(all_button, GamepadPage::ClearAll, wxEVT_COMMAND_BUTTON_CLICKED, this);
+
+ profile_cbox = new wxComboBox( this, -1, wxT(""), wxDefaultPosition, wxSize(128,-1) );
+
+ wxButton* const pload_btn = new wxButton( this, -1, wxT("Load"), wxDefaultPosition, wxSize(48,-1) );
+ wxButton* const psave_btn = new wxButton( this, -1, wxT("Save"), wxDefaultPosition, wxSize(48,-1) );
+ wxButton* const pdelete_btn = new wxButton( this, -1, wxT("Delete"), wxDefaultPosition, wxSize(60,-1) );
+
+ _connect_macro_(pload_btn, GamepadPage::LoadProfile, wxEVT_COMMAND_BUTTON_CLICKED, this);
+ _connect_macro_(psave_btn, GamepadPage::SaveProfile, wxEVT_COMMAND_BUTTON_CLICKED, this);
+ _connect_macro_(pdelete_btn, GamepadPage::DeleteProfile, wxEVT_COMMAND_BUTTON_CLICKED, this);
+
+ profile_sbox->Add( profile_cbox, 1, wxLEFT, 3 );
+ profile_sbox->Add( pload_btn, 0, wxLEFT, 3 );
+ profile_sbox->Add( psave_btn, 0, 0, 3 );
+ profile_sbox->Add( pdelete_btn, 0, wxRIGHT|wxBOTTOM, 3 );
+
+ wxBoxSizer* const dio = new wxBoxSizer( wxHORIZONTAL );
+ dio->Add( device_sbox, 1, wxEXPAND|wxRIGHT, 5 );
+ dio->Add( clear_sbox, 0, wxEXPAND|wxRIGHT, 5 );
+ dio->Add( profile_sbox, 1, wxEXPAND|wxRIGHT, 5 );
+
+ wxBoxSizer* const mapping = new wxBoxSizer( wxVERTICAL );
+
+ mapping->Add( dio, 1, wxEXPAND|wxLEFT|wxTOP|wxBOTTOM, 5 );
+ mapping->Add( control_group_sizer, 0, wxLEFT|wxEXPAND, 5 );
+
+ UpdateGUI();
+
+ SetSizerAndFit( mapping ); // needed
+ Layout();
+};
+
+ConfigDialog::~ConfigDialog()
+{
+ m_update_timer->Stop();
+}
+
+ConfigDialog::ConfigDialog( wxWindow* const parent, Plugin& plugin, const std::string& name, const bool _is_game_running )
+ : wxDialog( parent, wxID_ANY, wxString::FromAscii(name.c_str()), wxPoint(128,-1), wxDefaultSize )
+ , is_game_running(_is_game_running)
+ , m_plugin(plugin)
+{
+ g_plugin = &plugin;
+
+ m_pad_notebook = new wxNotebook( this, -1, wxDefaultPosition, wxDefaultSize, wxNB_DEFAULT );
+ for ( unsigned int i = 0; i < plugin.controllers.size(); ++i )
+ {
+ GamepadPage* gp = new GamepadPage( m_pad_notebook, i, this );
+ m_padpages.push_back( gp );
+ m_pad_notebook->AddPage( gp, wxString::FromAscii( g_plugin->gui_name ) + wxT(' ') + wxChar('1'+i) );
+ }
+
+ UpdateDeviceComboBox();
+ UpdateProfileComboBox();
+
+ wxButton* const close_button = new wxButton( this, -1, wxT("Save"));
+ _connect_macro_(close_button, ConfigDialog::ClickSave, wxEVT_COMMAND_BUTTON_CLICKED, this);
+ _connect_macro_(close_button, ConfigDialog::ClickSave, wxEVT_COMMAND_BUTTON_CLICKED, this);
+
+ wxBoxSizer* btns = new wxBoxSizer( wxHORIZONTAL );
+ //btns->Add( new wxStaticText( this, -1, wxString::FromAscii(ver.c_str())), 0, wxLEFT|wxTOP, 5 );
+ btns->AddStretchSpacer();
+ btns->Add( close_button, 0, 0, 0 );
+
+ wxBoxSizer* const szr = new wxBoxSizer( wxVERTICAL );
+ szr->Add( m_pad_notebook, 0, wxEXPAND|wxTOP|wxLEFT|wxRIGHT, 5 );
+ szr->Add( btns, 0, wxEXPAND|wxALL, 5 );
+
+ SetSizerAndFit( szr ); // needed
+
+ // not needed here it seems, but it cant hurt
+ //Layout();
+
+ Center();
+
+ // live preview update timer
+ m_update_timer = new wxTimer( this, -1 );
+ Connect( wxID_ANY, wxEVT_TIMER, wxTimerEventHandler( ConfigDialog::UpdateBitmaps ), (wxObject*)0, this );
+ m_update_timer->Start( PREVIEW_UPDATE_TIME, wxTIMER_CONTINUOUS);
+
+
+}
diff --git a/Source/Core/InputUICommon/Src/ConfigDiag.h b/Source/Core/InputUICommon/Src/ConfigDiag.h
new file mode 100644
index 0000000000..98e8e89340
--- /dev/null
+++ b/Source/Core/InputUICommon/Src/ConfigDiag.h
@@ -0,0 +1,245 @@
+// Copyright (C) 2010 Dolphin Project.
+
+// 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/
+
+#ifndef _CONFIGBOX_H_
+#define _CONFIGBOX_H_
+
+#define SLIDER_TICK_COUNT 100
+#define DETECT_WAIT_TIME 1500
+#define PREVIEW_UPDATE_TIME 25
+
+// might have to change this setup for wiimote
+#define PROFILES_PATH "Profiles/"
+
+#include <wx/wx.h>
+#include <wx/listbox.h>
+#include <wx/textctrl.h>
+#include <wx/button.h>
+#include <wx/stattext.h>
+#include <wx/combobox.h>
+#include <wx/checkbox.h>
+#include <wx/notebook.h>
+#include <wx/panel.h>
+#include <wx/spinctrl.h>
+
+#include <sstream>
+#include <vector>
+
+#include "ControllerInterface/ControllerInterface.h"
+#include "ControllerEmu.h"
+#include "InputConfig.h"
+#include "FileSearch.h"
+
+class PadSetting
+{
+protected:
+ PadSetting() {}
+
+public:
+ virtual void UpdateGUI() = 0;
+ virtual void UpdateValue() = 0;
+};
+
+class PadSettingExtension : public wxChoice, public PadSetting
+{
+public:
+ PadSettingExtension( wxWindow* const parent, ControllerEmu::Extension* const ext );
+ void UpdateGUI();
+ void UpdateValue();
+
+ ControllerEmu::Extension* const extension;
+};
+
+class PadSettingChoice : public wxSpinCtrl, public PadSetting
+{
+public:
+ PadSettingChoice( wxWindow* const parent, ControllerEmu::ControlGroup::Setting* const setting )
+ : wxSpinCtrl(parent, -1, wxEmptyString, wxDefaultPosition
+ , wxSize( 54, -1 ), 0, setting->low, setting->high, setting->value * 100)
+ , value(setting->value) {}
+
+ void UpdateGUI();
+ void UpdateValue();
+
+ ControlState& value;
+};
+
+class PadSettingCheckBox : public wxCheckBox, public PadSetting
+{
+public:
+ PadSettingCheckBox( wxWindow* const parent, ControlState& _value, const char* const label );
+ void UpdateGUI();
+ void UpdateValue();
+
+ ControlState& value;
+};
+
+class ControlChooser : public wxStaticBoxSizer
+{
+public:
+ ControlChooser( wxWindow* const parent, ControllerInterface::ControlReference* const ref, wxWindow* const eventsink );
+
+ void UpdateGUI();
+ void UpdateListContents();
+ void UpdateListSelection();
+
+ ControllerInterface::ControlReference* control_reference;
+
+ wxTextCtrl* textctrl;
+ wxListBox* control_lbox;
+ wxChoice* mode_cbox;
+ wxSlider* range_slider;
+
+private:
+ wxStaticText* m_bound_label;
+};
+
+class ControlList : public wxDialog
+{
+public:
+
+ ControlList( wxWindow* const parent, ControllerInterface::ControlReference* const ref, ControlChooser* const chooser );
+
+private:
+ ControlChooser* const m_control_chooser;
+};
+
+class ControlDialog : public wxDialog
+{
+public:
+ ControlDialog( wxWindow* const parent, ControllerInterface::ControlReference* const ref, const std::vector<ControllerInterface::Device*>& devs );
+
+ void SelectControl( wxCommandEvent& event );
+ void DetectControl( wxCommandEvent& event );
+ void ClearControl( wxCommandEvent& event );
+ void SetControl( wxCommandEvent& event );
+ void SetDevice( wxCommandEvent& event );
+
+ ControllerInterface::ControlReference* const control_reference;
+ wxComboBox* device_cbox;
+ ControlChooser* control_chooser;
+};
+
+class ExtensionButton : public wxButton
+{
+public:
+ ExtensionButton( wxWindow* const parent, ControllerEmu::Extension* const ext )
+ : wxButton( parent, -1, wxT("Configure"), wxDefaultPosition )
+ , extension(ext) {}
+
+ ControllerEmu::Extension* const extension;
+};
+
+class ControlButton : public wxButton
+{
+public:
+ ControlButton( wxWindow* const parent, ControllerInterface::ControlReference* const _ref, const unsigned int width, const std::string& label = "" );
+
+ ControllerInterface::ControlReference* const control_reference;
+};
+
+class ControlGroupBox : public wxStaticBoxSizer
+{
+public:
+ ControlGroupBox( ControllerEmu::ControlGroup* const group, wxWindow* const parent, wxWindow* const eventsink );
+
+ ControllerEmu::ControlGroup* control_group;
+ wxStaticBitmap* static_bitmap;
+ std::vector< PadSetting* > options;
+ std::vector< wxButton* > controls;
+ std::vector<ControlButton*> control_buttons;
+};
+
+class ControlGroupsSizer : public wxBoxSizer
+{
+public:
+ ControlGroupsSizer( ControllerEmu* const controller, wxWindow* const parent, wxWindow* const eventsink, std::vector<ControlGroupBox*>* const groups = NULL );
+
+
+};
+
+class ConfigDialog;
+
+class GamepadPage : public wxNotebookPage
+{
+ friend class ConfigDialog;
+
+public:
+ GamepadPage( wxWindow* parent, const unsigned int pad_num, ConfigDialog* const config_dialog );
+
+ void UpdateGUI();
+
+ void RefreshDevices( wxCommandEvent& event );
+
+ void LoadProfile( wxCommandEvent& event );
+ void SaveProfile( wxCommandEvent& event );
+ void DeleteProfile( wxCommandEvent& event );
+
+ void ConfigControl( wxCommandEvent& event );
+ void ClearControl( wxCommandEvent& event );
+ void DetectControl( wxCommandEvent& event );
+
+ void ConfigExtension( wxCommandEvent& event );
+
+ void SetDevice( wxCommandEvent& event );
+
+ void ClearAll( wxCommandEvent& event );
+
+ void AdjustControlOption( wxCommandEvent& event );
+ void AdjustSetting( wxCommandEvent& event );
+
+ wxComboBox* profile_cbox;
+ wxComboBox* device_cbox;
+
+ std::vector<ControlGroupBox*> control_groups;
+
+protected:
+
+ ControllerEmu* const controller;
+
+private:
+
+ ControlDialog* m_control_dialog;
+ ConfigDialog* const m_config_dialog;
+};
+
+class ConfigDialog : public wxDialog
+{
+public:
+
+ ConfigDialog( wxWindow* const parent, Plugin& plugin, const std::string& name, const bool _is_game_running );
+ ~ConfigDialog();
+
+ void ClickSave( wxCommandEvent& event );
+
+ void UpdateDeviceComboBox();
+ void UpdateProfileComboBox();
+
+ void UpdateControlReferences();
+ void UpdateBitmaps(wxTimerEvent&);
+
+ const bool is_game_running;
+
+private:
+
+ wxNotebook* m_pad_notebook;
+ std::vector<GamepadPage*> m_padpages;
+ Plugin& m_plugin;
+ wxTimer* m_update_timer;
+};
+
+#endif
diff --git a/Source/Core/InputUICommon/Src/ConfigDiagBitmaps.cpp b/Source/Core/InputUICommon/Src/ConfigDiagBitmaps.cpp
new file mode 100644
index 0000000000..4a31c112b9
--- /dev/null
+++ b/Source/Core/InputUICommon/Src/ConfigDiagBitmaps.cpp
@@ -0,0 +1,318 @@
+// Copyright (C) 2010 Dolphin Project.
+
+// 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 "ConfigDiag.h"
+
+void ConfigDialog::UpdateBitmaps(wxTimerEvent& WXUNUSED(event))
+{
+ GamepadPage* const current_page = (GamepadPage*)m_pad_notebook->GetPage( m_pad_notebook->GetSelection() );
+
+ std::vector< ControlGroupBox* >::iterator g = current_page->control_groups.begin(),
+ ge = current_page->control_groups.end();
+ for ( ; g != ge; ++g )
+ {
+ // if this control group has a bitmap
+ if ( (*g)->static_bitmap )
+ {
+
+ // don't want game thread updating input when we are using it here
+ if ( false == m_plugin.interface_crit.TryEnter() )
+ return;
+
+ //if ( false == is_game_running )
+ // just always update
+ m_plugin.controller_interface.UpdateInput();
+
+ wxMemoryDC dc;
+ wxBitmap bitmap((*g)->static_bitmap->GetBitmap());
+ dc.SelectObject(bitmap);
+ dc.Clear();
+
+ // label for sticks and stuff
+ if (64 == bitmap.GetHeight())
+ {
+ wxFont small_font(6, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD);
+ dc.SetFont(small_font);
+ dc.SetTextForeground(0xC0C0C0);
+ dc.DrawText(wxString::FromAscii((*g)->control_group->name).Upper(), 4, 2);
+ }
+
+ switch ( (*g)->control_group->type )
+ {
+ case GROUP_TYPE_TILT :
+ case GROUP_TYPE_STICK :
+ case GROUP_TYPE_CURSOR :
+ {
+ // this is starting to be a mess combining all these in one case
+
+ float x = 0, y = 0, z = 0;
+ float xx, yy;
+
+ switch ((*g)->control_group->type)
+ {
+ case GROUP_TYPE_STICK :
+ ((ControllerEmu::AnalogStick*)(*g)->control_group)->GetState( &x, &y, 32.0, 32-1.5 );
+ break;
+ case GROUP_TYPE_TILT :
+ ((ControllerEmu::Tilt*)(*g)->control_group)->GetState( &x, &y, 32.0, 32-1.5 );
+ break;
+ case GROUP_TYPE_CURSOR :
+ ((ControllerEmu::Cursor*)(*g)->control_group)->GetState( &x, &y, &z );
+ x *= (32-1.5); x+= 32;
+ y *= (32-1.5); y+= 32;
+ break;
+ }
+
+ xx = (*g)->control_group->controls[3]->control_ref->State();
+ xx -= (*g)->control_group->controls[2]->control_ref->State();
+ yy = (*g)->control_group->controls[1]->control_ref->State();
+ yy -= (*g)->control_group->controls[0]->control_ref->State();
+ xx *= 32 - 1; xx += 32;
+ yy *= 32 - 1; yy += 32;
+
+ // draw the shit
+
+ // ir cursor forward movement
+ if (GROUP_TYPE_CURSOR == (*g)->control_group->type)
+ {
+ if (z)
+ {
+ dc.SetPen(*wxRED_PEN);
+ dc.SetBrush(*wxRED_BRUSH);
+ }
+ else
+ {
+ dc.SetPen(*wxGREY_PEN);
+ dc.SetBrush(*wxGREY_BRUSH);
+ }
+ dc.DrawRectangle( 0, 31 - z*31, 64, 2);
+ }
+
+ // circle for visual aid for diagonal adjustment
+ dc.SetPen(*wxLIGHT_GREY_PEN);
+ dc.SetBrush(*wxWHITE_BRUSH);
+ if ( GROUP_TYPE_STICK == (*g)->control_group->type )
+ {
+ dc.SetBrush(*wxTRANSPARENT_BRUSH);
+ dc.DrawCircle( 32, 32, 32);
+ }
+ else
+ dc.DrawRectangle( 16, 16, 32, 32 );
+
+ if ( GROUP_TYPE_CURSOR != (*g)->control_group->type )
+ {
+ // deadzone circle
+ dc.SetBrush(*wxLIGHT_GREY_BRUSH);
+ dc.DrawCircle( 32, 32, ((*g)->control_group)->settings[0]->value * 32 );
+ }
+
+ // raw dot
+ dc.SetPen(*wxGREY_PEN);
+ dc.SetBrush(*wxGREY_BRUSH);
+ // i like the dot better than the cross i think
+ dc.DrawRectangle( xx - 2, yy - 2, 4, 4 );
+ //dc.DrawRectangle( xx-1, 64-yy-4, 2, 8 );
+ //dc.DrawRectangle( xx-4, 64-yy-1, 8, 2 );
+
+ // adjusted dot
+ if (x!=32 || y!=32)
+ {
+ dc.SetPen(*wxRED_PEN);
+ dc.SetBrush(*wxRED_BRUSH);
+ dc.DrawRectangle( x-2, 64-y-2, 4, 4 );
+ // i like the dot better than the cross i think
+ //dc.DrawRectangle( x-1, 64-y-4, 2, 8 );
+ //dc.DrawRectangle( x-4, 64-y-1, 8, 2 );
+ }
+
+ }
+ break;
+ case GROUP_TYPE_FORCE :
+ {
+ float raw_dot[3];
+ float adj_dot[3];
+ const float deadzone = 32 * ((*g)->control_group)->settings[0]->value;
+
+ // adjusted
+ ((ControllerEmu::Force*)(*g)->control_group)->GetState( adj_dot, 32.0, 32-1.5 );
+
+ // raw
+ for ( unsigned int i=0; i<3; ++i )
+ {
+ raw_dot[i] = (*g)->control_group->controls[i*2 + 1]->control_ref->State()
+ - (*g)->control_group->controls[i*2]->control_ref->State();
+ raw_dot[i] *= 32 - 1; raw_dot[i] += 32;
+ }
+
+ // deadzone rect for forward/backward visual
+ dc.SetBrush(*wxLIGHT_GREY_BRUSH);
+ dc.SetPen(*wxLIGHT_GREY_PEN);
+ dc.DrawRectangle( 0, 32 - deadzone, 64, deadzone * 2 );
+
+ // raw forward/background line
+ dc.SetPen(*wxGREY_PEN);
+ dc.SetBrush(*wxGREY_BRUSH);
+ dc.DrawRectangle( 0, raw_dot[2] - 1, 64, 2 );
+
+ // adjusted forward/background line
+ if ( adj_dot[2]!=32 )
+ {
+ dc.SetPen(*wxRED_PEN);
+ dc.SetBrush(*wxRED_BRUSH);
+ dc.DrawRectangle( 0, adj_dot[2] - 1, 64, 2 );
+ }
+
+ // a rectangle, for looks i guess
+ dc.SetBrush(*wxWHITE_BRUSH);
+ dc.SetPen(*wxLIGHT_GREY_PEN);
+ dc.DrawRectangle( 16, 16, 32, 32 );
+
+ // deadzone square
+ dc.SetBrush(*wxLIGHT_GREY_BRUSH);
+ dc.DrawRectangle( 32 - deadzone, 32 - deadzone, deadzone * 2, deadzone * 2 );
+
+ // raw dot
+ dc.SetPen(*wxGREY_PEN);
+ dc.SetBrush(*wxGREY_BRUSH);
+ dc.DrawRectangle( raw_dot[1] - 2, raw_dot[0] - 2, 4, 4 );
+
+ // adjusted dot
+ if ( adj_dot[1]!=32 || adj_dot[0]!=32 )
+ {
+ dc.SetPen(*wxRED_PEN);
+ dc.SetBrush(*wxRED_BRUSH);
+ dc.DrawRectangle( adj_dot[1]-2, adj_dot[0]-2, 4, 4 );
+ }
+
+ }
+ break;
+ case GROUP_TYPE_BUTTONS :
+ {
+ const unsigned int button_count = ((unsigned int)(*g)->control_group->controls.size());
+
+ // draw the shit
+ dc.SetPen(*wxGREY_PEN);
+
+ unsigned int * const bitmasks = new unsigned int[ button_count ];
+ for ( unsigned int n = 0; n<button_count; ++n )
+ bitmasks[n] = ( 1 << n );
+
+ unsigned int buttons = 0;
+ ((ControllerEmu::Buttons*)(*g)->control_group)->GetState( &buttons, bitmasks );
+
+ for ( unsigned int n = 0; n<button_count; ++n )
+ {
+ if ( buttons & bitmasks[n] )
+ dc.SetBrush( *wxRED_BRUSH );
+ else
+ {
+ unsigned char amt = 255 - (*g)->control_group->controls[n]->control_ref->State() * 128;
+ dc.SetBrush( wxBrush( wxColor( amt, amt, amt ) ) );
+ }
+ dc.DrawRectangle(n*12, 0, 14, 12);
+ }
+
+ delete[] bitmasks;
+
+ }
+ break;
+ case GROUP_TYPE_TRIGGERS :
+ {
+ const unsigned int trigger_count = ((unsigned int)((*g)->control_group->controls.size()));
+
+ // draw the shit
+ dc.SetPen(*wxGREY_PEN);
+ ControlState deadzone = (*g)->control_group->settings[0]->value;
+
+ unsigned int* const trigs = new unsigned int[trigger_count];
+ ((ControllerEmu::Triggers*)(*g)->control_group)->GetState( trigs, 64 );
+
+ for ( unsigned int n = 0; n < trigger_count; ++n )
+ {
+ ControlState trig_r = (*g)->control_group->controls[n]->control_ref->State();
+
+ // outline
+ dc.SetPen(*wxGREY_PEN);
+ dc.SetBrush(*wxWHITE_BRUSH);
+ dc.DrawRectangle(0, n*12, 64, 14);
+
+ // raw
+ dc.SetBrush(*wxGREY_BRUSH);
+ dc.DrawRectangle(0, n*12, trig_r*64, 14);
+
+ // deadzone affected
+ dc.SetBrush(*wxRED_BRUSH);
+ dc.DrawRectangle(0, n*12, trigs[n], 14);
+ }
+
+ delete[] trigs;
+
+ // deadzone box
+ dc.SetPen(*wxLIGHT_GREY_PEN);
+ dc.SetBrush(*wxTRANSPARENT_BRUSH);
+ dc.DrawRectangle(0, 0, deadzone*64, trigger_count*14);
+
+ }
+ break;
+ case GROUP_TYPE_MIXED_TRIGGERS :
+ {
+ const unsigned int trigger_count = ((unsigned int)((*g)->control_group->controls.size() / 2));
+
+ // draw the shit
+ dc.SetPen(*wxGREY_PEN);
+ ControlState thresh = (*g)->control_group->settings[0]->value;
+
+ for ( unsigned int n = 0; n < trigger_count; ++n )
+ {
+ dc.SetBrush(*wxRED_BRUSH);
+ ControlState trig_d = (*g)->control_group->controls[n]->control_ref->State();
+
+ ControlState trig_a = trig_d > thresh ? 1
+ : (*g)->control_group->controls[n+trigger_count]->control_ref->State();
+
+ dc.DrawRectangle(0, n*12, 64+20, 14);
+ if ( trig_d <= thresh )
+ dc.SetBrush(*wxWHITE_BRUSH);
+ dc.DrawRectangle(trig_a*64, n*12, 64+20, 14);
+ dc.DrawRectangle(64, n*12, 32, 14);
+ }
+
+ // threshold box
+ dc.SetPen(*wxLIGHT_GREY_PEN);
+ dc.SetBrush(*wxTRANSPARENT_BRUSH);
+ dc.DrawRectangle(thresh*64, 0, 128, trigger_count*14);
+
+ }
+ break;
+ default :
+ break;
+ }
+
+ // box outline
+ // Windows XP color
+ dc.SetPen(wxPen(_T("#7f9db9")));
+ dc.SetBrush(*wxTRANSPARENT_BRUSH);
+ dc.DrawRectangle(0, 0, bitmap.GetWidth(), bitmap.GetHeight());
+
+ dc.SelectObject(wxNullBitmap);
+ (*g)->static_bitmap->SetBitmap(bitmap);
+
+ m_plugin.interface_crit.Leave();
+ }
+ }
+
+}
diff --git a/Source/Core/InputUICommon/Src/SConscript b/Source/Core/InputUICommon/Src/SConscript
new file mode 100644
index 0000000000..18d98eed59
--- /dev/null
+++ b/Source/Core/InputUICommon/Src/SConscript
@@ -0,0 +1,14 @@
+# -*- python -*-
+
+Import('env')
+import sys
+
+if not env['HAVE_WX']:
+ Return()
+
+files = [
+ 'ConfigDiag.cpp',
+ 'ConfigDiagBitmaps.cpp',
+ ]
+
+env.StaticLibrary(env['local_libs'] + 'debugger_ui_util', files)