using Microsoft.Xna.Framework.Graphics; namespace SplitScreenSunBurn { /// /// Represents the many standard viewports. /// public enum ViewportLocation { FullScreen, TopHalf, BottomHalf, LeftHalf, RightHalf, TopLeftQuarter, TopRightQuarter, BottomLeftQuarter, BottomRightQuarter } public static class GraphicsDeviceExtensions { /// /// Sets the viewport on the GraphicsDevice to the desired viewport. /// /// The GraphicsDevice. /// The desired viewport location to set. public static void SetViewport(this GraphicsDevice device, ViewportLocation location) { Viewport viewport = new Viewport { MinDepth = 0f, MaxDepth = 1f }; switch (location) { case ViewportLocation.FullScreen: viewport.X = 0; viewport.Y = 0; viewport.Width = device.PresentationParameters.BackBufferWidth; viewport.Height = device.PresentationParameters.BackBufferHeight; break; case ViewportLocation.TopHalf: viewport.X = 0; viewport.Y = 0; viewport.Width = device.PresentationParameters.BackBufferWidth; viewport.Height = device.PresentationParameters.BackBufferHeight / 2; break; case ViewportLocation.BottomHalf: viewport.X = 0; viewport.Y = device.PresentationParameters.BackBufferHeight / 2; viewport.Width = device.PresentationParameters.BackBufferWidth; viewport.Height = device.PresentationParameters.BackBufferHeight / 2; break; case ViewportLocation.LeftHalf: viewport.X = 0; viewport.Y = 0; viewport.Width = device.PresentationParameters.BackBufferWidth / 2; viewport.Height = device.PresentationParameters.BackBufferHeight; break; case ViewportLocation.RightHalf: viewport.X = device.PresentationParameters.BackBufferWidth / 2; viewport.Y = 0; viewport.Width = device.PresentationParameters.BackBufferWidth / 2; viewport.Height = device.PresentationParameters.BackBufferHeight; break; case ViewportLocation.TopLeftQuarter: viewport.X = 0; viewport.Y = 0; viewport.Width = device.PresentationParameters.BackBufferWidth / 2; viewport.Height = device.PresentationParameters.BackBufferHeight / 2; break; case ViewportLocation.TopRightQuarter: viewport.X = device.PresentationParameters.BackBufferWidth / 2; viewport.Y = 0; viewport.Width = device.PresentationParameters.BackBufferWidth / 2; viewport.Height = device.PresentationParameters.BackBufferHeight / 2; break; case ViewportLocation.BottomLeftQuarter: viewport.X = 0; viewport.Y = device.PresentationParameters.BackBufferHeight / 2; viewport.Width = device.PresentationParameters.BackBufferWidth / 2; viewport.Height = device.PresentationParameters.BackBufferHeight / 2; break; case ViewportLocation.BottomRightQuarter: viewport.X = device.PresentationParameters.BackBufferWidth / 2; viewport.Y = device.PresentationParameters.BackBufferHeight / 2; viewport.Width = device.PresentationParameters.BackBufferWidth / 2; viewport.Height = device.PresentationParameters.BackBufferHeight / 2; break; } device.Viewport = viewport; } } }