modified doxygen comment
[framework/osp/uifw.git] / inc / FUiAnimations.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0/
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        FUiAnimations.h
20  * @brief       This is the header file for the %Animations namespace.
21  *
22  * This header file contains the declarations and descriptions of the %Animations namespace.
23  */
24
25 #ifndef _FUI_ANIMATIONS_H_
26 #define _FUI_ANIMATIONS_H_
27
28 #include <FUiAnimTypes.h>
29 #include <FUiAnimAnimationBase.h>
30 #include <FUiAnimAnimationGroup.h>
31 #include <FUiAnimParallelAnimationGroup.h>
32 #include <FUiAnimSequentialAnimationGroup.h>
33 #include <FUiAnimDimensionAnimation.h>
34 #include <FUiAnimFloatAnimation.h>
35 #include <FUiAnimIntegerAnimation.h>
36 #include <FUiAnimPointAnimation.h>
37 #include <FUiAnimRectangleAnimation.h>
38 #include <FUiAnimRotateAnimation.h>
39 #include <FUiAnimControlAnimator.h>
40 #include <FUiAnimFrameAnimator.h>
41
42 #include <FUiAnimAnimationTransaction.h>
43 #include <FUiAnimIAnimationTransactionEventListener.h>
44
45 #include <FUiAnimIControlAnimatorDetailedEventListener.h>
46 #include <FUiAnimIControlAnimatorEventListener.h>
47 #include <FUiAnimIFrameAnimatorEventListener.h>
48
49 #include <FUiAnimIVisualElementAnimationStatusEventListener.h>
50 #include <FUiAnimIVisualElementAnimationTickEventListener.h>
51 #include <FUiAnimIVisualElementAnimationTimingFunction.h>
52 #include <FUiAnimIVisualElementAnimationValueInterpolator.h>
53
54 #include <FUiAnimVisualElementAnimation.h>
55 #include <FUiAnimVisualElementAnimationGroup.h>
56 #include <FUiAnimVisualElementPropertyAnimation.h>
57 #include <FUiAnimVisualElementValueAnimation.h>
58
59 #include <FUiAnimBezierTimingFunction.h>
60 #include <FUiAnimDiscreteTimingFunction.h>
61 #include <FUiAnimEaseElasticInTimingFunction.h>
62 #include <FUiAnimEaseElasticOutTimingFunction.h>
63 #include <FUiAnimEaseInOutTimingFunction.h>
64 #include <FUiAnimEaseInTimingFunction.h>
65 #include <FUiAnimEaseOutInTimingFunction.h>
66 #include <FUiAnimEaseOutTimingFunction.h>
67 #include <FUiAnimExpInTimingFunction.h>
68 #include <FUiAnimExpOutTimingFunction.h>
69 #include <FUiAnimLinearTimingFunction.h>
70
71 #include <FUiAnimDisplayContext.h>
72 #include <FUiAnimVisualElement.h>
73 #include <FUiAnimVisualElementSurface.h>
74 #include <FUiAnimVisualElementAnimationProvider.h>
75 #include <FUiAnimVisualElementContentProvider.h>
76 #include <FUiAnimIVisualElementAnimationProvider.h>
77 #include <FUiAnimIVisualElementContentProvider.h>
78 #include <FUiAnimIVisualElementEventListener.h>
79
80 namespace Tizen
81 {
82 namespace Ui
83 {
84 /**
85  * @namespace Tizen::Ui::Animations
86  * @brief       This namespace contains the classes for the animation-related functionalities.
87  * @since       2.0
88  *
89  * @remarks     @b Header @b %file: @b \#include @b <FUiAnimations.h> @n
90  *                      @b Library : @b osp-uifw
91  *
92  *
93  *
94  * The %Animations namespace provides animation capabilities for the UI controls.
95  *
96  * For more information on the %Animations namespace features, see <a href="../org.tizen.native.appprogramming/html/guide/ui/animation.htm">Animations Guide</a>.
97  *
98  * The following diagram illustrates the relationships between the classes belonging to the %Animations namespace.
99  * @image html ui_animations_classdiagram.png
100  *
101  * The following examples demonstrate how to use the %Animations namespace.
102  *
103  *      @code
104 // Sample code for Control Animation using ControlAnimator
105 #include <FUi.h>
106 #include <FUiAnimations.h>
107
108 using namespace Tizen::Ui;
109 using namespace Tizen::Ui::Controls;
110 using namespace Tizen::Ui::Animations;
111 using namespace Tizen::Graphics;
112
113 class AnimationSample
114         : public Tizen::Ui::Controls::Form
115         , public Tizen::Ui::IActionEventListener
116 {
117 public:
118         virtual result OnInitializing(void);
119         virtual void OnActionPerformed(const Tizen::Ui::Control& source, int actionId);
120
121 protected:
122         static const int ID_BUTTON = 101;
123         Tizen::Ui::Controls::Button *__pButton;
124 };
125
126 result
127 AnimationSample::OnInitializing(void)
128 {
129         result r = E_SUCCESS;
130
131         // Creates an instance of Button
132         __pButton = new Button();
133         __pButton->Construct(Rectangle(10, 200, 460, 100));
134         __pButton->SetText(L"Start animation");
135         __pButton->SetActionId(ID_BUTTON);
136         __pButton->AddActionEventListener(*this);
137         AddControl(__pButton);
138
139         return r;
140 }
141
142 void
143 AnimationSample::OnActionPerformed(const Control& source, int actionId)
144 {
145         switch(actionId)
146         {
147         case ID_BUTTON:
148                 {
149                         // Starts an animation
150                         result r = E_SUCCESS;
151
152                         ControlAnimator* pButtonAnimator = __pButton->GetControlAnimator();
153                         Point startPos = __pButton->GetPosition();
154                         Point endPos(startPos.x, startPos.y + 200);
155                         PointAnimation pointAnimation(startPos,
156                                                                                   endPos,
157                                                                                   2000,
158                                                                                   ANIMATION_INTERPOLATOR_LINEAR);
159
160                         pointAnimation.SetAutoReverseEnabled(true);
161
162                         r = pButtonAnimator->StartUserAnimation(ANIMATION_TARGET_POSITION, pointAnimation);
163                         if (IsFailed(r))
164                         {
165                                 AppLog("Start Animation on Button Failed.\n");
166                                 return;
167                         }
168                 }
169                 break;
170         }
171 }
172  *      @endcode
173  *
174  *      @code
175 // Sample code for Form Transition Animation using FrameAnimator
176 #include <FUi.h>
177 #include <FUiAnimations.h>
178
179 using namespace Tizen::App;
180 using namespace Tizen::Ui;
181 using namespace Tizen::Ui::Controls;
182 using namespace Tizen::Ui::Animations;
183
184 bool
185 FrameAnimatorSample::OnAppInitializing(AppRegistry& appRegistry)
186 {
187         // Creates instances of Form
188         Form1 *pForm1 = new Form1();
189         pForm1->Initialize();
190
191         Form2* pForm2 = new Form2();
192         pForm2->Initialize();
193
194         // Adds forms to the frame
195         Frame *pFrame = GetAppFrame()->GetFrame();
196         pFrame->AddControl(pForm1);
197         pFrame->AddControl(pForm2);
198
199         // Sets the current form
200         pFrame->SetCurrentForm(pForm1);
201
202         // Display the form
203         pForm1->Invalidate();
204
205         return true;
206 }
207
208 // Transition from Form1 to Form2
209 void
210 Form1::OnActionPerformed(const Control& source, int actionId)
211 {
212         switch(actionId)
213         {
214         case ID_FOOTER_BUTTON_TRANSIT:
215                 {
216                         result r = E_SUCCESS;
217
218                         Frame *pFrame = UiApp::GetInstance()->GetAppFrame()->GetFrame();
219                         FrameAnimator *pFrameAnimator = pFrame->GetFrameAnimator();
220
221                         Form *nextForm = static_cast<Form*>(pFrame->GetControl(L"Form2"));
222
223                         if(pFrameAnimator->GetStatus() == ANIMATOR_STATUS_STOPPED)
224                         {
225                                 pFrameAnimator->SetFormTransitionAnimation (FRAME_ANIMATOR_FORM_TRANSITION_ANIMATION_TRANSLATE_LEFT,
226                                                                                                                         1000,
227                                                                                                                         ANIMATION_INTERPOLATOR_LINEAR );
228                                 r = pFrameAnimator->SetCurrentForm (nextForm);
229                                 if (IsFailed(r))
230                                 {
231                                         AppLog("SetCurrentForm on the Form2 Failed.\n");
232                                         return;
233                                 }
234                         }
235                 }
236                 break;
237         default:
238                 break;
239         }
240 }
241
242 // Transition from Form2 to Form1
243 void
244 Form2::OnActionPerformed(const Control& source, int actionId)
245 {
246         switch(actionId)
247         {
248         case ID_FOOTER_BUTTON_TRANSIT:
249                 {
250                         result r = E_SUCCESS;
251
252                         Frame *pFrame = UiApp::GetInstance()->GetAppFrame()->GetFrame();
253                         FrameAnimator *pFrameAnimator = pFrame->GetFrameAnimator();
254
255                         Form *nextForm = static_cast<Form*>(pFrame->GetControl(L"Form1"));
256                         if(pFrameAnimator->GetStatus() == ANIMATOR_STATUS_STOPPED)
257                         {
258                                 pFrameAnimator->SetFormTransitionAnimation(FRAME_ANIMATOR_FORM_TRANSITION_ANIMATION_TRANSLATE_RIGHT,
259                                                                                                                    1000,
260                                                                                                                    ANIMATION_INTERPOLATOR_LINEAR );
261                                 r = pFrameAnimator->SetCurrentForm (nextForm);
262                                 if (IsFailed(r))
263                                 {
264                                         AppLog("SetCurrentForm on the Form1 Failed.\n");
265                                         return;
266                                 }
267                         }
268                 }
269                 break;
270         default:
271                 break;
272         }
273 }
274  *      @endcode
275  *
276  *      @code
277  // Sample code for VisualElement and VisualElementAnimation
278 #include <FApp.h>
279 #include <FUi.h>
280 #include <FUiAnimations.h>
281
282 using namespace Tizen::Ui::Animations;
283 using namespace Tizen::Ui::Controls;
284 using namespace Tizen::Graphics;
285
286 class VisualElementSample
287         : public Tizen::Ui::Controls::Form
288         , public Tizen::Ui::IActionEventListener
289         , public Tizen::Ui::Animations::VisualElementContentProvider
290 {
291 public:
292         virtual result OnInitializing(void);
293         virtual result OnTerminating(void);
294
295         virtual void OnActionPerformed(const Tizen::Ui::Control& source, int actionId);
296
297         virtual void DrawContent(Tizen::Ui::Animations::VisualElement& target, Tizen::Graphics::Canvas& canvas);
298
299 private:
300         static const int ID_FOOTER_START_ANIMATION = 101;
301
302         Tizen::Ui::Animations::VisualElement* __pRect;
303 };
304
305 result
306 VisualElementSample::OnInitializing(void)
307 {
308         __pRect = new VisualElement();
309         __pRect->Construct();
310         __pRect->SetName(L"Rect");
311         __pRect->SetBounds(FloatRectangle(50.0f, 50.0f, 200.0f, 200.0f));
312         __pRect->SetShowState(true);
313         __pRect->SetContentProvider(this);
314
315         GetVisualElement()->AttachChild(__pRect);
316         __pRect->InvalidateRectangle(null);
317
318         return E_SUCCESS;
319 }
320
321 result
322 VisualElementSample::OnTerminating(void)
323 {
324         __pRect->Destroy();
325
326         return E_SUCCESS;
327 }
328
329 void
330 VisualElementSample::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
331 {
332         switch(actionId)
333         {
334         case ID_FOOTER_START_ANIMATION:
335                 {
336                         VisualElementPropertyAnimation* pAnimation = new VisualElementPropertyAnimation();
337                         pAnimation->SetPropertyName(L"opacity");
338                         pAnimation->SetStartValue(1.0f);
339                         pAnimation->SetEndValue(0.0f);
340                         pAnimation->SetDuration(500);
341                         pAnimation->SetAutoReverseEnabled(true);
342
343                         __pRect->AddAnimation(*pAnimation);
344                         delete pAnimation;
345                 }
346                 break;
347
348         default:
349                 break;
350         }
351 }
352
353 void
354 VisualElementSample::DrawContent(Tizen::Ui::Animations::VisualElement& target, Tizen::Graphics::Canvas& canvas)
355 {
356         if (target.GetName() == L"Rect")
357         {
358                 canvas.FillRectangle(Color::GetColor(COLOR_ID_WHITE), Rectangle(0, 0, 200, 200));
359         }
360 }
361  *      @endcode
362  *
363  *
364  *
365  */
366
367 namespace Animations
368 {
369 };
370
371 } } // Tizen::Ui
372
373 #endif // _FUI_ANIMATIONS_H_