]> git.tdb.fi Git - libs/gui.git/blob - source/smoothcontrol.cpp
293e0b3dcba7bf985dfe59904ad5fb7ae01682c3
[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         on_motion(0, -value);
68 }
69
70 void SmoothControl::on_motion(float v, float)
71 {
72         value=v;
73         signal_motion.emit(value);
74         
75         if(paired_ctrl)
76                 paired_ctrl->signal_motion.emit(-value);
77 }
78
79 } // namespace Input
80 } // namespace Msp