]> git.tdb.fi Git - libs/gui.git/blob - source/smoothcontrol.cpp
Bugfixes
[libs/gui.git] / source / smoothcontrol.cpp
1 /* $Id$
2
3 This file is part of libmspgbase
4 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #include "smoothcontrol.h"
9
10 namespace Msp {
11 namespace Input {
12
13 SmoothControl::SmoothControl():
14         value(0),
15         paired_ctrl(0)
16 { }
17
18 SmoothControl::SmoothControl(const ControlSource &s):
19         Control(s),
20         value(0),
21         paired_ctrl(0)
22 { }
23
24 SmoothControl::SmoothControl(Device &d, ControlSrcType t, unsigned i):
25         Control(d, t, i),
26         value(0),
27         paired_ctrl(0)
28 { }
29
30 SmoothControl &SmoothControl::operator=(const SmoothControl &sc)
31 {
32         Control::operator=(sc);
33
34         return *this;
35 }
36
37 SmoothControl::~SmoothControl()
38 {
39         pair(0);
40 }
41
42 void SmoothControl::pair(SmoothControl *ctrl)
43 {
44         if(ctrl==paired_ctrl)
45                 return;
46
47         if(paired_ctrl)
48         {
49                 SmoothControl *old_pair=paired_ctrl;
50                 paired_ctrl=0;
51                 old_pair->pair(0);
52         }
53
54         paired_ctrl=ctrl;
55
56         if(paired_ctrl)
57                 paired_ctrl->pair(this);
58 }
59
60 void SmoothControl::on_press()
61 {
62         on_motion(1, 1-value);
63 }
64
65 void SmoothControl::on_release()
66 {
67         if(value>0)
68                 on_motion(0, -value);
69 }
70
71 void SmoothControl::on_motion(float v, float)
72 {
73         value=v;
74         signal_motion.emit(value);
75         
76         if(paired_ctrl && paired_ctrl->get_value()!=-value)
77                 paired_ctrl->on_motion(-value, -value-paired_ctrl->get_value());
78 }
79
80 } // namespace Input
81 } // namespace Msp