GUIIntField.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 integer input field and an optional label.
  13. /// </summary>
  14. public sealed class GUIIntField : GUIElement
  15. {
  16. /// <summary>
  17. /// Triggered when the value in the field changes.
  18. /// </summary>
  19. public event Action<int> 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 int Value
  28. {
  29. get
  30. {
  31. int value;
  32. Internal_GetValue(mCachedPtr, out value);
  33. return value;
  34. }
  35. set { Internal_SetValue(mCachedPtr, value); }
  36. }
  37. /// <summary>
  38. /// Minimum change of the field.
  39. /// </summary>
  40. public int Step
  41. {
  42. get { return Internal_GetStep(mCachedPtr); }
  43. set { Internal_SetStep(mCachedPtr, value); }
  44. }
  45. /// <summary>
  46. /// Checks does the element currently has input focus. Input focus means the element has an input caret displayed
  47. /// and will accept input from the keyboard.
  48. /// </summary>
  49. public bool HasInputFocus
  50. {
  51. get
  52. {
  53. bool value;
  54. Internal_HasInputFocus(mCachedPtr, out value);
  55. return value;
  56. }
  57. }
  58. /// <summary>
  59. /// Creates a new integer field element with a label.
  60. /// </summary>
  61. /// <param name="title">Content to display on the label.</param>
  62. /// <param name="titleWidth">Width of the title label in pixels.</param>
  63. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  64. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  65. /// default element style is used.</param>
  66. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  67. /// override any similar options set by style.</param>
  68. public GUIIntField(GUIContent title, int titleWidth = 100, string style = "", params GUIOption[] options)
  69. {
  70. Internal_CreateInstance(this, title, titleWidth, style, options, true);
  71. }
  72. /// <summary>
  73. /// Creates a new integer field element without a label.
  74. /// </summary>
  75. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  76. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  77. /// default element style is used.</param>
  78. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  79. /// override any similar options set by style.</param>
  80. public GUIIntField(string style = "", params GUIOption[] options)
  81. {
  82. Internal_CreateInstance(this, null, 0, style, options, false);
  83. }
  84. /// <summary>
  85. /// Sets a range that will input field values will be clamped to. Set to large negative/positive values if clamping
  86. /// is not required.
  87. /// </summary>
  88. /// <param name="min">Minimum boundary of the range to clamp values to.</param>
  89. /// <param name="max">Maximum boundary of the range to clamp values to.</param>
  90. public void SetRange(int min, int max)
  91. {
  92. Internal_SetRange(mCachedPtr, min, max);
  93. }
  94. /// <summary>
  95. /// Colors the element with a specific tint.
  96. /// </summary>
  97. /// <param name="color">Tint to apply to the element.</param>
  98. public void SetTint(Color color)
  99. {
  100. Internal_SetTint(mCachedPtr, ref color);
  101. }
  102. /// <summary>
  103. /// Triggered by the runtime when the value of the float field changes.
  104. /// </summary>
  105. /// <param name="newValue">New value of the float field.</param>
  106. private void Internal_DoOnChanged(int newValue)
  107. {
  108. if (OnChanged != null)
  109. OnChanged(newValue);
  110. }
  111. /// <summary>
  112. /// Triggered by the native interop object when the user confirms the input.
  113. /// </summary>
  114. private void Internal_DoOnConfirmed()
  115. {
  116. if (OnConfirmed != null)
  117. OnConfirmed();
  118. }
  119. [MethodImpl(MethodImplOptions.InternalCall)]
  120. private static extern void Internal_CreateInstance(GUIIntField instance, GUIContent title, int titleWidth,
  121. string style, GUIOption[] options, bool withTitle);
  122. [MethodImpl(MethodImplOptions.InternalCall)]
  123. private static extern void Internal_GetValue(IntPtr nativeInstance, out int value);
  124. [MethodImpl(MethodImplOptions.InternalCall)]
  125. private static extern int Internal_SetValue(IntPtr nativeInstance, int value);
  126. [MethodImpl(MethodImplOptions.InternalCall)]
  127. private static extern void Internal_HasInputFocus(IntPtr nativeInstance, out bool value);
  128. [MethodImpl(MethodImplOptions.InternalCall)]
  129. private static extern void Internal_SetRange(IntPtr nativeInstance, int min, int max);
  130. [MethodImpl(MethodImplOptions.InternalCall)]
  131. private static extern void Internal_SetTint(IntPtr nativeInstance, ref Color color);
  132. [MethodImpl(MethodImplOptions.InternalCall)]
  133. private static extern void Internal_SetStep(IntPtr nativeInstance, int step);
  134. [MethodImpl(MethodImplOptions.InternalCall)]
  135. private static extern int Internal_GetStep(IntPtr nativeInstance);
  136. }
  137. /** @} */
  138. }