mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 12:58:33 +01:00
added a setfullscreen method
This commit is contained in:
parent
264d3ee313
commit
84e388677c
2 changed files with 39 additions and 0 deletions
27
MLEM/Extensions/GraphicsExtensions.cs
Normal file
27
MLEM/Extensions/GraphicsExtensions.cs
Normal 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,8 @@
|
||||||
|
using System;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using Microsoft.Xna.Framework.Input;
|
||||||
|
using MLEM.Extensions;
|
||||||
using MLEM.Font;
|
using MLEM.Font;
|
||||||
using MLEM.Startup;
|
using MLEM.Startup;
|
||||||
using MLEM.Textures;
|
using MLEM.Textures;
|
||||||
|
@ -12,6 +15,9 @@ namespace Sandbox {
|
||||||
|
|
||||||
public GameImpl() {
|
public GameImpl() {
|
||||||
this.IsMouseVisible = true;
|
this.IsMouseVisible = true;
|
||||||
|
this.Window.ClientSizeChanged += (o, args) => {
|
||||||
|
Console.WriteLine("Size changed");
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadContent() {
|
protected override void LoadContent() {
|
||||||
|
@ -34,6 +40,12 @@ namespace Sandbox {
|
||||||
this.UiSystem.Add("Panel", panel);
|
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) {
|
protected override void DoDraw(GameTime gameTime) {
|
||||||
this.GraphicsDevice.Clear(Color.Black);
|
this.GraphicsDevice.Clear(Color.Black);
|
||||||
base.DoDraw(gameTime);
|
base.DoDraw(gameTime);
|
||||||
|
|
Loading…
Reference in a new issue