using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace MyGame001
{
public class ResolutionChanger
{
private int myWidth;
private int myHeight;
private bool changeFullScreen;
private Rectangle mLastWindowedBounds;
private GraphicsDeviceManager _graphics;
private GameWindow myWindow;
public ResolutionChanger (GraphicsDeviceManager graphics, GameWindow window)
{
mLastWindowedBounds = window.ClientBounds;
myHeight = 1048;
myWidth = 840;
_graphics = graphics;
myWindow = window;
}
public void Update (bool set_fullscreen)
{
if (_graphics.GraphicsDevice.PresentationParameters.BackBufferWidth != myWidth ||
_graphics.GraphicsDevice.PresentationParameters.BackBufferHeight != myHeight ||
set_fullscreen)
{
bool setUserResizing = myWindow.AllowUserResizing;
if (!_graphics.IsFullScreen && !setUserResizing)
{
myWindow.AllowUserResizing = true;
}
mLastWindowedBounds = myWindow.ClientBounds;
_graphics.PreferredBackBufferWidth = myWidth;
_graphics.PreferredBackBufferHeight = myHeight;
_graphics.ApplyChanges();
if (!_graphics.IsFullScreen && !setUserResizing)
{
myWindow.AllowUserResizing = false;
}
Console.WriteLine("This change in resolution!");
}
if (changeFullScreen != _graphics.IsFullScreen)
{
_graphics.IsFullScreen = changeFullScreen;
if (!_graphics.IsFullScreen)
{
myWidth = mLastWindowedBounds.Width;
myHeight = mLastWindowedBounds.Height;
Update(false);
}
Console.WriteLine("FullScreen is changed!");
}
}
public int set_Width
{
get {
return myWidth;
}
set {
myWidth = value;
}
}
public int set_Height
{
get {
return myHeight;
}
set {
myHeight = value;
}
}
public bool FullScreen
{
get {
return changeFullScreen;
}
set {
changeFullScreen = value;
if (changeFullScreen)
{
myWidth = _graphics.GraphicsDevice.DisplayMode.Width;
myHeight = _graphics.GraphicsDevice.DisplayMode.Height;
}
}
}
}
}