2019-11-24 21:20:26 +00:00
|
|
|
|
using RecrownedAthenaeum.Types;
|
2019-03-27 07:35:20 +00:00
|
|
|
|
|
2019-12-28 20:35:01 +00:00
|
|
|
|
namespace RecrownedAthenaeum.Graphics.Render
|
2019-03-27 07:35:20 +00:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A simple utility object that will start and end a scissor setup given a <see cref="ConsistentSpriteBatch"/> to work with.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class BasicScissor
|
|
|
|
|
{
|
|
|
|
|
ConsistentSpriteBatch spriteBatch;
|
|
|
|
|
RasterizerState scissorRasterizer;
|
|
|
|
|
Rectangle scissorRectangle;
|
|
|
|
|
|
|
|
|
|
RasterizerState originalRasterizer;
|
|
|
|
|
Rectangle originalScissor;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes the basic scissor.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public BasicScissor()
|
|
|
|
|
{
|
|
|
|
|
scissorRasterizer = new RasterizerState();
|
|
|
|
|
scissorRasterizer.MultiSampleAntiAlias = false;
|
|
|
|
|
scissorRasterizer.ScissorTestEnable = true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Begins the <see cref="ConsistentSpriteBatch"/> with scissoring in mind.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="scissorRectangle">The rectangle to use to outline the scissor.</param>
|
|
|
|
|
/// <param name="consistentSpriteBatch">The consistent sprite batch to use for this process.</param>
|
|
|
|
|
public void Begin(Rectangle scissorRectangle, ConsistentSpriteBatch consistentSpriteBatch)
|
|
|
|
|
{
|
|
|
|
|
originalRasterizer = consistentSpriteBatch.rasterizerState;
|
|
|
|
|
this.scissorRectangle = scissorRectangle;
|
|
|
|
|
|
|
|
|
|
spriteBatch = consistentSpriteBatch;
|
|
|
|
|
spriteBatch.Begin(rasterizerState: scissorRasterizer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ends the scissor state of the spritebatch.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void End()
|
|
|
|
|
{
|
|
|
|
|
originalScissor = spriteBatch.GraphicsDevice.ScissorRectangle;
|
|
|
|
|
spriteBatch.GraphicsDevice.ScissorRectangle = scissorRectangle;
|
|
|
|
|
spriteBatch.End();
|
|
|
|
|
spriteBatch.rasterizerState = originalRasterizer;
|
|
|
|
|
spriteBatch.GraphicsDevice.ScissorRectangle = originalScissor;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|