// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using osu.Framework.Platform; namespace osu.Framework.Input { public class GameWindowTextInput : ITextInputSource { private readonly IWindow window; private string pending = string.Empty; public GameWindowTextInput(IWindow window) { this.window = window; } protected virtual void HandleKeyPress(object sender, osuTK.KeyPressEventArgs e) => pending += e.KeyChar; protected virtual void HandleKeyTyped(char c) => pending += c; public bool ImeActive => false; public string GetPendingText() { try { return pending; } finally { pending = string.Empty; } } public void Deactivate() { switch (window) { case SDL2DesktopWindow win: win.KeyTyped -= HandleKeyTyped; break; case OsuTKWindow tkWin: tkWin.KeyPress -= HandleKeyPress; break; } } public void Activate() { switch (window) { case SDL2DesktopWindow win: win.KeyTyped += HandleKeyTyped; break; case OsuTKWindow tkWin: tkWin.KeyPress += HandleKeyPress; break; } } public void EnsureActivated() { } private void imeCompose() { //todo: implement OnNewImeComposition?.Invoke(string.Empty); } private void imeResult() { //todo: implement OnNewImeResult?.Invoke(string.Empty); } public event Action OnNewImeComposition; public event Action OnNewImeResult; } }