internal SolidLayer(ILottieDrawable lottieDrawable, Layer layerModel) : base(lottieDrawable, layerModel) { LayerModel = layerModel; _paint.SetAlpha(0); _paint.Style = SKPaintStyle.Fill; _paint.Color = layerModel.SolidColor; }
public override void DrawLayer(SKCanvas canvas, Matrix3X3 parentMatrix, byte parentAlpha) { var bitmap = Bitmap; if (bitmap == null) { return; } var density = Utils.Utils.DpScale(); _paint.SetAlpha(parentAlpha); if (_colorFilterAnimation != null) { _paint.ColorFilter = _colorFilterAnimation.Value; } canvas.Save(); var sk = parentMatrix.ToSKMatrix(); canvas.Concat(ref sk); parentMatrix = sk.To3x3Matrix(); RectExt.Set(ref _src, 0, 0, PixelWidth, PixelHeight); RectExt.Set(ref _dst, 0, 0, (int)(PixelWidth * density), (int)(PixelHeight * density)); canvas.DrawBitmap(bitmap, _src, _dst, _paint); canvas.Restore(); }
public void Draw(SKCanvas canvas, Matrix3X3 parentMatrix, byte parentAlpha) { if (_hidden) { return; } LottieLog.BeginSection("FillContent.Draw"); _paint.Color = _colorAnimation.Value ?? SKColors.White; var alpha = (byte)(parentAlpha / 255f * _opacityAnimation.Value / 100f * 255); _paint.SetAlpha(alpha); if (_colorFilterAnimation != null) { _paint.ColorFilter = _colorFilterAnimation.Value; } _path.Reset(); for (var i = 0; i < _paths.Count; i++) { var m = parentMatrix.ToSKMatrix(); _path.AddPath(_paths[i].Path, ref m); } canvas.DrawPath(_path, _paint); LottieLog.EndSection("FillContent.Draw"); }
public override void DrawLayer(SKCanvas canvas, Matrix3X3 parentMatrix, byte parentAlpha) { canvas.Save(); if (!_lottieDrawable.UseTextGlyphs()) { canvas.SetMatrix(parentMatrix.ToSKMatrix()); } var documentData = _textAnimation.Value; if (!_composition.Fonts.TryGetValue(documentData.FontName, out var font)) { // Something is wrong. canvas.Restore(); return; } _fillPaint.Color = _colorAnimation?.Value ?? documentData.Color; _strokePaint.Color = _strokeColorAnimation?.Value ?? documentData.StrokeColor; var alpha = (byte)(Transform.Opacity.Value * 255 / 100f); _fillPaint.SetAlpha(alpha); _strokePaint.SetAlpha(alpha); if (_strokeWidthAnimation?.Value != null) { _strokePaint.StrokeWidth = _strokeWidthAnimation.Value.Value; } else { var parentScale = Utils.Utils.GetScale(parentMatrix); _strokePaint.StrokeWidth = (float)(documentData.StrokeWidth * Utils.Utils.DpScale() * parentScale); } if (_lottieDrawable.UseTextGlyphs()) { DrawTextGlyphs(documentData, parentMatrix, font, canvas); } else { DrawTextWithFont(documentData, font, parentMatrix, canvas); } canvas.Restore(); }
public void Draw(SKCanvas canvas, Matrix3X3 parentMatrix, byte parentAlpha) { if (_hidden) { return; } LottieLog.BeginSection("GradientFillContent.Draw"); _path.Reset(); for (var i = 0; i < _paths.Count; i++) { var m = parentMatrix.ToSKMatrix(); _path.AddPath(_paths[i].Path, ref m); } //_path.ComputeBounds(out _boundsRect); SKShader shader; if (_type == GradientType.Linear) { shader = LinearGradient; } else { shader = RadialGradient; } _shaderMatrix.Set(parentMatrix); shader = SKShader.CreateLocalMatrix(shader, _shaderMatrix.ToSKMatrix()); _paint.Shader = shader; if (_colorFilterAnimation != null) { _paint.ColorFilter = _colorFilterAnimation.Value; } var alpha = (byte)(parentAlpha / 255f * _opacityAnimation.Value / 100f * 255); _paint.SetAlpha(alpha); canvas.DrawPath(_path, _paint); LottieLog.EndSection("GradientFillContent.Draw"); }
internal BaseLayer(ILottieDrawable lottieDrawable, Layer layerModel) { LottieDrawable = lottieDrawable; LayerModel = layerModel; _drawTraceName = layerModel.Name + ".Draw"; _contentPaint.SetAlpha(255); _clearPaint.BlendMode = SKBlendMode.Clear; _addMaskPaint.BlendMode = SKBlendMode.DstIn; _addMaskPaint.Color = SKColors.Black; _subtractMaskPaint.BlendMode = SKBlendMode.DstOut; _subtractMaskPaint.Color = SKColors.Black; if (layerModel.GetMatteType() == Layer.MatteType.Invert) { _mattePaint.BlendMode = SKBlendMode.DstOut; } else { _mattePaint.BlendMode = SKBlendMode.DstIn; } _mattePaint.Color = SKColors.Black; Transform = layerModel.Transform.CreateAnimation(); Transform.ValueChanged += OnValueChanged; if (layerModel.Masks != null && layerModel.Masks.Count > 0) { _mask = new MaskKeyframeAnimation(layerModel.Masks); foreach (var animation in _mask.MaskAnimations) { // Don't call AddAnimation() because progress gets set manually in setProgress to // properly handle time scale. animation.ValueChanged += OnValueChanged; } foreach (var animation in _mask.OpacityAnimations) { AddAnimation(animation); animation.ValueChanged += OnValueChanged; } } SetupInOutAnimations(); }