GUIVector4Field.cs 4.5 KB

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