1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9 #include "input/Key.h"
10
CKey(void)11 CKey::CKey(void)
12 {
13 Reset();
14 }
15
16 CKey::~CKey(void) = default;
17
CKey(uint32_t buttonCode,uint8_t leftTrigger,uint8_t rightTrigger,float leftThumbX,float leftThumbY,float rightThumbX,float rightThumbY,float repeat)18 CKey::CKey(uint32_t buttonCode,
19 uint8_t leftTrigger,
20 uint8_t rightTrigger,
21 float leftThumbX,
22 float leftThumbY,
23 float rightThumbX,
24 float rightThumbY,
25 float repeat)
26 {
27 Reset();
28 m_buttonCode = buttonCode;
29 m_leftTrigger = leftTrigger;
30 m_rightTrigger = rightTrigger;
31 m_leftThumbX = leftThumbX;
32 m_leftThumbY = leftThumbY;
33 m_rightThumbX = rightThumbX;
34 m_rightThumbY = rightThumbY;
35 m_repeat = repeat;
36 }
37
CKey(uint32_t buttonCode,unsigned int held)38 CKey::CKey(uint32_t buttonCode, unsigned int held)
39 {
40 Reset();
41 m_buttonCode = buttonCode;
42 m_held = held;
43 }
44
CKey(uint32_t keycode,uint8_t vkey,wchar_t unicode,char ascii,uint32_t modifiers,uint32_t lockingModifiers,unsigned int held)45 CKey::CKey(uint32_t keycode,
46 uint8_t vkey,
47 wchar_t unicode,
48 char ascii,
49 uint32_t modifiers,
50 uint32_t lockingModifiers,
51 unsigned int held)
52 {
53 Reset();
54 if (vkey) // FIXME: This needs cleaning up - should we always use the unicode key where available?
55 m_buttonCode = vkey | KEY_VKEY;
56 else
57 m_buttonCode = KEY_UNICODE;
58 m_buttonCode |= modifiers;
59 m_keycode = keycode;
60 m_vkey = vkey;
61 m_unicode = unicode;
62 m_ascii = ascii;
63 m_modifiers = modifiers;
64 m_lockingModifiers = lockingModifiers;
65 m_held = held;
66 }
67
CKey(const CKey & key)68 CKey::CKey(const CKey& key)
69 {
70 *this = key;
71 }
72
Reset()73 void CKey::Reset()
74 {
75 m_leftTrigger = 0;
76 m_rightTrigger = 0;
77 m_leftThumbX = 0.0f;
78 m_leftThumbY = 0.0f;
79 m_rightThumbX = 0.0f;
80 m_rightThumbY = 0.0f;
81 m_repeat = 0.0f;
82 m_fromService = false;
83 m_buttonCode = KEY_INVALID;
84 m_keycode = 0;
85 m_vkey = 0;
86 m_unicode = 0;
87 m_ascii = 0;
88 m_modifiers = 0;
89 m_lockingModifiers = 0;
90 m_held = 0;
91 }
92
operator =(const CKey & key)93 CKey& CKey::operator=(const CKey& key)
94 {
95 if (&key == this)
96 return *this;
97 m_leftTrigger = key.m_leftTrigger;
98 m_rightTrigger = key.m_rightTrigger;
99 m_leftThumbX = key.m_leftThumbX;
100 m_leftThumbY = key.m_leftThumbY;
101 m_rightThumbX = key.m_rightThumbX;
102 m_rightThumbY = key.m_rightThumbY;
103 m_repeat = key.m_repeat;
104 m_fromService = key.m_fromService;
105 m_buttonCode = key.m_buttonCode;
106 m_keycode = key.m_keycode;
107 m_vkey = key.m_vkey;
108 m_unicode = key.m_unicode;
109 m_ascii = key.m_ascii;
110 m_modifiers = key.m_modifiers;
111 m_lockingModifiers = key.m_lockingModifiers;
112 m_held = key.m_held;
113 return *this;
114 }
115
GetLeftTrigger() const116 uint8_t CKey::GetLeftTrigger() const
117 {
118 return m_leftTrigger;
119 }
120
GetRightTrigger() const121 uint8_t CKey::GetRightTrigger() const
122 {
123 return m_rightTrigger;
124 }
125
GetLeftThumbX() const126 float CKey::GetLeftThumbX() const
127 {
128 return m_leftThumbX;
129 }
130
GetLeftThumbY() const131 float CKey::GetLeftThumbY() const
132 {
133 return m_leftThumbY;
134 }
135
136
GetRightThumbX() const137 float CKey::GetRightThumbX() const
138 {
139 return m_rightThumbX;
140 }
141
GetRightThumbY() const142 float CKey::GetRightThumbY() const
143 {
144 return m_rightThumbY;
145 }
146
FromKeyboard() const147 bool CKey::FromKeyboard() const
148 {
149 return (m_buttonCode >= KEY_VKEY && m_buttonCode != KEY_INVALID);
150 }
151
IsAnalogButton() const152 bool CKey::IsAnalogButton() const
153 {
154 if ((GetButtonCode() > 261 && GetButtonCode() < 270) ||
155 (GetButtonCode() > 279 && GetButtonCode() < 284))
156 return true;
157
158 return false;
159 }
160
IsIRRemote() const161 bool CKey::IsIRRemote() const
162 {
163 if (GetButtonCode() < 256)
164 return true;
165 return false;
166 }
167
GetRepeat() const168 float CKey::GetRepeat() const
169 {
170 return m_repeat;
171 }
172
SetFromService(bool fromService)173 void CKey::SetFromService(bool fromService)
174 {
175 if (fromService && (m_buttonCode & KEY_VKEY))
176 m_unicode = m_buttonCode - KEY_VKEY;
177
178 m_fromService = fromService;
179 }
180