示例#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));
            }
 private RectangleShape(string name, IAnimatableValue <PointF> position, AnimatablePointValue size, AnimatableFloatValue cornerRadius)
 {
     Name          = name;
     _position     = position;
     _size         = size;
     _cornerRadius = cornerRadius;
 }
示例#3
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;
 }
 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;
 }
            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));
            }
示例#6
0
 private CircleShape(string name, IAnimatableValue <Vector2?> position, AnimatablePointValue size)
 {
     Name     = name;
     Position = position;
     Size     = size;
 }