Microsoft.Xna.Framework.OpenTKGamePlatform.ResetWindowBounds C# (CSharp) Method

ResetWindowBounds() private method

private ResetWindowBounds ( ) : void
return void
        internal void ResetWindowBounds()
        {
            Rectangle bounds;

            bounds = Window.ClientBounds;

            //Changing window style forces a redraw. Some games
            //have fail-logic and toggle fullscreen in their draw function,
            //so temporarily become inactive so it won't execute.

            bool wasActive = IsActive;
            IsActive = false;

            var graphicsDeviceManager = (GraphicsDeviceManager)
                Game.Services.GetService(typeof(IGraphicsDeviceManager));

            if (graphicsDeviceManager.IsFullScreen)
            {
                bounds = new Rectangle(0, 0,graphicsDeviceManager.PreferredBackBufferWidth,graphicsDeviceManager.PreferredBackBufferHeight);

                if (OpenTK.DisplayDevice.Default.Width != graphicsDeviceManager.PreferredBackBufferWidth ||
                    OpenTK.DisplayDevice.Default.Height != graphicsDeviceManager.PreferredBackBufferHeight)
                {
                    OpenTK.DisplayDevice.Default.ChangeResolution(graphicsDeviceManager.PreferredBackBufferWidth,
                            graphicsDeviceManager.PreferredBackBufferHeight,
                            OpenTK.DisplayDevice.Default.BitsPerPixel,
                            OpenTK.DisplayDevice.Default.RefreshRate);
                }
            }
            else
            {
                
                // switch back to the normal screen resolution
                OpenTK.DisplayDevice.Default.RestoreResolution();
                // now update the bounds 
                bounds.Width = graphicsDeviceManager.PreferredBackBufferWidth;
                bounds.Height = graphicsDeviceManager.PreferredBackBufferHeight;
            }
            

            // Now we set our Presentation Parameters
            var device = (GraphicsDevice)graphicsDeviceManager.GraphicsDevice;
            // FIXME: Eliminate the need for null checks by only calling
            //        ResetWindowBounds after the device is ready.  Or,
            //        possibly break this method into smaller methods.
            if (device != null)
            {
                PresentationParameters parms = device.PresentationParameters;
                parms.BackBufferHeight = (int)bounds.Height;
                parms.BackBufferWidth = (int)bounds.Width;
            }

            if (graphicsDeviceManager.IsFullScreen != isCurrentlyFullScreen)
            {                
                _view.ToggleFullScreen();
            }

            // we only change window bounds if we are not fullscreen
            // or if fullscreen mode was just entered
            if (!graphicsDeviceManager.IsFullScreen || (graphicsDeviceManager.IsFullScreen != isCurrentlyFullScreen))
                _view.ChangeClientBounds(bounds);

            // store the current fullscreen state
            isCurrentlyFullScreen = graphicsDeviceManager.IsFullScreen;

            IsActive = wasActive;
        }