2019-03-21 00:28:16 +00:00
|
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
|
|
|
|
|
|
namespace RecrownedAthenaeum.Render
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Box that crops off anything outside of the bounds.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class ScissorBox
|
|
|
|
|
{
|
|
|
|
|
|
2019-03-24 00:04:43 +00:00
|
|
|
|
ConsistentSpriteBatch spriteBatch;
|
|
|
|
|
Rectangle originalScissor;
|
|
|
|
|
RasterizerState originalRasterizerState;
|
|
|
|
|
|
|
|
|
|
RasterizerState scissorRasterizerState;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Used to crop off anything that doesn't fit into the defined space.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public ScissorBox()
|
|
|
|
|
{
|
|
|
|
|
scissorRasterizerState = new RasterizerState();
|
|
|
|
|
scissorRasterizerState.ScissorTestEnable = true;
|
|
|
|
|
}
|
2019-03-21 00:28:16 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Starts spritebatch with scissoring enabled.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="rectangle"></param>
|
|
|
|
|
/// <param name="spriteBatch"></param>
|
2019-03-24 00:04:43 +00:00
|
|
|
|
public void Begin(Rectangle rectangle, ConsistentSpriteBatch spriteBatch)
|
2019-03-21 00:28:16 +00:00
|
|
|
|
{
|
|
|
|
|
this.spriteBatch = spriteBatch;
|
2019-03-24 00:04:43 +00:00
|
|
|
|
originalRasterizerState = spriteBatch.RasterizerState;
|
|
|
|
|
spriteBatch.Begin(rasterizerState: scissorRasterizerState);
|
|
|
|
|
|
|
|
|
|
originalScissor = spriteBatch.GraphicsDevice.ScissorRectangle;
|
2019-03-21 00:28:16 +00:00
|
|
|
|
spriteBatch.GraphicsDevice.ScissorRectangle = rectangle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ends the scissoring and spritebatch.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void End()
|
|
|
|
|
{
|
2019-03-24 00:04:43 +00:00
|
|
|
|
spriteBatch.GraphicsDevice.ScissorRectangle = originalScissor;
|
|
|
|
|
spriteBatch.RasterizerState = originalRasterizerState;
|
2019-03-21 00:28:16 +00:00
|
|
|
|
spriteBatch.End();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|