From 84e388677c0a2ae1e154dfd309434696eeea718f Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Fri, 8 Nov 2019 15:35:15 +0100 Subject: [PATCH] added a setfullscreen method --- MLEM/Extensions/GraphicsExtensions.cs | 27 +++++++++++++++++++++++++++ Sandbox/GameImpl.cs | 12 ++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 MLEM/Extensions/GraphicsExtensions.cs diff --git a/MLEM/Extensions/GraphicsExtensions.cs b/MLEM/Extensions/GraphicsExtensions.cs new file mode 100644 index 0000000..df5faa1 --- /dev/null +++ b/MLEM/Extensions/GraphicsExtensions.cs @@ -0,0 +1,27 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +namespace MLEM.Extensions { + public static class GraphicsExtensions { + + private static int lastWidth; + private static int lastHeight; + + public static void SetFullscreen(this GraphicsDeviceManager manager, bool fullscreen) { + manager.IsFullScreen = fullscreen; + if (fullscreen) { + lastWidth = manager.GraphicsDevice.Viewport.Width; + lastHeight = manager.GraphicsDevice.Viewport.Height; + + var curr = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode; + manager.PreferredBackBufferWidth = curr.Width; + manager.PreferredBackBufferHeight = curr.Height; + } else { + manager.PreferredBackBufferWidth = lastWidth; + manager.PreferredBackBufferHeight = lastHeight; + } + manager.ApplyChanges(); + } + + } +} \ No newline at end of file diff --git a/Sandbox/GameImpl.cs b/Sandbox/GameImpl.cs index 12d4dc0..79bac0c 100644 --- a/Sandbox/GameImpl.cs +++ b/Sandbox/GameImpl.cs @@ -1,5 +1,8 @@ +using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Input; +using MLEM.Extensions; using MLEM.Font; using MLEM.Startup; using MLEM.Textures; @@ -12,6 +15,9 @@ namespace Sandbox { public GameImpl() { this.IsMouseVisible = true; + this.Window.ClientSizeChanged += (o, args) => { + Console.WriteLine("Size changed"); + }; } protected override void LoadContent() { @@ -34,6 +40,12 @@ namespace Sandbox { this.UiSystem.Add("Panel", panel); } + protected override void Update(GameTime gameTime) { + base.Update(gameTime); + if (this.InputHandler.IsKeyPressed(Keys.F11)) + this.GraphicsDeviceManager.SetFullscreen(!this.GraphicsDeviceManager.IsFullScreen); + } + protected override void DoDraw(GameTime gameTime) { this.GraphicsDevice.Clear(Color.Black); base.DoDraw(gameTime);