GUITexture.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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
  36. /// be used.</param>
  37. /// <param name="scale">Scale mode to use when sizing the texture.</param>
  38. /// <param name="transparent">Determines should the texture be rendered with transparency active.</param>
  39. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  40. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  41. /// default element style is used.</param>
  42. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  43. /// override any similar options set by style.</param>
  44. public GUITexture(SpriteTexture texture, GUIImageScaleMode scale, bool transparent, string style, params GUIOption[] options)
  45. {
  46. Internal_CreateInstance(this, texture, scale, transparent, style, options);
  47. }
  48. /// <summary>
  49. /// Creates a new texture element.
  50. /// </summary>
  51. /// <param name="texture">Texture to display. If this is null then the texture specified by the style will
  52. /// be used.</param>
  53. /// <param name="scale">Scale mode to use when sizing the texture.</param>
  54. /// <param name="transparent">Determines should the texture be rendered with transparency active.</param>
  55. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  56. /// override any similar options set by style.</param>
  57. public GUITexture(SpriteTexture texture, GUIImageScaleMode scale, bool transparent, params GUIOption[] options)
  58. {
  59. Internal_CreateInstance(this, texture, scale, transparent, "", options);
  60. }
  61. /// <summary>
  62. /// Creates a new texture element. Texture will use the default StretchToFit scaling.
  63. /// </summary>
  64. /// <param name="texture">Texture to display. If this is null then the texture specified by the style will
  65. /// be used.</param>
  66. /// <param name="transparent">Determines should the texture be rendered with transparency active.</param>
  67. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  68. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  69. /// default element style is used.</param>
  70. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  71. /// override any similar options set by style.</param>
  72. public GUITexture(SpriteTexture texture, bool transparent, string style, params GUIOption[] options)
  73. {
  74. Internal_CreateInstance(this, texture, GUIImageScaleMode.StretchToFit, transparent, style, options);
  75. }
  76. /// <summary>
  77. /// Creates a new texture element. Texture will use the default StretchToFit scaling.
  78. /// </summary>
  79. /// <param name="texture">Texture to display. If this is null then the texture specified by the style will
  80. /// be used.</param>
  81. /// <param name="transparent">Determines should the texture be rendered with transparency active.</param>
  82. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  83. /// override any similar options set by style.</param>
  84. public GUITexture(SpriteTexture texture, bool transparent, params GUIOption[] options)
  85. {
  86. Internal_CreateInstance(this, texture, GUIImageScaleMode.StretchToFit, transparent, "", options);
  87. }
  88. /// <summary>
  89. /// Creates a new texture element with transparency active.
  90. /// </summary>
  91. /// <param name="texture">Texture to display. If this is null then the texture specified by the style will
  92. /// be used.</param>
  93. /// <param name="scale">Scale mode to use when sizing the texture.</param>
  94. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  95. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  96. /// default element style is used.</param>
  97. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  98. /// override any similar options set by style.</param>
  99. public GUITexture(SpriteTexture texture, GUIImageScaleMode scale, string style, params GUIOption[] options)
  100. {
  101. Internal_CreateInstance(this, texture, scale, true, style, options);
  102. }
  103. /// <summary>
  104. /// Creates a new texture element with transparency active.
  105. /// </summary>
  106. /// <param name="texture">Texture to display. If this is null then the texture specified by the style will
  107. /// be used.</param>
  108. /// <param name="scale">Scale mode to use when sizing the texture.</param>
  109. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  110. /// override any similar options set by style.</param>
  111. public GUITexture(SpriteTexture texture, GUIImageScaleMode scale, params GUIOption[] options)
  112. {
  113. Internal_CreateInstance(this, texture, scale, true, "", options);
  114. }
  115. /// <summary>
  116. /// Creates a new texture element with transparency active. Texture will use the default StretchToFit scaling.
  117. /// </summary>
  118. /// <param name="texture">Texture to display. If this is null then the texture specified by the style will
  119. /// be used.</param>
  120. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  121. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  122. /// default element style is used.</param>
  123. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  124. /// override any similar options set by style.</param>
  125. public GUITexture(SpriteTexture texture, string style, params GUIOption[] options)
  126. {
  127. Internal_CreateInstance(this, texture, GUIImageScaleMode.StretchToFit, true, style, options);
  128. }
  129. /// <summary>
  130. /// Creates a new texture element with transparency active. Texture will use the default StretchToFit scaling.
  131. /// </summary>
  132. /// <param name="texture">Texture to display. If this is null then the texture specified by the style will
  133. /// be used.</param>
  134. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  135. /// override any similar options set by style.</param>
  136. public GUITexture(SpriteTexture texture, params GUIOption[] options)
  137. {
  138. Internal_CreateInstance(this, texture, GUIImageScaleMode.StretchToFit, true, "", options);
  139. }
  140. /// <summary>
  141. /// Sets the texture to display.
  142. /// </summary>
  143. /// <param name="texture">Texture to display. If this is null then the texture specified by the style will
  144. /// be used.</param>
  145. public void SetTexture(SpriteTexture texture)
  146. {
  147. Internal_SetTexture(mCachedPtr, texture);
  148. }
  149. /// <summary>
  150. /// Colors the element with a specific tint.
  151. /// </summary>
  152. /// <param name="color">Tint to apply to the element.</param>
  153. public void SetTint(Color color)
  154. {
  155. Internal_SetTint(mCachedPtr, color);
  156. }
  157. [MethodImpl(MethodImplOptions.InternalCall)]
  158. private static extern void Internal_CreateInstance(GUITexture instance, SpriteTexture texture,
  159. GUIImageScaleMode scale, bool transparent, string style, GUIOption[] options);
  160. [MethodImpl(MethodImplOptions.InternalCall)]
  161. private static extern void Internal_SetTexture(IntPtr nativeInstance, SpriteTexture texture);
  162. [MethodImpl(MethodImplOptions.InternalCall)]
  163. private static extern void Internal_SetTint(IntPtr nativeInstance, Color color);
  164. }
  165. }