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
|
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
DeviceType m_type;
|
|
|
|
KeyBinding m_bindings[PA_COUNT];
|
|
|
|
|
2009-03-29 11:51:55 -04:00
|
|
|
std::string m_player;
|
|
|
|
|
2009-03-23 14:38:06 -04:00
|
|
|
public:
|
2009-03-29 21:15:52 -04:00
|
|
|
std::string m_name; // if device has a name; unused for keyboards since SDL can't tell keyboards apart
|
|
|
|
|
2009-03-23 14:38:06 -04:00
|
|
|
InputDevice();
|
|
|
|
|
|
|
|
DeviceType getType() const { return m_type; };
|
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
|
|
|
|
|
|
|
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-03-23 14:38:06 -04:00
|
|
|
public:
|
2009-04-25 13:55:39 -04:00
|
|
|
// FIXME - replace with non-SDL code
|
|
|
|
// SDL_Joystick *m_sdlJoystick;
|
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-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-04-25 14:25:08 -04:00
|
|
|
void open(const int irrIndex, const std::string name, const int axis_count);
|
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-04-25 14:25:08 -04:00
|
|
|
GamePadDevice(const int irrIndex, const std::string name, const int axis_number);
|
2009-03-29 20:58:12 -04:00
|
|
|
GamePadDevice(irr::io::IrrXMLReader* xml);
|
|
|
|
|
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
|
|
|
|
|