using RecrownedAthenaeum.Types; namespace RecrownedAthenaeum.Render { /// /// A simple utility object that will start and end a scissor setup given a to work with. /// public class BasicScissor { ConsistentSpriteBatch spriteBatch; RasterizerState scissorRasterizer; Rectangle scissorRectangle; RasterizerState originalRasterizer; Rectangle originalScissor; /// /// Initializes the basic scissor. /// public BasicScissor() { scissorRasterizer = new RasterizerState(); scissorRasterizer.MultiSampleAntiAlias = false; scissorRasterizer.ScissorTestEnable = true; } /// /// Begins the with scissoring in mind. /// /// The rectangle to use to outline the scissor. /// The consistent sprite batch to use for this process. public void Begin(Rectangle scissorRectangle, ConsistentSpriteBatch consistentSpriteBatch) { originalRasterizer = consistentSpriteBatch.rasterizerState; this.scissorRectangle = scissorRectangle; spriteBatch = consistentSpriteBatch; spriteBatch.Begin(rasterizerState: scissorRasterizer); } /// /// Ends the scissor state of the spritebatch. /// public void End() { originalScissor = spriteBatch.GraphicsDevice.ScissorRectangle; spriteBatch.GraphicsDevice.ScissorRectangle = scissorRectangle; spriteBatch.End(); spriteBatch.rasterizerState = originalRasterizer; spriteBatch.GraphicsDevice.ScissorRectangle = originalScissor; } } }