2009-03-23 14:38:06 -04:00
|
|
|
#ifndef INPUT_DEVICE_HPP
|
|
|
|
#define INPUT_DEVICE_HPP
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2010-02-18 16:28:32 -05:00
|
|
|
#include "config/device_config.hpp"
|
|
|
|
#include "input/input.hpp"
|
2010-05-03 14:56:55 -04:00
|
|
|
#include "input/input_manager.hpp"
|
2010-02-18 16:28:32 -05:00
|
|
|
#include "states_screens/state_manager.hpp"
|
2010-09-09 01:28:18 -04:00
|
|
|
#include "utils/no_copy.hpp"
|
2010-04-23 16:36:13 -04:00
|
|
|
/**
|
|
|
|
* \brief Input device type
|
|
|
|
* \ingroup input
|
|
|
|
*/
|
2009-03-23 14:38:06 -04:00
|
|
|
enum DeviceType
|
|
|
|
{
|
|
|
|
DT_KEYBOARD,
|
|
|
|
DT_GAMEPAD
|
|
|
|
};
|
|
|
|
|
2010-04-23 16:36:13 -04:00
|
|
|
/**
|
|
|
|
* \brief base class for input devices
|
|
|
|
* \ingroup input
|
|
|
|
*/
|
2010-09-09 01:28:18 -04:00
|
|
|
class InputDevice: public NoCopy
|
2009-03-23 14:38:06 -04:00
|
|
|
{
|
2009-07-04 16:00:18 -04:00
|
|
|
friend class DeviceManager;
|
2009-03-23 14:38:06 -04:00
|
|
|
protected:
|
|
|
|
DeviceType m_type;
|
2010-02-18 16:28:32 -05:00
|
|
|
StateManager::ActivePlayer* m_player;
|
2009-08-06 15:05:26 -04:00
|
|
|
DeviceConfig* m_configuration;
|
2009-07-04 16:00:18 -04:00
|
|
|
|
2009-03-23 14:38:06 -04:00
|
|
|
public:
|
2010-05-03 14:56:55 -04:00
|
|
|
std::string m_name; //!< if device has a name; unused for keyboards since AFAIK we can't tell keyboards apart
|
2009-03-29 21:15:52 -04:00
|
|
|
|
2009-03-23 14:38:06 -04:00
|
|
|
InputDevice();
|
2009-08-06 15:05:26 -04:00
|
|
|
void setConfiguration(DeviceConfig *config) {m_configuration = config;}
|
|
|
|
DeviceConfig *getConfiguration() {return m_configuration;}
|
|
|
|
|
2009-03-23 14:38:06 -04:00
|
|
|
DeviceType getType() const { return m_type; };
|
2009-03-29 19:37:21 -04:00
|
|
|
|
2010-02-18 16:28:32 -05:00
|
|
|
void setPlayer(StateManager::ActivePlayer* owner);
|
|
|
|
StateManager::ActivePlayer *getPlayer() { return m_player; }
|
2009-03-23 14:38:06 -04:00
|
|
|
};
|
|
|
|
|
2010-04-23 16:36:13 -04:00
|
|
|
/**
|
|
|
|
* \brief specialisation of InputDevice for keyboard type devices
|
|
|
|
* \ingroup input
|
|
|
|
*/
|
2009-03-23 14:38:06 -04:00
|
|
|
class KeyboardDevice : public InputDevice
|
|
|
|
{
|
|
|
|
public:
|
2009-12-27 14:12:44 -05:00
|
|
|
|
|
|
|
|
2009-03-23 14:38:06 -04:00
|
|
|
KeyboardDevice();
|
2009-08-06 14:00:18 -04:00
|
|
|
KeyboardDevice(KeyboardConfig *configuration);
|
2009-03-23 14:38:06 -04:00
|
|
|
|
2009-12-27 14:12:44 -05:00
|
|
|
/**
|
|
|
|
* Checks if this key belongs to this device. if yes, sets action and returns true; otherwise returns false
|
|
|
|
*
|
|
|
|
* \param id ID of the key that was pressed
|
2010-05-03 14:56:55 -04:00
|
|
|
* \param mode Used to determine whether to bind menu actions or game actions
|
2009-12-27 14:12:44 -05:00
|
|
|
* \param[out] action The action associated to this input (only check this value if method returned true)
|
|
|
|
*/
|
2010-11-20 14:10:43 -05:00
|
|
|
bool processAndMapInput(const int id, InputManager::InputDriverMode mode, PlayerAction* action);
|
2009-12-27 14:12:44 -05:00
|
|
|
|
2009-03-23 14:38:06 -04:00
|
|
|
};
|
|
|
|
|
2010-04-23 16:36:13 -04:00
|
|
|
/**
|
|
|
|
* \brief specialisation of Inputdevice for gamepad type devices
|
|
|
|
* \ingroup input
|
|
|
|
*/
|
2009-03-23 14:38:06 -04:00
|
|
|
class GamePadDevice : public InputDevice
|
|
|
|
{
|
2010-02-18 16:28:32 -05:00
|
|
|
void resetAxisDirection(const int axis, Input::AxisDirection direction, StateManager::ActivePlayer* player);
|
2009-05-30 21:27:21 -04:00
|
|
|
bool m_buttonPressed[SEvent::SJoystickEvent::NUMBER_OF_BUTTONS];
|
2009-08-06 14:00:18 -04:00
|
|
|
|
2009-03-23 14:38:06 -04:00
|
|
|
public:
|
2009-08-06 15:05:26 -04:00
|
|
|
Input::AxisDirection *m_prevAxisDirections;
|
2011-01-22 21:35:48 -05:00
|
|
|
|
|
|
|
/** used to determine if an axis is valid; an axis is considered valid when at least 2 different
|
|
|
|
* values are read from this axis (if an axis keeps on sending the exact same value continuously,
|
|
|
|
* chances are that it's not meant by the user - for instance some gamepads have hats or analog
|
|
|
|
* switches that get reported as axis, we even had a report that on linux some hard disks may be
|
|
|
|
* reported as gamepads with uninteresting axis values)
|
|
|
|
*/
|
|
|
|
int *m_prevAxisValue;
|
|
|
|
/** \see m_prevAxisValue */
|
|
|
|
bool *m_axis_ok;
|
|
|
|
|
2009-03-23 14:38:06 -04:00
|
|
|
int m_deadzone;
|
|
|
|
int m_index;
|
2009-04-25 20:12:55 -04:00
|
|
|
int m_axis_count;
|
2009-05-30 21:27:21 -04:00
|
|
|
int m_button_count;
|
2009-03-23 15:09:16 -04:00
|
|
|
|
2010-05-03 14:56:55 -04:00
|
|
|
/** Constructor for GamePadDevice from a connected gamepad for which no configuration existed
|
|
|
|
* (defaults will be used)
|
|
|
|
* \param irrIndex Index of stick as given by irrLicht.
|
|
|
|
*/
|
|
|
|
GamePadDevice(const int irrIndex, const std::string name, const int axis_number,
|
|
|
|
const int btnAmount, GamepadConfig *configuration);
|
2009-12-27 14:12:44 -05:00
|
|
|
~GamePadDevice();
|
2009-03-29 20:58:12 -04:00
|
|
|
|
2009-05-30 21:27:21 -04:00
|
|
|
bool isButtonPressed(const int i);
|
|
|
|
void setButtonPressed(const int i, bool isButtonPressed);
|
|
|
|
|
2009-12-27 14:12:44 -05:00
|
|
|
/**
|
2010-11-20 14:10:43 -05:00
|
|
|
* Invoked when this device it used. Verifies if the key/button that was pressed
|
|
|
|
* is associated with a binding. If yes, sets action and returns true; otherwise returns false.
|
2009-12-27 14:12:44 -05:00
|
|
|
*
|
|
|
|
* \param player Only passed to know where to send 'axis reset's when necessary
|
|
|
|
* \param id ID of the key that was pressed or of the axis that was triggered (depending on
|
|
|
|
* the value of the 'type' parameter)
|
2010-05-03 14:56:55 -04:00
|
|
|
* \param mode Used to determine whether to map menu actions or game actions
|
2009-12-27 14:12:44 -05:00
|
|
|
* \param[out] action The action associated to this input (only check this value if method returned true)
|
2010-11-20 14:10:43 -05:00
|
|
|
*
|
|
|
|
* \return Whether the pressed key/button is bound with an action
|
2009-12-27 14:12:44 -05:00
|
|
|
*/
|
2010-11-20 14:10:43 -05:00
|
|
|
bool processAndMapInput(Input::InputType type, const int id, const int value,
|
|
|
|
InputManager::InputDriverMode mode,
|
|
|
|
StateManager::ActivePlayer* player,
|
|
|
|
PlayerAction* action);
|
2009-12-27 14:12:44 -05:00
|
|
|
|
2009-03-29 19:37:21 -04:00
|
|
|
};
|
2009-03-23 14:38:06 -04:00
|
|
|
|
|
|
|
|
2009-03-30 23:15:41 -04:00
|
|
|
#endif
|
|
|
|
|