GUITexture.cs 9.8 KB

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