Tizen 2.1 base
[sdk/ide/native-sample.git] / samples / native / cpp / Sample / Tizen C++ / UiControlAnimator / UiControlAnimator / project / src / SamplePointAnimation.cpp
1 //
2 // Tizen C++ SDK
3 // Copyright (c) 2012 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://www.tizenopensource.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 #include "SamplePointAnimation.h"
19 #include "AnimationForm.h"
20
21 using namespace Osp::Graphics;
22 using namespace Osp::Ui;
23 using namespace Osp::Ui::Controls;
24 using namespace Osp::Ui::Animations;
25
26 SamplePointAnimation::SamplePointAnimation(AnimationForm& animationForm)
27         : AnimationManager(animationForm)
28         , __pButton1(null)
29         , __pButton2(null)
30         , __pButton3(null)
31         , __pButton4(null)
32 {
33 }
34
35 SamplePointAnimation::~SamplePointAnimation(void)
36 {
37 }
38
39 void
40 SamplePointAnimation::Initialize(void)
41 {
42         int offset = 50;
43
44         __pButton1 = new (std::nothrow) Button();
45         __pButton1->Construct(Rectangle(0+offset,0+offset,__buttonSize,__buttonSize),L"I");
46         __pAnimationForm->AddControl(*__pButton1);
47
48         __pButton2 = new (std::nothrow) Button();
49         __pButton2->Construct(Rectangle(__clientSize.width-__buttonSize-offset,0+offset,__buttonSize,__buttonSize),L"II");
50         __pAnimationForm->AddControl(*__pButton2);
51
52         __pButton3 = new (std::nothrow) Button();
53         __pButton3->Construct(Rectangle(0+offset,__clientSize.height-__buttonSize-offset,__buttonSize,__buttonSize),L"III");
54         __pAnimationForm->AddControl(*__pButton3);
55
56         __pButton4 = new (std::nothrow) Button();
57         __pButton4->Construct(Rectangle(__clientSize.width-__buttonSize-offset,__clientSize.height-__buttonSize-offset,__buttonSize,__buttonSize),L"IV");
58         __pAnimationForm->AddControl(*__pButton4);
59 }
60
61 void
62 SamplePointAnimation::PlayAnimation(void)
63 {
64         result r = E_SUCCESS;
65
66         int offset = 50;
67         int delta = 10;
68
69         Point controlPosition1 = __pButton1->GetPosition();
70         Point controlPosition2 = __pButton2->GetPosition();
71         Point controlPosition3 = __pButton3->GetPosition();
72         Point controlPosition4 = __pButton4->GetPosition();
73
74         Point finalPosition1 = Point(__clientCenter.x-__buttonSize/2-delta,__clientCenter.y-__buttonSize/2-delta);
75         Point finalPosition2 = Point(__clientCenter.x+__buttonSize/2+delta,__clientCenter.y-__buttonSize/2-delta);
76         Point finalPosition3 = Point(__clientCenter.x-__buttonSize/2-delta,__clientCenter.y+__buttonSize/2+delta);
77         Point finalPosition4 = Point(__clientCenter.x+__buttonSize/2+delta,__clientCenter.y+__buttonSize/2+delta);
78
79         PointAnimation pointAnimation1(__clientCenter,__clientCenter,1000,ANIMATION_INTERPOLATOR_LINEAR);
80         AnimationManager::CheckAnimationSuccessStatus(pointAnimation1);
81         PointAnimation pointAnimation2(__clientCenter,__clientCenter,1000,ANIMATION_INTERPOLATOR_LINEAR);
82         AnimationManager::CheckAnimationSuccessStatus(pointAnimation2);
83         PointAnimation pointAnimation3(__clientCenter,__clientCenter,1000,ANIMATION_INTERPOLATOR_LINEAR);
84         AnimationManager::CheckAnimationSuccessStatus(pointAnimation3);
85         PointAnimation pointAnimation4(__clientCenter,__clientCenter,1000,ANIMATION_INTERPOLATOR_LINEAR);
86         AnimationManager::CheckAnimationSuccessStatus(pointAnimation4);
87
88         //Initialize Animation
89         if (controlPosition1 == finalPosition1)
90         {
91                 pointAnimation1 = PointAnimation(finalPosition1,Point(0+offset,0+offset),1000,ANIMATION_INTERPOLATOR_LINEAR);
92         }
93         else
94         {
95                 pointAnimation1 = PointAnimation(Point(0+offset,0+offset),finalPosition1,1000,ANIMATION_INTERPOLATOR_LINEAR);
96         }
97         AnimationManager::CheckAnimationSuccessStatus(pointAnimation1);
98         AnimationManager::InitializeAnimationSettings(pointAnimation1);
99
100         if (controlPosition2 == finalPosition2)
101         {
102                 pointAnimation2 = PointAnimation(finalPosition2,Point(__clientSize.width-__buttonSize-offset,0+offset),1000,ANIMATION_INTERPOLATOR_LINEAR);
103         }
104         else
105         {
106                 pointAnimation2 = PointAnimation(Point(__clientSize.width-__buttonSize-offset,0+offset),finalPosition2,1000,ANIMATION_INTERPOLATOR_LINEAR);
107         }
108         AnimationManager::CheckAnimationSuccessStatus(pointAnimation2);
109         AnimationManager::InitializeAnimationSettings(pointAnimation2);
110
111         if (controlPosition3 == finalPosition3)
112         {
113                 pointAnimation3 = PointAnimation(finalPosition3,Point(0+offset,__clientSize.height-__buttonSize-offset),1000,ANIMATION_INTERPOLATOR_LINEAR);
114         }
115         else
116         {
117                 pointAnimation3 = PointAnimation(Point(0+offset,__clientSize.height-__buttonSize-offset),finalPosition3,1000,ANIMATION_INTERPOLATOR_LINEAR);
118         }
119         AnimationManager::CheckAnimationSuccessStatus(pointAnimation3);
120         AnimationManager::InitializeAnimationSettings(pointAnimation3);
121
122         if (controlPosition4 == finalPosition4)
123         {
124                 pointAnimation4 = PointAnimation(finalPosition4,Point(__clientSize.width-__buttonSize-offset,__clientSize.height-__buttonSize-offset),1000,ANIMATION_INTERPOLATOR_LINEAR);
125         }
126         else
127         {
128                 pointAnimation4 = PointAnimation(Point(__clientSize.width-__buttonSize-offset,__clientSize.height-__buttonSize-offset),finalPosition4,1000,ANIMATION_INTERPOLATOR_LINEAR);
129         }
130         AnimationManager::CheckAnimationSuccessStatus(pointAnimation4);
131         AnimationManager::InitializeAnimationSettings(pointAnimation4);
132
133         //Initialize Animator
134         ControlAnimator* pAnimator1 = __pButton1->GetControlAnimator();
135         AnimationManager::CheckAnimatorSuccessStatus(*pAnimator1);
136         ControlAnimator* pAnimator2 = __pButton2->GetControlAnimator();
137         AnimationManager::CheckAnimatorSuccessStatus(*pAnimator2);
138         ControlAnimator* pAnimator3 = __pButton3->GetControlAnimator();
139         AnimationManager::CheckAnimatorSuccessStatus(*pAnimator3);
140         ControlAnimator* pAnimator4 = __pButton4->GetControlAnimator();
141         AnimationManager::CheckAnimatorSuccessStatus(*pAnimator4);
142
143         //Start Animation
144         r = pAnimator1->StartUserAnimation(ANIMATION_TARGET_POSITION,pointAnimation1);
145         AnimationManager::CheckAnimationSuccessStatus(r,L"StartAnimation");
146
147         r = pAnimator2->StartUserAnimation(ANIMATION_TARGET_POSITION,pointAnimation2);
148         AnimationManager::CheckAnimationSuccessStatus(r,L"StartAnimation");
149
150         r = pAnimator3->StartUserAnimation(ANIMATION_TARGET_POSITION,pointAnimation3);
151         AnimationManager::CheckAnimationSuccessStatus(r,L"StartAnimation");
152
153         r = pAnimator4->StartUserAnimation(ANIMATION_TARGET_POSITION,pointAnimation4);
154         AnimationManager::CheckAnimationSuccessStatus(r,L"StartAnimation");
155 }
156
157 void
158 SamplePointAnimation::StopAnimation(void)
159 {
160         result r = E_SUCCESS;
161
162         for (int i=0; i<__pAnimationForm->GetControlCount(); ++i)
163         {
164                 Control* pControl = __pAnimationForm->GetControl(i);
165                 ControlAnimator* pAnimator = pControl->GetControlAnimator();
166                 AnimationManager::CheckAnimatorSuccessStatus(*pAnimator);
167
168                 if (pAnimator->GetStatus() == ANIMATOR_STATUS_PLAYING)
169                 {
170                         r = pAnimator->StopAnimation(ANIMATION_TRIGGER_USER);
171                         CheckAnimationSuccessStatus(r,L"StopAnimation");
172                 }
173         }
174 }