Exemplo n.º 1
0
        // Apply the specified ScreenMode and preserves the aspect ratio expressed in the mode.
        void ApplyScreenMode(GraphicsDeviceManager graphics, ScreenMode mode, bool fullscreen)
        {
            Mode = mode;
            graphics.PreferredBackBufferWidth  = Mode.Width;
            graphics.PreferredBackBufferHeight = Mode.Height;
            graphics.PreferMultiSampling       = true;
            graphics.IsFullScreen = fullscreen;
            graphics.ApplyChanges();

            ScaleFactor = Mode.Width * Mode.AspectRatio / InternalMode.Height;
            Scale       = Matrix.CreateScale(ScaleFactor);

            DefaultViewport = graphics.GraphicsDevice.Viewport;

            var viewport = new Viewport {
                X = 0, Y = (int)((Mode.Height - Mode.Width / Mode.AspectRatio) / 2), Width = Mode.Width, Height = (int)(Mode.Width / Mode.AspectRatio)
            };

            graphics.GraphicsDevice.Viewport = Viewport;
            Viewport = viewport;
        }
Exemplo n.º 2
0
        public Resolution()
        {
            ScaleFactor  = 1f;
            InternalMode = new ScreenMode(1920, 1080, 16 / 9f);

            var sortedScreenModes = new List <ScreenMode>();

            foreach (var displayMode in GraphicsAdapter.DefaultAdapter.SupportedDisplayModes)
            {
                if (displayMode.AspectRatio > 1f && displayMode.Width >= 800f && displayMode.Width <= InternalMode.Width && displayMode.Height <= InternalMode.Height)
                {
                    var screenMode = new ScreenMode(displayMode.Width, displayMode.Height, displayMode.AspectRatio);
                    if (!sortedScreenModes.Contains(screenMode))
                    {
                        sortedScreenModes.Add(screenMode);
                    }
                }
            }

            sortedScreenModes.Sort();
            SortedScreenModes = sortedScreenModes.AsReadOnly();
        }
Exemplo n.º 3
0
 // Initialize the Resolution using the specified ScreenMode
 public bool Initialize(GraphicsDeviceManager graphics, ScreenMode mode, bool fullscreen)
 {
     InternalMode = new ScreenMode(1920, 1080, 16 / 9f);
     return(SetScreenMode(graphics, mode, fullscreen));
 }