/// <summary>
        /// Test whether object contains point
        /// </summary>
        public override bool Contains(Point point)
        {
            if (IsSelected)
            {
                return(this.Rectangle.Contains(point));
            }
            else
            {
                EllipseGeometry g = new EllipseGeometry(Rectangle);

                return(g.FillContains(point) || g.StrokeContains(new Pen(Brushes.Black, ActualLineWidth), point));
            }
        }
Example #2
0
        private bool HitTestDrawing(GeometryDrawing drawing, Point pt)
        {
            Pen   pen   = drawing.Pen;
            Brush brush = drawing.Brush;

            if (pen != null && brush == null)
            {
                if (drawing.Geometry.StrokeContains(pen, pt))
                {
                    return(true);
                }
                else
                {
                    Geometry geometry = drawing.Geometry;

                    EllipseGeometry   ellipse   = null;
                    RectangleGeometry rectangle = null;
                    PathGeometry      path      = null;
                    if (TryCast.Cast(geometry, out ellipse))
                    {
                        if (ellipse.FillContains(pt))
                        {
                            return(true);
                        }
                    }
                    else if (TryCast.Cast(geometry, out rectangle))
                    {
                        if (rectangle.FillContains(pt))
                        {
                            return(true);
                        }
                    }
                    else if (TryCast.Cast(geometry, out path))
                    {
                        PathFigureCollection pathFigures = path.Figures;
                        int itemCount = pathFigures.Count;
                        if (itemCount == 1)
                        {
                            if (pathFigures[0].IsClosed && path.FillContains(pt))
                            {
                                return(true);
                            }
                        }
                        else
                        {
                            for (int f = 0; f < itemCount; f++)
                            {
                                PathFigure pathFigure = pathFigures[f];
                                if (pathFigure.IsClosed)
                                {
                                    PathFigureCollection testFigures = new PathFigureCollection();
                                    testFigures.Add(pathFigure);

                                    PathGeometry testPath = new PathGeometry();
                                    testPath.Figures = testFigures;

                                    if (testPath.FillContains(pt))
                                    {
                                        return(true);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else if (brush != null && drawing.Geometry.FillContains(pt))
            {
                return(true);
            }

            return(false);
        }
        private bool PointOutsideRadius(System.Windows.Point pointToTest, double radiusAA)
        {
            // determine if point's x and y coordinates are within the area that we want to modify
            if (pointToTest.X > rectangleLeftCoordinate && pointToTest.X < rectangleRightCoordinate)
            {
                return(false);
            }
            if (pointToTest.Y > rectangleTopCoordinate && pointToTest.Y < rectangleBottomCoordinate)
            {
                return(false);
            }

            // create geometry objects for testing
            System.Windows.Point circleCenter = new System.Windows.Point();
            EllipseGeometry      circle       = new EllipseGeometry();

            // update circle's values
            circle.RadiusX = (double)radiusValue + radiusAA;
            circle.RadiusY = (double)radiusValue + radiusAA;

            // create 4 center points that will be used to draw circles
            circleCenter.X = rectangleLeftCoordinate;
            circleCenter.Y = rectangleTopCoordinate;
            circle.Center  = circleCenter;

            // check to see if our test point is contained with the current circle
            if (circle.FillContains(pointToTest))
            {
                return(false);
            }

            // update circle's values
            circleCenter.X = rectangleRightCoordinate;
            circleCenter.Y = rectangleTopCoordinate;
            circle.Center  = circleCenter;

            // check to see if our test point is contained with the current circle
            if (circle.FillContains(pointToTest))
            {
                return(false);
            }

            // update circle's values
            circleCenter.X = rectangleLeftCoordinate;
            circleCenter.Y = rectangleBottomCoordinate;
            circle.Center  = circleCenter;

            // check to see if our test point is contained with the current circle
            if (circle.FillContains(pointToTest))
            {
                return(false);
            }

            // update circle's values
            circleCenter.X = rectangleRightCoordinate;
            circleCenter.Y = rectangleBottomCoordinate;
            circle.Center  = circleCenter;

            // check to see if our test point is contained with the current circle
            if (circle.FillContains(pointToTest))
            {
                return(false);
            }

            // all other condition's passed, so return true
            return(true);
        }
        private bool HitTestDrawing(GeometryDrawing drawing, Point pt)
        {
            Pen   pen   = drawing.Pen;
            Brush brush = drawing.Brush;

            if (pen != null)
            {
                if (drawing.Geometry.StrokeContains(pen, pt))
                {
                    return(true);
                }
                Geometry geometry = drawing.Geometry;

                LineGeometry      line      = null;
                EllipseGeometry   ellipse   = null;
                RectangleGeometry rectangle = null;
                PathGeometry      path      = null;

                if (TryCast.Cast(geometry, out path))
                {
                    if (path.FillContains(pt, 1, ToleranceType.Absolute))
                    {
                        return(true);
                    }

                    //PathFigureCollection pathFigures = path.Figures;
                    //int itemCount = pathFigures.Count;
                    //if (itemCount == 1)
                    //{
                    //    if (pathFigures[0].IsClosed && path.FillContains(pt))
                    //    {
                    //        return true;
                    //    }
                    //}
                    //else
                    //{
                    //    for (int f = 0; f < itemCount; f++)
                    //    {
                    //        PathFigure pathFigure = pathFigures[f];
                    //        if (pathFigure.IsClosed)
                    //        {
                    //            PathFigureCollection testFigures = new PathFigureCollection();
                    //            testFigures.Add(pathFigure);

                    //            PathGeometry testPath = new PathGeometry();
                    //            testPath.Figures = testFigures;

                    //            if (testPath.FillContains(pt))
                    //            {
                    //                return true;
                    //            }
                    //        }
                    //    }
                    //}
                }
                else if (TryCast.Cast(geometry, out line))
                {
                    if (line.FillContains(pt))
                    {
                        return(true);
                    }
                }
                else if (TryCast.Cast(geometry, out ellipse))
                {
                    if (ellipse.FillContains(pt))
                    {
                        return(true);
                    }
                }
                else if (TryCast.Cast(geometry, out rectangle))
                {
                    if (rectangle.FillContains(pt))
                    {
                        return(true);
                    }
                }
            }
            else if (brush != null && drawing.Geometry.FillContains(pt))
            {
                return(true);
            }
            else if (drawing.Geometry.FillContains(pt))
            {
                return(true);
            }

            return(false);
        }