[Tizen] (Animation) Reorder animation variables according to size & remove unused
[platform/core/uifw/dali-core.git] / dali / internal / event / animation / animation-impl.h
1 #ifndef __DALI_INTERNAL_ANIMATION_H__
2 #define __DALI_INTERNAL_ANIMATION_H__
3
4 /*
5  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // INTERNAL INCLUDES
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
30 namespace Dali
31 {
32
33 namespace Internal
34 {
35
36 namespace SceneGraph
37 {
38 class Animation;
39 class UpdateManager;
40 }
41
42 class Actor;
43 class Animation;
44 class AnimationPlaylist;
45 class Object;
46
47 typedef IntrusivePtr<Animation> AnimationPtr;
48 typedef std::vector<AnimationPtr> AnimationContainer;
49
50 typedef AnimationContainer::iterator AnimationIter;
51 typedef AnimationContainer::const_iterator AnimationConstIter;
52
53 /**
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.
57  */
58 class Animation : public BaseObject
59 {
60 public:
61
62   typedef Dali::Animation::EndAction EndAction;
63   typedef Dali::Animation::Interpolation Interpolation;
64
65   /**
66    * Create a new Animation object.
67    * @param[in] durationSeconds The duration of the animation.
68    * @return A smart-pointer to the newly allocated Animation.
69    */
70   static AnimationPtr New(float durationSeconds);
71
72   /**
73    * @copydoc Dali::Animation::SetDuration()
74    */
75   void SetDuration(float seconds);
76
77   /**
78    * @copydoc Dali::Animation::GetDuration()
79    */
80   float GetDuration() const;
81
82   /**
83    * @copydoc Dali::Animation::SetLooping()
84    */
85   void SetLooping(bool on);
86
87   /**
88    * @copydoc Dali::Animation::SetLoopCount()
89    */
90   void SetLoopCount(int count);
91
92   /**
93    * @copydoc Dali::Animation::GetLoopCount()
94    */
95   int GetLoopCount();
96
97   /**
98    * @copydoc Dali::Animation::GetCurrentLoop()
99    */
100   int GetCurrentLoop();
101
102   /**
103    * @copydoc Dali::Animation::IsLooping()
104    */
105   bool IsLooping() const;
106
107   /**
108    * @copydoc Dali::Animation::SetEndAction()
109    */
110   void SetEndAction(EndAction action);
111
112   /**
113    * @copydoc Dali::Animation::GetEndAction()
114    */
115   EndAction GetEndAction() const;
116
117   /**
118    * @copydoc Dali::Animation::SetDisconnectAction()
119    */
120   void SetDisconnectAction(EndAction action);
121
122   /**
123    * @copydoc Dali::Animation::GetDisconnectAction()
124    */
125   EndAction GetDisconnectAction() const;
126
127   /**
128    * @copydoc Dali::Animation::SetDefaultAlphaFunction()
129    */
130   void SetDefaultAlphaFunction(AlphaFunction alpha)
131   {
132     mDefaultAlpha = alpha;
133   }
134
135   /**
136    * @copydoc Dali::Animation::GetDefaultAlphaFunction()
137    */
138   AlphaFunction GetDefaultAlphaFunction() const
139   {
140     return mDefaultAlpha;
141   }
142
143   /**
144    * @copydoc Dali::Animation::Play()
145    */
146   void Play();
147
148   /**
149    * @copydoc Dali::Animation::PlayFrom()
150    */
151   void PlayFrom( float progress );
152
153   /**
154    * @copydoc Dali::Animation::Pause()
155    */
156   void Pause();
157
158   /**
159    * @copydoc Dali::Animation::GetState()
160    */
161   Dali::Animation::State GetState() const;
162
163   /**
164    * @copydoc Dali::Animation::Stop()
165    */
166   void Stop();
167
168   /**
169    * @copydoc Dali::Animation::Clear()
170    */
171   void Clear();
172
173   /**
174    * Query whether a Finished signal should be emitted for this animation.
175    * This should only be called by NotificationManager, before signals are emitted.
176    * @post HasFinished() will return false on subsequent calls, until the animation is replayed to completion.
177    */
178   bool HasFinished();
179
180   /**
181    * @copydoc Dali::Animation::FinishedSignal()
182    */
183   Dali::Animation::AnimationSignalType& FinishedSignal();
184
185   /**
186    * Emit the Finished signal
187    */
188   void EmitSignalFinish();
189
190   /**
191    * Connects a callback function with the object's signals.
192    * @param[in] object The object providing the signal.
193    * @param[in] tracker Used to disconnect the signal.
194    * @param[in] signalName The signal to connect to.
195    * @param[in] functor A newly allocated FunctorDelegate.
196    * @return True if the signal was connected.
197    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
198    */
199   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
200
201   /**
202    * Performs actions as requested using the action name.
203    * @param[in] object The object on which to perform the action.
204    * @param[in] actionName The action to perform.
205    * @param[in] attributes The attributes with which to perfrom this action.
206    * @return true if action was done
207    */
208   static bool DoAction(BaseObject* object, const std::string& actionName, const Property::Map& attributes);
209
210   /**
211    * @copydoc Dali::Animation::AnimateBy(Property target, Property::Value relativeValue)
212    */
213   void AnimateBy(Property& target, Property::Value& relativeValue);
214
215   /**
216    * @copydoc Dali::Animation::AnimateBy(Property target, Property::Value relativeValue, AlphaFunction alpha)
217    */
218   void AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha);
219
220   /**
221    * @copydoc Dali::Animation::AnimateBy(Property target, Property::Value relativeValue, TimePeriod period)
222    */
223   void AnimateBy(Property& target, Property::Value& relativeValue, TimePeriod period);
224
225   /**
226    * @copydoc Dali::Animation::AnimateBy(Property target, Property::Value relativeValue, AlphaFunction alpha, TimePeriod period)
227    */
228   void AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha, TimePeriod period);
229
230   /**
231    * @copydoc Dali::Animation::AnimateTo(Property target, Property::Value destinationValue)
232    */
233   void AnimateTo(Property& target, Property::Value& destinationValue);
234
235   /**
236    * @copydoc Dali::Animation::AnimateTo(Property target, Property::Value destinationValue, AlphaFunction alpha)
237    */
238   void AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha);
239
240   /**
241    * @copydoc Dali::Animation::AnimateTo(Property target, Property::Value destinationValue, TimePeriod period)
242    */
243   void AnimateTo(Property& target, Property::Value& destinationValue, TimePeriod period);
244
245   /**
246    * @copydoc Dali::Animation::AnimateTo(Property target, Property::Value destinationValue, AlphaFunction alpha, TimePeriod period)
247    */
248   void AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period);
249
250   /**
251    * Animate a property to a destination value.
252    * @param [in] targetObject The target object to animate.
253    * @param [in] targetPropertyIndex The index of the target property.
254    * @param [in] componentIndex Index to a sub component of a property, for use with Vector2, Vector3 and Vector4
255    * @param [in] destinationValue The destination value.
256    * @param [in] alpha The alpha function to apply.
257    * @param [in] period The effect will occur during this time period.
258    */
259   void AnimateTo(Object& targetObject, Property::Index targetPropertyIndex, int componentIndex, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period);
260
261   /**
262    * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames)
263    */
264   void AnimateBetween(Property target, const KeyFrames& keyFrames);
265
266   /**
267    * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames, Interpolation interpolation)
268    */
269   void AnimateBetween(Property target, const KeyFrames& keyFrames, Interpolation interpolation );
270
271   /**
272    * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames, TimePeriod period)
273    */
274   void AnimateBetween(Property target, const KeyFrames& keyFrames, TimePeriod period);
275
276   /**
277    * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames, TimePeriod period, Interpolation interpolation)
278    */
279   void AnimateBetween(Property target, const KeyFrames& keyFrames, TimePeriod period, Interpolation interpolation);
280
281   /**
282    * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames, AlphaFunction alpha)
283    */
284   void AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha);
285
286   /**
287    * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames, AlphaFunction alpha, Interpolation interpolation)
288    */
289   void AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, Interpolation interpolation);
290
291   /**
292    * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period)
293    */
294   void AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period);
295
296   /**
297    * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period, Interpolation interpolation )
298    */
299   void AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period, Interpolation interpolation );
300
301   // Actor-specific convenience functions
302
303   /**
304    * @copydoc Dali::Animation::Animate( Actor actor, Path path, const Vector3& forward )
305    */
306   void Animate( Actor& actor, const Path& path, const Vector3& forward );
307
308   /**
309    * @copydoc Dali::Animation::Animate( Actor actor, Path path, const Vector3& forward, AlphaFunction alpha )
310    */
311   void Animate( Actor& actor, const Path& path, const Vector3& forward, AlphaFunction alpha );
312
313   /**
314    * @copydoc Dali::Animation::Animate( Actor actor, Path path, const Vector3& forward, TimePeriod period )
315    */
316   void Animate( Actor& actor, const Path& path, const Vector3& forward, TimePeriod period );
317
318   /**
319    * @copydoc Dali::Animation::Animate( Actor actor, Path path, const Vector3& forward, AlphaFunction alpha, TimePeriod period)
320    */
321   void Animate( Actor& actor, const Path& path, const Vector3& forward, AlphaFunction alpha, TimePeriod period);
322
323   /**
324    * @copydoc Dali::Animation::Show()
325    */
326   void Show(Actor& actor, float delaySeconds);
327
328   /**
329    * @copydoc Dali::Animation::Hide()
330    */
331   void Hide(Actor& actor, float delaySeconds);
332
333   /*
334    * @copydoc Dali::Animation::SetCurrentProgress()
335    */
336   void SetCurrentProgress(float progress);
337
338   /*
339    * @copydoc Dali::Animation::GetCurrentProgress()
340    */
341   float GetCurrentProgress();
342
343   /*
344    * @copydoc Dali::Animation::SetSpeedFactor()
345    */
346   void SetSpeedFactor( float factor );
347
348   /*
349    * @copydoc Dali::Animation::GetSpeedFactor()
350    */
351   float GetSpeedFactor() const;
352
353   /*
354    * @copydoc Dali::Animation::SetPlayRange()
355    */
356   void SetPlayRange( const Vector2& range );
357
358   /*
359    * @copydoc Dali::Animation::GetPlayRange
360    */
361   Vector2 GetPlayRange() const;
362
363 public: // For connecting animators to animations
364
365   /**
366    * Add an animator connector.
367    * @param[in] connector The animator connector.
368    */
369   void AddAnimatorConnector( AnimatorConnectorBase* connector );
370
371   /**
372    * Retrieve the SceneGraph::Animation object.
373    * @return The animation.
374    */
375   const SceneGraph::Animation* GetSceneObject()
376   {
377     return mAnimation;
378   }
379
380   /**
381    * Retrieve the event thread services object
382    * @return The interface for sending messages to the scene graph
383    */
384   EventThreadServices& GetEventThreadServices()
385   {
386     return mEventThreadServices;
387   }
388
389 protected:
390
391   /**
392    * Construct a new Animation.
393    * @param[in] eventThreadServices The interface for sending messages to the scene graph
394    * @param[in] playlist The list of currently playing animations.
395    * @param[in] durationSeconds The duration of the animation in seconds.
396    * @param[in] endAction The action to perform when the animation ends.
397    * @param[in] disconnectAction The action to perform when the property owner of an animator is disconnected.
398    * @param[in] defaultAlpha The default alpha function to apply to animators.
399    */
400   Animation( EventThreadServices& eventThreadServices,
401              AnimationPlaylist& playlist,
402              float durationSeconds,
403              EndAction endAction,
404              EndAction disconnectAction,
405              AlphaFunction defaultAlpha);
406
407   /**
408    * Second-phase constructor.
409    */
410   void Initialize();
411
412   /**
413    * Helper to create a scene-graph animation
414    */
415   void CreateSceneObject();
416
417   /**
418    * Helper to create a scene-graph animation
419    */
420   void DestroySceneObject();
421
422   /**
423    * A reference counted object may only be deleted by calling Unreference()
424    */
425   virtual ~Animation();
426
427 private:
428
429   /**
430    * Extends the duration when an animator is added with TimePeriod that exceeds current duration.
431    * @param[in] timePeriod The time period for an animator.
432    */
433   void ExtendDuration( const TimePeriod& timePeriod );
434
435   // Undefined
436   Animation(const Animation&);
437
438   // Undefined
439   Animation& operator=(const Animation& rhs);
440
441 private:
442
443   struct ConnectorTargetValues
444   {
445     unsigned int connectorIndex;
446     Property::Value targetValue;
447   };
448
449   const SceneGraph::Animation* mAnimation;
450
451   EventThreadServices& mEventThreadServices;
452   AnimationPlaylist& mPlaylist;
453
454   Dali::Animation::AnimationSignalType mFinishedSignal;
455
456   AnimatorConnectorContainer mConnectors; ///< Owned by the Animation
457
458   std::vector< ConnectorTargetValues > mConnectorTargetValues; //< Used to store animating property target value information
459
460   Vector2 mPlayRange;
461
462   float mDurationSeconds;
463   float mSpeedFactor;
464   int mNotificationCount; ///< Keep track of how many Finished signals have been emitted.
465   int mLoopCount;
466   int mCurrentLoop;
467   EndAction mEndAction;
468   EndAction mDisconnectAction;
469   AlphaFunction mDefaultAlpha;
470   Dali::Animation::State mState;
471 };
472
473 } // namespace Internal
474
475 // Helpers for public-api forwarding methods
476
477 inline Internal::Animation& GetImplementation(Dali::Animation& animation)
478 {
479   DALI_ASSERT_ALWAYS( animation && "Animation handle is empty" );
480
481   BaseObject& handle = animation.GetBaseObject();
482
483   return static_cast<Internal::Animation&>(handle);
484 }
485
486 inline const Internal::Animation& GetImplementation(const Dali::Animation& animation)
487 {
488   DALI_ASSERT_ALWAYS( animation && "Animation handle is empty" );
489
490   const BaseObject& handle = animation.GetBaseObject();
491
492   return static_cast<const Internal::Animation&>(handle);
493 }
494
495 } // namespace Dali
496
497 #endif // __DALI_INTERNAL_ANIMATION_H__