SetMatrix() public method

public SetMatrix ( SKMatrix matrix ) : void
matrix SKMatrix
return void
        protected override void Draw(SKCanvas canvas, int width, int height)
        {
            float time = _frame / (LengthSec * Fps);

            using (var paint = new SKPaint())
            {
                paint.Color = Foreground.ToSkia();
                paint.StrokeWidth = (float)StrokeWidth;
                paint.IsAntialias = true;
                paint.IsStroke = true;

                for (int a = 0; a < 3; ++a)
                {
                    var matrix = SKMatrix.MakeRotation(2 * (float)Math.PI * time / 6 + 2 * (float)Math.PI * a / 3);
                    matrix.TransX = width / 2f;
                    matrix.TransY = height / 2f;

                    canvas.SetMatrix(matrix);

                    const int n = 12;
                    const int sp = 39;

                    for (int i = -n; i <= n; ++i)
                    {
                        float y = (float)(i * sp * Math.Pow(2, time));
                        float tt = (float)Math.Min(1, Math.Max(0, 1.09 * time - 0.00275 * Math.Abs(y) + 0.075));

                        float x;

                        if (i % 2 == 0)
                            x = width;
                        else
                            x = width * tt;

                        if (x > 0)
                            canvas.DrawLine(-x, y, x, y, paint);
                    }
                }
            }

            ++_frame;
            if (_frame > LengthSec * Fps)
                _frame = 0;
        }
示例#2
0
        private SKPoint DrawLineArrowInternal(SKCanvas canvas, SKPaint pen, SKPaint brush, float x, float y, double angle, ArrowStyle style)
        {
            SKPoint pt = default(SKPoint);
            var rt = MatrixHelper.Rotation(angle, new SKPoint(x, y));
            double rx = style.RadiusX;
            double ry = style.RadiusY;
            double sx = 2.0 * rx;
            double sy = 2.0 * ry;

            switch (style.ArrowType)
            {
                default:
                case ArrowType.None:
                    {
                        pt = new SKPoint(x, y);
                    }
                    break;
                case ArrowType.Rectangle:
                    {
                        pt = MatrixHelper.TransformPoint(rt, new SKPoint(x - (float)sx, y));
                        var rect = ToSKRect(x - sx, y - ry, sx, sy);
                        int count = canvas.Save();
                        canvas.SetMatrix(rt);
                        DrawRectangleInternal(canvas, brush, pen, style.IsStroked, style.IsFilled, ref rect);
                        canvas.RestoreToCount(count);
                    }
                    break;
                case ArrowType.Ellipse:
                    {
                        pt = MatrixHelper.TransformPoint(rt, new SKPoint(x - (float)sx, y));
                        int count = canvas.Save();
                        canvas.SetMatrix(rt);
                        var rect = ToSKRect(x - sx, y - ry, sx, sy);
                        DrawEllipseInternal(canvas, brush, pen, style.IsStroked, style.IsFilled, ref rect);
                        canvas.RestoreToCount(count);
                    }
                    break;
                case ArrowType.Arrow:
                    {
                        var pts = new SKPoint[]
                        {
                            new SKPoint(x, y),
                            new SKPoint(x - (float)sx, y + (float)sy),
                            new SKPoint(x, y),
                            new SKPoint(x - (float)sx, y - (float)sy),
                            new SKPoint(x, y)
                        };
                        pt = MatrixHelper.TransformPoint(rt, pts[0]);
                        var p11 = MatrixHelper.TransformPoint(rt, pts[1]);
                        var p21 = MatrixHelper.TransformPoint(rt, pts[2]);
                        var p12 = MatrixHelper.TransformPoint(rt, pts[3]);
                        var p22 = MatrixHelper.TransformPoint(rt, pts[4]);
                        DrawLineInternal(canvas, pen, style.IsStroked, ref p11, ref p21);
                        DrawLineInternal(canvas, pen, style.IsStroked, ref p12, ref p22);
                    }
                    break;
            }

            return pt;
        }