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) {
|
2020-01-26 01:31:40 +01:00
|
|
|
var view = manager.GraphicsDevice.Viewport;
|
|
|
|
lastWidth = view.Width;
|
|
|
|
lastHeight = view.Height;
|
2020-01-26 01:20:20 +01:00
|
|
|
|
2019-11-08 15:35:15 +01:00
|
|
|
var curr = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode;
|
|
|
|
manager.PreferredBackBufferWidth = curr.Width;
|
|
|
|
manager.PreferredBackBufferHeight = curr.Height;
|
|
|
|
} else {
|
2020-01-26 01:20:20 +01:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2020-01-26 01:31:40 +01:00
|
|
|
public static void ApplyChangesSafely(this GraphicsDeviceManager manager) {
|
|
|
|
// If we don't do this, then applying changes will cause the
|
|
|
|
// graphics device manager to reset the window size to the
|
|
|
|
// size set when starting the game :V
|
|
|
|
var view = manager.GraphicsDevice.Viewport;
|
|
|
|
manager.PreferredBackBufferWidth = view.Width;
|
|
|
|
manager.PreferredBackBufferHeight = view.Height;
|
|
|
|
manager.ApplyChanges();
|
|
|
|
}
|
|
|
|
|
2019-11-08 15:35:15 +01:00
|
|
|
}
|
|
|
|
}
|