2020-12-21 21:31:57 +00:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace GamecraftModdingAPI.Interface.IMGUI
|
|
|
|
{
|
2020-12-27 23:57:23 +00:00
|
|
|
/// <summary>
|
|
|
|
/// An image.
|
|
|
|
/// This wraps Unity's IMGUI Label.
|
|
|
|
/// </summary>
|
2020-12-21 21:31:57 +00:00
|
|
|
public class Image : UIElement
|
|
|
|
{
|
|
|
|
private bool automaticLayout = false;
|
|
|
|
|
2020-12-27 23:57:23 +00:00
|
|
|
/// <summary>
|
|
|
|
/// The image texture to display
|
|
|
|
/// </summary>
|
2020-12-21 21:31:57 +00:00
|
|
|
public Texture Texture { get; set; }
|
|
|
|
|
2020-12-27 23:57:23 +00:00
|
|
|
/// <summary>
|
|
|
|
/// The rectangular area in the window that the image can use
|
|
|
|
/// </summary>
|
2020-12-21 21:31:57 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-27 23:57:23 +00:00
|
|
|
/// <summary>
|
|
|
|
/// The image element's unique name.
|
|
|
|
/// </summary>
|
2020-12-21 21:31:57 +00:00
|
|
|
public string Name { get; }
|
2020-12-27 23:57:23 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Whether to display the image and everything in it.
|
|
|
|
/// </summary>
|
2020-12-21 21:31:57 +00:00
|
|
|
public bool Enabled { set; get; } = true;
|
|
|
|
|
2020-12-27 23:57:23 +00:00
|
|
|
/// <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>
|
2020-12-21 21:31:57 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2020-12-27 23:57:23 +00:00
|
|
|
/// <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>
|
2020-12-21 21:31:57 +00:00
|
|
|
public Image(Rect box, Texture texture = null, string name = null) : this(texture, name)
|
|
|
|
{
|
|
|
|
this.Box = box;
|
|
|
|
automaticLayout = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|