3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.tizenopensource.org/license
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.
18 #include "SampleCustomImplicitAnimation.h"
19 #include "AnimationForm.h"
21 using namespace Osp::Graphics;
22 using namespace Osp::Ui;
23 using namespace Osp::Ui::Controls;
24 using namespace Osp::Ui::Animations;
26 SampleCustomImplicitAnimation::SampleCustomImplicitAnimation(AnimationForm& animationForm)
27 : AnimationManager(animationForm)
35 SampleCustomImplicitAnimation::~SampleCustomImplicitAnimation(void)
40 SampleCustomImplicitAnimation::Initialize(void)
43 int buttonWidth = __buttonSize + offset;
44 int buttonHeight = __buttonSize/2;
46 __pButton1 = new (std::nothrow) Button();
47 __pButton1->Construct(Rectangle(0+offset,0+offset,buttonWidth,buttonHeight),L"Position");
48 __pAnimationForm->AddControl(*__pButton1);
50 __pButton2 = new (std::nothrow) Button();
51 __pButton2->Construct(Rectangle(0+offset,0+3*offset,buttonWidth,buttonHeight),L"Size");
52 __pAnimationForm->AddControl(*__pButton2);
54 __pButton3 = new (std::nothrow) Button();
55 __pButton3->Construct(Rectangle(0+offset,0+5*offset,buttonWidth,buttonHeight),L"Bounds");
56 __pAnimationForm->AddControl(*__pButton3);
58 __pButton4 = new (std::nothrow) Button();
59 __pButton4->Construct(Rectangle(0+offset,0+7*offset,buttonWidth,buttonHeight),L"ShowState");
60 __pAnimationForm->AddControl(*__pButton4);
64 SampleCustomImplicitAnimation::PlayAnimation(void)
69 int buttonWidth = __buttonSize + offset;
70 int buttonHeight = __buttonSize/2;
72 Point controlPosition1 = __pButton1->GetPosition();
73 Dimension controlSize2 = __pButton2->GetSize();
74 Rectangle controlBounds3 = __pButton3->GetBounds();
75 bool controlShowState4 = __pButton4->GetShowState();
77 Point finalPosition1 = Point(__clientCenter.x,0+offset);
78 Dimension finalSize2 = Dimension(buttonWidth+offset,buttonWidth-offset-20);
79 Rectangle finalBounds3 = Rectangle(__clientCenter.x,0+5*offset,buttonWidth+offset,buttonWidth-offset-20);
81 PointAnimation pointAnimation1(__clientCenter,__clientCenter,1000,ANIMATION_INTERPOLATOR_LINEAR);
82 AnimationManager::CheckAnimationSuccessStatus(pointAnimation1);
83 DimensionAnimation dimensionAnimation2(Dimension(__buttonSize,__buttonSize),Dimension(__buttonSize,__buttonSize),1000,ANIMATION_INTERPOLATOR_LINEAR);
84 AnimationManager::CheckAnimationSuccessStatus(dimensionAnimation2);
85 RectangleAnimation rectangleAnimation3(Rectangle(0,0,buttonWidth,buttonHeight),Rectangle(__clientCenter.x,0+offset,buttonWidth+offset,buttonHeight+offset-20),1000,ANIMATION_INTERPOLATOR_LINEAR);
86 AnimationManager::CheckAnimationSuccessStatus(rectangleAnimation3);
87 FloatAnimation floatAnimation4(0,0,1000,ANIMATION_INTERPOLATOR_LINEAR);
88 AnimationManager::CheckAnimationSuccessStatus(floatAnimation4);
89 RotateAnimation rotateAnimation(0,0,1000,ANIMATION_INTERPOLATOR_LINEAR);
90 AnimationManager::CheckAnimationSuccessStatus(rotateAnimation);
93 ControlAnimator* pAnimator1 = __pButton1->GetControlAnimator();
94 AnimationManager::CheckAnimatorSuccessStatus(*pAnimator1);
95 ControlAnimator* pAnimator2 = __pButton2->GetControlAnimator();
96 AnimationManager::CheckAnimatorSuccessStatus(*pAnimator2);
97 ControlAnimator* pAnimator3 = __pButton3->GetControlAnimator();
98 AnimationManager::CheckAnimatorSuccessStatus(*pAnimator3);
99 ControlAnimator* pAnimator4 = __pButton4->GetControlAnimator();
100 AnimationManager::CheckAnimatorSuccessStatus(*pAnimator4);
102 // Initialize Animation Group
103 ParallelAnimationGroup animationGroup1;
104 AnimationManager::CheckAnimationSuccessStatus(animationGroup1);
105 ParallelAnimationGroup animationGroup2;
106 AnimationManager::CheckAnimationSuccessStatus(animationGroup2);
107 ParallelAnimationGroup animationGroup3a;
108 AnimationManager::CheckAnimationSuccessStatus(animationGroup3a);
109 ParallelAnimationGroup animationGroup3b;
110 AnimationManager::CheckAnimationSuccessStatus(animationGroup3b);
111 ParallelAnimationGroup animationGroup4;
112 AnimationManager::CheckAnimationSuccessStatus(animationGroup4);
114 //Initialize Animations
115 if (controlPosition1 == finalPosition1)
117 pointAnimation1 = PointAnimation(Point(__clientCenter.x,0+offset),Point(0+offset,0+offset),1000,ANIMATION_INTERPOLATOR_LINEAR);
121 pointAnimation1 = PointAnimation(Point(0+offset,0+offset),Point(__clientCenter.x,0+offset),1000,ANIMATION_INTERPOLATOR_LINEAR);
123 AnimationManager::CheckAnimationSuccessStatus(r,L"SetPosition");
125 if (controlSize2 == finalSize2)
127 dimensionAnimation2 = DimensionAnimation(Dimension(buttonWidth+offset,buttonWidth-offset-20),Dimension(buttonWidth,buttonHeight),1000,ANIMATION_INTERPOLATOR_LINEAR);
131 dimensionAnimation2 = DimensionAnimation(Dimension(buttonWidth,buttonHeight),Dimension(buttonWidth+offset,buttonWidth-offset-20),1000,ANIMATION_INTERPOLATOR_LINEAR);
133 AnimationManager::CheckAnimationSuccessStatus(r,L"SetSize");
135 if (controlBounds3 == finalBounds3)
137 rectangleAnimation3 = RectangleAnimation(Rectangle(__clientCenter.x,0+5*offset,buttonWidth+offset,buttonWidth-offset-20),Rectangle(0+offset,0+5*offset,buttonWidth,buttonHeight),1000,ANIMATION_INTERPOLATOR_LINEAR);
141 rectangleAnimation3 = RectangleAnimation(Rectangle(0+offset,0+5*offset,buttonWidth,buttonHeight),Rectangle(__clientCenter.x,0+5*offset,buttonWidth+offset,buttonWidth-offset-20),1000,ANIMATION_INTERPOLATOR_LINEAR);
143 AnimationManager::CheckAnimationSuccessStatus(r,L"SetBounds");
145 if (controlShowState4 == true)
147 floatAnimation4 = FloatAnimation((1.0),(0.0),1000,ANIMATION_INTERPOLATOR_LINEAR);
151 floatAnimation4 = FloatAnimation((0.0),(1.0),1000,ANIMATION_INTERPOLATOR_LINEAR);
153 AnimationManager::CheckAnimationSuccessStatus(r,L"SetShowState");
155 if (controlPosition1 == finalPosition1 && controlSize2 == finalSize2)
157 rotateAnimation = RotateAnimation(0,360,1000,ANIMATION_INTERPOLATOR_LINEAR);
161 rotateAnimation = RotateAnimation(360,0,1000,ANIMATION_INTERPOLATOR_LINEAR);
163 AnimationManager::CheckAnimationSuccessStatus(rotateAnimation);
164 r = rotateAnimation.SetAnchor(0.5,0.5);
165 AnimationManager::CheckAnimationSuccessStatus(r,L"SetAnchor");
167 //Add Animations to Animation Group
168 r = animationGroup1.AddAnimation(ANIMATION_TARGET_ROTATION,rotateAnimation);
169 AnimationManager::CheckAnimationSuccessStatus(r,L"AddAnimation");
170 r = animationGroup1.AddAnimation(ANIMATION_TARGET_POSITION,pointAnimation1);
171 AnimationManager::CheckAnimationSuccessStatus(r,L"AddAnimation");
173 r = animationGroup2.AddAnimation(ANIMATION_TARGET_ROTATION,rotateAnimation);
174 AnimationManager::CheckAnimationSuccessStatus(r,L"AddAnimation");
175 r = animationGroup2.AddAnimation(ANIMATION_TARGET_SIZE,dimensionAnimation2);
176 AnimationManager::CheckAnimationSuccessStatus(r,L"AddAnimation");
178 r = animationGroup3a.AddAnimation(ANIMATION_TARGET_ROTATION,rotateAnimation);
179 AnimationManager::CheckAnimationSuccessStatus(r,L"AddAnimation");
180 r = animationGroup3a.AddAnimation(ANIMATION_TARGET_POSITION,rectangleAnimation3);
181 AnimationManager::CheckAnimationSuccessStatus(r,L"AddAnimation");
183 r = animationGroup3b.AddAnimation(ANIMATION_TARGET_SIZE,rectangleAnimation3);
184 AnimationManager::CheckAnimationSuccessStatus(r,L"AddAnimation");
186 r = animationGroup4.AddAnimation(ANIMATION_TARGET_ROTATION,rotateAnimation);
187 AnimationManager::CheckAnimationSuccessStatus(r,L"AddAnimation");
188 r = animationGroup4.AddAnimation(ANIMATION_TARGET_ALPHA,floatAnimation4);
189 AnimationManager::CheckAnimationSuccessStatus(r,L"AddAnimation");
192 r = pAnimator1->SetAnimation(ANIMATION_TRIGGER_POSITION_CHANGE,&animationGroup1);
193 AnimationManager::CheckAnimationSuccessStatus(r,L"SetAnimation");
195 r = pAnimator2->SetAnimation(ANIMATION_TRIGGER_SIZE_CHANGE,&animationGroup2);
196 AnimationManager::CheckAnimationSuccessStatus(r,L"SetAnimation");
198 r = pAnimator3->SetAnimation(ANIMATION_TRIGGER_POSITION_CHANGE,&animationGroup3a);
199 AnimationManager::CheckAnimationSuccessStatus(r,L"SetAnimation");
200 r = pAnimator3->SetAnimation(ANIMATION_TRIGGER_SIZE_CHANGE,&animationGroup3b);
201 AnimationManager::CheckAnimationSuccessStatus(r,L"SetAnimation");
203 r = pAnimator4->SetAnimation(ANIMATION_TRIGGER_SHOW_STATE_CHANGE,&animationGroup4);
204 AnimationManager::CheckAnimationSuccessStatus(r,L"SetAnimation");
206 //Start Custom Implicit animation
207 if (controlPosition1 == finalPosition1)
209 r = pAnimator1->SetPosition(Point(0+offset,0+offset));
213 r = pAnimator1->SetPosition(Point(__clientCenter.x,0+offset));
215 AnimationManager::CheckAnimationSuccessStatus(r,L"SetPosition");
217 if (controlSize2 == finalSize2)
219 r = pAnimator2->SetSize(Dimension(buttonWidth,buttonHeight));
223 r = pAnimator2->SetSize(Dimension(buttonWidth+offset,buttonWidth-offset-20));
225 AnimationManager::CheckAnimationSuccessStatus(r,L"SetSize");
227 if (controlBounds3 == finalBounds3)
229 r = pAnimator3->SetBounds(Rectangle(0+offset,0+5*offset,buttonWidth,buttonHeight));
233 r = pAnimator3->SetBounds(Rectangle(__clientCenter.x,0+5*offset,buttonWidth+offset,buttonWidth-offset-20));
235 AnimationManager::CheckAnimationSuccessStatus(r,L"SetBounds");
237 if (controlShowState4 == true)
239 r = pAnimator4->SetShowState(false);
243 r = pAnimator4->SetShowState(true);
245 AnimationManager::CheckAnimationSuccessStatus(r,L"SetShowState");
249 SampleCustomImplicitAnimation::StopAnimation(void)
251 result r = E_SUCCESS;
253 //Initialize Animator
254 ControlAnimator* pAnimator1 = __pButton1->GetControlAnimator();
255 AnimationManager::CheckAnimatorSuccessStatus(*pAnimator1);
256 ControlAnimator* pAnimator2 = __pButton2->GetControlAnimator();
257 AnimationManager::CheckAnimatorSuccessStatus(*pAnimator2);
258 ControlAnimator* pAnimator3 = __pButton3->GetControlAnimator();
259 AnimationManager::CheckAnimatorSuccessStatus(*pAnimator3);
260 ControlAnimator* pAnimator4 = __pButton4->GetControlAnimator();
261 AnimationManager::CheckAnimatorSuccessStatus(*pAnimator4);
263 if (pAnimator1->GetStatus() == ANIMATOR_STATUS_PLAYING)
265 r = pAnimator1->StopAnimation(ANIMATION_TRIGGER_POSITION_CHANGE);
266 CheckAnimationSuccessStatus(r,L"StopAnimation");
268 if (pAnimator2->GetStatus() == ANIMATOR_STATUS_PLAYING)
270 r = pAnimator2->StopAnimation(ANIMATION_TRIGGER_SIZE_CHANGE);
271 CheckAnimationSuccessStatus(r,L"StopAnimation");
273 if (pAnimator3->GetStatus() == ANIMATOR_STATUS_PLAYING)
275 r = pAnimator3->StopAnimation(ANIMATION_TRIGGER_SIZE_CHANGE);
276 CheckAnimationSuccessStatus(r,L"StopAnimation");
278 r = pAnimator3->StopAnimation(ANIMATION_TRIGGER_POSITION_CHANGE);
279 CheckAnimationSuccessStatus(r,L"StopAnimation");
281 if (pAnimator4->GetStatus() == ANIMATOR_STATUS_PLAYING)
283 r = pAnimator4->StopAnimation(ANIMATION_TRIGGER_SHOW_STATE_CHANGE);
284 CheckAnimationSuccessStatus(r,L"StopAnimation");