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>
29 #include <dali/internal/event/common/object-impl.h>
45 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;
67 * Create a new Animation object.
68 * @param[in] durationSeconds The duration of the animation.
69 * @return A smart-pointer to the newly allocated Animation.
71 static AnimationPtr New(float durationSeconds);
74 * @copydoc Dali::Animation::SetDuration()
76 void SetDuration(float seconds);
79 * @copydoc Dali::Animation::GetDuration()
81 float GetDuration() const;
84 * @copydoc Dali::Animation::SetLooping()
86 void SetLooping(bool on);
89 * @copydoc Dali::Animation::SetLoopCount()
91 void SetLoopCount(int count);
94 * @copydoc Dali::Animation::GetLoopCount()
99 * @copydoc Dali::Animation::GetCurrentLoop()
101 int GetCurrentLoop();
104 * @copydoc Dali::Animation::IsLooping()
106 bool IsLooping() const;
109 * @copydoc Dali::Animation::SetEndAction()
111 void SetEndAction(EndAction action);
114 * @copydoc Dali::Animation::GetEndAction()
116 EndAction GetEndAction() const;
119 * @copydoc Dali::Animation::SetDisconnectAction()
121 void SetDisconnectAction(EndAction action);
124 * @copydoc Dali::Animation::GetDisconnectAction()
126 EndAction GetDisconnectAction() const;
129 * @copydoc Dali::Animation::SetDefaultAlphaFunction()
131 void SetDefaultAlphaFunction(AlphaFunction alpha)
133 mDefaultAlpha = alpha;
137 * @copydoc Dali::Animation::GetDefaultAlphaFunction()
139 AlphaFunction GetDefaultAlphaFunction() const
141 return mDefaultAlpha;
145 * @copydoc Dali::Animation::Play()
150 * @copydoc Dali::Animation::PlayFrom()
152 void PlayFrom( float progress );
155 * @copydoc Dali::Animation::Pause()
160 * @copydoc Dali::Animation::GetState()
162 Dali::Animation::State GetState() const;
165 * @copydoc Dali::Animation::Stop()
170 * @copydoc Dali::Animation::Clear()
175 * Query whether a Finished signal should be emitted for this animation.
176 * This should only be called by NotificationManager, before signals are emitted.
177 * @post HasFinished() will return false on subsequent calls, until the animation is replayed to completion.
182 * @copydoc Dali::Animation::FinishedSignal()
184 Dali::Animation::AnimationSignalType& FinishedSignal();
187 * Emit the Finished signal
189 void EmitSignalFinish();
192 * Connects a callback function with the object's signals.
193 * @param[in] object The object providing the signal.
194 * @param[in] tracker Used to disconnect the signal.
195 * @param[in] signalName The signal to connect to.
196 * @param[in] functor A newly allocated FunctorDelegate.
197 * @return True if the signal was connected.
198 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
200 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
203 * Performs actions as requested using the action name.
204 * @param[in] object The object on which to perform the action.
205 * @param[in] actionName The action to perform.
206 * @param[in] attributes The attributes with which to perfrom this action.
207 * @return true if action was done
209 static bool DoAction(BaseObject* object, const std::string& actionName, const Property::Map& attributes);
212 * @copydoc Dali::Animation::AnimateBy(Property target, Property::Value relativeValue)
214 void AnimateBy(Property& target, Property::Value& relativeValue);
217 * @copydoc Dali::Animation::AnimateBy(Property target, Property::Value relativeValue, AlphaFunction alpha)
219 void AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha);
222 * @copydoc Dali::Animation::AnimateBy(Property target, Property::Value relativeValue, TimePeriod period)
224 void AnimateBy(Property& target, Property::Value& relativeValue, TimePeriod period);
227 * @copydoc Dali::Animation::AnimateBy(Property target, Property::Value relativeValue, AlphaFunction alpha, TimePeriod period)
229 void AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha, TimePeriod period);
232 * @copydoc Dali::Animation::AnimateTo(Property target, Property::Value destinationValue)
234 void AnimateTo(Property& target, Property::Value& destinationValue);
237 * @copydoc Dali::Animation::AnimateTo(Property target, Property::Value destinationValue, AlphaFunction alpha)
239 void AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha);
242 * @copydoc Dali::Animation::AnimateTo(Property target, Property::Value destinationValue, TimePeriod period)
244 void AnimateTo(Property& target, Property::Value& destinationValue, TimePeriod period);
247 * @copydoc Dali::Animation::AnimateTo(Property target, Property::Value destinationValue, AlphaFunction alpha, TimePeriod period)
249 void AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period);
252 * Animate a property to a destination value.
253 * @param [in] targetObject The target object to animate.
254 * @param [in] targetPropertyIndex The index of the target property.
255 * @param [in] componentIndex Index to a sub component of a property, for use with Vector2, Vector3 and Vector4
256 * @param [in] destinationValue The destination value.
257 * @param [in] alpha The alpha function to apply.
258 * @param [in] period The effect will occur during this time period.
260 void AnimateTo(Object& targetObject, Property::Index targetPropertyIndex, int componentIndex, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period);
263 * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames)
265 void AnimateBetween(Property target, const KeyFrames& keyFrames);
268 * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames, Interpolation interpolation)
270 void AnimateBetween(Property target, const KeyFrames& keyFrames, Interpolation interpolation );
273 * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames, TimePeriod period)
275 void AnimateBetween(Property target, const KeyFrames& keyFrames, TimePeriod period);
278 * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames, TimePeriod period, Interpolation interpolation)
280 void AnimateBetween(Property target, const KeyFrames& keyFrames, TimePeriod period, Interpolation interpolation);
283 * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames, AlphaFunction alpha)
285 void AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha);
288 * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames, AlphaFunction alpha, Interpolation interpolation)
290 void AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, Interpolation interpolation);
293 * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period)
295 void AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period);
298 * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period, Interpolation interpolation )
300 void AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period, Interpolation interpolation );
302 // Actor-specific convenience functions
305 * @copydoc Dali::Animation::Animate( Actor actor, Path path, const Vector3& forward )
307 void Animate( Actor& actor, const Path& path, const Vector3& forward );
310 * @copydoc Dali::Animation::Animate( Actor actor, Path path, const Vector3& forward, AlphaFunction alpha )
312 void Animate( Actor& actor, const Path& path, const Vector3& forward, AlphaFunction alpha );
315 * @copydoc Dali::Animation::Animate( Actor actor, Path path, const Vector3& forward, TimePeriod period )
317 void Animate( Actor& actor, const Path& path, const Vector3& forward, TimePeriod period );
320 * @copydoc Dali::Animation::Animate( Actor actor, Path path, const Vector3& forward, AlphaFunction alpha, TimePeriod period)
322 void Animate( Actor& actor, const Path& path, const Vector3& forward, AlphaFunction alpha, TimePeriod period);
325 * @copydoc Dali::Animation::Show()
327 void Show(Actor& actor, float delaySeconds);
330 * @copydoc Dali::Animation::Hide()
332 void Hide(Actor& actor, float delaySeconds);
335 * @copydoc Dali::Animation::SetCurrentProgress()
337 void SetCurrentProgress(float progress);
340 * @copydoc Dali::Animation::GetCurrentProgress()
342 float GetCurrentProgress();
345 * @copydoc Dali::Animation::SetSpeedFactor()
347 void SetSpeedFactor( float factor );
350 * @copydoc Dali::Animation::GetSpeedFactor()
352 float GetSpeedFactor() const;
355 * @copydoc Dali::Animation::SetPlayRange()
357 void SetPlayRange( const Vector2& range );
360 * @copydoc Dali::Animation::GetPlayRange
362 Vector2 GetPlayRange() const;
364 public: // For connecting animators to animations
367 * Add an animator connector.
368 * @param[in] connector The animator connector.
370 void AddAnimatorConnector( AnimatorConnectorBase* connector );
373 * Retrieve the SceneGraph::Animation object.
374 * @return The animation.
376 const SceneGraph::Animation* GetSceneObject()
382 * Retrieve the event thread services object
383 * @return The interface for sending messages to the scene graph
385 EventThreadServices& GetEventThreadServices()
387 return mEventThreadServices;
393 * Construct a new Animation.
394 * @param[in] eventThreadServices The interface for sending messages to the scene graph
395 * @param[in] playlist The list of currently playing animations.
396 * @param[in] durationSeconds The duration of the animation in seconds.
397 * @param[in] endAction The action to perform when the animation ends.
398 * @param[in] disconnectAction The action to perform when the property owner of an animator is disconnected.
399 * @param[in] defaultAlpha The default alpha function to apply to animators.
401 Animation( EventThreadServices& eventThreadServices,
402 AnimationPlaylist& playlist,
403 float durationSeconds,
405 EndAction disconnectAction,
406 AlphaFunction defaultAlpha);
409 * Second-phase constructor.
414 * Helper to create a scene-graph animation
416 void CreateSceneObject();
419 * Helper to create a scene-graph animation
421 void DestroySceneObject();
424 * A reference counted object may only be deleted by calling Unreference()
426 virtual ~Animation();
431 * Extends the duration when an animator is added with TimePeriod that exceeds current duration.
432 * @param[in] timePeriod The time period for an animator.
434 void ExtendDuration( const TimePeriod& timePeriod );
437 Animation(const Animation&);
440 Animation& operator=(const Animation& rhs);
444 struct ConnectorTargetValues
446 ConnectorTargetValues()
450 propertyChangeType( Object::PropertyChange::SET )
454 Property::Value targetValue;
455 TimePeriod timePeriod;
456 unsigned int connectorIndex;
457 Object::PropertyChange::Type propertyChangeType;
463 * Compares the end times of the animators returning true if lhs end time is less than rhs end time.
464 * @param[in] lhs The first comparator
465 * @param[in] rhs The second comparator
466 * @return True if end time of lhs is less, false otherwise.
468 static bool CompareConnectorEndTimes( const ConnectorTargetValues& lhs, const ConnectorTargetValues& rhs );
472 const SceneGraph::Animation* mAnimation;
474 EventThreadServices& mEventThreadServices;
475 AnimationPlaylist& mPlaylist;
477 Dali::Animation::AnimationSignalType mFinishedSignal;
479 AnimatorConnectorContainer mConnectors; ///< Owned by the Animation
481 typedef std::vector< ConnectorTargetValues > ConnectorTargetValuesContainer;
482 ConnectorTargetValuesContainer mConnectorTargetValues; //< Used to store animating property target value information
486 float mDurationSeconds;
488 int mNotificationCount; ///< Keep track of how many Finished signals have been emitted.
491 EndAction mEndAction;
492 EndAction mDisconnectAction;
493 AlphaFunction mDefaultAlpha;
494 Dali::Animation::State mState;
497 } // namespace Internal
499 // Helpers for public-api forwarding methods
501 inline Internal::Animation& GetImplementation(Dali::Animation& animation)
503 DALI_ASSERT_ALWAYS( animation && "Animation handle is empty" );
505 BaseObject& handle = animation.GetBaseObject();
507 return static_cast<Internal::Animation&>(handle);
510 inline const Internal::Animation& GetImplementation(const Dali::Animation& animation)
512 DALI_ASSERT_ALWAYS( animation && "Animation handle is empty" );
514 const BaseObject& handle = animation.GetBaseObject();
516 return static_cast<const Internal::Animation&>(handle);
521 #endif // __DALI_INTERNAL_ANIMATION_H__