VTB: release CVBuffer after it actually has been rendered
[xbmc.git] / xbmc / input / Key.cpp
bloba2006633323eb0d221b5af1ecdc7479157e88f97
1 /*
2 * Copyright (C) 2005-2013 Team XBMC
3 * http://xbmc.org
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
21 #include "system.h"
22 #include "input/Key.h"
23 #include "input/ButtonTranslator.h"
25 CKey::CKey(void)
27 Reset();
30 CKey::~CKey(void)
33 CKey::CKey(uint32_t buttonCode, uint8_t leftTrigger, uint8_t rightTrigger, float leftThumbX, float leftThumbY, float rightThumbX, float rightThumbY, float repeat)
35 Reset();
36 m_buttonCode = buttonCode;
37 m_leftTrigger = leftTrigger;
38 m_rightTrigger = rightTrigger;
39 m_leftThumbX = leftThumbX;
40 m_leftThumbY = leftThumbY;
41 m_rightThumbX = rightThumbX;
42 m_rightThumbY = rightThumbY;
43 m_repeat = repeat;
46 CKey::CKey(uint32_t buttonCode, unsigned int held)
48 Reset();
49 m_buttonCode = buttonCode;
50 m_held = held;
53 CKey::CKey(uint8_t vkey, wchar_t unicode, char ascii, uint32_t modifiers, unsigned int held)
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_vkey = vkey;
62 m_unicode = unicode;
63 m_ascii = ascii;
64 m_modifiers = modifiers;
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_vkey = 0;
85 m_unicode = 0;
86 m_ascii = 0;
87 m_modifiers = 0;
88 m_held = 0;
91 CKey& CKey::operator=(const CKey& key)
93 if (&key == this) return * this;
94 m_leftTrigger = key.m_leftTrigger;
95 m_rightTrigger = key.m_rightTrigger;
96 m_leftThumbX = key.m_leftThumbX;
97 m_leftThumbY = key.m_leftThumbY;
98 m_rightThumbX = key.m_rightThumbX;
99 m_rightThumbY = key.m_rightThumbY;
100 m_repeat = key.m_repeat;
101 m_fromService = key.m_fromService;
102 m_buttonCode = key.m_buttonCode;
103 m_vkey = key.m_vkey;
104 m_unicode = key.m_unicode;
105 m_ascii = key.m_ascii;
106 m_modifiers = key.m_modifiers;
107 m_held = key.m_held;
108 return *this;
111 BYTE CKey::GetLeftTrigger() const
113 return m_leftTrigger;
116 BYTE CKey::GetRightTrigger() const
118 return m_rightTrigger;
121 float CKey::GetLeftThumbX() const
123 return m_leftThumbX;
126 float CKey::GetLeftThumbY() const
128 return m_leftThumbY;
132 float CKey::GetRightThumbX() const
134 return m_rightThumbX;
137 float CKey::GetRightThumbY() const
139 return m_rightThumbY;
142 bool CKey::FromKeyboard() const
144 return (m_buttonCode >= KEY_VKEY && m_buttonCode != KEY_INVALID);
147 bool CKey::IsAnalogButton() const
149 if ((GetButtonCode() > 261 && GetButtonCode() < 270) || (GetButtonCode() > 279 && GetButtonCode() < 284))
150 return true;
152 return false;
155 bool CKey::IsIRRemote() const
157 if (GetButtonCode() < 256)
158 return true;
159 return false;
162 float CKey::GetRepeat() const
164 return m_repeat;
167 void CKey::SetFromService(bool fromService)
169 if (fromService && (m_buttonCode & KEY_ASCII))
170 m_unicode = m_buttonCode - KEY_ASCII;
172 m_fromService = fromService;
175 CAction::CAction(int actionID, float amount1 /* = 1.0f */, float amount2 /* = 0.0f */, const std::string &name /* = "" */, unsigned int holdTime /*= 0*/)
177 m_id = actionID;
178 m_amount[0] = amount1;
179 m_amount[1] = amount2;
180 for (unsigned int i = 2; i < max_amounts; i++)
181 m_amount[i] = 0;
182 m_name = name;
183 m_repeat = 0;
184 m_buttonCode = 0;
185 m_unicode = 0;
186 m_holdTime = holdTime;
189 CAction::CAction(int actionID, unsigned int state, float posX, float posY, float offsetX, float offsetY, const std::string &name):
190 m_name(name)
192 m_id = actionID;
193 m_amount[0] = posX;
194 m_amount[1] = posY;
195 m_amount[2] = offsetX;
196 m_amount[3] = offsetY;
197 for (unsigned int i = 4; i < max_amounts; i++)
198 m_amount[i] = 0;
199 m_repeat = 0;
200 m_buttonCode = 0;
201 m_unicode = 0;
202 m_holdTime = state;
205 CAction::CAction(int actionID, wchar_t unicode)
207 m_id = actionID;
208 for (unsigned int i = 0; i < max_amounts; i++)
209 m_amount[i] = 0;
210 m_repeat = 0;
211 m_buttonCode = 0;
212 m_unicode = unicode;
213 m_holdTime = 0;
216 CAction::CAction(int actionID, const std::string &name, const CKey &key):
217 m_name(name)
219 m_id = actionID;
220 m_amount[0] = 1; // digital button (could change this for repeat acceleration)
221 for (unsigned int i = 1; i < max_amounts; i++)
222 m_amount[i] = 0;
223 m_repeat = key.GetRepeat();
224 m_buttonCode = key.GetButtonCode();
225 m_unicode = 0;
226 m_holdTime = key.GetHeld();
227 // get the action amounts of the analog buttons
228 if (key.GetButtonCode() == KEY_BUTTON_LEFT_ANALOG_TRIGGER)
229 m_amount[0] = (float)key.GetLeftTrigger() / 255.0f;
230 else if (key.GetButtonCode() == KEY_BUTTON_RIGHT_ANALOG_TRIGGER)
231 m_amount[0] = (float)key.GetRightTrigger() / 255.0f;
232 else if (key.GetButtonCode() == KEY_BUTTON_LEFT_THUMB_STICK)
234 m_amount[0] = key.GetLeftThumbX();
235 m_amount[1] = key.GetLeftThumbY();
237 else if (key.GetButtonCode() == KEY_BUTTON_RIGHT_THUMB_STICK)
239 m_amount[0] = key.GetRightThumbX();
240 m_amount[1] = key.GetRightThumbY();
242 else if (key.GetButtonCode() == KEY_BUTTON_LEFT_THUMB_STICK_UP)
243 m_amount[0] = key.GetLeftThumbY();
244 else if (key.GetButtonCode() == KEY_BUTTON_LEFT_THUMB_STICK_DOWN)
245 m_amount[0] = -key.GetLeftThumbY();
246 else if (key.GetButtonCode() == KEY_BUTTON_LEFT_THUMB_STICK_LEFT)
247 m_amount[0] = -key.GetLeftThumbX();
248 else if (key.GetButtonCode() == KEY_BUTTON_LEFT_THUMB_STICK_RIGHT)
249 m_amount[0] = key.GetLeftThumbX();
250 else if (key.GetButtonCode() == KEY_BUTTON_RIGHT_THUMB_STICK_UP)
251 m_amount[0] = key.GetRightThumbY();
252 else if (key.GetButtonCode() == KEY_BUTTON_RIGHT_THUMB_STICK_DOWN)
253 m_amount[0] = -key.GetRightThumbY();
254 else if (key.GetButtonCode() == KEY_BUTTON_RIGHT_THUMB_STICK_LEFT)
255 m_amount[0] = -key.GetRightThumbX();
256 else if (key.GetButtonCode() == KEY_BUTTON_RIGHT_THUMB_STICK_RIGHT)
257 m_amount[0] = key.GetRightThumbX();
260 CAction::CAction(int actionID, const std::string &name):
261 m_name(name)
263 m_id = actionID;
264 for (unsigned int i = 0; i < max_amounts; i++)
265 m_amount[i] = 0;
266 m_repeat = 0;
267 m_buttonCode = 0;
268 m_unicode = 0;
269 m_holdTime = 0;
272 CAction& CAction::operator=(const CAction& rhs)
274 if (this != &rhs)
276 m_id = rhs.m_id;
277 for (unsigned int i = 0; i < max_amounts; i++)
278 m_amount[i] = rhs.m_amount[i];
279 m_name = rhs.m_name;
280 m_repeat = rhs.m_repeat;
281 m_buttonCode = rhs.m_buttonCode;
282 m_unicode = rhs.m_unicode;
283 m_holdTime = rhs.m_holdTime;
284 m_text = rhs.m_text;
286 return *this;
289 bool CAction::IsAnalog() const
291 return CButtonTranslator::IsAnalog(m_id);