Gondwana Game Engine Development (master) - 2.6.1
Gondwana is a cross-platform 2.5D game and rendering engine written in C#/.NET 8. It provides fine-grained control over rendering, timing, and scene composition, with built-in support for parallax, z-ordering, pixel overhang, collision detection, and particle effects. Gondwana targets desktop and web platforms using SkiaSharp for graphics and pluggable audio backends for desktop and browser targets.
Loading...
Searching...
No Matches
BlazorTextBoxInput.cs
5
7
11public static class BlazorTextBoxInput
12{
19 public static TextBoxWidget Configure(TextBoxWidget textBox)
20 {
21 ArgumentNullException.ThrowIfNull(textBox);
22
23 textBox.SubmitKey = (int)BlazorKey.Enter;
24 textBox.BackspaceKey = (int)BlazorKey.Backspace;
25 textBox.DeleteKey = (int)BlazorKey.Delete;
26 textBox.LeftKey = (int)BlazorKey.ArrowLeft;
27 textBox.RightKey = (int)BlazorKey.ArrowRight;
28 textBox.HomeKey = (int)BlazorKey.Home;
29 textBox.EndKey = (int)BlazorKey.End;
30 textBox.CharacterResolver = ResolveCharacter;
31
32 return textBox;
33 }
34
39 public static void StartMonitoring(KeyboardEventPoller keyboard)
40 {
41 ArgumentNullException.ThrowIfNull(keyboard);
42
43 RegisterRange(BlazorKey.KeyA, BlazorKey.KeyZ);
44 RegisterRange(BlazorKey.Digit1, BlazorKey.Digit0);
45 RegisterRange(BlazorKey.Numpad0, BlazorKey.Numpad9);
46
47 foreach (BlazorKey key in new[]
48 {
49 BlazorKey.Space,
50 BlazorKey.Enter,
51 BlazorKey.Backspace,
52 BlazorKey.Delete,
53 BlazorKey.ArrowLeft,
54 BlazorKey.ArrowRight,
55 BlazorKey.Home,
56 BlazorKey.End,
57 BlazorKey.NumpadAdd,
58 BlazorKey.NumpadSubtract,
59 BlazorKey.NumpadMultiply,
60 BlazorKey.NumpadDivide,
61 BlazorKey.NumpadDecimal,
62 BlazorKey.Minus,
63 BlazorKey.Equal,
64 BlazorKey.BracketLeft,
65 BlazorKey.BracketRight,
66 BlazorKey.Backslash,
67 BlazorKey.Semicolon,
68 BlazorKey.Quote,
69 BlazorKey.Backquote,
70 BlazorKey.Comma,
71 BlazorKey.Period,
73 })
74 {
75 keyboard.StartMonitoringKey((int)key);
76 }
77
78 void RegisterRange(BlazorKey first, BlazorKey last)
79 {
80 for (int key = (int)first; key <= (int)last; key++)
81 keyboard.StartMonitoringKey(key);
82 }
83 }
84
90 public static char? ResolveCharacter(WidgetKeyboardEventArgs args)
91 {
92 ArgumentNullException.ThrowIfNull(args);
93
94 if ((args.Modifiers & (KeyboardModifierState.Ctrl | KeyboardModifierState.Alt)) != 0)
95 return null;
96
97 bool shift = (args.Modifiers & KeyboardModifierState.Shift) != 0;
98 var key = (BlazorKey)args.Key;
99
100 if (key is >= BlazorKey.KeyA and <= BlazorKey.KeyZ)
101 {
102 char letter = (char)('a' + ((int)key - (int)BlazorKey.KeyA));
103 return shift ? char.ToUpperInvariant(letter) : letter;
104 }
105
106 if (key is >= BlazorKey.Digit1 and <= BlazorKey.Digit9)
107 {
108 int offset = (int)key - (int)BlazorKey.Digit1;
109 if (!shift)
110 return (char)('1' + offset);
111
112 const string shiftedDigits = "!@#$%^&*(";
113 return shiftedDigits[offset];
114 }
115
116 if (key == BlazorKey.Digit0)
117 return shift ? ')' : '0';
118
119 if (key is >= BlazorKey.Numpad0 and <= BlazorKey.Numpad9)
120 return (char)('0' + ((int)key - (int)BlazorKey.Numpad0));
121
122 return key switch
123 {
124 BlazorKey.Space => ' ',
125 BlazorKey.NumpadAdd => '+',
130 BlazorKey.Minus => shift ? '_' : '-',
131 BlazorKey.Equal => shift ? '+' : '=',
132 BlazorKey.BracketLeft => shift ? '{' : '[',
133 BlazorKey.BracketRight => shift ? '}' : ']',
134 BlazorKey.Backslash => shift ? '|' : '\\',
135 BlazorKey.Semicolon => shift ? ':' : ';',
136 BlazorKey.Quote => shift ? '"' : '\'',
137 BlazorKey.Backquote => shift ? '~' : '`',
138 BlazorKey.Comma => shift ? '<' : ',',
139 BlazorKey.Period => shift ? '>' : '.',
140 BlazorKey.Slash => shift ? '?' : '/',
141 _ => null
142 };
143 }
144}
Cross-platform singleton keyboard handler with throttling and manual input state feeding.
void StartMonitoringKey(int keyCode, string? displayName=null, double timeBetweenEvents=-1, bool isPaused=false)
Primary API: monitor by platform-agnostic key code. Platform layers (WinForms, SDL,...
Provides a single-line editable text box with keyboard caret navigation.
Provides data for widget keyboard input events routed by WidgetInputRouter.
KeyboardModifierState Modifiers
Gets the keyboard modifier state at the time of the event.
int Key
Gets the integer key identifier.
BlazorKey
Maps browser KeyboardEvent.code values to stable integer key codes used by BlazorKeyboardAdapter and ...
Definition BlazorKey.cs:15
@ NumpadDecimal
Numpad decimal point.
Definition BlazorKey.cs:209
KeyboardModifierState
Represents the state of keyboard modifier keys (Shift, Ctrl, Alt) that can be pressed simultaneously ...