GUIVector4Field.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. using BansheeEngine;
  4. namespace BansheeEditor
  5. {
  6. /// <summary>
  7. /// Editor GUI element that displays a 4D vector input field and an optional label.
  8. /// </summary>
  9. public sealed class GUIVector4Field : GUIElement
  10. {
  11. /// <summary>
  12. /// Triggered when the value in the field changes.
  13. /// </summary>
  14. public event Action<Vector4> OnChanged;
  15. /// <summary>
  16. /// Triggered whenever user confirms input.
  17. /// </summary>
  18. public event Action OnConfirmed;
  19. /// <summary>
  20. /// Value displayed by the field input box.
  21. /// </summary>
  22. public Vector4 Value
  23. {
  24. get
  25. {
  26. Vector4 value;
  27. Internal_GetValue(mCachedPtr, out value);
  28. return value;
  29. }
  30. set { Internal_SetValue(mCachedPtr, value); }
  31. }
  32. /// <summary>
  33. /// Checks does the element currently has input focus. Input focus means the element has an input caret displayed
  34. /// and will accept input from the keyboard.
  35. /// </summary>
  36. public bool HasInputFocus
  37. {
  38. get
  39. {
  40. bool value;
  41. Internal_HasInputFocus(mCachedPtr, out value);
  42. return value;
  43. }
  44. }
  45. /// <summary>
  46. /// Creates a new 4D vector field element with a label.
  47. /// </summary>
  48. /// <param name="title">Content to display on the label.</param>
  49. /// <param name="titleWidth">Width of the title label in pixels.</param>
  50. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  51. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  52. /// default element style is used.</param>
  53. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  54. /// override any similar options set by style.</param>
  55. public GUIVector4Field(GUIContent title, int titleWidth = 100, string style = "", params GUIOption[] options)
  56. {
  57. Internal_CreateInstance(this, title, titleWidth, style, options, true);
  58. }
  59. /// <summary>
  60. /// Creates a new 4D vector field element without a label.
  61. /// </summary>
  62. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  63. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  64. /// default element style is used.</param>
  65. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  66. /// override any similar options set by style.</param>
  67. public GUIVector4Field(string style = "", params GUIOption[] options)
  68. {
  69. Internal_CreateInstance(this, null, 0, style, options, false);
  70. }
  71. /// <summary>
  72. /// Colors the element with a specific tint.
  73. /// </summary>
  74. /// <param name="color">Tint to apply to the element.</param>
  75. public void SetTint(Color color)
  76. {
  77. Internal_SetTint(mCachedPtr, color);
  78. }
  79. /// <summary>
  80. /// Triggered by the runtime when the value of the field changes.
  81. /// </summary>
  82. /// <param name="newValue">New value of the field.</param>
  83. private void Internal_DoOnChanged(Vector4 newValue)
  84. {
  85. if (OnChanged != null)
  86. OnChanged(newValue);
  87. }
  88. /// <summary>
  89. /// Triggered by the native interop object when the user confirms the input.
  90. /// </summary>
  91. private void Internal_DoOnConfirmed()
  92. {
  93. if (OnConfirmed != null)
  94. OnConfirmed();
  95. }
  96. [MethodImpl(MethodImplOptions.InternalCall)]
  97. private static extern void Internal_CreateInstance(GUIVector4Field instance, GUIContent title, int titleWidth,
  98. string style, GUIOption[] options, bool withTitle);
  99. [MethodImpl(MethodImplOptions.InternalCall)]
  100. private static extern void Internal_GetValue(IntPtr nativeInstance, out Vector4 value);
  101. [MethodImpl(MethodImplOptions.InternalCall)]
  102. private static extern void Internal_SetValue(IntPtr nativeInstance, Vector4 value);
  103. [MethodImpl(MethodImplOptions.InternalCall)]
  104. private static extern void Internal_HasInputFocus(IntPtr nativeInstance, out bool value);
  105. [MethodImpl(MethodImplOptions.InternalCall)]
  106. private static extern void Internal_SetTint(IntPtr nativeInstance, Color color);
  107. }
  108. }