52 lines
1.5 KiB
C#
52 lines
1.5 KiB
C#
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using RecrownedAthenaeum.DataTypes;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Xml.Serialization;
|
|
|
|
namespace Recrowned_Athenaeum.DataTypes
|
|
{
|
|
public struct TextureAtlasRegion : IComparable<TextureAtlasRegion>, IDisposable
|
|
{
|
|
public string name;
|
|
Rectangle sourceRectangle;
|
|
Vector2 origin;
|
|
Color color;
|
|
float rotation;
|
|
NinePatch ninepatch;
|
|
[XmlIgnore]
|
|
Texture2D regionTexture;
|
|
|
|
public void Draw(SpriteBatch batch, Rectangle destination, Texture2D regionOfTexture)
|
|
{
|
|
batch.Draw(regionOfTexture, destination, sourceRectangle, color);
|
|
}
|
|
|
|
public Texture2D AsTexture2D(GraphicsDevice graphicsDevice, Texture2D textureAtlas)
|
|
{
|
|
if (regionTexture == null)
|
|
{
|
|
Color[] data = new Color[sourceRectangle.Width * sourceRectangle.Height];
|
|
regionTexture = new Texture2D(graphicsDevice, sourceRectangle.Width, sourceRectangle.Height);
|
|
textureAtlas.GetData(0, sourceRectangle, data, 0, sourceRectangle.Width * sourceRectangle.Height);
|
|
regionTexture.SetData(data);
|
|
}
|
|
return regionTexture;
|
|
}
|
|
|
|
public int CompareTo(TextureAtlasRegion other)
|
|
{
|
|
return name.CompareTo(other);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
regionTexture?.Dispose();
|
|
}
|
|
}
|
|
}
|