1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-05-29 03:23:37 +02:00

added a setfullscreen method

This commit is contained in:
Ellpeck 2019-11-08 15:35:15 +01:00
parent 264d3ee313
commit 84e388677c
2 changed files with 39 additions and 0 deletions

View file

@ -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();
}
}
}

View file

@ -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);