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/>.
22 #include "input/Key.h"
23 #include "input/ButtonTranslator.h"
33 CKey::CKey(uint32_t buttonCode
, uint8_t leftTrigger
, uint8_t rightTrigger
, float leftThumbX
, float leftThumbY
, float rightThumbX
, float rightThumbY
, float repeat
)
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
;
46 CKey::CKey(uint32_t buttonCode
, unsigned int held
)
49 m_buttonCode
= buttonCode
;
53 CKey::CKey(uint8_t vkey
, wchar_t unicode
, char ascii
, uint32_t modifiers
, unsigned int held
)
56 if (vkey
) // FIXME: This needs cleaning up - should we always use the unicode key where available?
57 m_buttonCode
= vkey
| KEY_VKEY
;
59 m_buttonCode
= KEY_UNICODE
;
60 m_buttonCode
|= modifiers
;
64 m_modifiers
= modifiers
;
68 CKey::CKey(const CKey
& key
)
82 m_fromService
= false;
83 m_buttonCode
= KEY_INVALID
;
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
;
104 m_unicode
= key
.m_unicode
;
105 m_ascii
= key
.m_ascii
;
106 m_modifiers
= key
.m_modifiers
;
111 BYTE
CKey::GetLeftTrigger() const
113 return m_leftTrigger
;
116 BYTE
CKey::GetRightTrigger() const
118 return m_rightTrigger
;
121 float CKey::GetLeftThumbX() const
126 float CKey::GetLeftThumbY() const
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))
155 bool CKey::IsIRRemote() const
157 if (GetButtonCode() < 256)
162 float CKey::GetRepeat() const
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*/)
178 m_amount
[0] = amount1
;
179 m_amount
[1] = amount2
;
180 for (unsigned int i
= 2; i
< max_amounts
; i
++)
186 m_holdTime
= holdTime
;
189 CAction::CAction(int actionID
, unsigned int state
, float posX
, float posY
, float offsetX
, float offsetY
, const std::string
&name
):
195 m_amount
[2] = offsetX
;
196 m_amount
[3] = offsetY
;
197 for (unsigned int i
= 4; i
< max_amounts
; i
++)
205 CAction::CAction(int actionID
, wchar_t unicode
)
208 for (unsigned int i
= 0; i
< max_amounts
; i
++)
216 CAction::CAction(int actionID
, const std::string
&name
, const CKey
&key
):
220 m_amount
[0] = 1; // digital button (could change this for repeat acceleration)
221 for (unsigned int i
= 1; i
< max_amounts
; i
++)
223 m_repeat
= key
.GetRepeat();
224 m_buttonCode
= key
.GetButtonCode();
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
):
264 for (unsigned int i
= 0; i
< max_amounts
; i
++)
272 CAction
& CAction::operator=(const CAction
& rhs
)
277 for (unsigned int i
= 0; i
< max_amounts
; i
++)
278 m_amount
[i
] = rhs
.m_amount
[i
];
280 m_repeat
= rhs
.m_repeat
;
281 m_buttonCode
= rhs
.m_buttonCode
;
282 m_unicode
= rhs
.m_unicode
;
283 m_holdTime
= rhs
.m_holdTime
;
289 bool CAction::IsAnalog() const
291 return CButtonTranslator::IsAnalog(m_id
);