2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2014-02-17 10:18:15 +00:00
|
|
|
// 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
|
|
|
|
{
|
2015-07-22 02:28:32 +00:00
|
|
|
// GC
|
2013-04-15 01:39:56 +00:00
|
|
|
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,
|
2015-12-17 17:26:58 +00:00
|
|
|
STICK_MAIN = 10, // Used on Java Side
|
2013-11-18 20:48:08 +00:00
|
|
|
STICK_MAIN_UP = 11,
|
|
|
|
STICK_MAIN_DOWN = 12,
|
|
|
|
STICK_MAIN_LEFT = 13,
|
|
|
|
STICK_MAIN_RIGHT = 14,
|
2015-12-17 17:26:58 +00:00
|
|
|
STICK_C = 15, // Used on Java Side
|
2013-11-18 20:48:08 +00:00
|
|
|
STICK_C_UP = 16,
|
|
|
|
STICK_C_DOWN = 17,
|
|
|
|
STICK_C_LEFT = 18,
|
|
|
|
STICK_C_RIGHT = 19,
|
|
|
|
TRIGGER_L = 20,
|
|
|
|
TRIGGER_R = 21,
|
2015-07-22 02:28:32 +00:00
|
|
|
// Wiimote
|
2015-12-17 17:26:58 +00:00
|
|
|
WIIMOTE_BUTTON_A = 100,
|
|
|
|
WIIMOTE_BUTTON_B = 101,
|
|
|
|
WIIMOTE_BUTTON_MINUS = 102,
|
|
|
|
WIIMOTE_BUTTON_PLUS = 103,
|
|
|
|
WIIMOTE_BUTTON_HOME = 104,
|
|
|
|
WIIMOTE_BUTTON_1 = 105,
|
|
|
|
WIIMOTE_BUTTON_2 = 106,
|
|
|
|
WIIMOTE_UP = 107,
|
|
|
|
WIIMOTE_DOWN = 108,
|
|
|
|
WIIMOTE_LEFT = 109,
|
|
|
|
WIIMOTE_RIGHT = 110,
|
|
|
|
WIIMOTE_IR = 111, // To Be Used on Java Side
|
|
|
|
WIIMOTE_IR_UP = 112,
|
|
|
|
WIIMOTE_IR_DOWN = 113,
|
|
|
|
WIIMOTE_IR_LEFT = 114,
|
|
|
|
WIIMOTE_IR_RIGHT = 115,
|
|
|
|
WIIMOTE_IR_FORWARD = 116,
|
|
|
|
WIIMOTE_IR_BACKWARD = 117,
|
|
|
|
WIIMOTE_IR_HIDE = 118,
|
|
|
|
WIIMOTE_SWING = 119, // To Be Used on Java Side
|
|
|
|
WIIMOTE_SWING_UP = 120,
|
|
|
|
WIIMOTE_SWING_DOWN = 121,
|
|
|
|
WIIMOTE_SWING_LEFT = 122,
|
|
|
|
WIIMOTE_SWING_RIGHT = 123,
|
|
|
|
WIIMOTE_SWING_FORWARD = 124,
|
|
|
|
WIIMOTE_SWING_BACKWARD = 125,
|
|
|
|
WIIMOTE_TILT = 126, // To Be Used on Java Side
|
|
|
|
WIIMOTE_TILT_FORWARD = 127,
|
|
|
|
WIIMOTE_TILT_BACKWARD = 128,
|
|
|
|
WIIMOTE_TILT_LEFT = 129,
|
|
|
|
WIIMOTE_TILT_RIGHT = 130,
|
2016-01-04 12:35:04 +00:00
|
|
|
WIIMOTE_TILT_MODIFIER = 131,
|
2015-12-17 17:26:58 +00:00
|
|
|
WIIMOTE_SHAKE_X = 132,
|
|
|
|
WIIMOTE_SHAKE_Y = 133,
|
|
|
|
WIIMOTE_SHAKE_Z = 134,
|
2015-12-02 20:58:54 +00:00
|
|
|
// Nunchuk
|
2015-12-17 17:26:58 +00:00
|
|
|
NUNCHUK_BUTTON_C = 200,
|
|
|
|
NUNCHUK_BUTTON_Z = 201,
|
|
|
|
NUNCHUK_STICK = 202, // To Be Used on Java Side
|
|
|
|
NUNCHUK_STICK_UP = 203,
|
|
|
|
NUNCHUK_STICK_DOWN = 204,
|
|
|
|
NUNCHUK_STICK_LEFT = 205,
|
|
|
|
NUNCHUK_STICK_RIGHT = 206,
|
|
|
|
NUNCHUK_SWING = 207, // To Be Used on Java Side
|
|
|
|
NUNCHUK_SWING_UP = 208,
|
|
|
|
NUNCHUK_SWING_DOWN = 209,
|
|
|
|
NUNCHUK_SWING_LEFT = 210,
|
|
|
|
NUNCHUK_SWING_RIGHT = 211,
|
|
|
|
NUNCHUK_SWING_FORWARD = 212,
|
|
|
|
NUNCHUK_SWING_BACKWARD = 213,
|
|
|
|
NUNCHUK_TILT = 214, // To Be Used on Java Side
|
|
|
|
NUNCHUK_TILT_FORWARD = 215,
|
|
|
|
NUNCHUK_TILT_BACKWARD = 216,
|
|
|
|
NUNCHUK_TILT_LEFT = 217,
|
|
|
|
NUNCHUK_TILT_RIGHT = 218,
|
2016-01-04 12:35:04 +00:00
|
|
|
NUNCHUK_TILT_MODIFIER = 219,
|
2015-12-17 17:26:58 +00:00
|
|
|
NUNCHUK_SHAKE_X = 220,
|
|
|
|
NUNCHUK_SHAKE_Y = 221,
|
|
|
|
NUNCHUK_SHAKE_Z = 222,
|
2015-12-02 20:58:54 +00:00
|
|
|
// Classic
|
2015-12-17 17:26:58 +00:00
|
|
|
CLASSIC_BUTTON_A = 300,
|
|
|
|
CLASSIC_BUTTON_B = 301,
|
|
|
|
CLASSIC_BUTTON_X = 302,
|
|
|
|
CLASSIC_BUTTON_Y = 303,
|
|
|
|
CLASSIC_BUTTON_MINUS = 304,
|
|
|
|
CLASSIC_BUTTON_PLUS = 305,
|
|
|
|
CLASSIC_BUTTON_HOME = 306,
|
|
|
|
CLASSIC_BUTTON_ZL = 307,
|
|
|
|
CLASSIC_BUTTON_ZR = 308,
|
|
|
|
CLASSIC_DPAD_UP = 309,
|
|
|
|
CLASSIC_DPAD_DOWN = 310,
|
|
|
|
CLASSIC_DPAD_LEFT = 311,
|
|
|
|
CLASSIC_DPAD_RIGHT = 312,
|
|
|
|
CLASSIC_STICK_LEFT = 313, // To Be Used on Java Side
|
|
|
|
CLASSIC_STICK_LEFT_UP = 314,
|
|
|
|
CLASSIC_STICK_LEFT_DOWN = 315,
|
|
|
|
CLASSIC_STICK_LEFT_LEFT = 316,
|
|
|
|
CLASSIC_STICK_LEFT_RIGHT = 317,
|
|
|
|
CLASSIC_STICK_RIGHT = 318, // To Be Used on Java Side
|
|
|
|
CLASSIC_STICK_RIGHT_UP = 319,
|
|
|
|
CLASSIC_STICK_RIGHT_DOWN = 320,
|
|
|
|
CLASSIC_STICK_RIGHT_LEFT = 321,
|
|
|
|
CLASSIC_STICK_RIGHT_RIGHT = 322,
|
|
|
|
CLASSIC_TRIGGER_L = 323,
|
|
|
|
CLASSIC_TRIGGER_R = 324,
|
2015-12-02 20:58:54 +00:00
|
|
|
// Guitar
|
2015-12-17 17:26:58 +00:00
|
|
|
GUITAR_BUTTON_MINUS = 400,
|
|
|
|
GUITAR_BUTTON_PLUS = 401,
|
|
|
|
GUITAR_FRET_GREEN = 402,
|
|
|
|
GUITAR_FRET_RED = 403,
|
|
|
|
GUITAR_FRET_YELLOW = 404,
|
|
|
|
GUITAR_FRET_BLUE = 405,
|
|
|
|
GUITAR_FRET_ORANGE = 406,
|
|
|
|
GUITAR_STRUM_UP = 407,
|
|
|
|
GUITAR_STRUM_DOWN = 408,
|
|
|
|
GUITAR_STICK = 409, // To Be Used on Java Side
|
|
|
|
GUITAR_STICK_UP = 410,
|
|
|
|
GUITAR_STICK_DOWN = 411,
|
|
|
|
GUITAR_STICK_LEFT = 412,
|
|
|
|
GUITAR_STICK_RIGHT = 413,
|
|
|
|
GUITAR_WHAMMY_BAR = 414,
|
2015-12-02 20:58:54 +00:00
|
|
|
// Drums
|
2015-12-17 17:26:58 +00:00
|
|
|
DRUMS_BUTTON_MINUS = 500,
|
|
|
|
DRUMS_BUTTON_PLUS = 501,
|
|
|
|
DRUMS_PAD_RED = 502,
|
|
|
|
DRUMS_PAD_YELLOW = 503,
|
|
|
|
DRUMS_PAD_BLUE = 504,
|
|
|
|
DRUMS_PAD_GREEN = 505,
|
|
|
|
DRUMS_PAD_ORANGE = 506,
|
|
|
|
DRUMS_PAD_BASS = 507,
|
|
|
|
DRUMS_STICK = 508, // To Be Used on Java Side
|
|
|
|
DRUMS_STICK_UP = 509,
|
|
|
|
DRUMS_STICK_DOWN = 510,
|
|
|
|
DRUMS_STICK_LEFT = 511,
|
|
|
|
DRUMS_STICK_RIGHT = 512,
|
2015-12-02 20:58:54 +00:00
|
|
|
// Turntable
|
2015-12-17 17:26:58 +00:00
|
|
|
TURNTABLE_BUTTON_GREEN_LEFT = 600,
|
|
|
|
TURNTABLE_BUTTON_RED_LEFT = 601,
|
|
|
|
TURNTABLE_BUTTON_BLUE_LEFT = 602,
|
|
|
|
TURNTABLE_BUTTON_GREEN_RIGHT = 603,
|
|
|
|
TURNTABLE_BUTTON_RED_RIGHT = 604,
|
|
|
|
TURNTABLE_BUTTON_BLUE_RIGHT = 605,
|
|
|
|
TURNTABLE_BUTTON_MINUS = 606,
|
|
|
|
TURNTABLE_BUTTON_PLUS = 607,
|
|
|
|
TURNTABLE_BUTTON_HOME = 608,
|
|
|
|
TURNTABLE_BUTTON_EUPHORIA = 609,
|
|
|
|
TURNTABLE_TABLE_LEFT = 610, // To Be Used on Java Side
|
|
|
|
TURNTABLE_TABLE_LEFT_LEFT = 611,
|
|
|
|
TURNTABLE_TABLE_LEFT_RIGHT = 612,
|
|
|
|
TURNTABLE_TABLE_RIGHT = 613, // To Be Used on Java Side
|
|
|
|
TURNTABLE_TABLE_RIGHT_LEFT = 614,
|
|
|
|
TURNTABLE_TABLE_RIGHT_RIGHT = 615,
|
|
|
|
TURNTABLE_STICK = 616, // To Be Used on Java Side
|
|
|
|
TURNTABLE_STICK_UP = 617,
|
|
|
|
TURNTABLE_STICK_DOWN = 618,
|
|
|
|
TURNTABLE_STICK_LEFT = 619,
|
|
|
|
TURNTABLE_STICK_RIGHT = 620,
|
|
|
|
TURNTABLE_EFFECT_DIAL = 621,
|
|
|
|
TURNTABLE_CROSSFADE = 622, // To Be Used on Java Side
|
|
|
|
TURNTABLE_CROSSFADE_LEFT = 623,
|
|
|
|
TURNTABLE_CROSSFADE_RIGHT = 624,
|
2019-10-28 15:40:14 +00:00
|
|
|
// Wiimote IMU
|
|
|
|
WIIMOTE_ACCEL_LEFT = 625,
|
|
|
|
WIIMOTE_ACCEL_RIGHT = 626,
|
|
|
|
WIIMOTE_ACCEL_FORWARD = 627,
|
|
|
|
WIIMOTE_ACCEL_BACKWARD = 628,
|
|
|
|
WIIMOTE_ACCEL_UP = 629,
|
|
|
|
WIIMOTE_ACCEL_DOWN = 630,
|
|
|
|
WIIMOTE_GYRO_PITCH_UP = 631,
|
|
|
|
WIIMOTE_GYRO_PITCH_DOWN = 632,
|
|
|
|
WIIMOTE_GYRO_ROLL_LEFT = 633,
|
|
|
|
WIIMOTE_GYRO_ROLL_RIGHT = 634,
|
|
|
|
WIIMOTE_GYRO_YAW_LEFT = 635,
|
|
|
|
WIIMOTE_GYRO_YAW_RIGHT = 636,
|
2018-09-02 20:55:22 +00:00
|
|
|
// Rumble
|
|
|
|
RUMBLE = 700,
|
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;
|
2014-03-29 10:05:44 +00:00
|
|
|
|
2013-11-14 21:17:51 +00:00
|
|
|
public:
|
|
|
|
Button() : m_state(BUTTON_RELEASED) {}
|
|
|
|
void SetState(ButtonState state) { m_state = state; }
|
|
|
|
bool Pressed() { return m_state == BUTTON_PRESSED; }
|
|
|
|
~Button() {}
|
2016-06-24 08:43:46 +00:00
|
|
|
};
|
2013-11-14 21:17:51 +00:00
|
|
|
class Axis
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2013-11-14 21:17:51 +00:00
|
|
|
private:
|
|
|
|
float m_value;
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
public:
|
2013-11-14 21:17:51 +00:00
|
|
|
Axis() : m_value(0.0f) {}
|
|
|
|
void SetValue(float value) { m_value = value; }
|
2013-11-24 21:04:53 +00:00
|
|
|
float AxisValue() { return m_value; }
|
2013-11-14 21:17:51 +00:00
|
|
|
~Axis() {}
|
2013-06-18 12:09:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct sBind
|
|
|
|
{
|
2019-11-27 06:34:01 +00:00
|
|
|
const int m_pad_id;
|
|
|
|
const ButtonType m_button_type;
|
|
|
|
const BindType m_bind_type;
|
|
|
|
const int m_bind;
|
|
|
|
const float m_neg;
|
|
|
|
sBind(int pad_id, ButtonType button_type, BindType bind_type, int bind, float neg)
|
|
|
|
: m_pad_id(pad_id), m_button_type(button_type), m_bind_type(bind_type), m_bind(bind),
|
|
|
|
m_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
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
|
|
|
private:
|
2019-11-27 06:34:01 +00:00
|
|
|
const std::string m_dev;
|
|
|
|
std::map<ButtonType, bool> m_buttons;
|
|
|
|
std::map<ButtonType, float> m_axises;
|
2013-06-18 12:09:20 +00:00
|
|
|
|
2019-11-27 06:34:01 +00:00
|
|
|
// Key is pad_id and ButtonType
|
|
|
|
std::map<std::pair<int, ButtonType>, sBind*> m_input_binds;
|
2014-04-23 08:49:25 +00:00
|
|
|
|
2013-06-18 12:09:20 +00:00
|
|
|
public:
|
2019-11-27 06:34:01 +00:00
|
|
|
InputDevice(std::string dev) : m_dev(dev) {}
|
2013-06-18 12:09:20 +00:00
|
|
|
~InputDevice()
|
|
|
|
{
|
2019-11-27 06:34:01 +00:00
|
|
|
for (const auto& bind : m_input_binds)
|
2014-02-12 15:00:34 +00:00
|
|
|
delete bind.second;
|
2019-11-27 06:34:01 +00:00
|
|
|
m_input_binds.clear();
|
|
|
|
}
|
|
|
|
void AddBind(sBind* bind)
|
|
|
|
{
|
|
|
|
m_input_binds[std::make_pair(bind->m_pad_id, bind->m_button_type)] = bind;
|
2013-06-18 12:09:20 +00:00
|
|
|
}
|
2015-02-23 02:36:30 +00:00
|
|
|
bool PressEvent(int button, int action);
|
2013-12-12 20:42:25 +00:00
|
|
|
void AxisEvent(int axis, float value);
|
2019-11-27 06:34:01 +00:00
|
|
|
bool ButtonValue(int pad_id, ButtonType button);
|
|
|
|
float AxisValue(int pad_id, ButtonType axis);
|
2013-06-18 12:09:20 +00:00
|
|
|
};
|
|
|
|
|
2018-08-26 22:27:27 +00:00
|
|
|
void Init(const std::string&);
|
2020-06-28 21:32:36 +00:00
|
|
|
|
|
|
|
// pad_id is numbered 0 to 3 for GC pads and 4 to 7 for Wiimotes
|
2019-11-27 06:34:01 +00:00
|
|
|
bool GetButtonPressed(int pad_id, ButtonType button);
|
|
|
|
float GetAxisValue(int pad_id, ButtonType axis);
|
2020-06-28 21:32:36 +00:00
|
|
|
|
|
|
|
// emu_pad_id is numbered 0 to 3 for both GC pads and Wiimotes
|
|
|
|
double GetInputRadiusAtAngle(int emu_pad_id, ButtonType stick, double angle);
|
|
|
|
|
2015-05-22 02:22:52 +00:00
|
|
|
bool GamepadEvent(const std::string& dev, int button, int action);
|
|
|
|
void GamepadAxisEvent(const std::string& dev, int axis, float value);
|
2020-06-28 21:32:36 +00:00
|
|
|
|
2013-04-15 01:39:56 +00:00
|
|
|
void Shutdown();
|
2019-05-05 23:48:12 +00:00
|
|
|
} // namespace ButtonManager
|