public static void SetPositiveDependencyPropValue(object obj, GetterSetterData data, double percent)
 {
     if (data != null)
     {
         ((DependencyObject)obj).SetValue(data.Prop as DependencyProperty, Math.Max(0D, EaseHelper.EaseValue((double)data.ValueStart, (double)data.ValueEnd, percent)));
     }
 }
Exemple #2
0
        public static Dictionary <string, GetterSetterData> ValidatePropsAndValue(object obj, object prop, object endValue)
        {
            var vList          = new Dictionary <string, GetterSetterData>();
            GetterSetterData g = null;

            if (prop is Array)
            {
                // must be in object[] form
                var props     = (prop is object[]) ? (object[])prop : ConvertToObjectArray(prop);
                var endValues = (endValue is object[]) ? (object[])endValue : ConvertToObjectArray(endValue);

                for (_i = 0; _i < props.Length; _i++)
                {
                    g = ValidatePropAndValue(obj, props[_i], endValues[_i]);
                    if (g != null)
                    {
                        vList[g.Name] = g;
                    }
                }
            }
            else
            {
                g = ValidatePropAndValue(obj, prop, endValue);
                if (g != null)
                {
                    vList[g.Name] = g;
                }
            }

            return(vList);
        }
 public static void SetPositiveDependencyPropValue(object obj, GetterSetterData data, double percent)
 {
     if (data != null) ((DependencyObject)obj).SetValue(data.Prop as DependencyProperty, Math.Max(0D, EaseHelper.EaseValue((double)data.ValueStart, (double)data.ValueEnd, percent)));
 }
 public static object GetPositiveDoubleDependencyPropValue(object obj, GetterSetterData data)
 {
     return ((DependencyObject)obj).GetValue(data.Prop as DependencyProperty);
 }
Exemple #5
0
        /**
         * public static EaseObject AddEase(object obj, object props, object endValues, GetterSetter gettersGetters, double time, PercentHandler ease, double delay)
         * {
         *  throw new NotImplementedException();
         *  return new EaseObject(time, ease, delay);
         * }
         #region OVERLOADS
         #endregion
         */

        #endregion

        #endregion

        #region VALIDATION - GETTER SETTER DATA
        public static GetterSetterData ValidatePropAndValue(object obj, object prop, object endValue)
        {
            GetterSetterData g  = null;
            GetterSetter     gs = null;

            if (prop as DependencyProperty != null)
            {
                if (AnimationTypes.GetterSettersByDependencyProperty.ContainsKey(prop as DependencyProperty))
                {
                    gs = AnimationTypes.GetterSettersByDependencyProperty[prop as DependencyProperty];
                }
                else
                {
                    try
                    {
                        var valueType = endValue.GetType();
                        if (AnimationTypes.GetterSettersByType.ContainsKey(valueType))
                        {
                            gs = AnimationTypes.GetterSettersByType[valueType];
                        }
                    }
                    catch (Exception error)
                    {
                        Debug.WriteLine("[ERROR] - " + error);
                        #if DEBUG
                        throw;
                        #endif
                    }
                }

                g = new GetterSetterData
                {
                    Name       = GetName(prop),
                    Getter     = gs != null ? gs.Getter : AnimationTypes.GetDoubleDependencyPropValue,
                    Setter     = gs != null ? gs.Setter : AnimationTypes.SetDoubleDependencyPropValue,
                    Prop       = prop,
                    ValueStart = endValue is int?(double)((int)endValue) : endValue,
                };
                g.ValueEnd = g.ValueStart;
            }
            else if (prop as string != null)
            {
                var propStr = prop as string;
                if (AnimationTypes.Shortcuts.ContainsKey(propStr))
                {
                    // SHORTCUT
                    if (AnimationTypes.Shortcuts[propStr] as DependencyProperty != null)
                    {
                        var dp = AnimationTypes.Shortcuts[propStr] as DependencyProperty;
                        if (dp != null)
                        {
                            if (AnimationTypes.GetterSettersByDependencyProperty.ContainsKey(dp))
                            {
                                gs = AnimationTypes.GetterSettersByDependencyProperty[dp];
                            }
                        }
                    }

                    g = new GetterSetterData
                    {
                        Name       = propStr,
                        Getter     = gs != null ? gs.Getter : AnimationTypes.GetDoubleDependencyPropValue,
                        Setter     = gs != null ? gs.Setter : AnimationTypes.SetDoubleDependencyPropValue,
                        Prop       = AnimationTypes.Shortcuts[propStr],
                        ValueStart = endValue is int?(double)((int)endValue) : endValue
                    };
                    g.ValueEnd = g.ValueStart;
                }
                else if (AnimationTypes.GetterSetterHash.ContainsKey(propStr))
                {
                    // GETTER / SETTER
                    g = new GetterSetterData
                    {
                        Name       = propStr,
                        Getter     = AnimationTypes.GetterSetterHash[propStr].Getter,
                        Setter     = AnimationTypes.GetterSetterHash[propStr].Setter,
                        Prop       = propStr,
                        ValueStart = endValue is int?(double)((int)endValue) : endValue
                    };
                    g.ValueEnd = g.ValueStart;
                }
                else
                {
                    // SIMPLE DEPENDENCY PROPERTY - FROM STRING
                    if (AnimationTypes.Shortcuts.ContainsKey(propStr) && AnimationTypes.Shortcuts[propStr] as DependencyProperty != null)
                    {
                        var dp = AnimationTypes.Shortcuts[propStr] as DependencyProperty;
                        if (dp != null)
                        {
                            if (AnimationTypes.GetterSettersByDependencyProperty.ContainsKey(dp))
                            {
                                gs = AnimationTypes.GetterSettersByDependencyProperty[dp];
                                g  = new GetterSetterData
                                {
                                    Name       = GetName(prop),
                                    Getter     = gs != null ? gs.Getter : AnimationTypes.GetDoubleDependencyPropValue,
                                    Setter     = gs != null ? gs.Setter : AnimationTypes.SetDoubleDependencyPropValue,
                                    Prop       = dp,
                                    ValueStart = endValue is int?(double)((int)endValue) : endValue
                                };
                                g.ValueEnd = g.ValueStart;
                                return(g);
                            }
                        }
                    }

                    if (gs == null)
                    {
                        throw new Exception("String \"" + prop + "\" is not registered with ArtefactAnimator and therefore cannot be animated. EndValue=" + endValue);
                    }
                }
            }
            return(g);
        }
 public static object GetPositiveDoubleDependencyPropValue(object obj, GetterSetterData data)
 {
     return(((DependencyObject)obj).GetValue(data.Prop as DependencyProperty));
 }
 private void ResetBeginingValues()
 {
     try
     {
         foreach (GetterSetterData data in Props.Values)
         {
             if (!data.IsActive)
             {
                 continue;
             }
             try
             {
                 data.ValueStart = data.Getter(Target, data);
                 RegisterDependencyProperty(data.Name);
             }
             catch (Exception error)
             {
                 data.IsActive = false;
                 Debug.WriteLine(string.Format("{0} - [ERROR] - Failed to ResetBeginingValue. Setting Prop InActive. - {1} - \n{2}", this, GetterSetterData.Describe(data), error));
                 #if DEBUG
                 throw;
                 #endif
             }
         }
     }
     catch (Exception error)
     {
         Debug.WriteLine(string.Format("{0} - [ERROR] - ResetBeginingValues - {1}", this, error));
         #if DEBUG
         throw;
         #endif
     }
 }
        public void Tick()
        {
            if ((flags & IS_RUNNING) != IS_RUNNING ||   // Ease object is not running
                Props.Count <= 0)                       // Without properties to ease, there is no way to tell when to stop.
            {
                #if debug
                Debug.WriteLine(string.Format("{0} {1}/{2} - [ERROR] - Not Currently Running or missing props to ease -> stopping esae object now.", this, inx, EaseObjectCount));
                #endif

                Stop();
                return;
            }

            // Calculate ellapsed time
            _timeElapsed = ArtefactAnimator.ElapsedMilliseconds - TimeStarted;


            if ((flags & IS_DELAYED) == IS_DELAYED) // Check delay
            {
                if (_timeElapsed < Delay)           // wait
                {
                    #if debug
                    Debug.WriteLine(string.Format("{0} - [DEBUG] - Delayed{3} - {1}<{2}.", this, _timeElapsed, Delay, inx));
                    #endif

                    return;
                }

                // continue
                flags       -= IS_DELAYED;
                TimeStarted  = ArtefactAnimator.ElapsedMilliseconds - (_timeElapsed - Delay);
                _timeElapsed = 0;
            }

            // first time running - set begining values
            if ((flags & IS_FIRSTRUN) == IS_FIRSTRUN)
            {
                flags -= IS_FIRSTRUN;
                ResetBeginingValues();
                if (Begin != null)
                {
                    Begin(this, PercentEase);
                }
            }


            if (Time < _timeElapsed)
            {
                Finish();
                return;
            }

            // update
            PercentTime = (_timeElapsed) / Time;
            PercentEase = Ease == null ? PercentTime : Ease(PercentTime);
            ActiveCount = 0;

            foreach (GetterSetterData data in Props.Values)
            {
                if (!data.IsActive)
                {
                    continue;
                }
                ActiveCount++;
                try
                {
                    data.Setter(Target, data, PercentEase);
                }
                catch (Exception error)
                {
                    data.IsActive = false;
                    ActiveCount--;
                    Debug.WriteLine("[ERROR] - EaseObject failed to apply Setter in Update() - " + GetterSetterData.Describe(data) + "\n" + error);
                   #if DEBUG
                    throw;
                   #endif
                }
            }

            if (ActiveCount > 0)
            {
                if (Update != null)
                {
                    Update(this, PercentEase);
                }
            }
            else
            {
                Stop(); // Nothing happened
            }
        }
        public static GetterSetterData ValidatePropAndValue(object obj, object prop, object endValue)
        {
            GetterSetterData g = null;
            GetterSetter gs = null;

            if (prop as DependencyProperty != null)
            {

                if (AnimationTypes.GetterSettersByDependencyProperty.ContainsKey(prop as DependencyProperty))
                {
                    gs = AnimationTypes.GetterSettersByDependencyProperty[prop as DependencyProperty];
                }
                else
                {
                    try
                    {
                        var valueType = endValue.GetType();
                        if (AnimationTypes.GetterSettersByType.ContainsKey(valueType))
                        {
                            gs = AnimationTypes.GetterSettersByType[valueType];
                        }
                    }
                    catch (Exception error)
                    {
                        Debug.WriteLine("[ERROR] - " + error);
                        return null;
                    }
                }

                g = new GetterSetterData
                {
                    Name = GetName(prop),
                    Getter = gs != null ? gs.Getter : AnimationTypes.GetDoubleDependencyPropValue,
                    Setter = gs != null ? gs.Setter : AnimationTypes.SetDoubleDependencyPropValue,
                    Prop = prop,
                    ValueStart = endValue is int ? (double)((int)endValue) : endValue,
                };
                g.ValueEnd = g.ValueStart;
            }
            else if (prop as string != null)
            {
                var propStr = prop as string;
                if (AnimationTypes.Shortcuts.ContainsKey(propStr))
                {
                    // SHORTCUT
                    if (AnimationTypes.Shortcuts[propStr] as DependencyProperty != null)
                    {
                        var dp = AnimationTypes.Shortcuts[propStr] as DependencyProperty;
                        if (dp != null)
                            if (AnimationTypes.GetterSettersByDependencyProperty.ContainsKey(dp)) gs = AnimationTypes.GetterSettersByDependencyProperty[dp];
                    }

                    g = new GetterSetterData
                    {
                        Name = propStr,
                        Getter = gs != null ? gs.Getter : AnimationTypes.GetDoubleDependencyPropValue,
                        Setter = gs != null ? gs.Setter : AnimationTypes.SetDoubleDependencyPropValue,
                        Prop = AnimationTypes.Shortcuts[propStr],
                        ValueStart = endValue is int ? (double)((int)endValue) : endValue
                    };
                    g.ValueEnd = g.ValueStart;
                }
                else if (AnimationTypes.GetterSetterHash.ContainsKey(propStr))
                {
                    // GETTER / SETTER
                    g = new GetterSetterData
                    {
                        Name = propStr,
                        Getter = AnimationTypes.GetterSetterHash[propStr].Getter,
                        Setter = AnimationTypes.GetterSetterHash[propStr].Setter,
                        Prop = propStr,
                        ValueStart = endValue is int ? (double)((int)endValue) : endValue
                    };
                    g.ValueEnd = g.ValueStart;
                }
                else
                {
                    // SIMPLE DEPENDENCY PROPERTY - FROM STRING
                    if (AnimationTypes.Shortcuts.ContainsKey(propStr) && AnimationTypes.Shortcuts[propStr] as DependencyProperty != null)
                    {
                        var dp = AnimationTypes.Shortcuts[propStr] as DependencyProperty;
                        if (dp != null)
                        {
                            if (AnimationTypes.GetterSettersByDependencyProperty.ContainsKey(dp))
                            {
                                gs = AnimationTypes.GetterSettersByDependencyProperty[dp];
                                g = new GetterSetterData
                                {
                                    Name = GetName(prop),
                                    Getter = gs != null ? gs.Getter : AnimationTypes.GetDoubleDependencyPropValue,
                                    Setter = gs != null ? gs.Setter : AnimationTypes.SetDoubleDependencyPropValue,
                                    Prop = dp,
                                    ValueStart = endValue is int ? (double)((int)endValue) : endValue
                                };
                                g.ValueEnd = g.ValueStart;
                                return g;
                            }
                        }
                    }

                    if (gs == null)
                    {
                        throw new Exception("String \"" + prop + "\" is not registered with ArtefactAnimator and therefore cannot be animated. EndValue=" + endValue);
                    }
                }
            }
            return g;
        }