コード例 #1
0
            internal static GradientFill NewInstance(JsonObject json, LottieComposition composition)
            {
                var name = json.GetNamedString("nm");

                var jsonColor = json.GetNamedObject("g", null);

                if (jsonColor != null && jsonColor.ContainsKey("k"))
                {
                    // This is a hack because the "p" value which contains the number of color points is outside
                    // of "k" which contains the useful data.
                    var points = (int)jsonColor.GetNamedNumber("p");
                    jsonColor = jsonColor.GetNamedObject("k");
                    try
                    {
                        jsonColor["p"] = JsonValue.CreateNumberValue(points);
                    }
                    catch (Exception)
                    {
                        // Do nothing. This shouldn't fail.
                    }
                }
                AnimatableGradientColorValue color = null;

                if (jsonColor != null)
                {
                    color = AnimatableGradientColorValue.Factory.NewInstance(jsonColor, composition);
                }

                var jsonOpacity = json.GetNamedObject("o", null);
                AnimatableIntegerValue opacity = null;

                if (jsonOpacity != null)
                {
                    opacity = AnimatableIntegerValue.Factory.NewInstance(jsonOpacity, composition);
                }

                var fillTypeInt = (int)json.GetNamedNumber("r", 1);
                var fillType    = fillTypeInt == 1 ? PathFillType.Winding : PathFillType.EvenOdd;

                var gradientTypeInt = (int)json.GetNamedNumber("t", 1);
                var gradientType    = gradientTypeInt == 1 ? GradientType.Linear : GradientType.Radial;

                var jsonStartPoint = json.GetNamedObject("s", null);
                AnimatablePointValue startPoint = null;

                if (jsonStartPoint != null)
                {
                    startPoint = AnimatablePointValue.Factory.NewInstance(jsonStartPoint, composition);
                }

                var jsonEndPoint = json.GetNamedObject("e", null);
                AnimatablePointValue endPoint = null;

                if (jsonEndPoint != null)
                {
                    endPoint = AnimatablePointValue.Factory.NewInstance(jsonEndPoint, composition);
                }

                return(new GradientFill(name, gradientType, fillType, color, opacity, startPoint, endPoint, null, null));
            }
コード例 #2
0
            internal static ShapeFill NewInstance(JsonObject json, LottieComposition composition)
            {
                AnimatableColorValue color = null;
                bool fillEnabled;
                AnimatableIntegerValue opacity = null;
                var name = json.GetNamedString("nm");

                var jsonColor = json.GetNamedObject("c", null);

                if (jsonColor != null)
                {
                    color = AnimatableColorValue.Factory.NewInstance(jsonColor, composition);
                }

                var jsonOpacity = json.GetNamedObject("o", null);

                if (jsonOpacity != null)
                {
                    opacity = AnimatableIntegerValue.Factory.NewInstance(jsonOpacity, composition);
                }
                fillEnabled = json.GetNamedBoolean("fillEnabled", false);

                var fillTypeInt = (int)json.GetNamedNumber("r", 1);
                var fillType    = fillTypeInt == 1 ? PathFillType.Winding : PathFillType.EvenOdd;

                return(new ShapeFill(name, fillEnabled, fillType, color, opacity));
            }
コード例 #3
0
 private AnimatableTransform(AnimatablePathValue anchorPoint, IAnimatableValue <PointF> position, AnimatableScaleValue scale, AnimatableFloatValue rotation, AnimatableIntegerValue opacity)
 {
     AnchorPoint = anchorPoint;
     Position    = position;
     Scale       = scale;
     Rotation    = rotation;
     Opacity     = opacity;
 }
コード例 #4
0
 private ShapeFill(string name, bool fillEnabled, PathFillType fillType, AnimatableColorValue color, AnimatableIntegerValue opacity)
 {
     Name         = name;
     _fillEnabled = fillEnabled;
     FillType     = fillType;
     _color       = color;
     _opacity     = opacity;
 }
コード例 #5
0
 private AnimatableTransform(AnimatablePathValue anchorPoint, IAnimatableValue <Vector2?> position, AnimatableScaleValue scale, AnimatableFloatValue rotation, AnimatableIntegerValue opacity, AnimatableFloatValue startOpacity, AnimatableFloatValue endOpacity)
 {
     AnchorPoint  = anchorPoint;
     Position     = position;
     Scale        = scale;
     Rotation     = rotation;
     Opacity      = opacity;
     StartOpacity = startOpacity;
     EndOpacity   = endOpacity;
 }
コード例 #6
0
 private ShapeStroke(string name, AnimatableFloatValue offset, IList <AnimatableFloatValue> lineDashPattern, AnimatableColorValue color, AnimatableIntegerValue opacity, AnimatableFloatValue width, LineCapType capType, LineJoinType joinType)
 {
     Name            = name;
     DashOffset      = offset;
     LineDashPattern = lineDashPattern;
     Color           = color;
     Opacity         = opacity;
     Width           = width;
     CapType         = capType;
     JoinType        = joinType;
 }
コード例 #7
0
 private GradientFill(string name, GradientType gradientType, PathFillType fillType, AnimatableGradientColorValue gradientColor, AnimatableIntegerValue opacity, AnimatablePointValue startPoint, AnimatablePointValue endPoint, AnimatableFloatValue highlightLength, AnimatableFloatValue highlightAngle)
 {
     GradientType    = gradientType;
     FillType        = fillType;
     GradientColor   = gradientColor;
     Opacity         = opacity;
     StartPoint      = startPoint;
     EndPoint        = endPoint;
     Name            = name;
     HighlightLength = highlightLength;
     HighlightAngle  = highlightAngle;
 }
コード例 #8
0
 private GradientStroke(string name, GradientType gradientType, AnimatableGradientColorValue gradientColor, AnimatableIntegerValue opacity, AnimatablePointValue startPoint, AnimatablePointValue endPoint, AnimatableFloatValue width, ShapeStroke.LineCapType capType, ShapeStroke.LineJoinType joinType, IList <AnimatableFloatValue> lineDashPattern, AnimatableFloatValue dashOffset)
 {
     Name            = name;
     GradientType    = gradientType;
     GradientColor   = gradientColor;
     Opacity         = opacity;
     StartPoint      = startPoint;
     EndPoint        = endPoint;
     Width           = width;
     CapType         = capType;
     JoinType        = joinType;
     LineDashPattern = lineDashPattern;
     DashOffset      = dashOffset;
 }
コード例 #9
0
            internal static AnimatableTransform NewInstance(JsonObject json, LottieComposition composition)
            {
                AnimatablePathValue       anchorPoint;
                IAnimatableValue <PointF> position = null;
                AnimatableScaleValue      scale;
                AnimatableFloatValue      rotation = null;
                AnimatableIntegerValue    opacity;
                var anchorJson = json.GetNamedObject("a", null);

                if (anchorJson != null)
                {
                    anchorPoint = new AnimatablePathValue(anchorJson["k"], composition);
                }
                else
                {
                    // Cameras don't have an anchor point property. Although we don't support them, at least
                    // we won't crash.
                    Debug.WriteLine("Layer has no transform property. You may be using an unsupported " + "layer type such as a camera.", "LOTTIE");
                    anchorPoint = new AnimatablePathValue();
                }

                var positionJson = json.GetNamedObject("p", null);

                if (positionJson != null)
                {
                    position = AnimatablePathValue.CreateAnimatablePathOrSplitDimensionPath(positionJson, composition);
                }
                else
                {
                    ThrowMissingTransform("position");
                }

                var scaleJson = json.GetNamedObject("s", null);

                if (scaleJson != null)
                {
                    scale = AnimatableScaleValue.Factory.NewInstance(scaleJson, composition);
                }
                else
                {
                    // Somehow some community animations don't have scale in the transform.
                    scale = new AnimatableScaleValue(new List <IKeyframe <ScaleXy> >(), new ScaleXy());
                }

                var rotationJson = json.GetNamedObject("r", null);

                if (rotationJson == null)
                {
                    rotationJson = json.GetNamedObject("rz", null);
                }
                if (rotationJson != null)
                {
                    rotation = AnimatableFloatValue.Factory.NewInstance(rotationJson, composition, false);
                }
                else
                {
                    ThrowMissingTransform("rotation");
                }

                var opacityJson = json.GetNamedObject("o", null);

                if (opacityJson != null)
                {
                    opacity = AnimatableIntegerValue.Factory.NewInstance(opacityJson, composition);
                }
                else
                {
                    // Somehow some community animations don't have opacity in the transform.
                    opacity = new AnimatableIntegerValue(new List <IKeyframe <int?> >(), 100);
                }
                return(new AnimatableTransform(anchorPoint, position, scale, rotation, opacity));
            }
コード例 #10
0
            internal static GradientStroke NewInstance(JsonObject json, LottieComposition composition)
            {
                var name      = json.GetNamedString("nm");
                var jsonColor = json.GetNamedObject("g", null);

                if (jsonColor != null && jsonColor.ContainsKey("k"))
                {
                    jsonColor = jsonColor.GetNamedObject("k");
                }
                AnimatableGradientColorValue color = null;

                if (jsonColor != null)
                {
                    color = AnimatableGradientColorValue.Factory.NewInstance(jsonColor, composition);
                }

                var jsonOpacity = json.GetNamedObject("o", null);
                AnimatableIntegerValue opacity = null;

                if (jsonOpacity != null)
                {
                    opacity = AnimatableIntegerValue.Factory.NewInstance(jsonOpacity, composition);
                }

                var gradientTypeInt = (int)json.GetNamedNumber("t", 1);
                var gradientType    = gradientTypeInt == 1 ? GradientType.Linear : GradientType.Radial;

                var jsonStartPoint = json.GetNamedObject("s", null);
                AnimatablePointValue startPoint = null;

                if (jsonStartPoint != null)
                {
                    startPoint = AnimatablePointValue.Factory.NewInstance(jsonStartPoint, composition);
                }

                var jsonEndPoint = json.GetNamedObject("e", null);
                AnimatablePointValue endPoint = null;

                if (jsonEndPoint != null)
                {
                    endPoint = AnimatablePointValue.Factory.NewInstance(jsonEndPoint, composition);
                }
                var width = AnimatableFloatValue.Factory.NewInstance(json.GetNamedObject("w"), composition);


                var capType  = (ShapeStroke.LineCapType)(int)(json.GetNamedNumber("lc") - 1);
                var joinType = (ShapeStroke.LineJoinType)(int)(json.GetNamedNumber("lj") - 1);

                AnimatableFloatValue         offset          = null;
                IList <AnimatableFloatValue> lineDashPattern = new List <AnimatableFloatValue>();

                if (json.ContainsKey("d"))
                {
                    var dashesJson = json.GetNamedArray("d");
                    for (var i = 0; i < dashesJson.Count; i++)
                    {
                        var dashJson = dashesJson[i].GetObject();
                        var n        = dashJson.GetNamedString("n");
                        if (n.Equals("o"))
                        {
                            var value = dashJson.GetNamedObject("v");
                            offset = AnimatableFloatValue.Factory.NewInstance(value, composition);
                        }
                        else if (n.Equals("d") || n.Equals("g"))
                        {
                            var value = dashJson.GetNamedObject("v");
                            lineDashPattern.Add(AnimatableFloatValue.Factory.NewInstance(value, composition));
                        }
                    }
                    if (lineDashPattern.Count == 1)
                    {
                        // If there is only 1 value then it is assumed to be equal parts on and off.
                        lineDashPattern.Add(lineDashPattern[0]);
                    }
                }

                return(new GradientStroke(name, gradientType, color, opacity, startPoint, endPoint, width, capType, joinType, lineDashPattern, offset));
            }
コード例 #11
0
        internal BaseStrokeContent(LottieDrawable lottieDrawable, BaseLayer layer, PenLineCap cap, PenLineJoin join, AnimatableIntegerValue opacity, AnimatableFloatValue width, IList <AnimatableFloatValue> dashPattern, AnimatableFloatValue offset)
        {
            _lottieDrawable = lottieDrawable;

            Paint.Style      = Paint.PaintStyle.Stroke;
            Paint.StrokeCap  = cap;
            Paint.StrokeJoin = join;

            _opacityAnimation = opacity.CreateAnimation();
            _widthAnimation   = width.CreateAnimation();

            if (offset == null)
            {
                _dashPatternOffsetAnimation = null;
            }
            else
            {
                _dashPatternOffsetAnimation = offset.CreateAnimation();
            }
            _dashPatternAnimations = new List <IBaseKeyframeAnimation <float?> >(dashPattern.Count);
            _dashPatternValues     = new double[dashPattern.Count];

            for (var i = 0; i < dashPattern.Count; i++)
            {
                _dashPatternAnimations.Add(dashPattern[i].CreateAnimation());
            }

            layer.AddAnimation(_opacityAnimation);
            layer.AddAnimation(_widthAnimation);
            for (var i = 0; i < _dashPatternAnimations.Count; i++)
            {
                layer.AddAnimation(_dashPatternAnimations[i]);
            }
            if (_dashPatternOffsetAnimation != null)
            {
                layer.AddAnimation(_dashPatternOffsetAnimation);
            }

            _opacityAnimation.ValueChanged += OnValueChanged;
            _widthAnimation.ValueChanged   += OnValueChanged;

            for (var i = 0; i < dashPattern.Count; i++)
            {
                _dashPatternAnimations[i].ValueChanged += OnValueChanged;
            }
            if (_dashPatternOffsetAnimation != null)
            {
                _dashPatternOffsetAnimation.ValueChanged += OnValueChanged;
            }
        }
コード例 #12
0
ファイル: Mask.cs プロジェクト: cloudmosa/LottieUWP
 private Mask(MaskMode maskMode, AnimatableShapeValue maskPath, AnimatableIntegerValue opacity)
 {
     _maskMode = maskMode;
     MaskPath  = maskPath;
     Opacity   = opacity;
 }