Ejemplo n.º 1
0
        public void AdjustWindow(int clientWidth, int clientHeight, WindowStyles style, out int winWidth, out int winHeight)
        {
            // NB only call this for non full screen
            var rc = new RECT(0, 0, clientWidth, clientHeight);

            AdjustWindowRect(ref rc, style, false);

            winWidth  = rc.Right - rc.Left;
            winHeight = rc.Bottom - rc.Top;

            // adjust to monitor
            var handle = this._windowHandle != null ? this._windowHandle.Handle : IntPtr.Zero;

            // Get monitor info
            var monitorInfo = ScreenHelper.FromHandle(handle);

            var maxW = monitorInfo.WorkingArea.Right - monitorInfo.WorkingArea.Left;
            var maxH = monitorInfo.WorkingArea.Bottom - monitorInfo.WorkingArea.Top;

            if (winWidth > maxW)
            {
                winWidth = maxW;
            }
            if (winHeight > maxH)
            {
                winHeight = maxH;
            }
        }
Ejemplo n.º 2
0
        internal void FinishSwitchingFullscreen()
        {
            if (isFullScreen)
            {
                // Need to reset the region on the window sometimes, when the
                // windowed mode was constrained by desktop
                ((DefaultForm)this._windowHandle).Region = new Region(new System.Drawing.Rectangle(0, 0, width, height));
            }
            else
            {
                // When switching back to windowed mode, need to reset window size
                // after device has been restored
                // We may have had a resize event which polluted our desired sizes
                int winWidth, winHeight;
                AdjustWindow(this._desiredWidth, this._desiredHeight, this._style, out winWidth, out winHeight);

                // deal with centering when switching down to smaller resolution
                var handle      = this._windowHandle != null ? this._windowHandle.Handle : IntPtr.Zero;
                var monitorInfo = ScreenHelper.FromHandle(handle);

                var screenw = monitorInfo.WorkingArea.Right - monitorInfo.WorkingArea.Left;
                var screenh = monitorInfo.WorkingArea.Bottom - monitorInfo.WorkingArea.Top;

                var left = screenw > winWidth ? ((screenw - winWidth) / 2) : 0;
                var top  = screenh > winHeight ? ((screenh - winHeight) / 2) : 0;
                ((DefaultForm)this._windowHandle).TopMost = false;
                ((DefaultForm)this._windowHandle).SetBounds(left, top, winWidth, winHeight);

                //TODO check the above statement with the following one
                //SetWindowPos(mHWnd, HWND_NOTOPMOST, left, top, winWidth, winHeight,
                // SWP_DRAWFRAME | SWP_FRAMECHANGED | SWP_NOACTIVATE);

                if (width != this._desiredWidth || height != this._desiredHeight)
                {
                    width  = this._desiredWidth;
                    height = this._desiredHeight;
                    // Notify viewports of resize
                    foreach (var it in ViewportList.Values)
                    {
                        it.UpdateDimensions();
                    }
                }
            }

            this._switchingFullScreen = false;
        }
Ejemplo n.º 3
0
        private void SetPlacement()
        {
            switch (Placement)
            {
            case ChatHeadFlyoutPlacement.Left:
                Left = 0;
                break;

            case ChatHeadFlyoutPlacement.Right:
            {
                var handle = new WindowInteropHelper(this).Handle;
                var screen = ScreenHelper.FromHandle(handle);

                var workingArea = screen.WorkingArea;

                Left = workingArea.Right - Width;
                break;
            }
            }
        }
Ejemplo n.º 4
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;
        }