X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Finput%2Fdevice.h;h=e7a779af3159fececfb53acc33f79ea86332500a;hb=11ab96ba152e389814543a6398e2cd6f17a31092;hp=e356bea86a4639cc5280d0a974eb6af3a8f005ab;hpb=5627c06b70fe2e8e926ed8d1d2d3fff0a33a503f;p=libs%2Fgui.git diff --git a/source/input/device.h b/source/input/device.h index e356bea..e7a779a 100644 --- a/source/input/device.h +++ b/source/input/device.h @@ -3,20 +3,40 @@ #include #include +#include #include +#include +#include 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 @@ -38,15 +58,19 @@ public: 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(); + 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); }; + +MSPGUI_API void operator>>(const LexicalConverter &, DeviceType &); +MSPGUI_API void operator<<(LexicalConverter &, DeviceType); + } // namespace Input } // namespace Msp