GUITextureField.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. using BansheeEngine;
  4. namespace BansheeEditor
  5. {
  6. /// <summary>
  7. /// Editor GUI element that displays a reference to a <see cref="Texture"/> and an optional label. Textures can
  8. /// be dragged and dropped onto the field to update the reference. This is similar to <see cref="GUIResourceField"/>
  9. /// but the will display the texture contents and not only the name.
  10. /// </summary>
  11. public sealed class GUITextureField : GUIElement
  12. {
  13. public delegate void OnChangedDelegate(ResourceRef newValue);
  14. /// <summary>
  15. /// Triggered when the value in the field changes.
  16. /// </summary>
  17. public event OnChangedDelegate OnChanged;
  18. /// <summary>
  19. /// <see cref="Texture"/> referenced by the field. This will load the texture if it is not already loaded. Use
  20. /// <see cref="ValueRef"/> if you don't require a loaded resource.
  21. /// </summary>
  22. public Texture Value
  23. {
  24. get
  25. {
  26. Texture value;
  27. Internal_GetValue(mCachedPtr, out value);
  28. return value;
  29. }
  30. set { Internal_SetValue(mCachedPtr, value); }
  31. }
  32. /// <summary>
  33. /// Reference to the <see cref="Texture"/> referenced by the field.
  34. /// </summary>
  35. public ResourceRef ValueRef
  36. {
  37. get
  38. {
  39. ResourceRef value;
  40. Internal_GetValueRef(mCachedPtr, out value);
  41. return value;
  42. }
  43. set { Internal_SetValueRef(mCachedPtr, value); }
  44. }
  45. /// <summary>
  46. /// Creates a new texture field element with a label.
  47. /// </summary>
  48. /// <param name="title">Content to display on the label.</param>
  49. /// <param name="titleWidth">Width of the title label in pixels.</param>
  50. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  51. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  52. /// default element style is used.</param>
  53. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  54. /// override any similar options set by style.</param>
  55. public GUITextureField(GUIContent title, int titleWidth = 100, string style = "", params GUIOption[] options)
  56. {
  57. Internal_CreateInstance(this, title, titleWidth, style, options, true);
  58. }
  59. /// <summary>
  60. /// Creates a new texture field element without a label.
  61. /// </summary>
  62. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  63. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  64. /// default element style is used.</param>
  65. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  66. /// override any similar options set by style.</param>
  67. public GUITextureField(string style = "", params GUIOption[] options)
  68. {
  69. Internal_CreateInstance(this, null, 0, style, options, false);
  70. }
  71. /// <summary>
  72. /// Colors the element with a specific tint.
  73. /// </summary>
  74. /// <param name="color">Tint to apply to the element.</param>
  75. public void SetTint(Color color)
  76. {
  77. Internal_SetTint(mCachedPtr, ref color);
  78. }
  79. /// <summary>
  80. /// Triggered by the runtime when the value of the field changes.
  81. /// </summary>
  82. /// <param name="newValue">New resource referenced by the field.</param>
  83. private void Internal_DoOnChanged(ResourceRef newValue)
  84. {
  85. if (OnChanged != null)
  86. OnChanged(newValue);
  87. }
  88. [MethodImpl(MethodImplOptions.InternalCall)]
  89. private static extern void Internal_CreateInstance(GUITextureField instance, GUIContent title, int titleWidth,
  90. string style, GUIOption[] options, bool withTitle);
  91. [MethodImpl(MethodImplOptions.InternalCall)]
  92. private static extern void Internal_GetValue(IntPtr nativeInstance, out Texture value);
  93. [MethodImpl(MethodImplOptions.InternalCall)]
  94. private static extern void Internal_SetValue(IntPtr nativeInstance, Texture value);
  95. [MethodImpl(MethodImplOptions.InternalCall)]
  96. private static extern void Internal_GetValueRef(IntPtr nativeInstance, out ResourceRef value);
  97. [MethodImpl(MethodImplOptions.InternalCall)]
  98. private static extern void Internal_SetValueRef(IntPtr nativeInstance, ResourceRef value);
  99. [MethodImpl(MethodImplOptions.InternalCall)]
  100. private static extern void Internal_SetTint(IntPtr nativeInstance, ref Color color);
  101. }
  102. }