1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-16 18:53:12 +01:00
MLEM/MLEM/Extensions/GraphicsExtensions.cs
2019-12-01 22:58:20 +01:00

31 lines
No EOL
1.2 KiB
C#

using System;
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 {
if (lastWidth <= 0 || lastHeight <= 0)
throw new InvalidOperationException("Can't call SetFullscreen to change out of fullscreen mode without going into fullscreen mode first");
manager.PreferredBackBufferWidth = lastWidth;
manager.PreferredBackBufferHeight = lastHeight;
}
manager.ApplyChanges();
}
}
}