/// <summary> /// Erzeugt eine neue Instanz der Klasse BaseScreenComponent. /// </summary> /// <param name="game">Die aktuelle Game-Instanz.</param> public BaseScreenComponent(Game game) : base(game) { Content = game.Content; KeyboardEnabled = true; MouseEnabled = true; GamePadEnabled = true; TouchEnabled = true; DoubleClickDelay = DEFAULTDOUBLECLICKDELAY; #if !ANDROID Game.Window.TextInput += (s, e) => { if (Game.IsActive) { KeyTextEventArgs args = new KeyTextEventArgs() { Character = e.Character }; root.InternalKeyTextPress(args); } }; #endif Game.Window.ClientSizeChanged += (s, e) => { if (ClientSizeChanged != null) ClientSizeChanged(s, e); }; }
public BaseScreenComponent(Game game) : base(game) { Content = game.Content; Game.Window.TextInput += (s, e) => { if (Game.IsActive) { KeyTextEventArgs args = new KeyTextEventArgs() { Character = e.Character }; root.InternalKeyTextPress(args); } }; }
protected override void OnKeyTextPress(KeyTextEventArgs args) { // Ignorieren, wenn kein Fokus if (Focused != TreeState.Active) { return; } // Steuerzeichen ignorieren if (args.Character == '\b' || args.Character == '\t' || args.Character == '\n' || args.Character == '\r') { return; } // Strg-Kombinationen (A, X, C, V) ignorieren if (args.Character == '\u0001' || args.Character == '\u0003' || args.Character == '\u0016' || args.Character == '\u0018') { return; } //Escape ignorieren if (args.Character == '\u001b') { return; } if (SelectionStart != CursorPosition) { int from = Math.Min(SelectionStart, CursorPosition); int to = Math.Max(SelectionStart, CursorPosition); Text = Text.Substring(0, from) + Text.Substring(to); CursorPosition = from; SelectionStart = from; } Text = Text.Substring(0, CursorPosition) + args.Character + Text.Substring(CursorPosition); CursorPosition++; SelectionStart++; args.Handled = true; }
protected virtual void OnKeyTextPress(KeyTextEventArgs args) { }
internal void InternalKeyTextPress(KeyTextEventArgs args) { // Children first (Order by Z-Order) foreach (var child in Children.InZOrder()) { child.InternalKeyTextPress(args); if (args.Handled) break; } // Bubble up if (!args.Handled) { OnKeyTextPress(args); if (KeyTextPress != null) KeyTextPress(this, args); } }
protected override void OnKeyTextPress(KeyTextEventArgs args) { // Ignorieren, wenn kein Fokus if (Focused != TreeState.Active) return; // Steuerzeichen ignorieren if (args.Character == '\b' || args.Character == '\t' || args.Character == '\n' || args.Character == '\r') return; // Strg-Kombinationen (A, X, C, V) ignorieren if (args.Character == '\u0001' || args.Character == '\u0003' || args.Character == '\u0016' || args.Character == '\u0018') return; //Escape ignorieren if (args.Character == '\u001b') return; if (SelectionStart != CursorPosition) { int from = Math.Min(SelectionStart, CursorPosition); int to = Math.Max(SelectionStart, CursorPosition); Text = Text.Substring(0, from) + Text.Substring(to); CursorPosition = from; SelectionStart = from; } Text = Text.Substring(0, CursorPosition) + args.Character + Text.Substring(CursorPosition); CursorPosition++; SelectionStart++; args.Handled = true; }