コード例 #1
0
        public static Tuple <Shape, string> FindShapeAtPoint(this Canvas Canvas, Point Pos)
        {
            Shape  found      = null;
            var    posRect    = Pos.GetRectAtPoint();
            string comboDebug = null;

            foreach (var elem in Canvas.Children)
            {
                var uiShape = elem as Shape;
                if (uiShape != null)
                {
                    if (uiShape is Line)
                    {
                        var uiLine = uiShape as Line;
                        if (uiLine.IntersectsWith(Pos))
                        {
                            found = uiShape;
                            break;
                        }
                    }

                    else if (uiShape is Path)
                    {
                        var uiPath = uiShape as Path;

                        var rectGeom = new RectangleGeometry();
                        rectGeom.Rect = new Rect(Pos, new Size(1, 1));
                        var rp = new Path();
                        rp.Fill            = Brushes.Black;
                        rp.Stroke          = Brushes.Black;
                        rp.StrokeThickness = 1;
                        rp.Data            = rectGeom;

                        var xx = uiPath.RenderedGeometry.FillContainsWithDetail(rectGeom);
                        if (xx == IntersectionDetail.Intersects)
                        {
                            found = uiShape;
                            break;
                        }
                    }

                    else
                    {
                        var rect = CanvasExt.GetShapeRect(uiShape);
                        if (rect.IntersectsWith(posRect))
                        {
                            found = uiShape;
                            break;
                        }
                    }
                }
            }

            return(new Tuple <Shape, string>(found, comboDebug));
        }
コード例 #2
0
        /// <summary>
        /// Find the first shape on the canvas at the point. If no shape found, look for
        /// shapes that are between the PriorPos and the Pos. Shapes between the two
        /// positions are passed over shapes. Return the estimated pass over point.
        /// </summary>
        /// <param name="Canvas"></param>
        /// <param name="Pos"></param>
        /// <param name="PriorPos"></param>
        /// <returns></returns>
        public static Tuple <Shape, Point?> FindShapeAtPoint(
            this Canvas Canvas, Point Pos, Point?PriorPos)
        {
            Shape found            = null;
            Point?estPassOverPoint = null;
            var   posRect          = Pos.GetRectAtPoint();

            foreach (var elem in Canvas.Children)
            {
                var uiShape = elem as Shape;
                if (uiShape != null)
                {
                    if (uiShape is Line)
                    {
                        var uiLine = uiShape as Line;
                        if (uiLine.IntersectsWith(Pos))
                        {
                            found = uiShape;
                            break;
                        }
                    }

                    else
                    {
                        var rect = CanvasExt.GetShapeRect(uiShape);
                        if (rect.IntersectsWith(posRect))
                        {
                            found = uiShape;
                            break;
                        }
                    }
                }
            }

            return(new Tuple <Shape, Point?>(found, estPassOverPoint));
        }