GUITextureField.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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(ResourceRef 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 ResourceRef ValueRef
  41. {
  42. get
  43. {
  44. ResourceRef 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, 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. Internal_CreateInstance(this, new GUIContent(), 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 resource referenced by the field.</param>
  88. private void Internal_DoOnChanged(ResourceRef newValue)
  89. {
  90. if (OnChanged != null)
  91. OnChanged(newValue);
  92. }
  93. [MethodImpl(MethodImplOptions.InternalCall)]
  94. private static extern void Internal_CreateInstance(GUITextureField instance, GUIContent title, int titleWidth,
  95. string style, GUIOption[] options, bool withTitle);
  96. [MethodImpl(MethodImplOptions.InternalCall)]
  97. private static extern void Internal_GetValue(IntPtr nativeInstance, out Texture value);
  98. [MethodImpl(MethodImplOptions.InternalCall)]
  99. private static extern void Internal_SetValue(IntPtr nativeInstance, Texture value);
  100. [MethodImpl(MethodImplOptions.InternalCall)]
  101. private static extern void Internal_GetValueRef(IntPtr nativeInstance, out ResourceRef value);
  102. [MethodImpl(MethodImplOptions.InternalCall)]
  103. private static extern void Internal_SetValueRef(IntPtr nativeInstance, ResourceRef value);
  104. [MethodImpl(MethodImplOptions.InternalCall)]
  105. private static extern void Internal_SetTint(IntPtr nativeInstance, ref Color color);
  106. }
  107. /** @} */
  108. }