Debian Codegraph @

xbmc/input/keyboard/Key.cpp

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