]> git.tdb.fi Git - libs/gui.git/blobdiff - source/input/smoothcontrol.cpp
Reorganize files to separate gbase and input
[libs/gui.git] / source / input / smoothcontrol.cpp
diff --git a/source/input/smoothcontrol.cpp b/source/input/smoothcontrol.cpp
new file mode 100644 (file)
index 0000000..69dfacf
--- /dev/null
@@ -0,0 +1,81 @@
+/* $Id$
+
+This file is part of libmspgbase
+Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
+#include "smoothcontrol.h"
+
+namespace Msp {
+namespace Input {
+
+SmoothControl::SmoothControl():
+       value(0),
+       paired_ctrl(0)
+{ }
+
+SmoothControl::SmoothControl(const ControlSource &s):
+       Control(s),
+       value(0),
+       paired_ctrl(0)
+{ }
+
+SmoothControl::SmoothControl(Device &d, ControlSrcType t, unsigned i):
+       Control(d, t, i),
+       value(0),
+       paired_ctrl(0)
+{ }
+
+SmoothControl &SmoothControl::operator=(const SmoothControl &sc)
+{
+       Control::operator=(sc);
+
+       return *this;
+}
+
+SmoothControl::~SmoothControl()
+{
+       pair(0);
+}
+
+void SmoothControl::pair(SmoothControl *ctrl)
+{
+       if(ctrl==paired_ctrl)
+               return;
+
+       if(paired_ctrl)
+       {
+               SmoothControl *old_pair=paired_ctrl;
+               paired_ctrl=0;
+               old_pair->pair(0);
+       }
+
+       paired_ctrl=ctrl;
+
+       if(paired_ctrl)
+               paired_ctrl->pair(this);
+}
+
+void SmoothControl::on_press()
+{
+       on_motion(1, 1-value);
+}
+
+void SmoothControl::on_release()
+{
+       if(value>0)
+               on_motion(0, -value);
+}
+
+void SmoothControl::on_motion(float v, float)
+{
+       value=v;
+       signal_motion.emit(value);
+       
+       if(paired_ctrl && paired_ctrl->get_value()!=-value)
+               paired_ctrl->on_motion(-value, -value-paired_ctrl->get_value());
+}
+
+} // namespace Input
+} // namespace Msp