Example #1
0
		/// <summary>
		/// Initializes a RenderWindow Instance
		/// </summary>
		/// <param name="name"></param>
		/// <param name="width"></param>
		/// <param name="height"></param>
		/// <param name="fullScreen"></param>
		/// <param name="miscParams"></param>
		public override void Create( string name, int width, int height, bool fullScreen, Axiom.Collections.NamedParameterList miscParams )
		{
			IntPtr parentHWnd = IntPtr.Zero;
			IntPtr externalHWnd = IntPtr.Zero;
			String title = name;
			int colourDepth = 32;
			int left = -1; // Defaults to screen center
			int top = -1; // Defaults to screen center
			bool depthBuffer = true;
			string border = "";
			bool outerSize = false;

			_useNVPerfHUD = false;
			_fsaaQuality = 0;
			_vSync = false;

			if ( miscParams != null )
			{
				// left (x)
				if ( miscParams.ContainsKey( "left" ) )
				{
					left = Int32.Parse( miscParams[ "left" ].ToString() );
				}

				// top (y)
				if ( miscParams.ContainsKey( "top" ) )
				{
					top = Int32.Parse( miscParams[ "top" ].ToString() );
				}

				// Window title
				if ( miscParams.ContainsKey( "title" ) )
				{
					title = (string)miscParams[ "title" ];
				}

#if !(XBOX || XBOX360 || SILVERLIGHT)
				// parentWindowHandle		-> parentHWnd
				if ( miscParams.ContainsKey( "parentWindowHandle" ) )
				{
					object handle = miscParams[ "parentWindowHandle" ];
					if ( handle.GetType() == typeof( IntPtr ) )
					{
						parentHWnd = (IntPtr)handle;
					}
					else if ( handle.GetType() == typeof( System.Int32 ) )
					{
						parentHWnd = new IntPtr( (int)handle );
					}
				}

				// externalWindowHandle		-> externalHWnd
				if ( miscParams.ContainsKey( "externalWindowHandle" ) )
				{
					object handle = miscParams[ "externalWindowHandle" ];
					if ( handle.GetType() == typeof( IntPtr ) )
					{
						externalHWnd = (IntPtr)handle;
					}
					else if ( handle.GetType() == typeof( System.Int32 ) )
					{
						externalHWnd = new IntPtr( (int)handle );
					}
				}
#endif
				// vsync	[parseBool]
				if ( miscParams.ContainsKey( "vsync" ) )
				{
					_vSync = bool.Parse( miscParams[ "vsync" ].ToString() );
				}

				// displayFrequency
				if ( miscParams.ContainsKey( "displayFrequency" ) )
				{
					_displayFrequency = Int32.Parse( miscParams[ "displayFrequency" ].ToString() );
				}

				// colourDepth
				if ( miscParams.ContainsKey( "colorDepth" ) )
				{
					colourDepth = Int32.Parse( miscParams[ "colorDepth" ].ToString() );
				}

				// depthBuffer [parseBool]
				if ( miscParams.ContainsKey( "depthBuffer" ) )
				{
					depthBuffer = bool.Parse( miscParams[ "depthBuffer" ].ToString() );
				}

                //FSAA type should hold a bool value, because anti-aliasing is either enabled, or it isn't.
                //// FSAA type
                //if ( miscParams.ContainsKey( "FSAA" ) )
                //{   
                //    //_fsaaType = (XFG.MultiSampleType)miscParams[ "FSAA" ];
                //}

				// FSAA quality
				if ( miscParams.ContainsKey( "FSAAQuality" ) )
				{
					_fsaaQuality = Int32.Parse( miscParams[ "FSAAQuality" ].ToString() );
				}

				// window border style
				if ( miscParams.ContainsKey( "border" ) )
				{
					border = ( (string)miscParams[ "border" ] ).ToLower();
				}

				// set outer dimensions?
				if ( miscParams.ContainsKey( "outerDimensions" ) )
				{
					outerSize = bool.Parse( miscParams[ "outerDimensions" ].ToString() );
				}

				// NV perf HUD?
				if ( miscParams.ContainsKey( "useNVPerfHUD" ) )
				{
					_useNVPerfHUD = bool.Parse( miscParams[ "useNVPerfHUD" ].ToString() );
				}
			}
#if !(XBOX || XBOX360 || SILVERLIGHT)
			if ( _windowHandle != IntPtr.Zero )
				Dispose();

			if ( externalHWnd == IntPtr.Zero )
			{
				Width = width;
				Height = height;
				this.top = top;
				this.left = left;

				_isExternal = false;
				DefaultForm newWin = new DefaultForm();
				newWin.Text = title;

				/* If we're in fullscreen, we can use the device's back and stencil buffers.
				 * If we're in windowed mode, we'll want our own.
				 * get references to the render target and depth stencil surface
				 */
				if ( !fullScreen )
				{
					newWin.StartPosition = SWF.FormStartPosition.CenterScreen;
					if ( parentHWnd != IntPtr.Zero )
					{
						newWin.Parent = SWF.Control.FromHandle( parentHWnd );
					}
					else
					{
						if ( border == "none" )
						{
							newWin.FormBorderStyle = SWF.FormBorderStyle.None;
						}
						else if ( border == "fixed" )
						{
							newWin.FormBorderStyle = SWF.FormBorderStyle.FixedSingle;
							newWin.MaximizeBox = false;
						}
					}

					if ( !outerSize )
					{
						newWin.ClientSize = new System.Drawing.Size( Width, Height );
					}
					else
					{
						newWin.Width = Width;
						newWin.Height = Height;
					}

					if ( top < 0 )
						top = ( SWF.Screen.PrimaryScreen.Bounds.Height - Height ) / 2;
					if ( left < 0 )
						left = ( SWF.Screen.PrimaryScreen.Bounds.Width - Width ) / 2;
				}
				else
				{
					//dwStyle |= WS_POPUP;
					top = left = 0;
				}

				// Create our main window
				newWin.Top = top;
				newWin.Left = left;

				newWin.RenderWindow = this;
				_windowHandle = newWin.Handle;

				WindowEventMonitor.Instance.RegisterWindow( this );
			}
			else
			{
				_windowHandle = externalHWnd;
				_isExternal = true;
			}
#endif

			// set the params of the window
			this.Name = name;
            this.ColorDepth = colourDepth;
			this.Width = width;
			this.Height = height;
			this.IsFullScreen = fullScreen;
			this.isDepthBuffered = depthBuffer;
			this.top = top;
			this.left = left;

			CreateXnaResources();

#if !(XBOX || XBOX360 || SILVERLIGHT)
			( SWF.Control.FromHandle( _windowHandle ) ).Show();
#endif

			IsActive = true;
			_isClosed = false;

			LogManager.Instance.Write( "[XNA] : Created D3D9 Rendering Window '{0}' : {1}x{2}, {3}bpp", Name, Width, Height, ColorDepth );
		}