예제 #1
0
        internal BaseLayer(LottieDrawable lottieDrawable, Layer layerModel)
        {
            LottieDrawable       = lottieDrawable;
            _layerModel          = layerModel;
            _clearPaint.Xfermode = new PorterDuffXfermode(PorterDuff.Mode.Clear);
            _maskPaint.Xfermode  = new PorterDuffXfermode(PorterDuff.Mode.DstIn);
            if (layerModel.GetMatteType() == Layer.MatteType.Invert)
            {
                _mattePaint.Xfermode = new PorterDuffXfermode(PorterDuff.Mode.DstOut);
            }
            else
            {
                _mattePaint.Xfermode = new PorterDuffXfermode(PorterDuff.Mode.DstIn);
            }

            Transform = layerModel.Transform.CreateAnimation();
            Transform.ValueChanged += OnValueChanged;
            Transform.AddAnimationsToLayer(this);

            if (layerModel.Masks != null && layerModel.Masks.Count > 0)
            {
                _mask = new MaskKeyframeAnimation(layerModel.Masks);
                foreach (var animation in _mask.MaskAnimations)
                {
                    AddAnimation(animation);
                    animation.ValueChanged += OnValueChanged;
                }
            }
            SetupInOutAnimations();
        }
예제 #2
0
        internal ContentGroup(LottieDrawable lottieDrawable, BaseLayer layer, string name, List <IContent> contents, AnimatableTransform transform)
        {
            Name      = name;
            _contents = contents;

            if (transform != null)
            {
                _transformAnimation = transform.CreateAnimation();

                _transformAnimation.AddAnimationsToLayer(layer);
                _transformAnimation.ValueChanged += (sender, args) =>
                {
                    lottieDrawable.InvalidateSelf();
                };
            }

            var greedyContents = new List <IGreedyContent>();

            for (var i = contents.Count - 1; i >= 0; i--)
            {
                var content = contents[i];
                if (content is IGreedyContent greedyContent)
                {
                    greedyContents.Add(greedyContent);
                }
            }

            for (var i = greedyContents.Count - 1; i >= 0; i--)
            {
                greedyContents[i].AbsorbContent(_contents);
            }
        }
예제 #3
0
        internal RepeaterContent(LottieDrawable lottieDrawable, BaseLayer layer, Repeater repeater)
        {
            _lottieDrawable = lottieDrawable;
            _layer          = layer;
            Name            = repeater.Name;
            _copies         = repeater.Copies.CreateAnimation();
            layer.AddAnimation(_copies);
            _copies.ValueChanged += OnValueChanged;

            _offset = repeater.Offset.CreateAnimation();
            layer.AddAnimation(_offset);
            _offset.ValueChanged += OnValueChanged;

            _transform = repeater.Transform.CreateAnimation();
            _transform.AddAnimationsToLayer(layer);
            _transform.ValueChanged += OnValueChanged;
        }
예제 #4
0
        internal ContentGroup(LottieDrawable lottieDrawable, BaseLayer layer, ShapeGroup shapeGroup)
        {
            Name = shapeGroup.Name;
            var items = shapeGroup.Items;

            if (items.Count == 0)
            {
                return;
            }

            if (items[items.Count - 1] is AnimatableTransform animatableTransform)
            {
                _transformAnimation = animatableTransform.CreateAnimation();

                _transformAnimation.AddAnimationsToLayer(layer);
                _transformAnimation.ValueChanged += (sender, args) =>
                {
                    lottieDrawable.InvalidateSelf();
                };
            }

            for (var i = 0; i < items.Count; i++)
            {
                var item = items[i];
                if (item is ShapeFill)
                {
                    _contents.Add(new FillContent(lottieDrawable, layer, (ShapeFill)item));
                }
                else if (item is GradientFill)
                {
                    _contents.Add(new GradientFillContent(lottieDrawable, layer, (GradientFill)item));
                }
                else if (item is ShapeStroke)
                {
                    _contents.Add(new StrokeContent(lottieDrawable, layer, (ShapeStroke)item));
                }
                else if (item is GradientStroke)
                {
                    _contents.Add(new GradientStrokeContent(lottieDrawable, layer, (GradientStroke)item));
                }
                else if (item is ShapeGroup)
                {
                    _contents.Add(new ContentGroup(lottieDrawable, layer, (ShapeGroup)item));
                }
                else if (item is RectangleShape)
                {
                    _contents.Add(new RectangleContent(lottieDrawable, layer, (RectangleShape)item));
                }
                else if (item is CircleShape)
                {
                    _contents.Add(new EllipseContent(lottieDrawable, layer, (CircleShape)item));
                }
                else if (item is ShapePath)
                {
                    _contents.Add(new ShapeContent(lottieDrawable, layer, (ShapePath)item));
                }
                else if (item is PolystarShape)
                {
                    _contents.Add(new PolystarContent(lottieDrawable, layer, (PolystarShape)item));
                }
                else if (item is ShapeTrimPath)
                {
                    _contents.Add(new TrimPathContent(layer, (ShapeTrimPath)item));
                }
                else
                {
                    if (item is MergePaths mergePaths)
                    {
                        if (lottieDrawable.EnableMergePathsForKitKatAndAbove())
                        {
                            _contents.Add(new MergePathsContent(mergePaths));
                        }
                        else
                        {
                            Debug.WriteLine("Animation contains merge paths but they are disabled.", Tag);
                        }
                    }
                }
            }

            IList <IContent>  contentsToRemove         = new List <IContent>();
            MergePathsContent currentMergePathsContent = null;

            for (var i = _contents.Count - 1; i >= 0; i--)
            {
                var content = _contents[i];
                if (content is MergePathsContent mergePathsContent)
                {
                    currentMergePathsContent = mergePathsContent;
                }
                if (currentMergePathsContent != null && content != currentMergePathsContent)
                {
                    currentMergePathsContent.AddContentIfNeeded(content);
                    contentsToRemove.Add(content);
                }
            }

            for (var i = _contents.Count - 1; i >= 0; i--)
            {
                if (contentsToRemove.Contains(_contents[i]))
                {
                    _contents.RemoveAt(i);
                }
            }
        }