Split text input into its own event.
This commit is contained in:
@@ -19,6 +19,7 @@ namespace OpenRA
|
|||||||
void ModifierKeys(Modifiers mods);
|
void ModifierKeys(Modifiers mods);
|
||||||
void OnKeyInput(KeyInput input);
|
void OnKeyInput(KeyInput input);
|
||||||
void OnMouseInput(MouseInput input);
|
void OnMouseInput(MouseInput input);
|
||||||
|
void OnTextInput(string text);
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum MouseInputEvent { Down, Move, Up }
|
public enum MouseInputEvent { Down, Move, Up }
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ namespace OpenRA
|
|||||||
// ignore all input
|
// ignore all input
|
||||||
public void ModifierKeys(Modifiers mods) { }
|
public void ModifierKeys(Modifiers mods) { }
|
||||||
public void OnKeyInput(KeyInput input) { }
|
public void OnKeyInput(KeyInput input) { }
|
||||||
|
public void OnTextInput(string text) { }
|
||||||
public void OnMouseInput(MouseInput input) { }
|
public void OnMouseInput(MouseInput input) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,6 +39,11 @@ namespace OpenRA
|
|||||||
Sync.CheckSyncUnchanged(world, () => Ui.HandleKeyPress(input));
|
Sync.CheckSyncUnchanged(world, () => Ui.HandleKeyPress(input));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void OnTextInput(string text)
|
||||||
|
{
|
||||||
|
Sync.CheckSyncUnchanged(world, () => Ui.HandleTextInput(text));
|
||||||
|
}
|
||||||
|
|
||||||
public void OnMouseInput(MouseInput input)
|
public void OnMouseInput(MouseInput input)
|
||||||
{
|
{
|
||||||
Sync.CheckSyncUnchanged(world, () => Ui.HandleInput(input));
|
Sync.CheckSyncUnchanged(world, () => Ui.HandleInput(input));
|
||||||
|
|||||||
@@ -154,27 +154,24 @@ namespace OpenRA.Widgets
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TypeChar(e);
|
if (e.Key == Keycode.BACKSPACE && CursorPosition > 0)
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void TypeChar(KeyInput key)
|
|
||||||
{
|
|
||||||
if (key.Key == Keycode.BACKSPACE && CursorPosition > 0)
|
|
||||||
{
|
{
|
||||||
CursorPosition--;
|
CursorPosition--;
|
||||||
Text = Text.Remove(CursorPosition, 1);
|
Text = Text.Remove(CursorPosition, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (key.IsValidInput())
|
return true;
|
||||||
{
|
}
|
||||||
if (MaxLength > 0 && Text.Length >= MaxLength)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Text = Text.Insert(CursorPosition, key.UnicodeChar.ToString());
|
public override bool HandleTextInput(string text)
|
||||||
|
{
|
||||||
|
if (MaxLength > 0 && Text.Length >= MaxLength)
|
||||||
|
return true;
|
||||||
|
|
||||||
CursorPosition++;
|
Text = Text.Insert(CursorPosition, text);
|
||||||
}
|
CursorPosition++;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int blinkCycle = 10;
|
protected int blinkCycle = 10;
|
||||||
|
|||||||
@@ -104,9 +104,15 @@ namespace OpenRA.Widgets
|
|||||||
if (KeyboardFocusWidget != null)
|
if (KeyboardFocusWidget != null)
|
||||||
return KeyboardFocusWidget.HandleKeyPressOuter(e);
|
return KeyboardFocusWidget.HandleKeyPressOuter(e);
|
||||||
|
|
||||||
if (Root.HandleKeyPressOuter(e))
|
return Root.HandleKeyPressOuter(e);
|
||||||
return true;
|
}
|
||||||
return false;
|
|
||||||
|
public static bool HandleTextInput(string text)
|
||||||
|
{
|
||||||
|
if (KeyboardFocusWidget != null)
|
||||||
|
return KeyboardFocusWidget.HandleTextInputOuter(text);
|
||||||
|
|
||||||
|
return Root.HandleTextInputOuter(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ResetAll()
|
public static void ResetAll()
|
||||||
@@ -334,12 +340,30 @@ namespace OpenRA.Widgets
|
|||||||
if (child.HandleKeyPressOuter(e))
|
if (child.HandleKeyPressOuter(e))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Do any widgety behavior (enter text etc)
|
// Do any widgety behavior
|
||||||
var handled = HandleKeyPress(e);
|
var handled = HandleKeyPress(e);
|
||||||
|
|
||||||
return handled;
|
return handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual bool HandleTextInput(string text) { return false; }
|
||||||
|
|
||||||
|
public virtual bool HandleTextInputOuter(string text)
|
||||||
|
{
|
||||||
|
if (!IsVisible())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Can any of our children handle this?
|
||||||
|
foreach (var child in Children.OfType<Widget>().Reverse())
|
||||||
|
if (child.HandleTextInputOuter(text))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Do any widgety behavior (enter text etc)
|
||||||
|
var handled = HandleTextInput(text);
|
||||||
|
|
||||||
|
return handled;
|
||||||
|
}
|
||||||
|
|
||||||
public virtual void Draw() {}
|
public virtual void Draw() {}
|
||||||
|
|
||||||
public virtual void DrawOuter()
|
public virtual void DrawOuter()
|
||||||
|
|||||||
@@ -130,6 +130,9 @@ namespace OpenRA.Renderer.SdlCommon
|
|||||||
else
|
else
|
||||||
inputHandler.OnKeyInput(keyEvent);
|
inputHandler.OnKeyInput(keyEvent);
|
||||||
|
|
||||||
|
if (keyEvent.IsValidInput())
|
||||||
|
inputHandler.OnTextInput(keyEvent.UnicodeChar.ToString());
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user