using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MLEM.Extensions;
using MLEM.Textures;
using MonoGame.Extended;
using MonoGame.Extended.BitmapFonts;
namespace MLEM.Extended.Extensions {
///
/// A set of extension methods for dealing with and in combination.
///
public static class SpriteBatchExtensions {
///
public static void Draw(this SpriteBatch batch, Texture2D texture, RectangleF destinationRectangle, Rectangle? sourceRectangle, Color color, float rotation, Vector2 origin, SpriteEffects effects, float layerDepth) {
batch.Draw(texture, destinationRectangle.ToMlem(), sourceRectangle, color, rotation, origin, effects, layerDepth);
}
///
public static void Draw(this SpriteBatch batch, Texture2D texture, RectangleF destinationRectangle, Rectangle? sourceRectangle, Color color) {
batch.Draw(texture, destinationRectangle, sourceRectangle, color, 0, Vector2.Zero, SpriteEffects.None, 0);
}
///
public static void Draw(this SpriteBatch batch, Texture2D texture, RectangleF destinationRectangle, Color color) {
batch.Draw(texture, destinationRectangle, null, color);
}
///
/// Draws a grid of tile outlines reminiscent of graph paper.
///
/// The sprite batch to draw with
/// The top left coordinate of the grid
/// The size of each tile
/// The amount of tiles in the x and y axes
/// The color to draw the grid outlines in
/// The thickness of each grid line. Defaults to 1.
public static void DrawGrid(this SpriteBatch batch, Vector2 start, Vector2 tileSize, Point tileCount, Color gridColor, float gridThickness = 1) {
for (var y = 0; y < tileCount.Y; y++) {
for (var x = 0; x < tileCount.X; x++)
batch.DrawRectangle(start + new Vector2(x, y) * tileSize, tileSize, gridColor, gridThickness / 2);
}
var size = tileSize * tileCount.ToVector2() + new Vector2(gridThickness);
batch.DrawRectangle(start - new Vector2(gridThickness / 2), size, gridColor, gridThickness / 2);
}
}
}