/*
* GraphicsProfile.cs
* Authors: Karl Orosz
* Copyright (c) 2007-2008 Cornell University
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Util;
namespace tAC_Engine.Profile
{
///
/// This class will store and apply settings to the graphics device
///
class GraphicsProfile
{
#region Fields
// Whether or not the screen is in fullscreen mode
private bool mFullScreen;
// The resolution of the screen
private int[] mResolution = new int[2];
// Reference to the current gamescreen
private static GameScreen mGraphics;
//Stores the current
private static GraphicsProfile mCurrent;
//Stores the info for when the user is changing graphics settings.
//This can be tossed away if the user cancels out of the graphics option screen.
private static GraphicsProfile mChanged;
#endregion
#region Properties
///
/// Gets/Sets whether or not the game is in fullscreen mode
///
public static bool FullScreen
{
get
{
if (mChanged != null)
{
return mChanged.mFullScreen;
}
return mCurrent.mFullScreen;
}
set
{
if (mChanged != null)
{
mChanged.mFullScreen = value;
}
else
{
mCurrent.mFullScreen = value;
}
}
}
///
/// Gets/Sets the resolution of the screen
///
public static int[] Resolution
{
get
{
if (mChanged != null)
{
return mChanged.mResolution;
}
return mCurrent.mResolution;
}
set
{
if (mChanged != null)
{
mChanged.mResolution = value;
}
else
{
mCurrent.mResolution = value;
}
}
}
///
/// Gets the graphics device manager
///
public static GraphicsDeviceManager GraphicsDeviceManager { get { return mGraphics.GraphicsDeviceManager; } }
#endregion
#region Creation
///
/// Load default graphics settings.
/// todo: load them from a file
///
public GraphicsProfile()
{
ResetToDefaults();
}
///
/// Creates a copy of the passed graphics profile
///
/// The graphics profile to copy
public GraphicsProfile(GraphicsProfile copy)
{
this.mFullScreen = copy.mFullScreen;
mResolution = new int[2];
mResolution[0] = copy.mResolution[0];
mResolution[1] = copy.mResolution[1];
}
#endregion
#region Initialization
///
/// Sets up the graphics options for this profile
///
/// Reference to the current gamescreen
public static void Initialize(GameScreen g)
{
mGraphics = g;
mCurrent = new GraphicsProfile();
ApplyToDevice(mCurrent);
}
#endregion
#region Update Graphics
///
/// Applies any grahical changes to the graphics device
///
/// Changes in the graphics profile to be applied
public static void ApplyToDevice(GraphicsProfile toBeApplied)
{
GraphicsDeviceManager gdm = GraphicsDeviceManager;
if (gdm.IsFullScreen != toBeApplied.mFullScreen)
{
gdm.ToggleFullScreen();
}
gdm.PreferredBackBufferWidth = toBeApplied.mResolution[0];
gdm.PreferredBackBufferHeight = toBeApplied.mResolution[1];
gdm.ApplyChanges();
}
#endregion
#region Profile Management
///
/// Resets to the defulat values. Varies based on rlease and debug
///
public void ResetToDefaults()
{
#if DEBUG
mFullScreen = false;
#else
mFullScreen = true;
#endif
mResolution[0] = 1024;
mResolution[1] = 768;
}
///
/// Modifies the current graphics profile
///
public static void Modify()
{
mChanged = new GraphicsProfile(mCurrent);
}
///
/// Applies the changes that were made recently
///
public static void ApplyChanges()
{
ApplyToDevice(mChanged);
}
///
/// Saves all the changes that were made recently
///
public static void SaveChanges()
{
mCurrent = mChanged;
mChanged = null;
}
///
/// Cancels any changes that were made recently without saving
///
public static void CancelChanges()
{
mChanged = null;
ApplyToDevice(mCurrent);
}
#endregion
}
}