Gondwana Game Engine Development (master) - 2.7.0
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
110 if (!shift)
111 return (char)('1' + offset);
112
113 const string shiftedDigits = "!@#$%^&*(";
114 return shiftedDigits[offset];
115 }
116
117 if (key == BlazorKey.Digit0)
118 return shift ? ')' : '0';
119
120 if (key is >= BlazorKey.Numpad0 and <= BlazorKey.Numpad9)
121 return (char)('0' + ((int)key - (int)BlazorKey.Numpad0));
122
123 return key switch
124 {
125 BlazorKey.Space => ' ',
126 BlazorKey.NumpadAdd => '+',
131 BlazorKey.Minus => shift ? '_' : '-',
132 BlazorKey.Equal => shift ? '+' : '=',
133 BlazorKey.BracketLeft => shift ? '{' : '[',
134 BlazorKey.BracketRight => shift ? '}' : ']',
135 BlazorKey.Backslash => shift ? '|' : '\\',
136 BlazorKey.Semicolon => shift ? ':' : ';',
137 BlazorKey.Quote => shift ? '"' : '\'',
138 BlazorKey.Backquote => shift ? '~' : '`',
139 BlazorKey.Comma => shift ? '<' : ',',
140 BlazorKey.Period => shift ? '>' : '.',
141 BlazorKey.Slash => shift ? '?' : '/',
142 _ => null
143 };
144 }
145}
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:291
KeyboardModifierState
Represents the state of keyboard modifier keys (Shift, Ctrl, Alt) that can be pressed simultaneously ...