GUIRenderTexture.cs 5.7 KB

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