private void OnClientSizeChanged(object sender, EventArgs eventArgs)
        {
            var viewport = GraphicsDevice.Viewport;

            var worldScaleX = (float)viewport.Width / VirtualWidth;
            var worldScaleY = (float)viewport.Height / VirtualHeight;

            var safeScaleX = (float)viewport.Width / (VirtualWidth - HorizontalBleed);
            var safeScaleY = (float)viewport.Height / (VirtualHeight - HorizontalBleed);

            var worldScale = MathHelper.Max(worldScaleX, worldScaleY);
            var safeScale  = MathHelper.Min(safeScaleX, safeScaleY);
            var scale      = MathHelper.Min(worldScale, safeScale);

            var width  = (int)(scale * VirtualWidth + 0.5f);
            var height = (int)(scale * VirtualHeight + 0.5f);

            if (height >= viewport.Height && width < viewport.Width)
            {
                BoxingMode = BoxingMode.Pillarbox;
            }
            else if (width >= viewport.Height && height < viewport.Height)
            {
                BoxingMode = BoxingMode.Letterbox;
            }
            else
            {
                BoxingMode = BoxingMode.None;
            }

            var x = (int)((viewport.Width - width) * .5f);
            var y = (int)((viewport.Height - height) * .5f);

            GraphicsDevice.Viewport = new Viewport(x, y, width, height);
        }
        private void OnClientSizeChanged(object sender, EventArgs eventArgs)
        {
            var viewport = GraphicsDevice.Viewport;
            var aspectRatio = (float) VirtualWidth / VirtualHeight;
            var width = viewport.Width;
            var height = (int)(width / aspectRatio + 0.5f);

            if (height > viewport.Height)
            {
                BoxingMode = BoxingMode.Pillarbox;
                height = viewport.Height;
                width = (int) (height * aspectRatio + 0.5f);
            }
            else
            {
                BoxingMode = BoxingMode.Letterbox;
            }

            var x = (viewport.Width / 2) - (width / 2);
            var y = (viewport.Height / 2) - (height / 2);
            GraphicsDevice.Viewport = new Viewport(x, y, width, height);

            // Needed for a DirectX bug in MonoGame 3.4. Hopefully it will be fixed in future versions
            // see http://gamedev.stackexchange.com/questions/68914/issue-with-monogame-resizing
            if (_graphicsDeviceManager != null &&
                    (_graphicsDeviceManager.PreferredBackBufferWidth != _window.ClientBounds.Width ||
                    _graphicsDeviceManager.PreferredBackBufferHeight != _window.ClientBounds.Height))
            {
                _graphicsDeviceManager.PreferredBackBufferWidth = _window.ClientBounds.Width;
                _graphicsDeviceManager.PreferredBackBufferHeight = _window.ClientBounds.Height;
                _graphicsDeviceManager.ApplyChanges();
            }
        }
Esempio n. 3
0
        private void OnClientSizeChanged(object sender, EventArgs eventArgs)
        {
            var viewport    = GraphicsDevice.Viewport;
            var aspectRatio = (float)VirtualWidth / VirtualHeight;
            var width       = viewport.Width;
            var height      = (int)(width / aspectRatio + 0.5f);

            if (height > viewport.Height)
            {
                BoxingMode = BoxingMode.Pillarbox;
                height     = viewport.Height;
                width      = (int)(height * aspectRatio + 0.5f);
            }
            else
            {
                BoxingMode = BoxingMode.Letterbox;
            }

            var x = (viewport.Width / 2) - (width / 2);
            var y = (viewport.Height / 2) - (height / 2);

            GraphicsDevice.Viewport = new Viewport(x, y, width, height);

            // Needed for a DirectX bug in MonoGame 3.4. Hopefully it will be fixed in future versions
            // see http://gamedev.stackexchange.com/questions/68914/issue-with-monogame-resizing
            if (_graphicsDeviceManager != null &&
                (_graphicsDeviceManager.PreferredBackBufferWidth != _window.ClientBounds.Width ||
                 _graphicsDeviceManager.PreferredBackBufferHeight != _window.ClientBounds.Height))
            {
                _graphicsDeviceManager.PreferredBackBufferWidth  = _window.ClientBounds.Width;
                _graphicsDeviceManager.PreferredBackBufferHeight = _window.ClientBounds.Height;
                _graphicsDeviceManager.ApplyChanges();
            }
        }
        private void OnClientSizeChanged(GameWindow window)
        {
            var viewport = GraphicsDevice.Viewport;

            var worldScaleX = (float)viewport.Width / VirtualWidth;
            var worldScaleY = (float)viewport.Height / VirtualHeight;

            var safeScaleX = (float)viewport.Width / (VirtualWidth - HorizontalBleed);
            var safeScaleY = (float)viewport.Height / (VirtualHeight - VerticalBleed);

            var worldScale = MathHelper.Max(worldScaleX, worldScaleY);
            var safeScale  = MathHelper.Min(safeScaleX, safeScaleY);
            var scale      = MathHelper.Min(worldScale, safeScale);

            var width  = (int)(scale * VirtualWidth + 0.5f);
            var height = (int)(scale * VirtualHeight + 0.5f);

            if ((height >= viewport.Height) && (width < viewport.Width))
            {
                BoxingMode = BoxingMode.Pillarbox;
            }
            else
            {
                if ((width >= viewport.Height) && (height < viewport.Height))
                {
                    BoxingMode = BoxingMode.Letterbox;
                }
                else
                {
                    BoxingMode = BoxingMode.None;
                }
            }

            var x = viewport.Width / 2 - width / 2;
            var y = viewport.Height / 2 - height / 2;

            GraphicsDevice.Viewport = new Viewport(x, y, width, height);

            // Needed for a DirectX bug in MonoGame 3.4. Hopefully it will be fixed in future versions
            // see http://gamedev.stackexchange.com/questions/68914/issue-with-monogame-resizing
            if ((_graphicsDeviceManager != null) &&
                ((_graphicsDeviceManager.PreferredBackBufferWidth != _window.ClientBounds.Width) ||
                 (_graphicsDeviceManager.PreferredBackBufferHeight != _window.ClientBounds.Height)))
            {
                _graphicsDeviceManager.PreferredBackBufferWidth  = _window.ClientBounds.Width;
                _graphicsDeviceManager.PreferredBackBufferHeight = _window.ClientBounds.Height;
                _graphicsDeviceManager.ApplyChanges();
            }
        }
Esempio n. 5
0
        private void OnClientSizeChanged(object sender, EventArgs eventArgs)
        {
            var clientBounds = _window.ClientBounds;

            var worldScaleX = (float)clientBounds.Width / VirtualWidth;
            var worldScaleY = (float)clientBounds.Height / VirtualHeight;

            var safeScaleX = (float)clientBounds.Width / (VirtualWidth - HorizontalBleed);
            var safeScaleY = (float)clientBounds.Height / (VirtualHeight - VerticalBleed);

            var worldScale = MathHelper.Max(worldScaleX, worldScaleY);
            var safeScale  = MathHelper.Min(safeScaleX, safeScaleY);
            var scale      = MathHelper.Min(worldScale, safeScale);

            var width  = (int)(scale * VirtualWidth + 0.5f);
            var height = (int)(scale * VirtualHeight + 0.5f);

            if (height >= clientBounds.Height && width < clientBounds.Width)
            {
                BoxingMode = BoxingMode.Pillarbox;
            }
            else
            {
                if (width >= clientBounds.Height && height <= clientBounds.Height)
                {
                    BoxingMode = BoxingMode.Letterbox;
                }
                else
                {
                    BoxingMode = BoxingMode.None;
                }
            }

            var x = clientBounds.Width / 2 - width / 2;
            var y = clientBounds.Height / 2 - height / 2;

            //GraphicsDevice.Viewport = new Viewport(x, y, width, height);
            Viewport       = new Viewport(x, y, width, height);
            RenderTarget2D = new RenderTarget2D(GraphicsDevice, Viewport.Width, Viewport.Height);
#if DEBUG
            FlxG.Log.Info("GraphicsDevice.Viewport.Bounds :" + GraphicsDevice.Viewport.Bounds);
#endif
        }
        public override void OnClientSizeChanged()
        {
            var viewport = GraphicsDevice.Viewport;
            var aspectRatio = (float) VirtualWidth / VirtualHeight;
            var width = viewport.Width;
            var height = (int)(width / aspectRatio + 0.5f);

            if (height > viewport.Height)
            {
                BoxingMode = BoxingMode.Pillarbox;
                height = viewport.Height;
                width = (int) (height * aspectRatio + 0.5f);
            }
            else
            {
                BoxingMode = BoxingMode.Letterbox;
            }

            var x = (viewport.Width / 2) - (width / 2);
            var y = (viewport.Height / 2) - (height / 2);
            GraphicsDevice.Viewport = new Viewport(x, y, width, height);
        }
        public override void OnClientSizeChanged()
        {
            var viewport    = GraphicsDevice.Viewport;
            var aspectRatio = (float)VirtualWidth / VirtualHeight;
            var width       = viewport.Width;
            var height      = (int)(width / aspectRatio + 0.5f);

            if (height > viewport.Height)
            {
                BoxingMode = BoxingMode.Pillarbox;
                height     = viewport.Height;
                width      = (int)(height * aspectRatio + 0.5f);
            }
            else
            {
                BoxingMode = BoxingMode.Letterbox;
            }

            var x = (viewport.Width / 2) - (width / 2);
            var y = (viewport.Height / 2) - (height / 2);

            GraphicsDevice.Viewport = new Viewport(x, y, width, height);
        }