GUIVector2Field.cs 5.1 KB

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