]> git.tdb.fi Git - libs/gui.git/blobdiff - source/input/device.h
Add decorations for things which should be exported from the library
[libs/gui.git] / source / input / device.h
index 43d180d50b6595696f1767f490c48d3c0863a178..e7a779af3159fececfb53acc33f79ea86332500a 100644 (file)
@@ -1,35 +1,77 @@
-#ifndef MSP_GBASE_INPUTDEVICE_H_
-#define MSP_GBASE_INPUTDEVICE_H_
+#ifndef MSP_INPUT_INPUTDEVICE_H_
+#define MSP_INPUT_INPUTDEVICE_H_
 
 #include <string>
 #include <vector>
+#include <stdexcept>
 #include <sigc++/signal.h>
+#include <msp/graphics/mspgui_api.h>
+#include <msp/strings/lexicalcast.h>
 
 namespace Msp {
 namespace Input {
 
+class MSPGUI_API device_not_available: public std::runtime_error
+{
+public:
+       device_not_available(const std::string &w): std::runtime_error(w) { }
+};
+
+
+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
-value in the range [-1, 1].
+value nominally in the range [-1, 1].
+
+Event handlers return a boolean indicating whether the event is considered
+processed.  If a handler returns true, no further handlers are invoked.
 */
-class Device
+class MSPGUI_API Device
 {
+protected:
+       struct EventAccumulator
+       {
+               typedef void result_type;
+
+               template<typename Iter>
+               result_type operator()(Iter begin, Iter end) const
+               {
+                       for(Iter i=begin; i!=end; ++i)
+                               if(*i)
+                                       return;
+               }
+       };
+
 public:
-       sigc::signal<void, unsigned> signal_button_press;
-       sigc::signal<void, unsigned> signal_button_release;
-       sigc::signal<void, unsigned, float, float> signal_axis_motion;
+       sigc::signal<bool, unsigned>::accumulated<EventAccumulator> signal_button_press;
+       sigc::signal<bool, unsigned>::accumulated<EventAccumulator> signal_button_release;
+       sigc::signal<bool, unsigned, float, float>::accumulated<EventAccumulator> signal_axis_motion;
 
 protected:
+       DeviceType type = UNSPECIFIED;
        std::string name;
-       std::vector<char>  buttons;
+       std::vector<char> buttons;
        std::vector<float> axes;
 
-       Device() { }
+       Device(DeviceType);
 public:
-       virtual ~Device() { }
+       virtual ~Device();
+
+       DeviceType get_type() const { return type; }
        const std::string &get_name() const { return name; }
-       bool  get_button_state(unsigned) const;
+       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;
 
        virtual std::string get_button_name(unsigned) const;
@@ -39,6 +81,10 @@ protected:
        void set_axis_value(unsigned, float, bool);
 };
 
+
+MSPGUI_API void operator>>(const LexicalConverter &, DeviceType &);
+MSPGUI_API void operator<<(LexicalConverter &, DeviceType);
+
 } // namespace Input
 } // namespace Msp