1 #ifndef MSP_INPUT_INPUTDEVICE_H_
2 #define MSP_INPUT_INPUTDEVICE_H_
7 #include <sigc++/signal.h>
8 #include <msp/strings/lexicalcast.h>
13 class device_not_available: public std::runtime_error
16 device_not_available(const std::string &w): std::runtime_error(w) { }
31 Base class for input devices. Input devices have two types of controls:
32 buttons and axes. Buttons are either on or off. Axes have a floating point
33 value nominally in the range [-1, 1].
35 Event handlers return a boolean indicating whether the event is considered
36 processed. If a handler returns true, no further handlers are invoked.
41 struct EventAccumulator
43 typedef void result_type;
45 template<typename Iter>
46 result_type operator()(Iter begin, Iter end) const
48 for(Iter i=begin; i!=end; ++i)
55 sigc::signal<bool, unsigned>::accumulated<EventAccumulator> signal_button_press;
56 sigc::signal<bool, unsigned>::accumulated<EventAccumulator> signal_button_release;
57 sigc::signal<bool, unsigned, float, float>::accumulated<EventAccumulator> signal_axis_motion;
62 std::vector<char> buttons;
63 std::vector<float> axes;
69 DeviceType get_type() const { return type; }
70 const std::string &get_name() const { return name; }
71 virtual Device *find_subdevice(DeviceType, unsigned = 0);
72 virtual Device *find_subdevice(const std::string &);
73 bool get_button_state(unsigned) const;
74 float get_axis_value(unsigned) const;
76 virtual std::string get_button_name(unsigned) const;
77 virtual std::string get_axis_name(unsigned) const;
79 void set_button_state(unsigned, bool, bool);
80 void set_axis_value(unsigned, float, bool);
84 void operator>>(const LexicalConverter &, DeviceType &);
85 void operator<<(LexicalConverter &, DeviceType);