GUITexture.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. /// Type of scaling modes for GUI images.
  12. /// </summary>
  13. public enum GUITextureScaleMode // Note: Must match C++ enum TextureScaleMode
  14. {
  15. /// <summary>
  16. /// Image will stretch non-uniformly in all dimensions in order to cover the assigned area fully.
  17. /// </summary>
  18. StretchToFit,
  19. /// <summary>
  20. /// Image will scale uniformly until one dimension is aligned with the assigned area. Remaining dimension might have empty space.
  21. /// </summary>
  22. ScaleToFit,
  23. /// <summary>
  24. /// Image will scale uniformly until both dimensions are larger or aligned with the assigned area. Remaining dimension might be cropped.
  25. /// </summary>
  26. CropToFit,
  27. /// <summary>
  28. /// Image will keep its original size, but will repeat in order to fill the assigned area.
  29. /// </summary>
  30. RepeatToFit
  31. };
  32. /// <summary>
  33. /// A GUI element that displays a texture.
  34. /// </summary>
  35. public sealed class GUITexture : GUIElement
  36. {
  37. /// <summary>
  38. /// Creates a new texture element.
  39. /// </summary>
  40. /// <param name="texture">Texture to display. If this is null then the texture specified by the style will
  41. /// be used.</param>
  42. /// <param name="scale">Scale mode to use when sizing the texture.</param>
  43. /// <param name="transparent">Determines should the texture be rendered with transparency active.</param>
  44. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  45. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  46. /// default element style is used.</param>
  47. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  48. /// override any similar options set by style.</param>
  49. public GUITexture(SpriteTexture texture, GUITextureScaleMode scale, bool transparent, string style, params GUIOption[] options)
  50. {
  51. Internal_CreateInstance(this, texture, scale, transparent, style, options);
  52. }
  53. /// <summary>
  54. /// Creates a new texture element.
  55. /// </summary>
  56. /// <param name="texture">Texture to display. If this is null then the texture specified by the style will
  57. /// be used.</param>
  58. /// <param name="scale">Scale mode to use when sizing the texture.</param>
  59. /// <param name="transparent">Determines should the texture be rendered with transparency active.</param>
  60. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  61. /// override any similar options set by style.</param>
  62. public GUITexture(SpriteTexture texture, GUITextureScaleMode scale, bool transparent, params GUIOption[] options)
  63. {
  64. Internal_CreateInstance(this, texture, scale, transparent, "", options);
  65. }
  66. /// <summary>
  67. /// Creates a new texture element. Texture will use the default StretchToFit scaling.
  68. /// </summary>
  69. /// <param name="texture">Texture to display. If this is null then the texture specified by the style will
  70. /// be used.</param>
  71. /// <param name="transparent">Determines should the texture be rendered with transparency active.</param>
  72. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  73. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  74. /// default element style is used.</param>
  75. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  76. /// override any similar options set by style.</param>
  77. public GUITexture(SpriteTexture texture, bool transparent, string style, params GUIOption[] options)
  78. {
  79. Internal_CreateInstance(this, texture, GUITextureScaleMode.StretchToFit, transparent, style, options);
  80. }
  81. /// <summary>
  82. /// Creates a new texture element. Texture will use the default StretchToFit scaling.
  83. /// </summary>
  84. /// <param name="texture">Texture to display. If this is null then the texture specified by the style will
  85. /// be used.</param>
  86. /// <param name="transparent">Determines should the texture be rendered with transparency active.</param>
  87. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  88. /// override any similar options set by style.</param>
  89. public GUITexture(SpriteTexture texture, bool transparent, params GUIOption[] options)
  90. {
  91. Internal_CreateInstance(this, texture, GUITextureScaleMode.StretchToFit, transparent, "", options);
  92. }
  93. /// <summary>
  94. /// Creates a new texture element with transparency active.
  95. /// </summary>
  96. /// <param name="texture">Texture to display. If this is null then the texture specified by the style will
  97. /// be used.</param>
  98. /// <param name="scale">Scale mode to use when sizing the texture.</param>
  99. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  100. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  101. /// default element style is used.</param>
  102. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  103. /// override any similar options set by style.</param>
  104. public GUITexture(SpriteTexture texture, GUITextureScaleMode scale, string style, params GUIOption[] options)
  105. {
  106. Internal_CreateInstance(this, texture, scale, true, style, options);
  107. }
  108. /// <summary>
  109. /// Creates a new texture element with transparency active.
  110. /// </summary>
  111. /// <param name="texture">Texture to display. If this is null then the texture specified by the style will
  112. /// be used.</param>
  113. /// <param name="scale">Scale mode to use when sizing the texture.</param>
  114. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  115. /// override any similar options set by style.</param>
  116. public GUITexture(SpriteTexture texture, GUITextureScaleMode scale, params GUIOption[] options)
  117. {
  118. Internal_CreateInstance(this, texture, scale, true, "", options);
  119. }
  120. /// <summary>
  121. /// Creates a new texture element with transparency active. Texture will use the default StretchToFit scaling.
  122. /// </summary>
  123. /// <param name="texture">Texture to display. If this is null then the texture specified by the style will
  124. /// be used.</param>
  125. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  126. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  127. /// default element style is used.</param>
  128. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  129. /// override any similar options set by style.</param>
  130. public GUITexture(SpriteTexture texture, string style, params GUIOption[] options)
  131. {
  132. Internal_CreateInstance(this, texture, GUITextureScaleMode.StretchToFit, true, style, options);
  133. }
  134. /// <summary>
  135. /// Creates a new texture element with transparency active. Texture will use the default StretchToFit scaling.
  136. /// </summary>
  137. /// <param name="texture">Texture to display. If this is null then the texture specified by the style will
  138. /// be used.</param>
  139. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  140. /// override any similar options set by style.</param>
  141. public GUITexture(SpriteTexture texture, params GUIOption[] options)
  142. {
  143. Internal_CreateInstance(this, texture, GUITextureScaleMode.StretchToFit, true, "", options);
  144. }
  145. /// <summary>
  146. /// Sets the texture to display.
  147. /// </summary>
  148. /// <param name="texture">Texture to display. If this is null then the texture specified by the style will
  149. /// be used.</param>
  150. public void SetTexture(SpriteTexture texture)
  151. {
  152. Internal_SetTexture(mCachedPtr, texture);
  153. }
  154. /// <summary>
  155. /// Colors the element with a specific tint.
  156. /// </summary>
  157. /// <param name="color">Tint to apply to the element.</param>
  158. public void SetTint(Color color)
  159. {
  160. Internal_SetTint(mCachedPtr, ref color);
  161. }
  162. [MethodImpl(MethodImplOptions.InternalCall)]
  163. private static extern void Internal_CreateInstance(GUITexture instance, SpriteTexture texture,
  164. GUITextureScaleMode scale, bool transparent, string style, GUIOption[] options);
  165. [MethodImpl(MethodImplOptions.InternalCall)]
  166. private static extern void Internal_SetTexture(IntPtr nativeInstance, SpriteTexture texture);
  167. [MethodImpl(MethodImplOptions.InternalCall)]
  168. private static extern void Internal_SetTint(IntPtr nativeInstance, ref Color color);
  169. }
  170. /** @} */
  171. }