2
0

GUITextureField.cs 5.2 KB

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