GCPad/Wiimote New: Added a set defaults button to the config dialog. (gave new wiimote plugin a few default buttons, not done) Moved MSWindows cursor position code to ControllerInterface/DInput (plan on moving Linux's cursor code to Xlib as well). IR Up,Down,L,R now must have Cursor X/Y/-+ mapped for regular mouse control on Windows. (hopefully this isn't too confusing, the reset to default button automatically sets this up). Renamed One,Two,Minus,Plus to 12-+ (you will have to reconfigure these buttons, sorry). Added text labels for the button and trigger preview bitmaps. -other minor stuff.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5865 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Jordan Woyak
2010-07-10 06:48:24 +00:00
parent 2bcdf4f5a4
commit a0aa506453
26 changed files with 359 additions and 222 deletions

View File

@ -307,27 +307,25 @@ ControllerEmu::Cursor::Cursor( const char* const _name, const SWiimoteInitialize
}
void ControllerEmu::LoadDefaults(const ControllerInterface &ciface)
{
// load an empty inifile section, clears everything
IniFile::Section sec;
LoadConfig(&sec);
if (ciface.Devices().size())
{
default_device.FromDevice(ciface.Devices()[0]);
UpdateDefaultDevice();
}
}
// TODO: remove this hackery
void GetMousePos(float& x, float& y, const SWiimoteInitialize* const wiimote_initialize)
{
#if ( defined(_WIN32) || (defined(HAVE_X11) && HAVE_X11))
#if 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
{
@ -344,15 +342,13 @@ void GetMousePos(float& x, float& y, const SWiimoteInitialize* const wiimote_ini
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
}

View File

@ -276,7 +276,7 @@ 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 )
void GetState(C* const x, C* const y, const unsigned int base, const R range, const bool step = true)
{
// this is all a mess
@ -326,15 +326,20 @@ public:
// 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);
// silly
if (step)
{
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);
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 );
@ -421,7 +426,7 @@ public:
virtual std::string GetName() const = 0;
virtual void LoadDefaults() {}
virtual void LoadDefaults(const ControllerInterface& ciface);
virtual void LoadConfig(IniFile::Section *sec, const std::string& base = "");
virtual void SaveConfig(IniFile::Section *sec, const std::string& base = "");

View File

@ -31,7 +31,7 @@ void ControllerInterface::Init()
return;
#ifdef CIFACE_USE_DINPUT
ciface::DInput::Init(m_devices);
ciface::DInput::Init(m_devices, (HWND)m_hwnd);
#endif
#ifdef CIFACE_USE_XINPUT
ciface::XInput::Init(m_devices);

View File

@ -204,7 +204,7 @@ public:
Device::Control* Detect(const unsigned int ms, Device* const device);
};
ControllerInterface() : m_is_init(false) {}
ControllerInterface() : m_is_init(false), m_hwnd(NULL) {}
void SetHwnd(void* const hwnd);
void Init();

View File

@ -61,14 +61,14 @@ std::string GetDeviceName(const LPDIRECTINPUTDEVICE8 device)
return StripSpaces(out);
}
void Init( std::vector<ControllerInterface::Device*>& devices/*, HWND hwnd*/ )
void Init(std::vector<ControllerInterface::Device*>& devices, HWND hwnd)
{
IDirectInput8* idi8;
if (FAILED(DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (LPVOID*)&idi8, NULL)))
return;
#ifdef CIFACE_USE_DINPUT_KBM
InitKeyboardMouse(idi8, devices);
InitKeyboardMouse(idi8, devices, hwnd);
#endif
#ifdef CIFACE_USE_DINPUT_JOYSTICK
InitJoystick(idi8, devices/*, hwnd*/);

View File

@ -23,7 +23,7 @@ BOOL CALLBACK DIEnumDeviceObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVO
BOOL CALLBACK DIEnumDevicesCallback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef);
std::string GetDeviceName(const LPDIRECTINPUTDEVICE8 device);
void Init( std::vector<ControllerInterface::Device*>& devices/*, HWND hwnd*/ );
void Init(std::vector<ControllerInterface::Device*>& devices, HWND hwnd);
}
}

View File

@ -19,7 +19,7 @@ namespace ciface
namespace DInput
{
struct
static struct
{
const BYTE code;
const char* const name;
@ -28,7 +28,7 @@ struct
#include "NamedKeys.h"
};
struct
static struct
{
const BYTE code;
const char* const name;
@ -39,8 +39,13 @@ struct
{ VK_SCROLL, "SCROLL LOCK" }
};
void InitKeyboardMouse( IDirectInput8* const idi8, std::vector<ControllerInterface::Device*>& devices )
// lil silly
static HWND hwnd;
void InitKeyboardMouse(IDirectInput8* const idi8, std::vector<ControllerInterface::Device*>& devices, HWND _hwnd)
{
hwnd = _hwnd;
// mouse and keyboard are a combined device, to allow shift+click and stuff
// if thats dumb, i will make a VirtualDevice class that just uses ranges of inputs/outputs from other devices
// so there can be a separated Keyboard and mouse, as well as combined KeyboardMouse
@ -81,7 +86,7 @@ KeyboardMouse::~KeyboardMouse()
m_mo_device->Release();
}
KeyboardMouse::KeyboardMouse( const LPDIRECTINPUTDEVICE8 kb_device, const LPDIRECTINPUTDEVICE8 mo_device )
KeyboardMouse::KeyboardMouse(const LPDIRECTINPUTDEVICE8 kb_device, const LPDIRECTINPUTDEVICE8 mo_device)
: m_kb_device(kb_device)
, m_mo_device(mo_device)
{
@ -90,16 +95,16 @@ KeyboardMouse::KeyboardMouse( const LPDIRECTINPUTDEVICE8 kb_device, const LPDIRE
m_last_update = GetTickCount();
ZeroMemory( &m_state_in, sizeof(m_state_in) );
ZeroMemory( m_state_out, sizeof(m_state_out) );
ZeroMemory( &m_current_state_out, sizeof(m_current_state_out) );
ZeroMemory(&m_state_in, sizeof(m_state_in));
ZeroMemory(m_state_out, sizeof(m_state_out));
ZeroMemory(&m_current_state_out, sizeof(m_current_state_out));
// KEYBOARD
// add keys
for ( unsigned int i = 0; i < sizeof(named_keys)/sizeof(*named_keys); ++i )
for (unsigned int i = 0; i < sizeof(named_keys)/sizeof(*named_keys); ++i)
AddInput(new Key(i));
// add lights
for ( unsigned int i = 0; i < sizeof(named_lights)/sizeof(*named_lights); ++i )
for (unsigned int i = 0; i < sizeof(named_lights)/sizeof(*named_lights); ++i)
AddOutput(new Light(i));
// MOUSE
@ -109,15 +114,38 @@ KeyboardMouse::KeyboardMouse( const LPDIRECTINPUTDEVICE8 kb_device, const LPDIRE
mouse_caps.dwSize = sizeof(mouse_caps);
m_mo_device->GetCapabilities(&mouse_caps);
// mouse buttons
for ( unsigned int i = 0; i < mouse_caps.dwButtons; ++i )
for (unsigned int i = 0; i < mouse_caps.dwButtons; ++i)
AddInput(new Button(i));
// mouse axes
for ( unsigned int i = 0; i < mouse_caps.dwAxes; ++i )
for (unsigned int i = 0; i < mouse_caps.dwAxes; ++i)
{
// each axis gets a negative and a positive input instance associated with it
AddInput(new Axis(i, (2==i) ? -1 : -MOUSE_AXIS_SENSITIVITY));
AddInput(new Axis(i, -(2==i) ? 1 : MOUSE_AXIS_SENSITIVITY));
}
// cursor, with a hax for-loop
for (unsigned int i=0; i<4; ++i)
AddInput(new Cursor(!!(i&2), !!(i&1)));
}
void GetMousePos(float* const x, float* const y)
{
unsigned int win_width = 2, win_height = 2;
POINT point = { 1, 1 };
GetCursorPos(&point);
// Get the cursor position relative to the upper left corner of the rendering window
ScreenToClient(hwnd, &point);
// Get the size of the rendering window. (In my case Rect.top and Rect.left was zero.)
RECT rect;
GetClientRect(hwnd, &rect);
// Width and height is the size of the rendering window
win_width = rect.right - rect.left;
win_height = rect.bottom - rect.top;
// 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;
}
bool KeyboardMouse::UpdateInput()
@ -148,11 +176,15 @@ bool KeyboardMouse::UpdateInput()
if (SUCCEEDED(kb_hr) && SUCCEEDED(mo_hr))
{
// need to smooth out the axes, otherwise it doesnt work for shit
for ( unsigned int i = 0; i < 3; ++i )
for (unsigned int i = 0; i < 3; ++i)
((&m_state_in.mouse.lX)[i] += (&tmp_mouse.lX)[i]) /= 2;
// copy over the buttons
memcpy( m_state_in.mouse.rgbButtons, tmp_mouse.rgbButtons, sizeof(m_state_in.mouse.rgbButtons) );
memcpy(m_state_in.mouse.rgbButtons, tmp_mouse.rgbButtons, sizeof(m_state_in.mouse.rgbButtons));
// update mouse cursor
GetMousePos(&m_state_in.cursor.x, &m_state_in.cursor.y);
return true;
}
@ -174,17 +206,17 @@ bool KeyboardMouse::UpdateOutput()
};
std::vector< KInput > kbinputs;
for ( unsigned int i = 0; i < sizeof(m_state_out)/sizeof(*m_state_out); ++i )
for (unsigned int i = 0; i < sizeof(m_state_out)/sizeof(*m_state_out); ++i)
{
bool want_on = false;
if ( m_state_out[i] )
if (m_state_out[i])
want_on = m_state_out[i] > GetTickCount() % 255 ; // light should flash when output is 0.5
// lights are set to their original state when output is zero
if ( want_on ^ m_current_state_out[i] )
if (want_on ^ m_current_state_out[i])
{
kbinputs.push_back( KInput( named_lights[i].code ) ); // press
kbinputs.push_back( KInput( named_lights[i].code, true ) ); // release
kbinputs.push_back(KInput(named_lights[i].code)); // press
kbinputs.push_back(KInput(named_lights[i].code, true)); // release
m_current_state_out[i] ^= 1;
}
@ -214,12 +246,12 @@ std::string KeyboardMouse::GetSource() const
ControlState KeyboardMouse::GetInputState(const ControllerInterface::Device::Input* const input) const
{
return ( ((Input*)input)->GetState( &m_state_in ) );
return (((Input*)input)->GetState(&m_state_in));
}
void KeyboardMouse::SetOutputState(const ControllerInterface::Device::Output* const output, const ControlState state)
{
((Output*)output)->SetState( state, m_state_out );
((Output*)output)->SetState(state, m_state_out);
}
// names
@ -236,7 +268,14 @@ std::string KeyboardMouse::Button::GetName() const
std::string KeyboardMouse::Axis::GetName() const
{
std::string tmpstr("Axis ");
tmpstr += "XYZ"[m_index]; tmpstr += ( m_range>0 ? '+' : '-' );
tmpstr += "XYZ"[m_index]; tmpstr += (m_range>0 ? '+' : '-');
return tmpstr;
}
std::string KeyboardMouse::Cursor::GetName() const
{
std::string tmpstr("Cursor ");
tmpstr += "XY"[m_index]; tmpstr += (m_positive ? '+' : '-');
return tmpstr;
}
@ -248,17 +287,22 @@ std::string KeyboardMouse::Light::GetName() const
// get/set state
ControlState KeyboardMouse::Key::GetState(const State* const state) const
{
return ( state->keyboard[named_keys[m_index].code] > 0 );
return (state->keyboard[named_keys[m_index].code] != 0);
}
ControlState KeyboardMouse::Button::GetState(const State* const state) const
{
return ( state->mouse.rgbButtons[m_index] > 0 );
return (state->mouse.rgbButtons[m_index] != 0);
}
ControlState KeyboardMouse::Axis::GetState(const State* const state) const
{
return std::max( 0.0f, ControlState((&state->mouse.lX)[m_index]) / m_range );
return std::max(0.0f, ControlState((&state->mouse.lX)[m_index]) / m_range);
}
ControlState KeyboardMouse::Cursor::GetState(const State* const state) const
{
return std::max(0.0f, ControlState((&state->cursor.x)[m_index]) / (m_positive ? 1.0f : -1.0f));
}
void KeyboardMouse::Light::SetState(const ControlState state, unsigned char* const state_out)

View File

@ -14,7 +14,7 @@ namespace ciface
namespace DInput
{
void InitKeyboardMouse( IDirectInput8* const idi8, std::vector<ControllerInterface::Device*>& devices );
void InitKeyboardMouse(IDirectInput8* const idi8, std::vector<ControllerInterface::Device*>& devices, HWND _hwnd);
class KeyboardMouse : public ControllerInterface::Device
{
@ -27,6 +27,10 @@ protected:
{
BYTE keyboard[256];
DIMOUSESTATE2 mouse;
struct
{
float x, y;
} cursor;
};
class Input : public ControllerInterface::Device::Input
@ -80,6 +84,20 @@ protected:
const LONG m_range;
};
class Cursor : public Input
{
friend class KeyboardMouse;
public:
std::string GetName() const;
bool IsDetectable() { return false; }
protected:
Cursor(const unsigned int index, const bool positive) : m_index(index), m_positive(positive) {}
ControlState GetState(const State* const state) const;
private:
const unsigned int m_index;
const bool m_positive;
};
class Light : public Output
{
friend class KeyboardMouse;

View File

@ -9,7 +9,7 @@ namespace ciface
namespace XInput
{
struct
static struct
{
const char* const name;
const WORD bitmask;
@ -31,13 +31,13 @@ struct
{ "Thumb R", XINPUT_GAMEPAD_RIGHT_THUMB }
};
const char* named_triggers[] =
static const char* const named_triggers[] =
{
"Trigger L",
"Trigger R"
};
const char* named_axes[] =
static const char* const named_axes[] =
{
"Left X",
"Left Y",
@ -45,7 +45,7 @@ const char* named_axes[] =
"Right Y"
};
const char* named_motors[] =
static const char* const named_motors[] =
{
"Motor L",
"Motor R"

View File

@ -43,14 +43,22 @@ bool InputPlugin::LoadConfig()
{
IniFile inifile;
if (false == inifile.Load(std::string(File::GetUserPath(D_CONFIG_IDX)) + ini_name + ".ini"))
{
controllers[0]->LoadDefaults(controller_interface);
return false;
}
std::vector< ControllerEmu* >::const_iterator
i = controllers.begin(),
e = controllers.end();
for ( ; i!=e; ++i ) {
for ( ; i!=e; ++i )
{
// load settings from ini
(*i)->LoadConfig(inifile.GetOrCreateSection((*i)->GetName().c_str()));
// update refs
(*i)->UpdateReferences(controller_interface);
}
return true;
}

View File

@ -3,19 +3,24 @@
#include <stdlib.h>
#include <string.h>
const char* DefaultPort(const int index)
{
static std::string s;
s = "443";
s += (char)('2' + index);
return s.c_str();
}
UDPWrapper::UDPWrapper(int indx, const char* const _name) :
ControllerEmu::ControlGroup(_name,GROUP_TYPE_UDPWII),
inst(NULL), index(indx),
updIR(false),updAccel(false),
updButt(false),udpEn(false)
, port(DefaultPort(indx))
{
char s[5];
sprintf(s,"%d",4432+index);
port=s;
//PanicAlert("UDPWrapper #%d ctor",index);
}
void UDPWrapper::LoadConfig(IniFile::Section *sec, const std::string& defdev, const std::string& base )
{
ControlGroup::LoadConfig(sec,defdev,base);
@ -23,15 +28,11 @@ void UDPWrapper::LoadConfig(IniFile::Section *sec, const std::string& defdev, co
std::string group( base + name ); group += "/";
int _updAccel,_updIR,_updButt,_udpEn;
sec->Get((group + "Enable").c_str(),&_udpEn,0);
char s[5];
sprintf(s,"%d",4432+index);
sec->Get((group + "Port").c_str(),&port,s);
sec->Get((group + "Update_Accel").c_str(),&_updAccel,1);
sec->Get((group + "Update_IR").c_str(),&_updIR,1);
sec->Get((group + "Update_Butt").c_str(),&_updButt,1);
sec->Get((group + "Enable").c_str(),&_udpEn, 0);
sec->Get((group + "Port").c_str(), &port, DefaultPort(index));
sec->Get((group + "Update_Accel").c_str(), &_updAccel, 1);
sec->Get((group + "Update_IR").c_str(), &_updIR, 1);
sec->Get((group + "Update_Butt").c_str(), &_updButt, 1);
udpEn=(_udpEn>0);
updAccel=(_updAccel>0);
@ -46,11 +47,11 @@ void UDPWrapper::SaveConfig(IniFile::Section *sec, const std::string& defdev, co
{
ControlGroup::SaveConfig(sec,defdev,base);
std::string group( base + name ); group += "/";
sec->Set((group + "Enable").c_str(),(int)udpEn);
sec->Set((group + "Port").c_str(),port.c_str());
sec->Set((group + "Update_Accel").c_str(),(int)updAccel);
sec->Set((group + "Update_IR").c_str(),(int)updIR);
sec->Set((group + "Update_Butt").c_str(),(int)updButt);
sec->Set((group + "Enable").c_str(), (int)udpEn, 0);
sec->Set((group + "Port").c_str(), port, DefaultPort(index));
sec->Set((group + "Update_Accel").c_str(), (int)updAccel, 1);
sec->Set((group + "Update_IR").c_str(), (int)updIR, 1);
sec->Set((group + "Update_Butt").c_str(), (int)updButt, 1);
}