Esempio n. 1
0
        public void Move(GDI.RECT rcDest)
        {
            if (_clientRect == null)
            {
                GDI.RECT rect;
                WindowsManagement.GetClientRect(_hMediaWindow, out rect);
                _clientRect = rect;
            }

            if (_windowRect == null)
            {
                GDI.RECT rect;
                WindowsManagement.GetWindowRect(_hMediaWindow, out rect);
                _windowRect = rect;
            }

            if ((_clientRect.Value.right - _clientRect.Value.left) != (rcDest.right - rcDest.left) ||
                (_clientRect.Value.bottom - _clientRect.Value.top) != (rcDest.bottom - rcDest.top))
            {
                GDI.RECT rect;
                rect.left   = rect.top = 0;
                rect.right  = (rcDest.right - rcDest.left) + ((_windowRect.Value.right - _windowRect.Value.left) - (_clientRect.Value.right - _clientRect.Value.left));
                rect.bottom = (rcDest.bottom - rcDest.top) + ((_windowRect.Value.bottom - _windowRect.Value.top) - (_clientRect.Value.bottom - _clientRect.Value.top));

                if (WindowsManagement.MoveWindow(_hMediaWindow, rect.left, rect.top, rect.right, rect.bottom, false) != 0)
                {
                    _windowRect = rect;
                    _clientRect = rcDest;
                }
            }
        }
 public void Invalidate()
 {
     if (_hwnd != IntPtr.Zero)
     {
         GDI.RECT rcClient;
         WindowsManagement.GetClientRect(_hwnd, out rcClient);
         WindowsManagement.InvalidateRect(_hwnd, ref rcClient, false);
     }
 }
Esempio n. 3
0
        private void ResizeNormal(bool initial = false)
        {
            if (!initial && _engine.GraphState == GraphState.Reset)
            {
                return;
            }

            GDI.RECT rect;
            WindowsManagement.GetClientRect(Handle, out rect);
            int clientWidth  = rect.right - rect.left;
            int clientHeight = rect.bottom - rect.top;

            double w     = clientWidth;
            double h     = clientHeight;
            double ratio = w / h;
            double dAspectRatio;

            switch (_aspectRatio)
            {
            case AspectRatio.AR_ORIGINAL:
                dAspectRatio = _nativeAspectRatio;
                break;

            case AspectRatio.AR_16x9:
                dAspectRatio = 16.0 / 9.0;
                break;

            case AspectRatio.AR_4x3:
                dAspectRatio = 4.0 / 3.0;
                break;

            case AspectRatio.AR_47x20:
                dAspectRatio = 47.0 / 20.0;
                break;

            default:
            {
                // free aspect ratio
                _rcDest.left   = 0;
                _rcDest.top    = 0;
                _rcDest.right  = clientWidth;
                _rcDest.bottom = clientHeight;
                ApplyDestinationRect();
                return;
            }
            }

            int hor;
            int vert;

            if (_isFixed)
            {
                int fixedSize = (int)_fixedSize;
                if (ratio >= dAspectRatio)
                {
                    vert           = ((int)(_rcSrc.cy * fixedSize / _divideSize)) - clientHeight;
                    _rcDest.top    = (vert >= 0) ? 0 : -vert / 2;
                    _rcDest.bottom = (vert >= 0) ? clientHeight : _rcDest.top + ((int)(_rcSrc.cy * fixedSize / _divideSize));
                    h             = _rcDest.bottom - _rcDest.top;
                    w             = h * dAspectRatio;
                    hor           = clientWidth - (int)w;
                    _rcDest.left  = (hor <= 0) ? 0 : hor / 2;
                    _rcDest.right = _rcDest.left + (int)w;
                }
                else
                {
                    hor = ((int)(_rcSrc.cx * fixedSize / _divideSize)) - clientWidth;
                    // hor>=0 - client area is smaller than video hor size
                    _rcDest.left   = (hor >= 0) ? 0 : -hor / 2;
                    _rcDest.right  = (hor >= 0) ? clientWidth : _rcDest.left + ((int)(_rcSrc.cx * fixedSize / _divideSize));
                    w              = _rcDest.right - _rcDest.left;
                    h              = w / dAspectRatio;
                    vert           = clientHeight - (int)h;
                    _rcDest.top    = (vert <= 0) ? 0 : vert / 2;
                    _rcDest.bottom = _rcDest.top + (int)h;
                }
            }
            else
            {
                if (ratio >= dAspectRatio)
                {
                    _rcDest.top    = 0;
                    _rcDest.bottom = clientHeight;
                    h             = _rcDest.bottom - _rcDest.top;
                    w             = h * dAspectRatio;
                    hor           = clientWidth - (int)w;
                    _rcDest.left  = (hor <= 0) ? 0 : hor / 2;
                    _rcDest.right = _rcDest.left + (int)w;
                }
                else
                {
                    _rcDest.left   = 0;
                    _rcDest.right  = clientWidth;
                    w              = _rcDest.right - _rcDest.left;
                    h              = w / dAspectRatio;
                    vert           = clientHeight - (int)h;
                    _rcDest.top    = (vert <= 0) ? 0 : vert / 2;
                    _rcDest.bottom = _rcDest.top + (int)h;
                }
            }

            ApplyDestinationRect();
        }