1 #ifndef MSP_INPUT_CONTROL_H_
2 #define MSP_INPUT_CONTROL_H_
5 #include <sigc++/signal.h>
6 #include <sigc++/trackable.h>
7 #include <msp/graphics/mspgui_api.h>
24 Specifies the source of a control. This provides a way for setting sources for
25 different types of controls in a uniform way.
27 struct MSPGUI_API ControlSource
29 Device *dev = nullptr;
30 ControlSrcType type = NO_SOURCE;
33 ControlSource() = default;
34 ControlSource(Device &, ControlSrcType, unsigned);
35 std::string str() const;
39 Provides further abstraction on top of input devices. There are two types of
40 controls currently defined: BinaryControl and SmoothControl.
42 A control uses either a button or half of an axis (positive or negative) as its
43 source. How the source values are interpreted depends on the exact type of the
44 control. Controls also support interactive binding by capturing a button press
47 A BinaryControl can be used as an activator, requiring that control to be
48 active for any events to be processed. This can be used to implement shifted
49 controls (when used on a BinaryControl) or click-and-drag functionality (when
50 used on a SmoothControl).
52 class MSPGUI_API Control: public sigc::trackable
55 sigc::signal<void> signal_capture_complete;
59 Device *capture_dev = nullptr;
60 BinaryControl *activator = nullptr;
62 bool rising_edge = false;
63 bool falling_edge = false;
66 Control(const ControlSource &);
67 Control(Device &, ControlSrcType, unsigned);
71 void capture(Device &);
72 void cancel_capture();
73 void set_source(Device &, ControlSrcType, unsigned);
74 void set_source(const ControlSource &);
75 const ControlSource &get_source() const { return src; }
76 void set_activator(BinaryControl *);
77 BinaryControl *get_activator() const { return activator; }
78 bool has_rising_edge() const { return rising_edge; }
79 bool has_falling_edge() const { return falling_edge; }
82 virtual void on_press() = 0;
83 virtual void on_release() = 0;
84 virtual void on_motion(float, float) = 0;
87 void connect_signals();
88 void button_press(unsigned);
89 void button_release(unsigned);
90 void axis_motion(unsigned, float, float);
93 Control(const Control &);
94 Control &operator=(const Control &);