コード例 #1
0
        private void SetFullScreen()
        {
            var screenWidth  = GraphicsDevice.DisplayMode.Width;
            var screenHeight = GraphicsDevice.DisplayMode.Height;

            graphics.PreferredBackBufferWidth  = screenWidth;
            graphics.PreferredBackBufferHeight = screenHeight;
            graphics.IsFullScreen = true;
            graphics.ApplyChanges();

            var virtualRatio = Width / (float)Height;
            var screenRatio  = screenWidth / (float)screenHeight;

            if (virtualRatio > screenRatio)
            {
                // letter box
                var scale  = screenWidth / (float)Width;
                var height = (int)(scale * Height);
                renderToScreenRect = new Rectangle(0, (screenHeight - height) / 2, screenWidth, height);
            }
            else if (virtualRatio < screenRatio)
            {
                // pillar box
                var scale = screenHeight / (float)Height;
                var width = (int)(scale * Width);
                renderToScreenRect = new Rectangle((screenWidth - width) / 2, 0, width, screenHeight);
            }
            else
            {
                // no box
                renderToScreenRect = new Rectangle(0, 0, screenWidth, screenHeight);
            }

            OnViewportChanged?.Invoke(renderToScreenRect.Width, renderToScreenRect.Height, true);
        }
コード例 #2
0
        private void SetWindowed()
        {
            var windowWidth  = (int)(Width * windowScale);
            var windowHeight = (int)(Height * windowScale);

            graphics.PreferredBackBufferWidth  = windowWidth;
            graphics.PreferredBackBufferHeight = windowHeight;
            renderToScreenRect    = new Rectangle(0, 0, windowWidth, windowHeight);
            graphics.IsFullScreen = false;
            graphics.ApplyChanges();

            OnViewportChanged?.Invoke(renderToScreenRect.Width, renderToScreenRect.Height, false);
        }
コード例 #3
0
 private void SetViewport(object sender, EventArgs e)
 {
     GL.Viewport(_control.Size);
     OnViewportChanged?.Invoke(_control.Size);
 }