A stable modding interface between Techblox and mods https://mod.exmods.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.7KB

  1. using UnityEngine;
  2. namespace GamecraftModdingAPI.Interface.IMGUI
  3. {
  4. /// <summary>
  5. /// An image.
  6. /// This wraps Unity's IMGUI Label.
  7. /// </summary>
  8. public class Image : UIElement
  9. {
  10. private bool automaticLayout = false;
  11. /// <summary>
  12. /// The image texture to display
  13. /// </summary>
  14. public Texture Texture { get; set; }
  15. /// <summary>
  16. /// The rectangular area in the window that the image can use
  17. /// </summary>
  18. public Rect Box { get; set; } = Rect.zero;
  19. public void OnGUI()
  20. {
  21. //if (Texture == null) return;
  22. if (automaticLayout)
  23. {
  24. GUILayout.Label(Texture, Constants.Default.label);
  25. }
  26. else
  27. {
  28. GUI.Label(Box, Texture, Constants.Default.label);
  29. }
  30. }
  31. /// <summary>
  32. /// The image element's unique name.
  33. /// </summary>
  34. public string Name { get; }
  35. /// <summary>
  36. /// Whether to display the image and everything in it.
  37. /// </summary>
  38. public bool Enabled { set; get; } = true;
  39. /// <summary>
  40. /// Initializes a new instance of the <see cref="T:GamecraftModdingAPI.Interface.IMGUI.Image"/> class with automatic layout.
  41. /// </summary>
  42. /// <param name="texture">Image to display.</param>
  43. /// <param name="name">The element's name.</param>
  44. public Image(Texture texture = null, string name = null)
  45. {
  46. automaticLayout = true;
  47. Texture = texture;
  48. if (name == null)
  49. {
  50. if (texture == null)
  51. {
  52. this.Name = typeof(Image).FullName + "::" + texture;
  53. }
  54. else
  55. {
  56. this.Name = typeof(Image).FullName + "::" + texture.name + "(" + texture.width + "x" + texture.height + ")";
  57. }
  58. }
  59. else
  60. {
  61. this.Name = name;
  62. }
  63. IMGUIManager.AddElement(this);
  64. }
  65. /// <summary>
  66. /// Initializes a new instance of the <see cref="T:GamecraftModdingAPI.Interface.IMGUI.Image"/> class.
  67. /// </summary>
  68. /// <param name="box">Rectangular area for the image.</param>
  69. /// <param name="texture">Image to display.</param>
  70. /// <param name="name">The element's name.</param>
  71. public Image(Rect box, Texture texture = null, string name = null) : this(texture, name)
  72. {
  73. this.Box = box;
  74. automaticLayout = false;
  75. }
  76. }
  77. }