Exemple #1
4
        public override void UpdateGeometry()
        {
            ScaleThickness = Image.State.Flags.HasFlag(ShapeStateFlags.Thickness);
            ScaleSize      = Image.State.Flags.HasFlag(ShapeStateFlags.Size);

            if (!string.IsNullOrEmpty(Image.Key))
            {
                ImageCached = BitmapCache.Get(Image.Key) as AMI.Bitmap;
                if (ImageCached == null && ImageCache != null)
                {
                    try
                    {
                        var bytes = ImageCache.GetImage(Image.Key);
                        if (bytes != null)
                        {
                            using var ms = new System.IO.MemoryStream(bytes);
                            ImageCached  = new AMI.Bitmap(ms);
                            BitmapCache.Set(Image.Key, ImageCached);
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine($"{ex.Message}");
                        Debug.WriteLine($"{ex.StackTrace}");
                    }
                }

                if (ImageCached != null)
                {
                    SourceRect = new A.Rect(0, 0, ImageCached.PixelSize.Width, ImageCached.PixelSize.Height);
                }
            }
            else
            {
                ImageCached = null;
            }

            var rect2 = Rect2.FromPoints(Image.TopLeft.X, Image.TopLeft.Y, Image.BottomRight.X, Image.BottomRight.Y, 0, 0);

            DestRect = new A.Rect(rect2.X, rect2.Y, rect2.Width, rect2.Height);
            Center   = DestRect.Center;

            base.UpdateTextGeometry();
        }
Exemple #2
0
 public static Rect2 ToRect2(this EllipseShape ellipse, double dx = 0.0, double dy = 0.0)
 {
     return(Rect2.FromPoints(
                ellipse.StartPoint.X, ellipse.StartPoint.Y,
                ellipse.Point.X, ellipse.Point.Y,
                dx, dy));
 }
 public static Rect2 ToRect2(this EllipseShape ellipse, double dx = 0.0, double dy = 0.0)
 {
     return(Rect2.FromPoints(
                ellipse.TopLeft.X, ellipse.TopLeft.Y,
                ellipse.BottomRight.X, ellipse.BottomRight.Y,
                dx, dy));
 }
 public static Rect2 ToRect2(this RectangleShape rectangle, double dx = 0.0, double dy = 0.0)
 {
     return(Rect2.FromPoints(
                rectangle.StartPoint.X, rectangle.StartPoint.Y,
                rectangle.Point.X, rectangle.Point.Y,
                dx, dy));
 }
 public static Rect2 ToRect2(this OvalShape oval, double dx = 0.0, double dy = 0.0)
 {
     return(Rect2.FromPoints(
                oval.StartPoint.X, oval.StartPoint.Y,
                oval.Point.X, oval.Point.Y,
                dx, dy));
 }
 public static Rect2 ToRect2(this RectangleShape rectangle, double dx = 0.0, double dy = 0.0)
 {
     return(Rect2.FromPoints(
                rectangle.TopLeft.X, rectangle.TopLeft.Y,
                rectangle.BottomRight.X, rectangle.BottomRight.Y,
                dx, dy));
 }
Exemple #7
0
        public static AM.Geometry ToGeometry(EllipseShapeViewModel ellipse)
        {
            var rect2 = Rect2.FromPoints(ellipse.TopLeft.X, ellipse.TopLeft.Y, ellipse.BottomRight.X, ellipse.BottomRight.Y);
            var rect  = new A.Rect(rect2.X, rect2.Y, rect2.Width, rect2.Height);
            var g     = new AM.EllipseGeometry(rect);

            return(g);
        }
 public static Rect2 ToRect2(this IPointShape center, double radius)
 {
     return(Rect2.FromPoints(
                center.X - radius,
                center.Y - radius,
                center.X + radius,
                center.Y + radius));
 }
Exemple #9
0
        public override void UpdateGeometry()
        {
            ScaleThickness = true; // Point.State.HasFlag(ShapeStateFlags.Thickness);
            ScaleSize      = true; // Point.State.HasFlag(ShapeStateFlags.Size);
            var rect2 = Rect2.FromPoints(Point.X - PointSize, Point.Y - PointSize, Point.X + PointSize, Point.Y + PointSize, 0, 0);

            Rect   = new A.Rect(rect2.X, rect2.Y, rect2.Width, rect2.Height);
            Center = Rect.Center;
        }
Exemple #10
0
        public override void UpdateGeometry()
        {
            ScaleThickness = Rectangle.State.HasFlag(ShapeStateFlags.Thickness);
            ScaleSize      = Rectangle.State.HasFlag(ShapeStateFlags.Size);
            var rect2 = Rect2.FromPoints(Rectangle.TopLeft.X, Rectangle.TopLeft.Y, Rectangle.BottomRight.X, Rectangle.BottomRight.Y, 0, 0);

            Rect   = new A.Rect(rect2.X, rect2.Y, rect2.Width, rect2.Height);
            Center = Rect.Center;
        }
Exemple #11
0
 /// <summary>
 /// Get the bounding rectangle for <see cref="XText"/> shape.
 /// </summary>
 /// <param name="text"></param>
 /// <param name="dx"></param>
 /// <param name="dy"></param>
 /// <returns></returns>
 public static Rect2 GetTextBounds(XText text, double dx, double dy)
 {
     return(Rect2.FromPoints(
                text.TopLeft.X,
                text.TopLeft.Y,
                text.BottomRight.X,
                text.BottomRight.Y,
                dx, dy));
 }
Exemple #12
0
        public override void UpdateGeometry()
        {
            ScaleThickness = Ellipse.State.HasFlag(ShapeStateFlags.Thickness);
            ScaleSize      = Ellipse.State.HasFlag(ShapeStateFlags.Size);
            var rect2 = Rect2.FromPoints(Ellipse.TopLeft.X, Ellipse.TopLeft.Y, Ellipse.BottomRight.X, Ellipse.BottomRight.Y, 0, 0);

            Rect   = SKRect.Create((float)rect2.X, (float)rect2.Y, (float)rect2.Width, (float)rect2.Height);
            Center = new SKPoint(Rect.MidX, Rect.MidY);
        }
Exemple #13
0
 /// <summary>
 /// Get the bounding rectangle for <see cref="XEllipse"/> shape.
 /// </summary>
 /// <param name="ellipse"></param>
 /// <param name="dx"></param>
 /// <param name="dy"></param>
 /// <returns></returns>
 public static Rect2 GetEllipseBounds(XEllipse ellipse, double dx, double dy)
 {
     return(Rect2.FromPoints(
                ellipse.TopLeft.X,
                ellipse.TopLeft.Y,
                ellipse.BottomRight.X,
                ellipse.BottomRight.Y,
                dx, dy));
 }
Exemple #14
0
 /// <summary>
 /// Get the bounding rectangle for <see cref="XImage"/> shape.
 /// </summary>
 /// <param name="image"></param>
 /// <param name="dx"></param>
 /// <param name="dy"></param>
 /// <returns></returns>
 public static Rect2 GetImageBounds(XImage image, double dx, double dy)
 {
     return(Rect2.FromPoints(
                image.TopLeft.X,
                image.TopLeft.Y,
                image.BottomRight.X,
                image.BottomRight.Y,
                dx, dy));
 }
Exemple #15
0
        public override void UpdateGeometry()
        {
            ScaleThickness = true; // Point.State.Flags.HasFlag(ShapeStateFlags.Thickness);
            ScaleSize      = true; // Point.State.Flags.HasFlag(ShapeStateFlags.Size);
            var rect2 = Rect2.FromPoints(Point.X - PointSize, Point.Y - PointSize, Point.X + PointSize, Point.Y + PointSize, 0, 0);

            Rect   = SKRect.Create((float)rect2.X, (float)rect2.Y, (float)rect2.Width, (float)rect2.Height);
            Center = new SKPoint(Rect.MidX, Rect.MidY);
        }
Exemple #16
0
 /// <summary>
 /// Get the bounding rectangle for <see cref="XRectangle"/> shape.
 /// </summary>
 /// <param name="rectangle"></param>
 /// <param name="dx"></param>
 /// <param name="dy"></param>
 /// <returns></returns>
 public static Rect2 GetRectangleBounds(XRectangle rectangle, double dx, double dy)
 {
     return(Rect2.FromPoints(
                rectangle.TopLeft.X,
                rectangle.TopLeft.Y,
                rectangle.BottomRight.X,
                rectangle.BottomRight.Y,
                dx, dy));
 }
Exemple #17
0
        public IBaseShape Overlaps(IBaseShape shape, Rect2 target, double radius, IHitTest hitTest, Modifier modifier)
        {
            var oval = shape as OvalShape ?? throw new ArgumentNullException("shape");

            return(Rect2.FromPoints(
                       oval.StartPoint.X,
                       oval.StartPoint.Y,
                       oval.Point.X,
                       oval.Point.Y).IntersectsWith(target) ? shape : null);
        }
Exemple #18
0
        public override BaseShape Overlaps(BaseShape shape, Rect2 target, double radius, IHitTest hitTest)
        {
            var box = shape as BoxShape ?? throw new ArgumentNullException("shape");

            return(Rect2.FromPoints(
                       box.TopLeft.X,
                       box.TopLeft.Y,
                       box.BottomRight.X,
                       box.BottomRight.Y).IntersectsWith(target) ? shape : null);
        }
Exemple #19
0
        public IBaseShape Contains(IBaseShape shape, Point2 target, double radius, IHitTest hitTest, Modifier modifier)
        {
            var rectangle = shape as RectangleShape ?? throw new ArgumentNullException("shape");

            return(Rect2.FromPoints(
                       rectangle.StartPoint.X,
                       rectangle.StartPoint.Y,
                       rectangle.Point.X,
                       rectangle.Point.Y).Contains(target) ? shape : null);
        }
Exemple #20
0
    public sealed override void UpdateGeometry()
    {
        ScaleThickness = Text.State.HasFlag(ShapeStateFlags.Thickness);
        ScaleSize      = Text.State.HasFlag(ShapeStateFlags.Size);
        var rect2 = Rect2.FromPoints(Text.TopLeft.X, Text.TopLeft.Y, Text.BottomRight.X, Text.BottomRight.Y, 0, 0);

        Rect   = new A.Rect(rect2.X, rect2.Y, rect2.Width, rect2.Height);
        Center = Rect.Center;

        UpdateTextGeometry();
    }
Exemple #21
0
        public bool Overlaps(IBaseShape shape, Rect2 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).IntersectsWith(target));
        }
Exemple #22
0
        public override bool Contains(IBaseShape shape, Point2 target, double radius, IDictionary <Type, HitTestBase> 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));
        }
Exemple #23
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));
        }
Exemple #24
0
        public bool Contains(IBaseShape shape, Point2 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).Contains(target));
        }
Exemple #25
0
        public override bool Overlaps(BaseShape shape, Rect2 target, double radius, IDictionary <Type, HitTestBase> registered)
        {
            var text = shape as TextShape;

            if (text == null)
            {
                throw new ArgumentNullException(nameof(shape));
            }

            return(Rect2.FromPoints(
                       text.TopLeft.X,
                       text.TopLeft.Y,
                       text.BottomRight.X,
                       text.BottomRight.Y).IntersectsWith(target));
        }
Exemple #26
0
        public override bool Contains(BaseShape shape, Point2 target, double radius, IDictionary <Type, HitTestBase> registered)
        {
            var ellipse = shape as EllipseShape;

            if (ellipse == null)
            {
                throw new ArgumentNullException(nameof(shape));
            }

            return(Rect2.FromPoints(
                       ellipse.TopLeft.X,
                       ellipse.TopLeft.Y,
                       ellipse.BottomRight.X,
                       ellipse.BottomRight.Y).Contains(target));
        }
Exemple #27
0
        public override void UpdateGeometry()
        {
            ScaleThickness = Image.State.Flags.HasFlag(ShapeStateFlags.Thickness);
            ScaleSize      = Image.State.Flags.HasFlag(ShapeStateFlags.Size);

            if (!string.IsNullOrEmpty(Image.Key))
            {
                ImageCached = BitmapCache.Get(Image.Key) as SKBitmap;
                if (ImageCached == null && ImageCache != null)
                {
                    try
                    {
                        var bytes = ImageCache.GetImage(Image.Key);
                        if (bytes != null)
                        {
                            ImageCached = SKBitmap.Decode(bytes);
                            BitmapCache.Set(Image.Key, ImageCached);
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine($"{ex.Message}");
                        Debug.WriteLine($"{ex.StackTrace}");
                    }
                }

                if (ImageCached != null)
                {
                    SourceRect = new SKRect(0, 0, ImageCached.Width, ImageCached.Height);
                }
            }
            else
            {
                ImageCached = null;
            }

            var rect2 = Rect2.FromPoints(Image.TopLeft.X, Image.TopLeft.Y, Image.BottomRight.X, Image.BottomRight.Y, 0, 0);

            DestRect = SKRect.Create((float)rect2.X, (float)rect2.Y, (float)rect2.Width, (float)rect2.Height);
            Center   = new SKPoint(DestRect.MidX, DestRect.MidY);

            base.UpdateTextGeometry();
        }
Exemple #28
0
        public bool Overlaps(IBaseShape shape, Rect2 target, double radius, double scale, IDictionary <Type, IBounds> registered)
        {
            if (!(shape is IEllipseShape ellipse))
            {
                throw new ArgumentNullException(nameof(shape));
            }

            var rect = Rect2.FromPoints(
                ellipse.TopLeft.X,
                ellipse.TopLeft.Y,
                ellipse.BottomRight.X,
                ellipse.BottomRight.Y);

            if (ellipse.State.Flags.HasFlag(ShapeStateFlags.Size) && scale != 1.0)
            {
                return(HitTestHelper.Inflate(ref rect, scale).IntersectsWith(target));
            }
            else
            {
                return(rect.IntersectsWith(target));
            }
        }
Exemple #29
0
        public bool Contains(IBaseShape shape, Point2 target, double radius, double scale, IDictionary <Type, IBounds> registered)
        {
            if (!(shape is ITextShape text))
            {
                throw new ArgumentNullException(nameof(shape));
            }

            var rect = Rect2.FromPoints(
                text.TopLeft.X,
                text.TopLeft.Y,
                text.BottomRight.X,
                text.BottomRight.Y);

            if (text.State.Flags.HasFlag(ShapeStateFlags.Size) && scale != 1.0)
            {
                return(HitTestHelper.Inflate(ref rect, scale).Contains(target));
            }
            else
            {
                return(rect.Contains(target));
            }
        }
Exemple #30
0
        public override void Find(IToolContext context, BaseShape shape)
        {
            var line = shape as LineShape;

            if (line == null)
            {
                throw new ArgumentNullException("shape");
            }

            if (!Settings.IsEnabled)
            {
                return;
            }

            var rectangles = context.CurrentContainer.Shapes.OfType <RectangleShape>();

            if (rectangles.Any())
            {
                foreach (var rectangle in rectangles)
                {
                    var rect          = Rect2.FromPoints(rectangle.TopLeft.ToPoint2(), rectangle.BottomRight.ToPoint2());
                    var p1            = line.StartPoint.ToPoint2();
                    var p2            = line.Point.ToPoint2();
                    var intersections = Line2.LineIntersectsWithRect(p1, p2, rect, out double x0clip, out double y0clip, out double x1clip, out double y1clip);
                    if (intersections)
                    {
                        var point1 = new PointShape(x0clip, y0clip, context.PointShape);
                        Intersections.Add(point1);
                        context.WorkingContainer.Shapes.Add(point1);
                        context.Renderer.SelectedShapes.Add(point1);

                        var point2 = new PointShape(x1clip, y1clip, context.PointShape);
                        Intersections.Add(point2);
                        context.WorkingContainer.Shapes.Add(point2);
                        context.Renderer.SelectedShapes.Add(point2);
                    }
                }
            }
        }