GUITexture.cs 10 KB

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