2018-02-06 18:13:21 +08:00
|
|
|
using System.IO;
|
2019-01-05 17:50:48 +08:00
|
|
|
using Microsoft.Xna.Framework;
|
2018-12-30 18:00:05 +08:00
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
using StardewModdingAPI;
|
2018-02-06 18:13:21 +08:00
|
|
|
|
|
|
|
namespace StardustCore.UIUtilities
|
|
|
|
{
|
|
|
|
public class Texture2DExtended
|
|
|
|
{
|
2019-01-05 17:50:48 +08:00
|
|
|
/*********
|
|
|
|
** Accessors
|
|
|
|
*********/
|
|
|
|
/// <summary>The underlying texture.</summary>
|
|
|
|
public Texture2D Texture { get; }
|
2018-12-30 18:00:05 +08:00
|
|
|
|
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
|
|
|
|
*********/
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Empty/null constructor.</summary>
|
2018-03-31 16:47:10 +08:00
|
|
|
public Texture2DExtended()
|
|
|
|
{
|
2019-01-05 17:50:48 +08:00
|
|
|
this.Texture = null;
|
2018-03-31 16:47:10 +08:00
|
|
|
}
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Construct an instance.</summary>
|
2019-01-05 17:50:48 +08:00
|
|
|
public Texture2DExtended(Texture2D texture)
|
2018-02-06 18:13:21 +08:00
|
|
|
{
|
2019-01-05 17:50:48 +08:00
|
|
|
this.Texture = texture;
|
2018-02-06 18:13:21 +08:00
|
|
|
}
|
2018-08-09 04:18:51 +08:00
|
|
|
|
2019-01-05 17:50:48 +08:00
|
|
|
public Texture2DExtended(IModHelper helper, string path, ContentSource contentSource = ContentSource.ModFolder)
|
2018-08-09 04:18:51 +08:00
|
|
|
{
|
2019-01-05 17:50:48 +08:00
|
|
|
this.Texture = helper.Content.Load<Texture2D>(path, contentSource);
|
2018-08-09 04:18:51 +08:00
|
|
|
}
|
|
|
|
|
2018-05-01 09:21:31 +08:00
|
|
|
public Texture2DExtended Copy()
|
2018-02-06 18:13:21 +08:00
|
|
|
{
|
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);
|
2018-05-01 09:21:31 +08:00
|
|
|
|
2019-01-05 17:50:48 +08:00
|
|
|
return new Texture2DExtended(clone);
|
2018-05-01 09:21:31 +08:00
|
|
|
}
|
2018-06-13 09:42:31 +08:00
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Returns the actual 2D texture held by this wrapper class.</summary>
|
2018-06-13 09:42:31 +08:00
|
|
|
public Texture2D getTexture()
|
|
|
|
{
|
2019-01-05 17:50:48 +08:00
|
|
|
return this.Texture;
|
2018-08-08 01:07:33 +08:00
|
|
|
}
|
2018-02-06 18:13:21 +08:00
|
|
|
}
|
|
|
|
}
|