2019-12-14 14:00:12 +01:00
|
|
|
using MLEM.Extensions;
|
2019-08-09 15:15:22 +02:00
|
|
|
using MLEM.Textures;
|
|
|
|
using MonoGame.Extended.TextureAtlases;
|
|
|
|
|
|
|
|
namespace MLEM.Extended.Extensions {
|
2020-05-22 20:32:38 +02:00
|
|
|
/// <summary>
|
|
|
|
/// A set of extensions for converting texture-related types between MLEM and MonoGame.Extended.
|
|
|
|
/// </summary>
|
2019-08-09 15:15:22 +02:00
|
|
|
public static class TextureExtensions {
|
|
|
|
|
2020-05-22 20:32:38 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Converts a MLEM <see cref="NinePatch"/> to a MonoGame.Extended <see cref="NinePatchRegion2D"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="patch">The nine patch to convert</param>
|
|
|
|
/// <returns>The converted nine patch</returns>
|
2019-08-09 15:15:22 +02:00
|
|
|
public static NinePatchRegion2D ToExtended(this NinePatch patch) {
|
2019-12-14 14:00:12 +01:00
|
|
|
return new NinePatchRegion2D(patch.Region.ToExtended(), patch.Padding.Left.Floor(), patch.Padding.Top.Floor(), patch.Padding.Right.Floor(), patch.Padding.Bottom.Floor());
|
2019-08-09 15:15:22 +02:00
|
|
|
}
|
|
|
|
|
2020-05-22 20:32:38 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Converts a MLEM <see cref="TextureRegion"/> to a MonoGame.Extended <see cref="TextureRegion2D"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="region">The nine patch to convert</param>
|
|
|
|
/// <returns>The converted nine patch</returns>
|
2019-08-09 15:15:22 +02:00
|
|
|
public static TextureRegion2D ToExtended(this TextureRegion region) {
|
2022-01-22 16:55:46 +01:00
|
|
|
return new TextureRegion2D(region.Name, region.Texture, region.U, region.V, region.Width, region.Height);
|
2019-08-09 15:15:22 +02:00
|
|
|
}
|
|
|
|
|
2020-05-22 20:32:38 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Converts a MonoGame.Extended <see cref="NinePatchRegion2D"/> to a MLEM <see cref="NinePatch"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="patch">The nine patch to convert</param>
|
|
|
|
/// <returns>The converted nine patch</returns>
|
2019-08-09 15:15:22 +02:00
|
|
|
public static NinePatch ToMlem(this NinePatchRegion2D patch) {
|
2022-01-22 16:55:46 +01:00
|
|
|
return new NinePatch(((TextureRegion2D) patch).ToMlem(), patch.LeftPadding, patch.RightPadding, patch.TopPadding, patch.BottomPadding);
|
2019-08-09 15:15:22 +02:00
|
|
|
}
|
|
|
|
|
2020-05-22 20:32:38 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Converts a MonoGame.Extended <see cref="TextureRegion2D"/> to a MLEM <see cref="TextureRegion"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="region">The nine patch to convert</param>
|
|
|
|
/// <returns>The converted nine patch</returns>
|
2019-08-09 15:15:22 +02:00
|
|
|
public static TextureRegion ToMlem(this TextureRegion2D region) {
|
2022-01-22 16:55:46 +01:00
|
|
|
return new TextureRegion(region.Texture, region.Bounds) {Name = region.Name};
|
2019-08-09 15:15:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2022-06-17 18:23:47 +02:00
|
|
|
}
|