Example #1
0
        public DefaultForm(WindowClassStyle classStyle, WindowsExtendedStyle dwStyleEx, string title,
                           WindowStyles windowStyle, int left, int top, int winWidth, int winHeight, Control parentHWnd)
        {
            this._classStyle  = classStyle;
            this._dwStyleEx   = dwStyleEx;
            this._windowStyle = windowStyle;
            this.Text         = title;

            SuspendLayout();

            BackColor = Color.Black;
            Name      = title;
            Left      = left;
            Top       = top;
            Width     = winWidth;
            Height    = winHeight;
            if (parentHWnd != null)
            {
                Parent = parentHWnd;
            }

            Load       += _defaultFormLoad;
            Deactivate += _defaultFormDeactivate;
            Activated  += _defaultFormActivated;
            Closing    += _defaultFormClose;
            Resize     += _defaultFormResize;
            Cursor.Hide();

            ResumeLayout(false);
        }
Example #2
0
	    public DefaultForm( WindowClassStyle classStyle, WindowsExtendedStyle dwStyleEx, string title, 
            WindowStyles windowStyle, int left, int top, int winWidth, int winHeight, Control parentHWnd )
	    {
	        _classStyle = classStyle;
	        _dwStyleEx = dwStyleEx;
	        _windowStyle = windowStyle;

	        SuspendLayout();
           
            AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            BackColor = System.Drawing.Color.Black;
            ClientSize = new System.Drawing.Size(640, 480);
            Name = title;
	        Left = left;
	        Top = top;
	        Width = winWidth;
	        Height = winHeight;
            if (parentHWnd != null)
	            Parent = parentHWnd;

            Load += DefaultFormLoad;
            Deactivate += DefaultFormDeactivate;
            Activated += DefaultFormActivated;
            Closing += DefaultFormClose;
            Resize += DefaultFormResize;

            ResumeLayout(false);
	    }
Example #3
0
        public override void Create(string name, int width, int height, bool fullScreen, NamedParameterList miscParams)
        {
            SWF.Control parentHWnd   = null;
            SWF.Control externalHWnd = null;
            this._fsaaType    = D3D9.MultisampleType.None;
            this._fsaaQuality = 0;
            fsaa                = 0;
            this._vSync         = false;
            this._vSyncInterval = 1;
            var title             = name;
            var colorDepth        = 32;
            var left              = int.MaxValue; // Defaults to screen center
            var top               = int.MaxValue; // Defaults to screen center
            var depthBuffer       = true;
            var border            = "";
            var outerSize         = false;
            var enableDoubleClick = false;

            this._useNVPerfHUD = false;
            //var fsaaSamples = 0; //Not used, even in Ogre
            var fsaaHint     = string.Empty;
            var monitorIndex = -1;

            if (miscParams != null)
            {
                object opt;

                // left (x)
                if (miscParams.TryGetValue("left", out opt))
                {
                    left = Int32.Parse(opt.ToString());
                }

                // top (y)
                if (miscParams.TryGetValue("top", out opt))
                {
                    top = Int32.Parse(opt.ToString());
                }

                // Window title
                if (miscParams.TryGetValue("title", out opt))
                {
                    title = (string)opt;
                }

                // parentWindowHandle		-> parentHWnd
                if (miscParams.TryGetValue("parentWindowHandle", out opt))
                {
                    // This is Axiom specific
                    var handle = opt;
                    var ptr    = IntPtr.Zero;
                    if (handle.GetType() == typeof(IntPtr))
                    {
                        ptr = (IntPtr)handle;
                    }
                    else if (handle.GetType() == typeof(Int32))
                    {
                        ptr = new IntPtr((int)handle);
                    }
                    else
                    {
                        throw new AxiomException("unhandled parentWindowHandle type");
                    }

                    parentHWnd = SWF.Control.FromHandle(ptr);
                }

                // externalWindowHandle		-> externalHWnd
                if (miscParams.TryGetValue("externalWindowHandle", out opt))
                {
                    // This is Axiom specific
                    var handle = opt;
                    var ptr    = IntPtr.Zero;
                    if (handle.GetType() == typeof(IntPtr))
                    {
                        ptr = (IntPtr)handle;
                    }
                    else if (handle.GetType() == typeof(Int32))
                    {
                        ptr = new IntPtr((int)handle);
                    }
                    else
                    {
                        throw new AxiomException("unhandled externalWindowHandle type");
                    }

                    externalHWnd = SWF.Control.FromHandle(ptr);
                }

                // vsync	[parseBool]
                if (miscParams.TryGetValue("vsync", out opt))
                {
                    this._vSync = bool.Parse(opt.ToString());
                }

                // vsyncInterval	[parseUnsignedInt]
                if (miscParams.TryGetValue("vsyncInterval", out opt))
                {
                    this._vSyncInterval = Int32.Parse(opt.ToString());
                }

                // displayFrequency
                if (miscParams.TryGetValue("displayFrequency", out opt))
                {
                    this._displayFrequency = Int32.Parse(opt.ToString());
                }

                // colorDepth
                if (miscParams.TryGetValue("colorDepth", out opt))
                {
                    colorDepth = Int32.Parse(opt.ToString());
                }

                // depthBuffer [parseBool]
                if (miscParams.TryGetValue("depthBuffer", out opt))
                {
                    depthBuffer = bool.Parse(opt.ToString());
                }

                //FSAA settings

                // FSAA type
                if (miscParams.TryGetValue("FSAA", out opt))
                {
                    this._fsaaType = (D3D9.MultisampleType)opt;
                }

                if (miscParams.TryGetValue("FSAAHint", out opt))
                {
                    fsaaHint = (string)opt;
                }

                // window border style
                if (miscParams.TryGetValue("border", out opt))
                {
                    border = ((string)opt).ToLower();
                }

                // set outer dimensions?
                if (miscParams.TryGetValue("outerDimensions", out opt))
                {
                    outerSize = bool.Parse(opt.ToString());
                }

                // NV perf HUD?
                if (miscParams.TryGetValue("useNVPerfHUD", out opt))
                {
                    this._useNVPerfHUD = bool.Parse(opt.ToString());
                }

                // sRGB?
                if (miscParams.TryGetValue("gamma", out opt))
                {
                    hwGamma = bool.Parse(opt.ToString());
                }

                // monitor index
                if (miscParams.TryGetValue("monitorIndex", out opt))
                {
                    monitorIndex = Int32.Parse(opt.ToString());
                }

                // enable double click messages
                if (miscParams.TryGetValue("enableDoubleClick", out opt))
                {
                    enableDoubleClick = bool.Parse(opt.ToString());
                }
            }

            // Destroy current window if any
            if (this._windowHandle != null)
            {
                Destroy();
            }

            if (externalHWnd == null)
            {
                var  dwStyle       = WindowStyles.WS_VISIBLE | WindowStyles.WS_CLIPCHILDREN;
                var  dwStyleEx     = (WindowsExtendedStyle)0;
                var  monitorHandle = IntPtr.Zero;
                RECT rc;

                // If we specified which adapter we want to use - find it's monitor.
                if (monitorIndex != -1)
                {
                    var direct3D9 = D3D9RenderSystem.Direct3D9;

                    for (var i = 0; i < direct3D9.AdapterCount; ++i)
                    {
                        if (i != monitorIndex)
                        {
                            continue;
                        }

                        monitorHandle = direct3D9.GetAdapterMonitor(i);
                        break;
                    }
                }

                // If we didn't specified the adapter index, or if it didn't find it
                if (monitorHandle == IntPtr.Zero)
                {
                    // Fill in anchor point.
                    var windowAnchorPoint = new Point(left, top);

                    // Get the nearest monitor to this window.
                    monitorHandle = ScreenHelper.GetHandle(windowAnchorPoint);
                }

                // Get the target monitor info
                var monitorInfo = ScreenHelper.FromHandle(monitorHandle);

                var winWidth  = width;
                var winHeight = height;

                // No specified top left -> Center the window in the middle of the monitor
                if (left == int.MaxValue || top == int.MaxValue)
                {
                    var screenw = monitorInfo.WorkingArea.Right - monitorInfo.WorkingArea.Left;
                    var screenh = monitorInfo.WorkingArea.Bottom - monitorInfo.WorkingArea.Top;

                    // clamp window dimensions to screen size
                    var outerw = (winWidth < screenw) ? winWidth : screenw;
                    var outerh = (winHeight < screenh) ? winHeight : screenh;

                    if (left == int.MaxValue)
                    {
                        left = monitorInfo.WorkingArea.Left + (screenw - outerw) / 2;
                    }
                    else if (monitorIndex != -1)
                    {
                        left += monitorInfo.WorkingArea.Left;
                    }

                    if (top == int.MaxValue)
                    {
                        top = monitorInfo.WorkingArea.Top + (screenh - outerh) / 2;
                    }
                    else if (monitorIndex != -1)
                    {
                        top += monitorInfo.WorkingArea.Top;
                    }
                }
                else if (monitorIndex != -1)
                {
                    left += monitorInfo.WorkingArea.Left;
                    top  += monitorInfo.WorkingArea.Top;
                }

                this.width  = this._desiredWidth = width;
                this.height = this._desiredHeight = height;
                this.top    = top;
                this.left   = left;

                if (fullScreen)
                {
                    dwStyleEx |= WindowsExtendedStyle.WS_EX_TOPMOST;
                    dwStyle   |= WindowStyles.WS_POPUP;
                    this.top   = monitorInfo.Bounds.Top;
                    this.left  = monitorInfo.Bounds.Left;
                }
                else
                {
                    if (parentHWnd != null)
                    {
                        dwStyle |= WindowStyles.WS_CHILD;
                    }
                    else
                    {
                        if (border == "none")
                        {
                            dwStyle |= WindowStyles.WS_POPUP;
                        }
                        else if (border == "fixed")
                        {
                            dwStyle |= WindowStyles.WS_OVERLAPPED | WindowStyles.WS_BORDER | WindowStyles.WS_CAPTION |
                                       WindowStyles.WS_SYSMENU | WindowStyles.WS_MINIMIZEBOX;
                        }
                        else
                        {
                            dwStyle |= WindowStyles.WS_OVERLAPPEDWINDOW;
                        }
                    }

                    AdjustWindow(width, height, dwStyle, out winWidth, out winHeight);

                    if (!outerSize)
                    {
                        // Calculate window dimensions required
                        // to get the requested client area
                        rc = new RECT(0, 0, this.width, this.height);
                        AdjustWindowRect(ref rc, dwStyle, false);
                        this.width  = rc.Right - rc.Left;
                        this.height = rc.Bottom - rc.Top;

                        // Clamp window rect to the nearest display monitor.
                        if (this.left < monitorInfo.WorkingArea.Left)
                        {
                            this.left = monitorInfo.WorkingArea.Left;
                        }

                        if (this.top < monitorInfo.WorkingArea.Top)
                        {
                            this.top = monitorInfo.WorkingArea.Top;
                        }

                        if (winWidth > monitorInfo.WorkingArea.Right - this.left)
                        {
                            winWidth = monitorInfo.WorkingArea.Right - this.left;
                        }

                        if (winHeight > monitorInfo.WorkingArea.Bottom - this.top)
                        {
                            winHeight = monitorInfo.WorkingArea.Bottom - this.top;
                        }
                    }
                }

                WindowClassStyle classStyle = 0;
                if (enableDoubleClick)
                {
                    classStyle |= WindowClassStyle.CS_DBLCLKS;
                }

                // Create our main window
                this._isExternal = false;
                var wnd = new DefaultForm(classStyle, dwStyleEx, title, dwStyle, this.left, this.top, winWidth, winHeight,
                                          parentHWnd);
                wnd.RenderWindow   = this;
                this._windowHandle = wnd;
                this._style        = dwStyle;
                WindowEventMonitor.Instance.RegisterWindow(this);
            }
            else
            {
                this._windowHandle = externalHWnd;
                this._isExternal   = true;
            }

            // top and left represent outer window coordinates
            var rc2 = new System.Drawing.Rectangle(this._windowHandle.Location, this._windowHandle.Size);

            this.top  = rc2.Top;
            this.left = rc2.Left;

            // width and height represent interior drawable area
            rc2 = this._windowHandle.ClientRectangle;

            this.width  = rc2.Right;
            this.height = rc2.Bottom;

            this.name       = name;
            isDepthBuffered = depthBuffer;
            isFullScreen    = fullScreen;
            this.colorDepth = colorDepth;

            LogManager.Instance.Write("D3D9 : Created D3D9 Rendering Window '{0}' : {1}x{2}, {3}bpp", this.name, this.width,
                                      this.height, ColorDepth);

            active         = true;
            this._isClosed = false;
        }
Example #4
0
		public DefaultForm( WindowClassStyle classStyle, WindowsExtendedStyle dwStyleEx, string title,
		                    WindowStyles windowStyle, int left, int top, int winWidth, int winHeight, Control parentHWnd )
		{
			this._classStyle = classStyle;
			this._dwStyleEx = dwStyleEx;
			this._windowStyle = windowStyle;

			SuspendLayout();

			BackColor = Color.Black;
			Name = title;
			Left = left;
			Top = top;
			Width = winWidth;
			Height = winHeight;
			if ( parentHWnd != null )
			{
				Parent = parentHWnd;
			}

			Load += _defaultFormLoad;
			Deactivate += _defaultFormDeactivate;
			Activated += _defaultFormActivated;
			Closing += _defaultFormClose;
			Resize += _defaultFormResize;
			Cursor.Hide();

			ResumeLayout( false );
		}