X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Finput%2Fdevice.h;h=e80029054548fe82c0a985bb2690b23c6773021c;hb=bc1a38d6d2c966a6aee74e483ca7a7d37a56909e;hp=3338137eb51e46e50528cf51af02c73beb31ce50;hpb=77f1906effbbaaff2c1c53926a3e77bb8f4aa799;p=libs%2Fgui.git diff --git a/source/input/device.h b/source/input/device.h index 3338137..e800290 100644 --- a/source/input/device.h +++ b/source/input/device.h @@ -3,32 +3,73 @@ #include #include +#include #include +#include namespace Msp { namespace Input { +class 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 { +protected: + struct EventAccumulator + { + typedef void result_type; + + template + result_type operator()(Iter begin, Iter end) const + { + for(Iter i=begin; i!=end; ++i) + if(*i) + return; + } + }; + public: - sigc::signal signal_button_press; - sigc::signal signal_button_release; - sigc::signal signal_axis_motion; + sigc::signal::accumulated signal_button_press; + sigc::signal::accumulated signal_button_release; + sigc::signal::accumulated signal_axis_motion; protected: + DeviceType type = UNSPECIFIED; std::string name; std::vector buttons; std::vector axes; - Device() { } + Device(DeviceType); public: - virtual ~Device() { } + 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; @@ -39,6 +80,10 @@ protected: void set_axis_value(unsigned, float, bool); }; + +void operator>>(const LexicalConverter &, DeviceType &); +void operator<<(LexicalConverter &, DeviceType); + } // namespace Input } // namespace Msp