public override PointHitTestResult HitTestPoint(VisualHitTestArgs args)
 {
     if (args.ChildLayoutBounds.Contains(args.ChildPoint))
     {
         return(new PointHitTestResult(args.ChildVisual, args.ChildPoint));
     }
     return((PointHitTestResult)null);
 }
        public override GeometryHitTestResult HitTestGeometry(VisualHitTestArgs args)
        {
            Rect rect   = TransformUtil.GetTransformToAncestor((DependencyObject)args.ChildVisual, args.SourceAncestor).TransformBounds(args.ChildLayoutBounds);
            Rect bounds = args.SourceHitGeometry.Bounds;

            if (args.SourceHitGeometry.FillContains((Geometry) new RectangleGeometry(rect)))
            {
                return(new GeometryHitTestResult(args.ChildVisual, IntersectionDetail.FullyInside));
            }
            if (rect.Contains(bounds))
            {
                return(new GeometryHitTestResult(args.ChildVisual, IntersectionDetail.FullyContains));
            }
            if (bounds.IntersectsWith(rect))
            {
                return(new GeometryHitTestResult(args.ChildVisual, IntersectionDetail.Intersects));
            }
            return(new GeometryHitTestResult(args.ChildVisual, IntersectionDetail.Empty));
        }
Esempio n. 3
0
 public virtual PointHitTestResult HitTestPoint(VisualHitTestArgs args)
 {
     return((PointHitTestResult)null);
 }
Esempio n. 4
0
 public virtual GeometryHitTestResult HitTestGeometry(VisualHitTestArgs args)
 {
     return(new GeometryHitTestResult(args.ChildVisual, IntersectionDetail.NotCalculated));
 }
Esempio n. 5
0
        public static HitTestResult HitTest(Visual root, HitTestFilterCallback filterCallback, HitTestResultCallback resultCallback, HitTestParameters hitTestParameters, HitTestFilterCallback modelCallback)
        {
            ModelHitTestHelper.HitTestFilterCallbackWrapper filterCallbackWrapper = new ModelHitTestHelper.HitTestFilterCallbackWrapper(filterCallback);
            ModelHitTestHelper.HitTestResultCallbackWrapper resultCallbackWrapper = new ModelHitTestHelper.HitTestResultCallbackWrapper(resultCallback, HitTestResultBehavior.Continue);
            VisualTreeHelper.HitTest(root, filterCallbackWrapper.FilterCallback, resultCallbackWrapper.ResultCallback, hitTestParameters);
            HitTestResult             topMostHit         = resultCallbackWrapper.TopMostHit;
            bool                      flag               = filterCallback == null && resultCallback == null;
            VisualHitTestArgs         args               = new VisualHitTestArgs(root, root, hitTestParameters);
            PointHitTestParameters    hitTestParameters1 = hitTestParameters as PointHitTestParameters;
            GeometryHitTestParameters hitTestParameters2 = hitTestParameters as GeometryHitTestParameters;

            foreach (DependencyObject dependencyObject in ModelHitTestHelper.GetDescendantsInZOrder((DependencyObject)root))
            {
                if (dependencyObject != null)
                {
                    if (filterCallback == null && topMostHit != null && dependencyObject == topMostHit.VisualHit)
                    {
                        resultCallbackWrapper.PlayResults();
                        return(resultCallbackWrapper.TopMostHit);
                    }
                    Visual          visual            = dependencyObject as Visual;
                    HitTestProvider singletonProvider = ModelHitTestHelper.GetSingletonProvider(dependencyObject);
                    if (singletonProvider != null && (modelCallback == null || modelCallback((DependencyObject)visual) != HitTestFilterBehavior.Continue))
                    {
                        args.UpdateChild(dependencyObject);
                        HitTestResult result = (HitTestResult)null;
                        if (hitTestParameters1 != null && visual != null)
                        {
                            PointHitTestResult pointHitTestResult = singletonProvider.HitTestPoint(args);
                            if (pointHitTestResult != null && pointHitTestResult.VisualHit != null)
                            {
                                result = (HitTestResult)pointHitTestResult;
                            }
                        }
                        else if (hitTestParameters2 != null && visual != null)
                        {
                            GeometryHitTestResult geometryHitTestResult = singletonProvider.HitTestGeometry(args);
                            if (geometryHitTestResult != null && geometryHitTestResult.IntersectionDetail != IntersectionDetail.Empty && geometryHitTestResult.IntersectionDetail != IntersectionDetail.NotCalculated)
                            {
                                result = (HitTestResult)geometryHitTestResult;
                            }
                        }
                        if (result != null)
                        {
                            HitTestFilterBehavior testFilterBehavior = filterCallbackWrapper.FilterCallback(dependencyObject);
                            switch (testFilterBehavior)
                            {
                            case HitTestFilterBehavior.Continue:
                            case HitTestFilterBehavior.Stop:
                                resultCallbackWrapper.InsertResult(result);
                                break;
                            }
                            if (flag && testFilterBehavior != HitTestFilterBehavior.ContinueSkipSelf || testFilterBehavior == HitTestFilterBehavior.Stop)
                            {
                                resultCallbackWrapper.PlayResults();
                                return(result);
                            }
                        }
                    }
                }
            }
            resultCallbackWrapper.PlayResults();
            return(resultCallbackWrapper.TopMostHit);
        }