1 #ifndef __DALI_INTERNAL_ANIMATION_H__
2 #define __DALI_INTERNAL_ANIMATION_H__
5 * Copyright (c) 2014 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;
48 typedef IntrusivePtr<Animation> AnimationPtr;
49 typedef std::vector<AnimationPtr> AnimationContainer;
51 typedef AnimationContainer::iterator AnimationIter;
52 typedef AnimationContainer::const_iterator AnimationConstIter;
55 * Animation is a proxy for a SceneGraph::Animation object.
56 * The UpdateManager owns the Animation object, but the lifetime of the animation is
57 * indirectly controlled by the Animation.
59 class Animation : public BaseObject
63 typedef Dali::Animation::EndAction EndAction;
64 typedef Dali::Animation::Interpolation Interpolation;
66 typedef void (*FinishedCallback)(Object* object);
69 * Create a new Animation object.
70 * @param[in] durationSeconds The duration of the animation.
71 * @return A smart-pointer to the newly allocated Animation.
73 static AnimationPtr New(float durationSeconds);
76 * @copydoc Dali::Animation::SetDuration()
78 void SetDuration(float seconds);
81 * @copydoc Dali::Animation::GetDuration()
83 float GetDuration() const;
86 * @copydoc Dali::Animation::SetLooping()
88 void SetLooping(bool looping);
91 * @copydoc Dali::Animation::IsLooping()
93 bool IsLooping() const;
96 * @copydoc Dali::Animation::SetEndAction()
98 void SetEndAction(EndAction action);
101 * @copydoc Dali::Animation::GetEndAction()
103 EndAction GetEndAction() const;
106 * @copydoc Dali::Animation::SetDisconnectAction()
108 void SetDisconnectAction(EndAction action);
111 * @copydoc Dali::Animation::GetDisconnectAction()
113 EndAction GetDisconnectAction() const;
116 * @copydoc Dali::Animation::SetDefaultAlphaFunction()
118 void SetDefaultAlphaFunction(AlphaFunction alpha)
120 mDefaultAlpha = alpha;
124 * @copydoc Dali::Animation::GetDefaultAlphaFunction()
126 AlphaFunction GetDefaultAlphaFunction() const
128 return mDefaultAlpha;
132 * @copydoc Dali::Animation::Play()
137 * @copydoc Dali::Animation::PlayFrom()
139 void PlayFrom( float progress );
142 * @copydoc Dali::Animation::Pause()
147 * @copydoc Dali::Animation::Stop()
152 * @copydoc Dali::Animation::Clear()
157 * Query whether a Finished signal should be emitted for this animation.
158 * This should only be called by NotificationManager, before signals are emitted.
159 * @post HasFinished() will return false on subsequent calls, until the animation is replayed to completion.
164 * @copydoc Dali::Animation::FinishedSignal()
166 Dali::Animation::AnimationSignalType& FinishedSignal();
169 * Emit the Finished signal
171 void EmitSignalFinish();
174 * Connects a callback function with the object's signals.
175 * @param[in] object The object providing the signal.
176 * @param[in] tracker Used to disconnect the signal.
177 * @param[in] signalName The signal to connect to.
178 * @param[in] functor A newly allocated FunctorDelegate.
179 * @return True if the signal was connected.
180 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
182 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
185 * Performs actions as requested using the action name.
186 * @param[in] object The object on which to perform the action.
187 * @param[in] actionName The action to perform.
188 * @param[in] attributes The attributes with which to perfrom this action.
189 * @return true if action was done
191 static bool DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes);
194 * This callback is intended for internal use only, to avoid the overhead of using a signal.
195 * @param[in] callback The callback function to connect.
196 * @param[in] object The internal object requesting the callback, or NULL.
198 void SetFinishedCallback( FinishedCallback callback, Object* object );
201 * @copydoc Dali::Animation::AnimateBy(Property target, Property::Value relativeValue)
203 void AnimateBy(Property& target, Property::Value& relativeValue);
206 * @copydoc Dali::Animation::AnimateBy(Property target, Property::Value relativeValue, AlphaFunction alpha)
208 void AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha);
211 * @copydoc Dali::Animation::AnimateBy(Property target, Property::Value relativeValue, TimePeriod period)
213 void AnimateBy(Property& target, Property::Value& relativeValue, TimePeriod period);
216 * @copydoc Dali::Animation::AnimateBy(Property target, Property::Value relativeValue, AlphaFunction alpha, TimePeriod period)
218 void AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha, TimePeriod period);
221 * @copydoc Dali::Animation::AnimateTo(Property target, Property::Value destinationValue)
223 void AnimateTo(Property& target, Property::Value& destinationValue);
226 * @copydoc Dali::Animation::AnimateTo(Property target, Property::Value destinationValue, AlphaFunction alpha)
228 void AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha);
231 * @copydoc Dali::Animation::AnimateTo(Property target, Property::Value destinationValue, TimePeriod period)
233 void AnimateTo(Property& target, Property::Value& destinationValue, TimePeriod period);
236 * @copydoc Dali::Animation::AnimateTo(Property target, Property::Value destinationValue, AlphaFunction alpha, TimePeriod period)
238 void AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period);
241 * Animate a property to a destination value.
242 * @param [in] targetObject The target object to animate.
243 * @param [in] targetPropertyIndex The index of the target property.
244 * @param [in] componentIndex Index to a sub component of a property, for use with Vector2, Vector3 and Vector4
245 * @param [in] destinationValue The destination value.
246 * @param [in] alpha The alpha function to apply.
247 * @param [in] period The effect will occur during this time period.
249 void AnimateTo(Object& targetObject, Property::Index targetPropertyIndex, int componentIndex, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period);
252 * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames)
254 void AnimateBetween(Property target, const KeyFrames& keyFrames);
257 * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames, Interpolation interpolation)
259 void AnimateBetween(Property target, const KeyFrames& keyFrames, Interpolation interpolation );
262 * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames, TimePeriod period)
264 void AnimateBetween(Property target, const KeyFrames& keyFrames, TimePeriod period);
267 * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames, TimePeriod period, Interpolation interpolation)
269 void AnimateBetween(Property target, const KeyFrames& keyFrames, TimePeriod period, Interpolation interpolation);
272 * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames, AlphaFunction alpha)
274 void AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha);
277 * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames, AlphaFunction alpha, Interpolation interpolation)
279 void AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, Interpolation interpolation);
282 * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period)
284 void AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period);
287 * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period, Interpolation interpolation )
289 void AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period, Interpolation interpolation );
291 // Actor-specific convenience functions
294 * @copydoc Dali::Animation::Animate( Actor actor, Path path, const Vector3& forward )
296 void Animate( Actor& actor, const Path& path, const Vector3& forward );
299 * @copydoc Dali::Animation::Animate( Actor actor, Path path, const Vector3& forward, AlphaFunction alpha )
301 void Animate( Actor& actor, const Path& path, const Vector3& forward, AlphaFunction alpha );
304 * @copydoc Dali::Animation::Animate( Actor actor, Path path, const Vector3& forward, TimePeriod period )
306 void Animate( Actor& actor, const Path& path, const Vector3& forward, TimePeriod period );
309 * @copydoc Dali::Animation::Animate( Actor actor, Path path, const Vector3& forward, AlphaFunction alpha, TimePeriod period)
311 void Animate( Actor& actor, const Path& path, const Vector3& forward, AlphaFunction alpha, TimePeriod period);
314 * @copydoc Dali::Animation::MoveBy(Actor actor, float x, float y, float z)
316 void MoveBy(Actor& actor, float x, float y, float z);
319 * @copydoc Dali::Animation::MoveBy(Actor actor, Vector3 displacement, AlphaFunction alpha)
321 void MoveBy(Actor& actor, const Vector3& translation, AlphaFunction alpha);
324 * @copydoc Dali::Animation::MoveBy(Actor actor, Vector3 displacement, AlphaFunction alpha, float delaySeconds, float durationSeconds)
326 void MoveBy(Actor& actor, const Vector3& translation, AlphaFunction alpha, float delaySeconds, float durationSeconds);
329 * @copydoc Dali::Animation::MoveTo(Actor actor, float x, float y, float z)
331 void MoveTo(Actor& actor, float x, float y, float z);
334 * @copydoc Dali::Animation::MoveTo(Actor actor, Vector3 position, AlphaFunction alpha)
336 void MoveTo(Actor& actor, const Vector3& translation, AlphaFunction alpha);
339 * @copydoc Dali::Animation::MoveTo(Actor actor, Vector3 position, AlphaFunction alpha, float delaySeconds, float durationSeconds)
341 void MoveTo(Actor& actor, const Vector3& translation, AlphaFunction alpha, float delaySeconds, float durationSeconds);
344 * @copydoc Dali::Animation::RotateBy(Actor actor, Radian angle, Vector3 axis)
346 void RotateBy(Actor& actor, Radian angle, const Vector3& axis);
349 * @copydoc Dali::Animation::RotateBy(Actor actor, Radian angle, Vector3 axis, AlphaFunction alpha)()
351 void RotateBy(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha);
354 * @copydoc Dali::Animation::RotateBy(Actor actor, Radian angle, Vector3 axis, AlphaFunction alpha, float delaySeconds, float durationSeconds)
356 void RotateBy(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha, float delaySeconds, float durationSeconds);
359 * @copydoc Dali::Animation::RotateTo(Actor actor, Radian angle, Vector3 axis)
361 void RotateTo(Actor& actor, Radian angle, const Vector3& axis);
364 * @copydoc Dali::Animation::RotateTo(Actor actor, Quaternion orientation)
366 void RotateTo(Actor& actor, const Quaternion& orientation);
369 * @copydoc Dali::Animation::RotateTo(Actor actor, Radian angle, Vector3 axis, AlphaFunction alpha)
371 void RotateTo(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha);
374 * @copydoc Dali::Animation::RotateTo(Actor actor, Quaternion orientation, AlphaFunction alpha)
376 void RotateTo(Actor& actor, const Quaternion& orientation, AlphaFunction alpha);
379 * @copydoc Dali::Animation::RotateTo(Actor actor, Quaternion orientation, AlphaFunction alpha, float delaySeconds, float durationSeconds)
381 void RotateTo(Actor& actor, const Quaternion& orientation, AlphaFunction alpha, float delaySeconds, float durationSeconds);
384 * @copydoc Dali::Animation::RotateTo(Actor actor, Radian angle, Vector3 axis, AlphaFunction alpha, float delaySeconds, float durationSeconds)()
386 void RotateTo(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha, float delaySeconds, float durationSeconds);
389 * @copydoc Dali::Animation::ScaleBy(Actor actor, float x, float y, float z)()
391 void ScaleBy(Actor& actor, float x, float y, float z);
394 * @copydoc Dali::Animation::ScaleBy(Actor actor, Vector3 scale, AlphaFunction alpha)
396 void ScaleBy(Actor& actor, const Vector3& scale, AlphaFunction alpha);
399 * @copydoc Dali::Animation::ScaleBy(Actor actor, Vector3 scale, AlphaFunction alpha, float delaySeconds, float durationSeconds)
401 void ScaleBy(Actor& actor, const Vector3& scale, AlphaFunction alpha, float delaySeconds, float durationSeconds);
404 * @copydoc Dali::Animation::ScaleTo(Actor actor, float x, float y, float z)
406 void ScaleTo(Actor& actor, float x, float y, float z);
409 * @copydoc Dali::Animation::ScaleTo(Actor actor, Vector3 scale, AlphaFunction alpha)
411 void ScaleTo(Actor& actor, const Vector3& scale, AlphaFunction alpha);
414 * @copydoc Dali::Animation::ScaleTo(Actor actor, Vector3 scale, AlphaFunction alpha, float delaySeconds, float durationSeconds)
416 void ScaleTo(Actor& actor, const Vector3& scale, AlphaFunction alpha, float delaySeconds, float durationSeconds);
419 * @copydoc Dali::Animation::Show()
421 void Show(Actor& actor, float delaySeconds);
424 * @copydoc Dali::Animation::Hide()
426 void Hide(Actor& actor, float delaySeconds);
429 * @copydoc Dali::Animation::OpacityBy(Actor actor, float opacity)
431 void OpacityBy(Actor& actor, float opacity);
434 * @copydoc Dali::Animation::OpacityBy(Actor actor, float opacity, AlphaFunction alpha)
436 void OpacityBy(Actor& actor, float opacity, AlphaFunction alpha);
439 * @copydoc Dali::Animation::OpacityBy(Actor actor, float opacity, AlphaFunction alpha, float delaySeconds, float durationSeconds)()
441 void OpacityBy(Actor& actor, float opacity, AlphaFunction alpha, float delaySeconds, float durationSeconds);
444 * @copydoc Dali::Animation::OpacityTo(Actor actor, float opacity)
446 void OpacityTo(Actor& actor, float opacity);
449 * @copydoc Dali::Animation::OpacityTo(Actor actor, float opacity, AlphaFunction alpha)
451 void OpacityTo(Actor& actor, float opacity, AlphaFunction alpha);
454 * @copydoc Dali::Animation::OpacityTo(Actor actor, float opacity, AlphaFunction alpha, float delaySeconds, float durationSeconds)
456 void OpacityTo(Actor& actor, float opacity, AlphaFunction alpha, float delaySeconds, float durationSeconds);
459 * @copydoc Dali::Animation::ColorBy(Actor actor, Vector4 color)
461 void ColorBy(Actor& actor, const Vector4& color);
464 * @copydoc Dali::Animation::ColorBy(Actor actor, Vector4 color, AlphaFunction alpha)
466 void ColorBy(Actor& actor, const Vector4& color, AlphaFunction alpha);
469 * @copydoc Dali::Animation::ColorBy(Actor actor, Vector4 color, AlphaFunction alpha, float delaySeconds, float durationSeconds)
471 void ColorBy(Actor& actor, const Vector4& color, AlphaFunction alpha, float delaySeconds, float durationSeconds);
474 * @copydoc Dali::Animation::ColorTo(Actor actor, Vector4 color)
476 void ColorTo(Actor& actor, const Vector4& color);
479 * @copydoc Dali::Animation::ColorTo(Actor actor, Vector4 color, AlphaFunction alpha)
481 void ColorTo(Actor& actor, const Vector4& color, AlphaFunction alpha);
484 * @copydoc Dali::Animation::ColorTo(Actor actor, Vector4 color, AlphaFunction alpha, float delaySeconds, float durationSeconds)
486 void ColorTo(Actor& actor, const Vector4& color, AlphaFunction alpha, float delaySeconds, float durationSeconds);
489 * @copydoc Dali::Animation::Resize(Actor actor, float width, float height)
491 void Resize(Actor& actor, float width, float height);
494 * @copydoc Dali::Animation::Resize(Actor actor, float width, float height, AlphaFunction alpha)
496 void Resize(Actor& actor, float width, float height, AlphaFunction alpha);
499 * @copydoc Dali::Animation::Resize(Actor actor, float width, float height, AlphaFunction alpha, float delaySeconds, float durationSeconds)
501 void Resize(Actor& actor, float width, float height, AlphaFunction alpha, float delaySeconds, float durationSeconds);
504 * @copydoc Dali::Animation::Resize(Actor actor, Vector3 size)
506 void Resize(Actor& actor, const Vector3& size);
509 * @copydoc Dali::Animation::Resize(Actor actor, Vector3 size, AlphaFunction alpha)
511 void Resize(Actor& actor, const Vector3& size, AlphaFunction alpha);
514 * @copydoc Dali::Animation::Resize(Actor actor, Vector3 size, AlphaFunction alpha, float delaySeconds, float durationSeconds)
516 void Resize(Actor& actor, const Vector3& size, AlphaFunction alpha, float delaySeconds, float durationSeconds);
519 * @copydoc Dali::Animation::SetCurrentProgress()
521 void SetCurrentProgress(float progress);
524 * @copydoc Dali::Animation::GetCurrentProgress()
526 float GetCurrentProgress();
529 * @copydoc Dali::Animation::SetSpeedFactor()
531 void SetSpeedFactor( float factor );
534 * @copydoc Dali::Animation::GetSpeedFactor()
536 float GetSpeedFactor() const;
539 * @copydoc Dali::Animation::SetPlayRange()
541 void SetPlayRange( const Vector2& range );
544 * @copydoc Dali::Animation::GetPlayRange
546 Vector2 GetPlayRange() const;
548 public: // For connecting animators to animations
551 * Add an animator connector.
552 * @param[in] connector The animator connector.
554 void AddAnimatorConnector( AnimatorConnectorBase* connector );
557 * Retrieve the SceneGraph::Animation object.
558 * @return The animation.
560 const SceneGraph::Animation* GetSceneObject()
566 * Retrieve the event thread services object
567 * @return The interface for sending messages to the scene graph
569 EventThreadServices& GetEventThreadServices()
571 return mEventThreadServices;
577 * Construct a new Animation.
578 * @param[in] eventThreadServices The interface for sending messages to the scene graph
579 * @param[in] playlist The list of currently playing animations.
580 * @param[in] durationSeconds The duration of the animation in seconds.
581 * @param[in] endAction The action to perform when the animation ends.
582 * @param[in] disconnectAction The action to perform when the property owner of an animator is disconnected.
583 * @param[in] defaultAlpha The default alpha function to apply to animators.
585 Animation( EventThreadServices& eventThreadServices,
586 AnimationPlaylist& playlist,
587 float durationSeconds,
589 EndAction disconnectAction,
590 AlphaFunction defaultAlpha);
593 * Second-phase constructor.
598 * Helper to create a scene-graph animation
600 void CreateSceneObject();
603 * Helper to create a scene-graph animation
605 void DestroySceneObject();
608 * A reference counted object may only be deleted by calling Unreference()
610 virtual ~Animation();
615 * Extends the duration when an animator is added with TimePeriod that exceeds current duration.
616 * @param[in] timePeriod The time period for an animator.
618 void ExtendDuration( const TimePeriod& timePeriod );
621 Animation(const Animation&);
624 Animation& operator=(const Animation& rhs);
627 EventThreadServices& mEventThreadServices;
628 AnimationPlaylist& mPlaylist;
630 const SceneGraph::Animation* mAnimation;
632 int mNotificationCount; ///< Keep track of how many Finished signals have been emitted.
634 Dali::Animation::AnimationSignalType mFinishedSignal;
636 FinishedCallback mFinishedCallback;
637 Object* mFinishedCallbackObject;
639 AnimatorConnectorContainer mConnectors; ///< Owned by the Animation
641 // Cached for public getters
642 float mDurationSeconds;
646 EndAction mEndAction;
647 EndAction mDisconnectAction;
648 AlphaFunction mDefaultAlpha;
652 } // namespace Internal
654 // Helpers for public-api forwarding methods
656 inline Internal::Animation& GetImplementation(Dali::Animation& animation)
658 DALI_ASSERT_ALWAYS( animation && "Animation handle is empty" );
660 BaseObject& handle = animation.GetBaseObject();
662 return static_cast<Internal::Animation&>(handle);
665 inline const Internal::Animation& GetImplementation(const Dali::Animation& animation)
667 DALI_ASSERT_ALWAYS( animation && "Animation handle is empty" );
669 const BaseObject& handle = animation.GetBaseObject();
671 return static_cast<const Internal::Animation&>(handle);
676 #endif // __DALI_INTERNAL_ANIMATION_H__