Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Clean up all the GetName methods for XInput2 controls.
  • Loading branch information
Max-E committed Jul 20, 2013
1 parent 9fbc5ff commit fe2fe8b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 35 deletions.
41 changes: 16 additions & 25 deletions Source/Core/InputCommon/Src/ControllerInterface/Xlib/XInput2.cpp
Expand Up @@ -340,47 +340,38 @@ ControlState KeyboardMouse::Key::GetState() const
return (m_keyboard[m_keycode / 8] & (1 << (m_keycode % 8))) != 0;
}

ControlState KeyboardMouse::Button::GetState() const
{
return ((m_buttons & (1 << m_index)) != 0);
}

ControlState KeyboardMouse::Cursor::GetState() const
KeyboardMouse::Button::Button(unsigned int index, unsigned int& buttons)
: m_buttons(buttons), m_index(index)
{
return std::max(0.0f, m_cursor / (m_positive ? 1.0f : -1.0f));
// this will be a problem if we remove the hardcoded five-button limit
name = std::string("Click ") + (char)('1' + m_index);
}

ControlState KeyboardMouse::Axis::GetState() const
ControlState KeyboardMouse::Button::GetState() const
{
return std::max(0.0f, m_axis / (m_positive ? MOUSE_AXIS_SENSITIVITY : -MOUSE_AXIS_SENSITIVITY));
return ((m_buttons & (1 << m_index)) != 0);
}

std::string KeyboardMouse::Key::GetName() const
KeyboardMouse::Cursor::Cursor(u8 index, bool positive, const float& cursor)
: m_cursor(cursor), m_index(index), m_positive(positive)
{
return m_keyname;
name = std::string("Cursor ") + (char)('X' + m_index) + (m_positive ? '+' : '-');
}

std::string KeyboardMouse::Cursor::GetName() const
ControlState KeyboardMouse::Cursor::GetState() const
{
static char tmpstr[] = "Cursor ..";
tmpstr[7] = (char)('X' + m_index);
tmpstr[8] = (m_positive ? '+' : '-');
return tmpstr;
return std::max(0.0f, m_cursor / (m_positive ? 1.0f : -1.0f));
}

std::string KeyboardMouse::Axis::GetName() const
KeyboardMouse::Axis::Axis(u8 index, bool positive, const float& axis)
: m_axis(axis), m_index(index), m_positive(positive)
{
static char tmpstr[] = "Axis ..";
tmpstr[5] = (char)('X' + m_index);
tmpstr[6] = (m_positive ? '+' : '-');
return tmpstr;
name = std::string("Axis ") + (char)('X' + m_index) + (m_positive ? '+' : '-');
}

std::string KeyboardMouse::Button::GetName() const
ControlState KeyboardMouse::Axis::GetState() const
{
static char tmpstr[] = "Click .";
tmpstr[6] = m_index + '1';
return tmpstr;
return std::max(0.0f, m_axis / (m_positive ? MOUSE_AXIS_SENSITIVITY : -MOUSE_AXIS_SENSITIVITY));
}

}
Expand Down
20 changes: 10 additions & 10 deletions Source/Core/InputCommon/Src/ControllerInterface/Xlib/XInput2.h
Expand Up @@ -40,7 +40,7 @@ class KeyboardMouse : public Core::Device
{
friend class KeyboardMouse;
public:
std::string GetName() const;
std::string GetName() const { return m_keyname; }
Key(Display* display, KeyCode keycode, const char* keyboard);
ControlState GetState() const;

Expand All @@ -54,44 +54,44 @@ class KeyboardMouse : public Core::Device
class Button : public Input
{
public:
std::string GetName() const;
Button(unsigned int index, unsigned int& buttons)
: m_buttons(buttons), m_index(index) {}
std::string GetName() const { return name; }
Button(unsigned int index, unsigned int& buttons);
ControlState GetState() const;

private:
const unsigned int& m_buttons;
const unsigned int m_index;
std::string name;
};

class Cursor : public Input
{
public:
std::string GetName() const;
std::string GetName() const { return name; }
bool IsDetectable() { return false; }
Cursor(u8 index, bool positive, const float& cursor)
: m_cursor(cursor), m_index(index), m_positive(positive) {}
Cursor(u8 index, bool positive, const float& cursor);
ControlState GetState() const;

private:
const float& m_cursor;
const u8 m_index;
const bool m_positive;
std::string name;
};

class Axis : public Input
{
public:
std::string GetName() const;
std::string GetName() const { return name; }
bool IsDetectable() { return false; }
Axis(u8 index, bool positive, const float& axis)
: m_axis(axis), m_index(index), m_positive(positive) {}
Axis(u8 index, bool positive, const float& axis);
ControlState GetState() const;

private:
const float& m_axis;
const u8 m_index;
const bool m_positive;
std::string name;
};

private:
Expand Down

0 comments on commit fe2fe8b

Please sign in to comment.