2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 /// EcoreTimelineAnimator is a helper class, it provides functions to manager animations.
24 public class EcoreTimelineAnimator
28 Action _timelineCallback;
29 Interop.Ecore.EcoreTimelineCallback _nativeCallback;
33 /// It occurs when the animator is complete.
35 public event EventHandler Finished;
38 /// Creates and initializes a new instance of the EcoreTimelineAnimator class.
40 /// <param name="runtime">The time to run in seconds</param>
41 /// <param name="timelineCallback">Functions called at each time line</param>
42 public EcoreTimelineAnimator(double runtime, Action timelineCallback)
45 _nativeCallback = NativeCallback;
46 _timelineCallback = timelineCallback;
51 /// Gets whether the animation is running.
53 public bool IsRunning { get; private set; }
56 /// Gets the current position of the animation.
58 public double Position => _position;
61 /// Starts an animator that runs for a limited time.for a limited time.
66 _animator = Interop.Ecore.ecore_animator_timeline_add(_runtime, _nativeCallback, IntPtr.Zero);
70 /// Stops an animator that running.
75 _animator = IntPtr.Zero;
79 /// Suspends the specified animator.
83 Interop.Ecore.ecore_animator_freeze(_animator);
87 /// Restores execution of the specified animator.
91 Interop.Ecore.ecore_animator_thaw(_animator);
95 /// Callback that is called when ticks off
97 protected void OnTimeline()
102 bool NativeCallback(IntPtr data, double pos)
105 if (!IsRunning) return false;
110 _animator = IntPtr.Zero;
111 Finished?.Invoke(this, EventArgs.Empty);