Exemplo n.º 1
0
        private void DrawPlane(SKCanvas canvas, SKImageInfo info, float x, SKPaint paint, float minX, float maxX)
        {
            var height = info.Height;
            var width  = info.Width;

            using (var path = SKPath.ParseSvgPathData("M21 16v-2l-8-5V3.5c0-.83-.67-1.5-1.5-1.5S10 2.67 10 3.5V9l-8 5v2l8-2.5V19l-2 1.5V22l3.5-1 3.5 1v-1.5L13 19v-5.5l8 2.5z"))
            {
                path.Transform(SKMatrix.MakeRotationDegrees(90));
                if (path.GetTightBounds(out var bounds))
                {
                    var scale = 2f / 3f / (bounds.Height / height);
                    path.Transform(SKMatrix.MakeScale(scale, scale));
                    if (path.GetTightBounds(out bounds))
                    {
                        var newX = x + bounds.Width / 2;
                        if ((newX - bounds.Width) <= minX)
                        {
                            newX = minX + bounds.Width;
                        }
                        else if (newX >= maxX)
                        {
                            newX = maxX;
                        }
                        path.Transform(SKMatrix.MakeTranslation(newX, (height / 2) - bounds.Height / 2 - (1 * scale / bounds.Height * height) - paint.StrokeWidth / 4));
                        canvas.DrawPath(path, paint);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private static SKMatrix CreateRotationMatrix(IReadOnlyViewport viewport, BoundingBox boundingBox, SKMatrix priorMatrix)
        {
            SKMatrix matrix = SKMatrix.MakeIdentity();

            // The front-end sets up the canvas with a matrix based on screen scaling (e.g. retina).
            // We need to retain that effect by combining our matrix with the incoming matrix.

            // We'll create four matrices in addition to the incoming matrix. They perform the
            // zoom scale, focal point offset, user rotation and finally, centering in the screen.

            var userRotation     = SKMatrix.MakeRotationDegrees((float)viewport.Rotation);
            var focalPointOffset = SKMatrix.MakeTranslation(
                (float)(boundingBox.Left - viewport.Center.X),
                (float)(viewport.Center.Y - boundingBox.Top));
            var zoomScale      = SKMatrix.MakeScale((float)(1.0 / viewport.Resolution), (float)(1.0 / viewport.Resolution));
            var centerInScreen = SKMatrix.MakeTranslation((float)(viewport.Width / 2.0), (float)(viewport.Height / 2.0));

            // We'll concatenate them like so: incomingMatrix * centerInScreen * userRotation * zoomScale * focalPointOffset

            SKMatrix.Concat(ref matrix, zoomScale, focalPointOffset);
            SKMatrix.Concat(ref matrix, userRotation, matrix);
            SKMatrix.Concat(ref matrix, centerInScreen, matrix);
            SKMatrix.Concat(ref matrix, priorMatrix, matrix);

            return(matrix);
        }
Exemplo n.º 3
0
        public static bool Contains(ComponentLoad load, IssoPoint2D pt, ModelViewSurface surface)
        {
            switch (load.CompType)
            {
            case ComponentTypes.ctDistributedLoad:
            {
                float  ArrawHeight = surface.ViewHeight / 30;
                SKPath b           = new SKPath();
                b.MoveTo(load.AppNodes[0].Location.X, load.AppNodes[0].Location.Y);
                b.LineTo(load.AppNodes[0].Location.X, load.AppNodes[0].Location.Y + ArrawHeight);
                b.LineTo(load.AppNodes[1].Location.X, load.AppNodes[1].Location.Y + ArrawHeight);
                b.LineTo(load.AppNodes[1].Location.X, load.AppNodes[1].Location.Y);
                b.Close();
                return(b.Contains(pt.X, pt.Y));
            }

            case ComponentTypes.ctForce:
            {
                float  ArrawHeight = surface.ViewHeight / 15;
                SKPath b           = new SKPath();
                b.MoveTo(load.AppNodes[0].Location.X - ArrawHeight / 6, load.AppNodes[0].Location.Y);
                b.LineTo(load.AppNodes[0].Location.X - ArrawHeight / 6, load.AppNodes[0].Location.Y - ArrawHeight);
                b.LineTo(load.AppNodes[0].Location.X + ArrawHeight / 6, load.AppNodes[0].Location.Y - ArrawHeight);
                b.LineTo(load.AppNodes[0].Location.X + ArrawHeight / 6, load.AppNodes[0].Location.Y);
                b.Close();
                SKMatrix rotate = SKMatrix.MakeRotationDegrees(load.Direction + 90, load.AppNodes[0].Location.X, load.AppNodes[0].Location.Y);;
                b.Transform(rotate);
                return(b.Contains(pt.X, pt.Y));
            }

            default: return(false);
            }
        }
Exemplo n.º 4
0
        public void Render(SKCanvas canvas)
        {
            if (AbsoluteVisible)
            {
                var textureBox    = Texture.ViewBox;
                var textureWidth  = textureBox.Width;
                var textureHeight = textureBox.Height;

                var scaleX = this.Width / textureWidth;
                var scaleY = this.Height / textureHeight;

                SKMatrix scaleMatrix = SKMatrix.MakeScale(scaleX, scaleY);
                // Gum uses counter clockwise rotation, Skia uses clockwise, so invert:
                SKMatrix rotationMatrix  = SKMatrix.MakeRotationDegrees(-Rotation);
                SKMatrix translateMatrix = SKMatrix.MakeTranslation(this.GetAbsoluteX(), this.GetAbsoluteY());
                SKMatrix result          = SKMatrix.MakeIdentity();

                SKMatrix.Concat(
                    ref result, rotationMatrix, scaleMatrix);
                SKMatrix.Concat(
                    ref result, translateMatrix, result);

                canvas.DrawPicture(Texture.Picture, ref result);
            }
        }
Exemplo n.º 5
0
        public override void DrawBound(SKRect boundingRect, SKCanvas canvas)
        {
            SKMatrix scaleMatrix = SKMatrix.MakeScale(1, 1);
            //// Gum uses counter clockwise rotation, Skia uses clockwise, so invert:
            SKMatrix rotationMatrix  = SKMatrix.MakeRotationDegrees(-Rotation);
            SKMatrix translateMatrix = SKMatrix.MakeTranslation(this.GetAbsoluteX(), this.GetAbsoluteY());
            SKMatrix result          = SKMatrix.MakeIdentity();

            SKMatrix.Concat(
                ref result, rotationMatrix, scaleMatrix);
            SKMatrix.Concat(
                ref result, translateMatrix, result);
            canvas.Save();
            canvas.SetMatrix(result);


            SKPath path = new SKPath();

            path.MoveTo(Points[0]);

            for (int i = 0; i < Points.Count; i++)
            {
                path.LineTo(Points[i]);
            }
            path.LineTo(Points[0]);

            path.Close();
            using (var paintToUse = paint)
            {
                canvas.DrawPath(path, paintToUse);
            }

            canvas.Restore();
        }
Exemplo n.º 6
0
        public void SKRotationScaleMatrixRotationToMatrixIsCorrect()
        {
            var m   = SKMatrix.MakeRotationDegrees(45);
            var rsm = SKRotationScaleMatrix.CreateRotationDegrees(45, 0, 0).ToMatrix();

            Assert.Equal(m.Values, rsm.Values);
        }
        protected override void OnSizeAllocated(double width, double height)
        {
            if (width > 0)
            {
                width        = height;
                WidthRequest = height;
                //Add points to paths
                path.Reset();
                path.AddPoly(mPoints, false);

                //Move to centre origin to make rotations correct
                var rect_inital = GetRectangle(path.Points);
                (var xshft, var yshft) = GetMinimumPoint(path.Points);
                path.Offset(-xshft, -yshft);
                path.Offset(-rect_inital.Width / 2, -rect_inital.Height / 2);

                //Rotate by 45 degrees
                path.Transform(SKMatrix.MakeRotationDegrees(OffsetAngle));

                //Offset to zero
                //Scale to fill
                var rect_scale = GetRectangle(path.Points);
                (xshft, yshft) = GetMinimumPoint(path.Points);
                path.Offset(-rect_scale.Left, -rect_scale.Top);

                var xscale = (float)Width * Scale / rect_scale.Width;
                var yscale = (float)Height * Scale / rect_scale.Height;

                path.Transform(SKMatrix.MakeScale(xscale, yscale));
                path.Offset((float)Width * Scale / 2, (float)Height * Scale / 2);
                base.OnSizeAllocated(width, height);
            }
        }
        private static void AddX(SKPath p)
        {
            SKPath XPath = new SKPath();

            AddY(XPath);
            SKMatrix rmatrix = SKMatrix.MakeRotationDegrees(-90, 0, 0);

            XPath.Transform(rmatrix);
            p.AddPath(XPath);
        }
Exemplo n.º 9
0
        private void AddRectangle2()
        {
            var rectangle = new SkiaSharp.Elements.Rectangle(SKRect.Create(120, 150, 100, 100))
            {
                FillColor      = new SKColor(SKColors.SkyBlue.Red, SKColors.SkyBlue.Green, SKColors.SkyBlue.Blue, 200),
                Transformation = SKMatrix.MakeRotationDegrees(45)
            };

            canvas.Elements.Add(rectangle);
        }
Exemplo n.º 10
0
        private static SKMatrix TRMatrix(ComponentLoad load, float scaleFactor, IssoPoint2D origin, float ViewHeight, out SKMatrix rmatrix)
        {
            SKPoint  point  = IssoConvert.IssoPoint2DToSkPoint(load.AppNodes[0].Location, scaleFactor, origin, ViewHeight);
            SKMatrix matrix = new SKMatrix();

            matrix.SetScaleTranslate(1, 1, point.X, point.Y);

            rmatrix = SKMatrix.MakeRotationDegrees(load.Direction + 90, point.X, point.Y);

            return(matrix);
        }
Exemplo n.º 11
0
        public static void AddOpenArrow(this SKPath path, SKPoint point, SKPoint normal)
        {
            var matrix1  = SKMatrix.MakeRotationDegrees(35);
            var rotated1 = matrix1.MapVector(normal.X, normal.Y);
            var matrix2  = SKMatrix.MakeRotationDegrees(-35);
            var rotated2 = matrix2.MapVector(normal.X, normal.Y);

            path.MoveTo(point + new SKPoint(rotated1.X * 8, rotated1.Y * 8));
            path.LineTo(point);
            path.LineTo(point + new SKPoint(rotated2.X * 8, rotated2.Y * 8));
        }
Exemplo n.º 12
0
        public void WillFailToTransformWithInvalidTransformation()
        {
            var rect   = SKRect.Create(10, 10, 100, 100);
            var offset = rect;

            offset.Offset(2, 2);

            var rrect       = new SKRoundRect(rect, 5, 5);
            var transformed = rrect.Transform(SKMatrix.MakeRotationDegrees(30));

            Assert.Null(transformed);
        }
Exemplo n.º 13
0
        public void RotateAt(float angleDegrees, PointF midPoint, MatrixOrder order)
        {
            var m = SKMatrix.MakeRotationDegrees(angleDegrees, midPoint.X, midPoint.Y);

            if (order == MatrixOrder.Append)
            {
                SKMatrix.PostConcat(ref _m, ref m);
            }
            else
            {
                SKMatrix.PreConcat(ref _m, ref m);
            }
        }
Exemplo n.º 14
0
        public async ValueTask <IActionResult> GetRotateAsync(int size, string topic = null, int degrees = 30)
        {
            int halfSize = size / 2;
            var rotate   = SKMatrix.MakeRotationDegrees(degrees, halfSize, halfSize);
            var scale    = SKMatrix.MakeScale(1.2F, 1.2F, halfSize, halfSize);

            using (var filter = SKImageFilter.CreateMatrix(rotate, SKFilterQuality.Medium))
            {
                var response = await GetWithFilterAsync(size, topic, filter);

                return(response);
            }
        }
Exemplo n.º 15
0
        void DrawRotatedWithMatrices(SKCanvas canvas, SKPath path, SKPaint paint, float degrees, int cx, int cy)
        {
            var result     = SKMatrix.MakeIdentity();
            var translate  = SKMatrix.MakeTranslation(-cx, -cy);
            var rotate     = SKMatrix.MakeRotationDegrees(degrees);
            var translate2 = SKMatrix.MakeTranslation(cx, cy);

            SKMatrix.PostConcat(ref result, translate);
            SKMatrix.PostConcat(ref result, rotate);
            SKMatrix.PostConcat(ref result, translate2);

            path.Transform(result);
            canvas.DrawPath(path, paint);
        }
Exemplo n.º 16
0
        public async ValueTask <IActionResult> GetGrayscaleAsync(int size, string topic = null, float contrast = 0.06F)
        {
            int halfSize = size / 2;
            var rotate   = SKMatrix.MakeRotationDegrees(30, halfSize, halfSize);
            var scale    = SKMatrix.MakeScale(1.2F, 1.2F, halfSize, halfSize);

            using (var filter = SKColorFilter.CreateHighContrast(
                       true, SKHighContrastConfigInvertStyle.NoInvert, contrast))
            {
                var response = await GetWithFilterAsync(size, topic, colorFilter : filter);

                return(response);
            }
        }
        private void Play()
        {
            new Animation((value) =>
            {
                canvas.SuspendLayout();

                _rectangle.Transformation = SKMatrix.MakeRotationDegrees(360 * (float)value);

                _rectangle.Location = new SKPoint(_startLocation.X + (100 * (float)value),
                                                  _startLocation.Y + (100 * (float)value));

                canvas.ResumeLayout(true);
            })
            .Commit(this, "Anim", length: 2000, easing: Easing.SpringOut);
        }
        private static SKMatrix TRMatrix(ComponentNode c, ModelViewSurface surface, out SKMatrix rmatrix)
        {
            float scale = surface.ViewHeight / 80;

            SKPoint location = IssoConvert.IssoPoint2DToSkPoint(c.Location, surface.ScaleFactor, surface.Origin, surface.ViewHeight);

            SKMatrix matrix = new SKMatrix();

            matrix.SetScaleTranslate(scale, scale, location.X, location.Y);

            //rmatrix = SKMatrix.MakeRotationDegrees(c.Angle - 90, location.X, location.Y);
            rmatrix = SKMatrix.MakeRotationDegrees(0, location.X, location.Y);

            return(matrix);
        }
        public PathTransformPage()
        {
            Title = "Path Transform";

            SKCanvasView canvasView = new SKCanvasView();

            canvasView.PaintSurface += OnCanvasViewPaintSurface;
            Content = canvasView;

            SKMatrix matrix = SKMatrix.MakeScale(3, 3);

            SKMatrix.PostConcat(ref matrix, SKMatrix.MakeRotationDegrees(360f / 22));
            SKMatrix.PostConcat(ref matrix, SKMatrix.MakeTranslation(300, 300));

            transformedPath.Transform(matrix);
        }
Exemplo n.º 20
0
        private void CreateLinearGradient()
        {
            int repeat = Properties.ColorsMultiplier.CurrentValue;

            _linearGradientRotation = Properties.LinearGradientRotation.CurrentValue;

            _shader?.Dispose();
            _shader = SKShader.CreateLinearGradient(
                new SKPoint(_shaderBounds.Left, _shaderBounds.Top),
                new SKPoint(_shaderBounds.Right, _shaderBounds.Top),
                Properties.Colors.BaseValue.GetColorsArray(repeat),
                Properties.Colors.BaseValue.GetPositionsArray(repeat),
                Properties.TileMode.CurrentValue,
                SKMatrix.MakeRotationDegrees(_linearGradientRotation, _shaderBounds.Left, _shaderBounds.MidY)
                );
            UpdatePaint();
        }
Exemplo n.º 21
0
        public static SKMatrix ToSKMatrix(this IViewport viewport)
        {
            var mapCenterX         = (float)viewport.Width * 0.5f;
            var mapCenterY         = (float)viewport.Height * 0.5f;
            var invertedResolution = 1f / (float)viewport.Resolution;

            var matrix = SKMatrix.MakeIdentity();

            SKMatrix.Concat(ref matrix, matrix, SKMatrix.MakeScale(invertedResolution, invertedResolution, mapCenterX, mapCenterY));
            SKMatrix.Concat(ref matrix, matrix, SKMatrix.MakeScale(1, -1, 0, -mapCenterY)); // As a consequence images will be up side down :(
            if (viewport.IsRotated)
            {
                SKMatrix.Concat(ref matrix, matrix, SKMatrix.MakeRotationDegrees((float)-viewport.Rotation));
            }
            SKMatrix.Concat(ref matrix, matrix, SKMatrix.MakeTranslation((float)-viewport.Center.X, (float)-viewport.Center.Y));
            return(matrix);
        }
        private void Transform(SKPoint positionScreen, SKPoint previousPositionScreen, float scaleDelta, float rotationDelta)
        {
            var positionDelta = positionScreen - previousPositionScreen;

            if (!positionDelta.IsEmpty)
            {
                totalTranslate += positionDelta;
                var m = SKMatrix.MakeTranslation(positionDelta.X, positionDelta.Y);
                SKMatrix.Concat(ref totalMatrix, ref m, ref totalMatrix);
            }

            if (scaleDelta != 1)
            {
                if (totalScale * scaleDelta > MaxScale)
                {
                    scaleDelta = MaxScale / totalScale;
                }
                if (totalScale * scaleDelta < MinScale)
                {
                    scaleDelta = MinScale / totalScale;
                }

                totalScale *= scaleDelta;
                var m = SKMatrix.MakeScale(scaleDelta, scaleDelta, positionScreen.X, positionScreen.Y);
                SKMatrix.Concat(ref totalMatrix, ref m, ref totalMatrix);
            }

            if (rotationDelta != 0)
            {
                if (totalRotation + rotationDelta > MaxRotation)
                {
                    rotationDelta = MaxRotation - totalRotation;
                }
                if (totalRotation + rotationDelta < MinRotation)
                {
                    rotationDelta = MinRotation - totalRotation;
                }

                totalRotation += rotationDelta;
                var m = SKMatrix.MakeRotationDegrees(rotationDelta, positionScreen.X, positionScreen.Y);
                SKMatrix.Concat(ref totalMatrix, ref m, ref totalMatrix);
            }

            gestureSurface.InvalidateSurface();
        }
Exemplo n.º 23
0
        public void Rotate(float elementRotation, MatrixOrder append)
        {
            var rot = SKMatrix.MakeRotationDegrees(elementRotation);

            var main = new SKMatrix(M11, M12, OffsetX, M21, M22, OffsetY, 0, 0, 1);

            if (append == MatrixOrder.Prepend)
            {
                SKMatrix.PreConcat(ref main, rot);
            }
            else
            {
                SKMatrix.PostConcat(ref main, rot);
            }

            this.SetMatrix(main.ScaleX, main.SkewX, main.SkewY, main.ScaleY, main.TransX, main.TransY,
                           MatrixTypes.TRANSFORM_IS_UNKNOWN);
        }
Exemplo n.º 24
0
        private static void DrawConcentrated(ComponentLoad load, ModelViewSurface surface, SKCanvas canvas)
        {
            SKPaint paint = new SKPaint
            {
                Style       = SKPaintStyle.StrokeAndFill,
                Color       = Color.PaleVioletRed.ToSKColor(),
                IsAntialias = true,
                StrokeWidth = 1
            };

            SKPath dc = GetConcentrated(load, surface.ViewHeight);

            dc.Transform(SKMatrix.MakeRotationDegrees(-load.Direction));
            SKPoint pt = IssoConvert.IssoPoint2DToSkPoint(load.AppNodes[0].Location, surface.ScaleFactor, surface.Origin, surface.ViewHeight);

            dc.Transform(SKMatrix.MakeTranslation(pt.X, pt.Y));
            canvas.DrawPath(dc, paint);
        }
        public ConveyorBeltPage()
        {
            Title = "Conveyor Belt";

            canvasView = new SKCanvasView();
            canvasView.PaintSurface += OnCanvasViewPaintSurface;
            Content = canvasView;

            // Create the path for the bucket starting with the handle
            bucketPath.AddRect(new SKRect(-5, -3, 25, 3));

            // Sides
            bucketPath.AddRoundedRect(new SKRect(25, -19, 27, 18), 10, 10,
                                      SKPathDirection.CounterClockwise);
            bucketPath.AddRoundedRect(new SKRect(63, -19, 65, 18), 10, 10,
                                      SKPathDirection.CounterClockwise);

            // Five slats
            for (int i = 0; i < 5; i++)
            {
                bucketPath.MoveTo(25, -19 + 8 * i);
                bucketPath.LineTo(25, -13 + 8 * i);
                bucketPath.ArcTo(50, 50, 0, SKPathArcSize.Small,
                                 SKPathDirection.CounterClockwise, 65, -13 + 8 * i);
                bucketPath.LineTo(65, -19 + 8 * i);
                bucketPath.ArcTo(50, 50, 0, SKPathArcSize.Small,
                                 SKPathDirection.Clockwise, 25, -19 + 8 * i);
                bucketPath.Close();
            }

            // Arc to suggest the hidden side
            bucketPath.MoveTo(25, -17);
            bucketPath.ArcTo(50, 50, 0, SKPathArcSize.Small,
                             SKPathDirection.Clockwise, 65, -17);
            bucketPath.LineTo(65, -19);
            bucketPath.ArcTo(50, 50, 0, SKPathArcSize.Small,
                             SKPathDirection.CounterClockwise, 25, -19);
            bucketPath.Close();

            // Make it a little bigger and correct the orientation
            bucketPath.Transform(SKMatrix.MakeScale(-2, 2));
            bucketPath.Transform(SKMatrix.MakeRotationDegrees(90));
        }
Exemplo n.º 26
0
        private void Play()
        {
            new Animation((value) =>
            {
                canvas.SuspendLayout();

                for (var y = 0; y < 10; y++)
                {
                    var index = y * 10;
                    for (var x = 0; x < 10; x++)
                    {
                        var ele = canvas.Elements[index + x];

                        var startX = ((x + 1) * 40);
                        var diffX  = startX - 400;
                        if (diffX < 0)
                        {
                            diffX *= -1;
                        }
                        diffX   = diffX - startX;
                        startX += 60;

                        var startY = ((y + 1) * 40);
                        var diffY  = startY - 400;
                        if (diffY < 0)
                        {
                            diffY *= -1;
                        }
                        diffY   = diffY - startY;
                        startY += 60;

                        ele.Location = new SKPoint(startX + (diffX * (float)value),
                                                   startY + (diffY * (float)value));

                        ele.Transformation = SKMatrix.MakeRotationDegrees(360 * (float)value);
                    }
                }

                canvas.ResumeLayout(true);
            })
            .Commit(this, "Anim", length: 100000, easing: Easing.Linear);
        }
        void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            canvas.DrawBitmap(monkeyBitmap, info.Rect, BitmapStretch.UniformToFill,
                              BitmapAlignment.Center, BitmapAlignment.Start);

            using (SKPaint paint = new SKPaint())
            {
                paint.Shader = SKShader.CreateBitmap(tileBitmap,
                                                     SKShaderTileMode.Repeat,
                                                     SKShaderTileMode.Repeat,
                                                     SKMatrix.MakeRotationDegrees(45));
                canvas.DrawRect(info.Rect, paint);
            }
        }
Exemplo n.º 28
0
        public void Matrix44ConvertsToMatrix()
        {
            var rowMajor44 = new float[] {
                2, 3, 4, 5,
                4, 6, 8, 10,
                6, 9, 12, 15,
                8, 12, 16, 20,
            };
            var rowMajor = new float[] {
                rowMajor44[0], rowMajor44[1], rowMajor44[3],
                rowMajor44[4], rowMajor44[5], rowMajor44[7],
                rowMajor44[12], rowMajor44[13], rowMajor44[15],
            };

            var matrix44 = SKMatrix44.FromRowMajor(rowMajor44);

            Assert.Equal(rowMajor, matrix44.Matrix.Values);

            matrix44 = SKMatrix44.CreateRotationDegrees(0, 0, 1, 45);
            Assert.Equal(SKMatrix.MakeRotationDegrees(45).Values, matrix44.Matrix.Values);
        }
Exemplo n.º 29
0
        /// <summary>
        /// DEPRECATED
        /// </summary>
        /// <returns>The static element.</returns>
        /// <param name="resource">Resource.</param>
        /// <param name="xPercent">X percent.</param>
        /// <param name="yPercent">Y percent.</param>
        /// <param name="tag">Tag.</param>
        /// <param name="degrees">Degrees.</param>
        public IconImage BuildStaticIcon(string resource, float xPercent, float yPercent, int tag, float degrees)
        {
            using (var stream = App.MainAssembly.GetManifestResourceStream(resource))
            {
                SKSize size = Constants.DeviceLayout.GetSizeByGrid(canvasReference.CanvasSize, xPercent, yPercent);

                SKPoint centerPoint = Constants.DeviceLayout.GetEmitterPoint(canvasReference.CanvasSize, size);

                IconImage emitterReference = new IconImage(SkiaSharp.SKBitmap.Decode(stream))
                {
                    Tag            = tag,
                    Transformation = SKMatrix.MakeRotationDegrees(degrees)
                };

                emitterReference.Bounds = SKRect.Create(centerPoint.X,
                                                        centerPoint.Y,
                                                        size.Height,
                                                        size.Height);

                return(emitterReference);
            }
        }
Exemplo n.º 30
0
        public static SKMatrix GetMatrix(SkiaSharp.Extended.Svg.SKSvg svg, float left, float top, float widthR, float heightR, float rotate = 0)
        {
            float canvasMin = Math.Min(widthR, heightR);
            // get the size of the picture
            float svgMax = Math.Max(svg.Picture.CullRect.Width, svg.Picture.CullRect.Height);
            // get the scale to fill the screen
            float scale  = canvasMin / svgMax;
            var   width  = svg.Picture.CullRect.Width * scale;
            var   height = svg.Picture.CullRect.Height * scale;

            var matrix = SKMatrix.MakeIdentity();

            if (rotate > 0)
            {
                SKMatrix.PreConcat(ref matrix, SKMatrix.MakeRotationDegrees(rotate, (left + widthR / 2), (top + heightR / 2)));
            }

            SKMatrix.PreConcat(ref matrix, SKMatrix.MakeTranslation(left + (widthR - width) / 2F, top + (heightR - height) / 2F));
            SKMatrix.PreConcat(ref matrix, SKMatrix.MakeScale(scale, scale));

            return(matrix);
        }