Repository navigation
Expand file tree
/
Copy pathbinding.cpp
More file actions
388 lines (375 loc) · 21 KB
/
Copy pathbinding.cpp
File metadata and controls
388 lines (375 loc) · 21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2010-2015 Marianne Gagnon
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "input/binding.hpp"
#include "io/xml_node.hpp"
#include "utils/string_utils.hpp"
#include "utils/translation.hpp"
#include "utils/log.hpp"
#include <SKeyMap.h>
/** Convert this binding to XML attributes. The full XML node is actually
* written by device_config, so we only have to add the attributes here.
*/
void Binding::save(std::ofstream& stream) const
{
stream << "event=\"" << m_type << "\" ";
stream << "id=\"" << m_id << "\" ";
// Only serialize the direction and the range for stick motions
if (m_type == Input::IT_STICKMOTION)
{
stream << "direction=\"" << m_dir << "\" ";
stream << "range=\"" << m_range << "\" ";
}
} // save
// ----------------------------------------------------------------------------
bool Binding::load(const XMLNode *action)
{
int n;
if(!action->get("id", &m_id) || !action->get("event", &n) )
{
Log::warn("Binding", "No id-string or event-string given - ignored.");
return false;
}
m_type = (Input::InputType)n;
// Default settings for button
m_range = Input::AR_HALF;
m_dir = Input::AD_NEUTRAL;
// If the action is not a stick motion (button or key)
if (m_type == Input::IT_STICKMOTION)
{
if(!action->get("direction", &n))
{
Log::warn("Binding", "IT_STICKMOTION without direction, ignoring.");
return false;
}
m_dir = (Input::AxisDirection)n;
if(!action->get("range", &n)) m_range = Input::AR_HALF;
else m_range = (Input::AxisRange)n;
} // if m_type!=stickmotion
return true;
} // load
// ----------------------------------------------------------------------------
/** Returns a string representing this binding, which can be displayed on the
* screen.
*/
irr::core::stringw Binding::getAsString() const
{
irr::core::stringw s;
switch (m_type)
{
case Input::IT_NONE:
//I18N: Unbound key binding
s = _("[none]");
break;
case Input::IT_KEYBOARD:
s = "?";
switch(m_id)
{
//I18N: input configuration screen: mouse button
case irr::IRR_KEY_LBUTTON : s = _C("input_key", "Left Mouse Button"); break;
//I18N: input configuration screen: mouse button
case irr::IRR_KEY_RBUTTON : s = _C("input_key", "Right Mouse Button"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_CANCEL : s = _C("input_key", "Cancel"); break;
//I18N: input configuration screen: mouse button
case irr::IRR_KEY_MBUTTON : s = _C("input_key", "Middle Mouse Button"); break;
//I18N: input configuration screen: mouse button
case irr::IRR_KEY_XBUTTON1 : s = _C("input_key", "X1 Mouse Button"); break;
//I18N: input configuration screen: mouse button
case irr::IRR_KEY_XBUTTON2 : s = _C("input_key", "X2 Mouse Button"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_BACK : s = _C("input_key", "Backspace"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_TAB : s = _C("input_key", "Tab"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_CLEAR : s = _C("input_key", "Clear"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_RETURN : s = _C("input_key", "Return"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_SHIFT : s = _C("input_key", "Shift"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_CONTROL : s = _C("input_key", "Control"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_MENU : s = _C("input_key", "Alt/Menu"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_PAUSE : s = _C("input_key", "Pause"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_CAPITAL : s = _C("input_key", "Caps Lock"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_KANA : s = _C("input_key", "Kana"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_JUNJA : s = _C("input_key", "Junja"); break;
//I18N: input configuration screen: keyboard key
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_FINAL : s = _C("input_key", "Final"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_ESCAPE : s = _C("input_key", "Escape"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_CONVERT : s = _C("input_key", "Convert"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_NONCONVERT : s = _C("input_key", "Nonconvert"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_ACCEPT : s = _C("input_key", "Accept"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_MODECHANGE : s = _C("input_key", "Modechange"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_SPACE : s = _C("input_key", "Space"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_PRIOR : s = _C("input_key", "Page Up"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_NEXT : s = _C("input_key", "Page Down"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_END : s = _C("input_key", "End"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_HOME : s = _C("input_key", "Home"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_LEFT : s = _C("input_key", "Left"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_UP : s = _C("input_key", "Up"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_RIGHT : s = _C("input_key", "Right"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_DOWN : s = _C("input_key", "Down"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_SELECT : s = _C("input_key", "Select"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_PRINT : s = _C("input_key", "Print"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_EXECUT : s = _C("input_key", "Exec"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_SNAPSHOT : s = _C("input_key", "Print Screen"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_INSERT : s = _C("input_key", "Insert"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_DELETE : s = _C("input_key", "Delete"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_HELP : s = _C("input_key", "Help"); break;
case irr::IRR_KEY_0 : s = "0"; break;
case irr::IRR_KEY_1 : s = "1"; break;
case irr::IRR_KEY_2 : s = "2"; break;
case irr::IRR_KEY_3 : s = "3"; break;
case irr::IRR_KEY_4 : s = "4"; break;
case irr::IRR_KEY_5 : s = "5"; break;
case irr::IRR_KEY_6 : s = "6"; break;
case irr::IRR_KEY_7 : s = "7"; break;
case irr::IRR_KEY_8 : s = "8"; break;
case irr::IRR_KEY_9 : s = "9"; break;
case irr::IRR_KEY_A : s = "A"; break;
case irr::IRR_KEY_B : s = "B"; break;
case irr::IRR_KEY_C : s = "C"; break;
case irr::IRR_KEY_D : s = "D"; break;
case irr::IRR_KEY_E : s = "E"; break;
case irr::IRR_KEY_F : s = "F"; break;
case irr::IRR_KEY_G : s = "G"; break;
case irr::IRR_KEY_H : s = "H"; break;
case irr::IRR_KEY_I : s = "I"; break;
case irr::IRR_KEY_J : s = "J"; break;
case irr::IRR_KEY_K : s = "K"; break;
case irr::IRR_KEY_L : s = "L"; break;
case irr::IRR_KEY_M : s = "M"; break;
case irr::IRR_KEY_N : s = "N"; break;
case irr::IRR_KEY_O : s = "O"; break;
case irr::IRR_KEY_P : s = "P"; break;
case irr::IRR_KEY_Q : s = "Q"; break;
case irr::IRR_KEY_R : s = "R"; break;
case irr::IRR_KEY_S : s = "S"; break;
case irr::IRR_KEY_T : s = "T"; break;
case irr::IRR_KEY_U : s = "U"; break;
case irr::IRR_KEY_V : s = "V"; break;
case irr::IRR_KEY_W : s = "W"; break;
case irr::IRR_KEY_X : s = "X"; break;
case irr::IRR_KEY_Y : s = "Y"; break;
case irr::IRR_KEY_Z : s = "Z"; break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_LWIN : s = _C("input_key", "Left Logo"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_RWIN : s = _C("input_key", "Right Logo"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_APPS : s = _C("input_key", "Apps"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_SLEEP : s = _C("input_key", "Sleep"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_NUMPAD0 : s = _C("input_key", "Numpad 0"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_NUMPAD1 : s = _C("input_key", "Numpad 1"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_NUMPAD2 : s = _C("input_key", "Numpad 2"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_NUMPAD3 : s = _C("input_key", "Numpad 3"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_NUMPAD4 : s = _C("input_key", "Numpad 4"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_NUMPAD5 : s = _C("input_key", "Numpad 5"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_NUMPAD6 : s = _C("input_key", "Numpad 6"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_NUMPAD7 : s = _C("input_key", "Numpad 7"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_NUMPAD8 : s = _C("input_key", "Numpad 8"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_NUMPAD9 : s = _C("input_key", "Numpad 9"); break;
case irr::IRR_KEY_MULTIPLY : s = "*"; break;
case irr::IRR_KEY_ADD : s = "+"; break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_SEPARATOR : s = _C("input_key", "Separator"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_SUBTRACT : s = _C("input_key", "- (Subtract)"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_DECIMAL : s = _C("input_key", "Decimal"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_DIVIDE : s = _C("input_key", "/ (Divide)"); break;
case irr::IRR_KEY_F1 : s = "F1"; break;
case irr::IRR_KEY_F2 : s = "F2"; break;
case irr::IRR_KEY_F3 : s = "F3"; break;
case irr::IRR_KEY_F4 : s = "F4"; break;
case irr::IRR_KEY_F5 : s = "F5"; break;
case irr::IRR_KEY_F6 : s = "F6"; break;
case irr::IRR_KEY_F7 : s = "F7"; break;
case irr::IRR_KEY_F8 : s = "F8"; break;
case irr::IRR_KEY_F9 : s = "F9"; break;
case irr::IRR_KEY_F10 : s = "F10"; break;
case irr::IRR_KEY_F11 : s = "F11"; break;
case irr::IRR_KEY_F12 : s = "F12"; break;
case irr::IRR_KEY_F13 : s = "F13"; break;
case irr::IRR_KEY_F14 : s = "F14"; break;
case irr::IRR_KEY_F15 : s = "F15"; break;
case irr::IRR_KEY_F16 : s = "F16"; break;
case irr::IRR_KEY_F17 : s = "F17"; break;
case irr::IRR_KEY_F18 : s = "F18"; break;
case irr::IRR_KEY_F19 : s = "F19"; break;
case irr::IRR_KEY_F20 : s = "F20"; break;
case irr::IRR_KEY_F21 : s = "F21"; break;
case irr::IRR_KEY_F22 : s = "F22"; break;
case irr::IRR_KEY_F23 : s = "F23"; break;
case irr::IRR_KEY_F24 : s = "F24"; break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_NUMLOCK : s = _C("input_key", "Num Lock"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_SCROLL : s = _C("input_key", "Scroll Lock"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_LSHIFT : s = _C("input_key", "Left Shift"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_RSHIFT : s = _C("input_key", "Right Shift"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_LCONTROL : s = _C("input_key", "Left Control"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_RCONTROL : s = _C("input_key", "Right Control"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_LMENU : s = _C("input_key", "Left Menu"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_RMENU : s = _C("input_key", "Right Menu"); break;
case irr::IRR_KEY_PLUS : s = "+"; break;
case irr::IRR_KEY_COMMA : s = ","; break;
case irr::IRR_KEY_MINUS : s = "-"; break;
case irr::IRR_KEY_PERIOD : s = "."; break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_ATTN : s = _C("input_key", "Attn"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_CRSEL : s = _C("input_key", "Crsel"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_EXSEL : s = _C("input_key", "Exsel"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_EREOF : s = _C("input_key", "Ereof"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_PLAY : s = _C("input_key", "Play"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_ZOOM : s = _C("input_key", "Zoom"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_PA1 : s = _C("input_key", "Pa1"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_OEM_CLEAR : s = _C("input_key", "Oem Clear"); break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_OEM_1 : s = ";"; break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_OEM_2 : s = "/"; break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_OEM_3 : s = "`"; break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_OEM_4 : s = "["; break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_OEM_5 : s = "\\"; break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_OEM_6 : s = "]"; break;
//I18N: input configuration screen: keyboard key
case irr::IRR_KEY_OEM_7 : s = "'"; break;
// for azerty layout
case irr::IRR_KEY_AMPERSAND : s = "&"; break;
case irr::IRR_KEY_EACUTE : s = "é"; break;
case irr::IRR_KEY_QUOTEDBL : s = "\""; break;
case irr::IRR_KEY_PARENLEFT : s = "("; break;
case irr::IRR_KEY_EGRAVE : s = "è"; break;
case irr::IRR_KEY_CCEDILLA : s = "ç"; break;
case irr::IRR_KEY_AGRAVE : s = "à"; break;
case irr::IRR_KEY_PARENRIGHT : s = ")"; break;
case irr::IRR_KEY_UGRAVE : s = "ù"; break;
case irr::IRR_KEY_COLON : s = ":"; break;
case irr::IRR_KEY_DOLLAR : s = "$"; break;
case irr::IRR_KEY_EXCLAM : s = "!"; break;
case irr::IRR_KEY_TWOSUPERIOR : s = "²"; break;
case irr::IRR_KEY_MU : s = "µ"; break;
case irr::IRR_KEY_SECTION : s = "§"; break;
}
break;
case Input::IT_STICKMOTION:
if (m_id == Input::HAT_H_ID)
{
//I18N: to appear in input configuration screen, for gamepad hats
s = _("Gamepad hat %d", (m_dir == Input::AD_NEGATIVE ? L"0-" : L"0+"));
}
else if (m_id == Input::HAT_V_ID)
{
//I18N: to appear in input configuration screen, for gamepad hats
s = _("Gamepad hat %d", (m_dir == Input::AD_NEGATIVE ? L"1-" : L"1+"));
}
else
{
if (m_range == Input::AR_HALF)
{
//I18N: to appear in input configuration screen, for gamepad axes
s = _("Axis %d %s", m_id, (m_dir == Input::AD_NEGATIVE) ? L"-" : L"+");
}
else
{
if(m_dir == Input::AD_NEGATIVE)
{
//I18N: to appear in input configuration screen, for gamepad axes
s = _("Axis %d inverted", m_id);
}
else
{
//I18N: to appear in input configuration screen, for gamepad axes
s = _("Axis %d", m_id);
}
}
}
break;
case Input::IT_STICKBUTTON:
//I18N: to appear in input configuration screen, for gamepad buttons
s = ( _("Gamepad button %d", m_id+1));
break; case Input::IT_MOUSEBUTTON:
//I18N: to appear in input configuration screen, for mouse (might not be used at all)
s = _("Mouse button %d", (m_id+1));
break;
case Input::IT_MOUSEMOTION: // FIXME : I don't reckon this is used at all
//I18N: to appear in input configuration screen, for mouse (might not be used at all)
s = _("Mouse axis %d %s", (m_id+1), (m_dir == Input::AD_NEGATIVE) ? '-': '+');
break;
default:
s = "?";
}
return s;
} // GetKeyAsString