Go to the documentation of this file.00001 #region using statements
00002 using System;
00003 using System.Collections.Generic;
00004 using System.Linq;
00005 using Microsoft.Xna.Framework;
00006 using Microsoft.Xna.Framework.Audio;
00007 using Microsoft.Xna.Framework.Content;
00008 using Microsoft.Xna.Framework.GamerServices;
00009 using Microsoft.Xna.Framework.Graphics;
00010 using Microsoft.Xna.Framework.Input;
00011 using Microsoft.Xna.Framework.Media;
00012 using Microsoft.Xna.Framework.Net;
00013 using Microsoft.Xna.Framework.Storage;
00014 using visLU.Effects;
00015 using visLU.Gui;
00016 #endregion
00017
00018 namespace visLU
00019 {
00023 public class Game1 : Microsoft.Xna.Framework.Game
00024 {
00025
00026 #region variables
00027 GraphicsDeviceManager graphics;
00028 GraphicsDevice device;
00029
00030 SpriteBatch spriteBatch;
00031 KeyboardState lastKeyboardState;
00032
00033 MainWindow gui;
00034 IntPtr XNADrawSurface;
00035
00036 Engine engine;
00037
00038 int screenWidth;
00039 int screenHeight;
00040 #endregion
00041
00042 public Game1()
00043 {
00044
00045
00046 gui = new MainWindow();
00047 gui.Show();
00048 gui.setXNADrawSurfaceDimensions();
00049 XNADrawSurface = gui.getDrawSurface();
00050
00051 graphics = new GraphicsDeviceManager(this);
00052 Content.RootDirectory = "Content";
00053
00054
00055 if (!GameProperties.Instance.fullscreen)
00056 {
00057
00058 graphics.PreparingDeviceSettings += new EventHandler<PreparingDeviceSettingsEventArgs>(graphics_PreparingDeviceSettings);
00059 System.Windows.Forms.Control.FromHandle((this.Window.Handle)).VisibleChanged += new EventHandler(Game1_VisibleChanged);
00060 screenWidth = GameProperties.Instance.XNADrawSurfaceWidth;
00061 screenHeight = GameProperties.Instance.XNADrawSurfaceHeight;
00062
00063 }
00064
00065
00066
00067
00068
00069 graphics.PreferMultiSampling = true;
00070
00071
00072 Camera[] cameras = new Camera[4];
00073 cameras[0] = new InteractiveCamera(this);
00074 base.Components.Add(cameras[0]);
00075 for (int i = 1; i < 4; i++)
00076 {
00077 cameras[i] = new Camera(this);
00078 base.Components.Add(cameras[i]);
00079
00080 }
00081 this.Services.AddService(typeof(Camera[]), cameras);
00082
00083 engine = new Engine(this);
00084
00085 base.Components.Add(engine);
00086
00087 }
00088
00095 protected override void Initialize()
00096 {
00097 device = this.GraphicsDevice;
00098 setGraphicsDeviceManager();
00099
00100 spriteBatch = new SpriteBatch(GraphicsDevice);
00101 Services.AddService(typeof(SpriteBatch), spriteBatch);
00102
00103 base.Initialize();
00104
00105 }
00106
00111 protected override void LoadContent()
00112 {
00113
00114 spriteBatch = new SpriteBatch(GraphicsDevice);
00115
00116 base.LoadContent();
00117
00118 }
00119
00124 protected override void UnloadContent()
00125 {
00126
00127 }
00128
00134 protected override void Update(GameTime gameTime)
00135 {
00136 KeyboardState currentKeyboardState = Keyboard.GetState();
00137
00138
00139 if (currentKeyboardState.IsKeyDown(Keys.Escape) || GameProperties.Instance.exitGame)
00140 {
00141 this.Exit();
00142 System.Windows.Forms.Application.Exit();
00143 }
00144
00145
00146 if (GameProperties.Instance.updateGuiForm)
00147 {
00148 gui.updateSliceControls(GameProperties.Instance.xDataRange, GameProperties.Instance.yDataRange, GameProperties.Instance.zDataRange);
00149 GameProperties.Instance.updateGuiForm = false;
00150 }
00151 lastKeyboardState = currentKeyboardState;
00152 base.Update(gameTime);
00153 }
00154
00159 protected override void Draw(GameTime gameTime)
00160 {
00161
00162 base.Draw(gameTime);
00163 }
00164
00165 private void setGraphicsDeviceManager()
00166 {
00167 if (GameProperties.Instance.fullscreen)
00168 {
00169 graphics.PreferredBackBufferWidth = GraphicsDevice.DisplayMode.Width;
00170 graphics.PreferredBackBufferHeight = GraphicsDevice.DisplayMode.Height;
00171 graphics.ToggleFullScreen();
00172 graphics.IsFullScreen = true;
00173 GameProperties.Instance.fullscreenWidth = GraphicsDevice.DisplayMode.Width;
00174 GameProperties.Instance.fullscreenHeight = GraphicsDevice.DisplayMode.Height;
00175 }
00176 else
00177 {
00178 graphics.PreferredBackBufferWidth = screenWidth;
00179 graphics.PreferredBackBufferHeight = screenHeight;
00180 }
00181
00182 graphics.ApplyChanges();
00183
00184
00185 graphics.PreferMultiSampling = true;
00186
00187
00188 graphics.MinimumVertexShaderProfile = ShaderProfile.VS_2_0;
00189 graphics.MinimumPixelShaderProfile = ShaderProfile.PS_2_0;
00190
00191
00192
00193
00194 }
00195
00196
00197 #region event handler
00198 void graphics_PreparingDeviceSettings(object sender, PreparingDeviceSettingsEventArgs e)
00199 {
00200 e.GraphicsDeviceInformation.PresentationParameters.DeviceWindowHandle = XNADrawSurface;
00201
00202 }
00203 private void Game1_VisibleChanged(object sender, EventArgs e)
00204
00205 {
00206
00207 if (System.Windows.Forms.Control.FromHandle((this.Window.Handle)).Visible == true)
00208
00209 System.Windows.Forms.Control.FromHandle((this.Window.Handle)).Visible = false;
00210 }
00211
00212 #endregion
00213
00214 }
00215 }