Example #1
0
 /// <summary>
 ///     Pause the animation
 /// </summary>
 public virtual void Pause()
 {
     if (CurrentStatus != AnimatorStatus.OnHold && CurrentStatus != AnimatorStatus.Playing)
     {
         return;
     }
     _timer.Stop();
     CurrentStatus = AnimatorStatus.Paused;
 }
Example #2
0
 public virtual void Stop()
 {
     this._timer.Stop();
     lock (this._tempPaths)
         this._tempPaths.Clear();
     this.ActivePath         = (Path)null;
     this.CurrentStatus      = AnimatorStatus.Stopped;
     this._tempReverseRepeat = false;
 }
Example #3
0
 /// <summary>
 ///     Stops the animation and resets its status, resume is no longer possible
 /// </summary>
 public virtual void Stop()
 {
     _timer.Stop();
     lock (_tempPaths)
     {
         _tempPaths.Clear();
     }
     ActivePath         = null;
     CurrentStatus      = AnimatorStatus.Stopped;
     _tempReverseRepeat = false;
 }
Example #4
0
        /// <summary>
        /// Starts an animation to the given parameters.
        /// </summary>
        /// <param name="center"></param>
        /// <param name="zoomLevel"></param>
        /// <param name="mapTilt"></param>
        /// <param name="time"></param>
        public void Start(GeoCoordinate center, float zoomLevel, Degree mapTilt, TimeSpan time)
        {
            // stop the previous timer.
            if (_timer != null)
            {             // timer exists, it might be active disable it immidiately.
                // cancel previous status.
                _timerStatus.Cancelled = true;
                _timer.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);
                _timer.Dispose();
            }

            // set the targets.
            _targetCenter = center;
            _targetTilt   = mapTilt;
            _targetZoom   = zoomLevel;

            // calculate the animation steps.
            _maxSteps    = (int)System.Math.Round((double)time.TotalMilliseconds / (double)_minimumTimeSpan.TotalMilliseconds, 0);
            _currentStep = 0;
            _stepCenter  = new GeoCoordinate(
                (_targetCenter.Latitude - _mapView.MapCenter.Latitude) / _maxSteps,
                (_targetCenter.Longitude - _mapView.MapCenter.Longitude) / _maxSteps);
            _stepZoom = (float)((_targetZoom - _mapView.MapZoom) / _maxSteps);

            // calculate the map tilt, make sure it turns along the smallest corner.
            double diff = _targetTilt.SmallestDifference(_mapView.MapTilt);

            OsmSharp.Logging.Log.TraceEvent("MapViewAnimator", OsmSharp.Logging.TraceEventType.Information, diff.ToString());
            _stepTilt = (diff / _maxSteps);

            OsmSharp.Logging.Log.TraceEvent("MapViewAnimator", OsmSharp.Logging.TraceEventType.Verbose,
                                            string.Format("Started new animation with steps z:{0} t:{1} c:{2} to z:{3} t:{4} c:{5} from z:{6} t:{7} c:{8}.",
                                                          _stepZoom, _stepTilt, _stepCenter.ToString(),
                                                          _targetZoom, _targetTilt, _targetCenter.ToString(),
                                                          _mapView.MapZoom, _mapView.MapTilt, _mapView.MapCenter.ToString()));

            // disable auto invalidate.
            _mapView.RegisterAnimator(this);

            // start the timer.
            // create a new timer.
            _timerStatus = new AnimatorStatus();
            _timer       = new Timer(new TimerCallback(_timer_Elapsed), _timerStatus, 0, (int)_minimumTimeSpan.TotalMilliseconds);
        }
Example #5
0
        /// <summary>
        /// Starts an animation to the given parameters.
        /// </summary>
        /// <param name="center"></param>
        /// <param name="zoomLevel"></param>
        /// <param name="mapTilt"></param>
        /// <param name="time"></param>
        public void Start(GeoCoordinate center, float zoomLevel, Degree mapTilt, TimeSpan time)
        {
            // stop the previous timer.
            if (_timer != null)
            {             // timer exists, it might be active disable it immidiately.
                // cancel previous status.
                _timerStatus.Cancelled = true;
                _timer.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);
                _timer.Dispose();
            }

            // Create the animation function.
            _animationFunction = CubicBezier.createEase();

            // Initialaize the start and end state of the map.
            _startState   = new MapAnimationState(_mapView.MapZoom, _mapView.MapTilt, _mapView.MapCenter);
            _endState     = new MapAnimationState(zoomLevel, mapTilt, center);
            _currentState = new MapAnimationState(_mapView.MapZoom, _mapView.MapTilt, _mapView.MapCenter);

            OsmSharp.Logging.Log.TraceEvent("MapViewAnimator", OsmSharp.Logging.TraceEventType.Verbose,
                                            string.Format("Started new animation to z:{0} t:{1} c:{2} from z:{3} t:{4} c:{5}.",
                                                          _endState.Zoom, _endState.Tilt, _endState.Center.ToString(),
                                                          _mapView.MapZoom, _mapView.MapTilt, _mapView.MapCenter.ToString()));

            // disable auto invalidate.
            _mapView.RegisterAnimator(this);

            _startTime = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
            _duration  = (long)time.TotalMilliseconds;
            _endTime   = _startTime + _duration;

            // start the timer.
            // create a new timer.
            _timerStatus = new AnimatorStatus();
            _timer       = new Timer(new TimerCallback(_timer_Elapsed), _timerStatus, 0, (int)_minimumTimeSpan.TotalMilliseconds);
        }
Example #6
0
 private void ElapsedInt(ulong millSinceBeginning = 0)
 {
     while (true)
     {
         lock (_tempPaths)
         {
             if (_tempPaths != null && ActivePath == null && _tempPaths.Count > 0)
             {
                 while (ActivePath == null)
                 {
                     if (_tempReverseRepeat)
                     {
                         ActivePath = _tempPaths.LastOrDefault();
                         _tempPaths.RemoveAt(_tempPaths.Count - 1);
                     }
                     else
                     {
                         ActivePath = _tempPaths.FirstOrDefault();
                         _tempPaths.RemoveAt(0);
                     }
                     _timer.ResetClock();
                     millSinceBeginning = 0;
                 }
             }
             var ended = ActivePath == null;
             if (ActivePath != null)
             {
                 if (!_tempReverseRepeat && millSinceBeginning < ActivePath.Delay)
                 {
                     CurrentStatus = AnimatorStatus.OnHold;
                     return;
                 }
                 if (millSinceBeginning - (!_tempReverseRepeat ? ActivePath.Delay : 0) <= ActivePath.Duration)
                 {
                     if (CurrentStatus != AnimatorStatus.Playing)
                     {
                         CurrentStatus = AnimatorStatus.Playing;
                     }
                     var value = ActivePath.Function(_tempReverseRepeat ? ActivePath.Duration - millSinceBeginning : millSinceBeginning - ActivePath.Delay, ActivePath.Start, ActivePath.Change, ActivePath.Duration);
                     FrameCallbackInt.Invoke((int)value);
                     return;
                 }
                 if (CurrentStatus == AnimatorStatus.Playing)
                 {
                     if (_tempPaths.Count == 0)
                     {
                         // For the last path, we make sure that control is in end point
                         FrameCallbackInt.Invoke(_tempReverseRepeat ? (int)ActivePath.Start : (int)ActivePath.End);
                         ended = true;
                     }
                     else
                     {
                         if ((_tempReverseRepeat && ActivePath.Delay > 0) || !_tempReverseRepeat && _tempPaths.FirstOrDefault()?.Delay > 0)
                         {
                             // Or if the next path or this one in revese order has a delay
                             FrameCallbackInt.Invoke(_tempReverseRepeat ? (int)ActivePath.Start : (int)ActivePath.End);
                         }
                     }
                 }
                 if (_tempReverseRepeat && (millSinceBeginning - ActivePath.Duration) < ActivePath.Delay)
                 {
                     CurrentStatus = AnimatorStatus.OnHold;
                     return;
                 }
                 ActivePath = null;
             }
             if (!ended)
             {
                 return;
             }
         }
         if (Repeat)
         {
             lock (_tempPaths)
             {
                 _tempPaths.AddRange(_paths);
                 _tempReverseRepeat = ReverseRepeat && !_tempReverseRepeat;
             }
             millSinceBeginning = 0;
             continue;
         }
         Stop();
         EndCallback?.Invoke();
         break;
     }
 }
Example #7
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="Animator" /> class.
 /// </summary>
 /// <param name="paths">
 ///     An array containing the list of paths of the animation
 /// </param>
 /// <param name="fpsLimiter">
 ///     Limits the maximum frames per seconds
 /// </param>
 /// <param name="type">
 ///     Redundant value. Enter 1
 /// </param>
 public Animator(Path[] paths, FPSLimiterKnownValues fpsLimiter, int type)
 {
     CurrentStatus = AnimatorStatus.Stopped;
     _timer        = new Timer(ElapsedInt, fpsLimiter);
     Paths         = paths;
 }
Example #8
0
 public Animator(Path[] paths, FPSLimiterKnownValues fpsLimiter)
 {
     this.CurrentStatus = AnimatorStatus.Stopped;
     this._timer        = new Timer(new Action <ulong>(this.Elapsed), fpsLimiter);
     this.Paths         = paths;
 }
Example #9
0
 private void Elapsed(ulong millSinceBeginning)
 {
     lock (this._tempPaths)
     {
         if (this._tempPaths != null && this.ActivePath == null && this._tempPaths.Count > 0)
         {
             while (this.ActivePath == null)
             {
                 if (this._tempReverseRepeat)
                 {
                     this.ActivePath = this._tempPaths.LastOrDefault <Path>();
                     this._tempPaths.RemoveAt(this._tempPaths.Count - 1);
                 }
                 else
                 {
                     this.ActivePath = this._tempPaths.FirstOrDefault <Path>();
                     this._tempPaths.RemoveAt(0);
                 }
                 this._timer.ResetClock();
                 millSinceBeginning = 0UL;
             }
         }
         if (this.ActivePath != null)
         {
             if (!this._tempReverseRepeat && millSinceBeginning < this.ActivePath.Delay)
             {
                 this.CurrentStatus = AnimatorStatus.OnHold;
             }
             else if (millSinceBeginning - (!this._tempReverseRepeat ? this.ActivePath.Delay : 0UL) <= this.ActivePath.Duration)
             {
                 if (this.CurrentStatus != AnimatorStatus.Playing)
                 {
                     this.FrameCallback.Invoke(this._tempReverseRepeat ? this.ActivePath.End : this.ActivePath.Start);
                     this.CurrentStatus = AnimatorStatus.Playing;
                 }
                 this.FrameCallback.Invoke(this.ActivePath.Function(this._tempReverseRepeat ? (float)(this.ActivePath.Duration - millSinceBeginning) : (float)(millSinceBeginning - this.ActivePath.Delay), this.ActivePath.Start, this.ActivePath.Change, (float)this.ActivePath.Duration));
             }
             else
             {
                 if (this.CurrentStatus == AnimatorStatus.Playing)
                 {
                     this.FrameCallback.Invoke(this._tempReverseRepeat ? this.ActivePath.Start : this.ActivePath.End);
                 }
                 if (this._tempReverseRepeat && millSinceBeginning - this.ActivePath.Duration < this.ActivePath.Delay)
                 {
                     this.CurrentStatus = AnimatorStatus.OnHold;
                 }
                 else
                 {
                     this.ActivePath = (Path)null;
                 }
             }
         }
         else if (this.Repeat)
         {
             lock (this._tempPaths)
             {
                 this._tempPaths.AddRange((IEnumerable <Path>) this._paths);
                 this._tempReverseRepeat = this.ReverseRepeat && !this._tempReverseRepeat;
             }
         }
         else
         {
             this.Stop();
             SafeInvoker temp_11 = this.EndCallback;
             if (temp_11 == null)
             {
                 return;
             }
             temp_11.Invoke();
         }
     }
 }
Example #10
0
 private void Elapsed(ulong millSinceBeginning)
 {
     lock (_tempPaths)
     {
         if (_tempPaths != null && ActivePath == null && _tempPaths.Count > 0)
         {
             while (ActivePath == null)
             {
                 if (_tempReverseRepeat)
                 {
                     ActivePath = _tempPaths.LastOrDefault();
                     _tempPaths.RemoveAt(_tempPaths.Count - 1);
                 }
                 else
                 {
                     ActivePath = _tempPaths.FirstOrDefault();
                     _tempPaths.RemoveAt(0);
                 }
                 _timer.ResetClock();
                 millSinceBeginning = 0;
             }
         }
         if (ActivePath != null)
         {
             if (!_tempReverseRepeat && millSinceBeginning < ActivePath.Delay)
             {
                 CurrentStatus = AnimatorStatus.OnHold;
                 return;
             }
             if (millSinceBeginning - (!_tempReverseRepeat ? ActivePath.Delay : 0) <= ActivePath.Duration)
             {
                 if (CurrentStatus != AnimatorStatus.Playing)
                 {
                     FrameCallback.Invoke(_tempReverseRepeat ? ActivePath.End : ActivePath.Start);
                     CurrentStatus = AnimatorStatus.Playing;
                 }
                 var value = ActivePath.Function(
                     _tempReverseRepeat
                         ? ActivePath.Duration - millSinceBeginning
                         : millSinceBeginning - ActivePath.Delay,
                     ActivePath.Start,
                     ActivePath.Change,
                     ActivePath.Duration);
                 FrameCallback.Invoke(value);
                 return;
             }
             if (CurrentStatus == AnimatorStatus.Playing)
             {
                 FrameCallback.Invoke(_tempReverseRepeat ? ActivePath.Start : ActivePath.End);
             }
             if (_tempReverseRepeat && (millSinceBeginning - ActivePath.Duration) < ActivePath.Delay)
             {
                 CurrentStatus = AnimatorStatus.OnHold;
                 return;
             }
             ActivePath = null;
         }
         else if (Repeat)
         {
             lock (_tempPaths)
             {
                 _tempPaths.AddRange(_paths);
                 _tempReverseRepeat = ReverseRepeat && !_tempReverseRepeat;
             }
         }
         else
         {
             Stop();
             EndCallback?.Invoke();
         }
     }
 }
Example #11
0
        /// <summary>
        /// Starts an animation to the given parameters.
        /// </summary>
        /// <param name="center"></param>
        /// <param name="zoomLevel"></param>
        /// <param name="mapTilt"></param>
        /// <param name="time"></param>
        public void Start(GeoCoordinate center, float zoomLevel, Degree mapTilt, TimeSpan time)
        {
            // stop the previous timer.
            if (_timer != null)
            { // timer exists, it might be active disable it immidiately.
                // cancel previous status.
                _timerStatus.Cancelled = true;
                _timer.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);
                _timer.Dispose();
            }

            // set the targets.
            _targetCenter = center;
            _targetTilt = mapTilt;
            _targetZoom = zoomLevel;

            // calculate the animation steps.
            _maxSteps = (int)System.Math.Round((double)time.TotalMilliseconds / (double)_minimumTimeSpan.TotalMilliseconds, 0);
            _currentStep = 0;
            _stepCenter = new GeoCoordinate(
                (_targetCenter.Latitude - _mapView.MapCenter.Latitude) / _maxSteps,
                (_targetCenter.Longitude - _mapView.MapCenter.Longitude) / _maxSteps);
            _stepZoom = (float)((_targetZoom - _mapView.MapZoom) / _maxSteps);

            // calculate the map tilt, make sure it turns along the smallest corner.
            double diff = _targetTilt.SmallestDifference(_mapView.MapTilt);
            OsmSharp.Logging.Log.TraceEvent("MapViewAnimator", OsmSharp.Logging.TraceEventType.Information, diff.ToString());
                _stepTilt = (diff / _maxSteps);

            OsmSharp.Logging.Log.TraceEvent("MapViewAnimator", OsmSharp.Logging.TraceEventType.Verbose,
                string.Format("Started new animation with steps z:{0} t:{1} c:{2} to z:{3} t:{4} c:{5} from z:{6} t:{7} c:{8}.",
                    _stepZoom, _stepTilt, _stepCenter.ToString(),
                    _targetZoom, _targetTilt, _targetCenter.ToString(),
                    _mapView.MapZoom, _mapView.MapTilt, _mapView.MapCenter.ToString()));

            // disable auto invalidate.
            _mapView.RegisterAnimator(this);

            // start the timer.
            // create a new timer.
            _timerStatus = new AnimatorStatus();
            _timer = new Timer(new TimerCallback(_timer_Elapsed), _timerStatus, 0, (int)_minimumTimeSpan.TotalMilliseconds);
        }
Example #12
0
        /// <summary>
        /// Starts an animation to the given parameters.
        /// </summary>
        /// <param name="center"></param>
        /// <param name="zoomLevel"></param>
        /// <param name="mapTilt"></param>
        /// <param name="time"></param>
        public void Start(GeoCoordinate center, float zoomLevel, Degree mapTilt, TimeSpan time)
		{
			// stop the previous timer.
			if (_timer != null)
			{ // timer exists, it might be active disable it immidiately.
				// cancel previous status.
				_timerStatus.Cancelled = true;
				_timer.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);
				_timer.Dispose();
			}

            // Create the animation function.
            _animationFunction = CubicBezier.createEase();

			// Initialaize the start and end state of the map.
            _startState = new MapAnimationState(_mapView.MapZoom, _mapView.MapTilt, _mapView.MapCenter);
            _endState   = new MapAnimationState(zoomLevel, mapTilt, center);
            _currentState = new MapAnimationState(_mapView.MapZoom, _mapView.MapTilt, _mapView.MapCenter);

			OsmSharp.Logging.Log.TraceEvent("MapViewAnimator", OsmSharp.Logging.TraceEventType.Verbose,
				string.Format("Started new animation to z:{0} t:{1} c:{2} from z:{3} t:{4} c:{5}.",
					_endState.Zoom, _endState.Tilt, _endState.Center.ToString(), 
					_mapView.MapZoom, _mapView.MapTilt, _mapView.MapCenter.ToString()));

			// disable auto invalidate.
			_mapView.RegisterAnimator(this);

            _startTime = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
            _duration = (long)time.TotalMilliseconds;
            _endTime = _startTime + _duration;

			// start the timer.
			// create a new timer.
			_timerStatus = new AnimatorStatus();
			_timer = new Timer(new TimerCallback(_timer_Elapsed), _timerStatus, 0, (int)_minimumTimeSpan.TotalMilliseconds);
            
		}