using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; namespace RecrownedAthenaeum.Render { /// /// Box that crops off anything outside of the bounds. /// public class ScissorBox { ConsistentSpriteBatch spriteBatch; Rectangle originalScissor; RasterizerState originalRasterizerState; RasterizerState scissorRasterizerState; /// /// Used to crop off anything that doesn't fit into the defined space. /// public ScissorBox() { scissorRasterizerState = new RasterizerState(); scissorRasterizerState.ScissorTestEnable = true; } /// /// Starts spritebatch with scissoring enabled. /// /// /// public void Begin(Rectangle rectangle, ConsistentSpriteBatch spriteBatch) { this.spriteBatch = spriteBatch; originalRasterizerState = spriteBatch.RasterizerState; spriteBatch.Begin(rasterizerState: scissorRasterizerState); originalScissor = spriteBatch.GraphicsDevice.ScissorRectangle; spriteBatch.GraphicsDevice.ScissorRectangle = rectangle; } /// /// Ends the scissoring and spritebatch. /// public void End() { spriteBatch.GraphicsDevice.ScissorRectangle = originalScissor; spriteBatch.RasterizerState = originalRasterizerState; spriteBatch.End(); } } }