TechbloxModdingAPI/GamecraftModdingAPI/Interface/IMGUI/Image.cs
2020-12-27 18:57:23 -05:00

86 lines
2.7 KiB
C#

using UnityEngine;
namespace GamecraftModdingAPI.Interface.IMGUI
{
/// <summary>
/// An image.
/// This wraps Unity's IMGUI Label.
/// </summary>
public class Image : UIElement
{
private bool automaticLayout = false;
/// <summary>
/// The image texture to display
/// </summary>
public Texture Texture { get; set; }
/// <summary>
/// The rectangular area in the window that the image can use
/// </summary>
public Rect Box { get; set; } = Rect.zero;
public void OnGUI()
{
//if (Texture == null) return;
if (automaticLayout)
{
GUILayout.Label(Texture, Constants.Default.label);
}
else
{
GUI.Label(Box, Texture, Constants.Default.label);
}
}
/// <summary>
/// The image element's unique name.
/// </summary>
public string Name { get; }
/// <summary>
/// Whether to display the image and everything in it.
/// </summary>
public bool Enabled { set; get; } = true;
/// <summary>
/// Initializes a new instance of the <see cref="T:GamecraftModdingAPI.Interface.IMGUI.Image"/> class with automatic layout.
/// </summary>
/// <param name="texture">Image to display.</param>
/// <param name="name">The element's name.</param>
public Image(Texture texture = null, string name = null)
{
automaticLayout = true;
Texture = texture;
if (name == null)
{
if (texture == null)
{
this.Name = typeof(Image).FullName + "::" + texture;
}
else
{
this.Name = typeof(Image).FullName + "::" + texture.name + "(" + texture.width + "x" + texture.height + ")";
}
}
else
{
this.Name = name;
}
IMGUIManager.AddElement(this);
}
/// <summary>
/// Initializes a new instance of the <see cref="T:GamecraftModdingAPI.Interface.IMGUI.Image"/> class.
/// </summary>
/// <param name="box">Rectangular area for the image.</param>
/// <param name="texture">Image to display.</param>
/// <param name="name">The element's name.</param>
public Image(Rect box, Texture texture = null, string name = null) : this(texture, name)
{
this.Box = box;
automaticLayout = false;
}
}
}