1 #ifndef MSP_INPUT_INPUTDEVICE_H_
2 #define MSP_INPUT_INPUTDEVICE_H_
7 #include <sigc++/signal.h>
8 #include <msp/graphics/mspgui_api.h>
9 #include <msp/strings/lexicalcast.h>
14 class MSPGUI_API device_not_available: public std::runtime_error
17 device_not_available(const std::string &w): std::runtime_error(w) { }
32 Base class for input devices. Input devices have two types of controls:
33 buttons and axes. Buttons are either on or off. Axes have a floating point
34 value nominally in the range [-1, 1].
36 Event handlers return a boolean indicating whether the event is considered
37 processed. If a handler returns true, no further handlers are invoked.
39 class MSPGUI_API Device
42 struct EventAccumulator
44 typedef void result_type;
46 template<typename Iter>
47 result_type operator()(Iter begin, Iter end) const
49 for(Iter i=begin; i!=end; ++i)
56 sigc::signal<bool, unsigned>::accumulated<EventAccumulator> signal_button_press;
57 sigc::signal<bool, unsigned>::accumulated<EventAccumulator> signal_button_release;
58 sigc::signal<bool, unsigned, float, float>::accumulated<EventAccumulator> signal_axis_motion;
61 DeviceType type = UNSPECIFIED;
63 std::vector<char> buttons;
64 std::vector<float> axes;
70 DeviceType get_type() const { return type; }
71 const std::string &get_name() const { return name; }
72 virtual Device *find_subdevice(DeviceType, unsigned = 0);
73 virtual Device *find_subdevice(const std::string &);
74 bool get_button_state(unsigned) const;
75 float get_axis_value(unsigned) const;
77 virtual std::string get_button_name(unsigned) const;
78 virtual std::string get_axis_name(unsigned) const;
80 void set_button_state(unsigned, bool, bool);
81 void set_axis_value(unsigned, float, bool);
85 MSPGUI_API void operator>>(const LexicalConverter &, DeviceType &);
86 MSPGUI_API void operator<<(LexicalConverter &, DeviceType);