Stardew_Valley_Mods/GeneralMods/StardustCore/UIUtilities/Texture2DExtended.cs

60 lines
1.7 KiB
C#
Raw Normal View History

using System.IO;
2019-01-05 17:50:48 +08:00
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using StardewModdingAPI;
namespace StardustCore.UIUtilities
{
public class Texture2DExtended
{
2019-01-05 17:50:48 +08:00
/*********
** Accessors
*********/
/// <summary>The underlying texture.</summary>
public Texture2D Texture { get; }
2019-01-05 17:50:48 +08:00
/// <summary>The texture width.</summary>
public int Width => this.Texture.Width;
/// <summary>The texture height.</summary>
public int Height => this.Texture.Height;
/*********
** Public methods
*********/
/// <summary>Empty/null constructor.</summary>
public Texture2DExtended()
{
2019-01-05 17:50:48 +08:00
this.Texture = null;
}
/// <summary>Construct an instance.</summary>
2019-01-05 17:50:48 +08:00
public Texture2DExtended(Texture2D texture)
{
2019-01-05 17:50:48 +08:00
this.Texture = texture;
}
2019-01-05 17:50:48 +08:00
public Texture2DExtended(IModHelper helper, string path, ContentSource contentSource = ContentSource.ModFolder)
{
2019-01-05 17:50:48 +08:00
this.Texture = helper.Content.Load<Texture2D>(path, contentSource);
}
public Texture2DExtended Copy()
{
2019-01-05 17:50:48 +08:00
Texture2D clone = new Texture2D(this.Texture.GraphicsDevice, this.Texture.Width, this.Texture.Height);
Color[] data = new Color[clone.Width * clone.Height];
this.Texture.GetData(data);
clone.SetData(data);
2019-01-05 17:50:48 +08:00
return new Texture2DExtended(clone);
}
/// <summary>Returns the actual 2D texture held by this wrapper class.</summary>
public Texture2D getTexture()
{
2019-01-05 17:50:48 +08:00
return this.Texture;
}
}
}