GUIRenderTexture.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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
  36. /// default element style is used.</param>
  37. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  38. /// override any similar options set by style.</param>
  39. public GUIRenderTexture(RenderTexture2D texture, string style, params GUIOption[] options)
  40. {
  41. IntPtr texturePtr = IntPtr.Zero;
  42. if (texture != null)
  43. texturePtr = texture.GetCachedPtr();
  44. Internal_CreateInstance(this, texturePtr, style, options);
  45. }
  46. /// <summary>
  47. /// Creates a new render texture element.
  48. /// </summary>
  49. /// <param name="texture">Render texture to display in the element.</param>
  50. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  51. /// override any similar options set by style.</param>
  52. public GUIRenderTexture(RenderTexture2D texture, params GUIOption[] options)
  53. {
  54. IntPtr texturePtr = IntPtr.Zero;
  55. if (texture != null)
  56. texturePtr = texture.GetCachedPtr();
  57. Internal_CreateInstance(this, texturePtr, "", options);
  58. }
  59. /// <summary>
  60. /// Colors the element with a specific tint.
  61. /// </summary>
  62. /// <param name="color">Tint to apply to the element.</param>
  63. public void SetTint(Color color)
  64. {
  65. Internal_SetTint(mCachedPtr, color);
  66. }
  67. [MethodImpl(MethodImplOptions.InternalCall)]
  68. private static extern void Internal_CreateInstance(GUIRenderTexture instance, IntPtr texture,
  69. string style, GUIOption[] options);
  70. [MethodImpl(MethodImplOptions.InternalCall)]
  71. private static extern void Internal_SetTexture(IntPtr nativeInstance, IntPtr texture);
  72. [MethodImpl(MethodImplOptions.InternalCall)]
  73. private static extern void Internal_SetTint(IntPtr nativeInstance, Color color);
  74. }
  75. }