fna-workbench

fna-workbench Commit Details


Date:2016-01-18 13:40:20 (9 years 7 months ago)
Author:Ethan Lee
Branch:master
Commit:39023e15e94ded94f79efb20391ad3a1b101616a
Parents: 124241feb24357bb7a337edde67efa1a63038acf
Message:USE_SCANCODES is now an environment variable

Changes:

File differences

src/SDL2/SDL2_FNAPlatform.cs
77
88
99
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
2710
2811
2912
......
157140
158141
159142
143
144
145
146
147
148
149
150
151
160152
161153
162154
......
176168
177169
178170
179
180
181
182
183
171
184172
185173
186174
......
213201
214202
215203
216
217
218
219
220
204
221205
222206
223207
*/
#endregion
#region USE_SCANCODES Option
// #define USE_SCANCODES
/* XNA Keys are based on keycodes, rather than scancodes.
*
* With SDL2 you can actually pick between SDL_Keycode and SDL_Scancode, but
* scancodes will not be accurate to XNA4. The benefit is that scancodes will
* essentially ignore "foreign" keyboard layouts, making default keyboard
* layouts work out of the box everywhere (unless the actual symbol for the keys
* matters in your game).
*
* At the same time, the TextInputEXT extension will still read the actual chars
* correctly, so you can (mostly) have your cake and eat it too if you don't
* care about your bindings menu not making a lot of sense on foreign layouts.
* -flibit
*/
#endregion
#region Using Statements
using System;
using System.IO;
osxUseSpaces = false;
}
// Do we want to read keycodes or scancodes?
SDL2_KeyboardUtil.UseScancodes = Environment.GetEnvironmentVariable(
"FNA_KEYBOARD_USE_SCANCODES"
) == "1";
if (SDL2_KeyboardUtil.UseScancodes)
{
Log("Using scancodes instead of keycodes!");
}
// Active Key List
List<Keys> keys = new List<Keys>();
// Keyboard
if (evt.type == SDL.SDL_EventType.SDL_KEYDOWN)
{
#if USE_SCANCODES
Keys key = SDL2_KeyboardUtil.ToXNA(evt.key.keysym.scancode);
#else
Keys key = SDL2_KeyboardUtil.ToXNA(evt.key.keysym.sym);
#endif
Keys key = SDL2_KeyboardUtil.ToXNA(ref evt.key.keysym);
if (!keys.Contains(key))
{
keys.Add(key);
}
else if (evt.type == SDL.SDL_EventType.SDL_KEYUP)
{
#if USE_SCANCODES
Keys key = SDL2_KeyboardUtil.ToXNA(evt.key.keysym.scancode);
#else
Keys key = SDL2_KeyboardUtil.ToXNA(evt.key.keysym.sym);
#endif
Keys key = SDL2_KeyboardUtil.ToXNA(ref evt.key.keysym);
if (keys.Remove(key))
{
if (key == Keys.Back)
src/SDL2/SDL2_KeyboardUtil.cs
1717
1818
1919
20
21
22
23
24
25
2026
2127
2228
......
409415
410416
411417
412
418
413419
414420
415
421
416422
417
423
424
425
426
418427
419428
420429
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
430
431
432
433
437434
435
436
437
438
439
440
438441
439442
440443
{
internal static class SDL2_KeyboardUtil
{
#region Public Static Key Map Override
public static bool UseScancodes = false;
#endregion
#region Private SDL2->XNA Key Hashmaps
/* From: http://blogs.msdn.com/b/shawnhar/archive/2007/07/02/twin-paths-to-garbage-collector-nirvana.aspx
#region Public SDL2<->XNA Key Conversion Methods
public static Keys ToXNA(SDL.SDL_Keycode key)
public static Keys ToXNA(ref SDL.SDL_Keysym key)
{
Keys retVal;
if (INTERNAL_keyMap.TryGetValue((int) key, out retVal))
if (UseScancodes)
{
return retVal;
if (INTERNAL_scanMap.TryGetValue((int) key.scancode, out retVal))
{
return retVal;
}
}
else
{
SDL2_FNAPlatform.Log("KEY MISSING FROM SDL2->XNA DICTIONARY: " + key.ToString());
return Keys.None;
}
}
public static Keys ToXNA(SDL.SDL_Scancode key)
{
Keys retVal;
if (INTERNAL_scanMap.TryGetValue((int) key, out retVal))
{
return retVal;
}
else
{
SDL2_FNAPlatform.Log("SCANCODE MISSING FROM SDL2->XNA DICTIONARY: " + key.ToString());
return Keys.None;
if (INTERNAL_keyMap.TryGetValue((int) key.sym, out retVal))
{
return retVal;
}
}
SDL2_FNAPlatform.Log(
"KEY/SCANCODE MISSING FROM SDL2->XNA DICTIONARY: " +
key.sym.ToString() + " " +
key.scancode.ToString()
);
return Keys.None;
}
public static Keys KeyFromScancode(Keys scancode)

Archive Download the corresponding diff file

Branches

Number of commits:
Page rendered in 0.61197s using 13 queries.