GUITextureField.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 reference to a <see cref="Texture"/> and an optional label. Textures can
  13. /// be dragged and dropped onto the field to update the reference. This is similar to <see cref="GUIResourceField"/>
  14. /// but the will display the texture contents and not only the name.
  15. /// </summary>
  16. public sealed class GUITextureField : GUIElement
  17. {
  18. public delegate void OnChangedDelegate(RRef<Texture> newValue);
  19. /// <summary>
  20. /// Triggered when the value in the field changes.
  21. /// </summary>
  22. public event OnChangedDelegate OnChanged;
  23. /// <summary>
  24. /// <see cref="Texture"/> referenced by the field. This will load the texture if it is not already loaded. Use
  25. /// <see cref="ValueRef"/> if you don't require a loaded resource.
  26. /// </summary>
  27. public Texture Value
  28. {
  29. get
  30. {
  31. Texture value;
  32. Internal_GetValue(mCachedPtr, out value);
  33. return value;
  34. }
  35. set { Internal_SetValue(mCachedPtr, value); }
  36. }
  37. /// <summary>
  38. /// Reference to the <see cref="Texture"/> referenced by the field.
  39. /// </summary>
  40. public RRef<Texture> ValueRef
  41. {
  42. get
  43. {
  44. RRef<Texture> value;
  45. Internal_GetValueRef(mCachedPtr, out value);
  46. return value;
  47. }
  48. set { Internal_SetValueRef(mCachedPtr, value); }
  49. }
  50. /// <summary>
  51. /// Creates a new texture 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 GUITextureField(GUIContent title, int titleWidth = 100, string style = "", params GUIOption[] options)
  61. {
  62. Internal_CreateInstance(this, ref title, titleWidth, style, options, true);
  63. }
  64. /// <summary>
  65. /// Creates a new texture 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 GUITextureField(string style = "", params GUIOption[] options)
  73. {
  74. GUIContent emptyContent = new GUIContent();
  75. Internal_CreateInstance(this, ref emptyContent, 0, style, options, false);
  76. }
  77. /// <summary>
  78. /// Colors the element with a specific tint.
  79. /// </summary>
  80. /// <param name="color">Tint to apply to the element.</param>
  81. public void SetTint(Color color)
  82. {
  83. Internal_SetTint(mCachedPtr, ref color);
  84. }
  85. /// <summary>
  86. /// Triggered by the runtime when the value of the field changes.
  87. /// </summary>
  88. /// <param name="newValue">New resource referenced by the field.</param>
  89. private void Internal_DoOnChanged(RRef<Texture> newValue)
  90. {
  91. if (OnChanged != null)
  92. OnChanged(newValue);
  93. }
  94. [MethodImpl(MethodImplOptions.InternalCall)]
  95. private static extern void Internal_CreateInstance(GUITextureField instance, ref GUIContent title, int titleWidth,
  96. string style, GUIOption[] options, bool withTitle);
  97. [MethodImpl(MethodImplOptions.InternalCall)]
  98. private static extern void Internal_GetValue(IntPtr nativeInstance, out Texture value);
  99. [MethodImpl(MethodImplOptions.InternalCall)]
  100. private static extern void Internal_SetValue(IntPtr nativeInstance, Texture value);
  101. [MethodImpl(MethodImplOptions.InternalCall)]
  102. private static extern void Internal_GetValueRef(IntPtr nativeInstance, out RRef<Texture> value);
  103. [MethodImpl(MethodImplOptions.InternalCall)]
  104. private static extern void Internal_SetValueRef(IntPtr nativeInstance, RRef<Texture> value);
  105. [MethodImpl(MethodImplOptions.InternalCall)]
  106. private static extern void Internal_SetTint(IntPtr nativeInstance, ref Color color);
  107. }
  108. /** @} */
  109. }