public void Draw(BitmapCanvas canvas, Matrix3X3 parentMatrix, byte parentAlpha) { LottieLog.BeginSection("GradientFillContent.Draw"); _path.Reset(); for (var i = 0; i < _paths.Count; i++) { _path.AddPath(_paths[i].Path, parentMatrix); } //_path.ComputeBounds(out _boundsRect); Shader shader; if (_type == GradientType.Linear) { shader = LinearGradient; } else { shader = RadialGradient; } _shaderMatrix.Set(parentMatrix); shader.LocalMatrix = _shaderMatrix; _paint.Shader = shader; if (_colorFilterAnimation != null) { _paint.ColorFilter = _colorFilterAnimation.Value; } var alpha = (byte)(parentAlpha / 255f * _opacityAnimation.Value / 100f * 255); _paint.Alpha = alpha; canvas.DrawPath(_path, _paint); LottieLog.EndSection("GradientFillContent.Draw"); }
internal static void ApplyTrimPathIfNeeded(Path path, float startValue, float endValue, float offsetValue) { LottieLog.BeginSection("applyTrimPathIfNeeded"); PathMeasure.SetPath(path); var length = PathMeasure.Length; if (startValue == 1f && endValue == 0f) { LottieLog.EndSection("applyTrimPathIfNeeded"); return; } if (length < 1f || Math.Abs(endValue - startValue - 1) < .01) { LottieLog.EndSection("applyTrimPathIfNeeded"); return; } var start = length * startValue; var end = length * endValue; var newStart = Math.Min(start, end); var newEnd = Math.Max(start, end); var offset = offsetValue * length; newStart += offset; newEnd += offset; // If the trim path has rotated around the path, we need to shift it back. if (newStart >= length && newEnd >= length) { newStart = MiscUtils.FloorMod(newStart, length); newEnd = MiscUtils.FloorMod(newEnd, length); } if (newStart < 0) { newStart = MiscUtils.FloorMod(newStart, length); } if (newEnd < 0) { newEnd = MiscUtils.FloorMod(newEnd, length); } // If the start and end are equals, return an empty path. if (newStart == newEnd) { path.Reset(); LottieLog.EndSection("applyTrimPathIfNeeded"); return; } if (newStart >= newEnd) { newStart -= length; } _tempPath.Reset(); PathMeasure.GetSegment(newStart, newEnd, ref _tempPath, true); if (newEnd > length) { _tempPath2.Reset(); PathMeasure.GetSegment(0, newEnd % length, ref _tempPath2, true); _tempPath.AddPath(_tempPath2); } else if (newStart < 0) { _tempPath2.Reset(); PathMeasure.GetSegment(length + newStart, length, ref _tempPath2, true); _tempPath.AddPath(_tempPath2); } path.Set(_tempPath); LottieLog.EndSection("applyTrimPathIfNeeded"); }