2013-04-15 01:39:56 +00:00
|
|
|
// Copyright (C) 2003 Dolphin Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
2013-06-18 12:09:20 +00:00
|
|
|
#pragma once
|
|
|
|
|
2013-04-15 01:39:56 +00:00
|
|
|
#include <string>
|
2013-06-18 12:09:20 +00:00
|
|
|
#include <map>
|
2013-04-15 01:39:56 +00:00
|
|
|
#include "CommonPaths.h"
|
2013-09-02 06:40:05 +00:00
|
|
|
#include "VideoBackendBase.h"
|
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; }
|
|
|
|
|
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;
|
|
|
|
std::map<int, bool> _buttons;
|
|
|
|
std::map<int, float> _axises;
|
|
|
|
std::map<ButtonType, sBind*> _binds;
|
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()
|
|
|
|
{
|
2013-11-30 00:37:33 +00:00
|
|
|
for (auto it = _binds.begin(); it != _binds.end(); ++it)
|
2013-09-23 06:43:18 +00:00
|
|
|
delete it->second;
|
2013-06-18 12:09:20 +00:00
|
|
|
}
|
2013-11-30 00:37:33 +00:00
|
|
|
void AddBind(sBind *bind) { _binds[bind->_buttontype] = bind; }
|
2013-11-25 16:58:05 +00:00
|
|
|
void PressEvent(ButtonType button, int action);
|
|
|
|
void AxisEvent(ButtonType axis, float value);
|
|
|
|
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-11-30 00:37:33 +00:00
|
|
|
void TouchEvent(int padID, ButtonType button, int action);
|
|
|
|
void TouchAxisEvent(int padID, ButtonType axis, float value);
|
2013-11-25 16:58:05 +00:00
|
|
|
void GamepadEvent(std::string dev, ButtonType button, int action);
|
|
|
|
void GamepadAxisEvent(std::string dev, ButtonType axis, float value);
|
2013-04-15 01:39:56 +00:00
|
|
|
void Shutdown();
|
|
|
|
}
|