using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MLEM.Extended.Maths;
using MLEM.Graphics;
using MLEM.Maths;
using ShapeExtensions = MonoGame.Extended.ShapeExtensions;
using RectangleF = MonoGame.Extended.RectangleF;
namespace MLEM.Extended.Graphics {
///
/// A set of extension methods for dealing with and in combination.
///
public static class SpriteBatchExtensions {
/// Submit a sprite for drawing in the current batch.
/// The sprite batch to draw with.
/// A texture.
/// The drawing bounds on screen.
/// An optional region on the texture which will be rendered. If null - draws full texture.
/// A color mask.
/// A rotation of this sprite.
/// Center of the rotation. 0,0 by default.
/// Modificators for drawing. Can be combined.
/// A depth of the layer of this sprite.
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);
}
/// Submit a sprite for drawing in the current batch.
/// The sprite batch to draw with.
/// A texture.
/// The drawing bounds on screen.
/// An optional region on the texture which will be rendered. If null - draws full texture.
/// A color mask.
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);
}
/// Submit a sprite for drawing in the current batch.
/// The sprite batch to draw with.
/// A texture.
/// The drawing bounds on screen.
/// A color mask.
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++)
ShapeExtensions.DrawRectangle(batch, start + new Vector2(x, y) * tileSize, tileSize, gridColor, gridThickness / 2);
}
var size = tileSize * tileCount.ToVector2() + new Vector2(gridThickness);
ShapeExtensions.DrawRectangle(batch, start - new Vector2(gridThickness / 2), size, gridColor, gridThickness / 2);
}
}
}