コード例 #1
0
ファイル: CardScroller.cs プロジェクト: jonbonne/OCTGN
 protected override GeometryHitTestResult HitTestCore
         (GeometryHitTestParameters hitTestParameters)
 {
     var geometry = new RectangleGeometry(VisualTreeHelper.GetDescendantBounds(this));
     return new GeometryHitTestResult
      (this, geometry.FillContainsWithDetail(hitTestParameters.HitGeometry));
 }
コード例 #2
0
ファイル: MagicLens.cs プロジェクト: prgoodwin/HabilisX
 public override bool AreBoundaryIntersecting(FrameworkElement cursorVisual)
 {
    RectangleGeometry cursorBounds =
        new RectangleGeometry(new Rect(0, 0, cursorVisual.ActualWidth, cursorVisual.ActualHeight));
    RectangleGeometry targetBounds =
        new RectangleGeometry(new Rect(0, 0, this.ActualWidth, this.ActualHeight));
    cursorBounds.Transform = (Transform)cursorVisual.TransformToVisual(this);
    return cursorBounds.FillContainsWithDetail(targetBounds) != IntersectionDetail.Empty;
 }
コード例 #3
0
ファイル: Ruler.cs プロジェクト: prgoodwin/HabilisX
 public override bool AreBoundaryIntersecting(FrameworkElement item)
 {
    RectangleGeometry itemBounds =
        new RectangleGeometry(new Rect(0, 0, item.ActualWidth, item.ActualHeight));
    RectangleGeometry rulerBounds =
        new RectangleGeometry(new Rect(0, 0, this.ActualWidth, this.ActualHeight));
    itemBounds.Transform = (Transform)item.TransformToVisual(this);
    return itemBounds.FillContainsWithDetail(rulerBounds) != IntersectionDetail.Empty;
 }
コード例 #4
0
ファイル: Ruler.cs プロジェクト: prgoodwin/HabilisX
      public int BoundaryIntersectingOnSide(FrameworkElement cursorVisual)
      {
         RectangleGeometry cursorBounds =
             new RectangleGeometry(new Rect(0, 0, cursorVisual.ActualWidth, cursorVisual.ActualHeight));
         RectangleGeometry targetBoundsTop =
             new RectangleGeometry(new Rect(0, 0, this.ActualWidth, 1));
         RectangleGeometry targetBoundsBottom =
             new RectangleGeometry(new Rect(0, this.ActualHeight-1, this.ActualWidth, 1));
         RectangleGeometry targetBoundsLeft =
             new RectangleGeometry(new Rect(0, 5, 1, this.ActualHeight-10));
         RectangleGeometry targetBoundsRight =
             new RectangleGeometry(new Rect(this.ActualWidth - 1, 5, 1, this.ActualHeight-10));


         cursorBounds.Transform = (Transform)cursorVisual.TransformToVisual(this);


         if (cursorBounds.FillContainsWithDetail(targetBoundsLeft) != IntersectionDetail.Empty)
         {
             Console.WriteLine("FOUND A LEFT");
            return LEFT;
         }
         else if (cursorBounds.FillContainsWithDetail(targetBoundsRight) != IntersectionDetail.Empty)
         {
             Console.WriteLine("FOUND A RIGHT");
            return RIGHT;
         }
         else if(cursorBounds.FillContainsWithDetail(targetBoundsTop) != IntersectionDetail.Empty)
         {
             Console.WriteLine("FOUND A TOP");
            return TOP;
         }
         else //if (cursorBounds.FillContainsWithDetail(targetBoundsBottom) != IntersectionDetail.Empty)
         {
             Console.WriteLine("FOUND A BOTTOM");
            return BOTTOM;
         }


      }
コード例 #5
0
ファイル: PushPin.cs プロジェクト: prgoodwin/HabilisX
      public override bool AreBoundaryIntersecting(FrameworkElement cursorVisual)
      {
         try
         {
            RectangleGeometry cursorBounds =
             new RectangleGeometry(new Rect(10,10, cursorVisual.ActualWidth-20, cursorVisual.ActualHeight-20));
            RectangleGeometry targetBounds =
                new RectangleGeometry(new Rect((this.ActualWidth / 4), (2 * this.ActualHeight / 3), 1, 1));
            cursorBounds.Transform = (Transform)cursorVisual.TransformToVisual(this);

            return cursorBounds.FillContainsWithDetail(targetBounds) != IntersectionDetail.Empty;
         }
         catch (Exception e) {
            Console.WriteLine("Found exception: " + e);
            return false;
         }
      }
コード例 #6
0
        /// <summary>
        /// HitTestCore implements whether we have hit the bounds of this visual.
        /// </summary>
        protected virtual GeometryHitTestResult HitTestCore(GeometryHitTestParameters hitTestParameters)
        {
            if (hitTestParameters == null)
            {
                throw new ArgumentNullException("hitTestParameters");
            }

            IntersectionDetail intersectionDetail;

            RectangleGeometry contentGeometry = new RectangleGeometry(GetHitTestBounds());

            intersectionDetail = contentGeometry.FillContainsWithDetail(hitTestParameters.InternalHitGeometry);
            Debug.Assert(intersectionDetail != IntersectionDetail.NotCalculated);

            if (intersectionDetail != IntersectionDetail.Empty)
            {
                return new GeometryHitTestResult(this, intersectionDetail);
            }


            return null;
        }
コード例 #7
0
        internal HitTestResultBehavior HitTestGeometry(
            HitTestFilterCallback filterCallback,
            HitTestResultCallback resultCallback,
            GeometryHitTestParameters geometryParams)
        {
            // we do not need parameter checks because they are done in HitTest()
            Geometry clip = VisualClip;
            if (clip != null)
            {
                // HitTest with a Geometry and a clip should hit test with
                // the intersection of the geometry and the clip, not the entire geometry
                IntersectionDetail intersectionDetail = clip.FillContainsWithDetail(geometryParams.InternalHitGeometry);
                
                Debug.Assert(intersectionDetail != IntersectionDetail.NotCalculated);
                if (intersectionDetail == IntersectionDetail.Empty)
                {
                    // bail out if there is a clip and this region is not inside
                    return HitTestResultBehavior.Continue;
                }
            }
            
            //
            // Check if the geometry intersects with our hittest bounds.
            // If not, the Visual is not hit-testable at all.

            if (_bboxSubgraph.IntersectsWith(geometryParams.Bounds))
            {
                //
                // Determine if there is a special filter behavior defined for this
                // Visual.
                //

                HitTestFilterBehavior filter = HitTestFilterBehavior.Continue;

                if (filterCallback != null)
                {
                    filter = filterCallback(this);

                    if (filter == HitTestFilterBehavior.ContinueSkipSelfAndChildren)
                    {
                        return HitTestResultBehavior.Continue;
                    }

                    if (filter == HitTestFilterBehavior.Stop)
                    {
                        return HitTestResultBehavior.Stop;
                    }
                }

                //
                // Hit-test against the children.
                //

                int childCount = VisualChildrenCount;

                if (filter != HitTestFilterBehavior.ContinueSkipChildren)
                {
                    for (int i=childCount-1; i>=0; i--)
                    {
                        Visual child = GetVisualChild(i);
                        if (child != null)
                        {
                            // Hit the scollClip bounds first, which are in the child's outer-space.
                            Rect? scrollClip = ScrollableAreaClipField.GetValue(child);
                            if (scrollClip.HasValue)
                            {
                                // Hit-testing with a Geometry and a clip should hit test with
                                // the intersection of the geometry and the clip, not the entire geometry
                                RectangleGeometry rectClip = new RectangleGeometry(scrollClip.Value);
                                IntersectionDetail intersectionDetail = rectClip.FillContainsWithDetail(geometryParams.InternalHitGeometry);
   
                                Debug.Assert(intersectionDetail != IntersectionDetail.NotCalculated);
                                if (intersectionDetail == IntersectionDetail.Empty)
                                {
                                    // Skip child if there is a scrollable clip and this region is not inside it.
                                    continue;
                                }
                            }
                            
                            // Transform the geometry below offset and transform.
                            Matrix inv = Matrix.Identity;
                            inv.Translate(-child._offset.X, -child._offset.Y);

                            Transform childTransform = TransformField.GetValue(child);
                            if (childTransform != null)
                            {
                                Matrix m = childTransform.Value;

                                // If we can't invert the transform, the child is not hitable. This makes sense since
                                // the node's rendered content is degnerated, i.e. does not really take up any space.
                                // Skipping the child by continuing the loop.
                                if (!m.HasInverse)
                                {
                                   continue;
                                }

                                // Inverse the transform.
                                m.Invert();

                                // Multiply the inverse and the offset together.
                                // inv = inv * m;
                                MatrixUtil.MultiplyMatrix(ref inv, ref m);
                            }

                            // Push the transform on the geometry params.
                            geometryParams.PushMatrix(ref inv);

                            // Hit-Test against the children.

                            HitTestResultBehavior result =
                                child.HitTestGeometry(filterCallback, resultCallback, geometryParams);

                            // Pop the transform from the geometry params.

                            geometryParams.PopMatrix();

                            // Process the result.
                            if (result == HitTestResultBehavior.Stop)
                            {
                                return HitTestResultBehavior.Stop;
                            }
                        }
                    }
                }

                //
                // Hit-test against the content of the Visual.
                //

                if (filter != HitTestFilterBehavior.ContinueSkipSelf)
                {
                    GeometryHitTestResult hitResult = HitTestCore(geometryParams);

                    if (hitResult != null)
                    {
                        Debug.Assert(resultCallback != null);

                        return resultCallback(hitResult);
                    }
                }
            }

            return HitTestResultBehavior.Continue;
        }