]> git.tdb.fi Git - libs/gui.git/blobdiff - source/input/device.h
Add functions to look up subdevices of composite input devices
[libs/gui.git] / source / input / device.h
index 7df388b18c34f5f0d2dc1001ac61e27ae5b9afa8..4544776ac3a36f1f6b36d7dfe0d7a79cdaacb232 100644 (file)
@@ -3,11 +3,31 @@
 
 #include <string>
 #include <vector>
+#include <stdexcept>
 #include <sigc++/signal.h>
+#include <msp/strings/lexicalcast.h>
 
 namespace Msp {
 namespace Input {
 
+class device_not_available: public std::runtime_error
+{
+public:
+       device_not_available(const std::string &w): std::runtime_error(w) { }
+       virtual ~device_not_available() throw() { }
+};
+
+
+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
@@ -38,15 +58,19 @@ public:
        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; }
+       virtual Device *find_subdevice(DeviceType, unsigned = 0);
+       virtual Device *find_subdevice(const std::string &);
        bool get_button_state(unsigned) const;
        float get_axis_value(unsigned) const;
 
@@ -57,6 +81,10 @@ protected:
        void set_axis_value(unsigned, float, bool);
 };
 
+
+void operator>>(const LexicalConverter &, DeviceType &);
+void operator<<(LexicalConverter &, DeviceType);
+
 } // namespace Input
 } // namespace Msp