Example #1
0
        /// <summary> Uses HitTesting to determine the block at the specified point. </summary>
        /// <param name="point"> The point at which the hit test should be performed. </param>
        /// <returns> The block at a the given point. </returns>
        public Block GetBlockAt(DocumentPoint point)
        {
            _block = null;

            if (point.Y < 0)
            {
                return(_ownerView.GetBlockFor(new DocumentPoint(0, 0)));
            }
            else if (point.Y > _ownerView.RootVisual.ActualHeight)
            {
                var lastBlock = _ownerView.Context.Document.Root.LastBlock;
                return(BlockTreeWalker.GetNextNonContainerBlock(lastBlock)
                       ?? lastBlock as ContentBlock);
            }

            var localPoint = _ownerView.ToPoint(point);
            var instance   = _ownerView.InputHitTest(localPoint);

            if (instance is IDocumentItemView view &&
                GetAssociatedBlock(view) is Block block)
            {
                _block = block;
            }
 public MeasuredRectangle(DocumentPoint documentPoint, double width, double height)
     : this(documentPoint.X, documentPoint.Y, width, height)
 {
 }
 /// <summary> Trims the point to be within the current rectangle. </summary>
 /// <param name="point"> The point to trim. </param>
 /// <returns>
 ///  A DocumentPoint with the X/Y values that now exist within the current rectangle.
 /// </returns>
 public DocumentPoint Trim(DocumentPoint point)
 {
     point.X = Math.Max(Left, Math.Min(Right, point.X));
     point.Y = Math.Max(Top, Math.Min(Bottom, point.Y));
     return(point);
 }
 public Block GetBlockFor(DocumentPoint point)
 {
     return(_blockSearchHitTester.GetBlockAt(point));
 }
        /// <summary> Convert a Document Point to a relative/WPF point. </summary>
        public Point ToPoint(DocumentPoint point)
        {
            var localPoint = new Point(point.X, point.Y);

            return(RootVisual.TranslatePoint(localPoint, _scrollView));
        }