-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSystemInterface.cpp
442 lines (427 loc) · 10.4 KB
/
SystemInterface.cpp
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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
/*
* This source file is part of RmlUi, the HTML/CSS Interface Middleware
*
* For the latest information, see http://github.com/mikke89/RmlUi
*
* Copyright (c) 2008-2010 Nuno Silva
* Copyright (c) 2019 The RmlUi Team, and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
#include "SystemInterface.h"
#include <RmlUi/Core.h>
Rml::Input::KeyIdentifier SystemInterface::TranslateKey(SDL_Keycode sdlkey)
{
using namespace Rml::Input;
switch(sdlkey) {
case SDLK_UNKNOWN:
return KI_UNKNOWN;
break;
case SDLK_SPACE:
return KI_SPACE;
break;
case SDLK_0:
return KI_0;
break;
case SDLK_1:
return KI_1;
break;
case SDLK_2:
return KI_2;
break;
case SDLK_3:
return KI_3;
break;
case SDLK_4:
return KI_4;
break;
case SDLK_5:
return KI_5;
break;
case SDLK_6:
return KI_6;
break;
case SDLK_7:
return KI_7;
break;
case SDLK_8:
return KI_8;
break;
case SDLK_9:
return KI_9;
break;
case SDLK_a:
return KI_A;
break;
case SDLK_b:
return KI_B;
break;
case SDLK_c:
return KI_C;
break;
case SDLK_d:
return KI_D;
break;
case SDLK_e:
return KI_E;
break;
case SDLK_f:
return KI_F;
break;
case SDLK_g:
return KI_G;
break;
case SDLK_h:
return KI_H;
break;
case SDLK_i:
return KI_I;
break;
case SDLK_j:
return KI_J;
break;
case SDLK_k:
return KI_K;
break;
case SDLK_l:
return KI_L;
break;
case SDLK_m:
return KI_M;
break;
case SDLK_n:
return KI_N;
break;
case SDLK_o:
return KI_O;
break;
case SDLK_p:
return KI_P;
break;
case SDLK_q:
return KI_Q;
break;
case SDLK_r:
return KI_R;
break;
case SDLK_s:
return KI_S;
break;
case SDLK_t:
return KI_T;
break;
case SDLK_u:
return KI_U;
break;
case SDLK_v:
return KI_V;
break;
case SDLK_w:
return KI_W;
break;
case SDLK_x:
return KI_X;
break;
case SDLK_y:
return KI_Y;
break;
case SDLK_z:
return KI_Z;
break;
case SDLK_SEMICOLON:
return KI_OEM_1;
break;
case SDLK_PLUS:
return KI_OEM_PLUS;
break;
case SDLK_COMMA:
return KI_OEM_COMMA;
break;
case SDLK_MINUS:
return KI_OEM_MINUS;
break;
case SDLK_PERIOD:
return KI_OEM_PERIOD;
break;
case SDLK_SLASH:
return KI_OEM_2;
break;
case SDLK_BACKQUOTE:
return KI_OEM_3;
break;
case SDLK_LEFTBRACKET:
return KI_OEM_4;
break;
case SDLK_BACKSLASH:
return KI_OEM_5;
break;
case SDLK_RIGHTBRACKET:
return KI_OEM_6;
break;
case SDLK_QUOTEDBL:
return KI_OEM_7;
break;
case SDLK_KP_0:
return KI_NUMPAD0;
break;
case SDLK_KP_1:
return KI_NUMPAD1;
break;
case SDLK_KP_2:
return KI_NUMPAD2;
break;
case SDLK_KP_3:
return KI_NUMPAD3;
break;
case SDLK_KP_4:
return KI_NUMPAD4;
break;
case SDLK_KP_5:
return KI_NUMPAD5;
break;
case SDLK_KP_6:
return KI_NUMPAD6;
break;
case SDLK_KP_7:
return KI_NUMPAD7;
break;
case SDLK_KP_8:
return KI_NUMPAD8;
break;
case SDLK_KP_9:
return KI_NUMPAD9;
break;
case SDLK_KP_ENTER:
return KI_NUMPADENTER;
break;
case SDLK_KP_MULTIPLY:
return KI_MULTIPLY;
break;
case SDLK_KP_PLUS:
return KI_ADD;
break;
case SDLK_KP_MINUS:
return KI_SUBTRACT;
break;
case SDLK_KP_PERIOD:
return KI_DECIMAL;
break;
case SDLK_KP_DIVIDE:
return KI_DIVIDE;
break;
case SDLK_KP_EQUALS:
return KI_OEM_NEC_EQUAL;
break;
case SDLK_BACKSPACE:
return KI_BACK;
break;
case SDLK_TAB:
return KI_TAB;
break;
case SDLK_CLEAR:
return KI_CLEAR;
break;
case SDLK_RETURN:
return KI_RETURN;
break;
case SDLK_PAUSE:
return KI_PAUSE;
break;
case SDLK_CAPSLOCK:
return KI_CAPITAL;
break;
case SDLK_PAGEUP:
return KI_PRIOR;
break;
case SDLK_PAGEDOWN:
return KI_NEXT;
break;
case SDLK_END:
return KI_END;
break;
case SDLK_HOME:
return KI_HOME;
break;
case SDLK_LEFT:
return KI_LEFT;
break;
case SDLK_UP:
return KI_UP;
break;
case SDLK_RIGHT:
return KI_RIGHT;
break;
case SDLK_DOWN:
return KI_DOWN;
break;
case SDLK_INSERT:
return KI_INSERT;
break;
case SDLK_DELETE:
return KI_DELETE;
break;
case SDLK_HELP:
return KI_HELP;
break;
case SDLK_F1:
return KI_F1;
break;
case SDLK_F2:
return KI_F2;
break;
case SDLK_F3:
return KI_F3;
break;
case SDLK_F4:
return KI_F4;
break;
case SDLK_F5:
return KI_F5;
break;
case SDLK_F6:
return KI_F6;
break;
case SDLK_F7:
return KI_F7;
break;
case SDLK_F8:
return KI_F8;
break;
case SDLK_F9:
return KI_F9;
break;
case SDLK_F10:
return KI_F10;
break;
case SDLK_F11:
return KI_F11;
break;
case SDLK_F12:
return KI_F12;
break;
case SDLK_F13:
return KI_F13;
break;
case SDLK_F14:
return KI_F14;
break;
case SDLK_F15:
return KI_F15;
break;
case SDLK_NUMLOCKCLEAR:
return KI_NUMLOCK;
break;
case SDLK_SCROLLLOCK:
return KI_SCROLL;
break;
case SDLK_LSHIFT:
return KI_LSHIFT;
break;
case SDLK_RSHIFT:
return KI_RSHIFT;
break;
case SDLK_LCTRL:
return KI_LCONTROL;
break;
case SDLK_RCTRL:
return KI_RCONTROL;
break;
case SDLK_LALT:
return KI_LMENU;
break;
case SDLK_RALT:
return KI_RMENU;
break;
case SDLK_LGUI:
return KI_LMETA;
break;
case SDLK_RGUI:
return KI_RMETA;
break;
/*case SDLK_LSUPER:
return KI_LWIN;
break;
case SDLK_RSUPER:
return KI_RWIN;
break;*/
default:
return KI_UNKNOWN;
break;
}
}
int SystemInterface::TranslateMouseButton(Uint8 button)
{
switch(button)
{
case SDL_BUTTON_LEFT:
return 0;
case SDL_BUTTON_RIGHT:
return 1;
case SDL_BUTTON_MIDDLE:
return 2;
default:
return 3;
}
}
int SystemInterface::GetKeyModifiers()
{
SDL_Keymod sdlMods = SDL_GetModState();
int retval = 0;
if(sdlMods & KMOD_CTRL)
retval |= Rml::Input::KM_CTRL;
if(sdlMods & KMOD_SHIFT)
retval |= Rml::Input::KM_SHIFT;
if(sdlMods & KMOD_ALT)
retval |= Rml::Input::KM_ALT;
return retval;
}
double SystemInterface::GetElapsedTime()
{
return double(SDL_GetTicks()) / 1000.0;
}
bool SystemInterface::LogMessage(Rml::Log::Type type, const Rml::String& message)
{
Rml::String Type;
switch(type)
{
case Rml::Log::LT_ALWAYS:
Type = "[Always]";
break;
case Rml::Log::LT_ERROR:
Type = "[Error]";
break;
case Rml::Log::LT_ASSERT:
Type = "[Assert]";
break;
case Rml::Log::LT_WARNING:
Type = "[Warning]";
break;
case Rml::Log::LT_INFO:
Type = "[Info]";
break;
case Rml::Log::LT_DEBUG:
Type = "[Debug]";
break;
case Rml::Log::LT_MAX:
break;
};
printf("%s - %s\n", Type.c_str(), message.c_str());
return true;
}