Пример #1
0
 public virtual float?ValueFromObject(IJsonValue @object, float scale)
 {
     return(JsonUtils.ValueFromObject(@object) * scale);
 }
Пример #2
0
            internal static Keyframe <T> NewInstance(JsonObject json, LottieComposition composition, float scale, IAnimatableValueFactory <T> valueFactory)
            {
                Vector2?      cp1          = null;
                Vector2?      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 Vector2(MiscUtils.Clamp(cp1.Value.X, -scale, scale),
                                          MiscUtils.Clamp(cp1.Value.Y, -MaxCpValue, MaxCpValue));
                        cp2 = new Vector2(MiscUtils.Clamp(cp2.Value.X, -scale, scale),
                                          MiscUtils.Clamp(cp2.Value.Y, -MaxCpValue, MaxCpValue));

                        int hash = Utils.HashFor(cp1.Value.X, cp1.Value.Y, cp2.Value.X, cp2.Value.Y);
                        if (PathInterpolatorCache.TryGetValue(hash, out var interpolatorRef) == false ||
                            interpolatorRef.TryGetTarget(out interpolator) == false)
                        {
                            interpolator = new PathInterpolator(cp1.Value.X / scale, cp1.Value.Y / scale, cp2.Value.X / scale, cp2.Value.Y / scale);
                            PathInterpolatorCache[hash] = new WeakReference <IInterpolator>(interpolator);
                        }
                    }
                    else
                    {
                        interpolator = LinearInterpolator;
                    }
                }
                else
                {
                    startValue = valueFactory.ValueFromObject(json, scale);
                    endValue   = startValue;
                }
                return(new Keyframe <T>(composition, startValue, endValue, interpolator, startFrame, null));
            }
 public PointF ValueFromObject(IJsonValue @object, float scale)
 {
     return(JsonUtils.PointFromJsonArray(@object.GetArray(), scale));
 }
Пример #4
0
 public int?ValueFromObject(IJsonValue @object, float scale)
 {
     return((int?)Math.Round(JsonUtils.ValueFromObject(@object) * scale));
 }