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 visLU2.Effects;
00015 using visLU2.Gui;
00016 #endregion
00017
00018 namespace visLU2
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 #region gui
00047 gui = new MainWindow();
00048 gui.Show();
00049 gui.setXNADrawSurfaceDimensions();
00050 XNADrawSurface = gui.getDrawSurface();
00051 #endregion
00052
00053 graphics = new GraphicsDeviceManager(this);
00054 Content.RootDirectory = "Content";
00055
00056
00057 #region gui
00058
00059
00060
00061 graphics.PreparingDeviceSettings += new EventHandler<PreparingDeviceSettingsEventArgs>(graphics_PreparingDeviceSettings);
00062 System.Windows.Forms.Control.FromHandle((this.Window.Handle)).VisibleChanged += new EventHandler(Game1_VisibleChanged);
00063 screenWidth = GameProperties.Instance.XNADrawSurfaceWidth;
00064 screenHeight = GameProperties.Instance.XNADrawSurfaceHeight;
00065
00066
00067 #endregion
00068
00069
00070
00071
00072
00073 graphics.PreferMultiSampling = true;
00074
00075
00076 Camera[] cameras = new Camera[4];
00077 cameras[0] = new InteractiveCamera(this);
00078 base.Components.Add(cameras[0]);
00079 for (int i = 1; i < 4; i++)
00080 {
00081 cameras[i] = new Camera(this);
00082 base.Components.Add(cameras[i]);
00083
00084 }
00085 this.Services.AddService(typeof(Camera[]), cameras);
00086
00087 engine = new Engine(this);
00088
00089 base.Components.Add(engine);
00090
00091
00092
00093 }
00094
00101 protected override void Initialize()
00102 {
00103 device = this.GraphicsDevice;
00104 setGraphicsDeviceManager();
00105
00106 spriteBatch = new SpriteBatch(GraphicsDevice);
00107 Services.AddService(typeof(SpriteBatch), spriteBatch);
00108
00109 base.Initialize();
00110
00111 }
00112
00117 protected override void LoadContent()
00118 {
00119
00120 spriteBatch = new SpriteBatch(GraphicsDevice);
00121
00122 base.LoadContent();
00123
00124 }
00125
00130 protected override void UnloadContent()
00131 {
00132
00133 }
00134
00140 protected override void Update(GameTime gameTime)
00141 {
00142 KeyboardState currentKeyboardState = Keyboard.GetState();
00143
00144
00145 if (currentKeyboardState.IsKeyDown(Keys.Escape) || GameProperties.Instance.exitGame)
00146 {
00147 this.Exit();
00148 System.Windows.Forms.Application.Exit();
00149 }
00150
00151
00152 #region gui
00153 if (GameProperties.Instance.updateGuiForm)
00154 {
00155 gui.updateArrowPlotControl();
00156 gui.updateChannelControl(GameProperties.Instance.channelNames, GameProperties.Instance.currentChannelIdx);
00157 gui.updateStreamlineControl(GameProperties.Instance.maxLineLength);
00158 GameProperties.Instance.updateGuiForm = false;
00159 }
00160 #endregion
00161 lastKeyboardState = currentKeyboardState;
00162 base.Update(gameTime);
00163
00164 }
00165
00170 protected override void Draw(GameTime gameTime)
00171 {
00172
00173 base.Draw(gameTime);
00174 }
00175
00176 private void setGraphicsDeviceManager()
00177 {
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189 graphics.PreferredBackBufferWidth = screenWidth;
00190 graphics.PreferredBackBufferHeight = screenHeight;
00191
00192
00193 graphics.ApplyChanges();
00194
00195
00196 graphics.PreferMultiSampling = true;
00197
00198
00199 graphics.MinimumVertexShaderProfile = ShaderProfile.VS_2_0;
00200 graphics.MinimumPixelShaderProfile = ShaderProfile.PS_2_0;
00201
00202 GraphicsDevice.Clear(Color.Black);
00203
00204
00205
00206 }
00207
00208
00209 #region event handler
00210 void graphics_PreparingDeviceSettings(object sender, PreparingDeviceSettingsEventArgs e)
00211 {
00212 e.GraphicsDeviceInformation.PresentationParameters.DeviceWindowHandle = XNADrawSurface;
00213
00214 }
00215 private void Game1_VisibleChanged(object sender, EventArgs e)
00216
00217 {
00218
00219 if (System.Windows.Forms.Control.FromHandle((this.Window.Handle)).Visible == true)
00220
00221 System.Windows.Forms.Control.FromHandle((this.Window.Handle)).Visible = false;
00222 }
00223
00224 #endregion
00225
00226 }
00227 }