]> git.tdb.fi Git - libs/gui.git/blobdiff - source/input/control.h
Use nullptr in place of 0 or NULL
[libs/gui.git] / source / input / control.h
index 1d8c50a06bd84040dc17f50c155b1997a733c0c2..f9c7003b4290ea17b8f57dfb43249b03f8489288 100644 (file)
@@ -1,12 +1,5 @@
-/* $Id$
-
-This file is part of libmspgbase
-Copyright © 2007 Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
-#ifndef MSP_GBASE_CONTROL_H_
-#define MSP_GBASE_CONTROL_H_
+#ifndef MSP_INPUT_CONTROL_H_
+#define MSP_INPUT_CONTROL_H_
 
 #include <string>
 #include <sigc++/signal.h>
@@ -15,11 +8,12 @@ Distributed under the LGPL
 namespace Msp {
 namespace Input {
 
+class BinaryControl;
 class Device;
 
 enum ControlSrcType
 {
-       NONE,
+       NO_SOURCE,
        BUTTON,
        AXIS_POS,
        AXIS_NEG
@@ -31,11 +25,11 @@ different types of controls in a uniform way.
 */
 struct 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;
 };
@@ -48,6 +42,11 @@ 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
 {
@@ -56,29 +55,39 @@ public:
 
 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;
-       virtual void on_motion(float, float) =0;
+       virtual void on_press() = 0;
+       virtual void on_release() = 0;
+       virtual void on_motion(float, float) = 0;
 
 private:
        void connect_signals();
        void button_press(unsigned);
        void button_release(unsigned);
        void axis_motion(unsigned, float, float);
+       void deactivate();
 
        Control(const Control &);
        Control &operator=(const Control &);