private AnimatableValueParser(JsonObject json, float scale, LottieComposition composition, IAnimatableValueFactory <T> valueFactory) { _json = json; _scale = scale; _composition = composition; _valueFactory = valueFactory; }
internal static AnimatableValueParser <T> NewInstance(JsonObject json, float scale, LottieComposition composition, IAnimatableValueFactory <T> valueFactory) { return(new AnimatableValueParser <T>(json, scale, composition, valueFactory)); }
internal static Keyframe <T> NewInstance(JsonObject json, LottieComposition composition, float scale, IAnimatableValueFactory <T> valueFactory) { PointF cp1 = null; PointF cp2 = null; float startFrame = 0; var startValue = default(T); var endValue = default(T); IInterpolator interpolator = null; if (json.ContainsKey("t")) { startFrame = (float)json.GetNamedNumber("t", 0); if (json.TryGetValue("s", out var startValueJson)) { startValue = valueFactory.ValueFromObject(startValueJson, scale); } if (json.TryGetValue("e", out var endValueJson)) { endValue = valueFactory.ValueFromObject(endValueJson, scale); } var cp1Json = json.GetNamedObject("o", null); var cp2Json = json.GetNamedObject("i", null); if (cp1Json != null && cp2Json != null) { cp1 = JsonUtils.PointFromJsonObject(cp1Json, scale); cp2 = JsonUtils.PointFromJsonObject(cp2Json, scale); } var hold = (int)json.GetNamedNumber("h", 0) == 1; if (hold) { endValue = startValue; // TODO: create a HoldInterpolator so progress changes don't invalidate. interpolator = LinearInterpolator; } else if (cp1 != null) { cp1 = new PointF(MiscUtils.Clamp(cp1.X, -scale, scale), MiscUtils.Clamp(cp1.Y, -MaxCpValue, MaxCpValue)); cp2 = new PointF(MiscUtils.Clamp(cp2.X, -scale, scale), MiscUtils.Clamp(cp2.Y, -MaxCpValue, MaxCpValue)); interpolator = new PathInterpolator(cp1.X / scale, cp1.Y / scale, cp2.X / scale, cp2.Y / scale); } else { interpolator = LinearInterpolator; } } else { startValue = valueFactory.ValueFromObject(json, scale); endValue = startValue; } return(new Keyframe <T>(composition, startValue, endValue, interpolator, startFrame, null)); }
internal static IList <IKeyframe <T> > ParseKeyframes(JsonArray json, LottieComposition composition, float scale, IAnimatableValueFactory <T> valueFactory) { var length = json.Count; if (length == 0) { return(new List <IKeyframe <T> >()); } IList <IKeyframe <T> > keyframes = new List <IKeyframe <T> >(); for (uint i = 0; i < length; i++) { keyframes.Add(NewInstance(json.GetObjectAt(i), composition, scale, valueFactory)); } SetEndFrames <IKeyframe <T>, T>(keyframes); return(keyframes); }
internal static PathKeyframe NewInstance(JsonObject json, LottieComposition composition, IAnimatableValueFactory <Vector2?> valueFactory) { var keyframe = KeyFrameFactory.NewInstance(json, composition, composition.DpScale, valueFactory); Vector2?cp1 = null; Vector2?cp2 = null; var tiJson = json.GetNamedArray("ti", null); var toJson = json.GetNamedArray("to", null); if (tiJson != null && toJson != null) { cp1 = JsonUtils.PointFromJsonArray(toJson, composition.DpScale); cp2 = JsonUtils.PointFromJsonArray(tiJson, composition.DpScale); } var pathKeyframe = new PathKeyframe(composition, keyframe.StartValue, keyframe.EndValue, keyframe.Interpolator, keyframe.StartFrame, keyframe.EndFrame); var equals = keyframe.EndValue != null && keyframe.StartValue != null && keyframe.StartValue.Equals(keyframe.EndValue); if (pathKeyframe.EndValue != null && !equals) { pathKeyframe._path = Utils.Utils.CreatePath(keyframe.StartValue.Value, keyframe.EndValue.Value, cp1, cp2); } return(pathKeyframe); }