]> git.tdb.fi Git - libs/gui.git/blob - source/smoothcontrol.cpp
Add a control layer suitable for games
[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 void SmoothControl::pair(SmoothControl *ctrl)
31 {
32         if(ctrl==paired_ctrl)
33                 return;
34
35         if(paired_ctrl)
36         {
37                 paired_ctrl=0;
38                 paired_ctrl->pair(0);
39         }
40
41         paired_ctrl=ctrl;
42
43         if(paired_ctrl)
44                 paired_ctrl->pair(this);
45 }
46
47 void SmoothControl::on_press()
48 {
49         on_motion(1, 1-value);
50 }
51
52 void SmoothControl::on_release()
53 {
54         on_motion(0, -value);
55 }
56
57 void SmoothControl::on_motion(float v, float)
58 {
59         value=v;
60         signal_motion.emit(value);
61         
62         if(paired_ctrl)
63                 paired_ctrl->signal_motion.emit(-value);
64 }
65
66 } // namespace Input
67 } // namespace Msp