1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 10:33:30 +08:00

Hook up new TextInputSource to TextBox.

This commit is contained in:
Dean Herbert 2016-09-02 14:30:29 +09:00
parent ebd15d6f7c
commit 7d9cb85289

View File

@ -36,7 +36,7 @@ namespace osu.Game.Graphics.UserInterface
public bool ReadOnly; public bool ReadOnly;
//BackingTextBox backingTextbox; TextInputSource textInput;
internal delegate void OnCommitHandler(TextBox sender, bool newText); internal delegate void OnCommitHandler(TextBox sender, bool newText);
internal event OnCommitHandler OnCommit; internal event OnCommitHandler OnCommit;
@ -84,7 +84,7 @@ namespace osu.Game.Graphics.UserInterface
OnChange = null; OnChange = null;
OnCommit = null; OnCommit = null;
UnbindTextbox(); UnbindInput();
base.Dispose(disposing); base.Dispose(disposing);
} }
@ -200,7 +200,7 @@ namespace osu.Game.Graphics.UserInterface
private void moveSelection(int offset, bool expand) private void moveSelection(int offset, bool expand)
{ {
//if (backingTextbox?.ImeActive == true) return; if (textInput?.ImeActive == true) return;
int oldStart = selectionStart; int oldStart = selectionStart;
int oldEnd = selectionEnd; int oldEnd = selectionEnd;
@ -375,7 +375,7 @@ namespace osu.Game.Graphics.UserInterface
if (!HasFocus) if (!HasFocus)
return false; return false;
//if (backingTextbox?.ImeActive == true) return true; if (textInput?.ImeActive == true) return true;
switch (args.Key) switch (args.Key)
{ {
@ -493,14 +493,14 @@ namespace osu.Game.Graphics.UserInterface
return true; return true;
case Key.V: case Key.V:
//the text is pasted into the hidden textbox, so we don't need any direct clipboard interaction here. //the text is pasted into the hidden textbox, so we don't need any direct clipboard interaction here.
//insertString(backingTextbox.GetPendingText()); //insertString(textInput.GetPendingText());
return true; return true;
} }
return false; return false;
} }
string str = "A";// backingTextbox.GetPendingText(); string str = textInput.GetPendingText();
if (!string.IsNullOrEmpty(str)) if (!string.IsNullOrEmpty(str))
{ {
if (state.Keyboard.ShiftPressed) if (state.Keyboard.ShiftPressed)
@ -517,7 +517,7 @@ namespace osu.Game.Graphics.UserInterface
protected override bool OnDrag(InputState state) protected override bool OnDrag(InputState state)
{ {
//if (backingTextbox?.ImeActive == true) return true; //if (textInput?.ImeActive == true) return true;
if (text.Length == 0) return true; if (text.Length == 0) return true;
@ -537,7 +537,7 @@ namespace osu.Game.Graphics.UserInterface
protected override bool OnDoubleClick(InputState state) protected override bool OnDoubleClick(InputState state)
{ {
//if (backingTextbox?.ImeActive == true) return true; if (textInput?.ImeActive == true) return true;
if (text.Length == 0) return true; if (text.Length == 0) return true;
@ -554,7 +554,7 @@ namespace osu.Game.Graphics.UserInterface
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
{ {
//if (backingTextbox?.ImeActive == true) return true; if (textInput?.ImeActive == true) return true;
selectionStart = selectionEnd = getCharacterClosestTo(state.Mouse.Position); selectionStart = selectionEnd = getCharacterClosestTo(state.Mouse.Position);
@ -565,7 +565,7 @@ namespace osu.Game.Graphics.UserInterface
protected override void OnFocusLost(InputState state) protected override void OnFocusLost(InputState state)
{ {
UnbindTextbox(); UnbindInput();
cursor.ClearTransformations(); cursor.ClearTransformations();
cursor.FadeOut(200); cursor.FadeOut(200);
@ -592,7 +592,7 @@ namespace osu.Game.Graphics.UserInterface
{ {
if (ReadOnly) return false; if (ReadOnly) return false;
//BindTextbox(); BindInput();
textBeforeCommit = Text; textBeforeCommit = Text;
if (ResetTextOnEdit) if (ResetTextOnEdit)
@ -606,39 +606,39 @@ namespace osu.Game.Graphics.UserInterface
} }
#region Native TextBox handling (winform specific) #region Native TextBox handling (winform specific)
protected void UnbindTextbox() protected void UnbindInput()
{ {
//backingTextbox?.Deactivate(OsuGame.Window.Form); textInput?.Deactivate();
} }
//protected void BindTextbox() protected void BindInput()
//{ {
// if (backingTextbox == null) if (textInput == null)
// { {
// backingTextbox = new BackingTextBox(); textInput = Game.Host.TextInput;
// backingTextbox.OnNewImeComposition += onImeComposition; textInput.OnNewImeComposition += onImeComposition;
// backingTextbox.OnNewImeResult += onImeResult; textInput.OnNewImeResult += onImeResult;
// } }
// backingTextbox.Activate(OsuGame.Window.Form); textInput.Activate();
//} }
//private void onImeResult(string s) private void onImeResult(string s)
//{ {
// //we only succeeded if there is pending data in the textbox //we only succeeded if there is pending data in the textbox
// if (imeDrawables.Count > 0) if (imeDrawables.Count > 0)
// { {
// Game.Audio.Sample.Get($@"Keyboard/key-confirm")?.Play(); Game.Audio.Sample.Get($@"Keyboard/key-confirm")?.Play();
// foreach (Drawable d in imeDrawables) foreach (Drawable d in imeDrawables)
// { {
// d.Colour = Color4.White; d.Colour = Color4.White;
// d.FadeTo(1, 200, EasingTypes.Out); d.FadeTo(1, 200, EasingTypes.Out);
// } }
// } }
// imeDrawables.Clear(); imeDrawables.Clear();
//} }
List<Drawable> imeDrawables = new List<Drawable>(); List<Drawable> imeDrawables = new List<Drawable>();