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 "SamplePointAnimation.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 SamplePointAnimation::SamplePointAnimation(AnimationForm& animationForm)
27 : AnimationManager(animationForm)
35 SamplePointAnimation::~SamplePointAnimation(void)
40 SamplePointAnimation::Initialize(void)
44 __pButton1 = new (std::nothrow) Button();
45 __pButton1->Construct(Rectangle(0+offset,0+offset,__buttonSize,__buttonSize),L"I");
46 __pAnimationForm->AddControl(*__pButton1);
48 __pButton2 = new (std::nothrow) Button();
49 __pButton2->Construct(Rectangle(__clientSize.width-__buttonSize-offset,0+offset,__buttonSize,__buttonSize),L"II");
50 __pAnimationForm->AddControl(*__pButton2);
52 __pButton3 = new (std::nothrow) Button();
53 __pButton3->Construct(Rectangle(0+offset,__clientSize.height-__buttonSize-offset,__buttonSize,__buttonSize),L"III");
54 __pAnimationForm->AddControl(*__pButton3);
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);
62 SamplePointAnimation::PlayAnimation(void)
69 Point controlPosition1 = __pButton1->GetPosition();
70 Point controlPosition2 = __pButton2->GetPosition();
71 Point controlPosition3 = __pButton3->GetPosition();
72 Point controlPosition4 = __pButton4->GetPosition();
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);
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);
88 //Initialize Animation
89 if (controlPosition1 == finalPosition1)
91 pointAnimation1 = PointAnimation(finalPosition1,Point(0+offset,0+offset),1000,ANIMATION_INTERPOLATOR_LINEAR);
95 pointAnimation1 = PointAnimation(Point(0+offset,0+offset),finalPosition1,1000,ANIMATION_INTERPOLATOR_LINEAR);
97 AnimationManager::CheckAnimationSuccessStatus(pointAnimation1);
98 AnimationManager::InitializeAnimationSettings(pointAnimation1);
100 if (controlPosition2 == finalPosition2)
102 pointAnimation2 = PointAnimation(finalPosition2,Point(__clientSize.width-__buttonSize-offset,0+offset),1000,ANIMATION_INTERPOLATOR_LINEAR);
106 pointAnimation2 = PointAnimation(Point(__clientSize.width-__buttonSize-offset,0+offset),finalPosition2,1000,ANIMATION_INTERPOLATOR_LINEAR);
108 AnimationManager::CheckAnimationSuccessStatus(pointAnimation2);
109 AnimationManager::InitializeAnimationSettings(pointAnimation2);
111 if (controlPosition3 == finalPosition3)
113 pointAnimation3 = PointAnimation(finalPosition3,Point(0+offset,__clientSize.height-__buttonSize-offset),1000,ANIMATION_INTERPOLATOR_LINEAR);
117 pointAnimation3 = PointAnimation(Point(0+offset,__clientSize.height-__buttonSize-offset),finalPosition3,1000,ANIMATION_INTERPOLATOR_LINEAR);
119 AnimationManager::CheckAnimationSuccessStatus(pointAnimation3);
120 AnimationManager::InitializeAnimationSettings(pointAnimation3);
122 if (controlPosition4 == finalPosition4)
124 pointAnimation4 = PointAnimation(finalPosition4,Point(__clientSize.width-__buttonSize-offset,__clientSize.height-__buttonSize-offset),1000,ANIMATION_INTERPOLATOR_LINEAR);
128 pointAnimation4 = PointAnimation(Point(__clientSize.width-__buttonSize-offset,__clientSize.height-__buttonSize-offset),finalPosition4,1000,ANIMATION_INTERPOLATOR_LINEAR);
130 AnimationManager::CheckAnimationSuccessStatus(pointAnimation4);
131 AnimationManager::InitializeAnimationSettings(pointAnimation4);
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);
144 r = pAnimator1->StartUserAnimation(ANIMATION_TARGET_POSITION,pointAnimation1);
145 AnimationManager::CheckAnimationSuccessStatus(r,L"StartAnimation");
147 r = pAnimator2->StartUserAnimation(ANIMATION_TARGET_POSITION,pointAnimation2);
148 AnimationManager::CheckAnimationSuccessStatus(r,L"StartAnimation");
150 r = pAnimator3->StartUserAnimation(ANIMATION_TARGET_POSITION,pointAnimation3);
151 AnimationManager::CheckAnimationSuccessStatus(r,L"StartAnimation");
153 r = pAnimator4->StartUserAnimation(ANIMATION_TARGET_POSITION,pointAnimation4);
154 AnimationManager::CheckAnimationSuccessStatus(r,L"StartAnimation");
158 SamplePointAnimation::StopAnimation(void)
160 result r = E_SUCCESS;
162 for (int i=0; i<__pAnimationForm->GetControlCount(); ++i)
164 Control* pControl = __pAnimationForm->GetControl(i);
165 ControlAnimator* pAnimator = pControl->GetControlAnimator();
166 AnimationManager::CheckAnimatorSuccessStatus(*pAnimator);
168 if (pAnimator->GetStatus() == ANIMATOR_STATUS_PLAYING)
170 r = pAnimator->StopAnimation(ANIMATION_TRIGGER_USER);
171 CheckAnimationSuccessStatus(r,L"StopAnimation");