GUITextBox.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. namespace BansheeEngine
  4. {
  5. /// <summary>
  6. /// GUI element that accepts Unicode textual input. It can be single or multi-line and handles various types of text
  7. /// manipulation.
  8. /// </summary>
  9. public sealed class GUITextBox : GUIElement
  10. {
  11. public delegate void OnChangedDelegate(string newValue);
  12. /// <summary>
  13. /// Triggered whenever input text has changed.
  14. /// </summary>
  15. public event OnChangedDelegate OnChanged;
  16. /// <summary>
  17. /// Creates a new text box element.
  18. /// </summary>
  19. /// <param name="multiline">Determines should the input box allow text that spans multiple lines.</param>
  20. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  21. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  22. /// default element style is used.</param>
  23. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  24. /// override any similar options set by style.</param>
  25. public GUITextBox(bool multiline, string style, params GUIOption[] options)
  26. {
  27. Internal_CreateInstance(this, multiline, style, options);
  28. }
  29. /// <summary>
  30. /// Creates a new text box element.
  31. /// </summary>
  32. /// <param name="multiline">Determines should the input box allow text that spans multiple lines.</param>
  33. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  34. /// override any similar options set by style.</param>
  35. public GUITextBox(bool multiline, params GUIOption[] options)
  36. {
  37. Internal_CreateInstance(this, multiline, "", options);
  38. }
  39. /// <summary>
  40. /// Creates a new single-line text box element.
  41. /// </summary>
  42. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  43. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  44. /// default element style is used.</param>
  45. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  46. /// override any similar options set by style.</param>
  47. public GUITextBox(string style, params GUIOption[] options)
  48. {
  49. Internal_CreateInstance(this, false, style, options);
  50. }
  51. /// <summary>
  52. /// Creates a new single-line text box element.
  53. /// </summary>
  54. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  55. /// override any similar options set by style.</param>
  56. public GUITextBox(params GUIOption[] options)
  57. {
  58. Internal_CreateInstance(this, false, "", options);
  59. }
  60. /// <summary>
  61. /// Text currently entered in the text box.
  62. /// </summary>
  63. public string Text
  64. {
  65. get { string value; Internal_GetText(mCachedPtr, out value); return value; }
  66. set { Internal_SetText(mCachedPtr, value); }
  67. }
  68. /// <summary>
  69. /// Colors the element with a specific tint.
  70. /// </summary>
  71. /// <param name="color">Tint to apply to the element.</param>
  72. public void SetTint(Color color)
  73. {
  74. Internal_SetTint(mCachedPtr, color);
  75. }
  76. /// <summary>
  77. /// Triggered by the native interop object when the text box value is changed.
  78. /// </summary>
  79. /// <param name="newValue">New value in the text box.</param>
  80. private void DoOnChanged(string newValue)
  81. {
  82. if (OnChanged != null)
  83. OnChanged(newValue);
  84. }
  85. [MethodImpl(MethodImplOptions.InternalCall)]
  86. private static extern void Internal_CreateInstance(GUITextBox instance, bool multiline, string style, GUIOption[] options);
  87. [MethodImpl(MethodImplOptions.InternalCall)]
  88. private static extern void Internal_SetText(IntPtr nativeInstance, string text);
  89. [MethodImpl(MethodImplOptions.InternalCall)]
  90. private static extern void Internal_GetText(IntPtr nativeInstance, out string text);
  91. [MethodImpl(MethodImplOptions.InternalCall)]
  92. private static extern void Internal_SetTint(IntPtr nativeInstance, Color color);
  93. }
  94. }