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 on);
91 * @copydoc Dali::Animation::SetLoopCount()
93 void SetLoopCount(int count);
96 * @copydoc Dali::Animation::GetLoopCount()
101 * @copydoc Dali::Animation::GetCurrentLoop()
103 int GetCurrentLoop();
106 * @copydoc Dali::Animation::IsLooping()
108 bool IsLooping() const;
111 * @copydoc Dali::Animation::SetEndAction()
113 void SetEndAction(EndAction action);
116 * @copydoc Dali::Animation::GetEndAction()
118 EndAction GetEndAction() const;
121 * @copydoc Dali::Animation::SetDisconnectAction()
123 void SetDisconnectAction(EndAction action);
126 * @copydoc Dali::Animation::GetDisconnectAction()
128 EndAction GetDisconnectAction() const;
131 * @copydoc Dali::Animation::SetDefaultAlphaFunction()
133 void SetDefaultAlphaFunction(AlphaFunction alpha)
135 mDefaultAlpha = alpha;
139 * @copydoc Dali::Animation::GetDefaultAlphaFunction()
141 AlphaFunction GetDefaultAlphaFunction() const
143 return mDefaultAlpha;
147 * @copydoc Dali::Animation::Play()
152 * @copydoc Dali::Animation::PlayFrom()
154 void PlayFrom( float progress );
157 * @copydoc Dali::Animation::Pause()
162 * @copydoc Dali::Animation::Stop()
167 * @copydoc Dali::Animation::Clear()
172 * Query whether a Finished signal should be emitted for this animation.
173 * This should only be called by NotificationManager, before signals are emitted.
174 * @post HasFinished() will return false on subsequent calls, until the animation is replayed to completion.
179 * @copydoc Dali::Animation::FinishedSignal()
181 Dali::Animation::AnimationSignalType& FinishedSignal();
184 * Emit the Finished signal
186 void EmitSignalFinish();
189 * Connects a callback function with the object's signals.
190 * @param[in] object The object providing the signal.
191 * @param[in] tracker Used to disconnect the signal.
192 * @param[in] signalName The signal to connect to.
193 * @param[in] functor A newly allocated FunctorDelegate.
194 * @return True if the signal was connected.
195 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
197 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
200 * Performs actions as requested using the action name.
201 * @param[in] object The object on which to perform the action.
202 * @param[in] actionName The action to perform.
203 * @param[in] attributes The attributes with which to perfrom this action.
204 * @return true if action was done
206 static bool DoAction(BaseObject* object, const std::string& actionName, const Property::Map& attributes);
209 * This callback is intended for internal use only, to avoid the overhead of using a signal.
210 * @param[in] callback The callback function to connect.
211 * @param[in] object The internal object requesting the callback, or NULL.
213 void SetFinishedCallback( FinishedCallback callback, Object* object );
216 * @copydoc Dali::Animation::AnimateBy(Property target, Property::Value relativeValue)
218 void AnimateBy(Property& target, Property::Value& relativeValue);
221 * @copydoc Dali::Animation::AnimateBy(Property target, Property::Value relativeValue, AlphaFunction alpha)
223 void AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha);
226 * @copydoc Dali::Animation::AnimateBy(Property target, Property::Value relativeValue, TimePeriod period)
228 void AnimateBy(Property& target, Property::Value& relativeValue, TimePeriod period);
231 * @copydoc Dali::Animation::AnimateBy(Property target, Property::Value relativeValue, AlphaFunction alpha, TimePeriod period)
233 void AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha, TimePeriod period);
236 * @copydoc Dali::Animation::AnimateTo(Property target, Property::Value destinationValue)
238 void AnimateTo(Property& target, Property::Value& destinationValue);
241 * @copydoc Dali::Animation::AnimateTo(Property target, Property::Value destinationValue, AlphaFunction alpha)
243 void AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha);
246 * @copydoc Dali::Animation::AnimateTo(Property target, Property::Value destinationValue, TimePeriod period)
248 void AnimateTo(Property& target, Property::Value& destinationValue, TimePeriod period);
251 * @copydoc Dali::Animation::AnimateTo(Property target, Property::Value destinationValue, AlphaFunction alpha, TimePeriod period)
253 void AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period);
256 * Animate a property to a destination value.
257 * @param [in] targetObject The target object to animate.
258 * @param [in] targetPropertyIndex The index of the target property.
259 * @param [in] componentIndex Index to a sub component of a property, for use with Vector2, Vector3 and Vector4
260 * @param [in] destinationValue The destination value.
261 * @param [in] alpha The alpha function to apply.
262 * @param [in] period The effect will occur during this time period.
264 void AnimateTo(Object& targetObject, Property::Index targetPropertyIndex, int componentIndex, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period);
267 * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames)
269 void AnimateBetween(Property target, const KeyFrames& keyFrames);
272 * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames, Interpolation interpolation)
274 void AnimateBetween(Property target, const KeyFrames& keyFrames, Interpolation interpolation );
277 * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames, TimePeriod period)
279 void AnimateBetween(Property target, const KeyFrames& keyFrames, TimePeriod period);
282 * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames, TimePeriod period, Interpolation interpolation)
284 void AnimateBetween(Property target, const KeyFrames& keyFrames, TimePeriod period, Interpolation interpolation);
287 * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames, AlphaFunction alpha)
289 void AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha);
292 * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames, AlphaFunction alpha, Interpolation interpolation)
294 void AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, Interpolation interpolation);
297 * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period)
299 void AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period);
302 * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period, Interpolation interpolation )
304 void AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period, Interpolation interpolation );
306 // Actor-specific convenience functions
309 * @copydoc Dali::Animation::Animate( Actor actor, Path path, const Vector3& forward )
311 void Animate( Actor& actor, const Path& path, const Vector3& forward );
314 * @copydoc Dali::Animation::Animate( Actor actor, Path path, const Vector3& forward, AlphaFunction alpha )
316 void Animate( Actor& actor, const Path& path, const Vector3& forward, AlphaFunction alpha );
319 * @copydoc Dali::Animation::Animate( Actor actor, Path path, const Vector3& forward, TimePeriod period )
321 void Animate( Actor& actor, const Path& path, const Vector3& forward, TimePeriod period );
324 * @copydoc Dali::Animation::Animate( Actor actor, Path path, const Vector3& forward, AlphaFunction alpha, TimePeriod period)
326 void Animate( Actor& actor, const Path& path, const Vector3& forward, AlphaFunction alpha, TimePeriod period);
329 * @copydoc Dali::Animation::Show()
331 void Show(Actor& actor, float delaySeconds);
334 * @copydoc Dali::Animation::Hide()
336 void Hide(Actor& actor, float delaySeconds);
339 * @copydoc Dali::Animation::SetCurrentProgress()
341 void SetCurrentProgress(float progress);
344 * @copydoc Dali::Animation::GetCurrentProgress()
346 float GetCurrentProgress();
349 * @copydoc Dali::Animation::SetSpeedFactor()
351 void SetSpeedFactor( float factor );
354 * @copydoc Dali::Animation::GetSpeedFactor()
356 float GetSpeedFactor() const;
359 * @copydoc Dali::Animation::SetPlayRange()
361 void SetPlayRange( const Vector2& range );
364 * @copydoc Dali::Animation::GetPlayRange
366 Vector2 GetPlayRange() const;
368 public: // For connecting animators to animations
371 * Add an animator connector.
372 * @param[in] connector The animator connector.
374 void AddAnimatorConnector( AnimatorConnectorBase* connector );
377 * Retrieve the SceneGraph::Animation object.
378 * @return The animation.
380 const SceneGraph::Animation* GetSceneObject()
386 * Retrieve the event thread services object
387 * @return The interface for sending messages to the scene graph
389 EventThreadServices& GetEventThreadServices()
391 return mEventThreadServices;
397 * Construct a new Animation.
398 * @param[in] eventThreadServices The interface for sending messages to the scene graph
399 * @param[in] playlist The list of currently playing animations.
400 * @param[in] durationSeconds The duration of the animation in seconds.
401 * @param[in] endAction The action to perform when the animation ends.
402 * @param[in] disconnectAction The action to perform when the property owner of an animator is disconnected.
403 * @param[in] defaultAlpha The default alpha function to apply to animators.
405 Animation( EventThreadServices& eventThreadServices,
406 AnimationPlaylist& playlist,
407 float durationSeconds,
409 EndAction disconnectAction,
410 AlphaFunction defaultAlpha);
413 * Second-phase constructor.
418 * Helper to create a scene-graph animation
420 void CreateSceneObject();
423 * Helper to create a scene-graph animation
425 void DestroySceneObject();
428 * A reference counted object may only be deleted by calling Unreference()
430 virtual ~Animation();
435 * Extends the duration when an animator is added with TimePeriod that exceeds current duration.
436 * @param[in] timePeriod The time period for an animator.
438 void ExtendDuration( const TimePeriod& timePeriod );
441 Animation(const Animation&);
444 Animation& operator=(const Animation& rhs);
447 EventThreadServices& mEventThreadServices;
448 AnimationPlaylist& mPlaylist;
450 const SceneGraph::Animation* mAnimation;
452 int mNotificationCount; ///< Keep track of how many Finished signals have been emitted.
454 Dali::Animation::AnimationSignalType mFinishedSignal;
456 FinishedCallback mFinishedCallback;
457 Object* mFinishedCallbackObject;
459 AnimatorConnectorContainer mConnectors; ///< Owned by the Animation
461 // Cached for public getters
462 float mDurationSeconds;
467 EndAction mEndAction;
468 EndAction mDisconnectAction;
469 AlphaFunction mDefaultAlpha;
473 } // namespace Internal
475 // Helpers for public-api forwarding methods
477 inline Internal::Animation& GetImplementation(Dali::Animation& animation)
479 DALI_ASSERT_ALWAYS( animation && "Animation handle is empty" );
481 BaseObject& handle = animation.GetBaseObject();
483 return static_cast<Internal::Animation&>(handle);
486 inline const Internal::Animation& GetImplementation(const Dali::Animation& animation)
488 DALI_ASSERT_ALWAYS( animation && "Animation handle is empty" );
490 const BaseObject& handle = animation.GetBaseObject();
492 return static_cast<const Internal::Animation&>(handle);
497 #endif // __DALI_INTERNAL_ANIMATION_H__