Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / animations / FUiAnim_FrameAnimatorImpl.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file        FUiAnim_FrameAnimatorImpl.h
20  * @brief       This is the header file for the _FrameAnimatorImpl class.
21  *
22  * This header file contains the declarations of the _FrameAnimatorImpl class. @n
23  */
24
25 #ifndef _FUI_ANIM_INTERNAL_FRAME_ANIMATOR_IMPL_H_
26 #define _FUI_ANIM_INTERNAL_FRAME_ANIMATOR_IMPL_H_
27
28 #include <FUiAnimFrameAnimator.h>
29 #include <FUiAnimVisualElementPropertyAnimation.h>
30 #include <FUiAnimIVisualElementAnimationTimingFunction.h>
31
32 #include "FUiAnim_ControlVisualElement.h"
33
34
35 namespace Tizen { namespace Ui { namespace Animations
36 {
37
38 /**
39  * @class       _FrameAnimatorImpl
40  * @brief       This class defines the animation API for Container::Frame
41  * @since       2.0
42  *
43  * The %_FrameAnimatorImpl class is used to control the animations operated on Tizen::Ui::Controls::Container::Frame
44  *
45  */
46 class _FrameAnimatorImpl
47         : public Tizen::Base::Object
48         , public IAnimationTransactionEventListener
49         , virtual public Tizen::Base::Runtime::IEventListener
50 {
51 public:
52         /**
53          * Destructor for %_FrameAnimatorImpl class.
54          *
55          * @since               2.0
56          */
57         ~_FrameAnimatorImpl(void);
58
59         /**
60          * Default constructor for %_FrameAnimatorImpl class.
61          *
62          * @since               2.0
63          */
64         _FrameAnimatorImpl(FrameAnimator* pFrameAnimator);
65
66         /**
67          * Initializes this %_FrameAnimatorImpl class.
68          *
69          * @since               2.0
70          *
71          * @return              An error code
72          * @exception   E_SUCCESS                       The method was successful.
73          * @exception   E_OUT_OF_MEMORY     Insufficient memory.
74          */
75         result Construct(const Tizen::Ui::Controls::Frame& source);
76
77         /**
78          * Adds framestatusevent listener to list.
79          *
80          * @since 2.0
81          *
82          * @return              An error code
83          * @exception   E_SUCCESS                       The method was successful.
84          * @exception   E_SYSTEM                        System error occurred.
85          */
86         result AddFrameAnimatorEventListener(IFrameAnimatorEventListener& listener);
87
88         /**
89          * Removes framestatusevent listener from list.
90          *
91          * @since 2.0
92          *
93          * @return              An error code
94          * @exception   E_SUCCESS                       The method was successful.
95          * @exception   E_SYSTEM                        System error occurred.
96          * @exception   E_OBJ_NOT_FOUND         Listener object not found in list.
97          */
98         result RemoveFrameAnimatorEventListener(IFrameAnimatorEventListener& listener);
99
100         /**
101          * Stops all the animations that are currently playing and jumps to the final frame of the animation.
102          *
103          * @since 2.0
104          *
105          * @return              An error code
106          * @exception   E_SUCCESS                       The method is successful.
107          * @exception   E_SYSTEM                        A system error has occurred.
108          */
109         result StopAllAnimations(void);
110
111         /**
112          * Adds the control at the end of the list maintained by the container with animation.
113          *
114          * @since 2.0
115          *
116          * @return              An error code
117          * @param[in]   control         The control to be added to the container
118          * @exception   E_SUCCESS       The method is successful.
119          * @exception   E_INVALID_ARG   The specified input parameter is invalid. @n
120          *                              The specified @c control is an instance of Window, or this control's parent container.
121          * @exception   E_OUT_OF_MEMORY The memory is insufficient.
122          * @exception   E_MAX_EXCEEDED  The number of child controls has exceeded the maximum limit.
123          * @exception   E_SYSTEM        A system error has occurred.
124          * @remarks             When the control is added, it is placed at the top of the drawing stack maintained by the container.@n
125          *              This means the last control added is drawn last
126          * @remarks             A control becomes displayable only after it has been added to a displayable container. Some methods may not work normally if the methods
127          *                              of the control are called before adding the control to a container. After the control is added to a %Container, the OnInitializing()
128          *                              method of the control are called before adding the control to a container. After the control is added to a Container, the
129          *                              OnInitializing() method of the control is invoked for the initialization of the control such as creating and adding child controls.
130          * @see                 Tizen::Ui::Control::OnInitializing()
131          * @see                 Tizen::Ui::Control::OnTerminating()
132          */
133         result AddControl(const Tizen::Ui::Control& control);
134
135         /**
136          * Sets the current form with animation.
137          *
138          * @since               2.0
139          *
140          * @return              An error code
141          * @exception   E_SUCCESS                       The method was successful.
142          * @exception   E_INVALID_ARG           A specified input parameter is invalid.
143          * @exception   E_INVALID_STATE     This instance has already been constructed.
144          * @exception   E_OUT_OF_MEMORY     Insufficient memory.
145          * @exception   E_SYSTEM                        System error occurred.
146          */
147         result SetCurrentForm(const Tizen::Ui::Controls::Form& form);
148
149
150         /**
151          * returns whether animation supported by underlying platform or not
152          *
153          * @since               2.0
154          *
155          * @return              An error code
156          * @remarks             %This function returns whether animation is supported or not. @n
157          *              If @c true, animation supported. @n
158          *              If @c false, animation not supported.
159          */
160         bool IsAnimationSupported(void) const;
161
162
163         /**
164          * This Callback is called when an animation is started.
165          *
166          * @since 2.0
167          */
168         virtual void OnAnimationTransactionStarted(int transactionId);
169
170
171         /**
172          * This Callback is called when an animation ends.
173          *
174          * @since 2.0
175          */
176         virtual void OnAnimationTransactionStopped(int transactionId);
177
178
179         /**
180          * This Callback is called when an animation ends.
181          *
182          * @since 2.0
183          */
184         virtual void OnAnimationTransactionFinished(int transactionId);
185
186
187         /**
188          * This Callback is called when an animation is started.
189          *
190          * @since 2.0
191          */
192         void OnFrameAnimationStarted(void);
193
194
195         /**
196          * This Callback is called when an animation ends.
197          *
198          * @since 2.0
199          */
200         void OnFrameAnimationStopped(bool completed);
201
202
203         /**
204          * Returns frame animator status.
205          *
206          * @since 2.0
207          *
208          * @return              AnimatorStatus for the frameanimator.
209          */
210         AnimatorStatus
211         GetFrameAnimatorStatus(void) const
212         {
213                 return __frameAnimatorStatus;
214         }
215
216         /**
217          * Returns frame animator FrameAnimatorFormTransitionAnimation.
218          *
219          * @since 2.0
220          *
221          * @return              FrameAnimatorFormTransitionAnimation for the frameanimator.
222          */
223         FrameAnimatorFormTransitionAnimation
224         GetAnimationEffectType(void) const
225         {
226                 return __animationEffectType;
227         }
228
229         /**
230          * Sets frame animator FrameAnimatorFormTransitionAnimation.
231          *
232          * @since 2.0
233          */
234         void
235         SetAnimationEffectType(FrameAnimatorFormTransitionAnimation animationEffectType)
236         {
237                 __animationEffectType = animationEffectType;
238         }
239
240         /**
241          * Returns frame animator animation duration.
242          *
243          * @since 2.0
244          *
245          * @return              long duration for the frameanimator.
246          */
247         long
248         GetDuration(void) const
249         {
250                 return __duration;
251         }
252
253         /**
254          * Sets frame animator animation duration.
255          *
256          * @since 2.0
257          */
258         void
259         SetDuration(long duration)
260         {
261                 __duration = duration;
262         }
263
264         /**
265          * Returns frame animator AnimInterpolatorType.
266          *
267          * @since 2.0
268          *
269          * @return              AnimInterpolatorType for the frameanimator.
270          */
271         AnimationInterpolatorType
272         GetAnimInterpolatorType(void) const
273         {
274                 return __animInterpolatorType;
275         }
276
277         /**
278          * Sets frame animator AnimInterpolatorType.
279          *
280          * @since 2.0
281          */
282         void
283         SetAnimInterpolatorType(AnimationInterpolatorType animInterpolatorType)
284         {
285                 __animInterpolatorType = animInterpolatorType;
286         }
287
288         /**
289          * Returns frame animator bezier control points.
290          *
291          * @since 2.0
292          *
293          * @return              A float type value.
294          */
295         void
296         GetFormTransitionBezierControlPoints(float& firstTime, float& firstValue, float& secondTime, float& secondValue) const
297         {
298                 firstTime = __firstBezierControlPointsTime;
299                 firstValue = __firstBezierControlPointsValue;
300                 secondTime = __secondBezierControlPointsTime;
301                 secondValue = __secondBezierControlPointsValue;
302         }
303
304         /**
305          * Sets frame animator bezier control points.
306          *
307          * @since 2.0
308          *
309          * @return              A float type value.
310          */
311         void
312         SetFormTransitionBezierControlPoints(float firstTime, float firstValue, float secondTime, float secondValue)
313         {
314                 __firstBezierControlPointsTime = firstTime;
315                 __firstBezierControlPointsValue = firstValue;
316                 __secondBezierControlPointsTime = secondTime;
317                 __secondBezierControlPointsValue = secondValue;
318         }
319
320         static _FrameAnimatorImpl* GetInstance(FrameAnimator& frameAnimator);
321         static const _FrameAnimatorImpl* GetInstance(const FrameAnimator& frameAnimator);
322
323 private:
324         /**
325          * This is the copy constructor for this class. @n
326          *
327          * @since               2.0
328          */
329         _FrameAnimatorImpl(const _FrameAnimatorImpl& rhs);
330
331         /**
332          * This is the assignment operator implementation for this class. @n
333          *
334          * @since               2.0
335          */
336         _FrameAnimatorImpl& operator =(const _FrameAnimatorImpl& rhs);
337
338         /**
339          * Delete & frees the memory used by the object.
340          *
341          * @since               2.0
342          *
343          * @return              An error code
344          * @exception   E_SUCCESS                       The method was successful.
345          * @exception   E_SYSTEM                        Failed to free the resource possessed by this instance.
346          */
347         result Dispose(void);
348
349         /**
350          * Starts the Layer animation.
351          *
352          * @since               2.0
353          *
354          * @return              An error code
355          * @exception   E_SUCCESS                       The method was successful.
356          * @exception   E_INVALID_ARG           A specified input parameter is invalid.
357          * @exception   E_INVALID_STATE     This instance has already been constructed.
358          * @exception   E_OUT_OF_MEMORY     Insufficient memory.
359          * @exception   E_SYSTEM                        System error occurred.
360          */
361         result StartLayerAnimation(VisualElement* pLayer, AnimationTargetType animTarget, Variant startValue, Variant endValue, Tizen::Base::String animName);
362
363
364         /**
365          * Adds the %Animation to the ActiveAnimation List.
366          *
367          * @since               2.0
368          *
369          * @return              An error code
370          * @param[in]   formAnimation           %FrameAnimatorFormTransitionAnimation
371          * @param[in]   propAnimation           An object of VisualElementPropertyAnimation
372          * @param[in]   animName                        Unique animation name
373          * @exception   E_SUCCESS                       The method was successful.
374          * @exception   E_SYSTEM                        A system error occurred.
375          * @exception   E_INVALID_ARG           A specified input parameter is invalid.
376          */
377         result AddFrameActiveAnimation(VisualElement* _pVisualElement, FrameAnimatorFormTransitionAnimation _formAnimation,
378                         VisualElementPropertyAnimation* _pPropertyAnimation, IVisualElementAnimationTimingFunction* _pTimingFunction, Tizen::Base::String _animName);
379
380         /**
381          * Gets the %Animation from the FrameActiveAnimation List attached against specified index
382          *
383          * @since               2.0
384          *
385          * @return              An error code
386          * @param[in]   index                           Value at the index to be retrieved
387          * @param[out]  propAnimation           An object of VisualElementPropertyAnimation
388          * @exception   E_SUCCESS                       The method was successful.
389          * @exception   E_SYSTEM                        A system error occurred.
390          * @exception   E_INVALID_ARG           A specified input parameter is invalid.
391          */
392         VisualElementPropertyAnimation* GetFrameActiveAnimationAt(int index);
393
394         /**
395          * Removes the %Animation from the FrameActiveAnimation List at specified index.
396          *
397          * @since               2.0
398          *
399          * @return              An error code
400          * @param[in]   index                           Values at the index to be removed.
401          * @exception   E_SUCCESS                       The method was successful.
402          * @exception   E_SYSTEM                        A system error occurred.
403          * @exception   E_INVALID_ARG           A specified input parameter is invalid.
404          */
405         result RemoveAnimationAt(int index);
406
407         /**
408          * Removes all the %Animation from the FrameActiveAnimation List.
409          *
410          * @since               2.0
411          *
412          * @return              An error code
413          * @exception   E_SUCCESS                       The method was successful.
414          * @exception   E_SYSTEM                        A system error occurred.
415          * @exception   E_INVALID_ARG           A specified input parameter is invalid.
416          */
417         result RemoveAllAnimations(bool deleteAnimation);
418
419         /**
420          * Searches the Frame's children list, for the given form, if present returns true else false.
421          *
422          * @since 2.0
423          *
424          * @return              bool                            True if form is still in the children list, else false.
425          * @exception   E_SUCCESS                       The method was successful.
426          * @exception   E_SYSTEM                        A system error occurred.
427          * @exception   E_INVALID_ARG           A specified input parameter is invalid.
428          */
429         bool IsFormPresent(Tizen::Ui::Controls::Form& pPrevForm) const;
430
431         /**
432          * Removes all the %Animation from the FrameActiveAnimation List.
433          *
434          * @since               2.0
435          *
436          * @return              An error code
437          * @exception   E_SUCCESS                       The method was successful.
438          * @exception   E_SYSTEM                        A system error occurred.
439          * @exception   E_INVALID_ARG           A specified input parameter is invalid.
440          */
441         result ChangeCurrentForm(Tizen::Ui::Controls::Form* pCurrentForm, Tizen::Ui::Controls::Form& nextForm);
442
443         result SetAnimations(void);
444
445         result PrepareCapture(void);
446
447 private:
448         /**
449          * Structure used for storing Frame Active Animations
450          *
451          * @since               2.0
452          */
453         struct FrameActiveAnimation
454         {
455                 VisualElement* pVisualElement;
456                 FrameAnimatorFormTransitionAnimation formTransitionAnimationType;
457                 VisualElementPropertyAnimation* pPropertyAnimation;
458                 IVisualElementAnimationTimingFunction* pTimingFunction;
459                 Tizen::Base::String animName;
460                 FrameActiveAnimation(void)
461                 {
462                         pVisualElement = null;
463                         formTransitionAnimationType = FRAME_ANIMATOR_FORM_TRANSITION_ANIMATION_MAX;
464                         pPropertyAnimation = null;
465                         pTimingFunction = null;
466                         animName = "";
467                 }
468                 ~FrameActiveAnimation(void)
469                 {
470                 }
471                 bool operator ==(const FrameActiveAnimation& frameActiveAnim) const;
472                 bool operator !=(const FrameActiveAnimation& frameActiveAnim) const;
473         };      // FrameActiveAnimation
474
475 private:
476         /**
477          * This is the object of Frame.
478          *
479          * @since               2.0
480          * @remark: This object need not be deleted in FrameAnimator scope
481          */
482         Tizen::Ui::Controls::Frame* __pFrame;
483
484         /**
485          * This is object of FrameAnimator class.
486          *
487          * @since               2.0
488          */
489         FrameAnimator* __pFrameAnimator;
490
491         /**
492          *      The List maintaining the Frame Active Animations.
493          *
494          *      @since          2.0
495          */
496         Tizen::Base::Collection::ArrayListT< FrameActiveAnimation > __frameActiveAnimationList;
497
498         /**
499          * This Callback is called when an animation is repeated.
500          *
501          * @since 2.0
502          */
503         Tizen::Base::Collection::LinkedListT< IFrameAnimatorEventListener* > __frameAnimStatusEventListener;
504
505         /**
506          * This is transactionID for the Form Transition animation
507          *
508          * @since               2.0
509          */
510         int __transactionId;
511
512         /**
513          * The animation status (play / stopped)
514          *
515          * @since               2.0
516          */
517         AnimatorStatus __frameAnimatorStatus;
518
519         /**
520          * CurrentForm object pointer.
521          *
522          * @since               2.0
523          */
524         Tizen::Ui::Controls::Form* __pCurrentForm;
525
526         /**
527          * NextForm object pointer.
528          *
529          * @since               2.0
530          */
531         Tizen::Ui::Controls::Form* __pNextForm;
532
533         /**
534          * The VisualElement of CurrentForm.
535          *
536          * @since 2.0
537          */
538         VisualElement* __pCurrentFormVisualElement;
539
540         /**
541          * The VisualElement of NextForm.
542          *
543          * @since 2.0
544          */
545         VisualElement* __pNextFormVisualElement;
546
547         /**
548          * This is the AnimationFormTransitionEffect used in animation.
549          *
550          * @since               2.0
551          */
552         FrameAnimatorFormTransitionAnimation __animationEffectType;
553
554         /**
555          * This is the AnimationInterpolatorType used in animation.
556          *
557          * @since               2.0
558          */
559         AnimationInterpolatorType __animInterpolatorType;
560
561         /**
562          * This is the duration of animation.
563          *
564          * @since               2.0
565          */
566         long __duration;
567
568         /**
569          * This is input time1 of Bezier Control point.
570          *
571          * @since               2.0
572          */
573         float __firstBezierControlPointsTime;
574
575         /**
576          * This is input value1 of Bezier Control point.
577          *
578          * @since               2.0
579          */
580         float __firstBezierControlPointsValue;
581
582         /**
583          * This is input time2 of Bezier Control point.
584          *
585          * @since               2.0
586          */
587         float __secondBezierControlPointsTime;
588
589         /**
590          * This is input value2 of Bezier Control point.
591          *
592          * @since               2.0
593          */
594         float __secondBezierControlPointsValue;
595
596         /**
597          * This Tizen::Graphics::FloatMatrix4 object to set default transform matrix to current form after animation.
598          *
599          * @since 2.0
600          */
601         Tizen::Graphics::FloatMatrix4 __veDefaultMatrix;
602
603         /**
604          * This Tizen::Graphics::FloatRectangle object to set default bounds to forms after animation.
605          *
606          * @since 2.0
607          */
608         Tizen::Graphics::FloatRectangle __veDefaultBounds;
609
610         /**
611          * This float value to set default opacity to forms after animation.
612          *
613          * @since 2.0
614          */
615         float __veDefaultOpacity;
616
617         /**
618          * Background ControlVisualElement to give a backgroud to Animating forms, so that background forms aren't visible
619          * in case of alpha animation.
620          *
621          * @since 2.0
622          */
623         _ControlVisualElement* __pBgElement;
624         VisualElement* __pCurrentCaptureVisualElement;
625         VisualElement* __pNextCaptureVisualElement;
626         VisualElementSurface* __pDummySurface;
627
628 };          // _FrameAnimatorImpl
629
630 }}}     // Tizen::Ui::Animations
631
632 #endif  //_FUI_ANIM_INTERNAL_FRAME_ANIMATOR_IMPL_H_