HeadlessDynamicTextInputHandler.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using Ryujinx.HLE.Ui;
  2. using System.Threading;
  3. using System.Threading.Tasks;
  4. namespace Ryujinx.Headless.SDL2
  5. {
  6. /// <summary>
  7. /// Headless text processing class, right now there is no way to forward the input to it.
  8. /// </summary>
  9. internal class HeadlessDynamicTextInputHandler : IDynamicTextInputHandler
  10. {
  11. private bool _canProcessInput;
  12. public event DynamicTextChangedHandler TextChangedEvent;
  13. public event KeyPressedHandler KeyPressedEvent { add { } remove { } }
  14. public event KeyReleasedHandler KeyReleasedEvent { add { } remove { } }
  15. public bool TextProcessingEnabled
  16. {
  17. get
  18. {
  19. return Volatile.Read(ref _canProcessInput);
  20. }
  21. set
  22. {
  23. Volatile.Write(ref _canProcessInput, value);
  24. // Launch a task to update the text.
  25. Task.Run(() =>
  26. {
  27. Thread.Sleep(100);
  28. TextChangedEvent?.Invoke("Ryujinx", 7, 7, false);
  29. });
  30. }
  31. }
  32. public HeadlessDynamicTextInputHandler()
  33. {
  34. // Start with input processing turned off so the text box won't accumulate text
  35. // if the user is playing on the keyboard.
  36. _canProcessInput = false;
  37. }
  38. public void SetText(string text, int cursorBegin) { }
  39. public void SetText(string text, int cursorBegin, int cursorEnd) { }
  40. public void Dispose() { }
  41. }
  42. }