2009-03-23 14:38:06 -04:00
|
|
|
#ifndef INPUT_DEVICE_HPP
|
|
|
|
#define INPUT_DEVICE_HPP
|
|
|
|
|
|
|
|
#include <SDL/SDL.h>
|
|
|
|
#include <string>
|
|
|
|
#include "input/input.hpp"
|
|
|
|
|
|
|
|
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:
|
|
|
|
InputDevice();
|
|
|
|
|
|
|
|
DeviceType getType() const { return m_type; };
|
|
|
|
};
|
|
|
|
|
|
|
|
class KeyboardDevice : public InputDevice
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
KeyboardDevice();
|
|
|
|
|
|
|
|
/** 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
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SDL_Joystick *m_sdlJoystick;
|
|
|
|
std::string m_id;
|
|
|
|
int m_deadzone;
|
|
|
|
int m_index;
|
|
|
|
Input::AxisDirection *m_prevAxisDirections;
|
2009-03-23 15:09:16 -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 axis, const int value, PlayerAction* action /* out */) const;
|
|
|
|
|
|
|
|
void loadDefaults();
|
2009-03-23 14:38:06 -04:00
|
|
|
|
|
|
|
GamePadDevice(int sdlIndex);
|
|
|
|
~GamePadDevice();
|
|
|
|
}; // Stickinfo
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|