示例#1
0
        public IBaseShape Contains(IBaseShape shape, Point2 target, double radius, IHitTest hitTest, Modifier modifier)
        {
            if (!(shape is ConicShape conic))
            {
                throw new ArgumentNullException("shape");
            }

            var points = new List <IPointShape>();

            conic.GetPoints(points);

            return(HitTestHelper.Contains(points, target) ? shape : null);
        }
示例#2
0
        public IBaseShape Overlaps(IBaseShape shape, Rect2 target, double radius, IHitTest hitTest, Modifier modifier)
        {
            if (!(shape is CubicBezierShape cubicBezier))
            {
                throw new ArgumentNullException("shape");
            }

            var points = new List <IPointShape>();

            cubicBezier.GetPoints(points);

            return(HitTestHelper.Overlap(points, target) ? shape : null);
        }
示例#3
0
        public bool Contains(IBaseShape shape, Point2 target, double radius, IDictionary <Type, IBounds> registered)
        {
            if (!(shape is IImageShape image))
            {
                throw new ArgumentNullException(nameof(shape));
            }

            return(Rect2.FromPoints(
                       image.TopLeft.X,
                       image.TopLeft.Y,
                       image.BottomRight.X,
                       image.BottomRight.Y).Contains(target));
        }
示例#4
0
        public override bool Overlaps(IBaseShape shape, Rect2 target, double radius, IDictionary <Type, HitTestBase> registered)
        {
            if (!(shape is IEllipseShape ellipse))
            {
                throw new ArgumentNullException(nameof(shape));
            }

            return(Rect2.FromPoints(
                       ellipse.TopLeft.X,
                       ellipse.TopLeft.Y,
                       ellipse.BottomRight.X,
                       ellipse.BottomRight.Y).IntersectsWith(target));
        }
示例#5
0
        public override bool Contains(IBaseShape shape, Point2 target, double radius, IDictionary <Type, HitTestBase> registered)
        {
            if (!(shape is ITextShape text))
            {
                throw new ArgumentNullException(nameof(shape));
            }

            return(Rect2.FromPoints(
                       text.TopLeft.X,
                       text.TopLeft.Y,
                       text.BottomRight.X,
                       text.BottomRight.Y).Contains(target));
        }
示例#6
0
 public bool Intersects(ref SKRect rect, out IBaseShape rootShape, out IBaseShape childShape)
 {
     rootShape  = null;
     childShape = null;
     for (int i = 0; i < _renderer._rootNodes.Count; i++)
     {
         if (_renderer._rootNodes[i].Intersects(ref rect, out rootShape, out childShape))
         {
             return(true);
         }
     }
     return(false);
 }
示例#7
0
        /// <summary>
        /// Replace shape at specified index.
        /// </summary>
        /// <param name="project">The project instance.</param>
        /// <param name="layer">The layer instance.</param>
        /// <param name="shape">The shape instance.</param>
        /// <param name="index">The shape index.</param>
        public static void ReplaceShape(this IProjectContainer project, ILayerContainer layer, IBaseShape shape, int index)
        {
            if (layer != null && shape != null && index >= 0)
            {
                var builder = layer.Shapes.ToBuilder();
                builder[index] = shape;

                var previous = layer.Shapes;
                var next     = builder.ToImmutable();
                project?.History?.Snapshot(previous, next, (p) => layer.Shapes = p);
                layer.Shapes = next;
            }
        }
示例#8
0
 public bool Contains(float x, float y, ContainsMode mode, out IBaseShape rootShape, out IBaseShape childShape)
 {
     rootShape  = null;
     childShape = null;
     for (int i = 0; i < _renderer._rootNodes.Count; i++)
     {
         if (_renderer._rootNodes[i].Contains(x, y, mode, out rootShape, out childShape))
         {
             return(true);
         }
     }
     return(false);
 }
示例#9
0
 /// <summary>
 /// Remove shape.
 /// </summary>
 /// <param name="project">The project instance.</param>
 /// <param name="shape">The shape instance.</param>
 /// <returns>The owner layer.</returns>
 public static ILayerContainer RemoveShape(this IProjectContainer project, IBaseShape shape)
 {
     if (project?.Documents != null && shape != null)
     {
         var layer = project.Documents.SelectMany(d => d.Pages).SelectMany(p => p.Layers).FirstOrDefault(l => l.Shapes.Contains(shape));
         if (layer != null)
         {
             project.RemoveShape(layer, shape);
         }
         return(layer);
     }
     return(null);
 }
示例#10
0
        public bool Overlaps(IBaseShape shape, Rect2 target, double radius, IDictionary <Type, IBounds> registered)
        {
            if (!(shape is IRectangleShape rectangle))
            {
                throw new ArgumentNullException(nameof(shape));
            }

            return(Rect2.FromPoints(
                       rectangle.TopLeft.X,
                       rectangle.TopLeft.Y,
                       rectangle.BottomRight.X,
                       rectangle.BottomRight.Y).IntersectsWith(target));
        }
示例#11
0
        public IPointShape TryToGetPoint(IBaseShape shape, Point2 target, double radius, IDictionary <Type, IBounds> registered)
        {
            if (!(shape is IPointShape point))
            {
                throw new ArgumentNullException(nameof(shape));
            }

            if (Point2.FromXY(point.X, point.Y).ExpandToRect(radius).Contains(target.X, target.Y))
            {
                return(point);
            }

            return(null);
        }
示例#12
0
        public IPointShape TryToGetPoint(IBaseShape shape, Point2 target, double radius, IHitTest hitTest, Modifier modifier)
        {
            if (!(shape is IPointShape point))
            {
                throw new ArgumentNullException("shape");
            }

            if (Point2.FromXY(point.X, point.Y).ExpandToRect(radius).Contains(target.X, target.Y))
            {
                return(point);
            }

            return(null);
        }
示例#13
0
        public static bool IsPointMovable(IPointShape point, IBaseShape parent)
        {
            if (point.State.Flags.HasFlag(ShapeStateFlags.Locked) || (point.Owner is IBaseShape ower && ower.State.Flags.HasFlag(ShapeStateFlags.Locked)))
            {
                return(false);
            }

            if (point.State.Flags.HasFlag(ShapeStateFlags.Connector) && point.Owner != parent)
            {
                return(false);
            }

            return(true);
        }
示例#14
0
        public override bool Contains(IBaseShape shape, Point2 target, double radius, IDictionary <Type, HitTestBase> registered)
        {
            if (!(shape is ILineShape line))
            {
                throw new ArgumentNullException(nameof(shape));
            }

            var    a        = new Point2(line.Start.X, line.Start.Y);
            var    b        = new Point2(line.End.X, line.End.Y);
            var    nearest  = target.NearestOnLine(a, b);
            double distance = target.DistanceTo(nearest);

            return(distance < radius);
        }
示例#15
0
        public IBaseShape Contains(IBaseShape shape, Point2 target, double radius, IHitTest hitTest, Modifier modifier)
        {
            if (!(shape is LineShape line))
            {
                throw new ArgumentNullException("shape");
            }

            var    a        = new Point2(line.StartPoint.X, line.StartPoint.Y);
            var    b        = new Point2(line.Point.X, line.Point.Y);
            var    nearest  = target.NearestOnLine(a, b);
            double distance = target.DistanceTo(nearest);

            return(distance < radius ? shape : null);
        }
示例#16
0
 public static void Swap(ICanvasContainer container, IBaseShape shape, int sourceIndex, int targetIndex)
 {
     if (sourceIndex < targetIndex)
     {
         SwapShape(container, shape, targetIndex + 1, sourceIndex);
     }
     else
     {
         if (container.Shapes.Count + 1 > sourceIndex + 1)
         {
             SwapShape(container, shape, targetIndex, sourceIndex + 1);
         }
     }
 }
示例#17
0
        public static void SendBackward(IToolContext context, IBaseShape source)
        {
            var container = context.ContainerView?.CurrentContainer;

            if (container != null)
            {
                var shapes      = container.Shapes;
                int sourceIndex = shapes.IndexOf(source);
                int targetIndex = sourceIndex - 1;
                if (targetIndex >= 0)
                {
                    Swap(container, source, sourceIndex, targetIndex);
                }
            }
        }
示例#18
0
        public override bool Contains(IBaseShape shape, Point2 target, double radius, IDictionary <Type, HitTestBase> registered)
        {
            if (!(shape is IPathShape path))
            {
                throw new ArgumentNullException(nameof(shape));
            }

            var points = path.GetPoints();

            if (points.Count() > 0)
            {
                return(HitTestHelper.Contains(points, target));
            }
            return(false);
        }
示例#19
0
        public static void SendToBack(IToolContext context, IBaseShape source)
        {
            var container = context.DocumentContainer?.ContainerView?.CurrentContainer;

            if (container != null)
            {
                var shapes      = container.Shapes;
                int sourceIndex = shapes.IndexOf(source);
                int targetIndex = 0;
                if (sourceIndex != targetIndex)
                {
                    Swap(container, source, sourceIndex, targetIndex);
                }
            }
        }
示例#20
0
        public static void BringForward(IToolContext context, IBaseShape source)
        {
            var container = context.DocumentContainer?.ContainerView?.CurrentContainer;

            if (container != null)
            {
                var shapes      = container.Shapes;
                int sourceIndex = shapes.IndexOf(source);
                int targetIndex = sourceIndex + 1;
                if (targetIndex < shapes.Count)
                {
                    Swap(container, source, sourceIndex, targetIndex);
                }
            }
        }
示例#21
0
 public bool Intersects(ref SKRect rect, out IBaseShape rootShape, out IBaseShape childShape)
 {
     rootShape  = null;
     childShape = null;
     for (int i = 0; i < Children.Count; i++)
     {
         if (Children[i].Bounds.IntersectsWith(rect))
         {
             rootShape  = this.Shape;
             childShape = Children[i].Shape;
             return(true);
         }
     }
     return(false);
 }
示例#22
0
 public bool Intersects(SKPath geometry, out IBaseShape rootShape, out IBaseShape childShape)
 {
     rootShape  = null;
     childShape = null;
     for (int i = 0; i < Children.Count; i++)
     {
         if (Children[i].Intersects(geometry))
         {
             rootShape  = this.Shape;
             childShape = Children[i].Shape;
             return(true);
         }
     }
     return(false);
 }
示例#23
0
        public static void BringToFront(IToolContext context, IBaseShape source)
        {
            var container = context.ContainerView?.CurrentContainer;

            if (container != null)
            {
                var shapes      = container.Shapes;
                int sourceIndex = shapes.IndexOf(source);
                int targetIndex = shapes.Count - 1;
                if (targetIndex >= 0 && sourceIndex != targetIndex)
                {
                    Swap(container, source, sourceIndex, targetIndex);
                }
            }
        }
示例#24
0
        public ShapeBox(IBaseShape shape)
        {
            Shape = shape;

            Points = new List <IPointShape>();

            foreach (var point in Shape.GetPoints())
            {
                Points.Add(point);
            }

            Bounds = new Box();

            Update();
        }
示例#25
0
        public bool Overlaps(IBaseShape shape, Rect2 target, double radius, IDictionary <Type, IBounds> registered)
        {
            if (!(shape is IPathShape path))
            {
                throw new ArgumentNullException(nameof(shape));
            }

            var points = path.GetPoints();

            if (points.Count() > 0)
            {
                return(HitTestHelper.Overlap(points, target));
            }
            return(false);
        }
示例#26
0
 public bool Overlaps(IBaseShape shape, Rect2 target, double radius, double scale, IDictionary <Type, IBounds> registered)
 {
     if (!(shape is IPointShape point))
     {
         throw new ArgumentNullException(nameof(shape));
     }
     if (point.State.Flags.HasFlag(ShapeStateFlags.Size) && scale != 1.0)
     {
         return(Point2.FromXY(point.X, point.Y).ExpandToRect(radius / scale).IntersectsWith(target));
     }
     else
     {
         return(Point2.FromXY(point.X, point.Y).ExpandToRect(radius).IntersectsWith(target));
     }
 }
示例#27
0
 public static SKPath ToSKPath(this IBaseShape shape, double dx, double dy, Func <double, float> scale)
 {
     return(shape switch
     {
         ILineShape lineShape => ToSKPath(lineShape, dx, dy, scale),
         IRectangleShape rectangleShape => ToSKPath(rectangleShape, dx, dy, scale),
         IEllipseShape ellipseShape => ToSKPath(ellipseShape, dx, dy, scale),
         IImageShape imageShape => ToSKPath(imageShape, dx, dy, scale),
         IArcShape arcShape => ToSKPath(arcShape, dx, dy, scale),
         ICubicBezierShape cubicBezierShape => ToSKPath(cubicBezierShape, dx, dy, scale),
         IQuadraticBezierShape quadraticBezierShape => ToSKPath(quadraticBezierShape, dx, dy, scale),
         ITextShape textShape => ToSKPath(textShape, dx, dy, scale),
         IPathShape pathShape => ToSKPath(pathShape, dx, dy, scale),
         IGroupShape groupShape => ToSKPath(groupShape.Shapes, dx, dy, scale),
         _ => null,
     });
示例#28
0
 public PathShape ToPathShape(IToolContext context, IBaseShape shape)
 {
     using (var geometry = ToPath(context, shape))
     {
         if (geometry != null)
         {
             var style = context.DocumentContainer?.StyleLibrary?.Get(shape.StyleId);
             if (style == null)
             {
                 style = context.DocumentContainer?.StyleLibrary?.CurrentItem;
             }
             return(SkiaHelper.ToPathShape(context, geometry, style, context?.DocumentContainer?.PointTemplate));
         }
     }
     return(null);
 }
示例#29
0
        public IBaseShape Overlaps(IBaseShape shape, Rect2 target, double radius, IHitTest hitTest, Modifier modifier)
        {
            if (!(shape is CanvasContainer container))
            {
                throw new ArgumentNullException("shape");
            }

            foreach (var containerShape in container.Shapes)
            {
                var result = containerShape.Bounds?.Overlaps(containerShape, target, radius, hitTest, modifier);
                if (result != null)
                {
                    return(container);
                }
            }
            return(null);
        }
示例#30
0
        public IPointShape TryToGetPoint(IBaseShape shape, Point2 target, double radius, IHitTest hitTest, Modifier modifier)
        {
            if (!(shape is CanvasContainer container))
            {
                throw new ArgumentNullException("shape");
            }

            foreach (var containerPoint in container.Points)
            {
                if (containerPoint.Bounds?.TryToGetPoint(containerPoint, target, radius, hitTest, modifier) != null)
                {
                    return(containerPoint);
                }
            }

            return(null);
        }