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

31 lines
1.2 KiB
C#
Raw Normal View History

2019-12-01 22:58:20 +01:00
using System;
2019-11-08 15:35:15 +01:00
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;
2019-11-08 15:35:15 +01:00
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");
2019-11-08 15:35:15 +01:00
manager.PreferredBackBufferWidth = lastWidth;
manager.PreferredBackBufferHeight = lastHeight;
}
manager.ApplyChanges();
}
}
}