1 #ifndef __DALI_INTERNAL_ANIMATION_H__
2 #define __DALI_INTERNAL_ANIMATION_H__
5 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/public-api/common/vector-wrapper.h>
23 #include <dali/public-api/object/ref-object.h>
24 #include <dali/public-api/animation/animation.h>
25 #include <dali/public-api/object/base-object.h>
26 #include <dali/internal/event/animation/animator-connector-base.h>
27 #include <dali/internal/event/animation/key-frames-impl.h>
28 #include <dali/internal/event/animation/path-impl.h>
44 class AnimationPlaylist;
47 typedef IntrusivePtr<Animation> AnimationPtr;
48 typedef std::vector<AnimationPtr> AnimationContainer;
50 typedef AnimationContainer::iterator AnimationIter;
51 typedef AnimationContainer::const_iterator AnimationConstIter;
54 * Animation is a proxy for a SceneGraph::Animation object.
55 * The UpdateManager owns the Animation object, but the lifetime of the animation is
56 * indirectly controlled by the Animation.
58 class Animation : public BaseObject
62 typedef Dali::Animation::EndAction EndAction;
63 typedef Dali::Animation::Interpolation Interpolation;
65 typedef void (*FinishedCallback)(Object* object);
68 * Create a new Animation object.
69 * @param[in] durationSeconds The duration of the animation.
70 * @return A smart-pointer to the newly allocated Animation.
72 static AnimationPtr New(float durationSeconds);
75 * @copydoc Dali::Animation::SetDuration()
77 void SetDuration(float seconds);
80 * @copydoc Dali::Animation::GetDuration()
82 float GetDuration() const;
85 * @copydoc Dali::Animation::SetLooping()
87 void SetLooping(bool on);
90 * @copydoc Dali::Animation::SetLoopCount()
92 void SetLoopCount(int count);
95 * @copydoc Dali::Animation::GetLoopCount()
100 * @copydoc Dali::Animation::GetCurrentLoop()
102 int GetCurrentLoop();
105 * @copydoc Dali::Animation::IsLooping()
107 bool IsLooping() const;
110 * @copydoc Dali::Animation::SetEndAction()
112 void SetEndAction(EndAction action);
115 * @copydoc Dali::Animation::GetEndAction()
117 EndAction GetEndAction() const;
120 * @copydoc Dali::Animation::SetDisconnectAction()
122 void SetDisconnectAction(EndAction action);
125 * @copydoc Dali::Animation::GetDisconnectAction()
127 EndAction GetDisconnectAction() const;
130 * @copydoc Dali::Animation::SetDefaultAlphaFunction()
132 void SetDefaultAlphaFunction(AlphaFunction alpha)
134 mDefaultAlpha = alpha;
138 * @copydoc Dali::Animation::GetDefaultAlphaFunction()
140 AlphaFunction GetDefaultAlphaFunction() const
142 return mDefaultAlpha;
146 * @copydoc Dali::Animation::Play()
151 * @copydoc Dali::Animation::PlayFrom()
153 void PlayFrom( float progress );
156 * @copydoc Dali::Animation::Pause()
161 * @copydoc Dali::Animation::GetState()
163 Dali::Animation::State GetState() const;
166 * @copydoc Dali::Animation::Stop()
171 * @copydoc Dali::Animation::Clear()
176 * Query whether a Finished signal should be emitted for this animation.
177 * This should only be called by NotificationManager, before signals are emitted.
178 * @post HasFinished() will return false on subsequent calls, until the animation is replayed to completion.
183 * @copydoc Dali::Animation::FinishedSignal()
185 Dali::Animation::AnimationSignalType& FinishedSignal();
188 * Emit the Finished signal
190 void EmitSignalFinish();
193 * Connects a callback function with the object's signals.
194 * @param[in] object The object providing the signal.
195 * @param[in] tracker Used to disconnect the signal.
196 * @param[in] signalName The signal to connect to.
197 * @param[in] functor A newly allocated FunctorDelegate.
198 * @return True if the signal was connected.
199 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
201 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
204 * Performs actions as requested using the action name.
205 * @param[in] object The object on which to perform the action.
206 * @param[in] actionName The action to perform.
207 * @param[in] attributes The attributes with which to perfrom this action.
208 * @return true if action was done
210 static bool DoAction(BaseObject* object, const std::string& actionName, const Property::Map& attributes);
213 * This callback is intended for internal use only, to avoid the overhead of using a signal.
214 * @param[in] callback The callback function to connect.
215 * @param[in] object The internal object requesting the callback, or NULL.
217 void SetFinishedCallback( FinishedCallback callback, Object* object );
220 * @copydoc Dali::Animation::AnimateBy(Property target, Property::Value relativeValue)
222 void AnimateBy(Property& target, Property::Value& relativeValue);
225 * @copydoc Dali::Animation::AnimateBy(Property target, Property::Value relativeValue, AlphaFunction alpha)
227 void AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha);
230 * @copydoc Dali::Animation::AnimateBy(Property target, Property::Value relativeValue, TimePeriod period)
232 void AnimateBy(Property& target, Property::Value& relativeValue, TimePeriod period);
235 * @copydoc Dali::Animation::AnimateBy(Property target, Property::Value relativeValue, AlphaFunction alpha, TimePeriod period)
237 void AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha, TimePeriod period);
240 * @copydoc Dali::Animation::AnimateTo(Property target, Property::Value destinationValue)
242 void AnimateTo(Property& target, Property::Value& destinationValue);
245 * @copydoc Dali::Animation::AnimateTo(Property target, Property::Value destinationValue, AlphaFunction alpha)
247 void AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha);
250 * @copydoc Dali::Animation::AnimateTo(Property target, Property::Value destinationValue, TimePeriod period)
252 void AnimateTo(Property& target, Property::Value& destinationValue, TimePeriod period);
255 * @copydoc Dali::Animation::AnimateTo(Property target, Property::Value destinationValue, AlphaFunction alpha, TimePeriod period)
257 void AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period);
260 * Animate a property to a destination value.
261 * @param [in] targetObject The target object to animate.
262 * @param [in] targetPropertyIndex The index of the target property.
263 * @param [in] componentIndex Index to a sub component of a property, for use with Vector2, Vector3 and Vector4
264 * @param [in] destinationValue The destination value.
265 * @param [in] alpha The alpha function to apply.
266 * @param [in] period The effect will occur during this time period.
268 void AnimateTo(Object& targetObject, Property::Index targetPropertyIndex, int componentIndex, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period);
271 * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames)
273 void AnimateBetween(Property target, const KeyFrames& keyFrames);
276 * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames, Interpolation interpolation)
278 void AnimateBetween(Property target, const KeyFrames& keyFrames, Interpolation interpolation );
281 * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames, TimePeriod period)
283 void AnimateBetween(Property target, const KeyFrames& keyFrames, TimePeriod period);
286 * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames, TimePeriod period, Interpolation interpolation)
288 void AnimateBetween(Property target, const KeyFrames& keyFrames, TimePeriod period, Interpolation interpolation);
291 * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames, AlphaFunction alpha)
293 void AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha);
296 * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames, AlphaFunction alpha, Interpolation interpolation)
298 void AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, Interpolation interpolation);
301 * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period)
303 void AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period);
306 * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period, Interpolation interpolation )
308 void AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period, Interpolation interpolation );
310 // Actor-specific convenience functions
313 * @copydoc Dali::Animation::Animate( Actor actor, Path path, const Vector3& forward )
315 void Animate( Actor& actor, const Path& path, const Vector3& forward );
318 * @copydoc Dali::Animation::Animate( Actor actor, Path path, const Vector3& forward, AlphaFunction alpha )
320 void Animate( Actor& actor, const Path& path, const Vector3& forward, AlphaFunction alpha );
323 * @copydoc Dali::Animation::Animate( Actor actor, Path path, const Vector3& forward, TimePeriod period )
325 void Animate( Actor& actor, const Path& path, const Vector3& forward, TimePeriod period );
328 * @copydoc Dali::Animation::Animate( Actor actor, Path path, const Vector3& forward, AlphaFunction alpha, TimePeriod period)
330 void Animate( Actor& actor, const Path& path, const Vector3& forward, AlphaFunction alpha, TimePeriod period);
333 * @copydoc Dali::Animation::Show()
335 void Show(Actor& actor, float delaySeconds);
338 * @copydoc Dali::Animation::Hide()
340 void Hide(Actor& actor, float delaySeconds);
343 * @copydoc Dali::Animation::SetCurrentProgress()
345 void SetCurrentProgress(float progress);
348 * @copydoc Dali::Animation::GetCurrentProgress()
350 float GetCurrentProgress();
353 * @copydoc Dali::Animation::SetSpeedFactor()
355 void SetSpeedFactor( float factor );
358 * @copydoc Dali::Animation::GetSpeedFactor()
360 float GetSpeedFactor() const;
363 * @copydoc Dali::Animation::SetPlayRange()
365 void SetPlayRange( const Vector2& range );
368 * @copydoc Dali::Animation::GetPlayRange
370 Vector2 GetPlayRange() const;
372 public: // For connecting animators to animations
375 * Add an animator connector.
376 * @param[in] connector The animator connector.
378 void AddAnimatorConnector( AnimatorConnectorBase* connector );
381 * Retrieve the SceneGraph::Animation object.
382 * @return The animation.
384 const SceneGraph::Animation* GetSceneObject()
390 * Retrieve the event thread services object
391 * @return The interface for sending messages to the scene graph
393 EventThreadServices& GetEventThreadServices()
395 return mEventThreadServices;
401 * Construct a new Animation.
402 * @param[in] eventThreadServices The interface for sending messages to the scene graph
403 * @param[in] playlist The list of currently playing animations.
404 * @param[in] durationSeconds The duration of the animation in seconds.
405 * @param[in] endAction The action to perform when the animation ends.
406 * @param[in] disconnectAction The action to perform when the property owner of an animator is disconnected.
407 * @param[in] defaultAlpha The default alpha function to apply to animators.
409 Animation( EventThreadServices& eventThreadServices,
410 AnimationPlaylist& playlist,
411 float durationSeconds,
413 EndAction disconnectAction,
414 AlphaFunction defaultAlpha);
417 * Second-phase constructor.
422 * Helper to create a scene-graph animation
424 void CreateSceneObject();
427 * Helper to create a scene-graph animation
429 void DestroySceneObject();
432 * A reference counted object may only be deleted by calling Unreference()
434 virtual ~Animation();
439 * Extends the duration when an animator is added with TimePeriod that exceeds current duration.
440 * @param[in] timePeriod The time period for an animator.
442 void ExtendDuration( const TimePeriod& timePeriod );
445 Animation(const Animation&);
448 Animation& operator=(const Animation& rhs);
451 EventThreadServices& mEventThreadServices;
452 AnimationPlaylist& mPlaylist;
454 const SceneGraph::Animation* mAnimation;
456 int mNotificationCount; ///< Keep track of how many Finished signals have been emitted.
458 Dali::Animation::AnimationSignalType mFinishedSignal;
460 FinishedCallback mFinishedCallback;
461 Object* mFinishedCallbackObject;
463 AnimatorConnectorContainer mConnectors; ///< Owned by the Animation
465 // Cached for public getters
466 float mDurationSeconds;
471 EndAction mEndAction;
472 EndAction mDisconnectAction;
473 AlphaFunction mDefaultAlpha;
474 Dali::Animation::State mState;
478 } // namespace Internal
480 // Helpers for public-api forwarding methods
482 inline Internal::Animation& GetImplementation(Dali::Animation& animation)
484 DALI_ASSERT_ALWAYS( animation && "Animation handle is empty" );
486 BaseObject& handle = animation.GetBaseObject();
488 return static_cast<Internal::Animation&>(handle);
491 inline const Internal::Animation& GetImplementation(const Dali::Animation& animation)
493 DALI_ASSERT_ALWAYS( animation && "Animation handle is empty" );
495 const BaseObject& handle = animation.GetBaseObject();
497 return static_cast<const Internal::Animation&>(handle);
502 #endif // __DALI_INTERNAL_ANIMATION_H__