GUIVector2Field.cs 5.2 KB

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