GUIRenderTexture.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. namespace BansheeEngine
  4. {
  5. /// <summary>
  6. /// Allows you to display a render texture in the GUI. Has the same functionality as GUITexture, but also forwards any
  7. /// input to underlying GUI elements being rendered on the provided render texture.
  8. /// </summary>
  9. public sealed class GUIRenderTexture : GUIElement
  10. {
  11. private RenderTexture2D renderTexture;
  12. /// <summary>
  13. /// Render texture that is displayed on the GUI element.
  14. /// </summary>
  15. public RenderTexture2D RenderTexture
  16. {
  17. get
  18. {
  19. return renderTexture;
  20. }
  21. set
  22. {
  23. IntPtr texturePtr = IntPtr.Zero;
  24. if (value != null)
  25. texturePtr = value.GetCachedPtr();
  26. renderTexture = value;
  27. Internal_SetTexture(mCachedPtr, texturePtr);
  28. }
  29. }
  30. /// <summary>
  31. /// Creates a new render texture element.
  32. /// </summary>
  33. /// <param name="texture">Render texture to display in the element.</param>
  34. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  35. /// default layout options. Style will be retrieved from the active GUISkin. If not specified default element style
  36. /// is used.
  37. /// </param>
  38. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  39. /// override any similar options set by style.
  40. /// </param>
  41. public GUIRenderTexture(RenderTexture2D texture, string style, params GUIOption[] options)
  42. {
  43. IntPtr texturePtr = IntPtr.Zero;
  44. if (texture != null)
  45. texturePtr = texture.GetCachedPtr();
  46. Internal_CreateInstance(this, texturePtr, style, options);
  47. }
  48. /// <summary>
  49. /// Creates a new render texture element.
  50. /// </summary>
  51. /// <param name="texture">Render texture to display in the element.</param>
  52. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  53. /// override any similar options set by style.
  54. /// </param>
  55. public GUIRenderTexture(RenderTexture2D texture, params GUIOption[] options)
  56. {
  57. IntPtr texturePtr = IntPtr.Zero;
  58. if (texture != null)
  59. texturePtr = texture.GetCachedPtr();
  60. Internal_CreateInstance(this, texturePtr, "", options);
  61. }
  62. /// <summary>
  63. /// Colors the element with a specific tint.
  64. /// </summary>
  65. /// <param name="color">Tint to apply to the element.</param>
  66. public void SetTint(Color color)
  67. {
  68. Internal_SetTint(mCachedPtr, color);
  69. }
  70. [MethodImpl(MethodImplOptions.InternalCall)]
  71. private static extern void Internal_CreateInstance(GUIRenderTexture instance, IntPtr texture,
  72. string style, GUIOption[] options);
  73. [MethodImpl(MethodImplOptions.InternalCall)]
  74. private static extern void Internal_SetTexture(IntPtr nativeInstance, IntPtr texture);
  75. [MethodImpl(MethodImplOptions.InternalCall)]
  76. private static extern void Internal_SetTint(IntPtr nativeInstance, Color color);
  77. }
  78. }