Exemplo n.º 1
0
        public void SetPathWithoutClipDoesNotCreateEmptyRegion()
        {
            var path = new SKPath();

            path.AddRect(SKRect.Create(10, 20, 30, 40));

            var region     = new SKRegion();
            var isNonEmpty = region.SetPath(path);

            Assert.True(isNonEmpty);
            Assert.Equal(SKRectI.Truncate(path.Bounds), region.Bounds);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Checks whether the region intersects the given rectangle.
        /// </summary>
        /// <param name="region">The region to check collision with.</param>
        /// <param name="rect">The rectangle to check for intersection.</param>
        internal static bool IntersectsRect(this SKRegion region, SKRect rect)
        {
            if (region.Bounds.IsEmpty)
            {
                return(false);
            }

            using SKRegion rectRegion = new SKRegion();

            rectRegion.SetRect(SKRectI.Round(rect));
            return(region.Intersects(rectRegion));
        }
Exemplo n.º 3
0
        public void SetPathWithEmptyClipDoesCreatesEmptyRegion()
        {
            var path = new SKPath();

            path.AddRect(SKRect.Create(10, 20, 30, 40));

            var region     = new SKRegion();
            var isNonEmpty = region.SetPath(path, new SKRegion());

            Assert.False(isNonEmpty);
            Assert.Equal(SKRectI.Empty, region.Bounds);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Checks whether the region intersects the given path.
        /// </summary>
        /// <param name="region">The region to check collision with.</param>
        /// <param name="rect">The rectangle to check for intersection.</param>
        internal static bool IntersectsPath(this SKRegion region, SKPath path)
        {
            if (region.Bounds.IsEmpty)
            {
                return(false);
            }

            using SKRegion pathRegion = new SKRegion();

            pathRegion.SetPath(path, region);
            return(region.Intersects(pathRegion));
        }
Exemplo n.º 5
0
        //Default resolution makes 10 points per line segment
        private bool IsInside(SKPath pInput, SKPath pBoundary)
        {
            var input    = new SKRegion();
            var boundary = new SKRegion();

            input.SetRect(ToIntRect(pInput.Bounds));
            boundary.SetRect(ToIntRect(pBoundary.Bounds));
            input.SetPath(pInput);
            boundary.SetPath(pBoundary);

            var contained = boundary.Contains(input);

            return(contained);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Sets the contents of the region to the specified path.
        /// </summary>
        /// <param name="region">The region to set the path into.</param>
        /// <param name="path">The path object.</param>
        /// <param name="usePathBounds">Whether to set the region's new bounds to the bounds of the path itself.</param>
        internal static bool SetPath(this SKRegion region, SKPath path, bool usePathBounds)
        {
            if (usePathBounds && path.GetBounds(out SKRect bounds))
            {
                using SKRegion clip = new SKRegion();

                clip.SetRect(SKRectI.Ceiling(bounds));
                return(region.SetPath(path, clip));
            }
            else
            {
                return(region.SetPath(path));
            }
        }
Exemplo n.º 7
0
        void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    if (skRegion != null)
                    {
                        skRegion.Dispose();
                        skRegion = null;
                    }
                }

                disposedValue = true;
            }
        }
        void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            int radius = 10;

            // Create circular path
            using (SKPath circlePath = new SKPath())
            {
                circlePath.AddCircle(0, 0, radius);

                // Create circular region
                using (SKRegion circleRegion = new SKRegion())
                {
                    circleRegion.SetRect(new SKRectI(-radius, -radius, radius, radius));
                    circleRegion.SetPath(circlePath);

                    // Set transform to move it to center and scale up
                    canvas.Translate(info.Width / 2, info.Height / 2);
                    canvas.Scale(Math.Min(info.Width / 2, info.Height / 2) / radius);

                    // Fill region
                    using (SKPaint fillPaint = new SKPaint())
                    {
                        fillPaint.Style = SKPaintStyle.Fill;
                        fillPaint.Color = SKColors.Orange;

                        canvas.DrawRegion(circleRegion, fillPaint);
                    }

                    // Stroke path for comparison
                    using (SKPaint strokePaint = new SKPaint())
                    {
                        strokePaint.Style       = SKPaintStyle.Stroke;
                        strokePaint.Color       = SKColors.Blue;
                        strokePaint.StrokeWidth = 0.1f;

                        canvas.DrawPath(circlePath, strokePaint);
                    }
                }
            }
        }
Exemplo n.º 9
0
        public void SetPathWithClipDoesCreatesCorrectRegion()
        {
            var clipRect = new SKRectI(25, 25, 50, 50);
            var clip     = new SKRegion();

            clip.SetRect(clipRect);

            var rect = new SKRectI(10, 20, 30, 40);
            var path = new SKPath();

            path.AddRect(rect);

            var region     = new SKRegion();
            var isNonEmpty = region.SetPath(path, clip);

            Assert.IsTrue(isNonEmpty);
            Assert.AreEqual(SKRectI.Intersect(clipRect, rect), region.Bounds);
        }
Exemplo n.º 10
0
 public MainPage()
 {
     InitializeComponent();
     a = new BookPoint();
     f = new BookPoint();
     g = new BookPoint();
     e = new BookPoint();
     h = new BookPoint();
     c = new BookPoint();
     j = new BookPoint();
     b = new BookPoint();
     k = new BookPoint();
     d = new BookPoint();
     i = new BookPoint();
     CanvasView.IgnorePixelScaling = true;
     _region = new SKRegion();
     _pathA  = new SKPath();
     _pathC  = new SKPath();
 }
Exemplo n.º 11
0
        void DisplayClipOp(SKCanvas canvas, SKRect rect, SKRegionOperation regionOp)
        {
            float textSize = textPaint.TextSize;

            canvas.DrawText(regionOp.ToString(), rect.MidX, rect.Top + textSize, textPaint);
            rect.Top += textSize;

            float radius  = 0.9f * Math.Min(rect.Width / 3, rect.Height / 2);
            float xCenter = rect.MidX;
            float yCenter = rect.MidY;

            SKRectI recti = new SKRectI((int)rect.Left, (int)rect.Top,
                                        (int)rect.Right, (int)rect.Bottom);

            using (SKRegion wholeRectRegion = new SKRegion())
            {
                wholeRectRegion.SetRect(recti);

                using (SKRegion region1 = new SKRegion(wholeRectRegion))
                    using (SKRegion region2 = new SKRegion(wholeRectRegion))
                    {
                        using (SKPath path1 = new SKPath())
                        {
                            path1.AddCircle(xCenter - radius / 2, yCenter, radius);
                            region1.SetPath(path1);
                        }

                        using (SKPath path2 = new SKPath())
                        {
                            path2.AddCircle(xCenter + radius / 2, yCenter, radius);
                            region2.SetPath(path2);
                        }

                        region1.Op(region2, regionOp);

                        canvas.Save();
                        canvas.ClipRegion(region1);
                        canvas.DrawPaint(fillPaint);
                        canvas.Restore();
                    }
            }
        }
Exemplo n.º 12
0
        public bool HitTest(Point p, IShape shape)
        {
            var stroke = shape.Stroke;

            if (stroke is not null && stroke.Width < 4)
            {
                stroke = new Stroke(color: stroke.Color, width: 4);
            }
            using var path = new SKPath();
            path.AddOval(shape.Bounds.ToSk());

            using var paint = new SKPaint()
                              .SetStroke(stroke)
                              .SetFill(shape.Fill)
                              .SetPaintStyle(stroke, shape.Fill);

            using var fillPath = paint.GetFillPath(path);
            using var region   = new SKRegion(fillPath);
            return(region.Contains((int)p.X, (int)p.Y));
        }
Exemplo n.º 13
0
        public void ClipIteratorHasCorrectRects()
        {
            var rectA = SKRectI.Create(10, 10, 100, 100);
            var rectB = SKRectI.Create(50, 50, 100, 100);

            using var region = new SKRegion(rectA);
            region.Op(rectB, SKRegionOperation.Union);

            using var iterator = region.CreateClipIterator(SKRectI.Create(5, 5, 65, 65));

            Assert.True(iterator.Next(out var rect));
            Assert.Equal(SKRectI.Create(10, 10, 100, 40), rect);

            Assert.True(iterator.Next(out rect));
            Assert.Equal(SKRectI.Create(10, 50, 140, 60), rect);

            Assert.False(iterator.Next(out rect));
            Assert.Equal(SKRect.Empty, rect);

            Assert.False(iterator.Next(out rect));
            Assert.Equal(SKRect.Empty, rect);
        }
Exemplo n.º 14
0
        public void SpanIteratorHasCorrectIntercepts()
        {
            var rectA = SKRectI.Create(10, 10, 100, 100);
            var rectB = SKRectI.Create(50, 50, 100, 100);

            using var region = new SKRegion(rectA);
            region.Op(rectB, SKRegionOperation.Union);

            using var iterator = region.CreateSpanIterator(30, 5, 200);

            Assert.True(iterator.Next(out var left, out var right));
            Assert.Equal(10, left);
            Assert.Equal(110, right);

            Assert.False(iterator.Next(out left, out right));
            Assert.Equal(0, left);
            Assert.Equal(0, right);

            Assert.False(iterator.Next(out left, out right));
            Assert.Equal(0, left);
            Assert.Equal(0, right);
        }
Exemplo n.º 15
0
        public Region(Rectangle rect)
        {
            SKRectI skRectI = new SKRectI(rect.Left, rect.Top, rect.Right, rect.Bottom);

            skRegion = new SKRegion(skRectI);
        }
Exemplo n.º 16
0
 internal ClipIterator(SKRegion region, SKRectI clip)
     : base(SkiaApi.sk_region_cliperator_new(region.Handle, &clip), true)
 {
     this.region = region;
     this.clip   = clip;
 }
Exemplo n.º 17
0
 internal RectIterator(SKRegion region)
     : base(SkiaApi.sk_region_iterator_new(region.Handle), true)
 {
     this.region = region;
 }
Exemplo n.º 18
0
        public void DrawImage(SKCanvas canvas, SKRect rect_Card)
        {
            SKPath  gp_Card;
            SKPaint tempPen;

            SKPoint[] pts;
            int       int_Temp;
            SKMatrix  tmp_Matrix;
            SKRegion  reg_Temp;
            SKPoint   pt_Center;

            pt_Center = new SKPoint(rect_Card.Left + (rect_Card.Width / 2), rect_Card.Top + (rect_Card.Height / 2) + (rect_Card.Width / 100));
            SKPaint textPaint;
            SKPaint textBorder;

            switch (Category)
            {
            case EnumCompleteCategories.Accident:
                gp_Card = new SKPath();
                gp_Card.AddLine(System.Convert.ToInt32(((rect_Card.Left + (rect_Card.Width / 2)) - (rect_Card.Width / 8))), System.Convert.ToInt32(((rect_Card.Top + (rect_Card.Height / 2)) - (rect_Card.Height / 10))), System.Convert.ToInt32((rect_Card.Left + (rect_Card.Width / 2) + (rect_Card.Width / 8))), System.Convert.ToInt32(((rect_Card.Top + (rect_Card.Height / 2)) - (rect_Card.Height / 10))), true);
                gp_Card.AddLine(System.Convert.ToInt32((rect_Card.Left + ((rect_Card.Width * 3) / 4))), System.Convert.ToInt32((rect_Card.Top + (rect_Card.Height / 2))), System.Convert.ToInt32((rect_Card.Left + ((rect_Card.Width * 9) / 10))), System.Convert.ToInt32((rect_Card.Top + (rect_Card.Height / 2))));
                gp_Card.AddLine(System.Convert.ToInt32((rect_Card.Left + ((rect_Card.Width * 9) / 10))), System.Convert.ToInt32((rect_Card.Top + (rect_Card.Height / 2) + (rect_Card.Height / 8))), System.Convert.ToInt32((rect_Card.Left + (rect_Card.Width / 10))), System.Convert.ToInt32((rect_Card.Top + (rect_Card.Height / 2) + (rect_Card.Height / 8))));
                gp_Card.AddLine(System.Convert.ToInt32((rect_Card.Left + (rect_Card.Width / 10))), System.Convert.ToInt32((rect_Card.Top + (rect_Card.Height / 2))), System.Convert.ToInt32((rect_Card.Left + (rect_Card.Width / 4))), System.Convert.ToInt32((rect_Card.Top + (rect_Card.Height / 2))));
                gp_Card.Close();     // i think
                canvas.DrawPath(gp_Card, _basicPen);
                gp_Card = new SKPath();
                gp_Card.AddOval(SKRect.Create((rect_Card.Left + (rect_Card.Width / 4)) - (rect_Card.Width / 12), (rect_Card.Top + (rect_Card.Height / 2) + (rect_Card.Height / 8)) - (rect_Card.Width / 12), rect_Card.Width / 6, rect_Card.Width / 6));
                canvas.DrawPath(gp_Card, _whitePaint);
                canvas.DrawPath(gp_Card, _basicPen);
                gp_Card = new SKPath();
                gp_Card.AddOval(SKRect.Create((rect_Card.Left + ((rect_Card.Width * 3) / 4)) - (rect_Card.Width / 12), (rect_Card.Top + (rect_Card.Height / 2) + (rect_Card.Height / 8)) - (rect_Card.Width / 12), rect_Card.Width / 6, rect_Card.Width / 6));
                canvas.DrawPath(gp_Card, _whitePaint);
                canvas.DrawPath(gp_Card, _basicPen);
                tempPen = MiscHelpers.GetStrokePaint(SKColors.Red, rect_Card.Width / 30);
                canvas.DrawLine(System.Convert.ToInt32((rect_Card.Left + ((rect_Card.Width * 3) / 4))), System.Convert.ToInt32((rect_Card.Top + (rect_Card.Height / 2))), System.Convert.ToInt32((rect_Card.Left + ((rect_Card.Width * 19) / 20))), System.Convert.ToInt32((rect_Card.Top + (rect_Card.Height / 2) + (rect_Card.Height / 10))), tempPen);
                canvas.DrawLine(System.Convert.ToInt32((rect_Card.Left + ((rect_Card.Width * 3) / 4))), System.Convert.ToInt32((rect_Card.Top + (rect_Card.Height / 2) + (rect_Card.Height / 10))), System.Convert.ToInt32((rect_Card.Left + ((rect_Card.Width * 19) / 20))), System.Convert.ToInt32((rect_Card.Top + (rect_Card.Height / 2))), tempPen);
                break;

            case EnumCompleteCategories.OutOfGas:
                tempPen  = MiscHelpers.GetStrokePaint(SKColors.Black, rect_Card.Height / 40);
                int_Temp = (int)rect_Card.Width;
                gp_Card  = new SKPath();
                gp_Card.AddArc(SKRect.Create(rect_Card.Left - (int_Temp / 2) + (rect_Card.Width / 2), rect_Card.Top + (rect_Card.Height / 3), int_Temp, int_Temp), -135, 90);
                canvas.DrawPath(gp_Card, tempPen);
                tempPen           = MiscHelpers.GetStrokePaint(SKColors.Red, rect_Card.Height / 40);
                tempPen.StrokeCap = SKStrokeCap.Round;     // strokejoin did not help one bit
                canvas.DrawLine(rect_Card.Left + (rect_Card.Width / 2), rect_Card.Top + (rect_Card.Height / 3) + (int_Temp / 2), rect_Card.Width / 3.5f, rect_Card.Height / 2.16f, tempPen);
                var ThisPaint = MiscHelpers.GetTextPaint(SKColors.Red, rect_Card.Height / 4, "Ariel");
                ThisPaint.FakeBoldText = true;
                canvas.DrawText("E", rect_Card.Left + (rect_Card.Width / 10), rect_Card.Top + (rect_Card.Height / 3), ThisPaint);
                ThisPaint = MiscHelpers.GetTextPaint(SKColors.Black, rect_Card.Height / 4, "Ariel");
                ThisPaint.FakeBoldText = true;
                canvas.DrawText("F", rect_Card.Left + ((rect_Card.Width * 15) / 20), rect_Card.Top + (rect_Card.Height / 3), ThisPaint);
                break;

            case EnumCompleteCategories.FlatTire:
                gp_Card = new SKPath();
                gp_Card.AddOval(SKRect.Create(rect_Card.Left + (rect_Card.Width / 6), pt_Center.Y - ((rect_Card.Width * 4) / 12), (rect_Card.Width * 4) / 6, (rect_Card.Width * 4) / 6));
                reg_Temp = MiscHelpers.GetNewRegion(SKRect.Create(rect_Card.Left + (rect_Card.Width / 6), (pt_Center.Y - ((rect_Card.Width * 4) / 12)) + ((((rect_Card.Width * 4) / 6) * 5) / 6), (rect_Card.Width * 4) / 6, (rect_Card.Width * 4) / 6));
                var OtherRegion = new SKRegion(reg_Temp);
                reg_Temp.SetPath(gp_Card);
                canvas.DrawRegion(reg_Temp, _redFill);
                reg_Temp.SetPath(gp_Card, OtherRegion);
                canvas.DrawRegion(reg_Temp, _whitePaint);
                gp_Card = new SKPath();
                gp_Card.AddOval(SKRect.Create(rect_Card.Left + ((rect_Card.Width * 2) / 6), pt_Center.Y - ((rect_Card.Width * 2) / 12), (rect_Card.Width * 2) / 6, (rect_Card.Width * 2) / 6));
                canvas.DrawPath(gp_Card, _whitePaint);
                gp_Card = new SKPath();
                gp_Card.AddOval(SKRect.Create(rect_Card.Left + (rect_Card.Width / 3) + (rect_Card.Width / 12), pt_Center.Y - (rect_Card.Width / 12), rect_Card.Width / 6, rect_Card.Width / 6));
                canvas.DrawPath(gp_Card, _blackPaint);
                break;

            case EnumCompleteCategories.SpeedLimit:
                textPaint  = MiscHelpers.GetTextPaint(SKColors.Black, rect_Card.Height / 3);
                textBorder = MiscHelpers.GetStrokePaint(SKColors.Black, 1);     // for speed limit, 1 is fine
                canvas.DrawBorderText("50", TextExtensions.EnumLayoutOptions.Center, TextExtensions.EnumLayoutOptions.Center, textPaint, textBorder, rect_Card);
                tempPen = MiscHelpers.GetStrokePaint(SKColors.Red, rect_Card.Width / 10);
                gp_Card = new SKPath();
                gp_Card.AddOval(SKRect.Create(rect_Card.Left + (rect_Card.Width / 8), (rect_Card.Top + (rect_Card.Height / 2)) - ((rect_Card.Width * 3) / 8), (rect_Card.Width * 3) / 4, (rect_Card.Width * 3) / 4));
                canvas.DrawPath(gp_Card, tempPen);
                break;

            case EnumCompleteCategories.Stop:
                gp_Card = new SKPath();
                gp_Card.AddOval(SKRect.Create((rect_Card.Left + (rect_Card.Width / 2)) - (rect_Card.Width / 6), (rect_Card.Top + (rect_Card.Height / 2)) - (rect_Card.Width / 6), rect_Card.Width / 3, rect_Card.Width / 3));
                canvas.DrawPath(gp_Card, _grayPaint);
                tmp_Matrix = SKMatrix.MakeTranslation(0, (rect_Card.Width * 5) / 13);
                gp_Card.Transform(tmp_Matrix);
                canvas.DrawPath(gp_Card, _grayPaint);
                tmp_Matrix = SKMatrix.MakeTranslation(0, (-rect_Card.Width * 10) / 13);
                gp_Card.Transform(tmp_Matrix);
                canvas.DrawPath(gp_Card, _redFill);
                break;

            case EnumCompleteCategories.Repairs:
                gp_Card  = new SKPath();
                reg_Temp = MiscHelpers.GetNewRegion(SKRect.Create(rect_Card.Left + (rect_Card.Width / 3), rect_Card.Top, rect_Card.Width / 3, rect_Card.Height / 3));
                gp_Card.AddOval(SKRect.Create(rect_Card.Left + (rect_Card.Width / 6), rect_Card.Top + (rect_Card.Height / 10), (rect_Card.Width * 4) / 6, (rect_Card.Height * 3) / 7));
                gp_Card.AddRect(SKRect.Create(rect_Card.Left + (rect_Card.Width / 3), rect_Card.Top + (rect_Card.Height / 2), rect_Card.Width / 3, (rect_Card.Height * 4) / 9));
                var OtherRegion2 = new SKRegion(reg_Temp);
                reg_Temp.SetPath(gp_Card);
                canvas.DrawRegion(reg_Temp, _greenPaint);
                reg_Temp.SetPath(gp_Card, OtherRegion2);
                canvas.DrawRegion(reg_Temp, _whitePaint);
                gp_Card = new SKPath();
                gp_Card.AddRect(SKRect.Create((rect_Card.Left + (rect_Card.Width / 2)) - (rect_Card.Width / 12), rect_Card.Top + (rect_Card.Height / 8), rect_Card.Width / 6, rect_Card.Height / 7));
                canvas.DrawPath(gp_Card, _blackPaint);
                break;

            case EnumCompleteCategories.Gasoline:
                gp_Card = new SKPath();
                gp_Card.AddLine(System.Convert.ToInt32((rect_Card.Left + (rect_Card.Width / 4))), System.Convert.ToInt32((rect_Card.Top + (rect_Card.Height / 4))), System.Convert.ToInt32((rect_Card.Left + (rect_Card.Width / 2))), System.Convert.ToInt32((rect_Card.Top + (rect_Card.Height / 4))), true);
                gp_Card.AddLine(System.Convert.ToInt32((rect_Card.Left + (rect_Card.Width / 2))), System.Convert.ToInt32((rect_Card.Top + (rect_Card.Height / 4))), System.Convert.ToInt32((rect_Card.Left + ((rect_Card.Width * 3) / 4))), System.Convert.ToInt32((rect_Card.Top + (rect_Card.Height / 3))));
                gp_Card.AddLine(System.Convert.ToInt32((rect_Card.Left + ((rect_Card.Width * 3) / 4))), System.Convert.ToInt32((rect_Card.Top + ((rect_Card.Height * 3) / 4))), System.Convert.ToInt32((rect_Card.Left + (rect_Card.Width / 4))), System.Convert.ToInt32((rect_Card.Top + ((rect_Card.Height * 3) / 4))));
                gp_Card.Close();
                canvas.DrawPath(gp_Card, _greenPaint);
                gp_Card = new SKPath();
                gp_Card.AddRect(SKRect.Create(rect_Card.Left, rect_Card.Top, rect_Card.Width / 8, rect_Card.Height / 20));
                tmp_Matrix        = SKMatrix.MakeRotationDegrees(23, rect_Card.Left, rect_Card.Top);
                tmp_Matrix.TransX = (rect_Card.Width * 20) / 30;
                tmp_Matrix.TransY = rect_Card.Height / 5.4f;
                gp_Card.Transform(tmp_Matrix);
                canvas.DrawPath(gp_Card, _greenPaint);
                break;

            case EnumCompleteCategories.Spare:
                gp_Card = new SKPath();
                gp_Card.AddOval(SKRect.Create(rect_Card.Left + (rect_Card.Width / 6), pt_Center.Y - ((rect_Card.Width * 4) / 12), (rect_Card.Width * 4) / 6, (rect_Card.Width * 4) / 6));
                reg_Temp = MiscHelpers.GetNewRegion(SKRect.Create(rect_Card.Left + (rect_Card.Width / 6), (pt_Center.Y - ((rect_Card.Width * 4) / 12)) + ((((rect_Card.Width * 4) / 6) * 5) / 6), (rect_Card.Width * 4) / 6, (rect_Card.Width * 4) / 6));
                reg_Temp.SetPath(gp_Card);
                canvas.DrawRegion(reg_Temp, _greenPaint);
                gp_Card = new SKPath();
                gp_Card.AddOval(SKRect.Create(rect_Card.Left + ((rect_Card.Width * 2) / 6), pt_Center.Y - ((rect_Card.Width * 2) / 12), (rect_Card.Width * 2) / 6, (rect_Card.Width * 2) / 6));
                canvas.DrawPath(gp_Card, _whitePaint);
                gp_Card = new SKPath();
                gp_Card.AddOval(SKRect.Create(rect_Card.Left + (rect_Card.Width / 3) + (rect_Card.Width / 12), pt_Center.Y - (rect_Card.Width / 12), rect_Card.Width / 6, rect_Card.Width / 6));
                canvas.DrawPath(gp_Card, _blackPaint);
                break;

            case EnumCompleteCategories.EndOfLimit:
                textPaint              = MiscHelpers.GetTextPaint(SKColors.Gray, rect_Card.Height / 3);
                textBorder             = MiscHelpers.GetStrokePaint(SKColors.Black, 1); // for speed limit, 1 is fine
                textPaint.FakeBoldText = true;
                canvas.DrawBorderText("50", TextExtensions.EnumLayoutOptions.Center, TextExtensions.EnumLayoutOptions.Center, textPaint, textBorder, rect_Card);
                tempPen = MiscHelpers.GetStrokePaint(SKColors.Green, rect_Card.Width / 10);
                gp_Card = new SKPath();
                gp_Card.AddOval(SKRect.Create(rect_Card.Left + (rect_Card.Width / 8), (rect_Card.Top + (rect_Card.Height / 2)) - ((rect_Card.Width * 3) / 8), (rect_Card.Width * 3) / 4, (rect_Card.Width * 3) / 4));
                canvas.DrawPath(gp_Card, tempPen);
                gp_Card = new SKPath();
                gp_Card.AddLine(System.Convert.ToInt32((rect_Card.Left + (rect_Card.Width / 2))), System.Convert.ToInt32(((rect_Card.Top + (rect_Card.Height / 2)) - ((rect_Card.Width * 3) / 8))), System.Convert.ToInt32((rect_Card.Left + (rect_Card.Width / 2))), System.Convert.ToInt32((rect_Card.Top + (rect_Card.Height / 2) + ((rect_Card.Width * 3) / 8))), true);
                tmp_Matrix = SKMatrix.MakeRotationDegrees(45, pt_Center.X, pt_Center.Y);
                gp_Card.Transform(tmp_Matrix);
                canvas.DrawPath(gp_Card, tempPen);
                break;

            case EnumCompleteCategories.Roll:
                gp_Card = new SKPath();
                gp_Card.AddOval(SKRect.Create((rect_Card.Left + (rect_Card.Width / 2)) - (rect_Card.Width / 6), (rect_Card.Top + (rect_Card.Height / 2)) - (rect_Card.Width / 6), rect_Card.Width / 3, rect_Card.Width / 3));
                canvas.DrawPath(gp_Card, _grayPaint);
                tmp_Matrix = SKMatrix.MakeTranslation(0, (rect_Card.Width * 5) / 13);
                gp_Card.Transform(tmp_Matrix);
                canvas.DrawPath(gp_Card, _greenPaint);
                tmp_Matrix = SKMatrix.MakeTranslation(0, (-rect_Card.Width * 10) / 13);
                gp_Card.Transform(tmp_Matrix);
                canvas.DrawPath(gp_Card, _grayPaint);
                break;

            case EnumCompleteCategories.DrivingAce:
                gp_Card = new SKPath();
                gp_Card.AddOval(SKRect.Create(rect_Card.Left + (rect_Card.Width / 10), (rect_Card.Top + (rect_Card.Height / 2)) - ((rect_Card.Width * 4) / 10), (rect_Card.Width * 8) / 10, (rect_Card.Width * 8) / 10));
                tempPen = MiscHelpers.GetStrokePaint(SKColors.Blue, rect_Card.Width / 20);
                canvas.DrawPath(gp_Card, tempPen);
                tmp_Matrix = SKMatrix.MakeRotationDegrees(120, pt_Center.X, pt_Center.Y);
                gp_Card    = new SKPath();
                gp_Card.AddLine(System.Convert.ToInt32(((rect_Card.Left + (rect_Card.Width / 2)) - (rect_Card.Width / 25))), System.Convert.ToInt32((rect_Card.Top + (rect_Card.Height / 2) + ((rect_Card.Width * 4) / 10))), System.Convert.ToInt32(((rect_Card.Left + (rect_Card.Width / 2)) - (rect_Card.Width / 15))), System.Convert.ToInt32((rect_Card.Top + (rect_Card.Height / 2))), true);
                gp_Card.AddLine(System.Convert.ToInt32((rect_Card.Left + (rect_Card.Width / 2) + (rect_Card.Width / 15))), System.Convert.ToInt32((rect_Card.Top + (rect_Card.Height / 2))), System.Convert.ToInt32((rect_Card.Left + (rect_Card.Width / 2) + (rect_Card.Width / 25))), System.Convert.ToInt32((rect_Card.Top + (rect_Card.Height / 2) + ((rect_Card.Width * 4) / 10))));
                gp_Card.Close();
                canvas.DrawPath(gp_Card, _safefyPaint);
                gp_Card.Transform(tmp_Matrix);
                canvas.DrawPath(gp_Card, _safefyPaint);
                gp_Card.Transform(tmp_Matrix);
                canvas.DrawPath(gp_Card, _safefyPaint);
                gp_Card = new SKPath();
                gp_Card.AddOval(SKRect.Create((rect_Card.Left + (rect_Card.Width / 2)) - (rect_Card.Width / 8), (rect_Card.Top + (rect_Card.Height / 2)) - (rect_Card.Width / 8), rect_Card.Width / 4, rect_Card.Width / 4));
                canvas.DrawPath(gp_Card, _whitePaint);
                canvas.DrawPath(gp_Card, tempPen);
                break;

            case EnumCompleteCategories.ExtraTank:
                gp_Card = new SKPath();
                pts     = new SKPoint[3];
                pts[0]  = new SKPoint(rect_Card.Left + (rect_Card.Width / 4), (rect_Card.Top + (rect_Card.Height / 2)) - (rect_Card.Height / 8));
                pts[1]  = new SKPoint(rect_Card.Left + (rect_Card.Width / 6), rect_Card.Top + (rect_Card.Height / 2));
                pts[2]  = new SKPoint(rect_Card.Left + (rect_Card.Width / 4), rect_Card.Top + (rect_Card.Height / 2) + (rect_Card.Height / 8));
                var top1 = pts[0];
                gp_Card.MoveTo(pts[0]);
                gp_Card.QuadTo(pts[1], pts[2]);
                pts[0] = new SKPoint(rect_Card.Left + ((rect_Card.Width * 3) / 4), rect_Card.Top + (rect_Card.Height / 2) + (rect_Card.Height / 8));
                pts[1] = new SKPoint(rect_Card.Left + ((rect_Card.Width * 5) / 6), rect_Card.Top + (rect_Card.Height / 2));
                pts[2] = new SKPoint(rect_Card.Left + ((rect_Card.Width * 3) / 4), (rect_Card.Top + (rect_Card.Height / 2)) - (rect_Card.Height / 8));
                var bottom2 = pts[0];
                gp_Card.MoveTo(pts[0]);
                gp_Card.QuadTo(pts[1], pts[2]);
                var tempRect = new SKRect(top1.X, top1.Y, bottom2.X, bottom2.Y);
                gp_Card.Close();
                canvas.DrawPath(gp_Card, _safefyPaint);
                gp_Card = new SKPath();
                gp_Card.AddRect(SKRect.Create(rect_Card.Left + ((rect_Card.Width * 2) / 5), (rect_Card.Top + (rect_Card.Height / 2)) - (rect_Card.Height / 8) - (rect_Card.Height / 20), rect_Card.Width / 5, rect_Card.Height / 30));
                canvas.DrawPath(gp_Card, _safefyPaint);
                canvas.DrawRect(tempRect, _safefyPaint);
                break;

            case EnumCompleteCategories.PunctureProof:
                gp_Card = new SKPath();
                gp_Card.AddOval(SKRect.Create(rect_Card.Left + (rect_Card.Width / 6), pt_Center.Y - ((rect_Card.Width * 4) / 12), (rect_Card.Width * 4) / 6, (rect_Card.Width * 4) / 6));
                reg_Temp = MiscHelpers.GetNewRegion(SKRect.Create(rect_Card.Left + (rect_Card.Width / 6), (pt_Center.Y - ((rect_Card.Width * 4) / 12)) + ((((rect_Card.Width * 4) / 6) * 5) / 6), (rect_Card.Width * 4) / 6, (rect_Card.Width * 4) / 6));
                reg_Temp.SetPath(gp_Card);
                canvas.DrawRegion(reg_Temp, _safefyPaint);
                gp_Card = new SKPath();
                gp_Card.AddOval(SKRect.Create(rect_Card.Left + ((rect_Card.Width * 2) / 6), pt_Center.Y - ((rect_Card.Width * 2) / 12), (rect_Card.Width * 2) / 6, (rect_Card.Width * 2) / 6));
                canvas.DrawPath(gp_Card, _whitePaint);
                gp_Card = new SKPath();
                gp_Card.AddOval(SKRect.Create(rect_Card.Left + (rect_Card.Width / 3) + (rect_Card.Width / 12), pt_Center.Y - (rect_Card.Width / 12), rect_Card.Width / 6, rect_Card.Width / 6));
                canvas.DrawPath(gp_Card, _blackPaint);
                tmp_Matrix = SKMatrix.MakeTranslation(rect_Card.Width / 12, 0);
                gp_Card    = new SKPath();
                gp_Card.AddLine(rect_Card.Left, rect_Card.Top + (rect_Card.Height * 4 / 5) + (rect_Card.Width / 24), rect_Card.Left + (rect_Card.Width / 24), rect_Card.Top + (rect_Card.Height * 4 / 5 - (rect_Card.Width / 24)), true);
                gp_Card.AddLine(System.Convert.ToInt32((rect_Card.Left + (rect_Card.Width / 24))), System.Convert.ToInt32(((rect_Card.Top + ((rect_Card.Height * 4) / 5)) - (rect_Card.Width / 24))), System.Convert.ToInt32((rect_Card.Left + (rect_Card.Width / 12))), System.Convert.ToInt32((rect_Card.Top + ((rect_Card.Height * 4) / 5) + (rect_Card.Width / 24))));
                for (var int_Count = 1; int_Count <= 10; int_Count++)
                {
                    gp_Card.Transform(tmp_Matrix);
                    canvas.DrawPath(gp_Card, _safefyPaint);
                }
                break;

            case EnumCompleteCategories.RightOfWay:
                tempPen = MiscHelpers.GetStrokePaint(SKColors.Blue, rect_Card.Width / 50);
                gp_Card = new SKPath();
                gp_Card.AddLine(System.Convert.ToInt32((rect_Card.Left + (rect_Card.Width / 10))), System.Convert.ToInt32(((rect_Card.Top + (rect_Card.Height / 2)) - (rect_Card.Height / 5))), System.Convert.ToInt32((rect_Card.Left + ((rect_Card.Width * 9) / 10))), System.Convert.ToInt32((rect_Card.Top + (rect_Card.Height / 2))), true);
                canvas.DrawPath(gp_Card, tempPen);
                gp_Card = new SKPath();
                gp_Card.AddLine(System.Convert.ToInt32((rect_Card.Left + (rect_Card.Width / 10))), System.Convert.ToInt32(((rect_Card.Top + (rect_Card.Height / 2)) - (rect_Card.Height / 10))), System.Convert.ToInt32((rect_Card.Left + ((rect_Card.Width * 9) / 10))), System.Convert.ToInt32(((rect_Card.Top + (rect_Card.Height / 2)) - (rect_Card.Height / 10))), true);
                canvas.DrawPath(gp_Card, tempPen);
                gp_Card = new SKPath();
                gp_Card.AddLine(System.Convert.ToInt32((rect_Card.Left + (rect_Card.Width / 10))), System.Convert.ToInt32((rect_Card.Top + (rect_Card.Height / 2))), System.Convert.ToInt32((rect_Card.Left + ((rect_Card.Width * 9) / 10))), System.Convert.ToInt32(((rect_Card.Top + (rect_Card.Height / 2)) - (rect_Card.Height / 5))), true);
                canvas.DrawPath(gp_Card, tempPen);
                gp_Card = new SKPath();
                canvas.DrawPath(gp_Card, _whitePaint);
                gp_Card = new SKPath();
                pts     = new SKPoint[3];
                pts[0]  = new SKPoint((rect_Card.Left + (rect_Card.Width / 2)) - (rect_Card.Width / 6), (rect_Card.Top + (rect_Card.Height / 2)) - (rect_Card.Height / 5));
                pts[1]  = new SKPoint(rect_Card.Left + (rect_Card.Width / 2), (rect_Card.Top + (rect_Card.Height / 2)) - (rect_Card.Height / 4));
                pts[2]  = new SKPoint(rect_Card.Left + (rect_Card.Width / 2) + (rect_Card.Width / 6), (rect_Card.Top + (rect_Card.Height / 2)) - (rect_Card.Height / 5));
                gp_Card.MoveTo(pts[0]);
                gp_Card.QuadTo(pts[1], pts[2]);
                gp_Card.AddLine(System.Convert.ToInt32((rect_Card.Left + (rect_Card.Width / 2) + (rect_Card.Width / 6))), System.Convert.ToInt32((rect_Card.Top + (rect_Card.Height / 2))), System.Convert.ToInt32(((rect_Card.Left + (rect_Card.Width / 2)) - (rect_Card.Width / 6))), System.Convert.ToInt32((rect_Card.Top + (rect_Card.Height / 2))));
                gp_Card.Close();
                canvas.DrawPath(gp_Card, _safefyPaint);
                gp_Card = new SKPath();
                pts     = new SKPoint[3];
                pts[0]  = new SKPoint((rect_Card.Left + (rect_Card.Width / 2)) - (rect_Card.Width / 12), (rect_Card.Top + (rect_Card.Height / 2)) - (rect_Card.Height / 8));
                pts[1]  = new SKPoint(rect_Card.Left + (rect_Card.Width / 2), (rect_Card.Top + (rect_Card.Height / 2)) - (rect_Card.Height / 6));
                pts[2]  = new SKPoint(rect_Card.Left + (rect_Card.Width / 2) + (rect_Card.Width / 12), (rect_Card.Top + (rect_Card.Height / 2)) - (rect_Card.Height / 8));
                gp_Card.MoveTo(pts[0]);
                gp_Card.QuadTo(pts[1], pts[2]);
                gp_Card.AddLine(System.Convert.ToInt32((rect_Card.Left + (rect_Card.Width / 2) + (rect_Card.Width / 12))), System.Convert.ToInt32(((rect_Card.Top + (rect_Card.Height / 2)) - (rect_Card.Height / 20))), System.Convert.ToInt32(((rect_Card.Left + (rect_Card.Width / 2)) - (rect_Card.Width / 12))), System.Convert.ToInt32(((rect_Card.Top + (rect_Card.Height / 2)) - (rect_Card.Height / 20))));
                gp_Card.Close();
                canvas.DrawPath(gp_Card, _whitePaint);
                canvas.DrawRect(SKRect.Create(rect_Card.Left + (rect_Card.Width / 4), rect_Card.Top + (rect_Card.Height / 2), rect_Card.Width / 2, rect_Card.Height / 10), _blackPaint);
                break;

            case EnumCompleteCategories.Distance25:
                DrawDistanceCard(canvas, "25", rect_Card);
                break;

            case EnumCompleteCategories.Distance50:
                DrawDistanceCard(canvas, "50", rect_Card);
                break;

            case EnumCompleteCategories.Distance75:
                DrawDistanceCard(canvas, "75", rect_Card);
                break;

            case EnumCompleteCategories.Distance100:
                DrawDistanceCard(canvas, "100", rect_Card);
                break;

            case EnumCompleteCategories.Distance200:
                DrawDistanceCard(canvas, "200", rect_Card);
                break;

            default:
                throw new BasicBlankException("Nothing Found");
            }
        }
Exemplo n.º 19
0
 internal SpanIterator(SKRegion region, int y, int left, int right)
     : base(SkiaApi.sk_region_spanerator_new(region.Handle, y, left, right), true)
 {
 }
Exemplo n.º 20
0
        public void QuickContainsReturnsTrueIfItDoesContain()
        {
            using var region = new SKRegion(new SKRectI(25, 25, 50, 50));

            Assert.True(region.QuickContains(new SKRectI(30, 30, 40, 40)));
        }
Exemplo n.º 21
0
 public Region()
 {
     skRegion = new SKRegion();
 }
Exemplo n.º 22
0
        public void ContainsReturnsFalseIfItDoesNotContainPoint()
        {
            var region = new SKRegion(new SKRectI(30, 30, 40, 40));

            Assert.False(region.Contains(60, 60));
        }
Exemplo n.º 23
0
        public void ContainsReturnsTrueIfItDoesContainPoint()
        {
            var region = new SKRegion(new SKRectI(25, 25, 50, 50));

            Assert.True(region.Contains(40, 40));
        }
Exemplo n.º 24
0
        protected override void OnDraw(SKImageInfo info, SKCanvas canvas)
        {
            if (CanvasSizeChanged)
            {
                _outterRect = SKRect.Create(
                    _outterWidthRatio * info.Width / -2,
                    _outterHeightRatio * info.Height / -2,
                    _outterWidthRatio * info.Width,
                    _outterHeightRatio * info.Height);
            }

            if (_firstDraw)
            {
                if (IsSquare)
                {
                    float cropRectLength = Math.Min(_initCropperWidthRatio * info.Width, _initCropperHeightRatio * info.Height);

                    _cropRect = SKRect.Create(cropRectLength / -2, cropRectLength / -2, cropRectLength, cropRectLength);
                }
                else
                {
                    _cropRect = SKRect.Create(
                        _initCropperWidthRatio * info.Width / -2,
                        _initCropperHeightRatio * info.Height / -2,
                        _initCropperWidthRatio * info.Width,
                        _initCropperHeightRatio * info.Height);
                }
                _firstDraw = false;
            }


            //Draw Dim Bg
            using SKRegion bgRegion = new SKRegion(SKRectI.Round(_outterRect));

            bgRegion.Op(SKRectI.Round(_cropRect), SKRegionOperation.Difference);

            canvas.DrawRegion(bgRegion, _outterRectPaint);

            //Draw CropRect
            canvas.DrawRect(_cropRect, _cropperRectPaint);

            //Draw Corner

            using SKPath cornerPath = new SKPath();

            //左上角
            cornerPath.MoveTo(_cropRect.Left + _cornerLength, _cropRect.Top);
            cornerPath.LineTo(_cropRect.Left, _cropRect.Top);
            cornerPath.LineTo(_cropRect.Left, _cropRect.Top + _cornerLength);

            //右上角
            cornerPath.MoveTo(_cropRect.Right - _cornerLength, _cropRect.Top);
            cornerPath.LineTo(_cropRect.Right, _cropRect.Top);
            cornerPath.LineTo(_cropRect.Right, _cropRect.Top + _cornerLength);

            //左下角
            cornerPath.MoveTo(_cropRect.Left + _cornerLength, _cropRect.Bottom);
            cornerPath.LineTo(_cropRect.Left, _cropRect.Bottom);
            cornerPath.LineTo(_cropRect.Left, _cropRect.Bottom - _cornerLength);

            //右下角
            cornerPath.MoveTo(_cropRect.Right - _cornerLength, _cropRect.Bottom);
            cornerPath.LineTo(_cropRect.Right, _cropRect.Bottom);
            cornerPath.LineTo(_cropRect.Right, _cropRect.Bottom - _cornerLength);

            canvas.DrawPath(cornerPath, _cornerPaint);
        }
        void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            float xCenter = info.Width / 2;
            float yCenter = info.Height / 2;
            float radius  = 0.24f * Math.Min(info.Width, info.Height);

            using (SKRegion wholeScreenRegion = new SKRegion())
            {
                wholeScreenRegion.SetRect(new SKRectI(0, 0, info.Width, info.Height));

                using (SKRegion leftRegion = new SKRegion(wholeScreenRegion))
                    using (SKRegion rightRegion = new SKRegion(wholeScreenRegion))
                        using (SKRegion topRegion = new SKRegion(wholeScreenRegion))
                            using (SKRegion bottomRegion = new SKRegion(wholeScreenRegion))
                            {
                                using (SKPath circlePath = new SKPath())
                                {
                                    // Make basic circle path
                                    circlePath.AddCircle(xCenter, yCenter, radius);

                                    // Left leaf
                                    circlePath.Transform(SKMatrix.MakeTranslation(-radius, 0));
                                    leftRegion.SetPath(circlePath);

                                    // Right leaf
                                    circlePath.Transform(SKMatrix.MakeTranslation(2 * radius, 0));
                                    rightRegion.SetPath(circlePath);

                                    // Make union of right with left
                                    leftRegion.Op(rightRegion, SKRegionOperation.Union);

                                    // Top leaf
                                    circlePath.Transform(SKMatrix.MakeTranslation(-radius, -radius));
                                    topRegion.SetPath(circlePath);

                                    // Combine with bottom leaf
                                    circlePath.Transform(SKMatrix.MakeTranslation(0, 2 * radius));
                                    bottomRegion.SetPath(circlePath);

                                    // Make union of top with bottom
                                    bottomRegion.Op(topRegion, SKRegionOperation.Union);

                                    // Exclusive-OR left and right with top and bottom
                                    leftRegion.Op(bottomRegion, SKRegionOperation.XOR);

                                    // Set that as clip region
                                    canvas.ClipRegion(leftRegion);

                                    // Set transform for drawing lines from center
                                    canvas.Translate(xCenter, yCenter);

                                    // Draw 360 lines
                                    for (double angle = 0; angle < 360; angle++)
                                    {
                                        float x = 2 * radius * (float)Math.Cos(Math.PI * angle / 180);
                                        float y = 2 * radius * (float)Math.Sin(Math.PI * angle / 180);

                                        using (SKPaint strokePaint = new SKPaint())
                                        {
                                            strokePaint.Color       = SKColors.Green;
                                            strokePaint.StrokeWidth = 2;

                                            canvas.DrawLine(0, 0, x, y, strokePaint);
                                        }
                                    }
                                }
                            }
            }
        }
Exemplo n.º 26
0
 public Region(GraphicsPath path)
 {
     skRegion = new SKRegion(path.skPath);
 }
        /// <summary>
        /// Process image pipeline
        /// <para>Region THEN Size THEN Rotation THEN Quality THEN Format</para>
        /// </summary>
        /// <param name="imageUri">The <see cref="Uri"/> of the source image</param>
        /// <param name="request">The parsed and validated IIIF Image API request</param>
        /// <param name="quality">Image output encoding quality settings</param>
        /// <param name="allowSizeAboveFull">Allow output image dimensions to exceed that of the source image</param>
        /// <param name="pdfMetadata">Optional PDF metadata fields</param>
        /// <returns></returns>
        public async Task <Stream> ProcessImage(Uri imageUri, ImageRequest request, Conf.ImageQuality quality, bool allowSizeAboveFull, Conf.PdfMetadata pdfMetadata)
        {
            var encodingStrategy = GetEncodingStrategy(request.Format);

            if (encodingStrategy == EncodingStrategy.Unknown)
            {
                throw new ArgumentException("Unsupported format", "format");
            }

            var loader = new ImageLoader {
                HttpClient = HttpClient, Log = Log
            };

            (var state, var imageRegion) = await loader.ExtractRegion(imageUri, request, allowSizeAboveFull, quality);

            using (imageRegion)
            {
                var expectedWidth  = state.OutputWidth;
                var expectedHeight = state.OutputHeight;
                var alphaType      = request.Quality == ImageQuality.bitonal ? SKAlphaType.Opaque : SKAlphaType.Premul;

                (var angle, var originX, var originY, var newImgWidth, var newImgHeight) = Rotate(expectedWidth, expectedHeight, request.Rotation.Degrees);

                using (var surface = SKSurface.Create(width: newImgWidth, height: newImgHeight, colorType: SKImageInfo.PlatformColorType, alphaType: alphaType))
                    using (var canvas = surface.Canvas)
                        using (var region = new SKRegion())
                        {
                            // If the rotation parameter includes mirroring ("!"), the mirroring is applied before the rotation.
                            if (request.Rotation.Mirror)
                            {
                                canvas.Translate(newImgWidth, 0);
                                canvas.Scale(-1, 1);
                            }

                            canvas.Translate(originX, originY);
                            canvas.RotateDegrees(angle, 0, 0);

                            // reset clip rects to rotated boundaries
                            region.SetRect(new SKRectI(0 - (int)originX, 0 - (int)originY, newImgWidth, newImgHeight));
                            canvas.ClipRegion(region);

                            // quality
                            if (request.Quality == ImageQuality.gray || request.Quality == ImageQuality.bitonal)
                            {
                                var contrast = request.Quality == ImageQuality.gray ? 0.1f : 1f;
                                using (var cf = SKColorFilter.CreateHighContrast(true, SKHighContrastConfigInvertStyle.NoInvert, contrast))
                                    using (var paint = new SKPaint())
                                    {
                                        paint.FilterQuality = SKFilterQuality.High;
                                        paint.ColorFilter   = cf;

                                        canvas.DrawImage(imageRegion, new SKRect(0, 0, expectedWidth, expectedHeight), paint);
                                    }
                            }
                            else
                            {
                                using (var paint = new SKPaint())
                                {
                                    paint.FilterQuality = SKFilterQuality.High;
                                    canvas.DrawImage(imageRegion, new SKRect(0, 0, expectedWidth, expectedHeight), paint);
                                }
                            }

                            return(Encode(surface,
                                          expectedWidth,
                                          expectedHeight,
                                          encodingStrategy,
                                          request.Format,
                                          quality.GetOutputFormatQuality(request.Format),
                                          pdfMetadata,
                                          state.HorizontalResolution,
                                          state.VerticalResolution));
                        }
            }
        }
Exemplo n.º 28
0
        /// <summary>
        /// Draws 3D border
        /// </summary>
        /// <param name="graph">Graphics to draw the border on.</param>
        /// <param name="borderSkin">Border skin object.</param>
        /// <param name="rect">Rectangle of the border.</param>
        /// <param name="backColor">Color of rectangle</param>
        /// <param name="backHatchStyle">Hatch style</param>
        /// <param name="backImage">Back Image</param>
        /// <param name="backImageWrapMode">Image mode</param>
        /// <param name="backImageTransparentColor">Image transparent color.</param>
        /// <param name="backImageAlign">Image alignment</param>
        /// <param name="backGradientStyle">Gradient type</param>
        /// <param name="backSecondaryColor">Gradient End Color</param>
        /// <param name="borderColor">Border Color</param>
        /// <param name="borderWidth">Border Width</param>
        /// <param name="borderDashStyle">Border Style</param>
        public virtual void DrawBorder(
            ChartGraphics graph,
            BorderSkin borderSkin,
            SKRect rect,
            SKColor backColor,
            ChartHatchStyle backHatchStyle,
            string backImage,
            ChartImageWrapMode backImageWrapMode,
            SKColor backImageTransparentColor,
            ChartImageAlignmentStyle backImageAlign,
            GradientStyle backGradientStyle,
            SKColor backSecondaryColor,
            SKColor borderColor,
            int borderWidth,
            ChartDashStyle borderDashStyle)
        {
            SKRect absolute = ChartGraphics.Round(rect);

            // Calculate shadow colors (0.2 - 0.6)
            float   colorDarkeningIndex = 0.3f + (0.4f * (borderSkin.PageColor.Red + borderSkin.PageColor.Green + borderSkin.PageColor.Blue) / 765f);
            SKColor shadowColor         = new(
                (byte)(backColor.Red * colorDarkeningIndex),
                (byte)(backColor.Green * colorDarkeningIndex),
                (byte)(backColor.Blue * colorDarkeningIndex));

            colorDarkeningIndex += 0.2f;
            SKColor shadowLightColor = new(
                (byte)(borderSkin.PageColor.Red * colorDarkeningIndex),
                (byte)(borderSkin.PageColor.Green * colorDarkeningIndex),
                (byte)(borderSkin.PageColor.Blue * colorDarkeningIndex));

            if (borderSkin.PageColor == SKColors.Transparent)
            {
                shadowLightColor = new SKColor(0, 0, 0, 60);
            }

            // Calculate rounded rect radius
            float radius = defaultRadiusSize;

            radius = Math.Max(radius, 2f * resolution / 96.0f);
            radius = Math.Min(radius, rect.Width / 2f);
            radius = Math.Min(radius, rect.Height / 2f);
            radius = (float)Math.Ceiling(radius);

            // Fill page background color
            using (SKPaint brush = new() { Color = borderSkin.PageColor, Style = SKPaintStyle.Fill })
            {
                graph.FillRectangle(brush, rect);
            }

            SKRect shadowRect;

            if (drawOutsideTopLeftShadow)
            {
                // Top/Left outside shadow
                shadowRect         = absolute;
                shadowRect.Left   -= radius * 0.3f;
                shadowRect.Top    -= radius * 0.3f;
                shadowRect.Right  -= radius * .3f;
                shadowRect.Bottom -= radius * .3f;
                graph.DrawRoundedRectShadowAbs(shadowRect, cornerRadius, radius, Color.FromArgb(128, SKColors.Black), borderSkin.PageColor, outsideShadowRate);
            }

            // Bottom/Right outside shadow
            shadowRect         = absolute;
            shadowRect.Left   += radius * 0.3f;
            shadowRect.Top    += radius * 0.3f;
            shadowRect.Right  -= radius * .3f;
            shadowRect.Bottom -= radius * .3f;
            graph.DrawRoundedRectShadowAbs(shadowRect, cornerRadius, radius, shadowLightColor, borderSkin.PageColor, outsideShadowRate);

            // Background
            shadowRect         = absolute;
            shadowRect.Right  -= radius * .3f;
            shadowRect.Bottom -= radius * .3f;
            SKPath path = ChartGraphics.CreateRoundedRectPath(shadowRect, cornerRadius);

            graph.DrawPathAbs(
                path,
                backColor,
                backHatchStyle,
                backImage,
                backImageWrapMode,
                backImageTransparentColor,
                backImageAlign,
                backGradientStyle,
                backSecondaryColor,
                borderColor,
                borderWidth,
                borderDashStyle,
                PenAlignment.Inset);

            // Dispose Graphic path
            if (path != null)
            {
                path.Dispose();
            }

            // Draw screws imitation in the corners of the farame
            if (drawScrews)
            {
                // Left/Top screw
                SKRect screwRect = SKRect.Empty;
                float  offset    = radius * 0.4f;
                screwRect.Left = shadowRect.Left + offset;
                screwRect.Top  = shadowRect.Top + offset;
                screwRect.Size = new(radius * 0.55f, screwRect.Width);
                DrawScrew(graph, screwRect);

                // Right/Top screw
                screwRect.Left = shadowRect.Right - offset - screwRect.Width;
                DrawScrew(graph, screwRect);

                // Right/Bottom screw
                screwRect.Left = shadowRect.Right - offset - screwRect.Width;
                screwRect.Top  = shadowRect.Bottom - offset - screwRect.Height;
                DrawScrew(graph, screwRect);

                // Left/Bottom screw
                screwRect.Left = shadowRect.Left + offset;
                screwRect.Top  = shadowRect.Bottom - offset - screwRect.Height;
                DrawScrew(graph, screwRect);
            }

            // Bottom/Right inner shadow
            SKRegion innerShadowRegion;

            if (drawBottomShadow)
            {
                shadowRect         = absolute;
                shadowRect.Right  -= radius * .3f;
                shadowRect.Bottom -= radius * .3f;
                innerShadowRegion  = new SKRegion(
                    ChartGraphics.CreateRoundedRectPath(
                        new SKRect(
                            shadowRect.Left - radius,
                            shadowRect.Top - radius,
                            shadowRect.Width + 0.5f * radius,
                            shadowRect.Height + 0.5f * radius),
                        cornerRadius));

                // TODO: innerShadowRegion.Complement(graph.CreateRoundedRectPath(shadowRect, cornerRadius));

                graph.Clip = innerShadowRegion;

                shadowRect.Left   -= 0.5f * radius;
                shadowRect.Top    -= 0.5f * radius;
                shadowRect.Right  += 0.5f * radius;
                shadowRect.Bottom += 0.5f * radius;

                graph.DrawRoundedRectShadowAbs(
                    shadowRect,
                    cornerRadius,
                    radius,
                    SKColors.Transparent,
                    Color.FromArgb(175, (sunken) ? SKColors.White : shadowColor),
                    1.0f);
                graph.Clip = new SKRegion();
            }

            // Top/Left inner shadow
            shadowRect         = absolute;
            shadowRect.Right  -= radius * .3f;
            shadowRect.Bottom -= radius * .3f;
            innerShadowRegion  = new(
                ChartGraphics.CreateRoundedRectPath(
                    new SKRect(
                        shadowRect.Left + radius * .5f,
                        shadowRect.Top + radius * .5f,
                        shadowRect.Width - .2f * radius,
                        shadowRect.Height - .2f * radius),
                    cornerRadius));

            SKRect shadowWithOffset = shadowRect;

            shadowWithOffset.Right  += radius;
            shadowWithOffset.Bottom += radius;
            // TODO: innerShadowRegion.Complement(graph.CreateRoundedRectPath(shadowWithOffset, cornerRadius));

            innerShadowRegion.SetPath(ChartGraphics.CreateRoundedRectPath(shadowRect, cornerRadius), innerShadowRegion);
            graph.Clip = innerShadowRegion;
            graph.DrawRoundedRectShadowAbs(
                shadowWithOffset,
                cornerRadius,
                radius,
                SKColors.Transparent,
                Color.FromArgb(175, (sunken) ? shadowColor : SKColors.White),
                1.0f);
            graph.Clip = new();
        }