GUIContent.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. using System.Runtime.CompilerServices;
  2. namespace BansheeEngine
  3. {
  4. /// <summary>
  5. /// Holds data used for displaying content in a GUIElement. Content can consist of a string, image, a tooltip or none
  6. /// of those.
  7. /// </summary>
  8. public sealed class GUIContent
  9. {
  10. private LocString text;
  11. private LocString tooltip;
  12. private SpriteTexture image;
  13. /// <summary>
  14. /// Returns string content (if any).
  15. /// </summary>
  16. public LocString Text
  17. {
  18. get { return text; }
  19. }
  20. /// <summary>
  21. /// Returns image content (if any).
  22. /// </summary>
  23. public SpriteTexture Image
  24. {
  25. get { return image; }
  26. }
  27. /// <summary>
  28. /// Returns tooltip content (if any).
  29. /// </summary>
  30. public LocString Tooltip
  31. {
  32. get { return tooltip; }
  33. }
  34. /// <summary>
  35. /// Constructs content with just a string.
  36. /// </summary>
  37. /// <param name="text">Textual portion of the content to be displayed as label in GUI elements.</param>
  38. public GUIContent(LocString text)
  39. {
  40. this.text = text;
  41. }
  42. /// <summary>
  43. /// Constructs content with a string and a tooltip.
  44. /// </summary>
  45. /// <param name="text">Textual portion of the content to be displayed as label in GUI elements.</param>
  46. /// <param name="tooltip">Tooltip to be displayed when user hovers over a GUI element.</param>
  47. public GUIContent(LocString text, LocString tooltip)
  48. {
  49. this.text = text;
  50. this.tooltip = tooltip;
  51. }
  52. /// <summary>
  53. /// Constructs content with just an image.
  54. /// </summary>
  55. /// <param name="image">Image to be displayed on top of the GUI element.</param>
  56. public GUIContent(SpriteTexture image)
  57. {
  58. this.image = image;
  59. }
  60. /// <summary>
  61. /// Constructs content with an image and a tooltip.
  62. /// </summary>
  63. /// <param name="image">Image to be displayed on top of the GUI element.</param>
  64. /// <param name="tooltip">Tooltip to be displayed when user hovers over a GUI element.</param>
  65. public GUIContent(SpriteTexture image, LocString tooltip)
  66. {
  67. this.image = image;
  68. this.tooltip = tooltip;
  69. }
  70. /// <summary>
  71. /// Constructs content with a string and an image.
  72. /// </summary>
  73. /// <param name="text">Textual portion of the content to be displayed as label in GUI elements.
  74. /// </param>
  75. /// <param name="image">Image to be displayed on top of the GUI element. Image will be placed to the right or to the
  76. /// left of the text depending on active GUI style.
  77. /// </param>
  78. public GUIContent(LocString text, SpriteTexture image)
  79. {
  80. this.text = text;
  81. this.image = image;
  82. }
  83. /// <summary>
  84. /// Constructs content with a string, an image and a tooltip.
  85. /// </summary>
  86. /// <param name="text">Textual portion of the content to be displayed as label in GUI elements.
  87. /// </param>
  88. /// <param name="image">Image to be displayed on top of the GUI element. Image will be placed to the right or to the
  89. /// left of the text depending on active GUI style.
  90. /// </param>
  91. /// <param name="tooltip">Tooltip to be displayed when user hovers over a GUI element.
  92. /// </param>
  93. public GUIContent(LocString text, SpriteTexture image, LocString tooltip)
  94. {
  95. this.text = text;
  96. this.image = image;
  97. this.tooltip = tooltip;
  98. }
  99. /// <summary>
  100. /// Implicitly converts a localized string into a GUI content containing only text.
  101. /// </summary>
  102. /// <param name="text">Localized string to initialize the GUI content with.</param>
  103. /// <returns>GUI content containing only a string.</returns>
  104. public static implicit operator GUIContent(LocString text)
  105. {
  106. return new GUIContent(text);
  107. }
  108. /// <summary>
  109. /// Implicitly converts a string into a GUI content containing only text.
  110. /// </summary>
  111. /// <param name="text">String to initialize the GUI content with.</param>
  112. /// <returns>GUI content containing only a string.</returns>
  113. public static implicit operator GUIContent(string text)
  114. {
  115. return new GUIContent(new LocString(text));
  116. }
  117. }
  118. }