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;
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 looping);
90 * @copydoc Dali::Animation::IsLooping()
92 bool IsLooping() const;
95 * @copydoc Dali::Animation::SetEndAction()
97 void SetEndAction(EndAction action);
100 * @copydoc Dali::Animation::GetEndAction()
102 EndAction GetEndAction() const;
105 * @copydoc Dali::Animation::SetDisconnectAction()
107 void SetDisconnectAction(EndAction action);
110 * @copydoc Dali::Animation::GetDisconnectAction()
112 EndAction GetDisconnectAction() const;
115 * @copydoc Dali::Animation::SetDefaultAlphaFunction()
117 void SetDefaultAlphaFunction(AlphaFunction alpha)
119 mDefaultAlpha = alpha;
123 * @copydoc Dali::Animation::GetDefaultAlphaFunction()
125 AlphaFunction GetDefaultAlphaFunction() const
127 return mDefaultAlpha;
131 * @copydoc Dali::Animation::Play()
136 * @copydoc Dali::Animation::PlayFrom()
138 void PlayFrom( float progress );
141 * @copydoc Dali::Animation::Pause()
146 * @copydoc Dali::Animation::Stop()
151 * @copydoc Dali::Animation::Clear()
156 * Query whether a Finished signal should be emitted for this animation.
157 * This should only be called by NotificationManager, before signals are emitted.
158 * @post HasFinished() will return false on subsequent calls, until the animation is replayed to completion.
163 * @copydoc Dali::Animation::FinishedSignal()
165 Dali::Animation::AnimationSignalV2& FinishedSignal();
168 * Emit the Finished signal
170 void EmitSignalFinish();
173 * Connects a callback function with the object's signals.
174 * @param[in] object The object providing the signal.
175 * @param[in] tracker Used to disconnect the signal.
176 * @param[in] signalName The signal to connect to.
177 * @param[in] functor A newly allocated FunctorDelegate.
178 * @return True if the signal was connected.
179 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
181 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
184 * Performs actions as requested using the action name.
185 * @param[in] object The object on which to perform the action.
186 * @param[in] actionName The action to perform.
187 * @param[in] attributes The attributes with which to perfrom this action.
188 * @return true if action was done
190 static bool DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes);
193 * This callback is intended for internal use only, to avoid the overhead of using a signal.
194 * @param[in] callback The callback function to connect.
195 * @param[in] object The internal object requesting the callback, or NULL.
197 void SetFinishedCallback( FinishedCallback callback, Object* object );
200 * @copydoc Dali::Animation::AnimateBy(Property target, Property::Value relativeValue)
202 void AnimateBy(Property& target, Property::Value& relativeValue);
205 * @copydoc Dali::Animation::AnimateBy(Property target, Property::Value relativeValue, AlphaFunction alpha)
207 void AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha);
210 * @copydoc Dali::Animation::AnimateBy(Property target, Property::Value relativeValue, TimePeriod period)
212 void AnimateBy(Property& target, Property::Value& relativeValue, TimePeriod period);
215 * @copydoc Dali::Animation::AnimateBy(Property target, Property::Value relativeValue, AlphaFunction alpha, TimePeriod period)
217 void AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha, TimePeriod period);
220 * @copydoc Dali::Animation::AnimateTo(Property target, Property::Value destinationValue)
222 void AnimateTo(Property& target, Property::Value& destinationValue);
225 * @copydoc Dali::Animation::AnimateTo(Property target, Property::Value destinationValue, AlphaFunction alpha)
227 void AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha);
230 * @copydoc Dali::Animation::AnimateTo(Property target, Property::Value destinationValue, TimePeriod period)
232 void AnimateTo(Property& target, Property::Value& destinationValue, TimePeriod period);
235 * @copydoc Dali::Animation::AnimateTo(Property target, Property::Value destinationValue, AlphaFunction alpha, TimePeriod period)
237 void AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period);
240 * Animate a property to a destination value.
241 * @param [in] targetObject The target object to animate.
242 * @param [in] targetPropertyIndex The index of the target property.
243 * @param [in] componentIndex Index to a sub component of a property, for use with Vector2, Vector3 and Vector4
244 * @param [in] destinationValue The destination value.
245 * @param [in] alpha The alpha function to apply.
246 * @param [in] period The effect will occur during this time period.
248 void AnimateTo(ProxyObject& targetObject, Property::Index targetPropertyIndex, int componentIndex, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period);
251 * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames)
253 void AnimateBetween(Property target, const KeyFrames& keyFrames);
256 * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames, TimePeriod period)
258 void AnimateBetween(Property target, const KeyFrames& keyFrames, TimePeriod period);
261 * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames, AlphaFunction alpha)
263 void AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha);
266 * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period)
268 void AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period);
270 // Actor-specific convenience functions
273 * @copydoc Dali::Animation::Animate( Actor actor, Path path, const Vector3& forward )
275 void Animate( Actor& actor, const Path& path, const Vector3& forward );
278 * @copydoc Dali::Animation::Animate( Actor actor, Path path, const Vector3& forward, AlphaFunction alpha )
280 void Animate( Actor& actor, const Path& path, const Vector3& forward, AlphaFunction alpha );
283 * @copydoc Dali::Animation::Animate( Actor actor, Path path, const Vector3& forward, TimePeriod period )
285 void Animate( Actor& actor, const Path& path, const Vector3& forward, TimePeriod period );
288 * @copydoc Dali::Animation::Animate( Actor actor, Path path, const Vector3& forward, AlphaFunction alpha, TimePeriod period)
290 void Animate( Actor& actor, const Path& path, const Vector3& forward, AlphaFunction alpha, TimePeriod period);
293 * @copydoc Dali::Animation::MoveBy(Actor actor, float x, float y, float z)
295 void MoveBy(Actor& actor, float x, float y, float z);
298 * @copydoc Dali::Animation::MoveBy(Actor actor, Vector3 displacement, AlphaFunction alpha)
300 void MoveBy(Actor& actor, const Vector3& translation, AlphaFunction alpha);
303 * @copydoc Dali::Animation::MoveBy(Actor actor, Vector3 displacement, AlphaFunction alpha, float delaySeconds, float durationSeconds)
305 void MoveBy(Actor& actor, const Vector3& translation, AlphaFunction alpha, float delaySeconds, float durationSeconds);
308 * @copydoc Dali::Animation::MoveTo(Actor actor, float x, float y, float z)
310 void MoveTo(Actor& actor, float x, float y, float z);
313 * @copydoc Dali::Animation::MoveTo(Actor actor, Vector3 position, AlphaFunction alpha)
315 void MoveTo(Actor& actor, const Vector3& translation, AlphaFunction alpha);
318 * @copydoc Dali::Animation::MoveTo(Actor actor, Vector3 position, AlphaFunction alpha, float delaySeconds, float durationSeconds)
320 void MoveTo(Actor& actor, const Vector3& translation, AlphaFunction alpha, float delaySeconds, float durationSeconds);
323 * @copydoc Dali::Animation::RotateBy(Actor actor, Radian angle, Vector3 axis)
325 void RotateBy(Actor& actor, Radian angle, const Vector3& axis);
328 * @copydoc Dali::Animation::RotateBy(Actor actor, Radian angle, Vector3 axis, AlphaFunction alpha)()
330 void RotateBy(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha);
333 * @copydoc Dali::Animation::RotateBy(Actor actor, Radian angle, Vector3 axis, AlphaFunction alpha, float delaySeconds, float durationSeconds)
335 void RotateBy(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha, float delaySeconds, float durationSeconds);
338 * @copydoc Dali::Animation::RotateTo(Actor actor, Radian angle, Vector3 axis)
340 void RotateTo(Actor& actor, Radian angle, const Vector3& axis);
343 * @copydoc Dali::Animation::RotateTo(Actor actor, Quaternion orientation)
345 void RotateTo(Actor& actor, const Quaternion& orientation);
348 * @copydoc Dali::Animation::RotateTo(Actor actor, Radian angle, Vector3 axis, AlphaFunction alpha)
350 void RotateTo(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha);
353 * @copydoc Dali::Animation::RotateTo(Actor actor, Quaternion orientation, AlphaFunction alpha)
355 void RotateTo(Actor& actor, const Quaternion& orientation, AlphaFunction alpha);
358 * @copydoc Dali::Animation::RotateTo(Actor actor, Quaternion orientation, AlphaFunction alpha, float delaySeconds, float durationSeconds)
360 void RotateTo(Actor& actor, const Quaternion& orientation, AlphaFunction alpha, float delaySeconds, float durationSeconds);
363 * @copydoc Dali::Animation::RotateTo(Actor actor, Radian angle, Vector3 axis, AlphaFunction alpha, float delaySeconds, float durationSeconds)()
365 void RotateTo(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha, float delaySeconds, float durationSeconds);
368 * @copydoc Dali::Animation::ScaleBy(Actor actor, float x, float y, float z)()
370 void ScaleBy(Actor& actor, float x, float y, float z);
373 * @copydoc Dali::Animation::ScaleBy(Actor actor, Vector3 scale, AlphaFunction alpha)
375 void ScaleBy(Actor& actor, const Vector3& scale, AlphaFunction alpha);
378 * @copydoc Dali::Animation::ScaleBy(Actor actor, Vector3 scale, AlphaFunction alpha, float delaySeconds, float durationSeconds)
380 void ScaleBy(Actor& actor, const Vector3& scale, AlphaFunction alpha, float delaySeconds, float durationSeconds);
383 * @copydoc Dali::Animation::ScaleTo(Actor actor, float x, float y, float z)
385 void ScaleTo(Actor& actor, float x, float y, float z);
388 * @copydoc Dali::Animation::ScaleTo(Actor actor, Vector3 scale, AlphaFunction alpha)
390 void ScaleTo(Actor& actor, const Vector3& scale, AlphaFunction alpha);
393 * @copydoc Dali::Animation::ScaleTo(Actor actor, Vector3 scale, AlphaFunction alpha, float delaySeconds, float durationSeconds)
395 void ScaleTo(Actor& actor, const Vector3& scale, AlphaFunction alpha, float delaySeconds, float durationSeconds);
398 * @copydoc Dali::Animation::Show()
400 void Show(Actor& actor, float delaySeconds);
403 * @copydoc Dali::Animation::Hide()
405 void Hide(Actor& actor, float delaySeconds);
408 * @copydoc Dali::Animation::OpacityBy(Actor actor, float opacity)
410 void OpacityBy(Actor& actor, float opacity);
413 * @copydoc Dali::Animation::OpacityBy(Actor actor, float opacity, AlphaFunction alpha)
415 void OpacityBy(Actor& actor, float opacity, AlphaFunction alpha);
418 * @copydoc Dali::Animation::OpacityBy(Actor actor, float opacity, AlphaFunction alpha, float delaySeconds, float durationSeconds)()
420 void OpacityBy(Actor& actor, float opacity, AlphaFunction alpha, float delaySeconds, float durationSeconds);
423 * @copydoc Dali::Animation::OpacityTo(Actor actor, float opacity)
425 void OpacityTo(Actor& actor, float opacity);
428 * @copydoc Dali::Animation::OpacityTo(Actor actor, float opacity, AlphaFunction alpha)
430 void OpacityTo(Actor& actor, float opacity, AlphaFunction alpha);
433 * @copydoc Dali::Animation::OpacityTo(Actor actor, float opacity, AlphaFunction alpha, float delaySeconds, float durationSeconds)
435 void OpacityTo(Actor& actor, float opacity, AlphaFunction alpha, float delaySeconds, float durationSeconds);
438 * @copydoc Dali::Animation::ColorBy(Actor actor, Vector4 color)
440 void ColorBy(Actor& actor, const Vector4& color);
443 * @copydoc Dali::Animation::ColorBy(Actor actor, Vector4 color, AlphaFunction alpha)
445 void ColorBy(Actor& actor, const Vector4& color, AlphaFunction alpha);
448 * @copydoc Dali::Animation::ColorBy(Actor actor, Vector4 color, AlphaFunction alpha, float delaySeconds, float durationSeconds)
450 void ColorBy(Actor& actor, const Vector4& color, AlphaFunction alpha, float delaySeconds, float durationSeconds);
453 * @copydoc Dali::Animation::ColorTo(Actor actor, Vector4 color)
455 void ColorTo(Actor& actor, const Vector4& color);
458 * @copydoc Dali::Animation::ColorTo(Actor actor, Vector4 color, AlphaFunction alpha)
460 void ColorTo(Actor& actor, const Vector4& color, AlphaFunction alpha);
463 * @copydoc Dali::Animation::ColorTo(Actor actor, Vector4 color, AlphaFunction alpha, float delaySeconds, float durationSeconds)
465 void ColorTo(Actor& actor, const Vector4& color, AlphaFunction alpha, float delaySeconds, float durationSeconds);
468 * @copydoc Dali::Animation::Resize(Actor actor, float width, float height)
470 void Resize(Actor& actor, float width, float height);
473 * @copydoc Dali::Animation::Resize(Actor actor, float width, float height, AlphaFunction alpha)
475 void Resize(Actor& actor, float width, float height, AlphaFunction alpha);
478 * @copydoc Dali::Animation::Resize(Actor actor, float width, float height, AlphaFunction alpha, float delaySeconds, float durationSeconds)
480 void Resize(Actor& actor, float width, float height, AlphaFunction alpha, float delaySeconds, float durationSeconds);
483 * @copydoc Dali::Animation::Resize(Actor actor, Vector3 size)
485 void Resize(Actor& actor, const Vector3& size);
488 * @copydoc Dali::Animation::Resize(Actor actor, Vector3 size, AlphaFunction alpha)
490 void Resize(Actor& actor, const Vector3& size, AlphaFunction alpha);
493 * @copydoc Dali::Animation::Resize(Actor actor, Vector3 size, AlphaFunction alpha, float delaySeconds, float durationSeconds)
495 void Resize(Actor& actor, const Vector3& size, AlphaFunction alpha, float delaySeconds, float durationSeconds);
498 * @copydoc Dali::Animation::SetCurrentProgress()
500 void SetCurrentProgress(float progress);
503 * @copydoc Dali::Animation::GetCurrentProgress()
505 float GetCurrentProgress();
508 * @copydoc Dali::Animation::SetSpeedFactor()
510 void SetSpeedFactor( float factor );
513 * @copydoc Dali::Animation::GetSpeedFactor()
515 float GetSpeedFactor() const;
518 * @copydoc Dali::Animation::SetPlayRange()
520 void SetPlayRange( const Vector2& range );
523 * @copydoc Dali::Animation::GetPlayRange
525 Vector2 GetPlayRange() const;
527 public: // For connecting animators to animations
530 * Add an animator connector.
531 * @param[in] connector The animator connector.
533 void AddAnimatorConnector( AnimatorConnectorBase* connector );
536 * Retrieve the SceneGraph::Animation object.
537 * @return The animation.
539 const SceneGraph::Animation* GetSceneObject()
545 * Retrieve the UpdateManager associated with this animation.
546 * @return The UpdateManager.
548 SceneGraph::UpdateManager& GetUpdateManager()
550 return mUpdateManager;
556 * Construct a new Animation.
557 * @param[in] updateManager The UpdateManager associated with this animation.
558 * @param[in] playlist The list of currently playing animations.
559 * @param[in] durationSeconds The duration of the animation in seconds.
560 * @param[in] endAction The action to perform when the animation ends.
561 * @param[in] disconnectAction The action to perform when the property owner of an animator is disconnected.
562 * @param[in] defaultAlpha The default alpha function to apply to animators.
564 Animation( SceneGraph::UpdateManager& updateManager,
565 AnimationPlaylist& playlist,
566 float durationSeconds,
568 EndAction disconnectAction,
569 AlphaFunction defaultAlpha);
572 * Second-phase constructor.
577 * Helper to create a scene-graph animation
579 void CreateSceneObject();
582 * Helper to create a scene-graph animation
584 void DestroySceneObject();
587 * A reference counted object may only be deleted by calling Unreference()
589 virtual ~Animation();
594 * Extends the duration when an animator is added with TimePeriod that exceeds current duration.
595 * @param[in] timePeriod The time period for an animator.
597 void ExtendDuration( const TimePeriod& timePeriod );
600 Animation(const Animation&);
603 Animation& operator=(const Animation& rhs);
607 SceneGraph::UpdateManager& mUpdateManager;
608 AnimationPlaylist& mPlaylist;
610 const SceneGraph::Animation* mAnimation;
612 int mNotificationCount; ///< Keep track of how many Finished signals have been emitted.
614 Dali::Animation::AnimationSignalV2 mFinishedSignal;
616 FinishedCallback mFinishedCallback;
617 Object* mFinishedCallbackObject;
619 AnimatorConnectorContainer mConnectors; ///< Owned by the Animation
621 // Cached for public getters
622 float mDurationSeconds;
626 EndAction mEndAction;
627 EndAction mDisconnectAction;
628 AlphaFunction mDefaultAlpha;
632 } // namespace Internal
634 // Helpers for public-api forwarding methods
636 inline Internal::Animation& GetImplementation(Dali::Animation& animation)
638 DALI_ASSERT_ALWAYS( animation && "Animation handle is empty" );
640 BaseObject& handle = animation.GetBaseObject();
642 return static_cast<Internal::Animation&>(handle);
645 inline const Internal::Animation& GetImplementation(const Dali::Animation& animation)
647 DALI_ASSERT_ALWAYS( animation && "Animation handle is empty" );
649 const BaseObject& handle = animation.GetBaseObject();
651 return static_cast<const Internal::Animation&>(handle);
656 #endif // __DALI_INTERNAL_ANIMATION_H__