Merge pull request #24470 from fuzzard/release_20.3
[xbmc.git] / xbmc / input / Key.cpp
blob24f6a0c1b53a903613a8e0e5696ed9df02c2b771
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "input/Key.h"
11 CKey::CKey(void)
13 Reset();
16 CKey::~CKey(void) = default;
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)
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;
38 CKey::CKey(uint32_t buttonCode, unsigned int held)
40 Reset();
41 m_buttonCode = buttonCode;
42 m_held = 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)
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;
68 CKey::CKey(const CKey& key)
70 *this = key;
73 void CKey::Reset()
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;
93 CKey& CKey::operator=(const CKey& key)
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;
116 uint8_t CKey::GetLeftTrigger() const
118 return m_leftTrigger;
121 uint8_t CKey::GetRightTrigger() const
123 return m_rightTrigger;
126 float CKey::GetLeftThumbX() const
128 return m_leftThumbX;
131 float CKey::GetLeftThumbY() const
133 return m_leftThumbY;
136 float CKey::GetRightThumbX() const
138 return m_rightThumbX;
141 float CKey::GetRightThumbY() const
143 return m_rightThumbY;
146 bool CKey::FromKeyboard() const
148 return (m_buttonCode >= KEY_VKEY && m_buttonCode != KEY_INVALID);
151 bool CKey::IsAnalogButton() const
153 if ((GetButtonCode() > 261 && GetButtonCode() < 270) ||
154 (GetButtonCode() > 279 && GetButtonCode() < 284))
155 return true;
157 return false;
160 bool CKey::IsIRRemote() const
162 if (GetButtonCode() < 256)
163 return true;
164 return false;
167 float CKey::GetRepeat() const
169 return m_repeat;
172 void CKey::SetFromService(bool fromService)
174 if (fromService && (m_buttonCode & KEY_VKEY))
175 m_unicode = m_buttonCode - KEY_VKEY;
177 m_fromService = fromService;