Exemplo n.º 1
0
 private static Rect GetIntersectionArea( ISpatialBinding binding, IDictionary<IWindowElement, Rect> setToChallenge, Rect rect, ref Rect enlargedRectangle, out IWindowElement otherWindow )
 {
     ICollection<IWindowElement> boundWindows = binding.AllDescendants().Select( x => x.Window ).ToArray();
     otherWindow = null;
     Rect rectWindow = setToChallenge[binding.Window];
     foreach( var item in setToChallenge )
     {
         otherWindow = item.Key;
         // If in all registered windows a window intersect with the one that moved
         if( otherWindow != binding.Window && !boundWindows.Contains( otherWindow ) )
         {
             rect = setToChallenge[otherWindow];
             if( !rectWindow.IntersectsWith( rect ) && rect.IntersectsWith( enlargedRectangle ) ) return Rect.Intersect( enlargedRectangle, rect );
         }
     }
     return Rect.Empty;
 }
Exemplo n.º 2
0
        public IBinding Test( ISpatialBinding binding, IDictionary<IWindowElement, Rect> setToChallenge, double radius )
        {
            if( _lock == true ) throw new ApplicationException( "You must check the state before perform a hit test" );

            Rect bindingRect = setToChallenge[binding.Window];

            ICollection<IWindowElement> boundWindows = binding.AllDescendants().Select( x => x.Window ).ToArray();
            IWindowElement otherWindow = null;

            Rect r = Rect.Empty;
            foreach( var item in setToChallenge )
            {
                otherWindow = item.Key;
                // If in all registered windows a window intersect with the one that moved
                if( otherWindow != binding.Window && !boundWindows.Contains( otherWindow ) )
                {
                    r = setToChallenge[otherWindow];
                    if( !r.IntersectsWith( bindingRect ) )
                    {
                        //TOP
                        Rect rectTop = new Rect( r.X, r.Y - radius, r.Width, radius );
                        //BOTTOM
                        Rect rectBot = new Rect( r.X, r.Y + r.Height, r.Width, radius );
                        //LEFT
                        Rect rectLeft = new Rect( r.X - radius, r.Y, radius, r.Height );
                        //RIGHT
                        Rect rectRight = new Rect( r.X + r.Width, r.Y, radius, r.Height );
                        if( rectTop.IntersectsWith( bindingRect ) )
                        {
                            _lastResult = new HitTestResult( binding.Window, otherWindow, BindingPosition.Top );
                            return _lastResult;
                        }
                        else if( rectBot.IntersectsWith( bindingRect ) )
                        {
                            _lastResult = new HitTestResult( binding.Window, otherWindow, BindingPosition.Bottom );
                            return _lastResult;
                        }
                        else if( rectLeft.IntersectsWith( bindingRect ) )
                        {
                            _lastResult = new HitTestResult( binding.Window, otherWindow, BindingPosition.Left );
                            return _lastResult;
                        }
                        else if( rectRight.IntersectsWith( bindingRect ) )
                        {
                            _lastResult = new HitTestResult( binding.Window, otherWindow, BindingPosition.Right );
                            return _lastResult;
                        }
                    }
                }
            }
            //RegionHelper region = CreateRegion( rect, radius );

            //IWindowElement matchedWindow = null;
            //Rect intersectArea = GetIntersectionArea( binding, setToChallenge,  rect, ref enlargedArea, out matchedWindow );
            //if( intersectArea != Rect.Empty )
            //{
            //    Debug.Assert( matchedWindow != null );
            //    _lastResult = new HitTestResult( matchedWindow, binding.Window, enlargedArea, intersectArea );
            //    return _lastResult;
            //}
            return null;
        }
        void ResizingWindow( ISpatialBinding binding, BindingPosition masterPosition = BindingPosition.None )
        {
            Debug.Assert( Dispatcher.CurrentDispatcher == Application.Current.Dispatcher, "This method should only be called by the ExternalThread." );

            IWindowElement reference = binding.Window;
            IWindowElement slave = null;

            if( masterPosition != BindingPosition.Top && binding.Top != null )
            {
                slave = binding.Top.Window;
                if( reference.Height != slave.Height )
                {
                    WindowManager.Resize( slave, reference.Width, slave.Height );
                    ResizingWindow( binding.Top, BindingPosition.Bottom );
                }
                WindowManager.Move( slave, reference.Top - slave.Height, reference.Left );
            }
            if( masterPosition != BindingPosition.Bottom && binding.Bottom != null )
            {
                slave = binding.Bottom.Window;
                if( reference.Height != slave.Height )
                {
                    WindowManager.Resize( slave, reference.Width, slave.Height );
                    ResizingWindow( binding.Bottom, BindingPosition.Top );
                }
                WindowManager.Move( slave, reference.Top + reference.Height, reference.Left );
            }
            if( masterPosition != BindingPosition.Left && binding.Left != null )
            {
                slave = binding.Left.Window;
                if( reference.Width != slave.Width )
                {
                    WindowManager.Resize( slave, slave.Width, reference.Height );
                    ResizingWindow( binding.Left, BindingPosition.Right );
                }
                WindowManager.Move( slave, reference.Top, reference.Left - slave.Width );
            }
            if( masterPosition != BindingPosition.Right && binding.Right != null )
            {
                slave = binding.Right.Window;
                if( reference.Width != slave.Width )
                {
                    WindowManager.Resize( slave, slave.Width, reference.Height );
                    ResizingWindow( binding.Right, BindingPosition.Left );
                }
                WindowManager.Move( slave, reference.Top, reference.Left + reference.Width );
            }
        }