GUITextureField.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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(Texture 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.
  20. /// </summary>
  21. public Texture Value
  22. {
  23. get
  24. {
  25. Texture value;
  26. Internal_GetValue(mCachedPtr, out value);
  27. return value;
  28. }
  29. set { Internal_SetValue(mCachedPtr, value); }
  30. }
  31. /// <summary>
  32. /// Creates a new texture field element with a label.
  33. /// </summary>
  34. /// <param name="title">Content to display on the label.</param>
  35. /// <param name="titleWidth">Width of the title label in pixels.</param>
  36. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  37. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  38. /// default element style is used.</param>
  39. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  40. /// override any similar options set by style.</param>
  41. public GUITextureField(GUIContent title, int titleWidth = 100, string style = "", params GUIOption[] options)
  42. {
  43. Internal_CreateInstance(this, title, titleWidth, style, options, true);
  44. }
  45. /// <summary>
  46. /// Creates a new texture field element without a label.
  47. /// </summary>
  48. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  49. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  50. /// default element style is used.</param>
  51. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  52. /// override any similar options set by style.</param>
  53. public GUITextureField(string style = "", params GUIOption[] options)
  54. {
  55. Internal_CreateInstance(this, null, 0, style, options, false);
  56. }
  57. /// <summary>
  58. /// Colors the element with a specific tint.
  59. /// </summary>
  60. /// <param name="color">Tint to apply to the element.</param>
  61. public void SetTint(Color color)
  62. {
  63. Internal_SetTint(mCachedPtr, color);
  64. }
  65. /// <summary>
  66. /// Triggered by the runtime when the value of the field changes.
  67. /// </summary>
  68. /// <param name="newValue">New resource referenced by the field.</param>
  69. private void Internal_DoOnChanged(Texture newValue)
  70. {
  71. if (OnChanged != null)
  72. OnChanged(newValue);
  73. }
  74. [MethodImpl(MethodImplOptions.InternalCall)]
  75. private static extern void Internal_CreateInstance(GUITextureField instance, GUIContent title, int titleWidth,
  76. string style, GUIOption[] options, bool withTitle);
  77. [MethodImpl(MethodImplOptions.InternalCall)]
  78. private static extern void Internal_GetValue(IntPtr nativeInstance, out Texture value);
  79. [MethodImpl(MethodImplOptions.InternalCall)]
  80. private static extern void Internal_SetValue(IntPtr nativeInstance, Texture value);
  81. [MethodImpl(MethodImplOptions.InternalCall)]
  82. private static extern void Internal_SetTint(IntPtr nativeInstance, Color color);
  83. }
  84. }