2009-03-23 14:38:06 -04:00
|
|
|
#ifndef INPUT_DEVICE_HPP
|
|
|
|
#define INPUT_DEVICE_HPP
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include "input/input.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
|
|
|
|
};
|
|
|
|
|
|
|
|
struct KeyBinding
|
|
|
|
{
|
2009-03-29 11:51:55 -04:00
|
|
|
Input::InputType type;
|
|
|
|
|
|
|
|
// key for keyboards, axis for gamepads
|
|
|
|
int id;
|
|
|
|
|
|
|
|
Input::AxisDirection dir; // for gamepads
|
2009-03-23 14:38:06 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
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-04 13:24:09 -04:00
|
|
|
KeyBinding m_default_bindings[PA_COUNT];
|
2009-03-23 14:38:06 -04:00
|
|
|
|
2009-07-04 16:00:18 -04:00
|
|
|
int m_player_id;
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
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-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
|
|
|
|
*/
|
|
|
|
std::string getBindingAsString(const PlayerAction action) const;
|
|
|
|
|
2009-03-29 19:37:21 -04:00
|
|
|
void serialize(std::ofstream& stream);
|
2009-03-29 20:19:24 -04:00
|
|
|
bool deserializeAction(irr::io::IrrXMLReader* xml);
|
2009-03-23 14:38:06 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
class KeyboardDevice : public InputDevice
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
KeyboardDevice();
|
2009-03-29 20:58:12 -04:00
|
|
|
KeyboardDevice(irr::io::IrrXMLReader* xml);
|
2009-03-23 14:38:06 -04:00
|
|
|
|
|
|
|
/** checks if this key belongs to this belongs. if yes, sets action and returns true; otherwise returns false */
|
2009-03-29 11:51:55 -04:00
|
|
|
bool hasBinding(const int key_id, PlayerAction* action /* out */) const;
|
2009-03-23 14:38:06 -04:00
|
|
|
|
2009-05-30 15:35:47 -04:00
|
|
|
void editBinding(PlayerAction action, int key_id);
|
|
|
|
|
2009-03-23 14:38:06 -04:00
|
|
|
void loadDefaults();
|
|
|
|
};
|
|
|
|
|
|
|
|
class GamePadDevice : public InputDevice
|
|
|
|
{
|
2009-03-29 12:15:17 -04:00
|
|
|
void resetAxisDirection(const int axis, Input::AxisDirection direction, const int player);
|
2009-05-30 21:27:21 -04:00
|
|
|
bool m_buttonPressed[SEvent::SJoystickEvent::NUMBER_OF_BUTTONS];
|
2009-03-23 14:38:06 -04:00
|
|
|
public:
|
|
|
|
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 14:38:06 -04:00
|
|
|
Input::AxisDirection *m_prevAxisDirections;
|
2009-03-23 15:09:16 -04:00
|
|
|
|
2009-03-29 20:58:12 -04:00
|
|
|
/** checks if this key belongs to this belongs. if yes, sets action and returns true; otherwise returns false.
|
|
|
|
The 'player' id passed is simply to know where to send 'axis reset's when necessary*/
|
2009-03-31 16:33:44 -04:00
|
|
|
bool hasBinding(Input::InputType type, const int id, const int value, const int player, PlayerAction* action /* out */);
|
2009-03-29 11:51:55 -04:00
|
|
|
|
2009-05-30 20:40:42 -04:00
|
|
|
void editBinding(const PlayerAction action, const Input::InputType type, const int id,
|
|
|
|
Input::AxisDirection direction=Input::AD_NEUTRAL);
|
|
|
|
|
2009-05-30 21:27:21 -04:00
|
|
|
void open(const int irrIndex, const std::string name, const int axis_count, const int btnCount);
|
2009-03-29 20:58:12 -04:00
|
|
|
|
2009-03-29 11:51:55 -04:00
|
|
|
void loadDefaults();
|
2009-03-23 14:38:06 -04:00
|
|
|
|
2009-05-30 21:27:21 -04:00
|
|
|
GamePadDevice(const int irrIndex, const std::string name, const int axis_number, const int btnAmount);
|
2009-03-29 20:58:12 -04:00
|
|
|
GamePadDevice(irr::io::IrrXMLReader* xml);
|
|
|
|
|
2009-05-30 21:27:21 -04:00
|
|
|
bool isButtonPressed(const int i);
|
|
|
|
void setButtonPressed(const int i, bool isButtonPressed);
|
|
|
|
|
2009-03-23 14:38:06 -04:00
|
|
|
~GamePadDevice();
|
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
|
|
|
|
|