X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Finput%2Fcontrol.h;h=177776d1a4aac86dc413a5364a7e0cdd4900113c;hb=a6eecc5117d91534aaf13e93baf64855f4b963c0;hp=924bbeca39024f3c0ed615c17d986cffa7ce7eb5;hpb=1023b38fa278cea71fba3d2881e1bfde930cd025;p=libs%2Fgui.git diff --git a/source/input/control.h b/source/input/control.h index 924bbec..177776d 100644 --- a/source/input/control.h +++ b/source/input/control.h @@ -4,15 +4,17 @@ #include #include #include +#include namespace Msp { namespace Input { +class BinaryControl; class Device; enum ControlSrcType { - NONE, + NO_SOURCE, BUTTON, AXIS_POS, AXIS_NEG @@ -22,13 +24,13 @@ enum ControlSrcType Specifies the source of a control. This provides a way for setting sources for different types of controls in a uniform way. */ -struct ControlSource +struct MSPGUI_API ControlSource { - Device *dev; - ControlSrcType type; - unsigned index; + Device *dev = nullptr; + ControlSrcType type = NO_SOURCE; + unsigned index = 0; - ControlSource(); + ControlSource() = default; ControlSource(Device &, ControlSrcType, unsigned); std::string str() const; }; @@ -41,27 +43,41 @@ A control uses either a button or half of an axis (positive or negative) as its source. How the source values are interpreted depends on the exact type of the control. Controls also support interactive binding by capturing a button press or axis motion. + +A BinaryControl can be used as an activator, requiring that control to be +active for any events to be processed. This can be used to implement shifted +controls (when used on a BinaryControl) or click-and-drag functionality (when +used on a SmoothControl). */ -class Control: public sigc::trackable +class MSPGUI_API Control: public sigc::trackable { public: sigc::signal signal_capture_complete; protected: ControlSource src; - Device *capture_dev; + Device *capture_dev = nullptr; + BinaryControl *activator = nullptr; + float origin = 0.0f; + bool rising_edge = false; + bool falling_edge = false; - Control(); + Control() = default; Control(const ControlSource &); Control(Device &, ControlSrcType, unsigned); public: - virtual ~Control() { } + virtual ~Control(); void capture(Device &); void cancel_capture(); void set_source(Device &, ControlSrcType, unsigned); void set_source(const ControlSource &); const ControlSource &get_source() const { return src; } + void set_activator(BinaryControl *); + BinaryControl *get_activator() const { return activator; } + bool has_rising_edge() const { return rising_edge; } + bool has_falling_edge() const { return falling_edge; } + void reset_edges(); protected: virtual void on_press() = 0; virtual void on_release() = 0; @@ -72,6 +88,7 @@ private: void button_press(unsigned); void button_release(unsigned); void axis_motion(unsigned, float, float); + void deactivate(); Control(const Control &); Control &operator=(const Control &);