1 /** @file hatinputcontrol.cpp  Hat control for a logical input device.
2  *
3  * @authors Copyright © 2003-2017 Jaakko Keränen <jaakko.keranen@iki.fi>
4  * @authors Copyright © 2005-2014 Daniel Swanson <danij@dengine.net>
5  *
6  * @par License
7  * GPL: http://www.gnu.org/licenses/gpl.html
8  *
9  * <small>This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by the
11  * Free Software Foundation; either version 2 of the License, or (at your
12  * option) any later version. This program is distributed in the hope that it
13  * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
15  * Public License for more details. You should have received a copy of the GNU
16  * General Public License along with this program; if not, write to the Free
17  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18  * 02110-1301 USA</small>
19  */
20 
21 #include "ui/hatinputcontrol.h"
22 #include <de/timer.h> // Timer_RealMilliseconds()
23 
24 using namespace de;
25 
HatInputControl(String const & name)26 HatInputControl::HatInputControl(String const &name)
27 {
28     setName(name);
29 }
30 
~HatInputControl()31 HatInputControl::~HatInputControl()
32 {}
33 
position() const34 dint HatInputControl::position() const
35 {
36     return _pos;
37 }
38 
setPosition(dint newPosition)39 void HatInputControl::setPosition(dint newPosition)
40 {
41     _pos  = newPosition;
42     _time = Timer_RealMilliseconds(); // Remember when the change occured.
43 
44     // We can clear the expiration when centered.
45     if (_pos < 0)
46     {
47         setBindContextAssociation(Expired, UnsetFlags);
48     }
49 }
50 
time() const51 duint HatInputControl::time() const
52 {
53     return _time;
54 }
55 
description() const56 String HatInputControl::description() const
57 {
58     return String(_E(b) "%1 " _E(.) "(Hat) "
59                   _E(l) "Position: " _E(.) "%2")
60             .arg(fullName())
61             .arg(_pos);
62 }
63 
inDefaultState() const64 bool HatInputControl::inDefaultState() const
65 {
66     return _pos < 0; // Centered?
67 }
68