Beispiel #1
0
        public void Animate(int duration, int fps, IAnimateHandler handler, Action onFinished, AnimateFunctionType funcType)
        {
            if (_disposed || !IsAvailable)
            {
                return;
            }

            var start = DateTime.Now;
            var end   = DateTime.Now.AddMilliseconds(duration);

            if (_timer == null)
            {
                _timer = new Timer();

                _timer.Tick += (x, y) =>
                {
                    if (DateTime.Now > end)
                    {
                        handler.OnAnimate(AnimateFunction.Caculate(funcType, 1f));
                        onFinished?.Invoke();
                        _timer.Enabled = false;
                        IsAvailable    = true;
                    }
                    else
                    {
                        handler?.OnAnimate(AnimateFunction.Caculate(funcType, (float)(DateTime.Now - start).TotalMilliseconds / (float)duration));
                    }
                };
            }

            _timer.Interval = (int)(1000 / (float)fps);
            IsAvailable     = false;
            _timer.Enabled  = true;
        }
Beispiel #2
0
 public void Add(IAnimateHandler animateHandler, bool safe = false)
 {
     if (safe && _animateHandlers.Contains(animateHandler))
     {
         return;
     }
     _animateHandlers.Add(animateHandler);
 }
Beispiel #3
0
 public void Remove(IAnimateHandler animateHandler)
 {
     if (_isAnimateInProcess)
     {
         _removedAnimateHandlers.Add(animateHandler);
     }
     else
     {
         _animateHandlers.Remove(animateHandler);
     }
 }