2009-03-23 14:38:06 -04:00
|
|
|
#ifndef INPUT_DEVICE_HPP
|
|
|
|
#define INPUT_DEVICE_HPP
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include "input/input.hpp"
|
2009-08-06 14:00:18 -04:00
|
|
|
#include "config/device_config.hpp"
|
2009-03-29 19:37:21 -04:00
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
2009-03-29 20:19:24 -04:00
|
|
|
#include "io/xml_node.hpp"
|
2009-03-23 14:38:06 -04:00
|
|
|
|
2009-07-11 12:50:57 -04:00
|
|
|
class ActivePlayer;
|
2009-07-04 16:00:18 -04:00
|
|
|
|
2009-03-23 14:38:06 -04:00
|
|
|
enum DeviceType
|
|
|
|
{
|
|
|
|
DT_KEYBOARD,
|
|
|
|
DT_GAMEPAD
|
|
|
|
};
|
|
|
|
|
|
|
|
class InputDevice
|
|
|
|
{
|
2009-07-04 16:00:18 -04:00
|
|
|
friend class DeviceManager;
|
2009-03-23 14:38:06 -04:00
|
|
|
protected:
|
|
|
|
DeviceType m_type;
|
2009-07-11 20:18:37 -04:00
|
|
|
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:
|
2009-05-02 20:50:09 -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
|
|
|
|
2009-07-11 12:50:57 -04:00
|
|
|
void setPlayer(ActivePlayer* owner);
|
2009-08-09 15:04:06 -04:00
|
|
|
ActivePlayer *getPlayer() {return m_player;}
|
2009-07-04 16:00:18 -04:00
|
|
|
|
2009-05-23 20:52:31 -04:00
|
|
|
/**
|
|
|
|
* returns a human-readable string for the key binded with the given action
|
|
|
|
*/
|
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
|
|
|
|
* \param[out] action The action associated to this input (only check this value if method returned true)
|
|
|
|
*/
|
|
|
|
bool hasBinding(const int id, PlayerAction* action);
|
|
|
|
|
2009-03-23 14:38:06 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
class GamePadDevice : public InputDevice
|
|
|
|
{
|
2009-07-11 20:18:37 -04:00
|
|
|
void resetAxisDirection(const int axis, Input::AxisDirection direction, 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;
|
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
|
|
|
|
2009-08-06 14:00:18 -04:00
|
|
|
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
|
|
|
/**
|
|
|
|
* Checks if this key belongs to this device. if yes, sets action and returns true; otherwise returns false.
|
|
|
|
*
|
|
|
|
* \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)
|
|
|
|
* \param[out] action The action associated to this input (only check this value if method returned true)
|
|
|
|
*/
|
|
|
|
bool hasBinding(Input::InputType type, const int id, const int value, ActivePlayer* player, PlayerAction* action);
|
|
|
|
|
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
|
|
|
|
|