GUIRenderTexture.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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="transparent">Determines should the texture be rendered with transparency active.</param>
  35. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  36. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  37. /// default element style is used.</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.</param>
  40. public GUIRenderTexture(RenderTexture2D texture, bool transparent, string style, params GUIOption[] options)
  41. {
  42. IntPtr texturePtr = IntPtr.Zero;
  43. if (texture != null)
  44. texturePtr = texture.GetCachedPtr();
  45. Internal_CreateInstance(this, texturePtr, transparent, style, options);
  46. }
  47. /// <summary>
  48. /// Creates a new render texture element.
  49. /// </summary>
  50. /// <param name="texture">Render texture to display in the element.</param>
  51. /// <param name="transparent">Determines should the texture be rendered with transparency active.</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.</param>
  54. public GUIRenderTexture(RenderTexture2D texture, bool transparent, params GUIOption[] options)
  55. {
  56. IntPtr texturePtr = IntPtr.Zero;
  57. if (texture != null)
  58. texturePtr = texture.GetCachedPtr();
  59. Internal_CreateInstance(this, texturePtr, transparent, "", options);
  60. }
  61. /// <summary>
  62. /// Creates a new render texture element.
  63. /// </summary>
  64. /// <param name="texture">Render texture to display in the element.</param>
  65. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  66. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  67. /// default element style is used.</param>
  68. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  69. /// override any similar options set by style.</param>
  70. public GUIRenderTexture(RenderTexture2D texture, string style, params GUIOption[] options)
  71. {
  72. IntPtr texturePtr = IntPtr.Zero;
  73. if (texture != null)
  74. texturePtr = texture.GetCachedPtr();
  75. Internal_CreateInstance(this, texturePtr, false, style, options);
  76. }
  77. /// <summary>
  78. /// Creates a new render texture element.
  79. /// </summary>
  80. /// <param name="texture">Render texture to display in the element.</param>
  81. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  82. /// override any similar options set by style.</param>
  83. public GUIRenderTexture(RenderTexture2D texture, params GUIOption[] options)
  84. {
  85. IntPtr texturePtr = IntPtr.Zero;
  86. if (texture != null)
  87. texturePtr = texture.GetCachedPtr();
  88. Internal_CreateInstance(this, texturePtr, false, "", options);
  89. }
  90. /// <summary>
  91. /// Colors the element with a specific tint.
  92. /// </summary>
  93. /// <param name="color">Tint to apply to the element.</param>
  94. public void SetTint(Color color)
  95. {
  96. Internal_SetTint(mCachedPtr, ref color);
  97. }
  98. [MethodImpl(MethodImplOptions.InternalCall)]
  99. private static extern void Internal_CreateInstance(GUIRenderTexture instance, IntPtr texture, bool transparency,
  100. string style, GUIOption[] options);
  101. [MethodImpl(MethodImplOptions.InternalCall)]
  102. private static extern void Internal_SetTexture(IntPtr nativeInstance, IntPtr texture);
  103. [MethodImpl(MethodImplOptions.InternalCall)]
  104. private static extern void Internal_SetTint(IntPtr nativeInstance, ref Color color);
  105. }
  106. }