Inheritance: System.Windows.Forms.Form
		///<summary>
		///  Creates a default form to use for a rendering target.
		///</summary>
		///<remarks>
		///  This is used internally whenever <see cref = "Initialize" /> is called and autoCreateWindow is set to true.
		///</remarks>
		///<param name = "windowTitle">Title of the window.</param>
		///<param name = "top">Top position of the window.</param>
		///<param name = "left">Left position of the window.</param>
		///<param name = "width">Width of the window.</param>
		///<param name = "height">Height of the window</param>
		///<param name = "fullScreen">Prepare the form for fullscreen mode?</param>
		///<returns>A form suitable for using as a rendering target.</returns>
		private DefaultForm _createDefaultForm(string windowTitle, int top, int left, int width, int height,
												bool fullScreen)
		{
			var form = new DefaultForm();

			form.ClientSize = new Size(width, height);
			form.MaximizeBox = false;
			form.MinimizeBox = false;
			form.StartPosition = FormStartPosition.CenterScreen;

			if (fullScreen)
			{
				form.Top = 0;
				form.Left = 0;
				form.FormBorderStyle = FormBorderStyle.None;
				form.WindowState = FormWindowState.Maximized;
				form.TopMost = true;
				form.TopLevel = true;
			}
			else
			{
				form.Top = top;
				form.Left = left;
				form.FormBorderStyle = FormBorderStyle.FixedSingle;
				form.WindowState = FormWindowState.Normal;
				form.Text = windowTitle;
			}

			return form;
		}
Exemple #2
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 );
		}
Exemple #3
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, NamedParameterList miscParams)
        {
            var parentHWnd   = IntPtr.Zero;
            var externalHWnd = IntPtr.Zero;
            var title        = name;
            var colourDepth  = 32;
            var left         = -1;    // Defaults to screen center
            var top          = -1;    // Defaults to screen center
            var depthBuffer  = true;
            var border       = "";
            var 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 (miscParams.ContainsKey("xnaGraphicsDevice"))
                {
                    var graphics = miscParams["xnaGraphicsDevice"] as GraphicsDevice;
                    this.Driver.XnaDevice = graphics;
                }

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

                // externalWindowHandle		-> externalHWnd
                if (miscParams.ContainsKey("externalWindowHandle"))
                {
                    var handle = miscParams["externalWindowHandle"];
                    if (handle.GetType() == typeof(IntPtr))
                    {
                        externalHWnd = (IntPtr)handle;
                    }
                    else if (handle.GetType() == typeof(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 = (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 || WINDOWS_PHONE)
            if (_windowHandle != IntPtr.Zero)
            {
                Dispose();
            }

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

                _isExternal = false;
                var 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 = FormStartPosition.CenterScreen;
                    if (parentHWnd != IntPtr.Zero)
                    {
                        newWin.Parent = Control.FromHandle(parentHWnd);
                    }
                    else
                    {
                        if (border == "none")
                        {
                            newWin.FormBorderStyle = FormBorderStyle.None;
                        }
                        else if (border == "fixed")
                        {
                            newWin.FormBorderStyle = FormBorderStyle.FixedSingle;
                            newWin.MaximizeBox     = false;
                        }
                    }

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

                    if (top < 0)
                    {
                        top = (Screen.PrimaryScreen.Bounds.Height - Height) / 2;
                    }
                    if (left < 0)
                    {
                        left = (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;
            colorDepth      = colourDepth;
            this.width      = width;
            this.height     = height;
            IsFullScreen    = fullScreen;
            isDepthBuffered = depthBuffer;
            this.top        = top;
            this.left       = left;


            if (Driver.XnaDevice == null)
            {
                CreateXnaResources();
            }

#if !(XBOX || XBOX360 || SILVERLIGHT || WINDOWS_PHONE)
            (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);
        }