2014-02-17 10:18:15 +00:00
|
|
|
// Copyright 2014 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2013-04-15 01:39:56 +00:00
|
|
|
|
2013-06-18 12:09:20 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <map>
|
2014-02-17 10:18:15 +00:00
|
|
|
#include <string>
|
2013-04-15 01:39:56 +00:00
|
|
|
|
|
|
|
namespace ButtonManager
|
|
|
|
{
|
|
|
|
enum ButtonType
|
|
|
|
{
|
|
|
|
BUTTON_A = 0,
|
2013-11-18 20:48:08 +00:00
|
|
|
BUTTON_B = 1,
|
|
|
|
BUTTON_START = 2,
|
|
|
|
BUTTON_X = 3,
|
|
|
|
BUTTON_Y = 4,
|
|
|
|
BUTTON_Z = 5,
|
|
|
|
BUTTON_UP = 6,
|
|
|
|
BUTTON_DOWN = 7,
|
|
|
|
BUTTON_LEFT = 8,
|
|
|
|
BUTTON_RIGHT = 9,
|
|
|
|
STICK_MAIN = 10, /* Used on Java Side */
|
|
|
|
STICK_MAIN_UP = 11,
|
|
|
|
STICK_MAIN_DOWN = 12,
|
|
|
|
STICK_MAIN_LEFT = 13,
|
|
|
|
STICK_MAIN_RIGHT = 14,
|
|
|
|
STICK_C = 15, /* Used on Java Side */
|
|
|
|
STICK_C_UP = 16,
|
|
|
|
STICK_C_DOWN = 17,
|
|
|
|
STICK_C_LEFT = 18,
|
|
|
|
STICK_C_RIGHT = 19,
|
|
|
|
TRIGGER_L = 20,
|
|
|
|
TRIGGER_R = 21,
|
2013-04-15 01:39:56 +00:00
|
|
|
};
|
|
|
|
enum ButtonState
|
|
|
|
{
|
|
|
|
BUTTON_RELEASED = 0,
|
|
|
|
BUTTON_PRESSED = 1
|
|
|
|
};
|
2013-06-18 12:09:20 +00:00
|
|
|
enum BindType
|
|
|
|
{
|
|
|
|
BIND_BUTTON = 0,
|
|
|
|
BIND_AXIS
|
|
|
|
};
|
2013-04-15 01:39:56 +00:00
|
|
|
class Button
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
ButtonState m_state;
|
|
|
|
public:
|
2013-10-26 10:36:20 +00:00
|
|
|
Button() : m_state(BUTTON_RELEASED) {}
|
2013-04-15 01:39:56 +00:00
|
|
|
void SetState(ButtonState state) { m_state = state; }
|
|
|
|
bool Pressed() { return m_state == BUTTON_PRESSED; }
|
2014-03-29 10:05:44 +00:00
|
|
|
|
2013-11-14 21:17:51 +00:00
|
|
|
~Button() {}
|
|
|
|
};
|
|
|
|
class Axis
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
float m_value;
|
|
|
|
public:
|
|
|
|
Axis() : m_value(0.0f) {}
|
|
|
|
void SetValue(float value) { m_value = value; }
|
|
|
|
float AxisValue() { return m_value; }
|
|
|
|
|
|
|
|
~Axis() {}
|
2013-06-18 12:09:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct sBind
|
|
|
|
{
|
2013-11-30 00:37:33 +00:00
|
|
|
const int _padID;
|
|
|
|
const ButtonType _buttontype;
|
|
|
|
const BindType _bindtype;
|
|
|
|
const int _bind;
|
|
|
|
const float _neg;
|
2013-11-25 16:58:05 +00:00
|
|
|
sBind(int padID, ButtonType buttontype, BindType bindtype, int bind, float neg)
|
2013-11-30 00:37:33 +00:00
|
|
|
: _padID(padID), _buttontype(buttontype), _bindtype(bindtype), _bind(bind), _neg(neg)
|
2013-06-18 12:09:20 +00:00
|
|
|
{}
|
2013-04-15 01:39:56 +00:00
|
|
|
};
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-06-18 12:09:20 +00:00
|
|
|
|
|
|
|
class InputDevice
|
|
|
|
{
|
|
|
|
private:
|
2013-11-30 00:37:33 +00:00
|
|
|
const std::string _dev;
|
2013-12-12 20:42:25 +00:00
|
|
|
std::map<ButtonType, bool> _buttons;
|
|
|
|
std::map<ButtonType, float> _axises;
|
2014-04-23 08:49:25 +00:00
|
|
|
|
|
|
|
// Key is padID and ButtonType
|
|
|
|
std::map<std::pair<int, ButtonType>, sBind*> _inputbinds;
|
2013-06-18 12:09:20 +00:00
|
|
|
public:
|
|
|
|
InputDevice(std::string dev)
|
2013-11-30 00:37:33 +00:00
|
|
|
: _dev(dev) {}
|
2013-06-18 12:09:20 +00:00
|
|
|
~InputDevice()
|
|
|
|
{
|
2014-04-23 08:49:25 +00:00
|
|
|
for (const auto& bind : _inputbinds)
|
2014-02-12 15:00:34 +00:00
|
|
|
delete bind.second;
|
2014-04-23 08:49:25 +00:00
|
|
|
_inputbinds.clear();
|
2013-06-18 12:09:20 +00:00
|
|
|
}
|
2014-11-14 19:46:49 +00:00
|
|
|
void AddBind(sBind* bind) { _inputbinds[std::make_pair(bind->_padID, bind->_buttontype)] = bind; }
|
2013-12-12 20:42:25 +00:00
|
|
|
void PressEvent(int button, int action);
|
|
|
|
void AxisEvent(int axis, float value);
|
2013-11-25 16:58:05 +00:00
|
|
|
bool ButtonValue(int padID, ButtonType button);
|
|
|
|
float AxisValue(int padID, ButtonType axis);
|
2013-06-18 12:09:20 +00:00
|
|
|
};
|
|
|
|
|
2013-04-15 01:39:56 +00:00
|
|
|
void Init();
|
2013-11-24 21:04:53 +00:00
|
|
|
bool GetButtonPressed(int padID, ButtonType button);
|
|
|
|
float GetAxisValue(int padID, ButtonType axis);
|
2013-12-12 20:42:25 +00:00
|
|
|
void GamepadEvent(std::string dev, int button, int action);
|
|
|
|
void GamepadAxisEvent(std::string dev, int axis, float value);
|
2013-04-15 01:39:56 +00:00
|
|
|
void Shutdown();
|
|
|
|
}
|