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

@ -474,9 +474,9 @@ std::string Joystick::Axis::GetName() const
{
std::ostringstream ss;
// axis
if ( m_index < 6 )
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

@ -262,20 +262,22 @@ std::string KeyboardMouse::Key::GetName() const
std::string KeyboardMouse::Button::GetName() const
{
return std::string("Button ") + char('0'+m_index);
return std::string("Button ") + char('0' + m_index);
}
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;
@ -65,6 +69,20 @@ protected:
private:
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;