New Wiimote Plugin: Moved Linux cursor position code into ControllerInterface/Xlib. (absolute cursor position can be mapped to something other than IR camera) (code fixed by Glennrics) Put the UDP Wiimote dialog's Update Buttons,Update IR,Update Nunchuk... checkboxes in an "Update" group box. Fixed some Linux config dialog problems. (thanks Glennrics again) Some other minor cleanup in ControllerInterface. (changed some std::string/stringstream to char[] where possible) Removed a warning in DX11 plugin.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5880 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Jordan Woyak 2010-07-16 03:43:11 +00:00
parent f438532879
commit deffc95794
15 changed files with 146 additions and 130 deletions

View File

@ -397,7 +397,11 @@ THREAD_RETURN EmuThread(void *pArg)
Plugins.GetDSP()->Initialize((void *)&dspInit);
#if defined(HAVE_X11) && HAVE_X11
GCPad_Init(g_pXWindow);
#else
GCPad_Init(g_pWindowHandle);
#endif
// Load and Init WiimotePlugin - only if we are booting in wii mode
if (_CoreParameter.bWii)

View File

@ -955,7 +955,8 @@ void CFrame::OnPluginPAD(wxCommandEvent& WXUNUSED (event))
else
{
#if defined(HAVE_X11) && HAVE_X11
GCPad_Init(X11Utils::XDisplayFromHandle(GetHandle()));
Window win = X11Utils::XWindowFromHandle(GetHandle());
GCPad_Init(&win);
#else
GCPad_Init(GetHandle());
#endif

View File

@ -319,36 +319,3 @@ void ControllerEmu::LoadDefaults(const ControllerInterface &ciface)
UpdateDefaultDevice();
}
}
// TODO: remove this hackery
void GetMousePos(float& x, float& y, const SWiimoteInitialize* const wiimote_initialize)
{
#if defined(HAVE_X11) && HAVE_X11
unsigned int win_width = 2, win_height = 2;
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);
// 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

@ -56,8 +56,6 @@ const char * const named_directions[] =
"Right"
};
void GetMousePos(float& x, float& y, const SWiimoteInitialize* const wiimote_initialize);
class ControllerEmu
{
public:
@ -373,18 +371,8 @@ public:
}
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->BoundCount() || controls[1]->control_ref->BoundCount() )
yy = controls[0]->control_ref->State() - controls[1]->control_ref->State();
else
yy = -yy;
if ( controls[2]->control_ref->BoundCount() || controls[3]->control_ref->BoundCount() )
xx = controls[3]->control_ref->State() - controls[2]->control_ref->State();
float yy = controls[0]->control_ref->State() - controls[1]->control_ref->State();
float xx = controls[3]->control_ref->State() - controls[2]->control_ref->State();
// adjust cursor according to settings
if (adjusted)

View File

@ -476,7 +476,7 @@ std::string Joystick::Axis::GetName() const
// axis
if (m_index < 6)
{
ss << "Axis " << "XYZ"[m_index%3];
ss << "Axis " << (char)('X' + (m_index % 3));
if ( m_index > 2 )
ss << 'r';
}
@ -484,15 +484,16 @@ std::string Joystick::Axis::GetName() const
else
ss << "Slider " << m_index-6;
ss << ( m_range>0 ? '+' : '-' );
ss << (m_range<0 ? '-' : '+');
return ss.str();
}
std::string Joystick::Hat::GetName() const
{
std::ostringstream ss;
ss << "Hat " << m_index << ' ' << "NESW"[m_direction];
return ss.str();
static char tmpstr[] = "Hat . .";
tmpstr[4] = (char)('0' + m_index);
tmpstr[6] = "NESW"[m_direction];
return tmpstr;
}
std::string Joystick::Force::GetName() const

View File

@ -267,15 +267,17 @@ std::string KeyboardMouse::Button::GetName() const
std::string KeyboardMouse::Axis::GetName() const
{
std::string tmpstr("Axis ");
tmpstr += "XYZ"[m_index]; tmpstr += (m_range>0 ? '+' : '-');
static char tmpstr[] = "Axis ..";
tmpstr[5] = (char)('X' + m_index);
tmpstr[6] = (m_range<0 ? '-' : '+');
return tmpstr;
}
std::string KeyboardMouse::Cursor::GetName() const
{
std::string tmpstr("Cursor ");
tmpstr += "XY"[m_index]; tmpstr += (m_positive ? '+' : '-');
static char tmpstr[] = "Cursor ..";
tmpstr[7] = (char)('X' + m_index);
tmpstr[8] = (m_positive ? '+' : '-');
return tmpstr;
}

View File

@ -262,15 +262,17 @@ std::string Joystick::Button::GetName() const
std::string Joystick::Axis::GetName() const
{
std::ostringstream ss;
ss << "Axis " << m_index << ( m_range>0 ? '+' : '-' );
ss << "Axis " << m_index << (m_range<0 ? '-' : '+');
return ss.str();
}
std::string Joystick::Hat::GetName() const
{
std::ostringstream ss;
ss << "Hat " << m_index << ' ' << "NESW"[m_direction];
return ss.str();
static char tmpstr[] = "Hat . .";
// I don't think more than 10 hats are supported
tmpstr[4] = (char)('0' + m_index);
tmpstr[6] = "NESW"[m_direction];
return tmpstr;
}
ControlState Joystick::Button::GetState( SDL_Joystick* const js ) const

View File

@ -170,7 +170,7 @@ std::string Device::Button::GetName() const
std::string Device::Axis::GetName() const
{
return std::string(named_axes[m_index]) + ( m_range>0 ? '+' : '-' );
return std::string(named_axes[m_index]) + (m_range<0 ? '-' : '+');
}
std::string Device::Trigger::GetName() const

View File

@ -7,16 +7,14 @@ namespace Xlib
void Init(std::vector<ControllerInterface::Device*>& devices, void* const hwnd)
{
// mouse will be added to this, Keyboard class will be turned into KeyboardMouse
// single device for combined keyboard/mouse, this will allow combinations like shift+click more easily
devices.push_back(new Keyboard((Display*)hwnd));
devices.push_back(new KeyboardMouse(*(Window*)hwnd));
}
Keyboard::Keyboard(Display* display) : m_display(display)
KeyboardMouse::KeyboardMouse(Window window) : m_window(window)
{
memset(&m_state, 0, sizeof(m_state));
m_window = DefaultRootWindow(m_display);
m_display = XOpenDisplay(NULL);
int min_keycode, max_keycode;
XDisplayKeycodes(m_display, &min_keycode, &max_keycode);
@ -37,24 +35,28 @@ Keyboard::Keyboard(Display* display) : m_display(display)
AddInput(new Button(Button3Mask));
AddInput(new Button(Button4Mask));
AddInput(new Button(Button5Mask));
// Mouse Cursor, X-/+ and Y-/+
for (unsigned int i=0; i<4; ++i)
AddInput(new Cursor(!!(i&2), !!(i&1)));
}
Keyboard::~Keyboard()
KeyboardMouse::~KeyboardMouse()
{
XCloseDisplay(m_display);
}
ControlState Keyboard::GetInputState(const ControllerInterface::Device::Input* const input) const
ControlState KeyboardMouse::GetInputState(const ControllerInterface::Device::Input* const input) const
{
return ((Input*)input)->GetState(&m_state);
}
void Keyboard::SetOutputState(const ControllerInterface::Device::Output* const output, const ControlState state)
void KeyboardMouse::SetOutputState(const ControllerInterface::Device::Output* const output, const ControlState state)
{
}
bool Keyboard::UpdateInput()
bool KeyboardMouse::UpdateInput()
{
XQueryKeymap(m_display, m_state.keyboard);
@ -62,33 +64,40 @@ bool Keyboard::UpdateInput()
Window root, child;
XQueryPointer(m_display, m_window, &root, &child, &root_x, &root_y, &win_x, &win_y, &m_state.buttons);
// update mouse cursor
XWindowAttributes win_attribs;
XGetWindowAttributes(m_display, m_window, &win_attribs);
// the mouse position as a range from -1 to 1
m_state.cursor.x = (float)win_x / (float)win_attribs.width * 2 - 1;
m_state.cursor.y = (float)win_y / (float)win_attribs.height * 2 - 1;
return true;
}
bool Keyboard::UpdateOutput()
bool KeyboardMouse::UpdateOutput()
{
return true;
}
std::string Keyboard::GetName() const
std::string KeyboardMouse::GetName() const
{
return "Keyboard";
//return "Keyboard Mouse"; // change to this later
return "Keyboard Mouse";
}
std::string Keyboard::GetSource() const
std::string KeyboardMouse::GetSource() const
{
return "Xlib";
}
int Keyboard::GetId() const
int KeyboardMouse::GetId() const
{
return 0;
}
Keyboard::Key::Key(Display* const display, KeyCode keycode)
KeyboardMouse::Key::Key(Display* const display, KeyCode keycode)
: m_display(display), m_keycode(keycode)
{
int i = 0;
@ -112,22 +121,35 @@ Keyboard::Key::Key(Display* const display, KeyCode keycode)
m_keyname = std::string(XKeysymToString(keysym));
}
ControlState Keyboard::Key::GetState(const State* const state) const
ControlState KeyboardMouse::Key::GetState(const State* const state) const
{
return (state->keyboard[m_keycode/8] & (1 << (m_keycode%8))) != 0;
}
ControlState Keyboard::Button::GetState(const State* const state) const
ControlState KeyboardMouse::Button::GetState(const State* const state) const
{
return ((state->buttons & m_index) > 0);
}
std::string Keyboard::Key::GetName() const
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));
}
std::string KeyboardMouse::Key::GetName() const
{
return m_keyname;
}
std::string Keyboard::Button::GetName() const
std::string KeyboardMouse::Cursor::GetName() const
{
static char tmpstr[] = "Cursor ..";
tmpstr[7] = (char)('X' + m_index);
tmpstr[8] = (m_positive ? '+' : '-');
return tmpstr;
}
std::string KeyboardMouse::Button::GetName() const
{
char button = '0';
switch (m_index)
@ -139,7 +161,9 @@ std::string Keyboard::Button::GetName() const
case Button5Mask: button = '5'; break;
}
return std::string("Button ") + button;
static char tmpstr[] = "Button .";
tmpstr[7] = button;
return tmpstr;
}
}

View File

@ -12,7 +12,7 @@ namespace Xlib
void Init(std::vector<ControllerInterface::Device*>& devices, void* const hwnd);
class Keyboard : public ControllerInterface::Device
class KeyboardMouse : public ControllerInterface::Device
{
friend class ControllerInterface;
friend class ControllerInterface::ControlReference;
@ -23,11 +23,15 @@ protected:
{
char keyboard[32];
unsigned int buttons;
struct
{
float x, y;
} cursor;
};
class Input : public ControllerInterface::Device::Input
{
friend class Keyboard;
friend class KeyboardMouse;
protected:
virtual ControlState GetState(const State* const state) const = 0;
@ -35,7 +39,7 @@ protected:
class Key : public Input
{
friend class Keyboard;
friend class KeyboardMouse;
public:
std::string GetName() const;
@ -53,7 +57,7 @@ protected:
class Button : public Input
{
friend class Keyboard;
friend class KeyboardMouse;
public:
std::string GetName() const;
@ -66,6 +70,20 @@ protected:
const unsigned int m_index;
};
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;
};
bool UpdateInput();
bool UpdateOutput();
@ -73,8 +91,8 @@ protected:
void SetOutputState(const ControllerInterface::Device::Output* const output, const ControlState state);
public:
Keyboard(Display* display);
~Keyboard();
KeyboardMouse(Window window);
~KeyboardMouse();
std::string GetName() const;
std::string GetSource() const;

View File

@ -116,23 +116,23 @@ UDPConfigDiag::UDPConfigDiag(wxWindow * const parent, UDPWrapper * _wrp) :
wxDialog(parent, -1, wxT("UDP Wiimote"), wxDefaultPosition, wxDefaultSize),
wrp(_wrp)
{
wxBoxSizer * outer_sizer = new wxBoxSizer(wxVERTICAL);
wxBoxSizer * sizer1 = new wxBoxSizer(wxVERTICAL);
wxBoxSizer * sizer2 = new wxBoxSizer(wxVERTICAL);
outer_sizer ->Add(sizer1, 0, wxUP | wxLEFT| wxRIGHT | wxEXPAND, 10);
outer_sizer ->Add(sizer2, 1, wxALL | wxEXPAND, 10);
wxBoxSizer *const outer_sizer = new wxBoxSizer(wxVERTICAL);
wxBoxSizer *const sizer1 = new wxBoxSizer(wxVERTICAL);
wxStaticBoxSizer *const sizer2 = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Update"));
outer_sizer->Add(sizer1, 0, wxTOP | wxLEFT | wxRIGHT | wxEXPAND, 5);
outer_sizer->Add(sizer2, 1, wxLEFT | wxRIGHT | wxEXPAND, 10);
enable = new wxCheckBox(this,wxID_ANY,wxT("Enable"));
butt = new wxCheckBox(this,wxID_ANY,wxT("Update Buttons"));
accel = new wxCheckBox(this,wxID_ANY,wxT("Update Acceleration"));
point = new wxCheckBox(this,wxID_ANY,wxT("Update IR Pointer"));
nun = new wxCheckBox(this,wxID_ANY,wxT("Update Nunchuk"));
nunaccel = new wxCheckBox(this,wxID_ANY,wxT("Update Nunchuk Acceleration"));
butt = new wxCheckBox(this,wxID_ANY,wxT("Buttons"));
accel = new wxCheckBox(this,wxID_ANY,wxT("Acceleration"));
point = new wxCheckBox(this,wxID_ANY,wxT("IR Pointer"));
nun = new wxCheckBox(this,wxID_ANY,wxT("Nunchuk"));
nunaccel = new wxCheckBox(this,wxID_ANY,wxT("Nunchuk Acceleration"));
wxButton *const ok_butt = new wxButton(this,wxID_ANY,wxT("OK"));
wxButton * ok_butt = new wxButton(this,wxID_ANY,wxT("OK"));
wxBoxSizer * port_sizer = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer *const port_sizer = new wxBoxSizer(wxHORIZONTAL);
port_sizer->Add(new wxStaticText(this, wxID_ANY, wxT("UDP Port:")), 0, wxALIGN_CENTER);
port_tbox = new wxTextCtrl(this, wxID_ANY, wxString::FromUTF8(wrp->port.c_str()));
port_sizer->Add(port_tbox, 1, wxLEFT | wxEXPAND , 5);
@ -154,7 +154,7 @@ UDPConfigDiag::UDPConfigDiag(wxWindow * const parent, UDPWrapper * _wrp) :
nunaccel->SetValue(wrp->updNunAccel);
sizer1->Add(enable, 1, wxALL | wxEXPAND, 5);
sizer1->Add(port_sizer, 1,wxDOWN | wxLEFT| wxRIGHT | wxEXPAND,5);
sizer1->Add(port_sizer, 1, wxBOTTOM | wxLEFT| wxRIGHT | wxEXPAND, 5);
sizer2->Add(butt, 1, wxALL | wxEXPAND, 5);
sizer2->Add(accel, 1, wxALL | wxEXPAND, 5);
@ -162,7 +162,7 @@ UDPConfigDiag::UDPConfigDiag(wxWindow * const parent, UDPWrapper * _wrp) :
sizer2->Add(nun, 1, wxALL | wxEXPAND, 5);
sizer2->Add(nunaccel, 1, wxALL | wxEXPAND, 5);
outer_sizer->Add(ok_butt,0, wxDOWN | wxLEFT| wxRIGHT | wxALIGN_RIGHT,10);
outer_sizer->Add(ok_butt, 0, wxALL | wxALIGN_RIGHT, 5);
SetSizerAndFit(outer_sizer);
Layout();

View File

@ -379,7 +379,7 @@ void ControlDialog::AppendControl(wxCommandEvent& event)
// o boy!, hax
const wxString lbl = ((wxButton*)event.GetEventObject())->GetLabel();
wxString expr = textctrl->GetLabel();
wxString expr = textctrl->GetValue();
// append the operator to the expression
if (wxT('!') == lbl[0] || false == expr.empty())
@ -449,6 +449,9 @@ void ControlDialog::DetectControl(wxCommandEvent& event)
{
btn->SetLabel(wxT("[ waiting ]"));
// apparently, this makes the "waiting" text work on Linux
wxYield();
m_plugin.controls_crit.Enter(); // enter
ControllerInterface::Device::Control* const ctrl = control_reference->Detect(DETECT_WAIT_TIME, dev);
m_plugin.controls_crit.Leave(); // leave
@ -471,6 +474,9 @@ void GamepadPage::DetectControl( wxCommandEvent& event )
{
btn->SetLabel(wxT("[ waiting ]"));
// apparently, this makes the "waiting" text work on Linux
wxYield();
m_plugin.controls_crit.Enter(); // enter
ControllerInterface::Device::Control* const ctrl = btn->control_reference->Detect(DETECT_WAIT_TIME, dev);
@ -900,7 +906,7 @@ GamepadPage::GamepadPage( wxWindow* parent, InputPlugin& plugin, const unsigned
device_sbox->Add( refresh_button, 0, wxRIGHT|wxBOTTOM, 3 );
wxButton* const default_button = new wxButton(this, -1, wxT("Default"), wxDefaultPosition, wxSize(48,-1));
wxButton* const clearall_button = new wxButton( this, -1, wxT("Clear"), wxDefaultPosition, wxSize(48,-1) );
wxButton* const clearall_button = new wxButton(this, -1, wxT("Clear"), wxDefaultPosition, wxSize(58,-1));
wxStaticBoxSizer* const clear_sbox = new wxStaticBoxSizer( wxHORIZONTAL, this, wxT("Reset") );
clear_sbox->Add(default_button, 1, wxLEFT, 3);

View File

@ -255,6 +255,7 @@ unsigned int GetMaxTextureSize()
case D3D_FEATURE_LEVEL_9_2:
case D3D_FEATURE_LEVEL_9_1:
default:
return 2048;
}
}

View File

@ -729,7 +729,7 @@ void Wiimote::LoadDefaults(const ControllerInterface& ciface)
set_control(m_shake, i, "Button 2");
// IR
#ifdef _WIN32
#ifndef __APPLE__
set_control(m_ir, 0, "Cursor Y-");
set_control(m_ir, 1, "Cursor Y+");
set_control(m_ir, 2, "Cursor X-");

View File

@ -281,9 +281,7 @@ void DllConfig(HWND _hParent)
{
#if defined(HAVE_X11) && HAVE_X11
Window win = GDK_WINDOW_XID(GTK_WIDGET(_hParent)->window);
g_WiimoteInitialize.hWnd = GDK_WINDOW_XDISPLAY(GTK_WIDGET(_hParent)->window);
g_WiimoteInitialize.pXWindow = &win;
InitPlugin(g_WiimoteInitialize.hWnd);
InitPlugin(&win);
#else
InitPlugin(_hParent);
#endif
@ -348,7 +346,11 @@ void Initialize(void *init)
{
g_WiimoteInitialize = *(SWiimoteInitialize*)init;
if ( false == g_plugin.controller_interface.IsInit() )
#if defined(HAVE_X11) && HAVE_X11
InitPlugin( g_WiimoteInitialize.pXWindow );
#else
InitPlugin( g_WiimoteInitialize.hWnd );
#endif
}
// ___________________________________________________________________________