namespace Msp {
namespace Input {
-Device::Device()
+Device::Device(DeviceType t):
+ type(t)
{ }
Device::~Device()
};
+enum DeviceType
+{
+ UNSPECIFIED,
+ KEYBOARD,
+ MOUSE,
+ TOUCH_SURFACE,
+ GAME_CONTROLLER
+};
+
+
/**
Base class for input devices. Input devices have two types of controls:
buttons and axes. Buttons are either on or off. Axes have a floating point
sigc::signal<bool, unsigned, float, float>::accumulated<EventAccumulator> signal_axis_motion;
protected:
+ DeviceType type;
std::string name;
std::vector<char> buttons;
std::vector<float> axes;
- Device();
+ Device(DeviceType);
public:
virtual ~Device();
+ DeviceType get_type() const { return type; }
const std::string &get_name() const { return name; }
bool get_button_state(unsigned) const;
float get_axis_value(unsigned) const;
namespace Msp {
namespace Input {
-GameController::GameController(unsigned)
+GameController::GameController(unsigned):
+ Device(GAME_CONTROLLER)
{
throw device_not_available("GameController");
}
namespace Input {
GestureDetector::GestureDetector(Touchscreen &ts):
+ Device(UNSPECIFIED),
touchscreen(ts),
current_gesture(GESTURE_NONE),
pending_tap(GESTURE_NONE),
namespace Msp {
namespace Input {
-Hub::Hub()
+Hub::Hub():
+ Device(UNSPECIFIED)
{
name = "Hub";
}
namespace Input {
Keyboard::Keyboard(Graphics::Window &w):
+ Device(KEYBOARD),
window(w)
{
name = "Keyboard";
vector<string> GameController::Private::detected_controllers;
GameController::GameController(unsigned index):
+ Device(GAME_CONTROLLER),
event_disp(0)
{
if(!detect_done)
unsigned count = len/sizeof(js_event);
for(unsigned i=0; i<count; ++i)
{
- unsigned type = events[i].type&0x7F;
+ unsigned etype = events[i].type&0x7F;
bool init = events[i].type&JS_EVENT_INIT;
- if(type==JS_EVENT_AXIS)
+ if(etype==JS_EVENT_AXIS)
set_axis_value(events[i].number, events[i].value/32768.0f, !init);
- else if(type==JS_EVENT_BUTTON)
+ else if(etype==JS_EVENT_BUTTON)
set_button_state(events[i].number, events[i].value, !init);
}
namespace Input {
Mouse::Mouse(Graphics::Window &w):
+ Device(MOUSE),
window(w)
{
name = "Mouse";
namespace Input {
Touchscreen::Touchscreen(Graphics::Window &w):
+ Device(TOUCH_SURFACE),
window(w)
{
if(!is_available())
vector<unsigned> GameController::Private::detected_controllers;
-GameController::GameController(unsigned index)
+GameController::GameController(unsigned index):
+ Device(GAME_CONTROLLER)
{
if(!detect_done)
detect();