GUIContent.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using System.Runtime.CompilerServices;
  4. namespace BansheeEngine
  5. {
  6. /** @addtogroup GUI_Engine
  7. * @{
  8. */
  9. public partial struct GUIContent
  10. {
  11. /// <summary>
  12. /// Returns image content (if any).
  13. /// </summary>
  14. public SpriteTexture GetImage(GUIElementState state = GUIElementState.Normal)
  15. {
  16. switch (state)
  17. {
  18. case GUIElementState.Normal:
  19. return images.normal;
  20. case GUIElementState.Hover:
  21. return images.hover;
  22. case GUIElementState.Active:
  23. return images.active;
  24. case GUIElementState.Focused:
  25. return images.focused;
  26. case GUIElementState.NormalOn:
  27. return images.normalOn;
  28. case GUIElementState.HoverOn:
  29. return images.hoverOn;
  30. case GUIElementState.ActiveOn:
  31. return images.activeOn;
  32. case GUIElementState.FocusedOn:
  33. return images.focusedOn;
  34. default:
  35. return images.normal;
  36. }
  37. }
  38. /// <summary>
  39. /// Implicitly converts a localized string into a GUI content containing only text.
  40. /// </summary>
  41. /// <param name="text">Localized string to initialize the GUI content with.</param>
  42. /// <returns>GUI content containing only a string.</returns>
  43. public static implicit operator GUIContent(LocString text)
  44. {
  45. return new GUIContent(text);
  46. }
  47. /// <summary>
  48. /// Implicitly converts a string into a GUI content containing only text.
  49. /// </summary>
  50. /// <param name="text">String to initialize the GUI content with.</param>
  51. /// <returns>GUI content containing only a string.</returns>
  52. public static implicit operator GUIContent(string text)
  53. {
  54. return new GUIContent(new LocString(text));
  55. }
  56. }
  57. public partial struct GUIContentImages
  58. {
  59. /// <summary>
  60. /// Creates a new object where content images for on and off states are different.
  61. /// </summary>
  62. /// <param name="imageOff">Image to assign to all off states.</param>
  63. /// <param name="imageOn">Image to assign to all on states.</param>
  64. public GUIContentImages(SpriteTexture imageOff, SpriteTexture imageOn)
  65. {
  66. normal = imageOff;
  67. hover = imageOff;
  68. active = imageOff;
  69. focused = imageOff;
  70. normalOn = imageOn;
  71. hoverOn = imageOn;
  72. activeOn = imageOn;
  73. focusedOn = imageOn;
  74. }
  75. /// <summary>
  76. /// Implicitly converts a sprite texture into a GUI content images object.
  77. /// </summary>
  78. /// <param name="image">Image to instantiate the GUI content images with.</param>
  79. /// <returns>GUI content images with all states set to the provided image.</returns>
  80. public static implicit operator GUIContentImages(SpriteTexture image)
  81. {
  82. return new GUIContentImages(image);
  83. }
  84. }
  85. /** @} */
  86. }