GUIRenderTexture.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. namespace BansheeEngine
  6. {
  7. /// <summary>
  8. /// Allows you to display a render texture in the GUI. Has the same functionality as GUITexture, but also forwards any
  9. /// input to underlying GUI elements being rendered on the provided render texture.
  10. /// </summary>
  11. public sealed class GUIRenderTexture : GUIElement
  12. {
  13. private RenderTexture2D renderTexture;
  14. /// <summary>
  15. /// Render texture that is displayed on the GUI element.
  16. /// </summary>
  17. public RenderTexture2D RenderTexture
  18. {
  19. get
  20. {
  21. return renderTexture;
  22. }
  23. set
  24. {
  25. IntPtr texturePtr = IntPtr.Zero;
  26. if (value != null)
  27. texturePtr = value.GetCachedPtr();
  28. renderTexture = value;
  29. Internal_SetTexture(mCachedPtr, texturePtr);
  30. }
  31. }
  32. /// <summary>
  33. /// Creates a new render texture element.
  34. /// </summary>
  35. /// <param name="texture">Render texture to display in the element.</param>
  36. /// <param name="transparent">Determines should the texture be rendered with transparency active.</param>
  37. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  38. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  39. /// default element style is used.</param>
  40. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  41. /// override any similar options set by style.</param>
  42. public GUIRenderTexture(RenderTexture2D texture, bool transparent, string style, params GUIOption[] options)
  43. {
  44. IntPtr texturePtr = IntPtr.Zero;
  45. if (texture != null)
  46. texturePtr = texture.GetCachedPtr();
  47. Internal_CreateInstance(this, texturePtr, transparent, style, options);
  48. }
  49. /// <summary>
  50. /// Creates a new render texture element.
  51. /// </summary>
  52. /// <param name="texture">Render texture to display in the element.</param>
  53. /// <param name="transparent">Determines should the texture be rendered with transparency active.</param>
  54. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  55. /// override any similar options set by style.</param>
  56. public GUIRenderTexture(RenderTexture2D texture, bool transparent, params GUIOption[] options)
  57. {
  58. IntPtr texturePtr = IntPtr.Zero;
  59. if (texture != null)
  60. texturePtr = texture.GetCachedPtr();
  61. Internal_CreateInstance(this, texturePtr, transparent, "", options);
  62. }
  63. /// <summary>
  64. /// Creates a new render texture element.
  65. /// </summary>
  66. /// <param name="texture">Render texture to display in the element.</param>
  67. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  68. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  69. /// default element style is used.</param>
  70. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  71. /// override any similar options set by style.</param>
  72. public GUIRenderTexture(RenderTexture2D texture, string style, params GUIOption[] options)
  73. {
  74. IntPtr texturePtr = IntPtr.Zero;
  75. if (texture != null)
  76. texturePtr = texture.GetCachedPtr();
  77. Internal_CreateInstance(this, texturePtr, false, style, options);
  78. }
  79. /// <summary>
  80. /// Creates a new render texture element.
  81. /// </summary>
  82. /// <param name="texture">Render texture to display in the element.</param>
  83. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  84. /// override any similar options set by style.</param>
  85. public GUIRenderTexture(RenderTexture2D texture, params GUIOption[] options)
  86. {
  87. IntPtr texturePtr = IntPtr.Zero;
  88. if (texture != null)
  89. texturePtr = texture.GetCachedPtr();
  90. Internal_CreateInstance(this, texturePtr, false, "", options);
  91. }
  92. /// <summary>
  93. /// Colors the element with a specific tint.
  94. /// </summary>
  95. /// <param name="color">Tint to apply to the element.</param>
  96. public void SetTint(Color color)
  97. {
  98. Internal_SetTint(mCachedPtr, ref color);
  99. }
  100. [MethodImpl(MethodImplOptions.InternalCall)]
  101. private static extern void Internal_CreateInstance(GUIRenderTexture instance, IntPtr texture, bool transparency,
  102. string style, GUIOption[] options);
  103. [MethodImpl(MethodImplOptions.InternalCall)]
  104. private static extern void Internal_SetTexture(IntPtr nativeInstance, IntPtr texture);
  105. [MethodImpl(MethodImplOptions.InternalCall)]
  106. private static extern void Internal_SetTint(IntPtr nativeInstance, ref Color color);
  107. }
  108. }