2 * Copyright (C) 2005-2013 Team XBMC
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)
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/>.
32 CKey::CKey(uint32_t buttonCode, uint8_t leftTrigger, uint8_t rightTrigger, float leftThumbX, float leftThumbY, float rightThumbX, float rightThumbY, float repeat)
35 m_buttonCode = buttonCode;
36 m_leftTrigger = leftTrigger;
37 m_rightTrigger = rightTrigger;
38 m_leftThumbX = leftThumbX;
39 m_leftThumbY = leftThumbY;
40 m_rightThumbX = rightThumbX;
41 m_rightThumbY = rightThumbY;
45 CKey::CKey(uint32_t buttonCode, unsigned int held)
48 m_buttonCode = buttonCode;
52 CKey::CKey(uint8_t vkey, wchar_t unicode, char ascii, uint32_t modifiers, unsigned int held)
55 if (vkey) // FIXME: This needs cleaning up - should we always use the unicode key where available?
56 m_buttonCode = vkey | KEY_VKEY;
58 m_buttonCode = KEY_UNICODE;
59 m_buttonCode |= modifiers;
63 m_modifiers = modifiers;
67 CKey::CKey(const CKey& key)
81 m_fromService = false;
82 m_buttonCode = KEY_INVALID;
90 CKey& CKey::operator=(const CKey& key)
92 if (&key == this) return * this;
93 m_leftTrigger = key.m_leftTrigger;
94 m_rightTrigger = key.m_rightTrigger;
95 m_leftThumbX = key.m_leftThumbX;
96 m_leftThumbY = key.m_leftThumbY;
97 m_rightThumbX = key.m_rightThumbX;
98 m_rightThumbY = key.m_rightThumbY;
99 m_repeat = key.m_repeat;
100 m_fromService = key.m_fromService;
101 m_buttonCode = key.m_buttonCode;
103 m_unicode = key.m_unicode;
104 m_ascii = key.m_ascii;
105 m_modifiers = key.m_modifiers;
110 BYTE CKey::GetLeftTrigger() const
112 return m_leftTrigger;
115 BYTE CKey::GetRightTrigger() const
117 return m_rightTrigger;
120 float CKey::GetLeftThumbX() const
125 float CKey::GetLeftThumbY() const
131 float CKey::GetRightThumbX() const
133 return m_rightThumbX;
136 float CKey::GetRightThumbY() const
138 return m_rightThumbY;
141 bool CKey::FromKeyboard() const
143 return (m_buttonCode >= KEY_VKEY && m_buttonCode != KEY_INVALID);
146 bool CKey::IsAnalogButton() const
148 if ((GetButtonCode() > 261 && GetButtonCode() < 270) || (GetButtonCode() > 279 && GetButtonCode() < 284))
154 bool CKey::IsIRRemote() const
156 if (GetButtonCode() < 256)
161 float CKey::GetRepeat() const
166 void CKey::SetFromService(bool fromService)
168 if (fromService && (m_buttonCode & KEY_ASCII))
169 m_unicode = m_buttonCode - KEY_ASCII;
171 m_fromService = fromService;
174 CAction::CAction(int actionID, float amount1 /* = 1.0f */, float amount2 /* = 0.0f */, const CStdString &name /* = "" */, unsigned int holdTime /*= 0*/)
177 m_amount[0] = amount1;
178 m_amount[1] = amount2;
179 for (unsigned int i = 2; i < max_amounts; i++)
185 m_holdTime = holdTime;
188 CAction::CAction(int actionID, unsigned int state, float posX, float posY, float offsetX, float offsetY, const CStdString &name)
193 m_amount[2] = offsetX;
194 m_amount[3] = offsetY;
195 for (unsigned int i = 4; i < max_amounts; i++)
204 CAction::CAction(int actionID, wchar_t unicode)
207 for (unsigned int i = 0; i < max_amounts; i++)
215 CAction::CAction(int actionID, const CStdString &name, const CKey &key)
219 m_amount[0] = 1; // digital button (could change this for repeat acceleration)
220 for (unsigned int i = 1; i < max_amounts; i++)
222 m_repeat = key.GetRepeat();
223 m_buttonCode = key.GetButtonCode();
225 m_holdTime = key.GetHeld();
226 // get the action amounts of the analog buttons
227 if (key.GetButtonCode() == KEY_BUTTON_LEFT_ANALOG_TRIGGER)
228 m_amount[0] = (float)key.GetLeftTrigger() / 255.0f;
229 else if (key.GetButtonCode() == KEY_BUTTON_RIGHT_ANALOG_TRIGGER)
230 m_amount[0] = (float)key.GetRightTrigger() / 255.0f;
231 else if (key.GetButtonCode() == KEY_BUTTON_LEFT_THUMB_STICK)
233 m_amount[0] = key.GetLeftThumbX();
234 m_amount[1] = key.GetLeftThumbY();
236 else if (key.GetButtonCode() == KEY_BUTTON_RIGHT_THUMB_STICK)
238 m_amount[0] = key.GetRightThumbX();
239 m_amount[1] = key.GetRightThumbY();
241 else if (key.GetButtonCode() == KEY_BUTTON_LEFT_THUMB_STICK_UP)
242 m_amount[0] = key.GetLeftThumbY();
243 else if (key.GetButtonCode() == KEY_BUTTON_LEFT_THUMB_STICK_DOWN)
244 m_amount[0] = -key.GetLeftThumbY();
245 else if (key.GetButtonCode() == KEY_BUTTON_LEFT_THUMB_STICK_LEFT)
246 m_amount[0] = -key.GetLeftThumbX();
247 else if (key.GetButtonCode() == KEY_BUTTON_LEFT_THUMB_STICK_RIGHT)
248 m_amount[0] = key.GetLeftThumbX();
249 else if (key.GetButtonCode() == KEY_BUTTON_RIGHT_THUMB_STICK_UP)
250 m_amount[0] = key.GetRightThumbY();
251 else if (key.GetButtonCode() == KEY_BUTTON_RIGHT_THUMB_STICK_DOWN)
252 m_amount[0] = -key.GetRightThumbY();
253 else if (key.GetButtonCode() == KEY_BUTTON_RIGHT_THUMB_STICK_LEFT)
254 m_amount[0] = -key.GetRightThumbX();
255 else if (key.GetButtonCode() == KEY_BUTTON_RIGHT_THUMB_STICK_RIGHT)
256 m_amount[0] = key.GetRightThumbX();
259 CAction::CAction(int actionID, const std::string &name)
263 for (unsigned int i = 0; i < max_amounts; i++)