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 "SampleTransactionSetAnimation.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 SampleTransactionSetAnimation::SampleTransactionSetAnimation(AnimationForm& animationForm)
27 : AnimationManager(animationForm)
36 SampleTransactionSetAnimation::~SampleTransactionSetAnimation(void)
41 SampleTransactionSetAnimation::Initialize(void)
45 __pButton1 = new (std::nothrow) Button();
46 __pButton1->Construct(Rectangle(0+offset,0+offset,__buttonSize,__buttonSize),L"I");
47 __pButton1->SetColor(BUTTON_STATUS_NORMAL,Color::GetColor(COLOR_ID_RED));
48 __pAnimationForm->AddControl(*__pButton1);
50 __pButton2 = new (std::nothrow) Button();
51 __pButton2->Construct(Rectangle(__clientSize.width-__buttonSize-offset,0+offset,__buttonSize,__buttonSize),L"II");
52 __pButton2->SetColor(BUTTON_STATUS_NORMAL,Color::GetColor(COLOR_ID_CYAN));
53 __pAnimationForm->AddControl(*__pButton2);
55 __pButton3 = new (std::nothrow) Button();
56 __pButton3->Construct(Rectangle(__clientCenter.x,__clientCenter.y,__buttonSize,__buttonSize),L"III");
57 __pButton3->SetColor(BUTTON_STATUS_NORMAL,Color::GetColor(COLOR_ID_YELLOW));
58 __pAnimationForm->AddControl(*__pButton3);
60 __pButton4 = new (std::nothrow) Button();
61 __pButton4->Construct(Rectangle(0+offset,__clientSize.height-__buttonSize-offset,__buttonSize,__buttonSize),L"IV");
62 __pButton4->SetColor(BUTTON_STATUS_NORMAL,Color::GetColor(COLOR_ID_BLUE));
63 __pAnimationForm->AddControl(*__pButton4);
65 __pButton5 = new (std::nothrow) Button();
66 __pButton5->Construct(Rectangle(__clientSize.width-__buttonSize-offset,__clientSize.height-__buttonSize-offset,__buttonSize,__buttonSize),L"V");
67 __pButton5->SetColor(BUTTON_STATUS_NORMAL,Color::GetColor(COLOR_ID_GREEN));
68 __pAnimationForm->AddControl(*__pButton5);
72 SampleTransactionSetAnimation::PlayAnimation(void)
78 Point controlPosition1 = __pButton1->GetPosition();
79 Point controlPosition2 = __pButton2->GetPosition();
80 Point controlPosition4 = __pButton4->GetPosition();
81 Point controlPosition5 = __pButton5->GetPosition();
83 Point finalPosition1 = Point(__clientSize.width-__buttonSize-offset,0+offset);
84 Point finalPosition2 = Point(__clientSize.width-__buttonSize-offset,__clientSize.height-__buttonSize-offset);
85 Point finalPosition4 = Point(0+offset,0+offset);
86 Point finalPosition5 = Point(0+offset,__clientSize.height-__buttonSize-offset);
88 PointAnimation pointAnimation1(__clientCenter,__clientCenter,1000,ANIMATION_INTERPOLATOR_LINEAR);
89 AnimationManager::CheckAnimationSuccessStatus(pointAnimation1);
90 PointAnimation pointAnimation2(__clientCenter,__clientCenter,1000,ANIMATION_INTERPOLATOR_LINEAR);
91 AnimationManager::CheckAnimationSuccessStatus(pointAnimation2);
92 PointAnimation pointAnimation4(__clientCenter,__clientCenter,1000,ANIMATION_INTERPOLATOR_LINEAR);
93 AnimationManager::CheckAnimationSuccessStatus(pointAnimation4);
94 PointAnimation pointAnimation5(__clientCenter,__clientCenter,1000,ANIMATION_INTERPOLATOR_LINEAR);
95 AnimationManager::CheckAnimationSuccessStatus(pointAnimation5);
97 if (AnimationTransaction::GetStatus(__transactionId) == ANIMATION_TRANSACTION_STATUS_STOPPED)
99 //Initialize Animation
100 if (controlPosition1 == finalPosition1)
102 pointAnimation1 = PointAnimation(Point(__clientSize.width-__buttonSize-offset,0+offset),Point(0+offset,0+offset),1000,ANIMATION_INTERPOLATOR_LINEAR);
106 pointAnimation1 = PointAnimation(Point(0+offset,0+offset),Point(__clientSize.width-__buttonSize-offset,0+offset),1000,ANIMATION_INTERPOLATOR_LINEAR);
108 AnimationManager::CheckAnimationSuccessStatus(pointAnimation1);
109 AnimationManager::InitializeAnimationSettings(pointAnimation1);
111 if (controlPosition2 == finalPosition2)
113 pointAnimation2 = PointAnimation(Point(__clientSize.width-__buttonSize-offset,__clientSize.height-__buttonSize-offset),Point(__clientSize.width-__buttonSize-offset,0+offset),1000,ANIMATION_INTERPOLATOR_LINEAR);
117 pointAnimation2 = PointAnimation(Point(__clientSize.width-__buttonSize-offset,0+offset),Point(__clientSize.width-__buttonSize-offset,__clientSize.height-__buttonSize-offset),1000,ANIMATION_INTERPOLATOR_LINEAR);
119 AnimationManager::CheckAnimationSuccessStatus(pointAnimation2);
120 AnimationManager::InitializeAnimationSettings(pointAnimation2);
122 if (controlPosition4 == finalPosition4)
124 pointAnimation4 = PointAnimation(Point(0+offset,0+offset),Point(0+offset,__clientSize.height-__buttonSize-offset),1000,ANIMATION_INTERPOLATOR_LINEAR);
128 pointAnimation4 = PointAnimation(Point(0+offset,__clientSize.height-__buttonSize-offset),Point(0+offset,0+offset),1000,ANIMATION_INTERPOLATOR_LINEAR);
130 AnimationManager::CheckAnimationSuccessStatus(pointAnimation4);
131 AnimationManager::InitializeAnimationSettings(pointAnimation4);
133 if (controlPosition5 == finalPosition5)
135 pointAnimation5 = PointAnimation(Point(0+offset,__clientSize.height-__buttonSize-offset),Point(__clientSize.width-__buttonSize-offset,__clientSize.height-__buttonSize-offset),1000,ANIMATION_INTERPOLATOR_LINEAR);
139 pointAnimation5 = PointAnimation(Point(__clientSize.width-__buttonSize-offset,__clientSize.height-__buttonSize-offset),Point(0+offset,__clientSize.height-__buttonSize-offset),1000,ANIMATION_INTERPOLATOR_LINEAR);
141 AnimationManager::CheckAnimationSuccessStatus(pointAnimation5);
142 AnimationManager::InitializeAnimationSettings(pointAnimation5);
144 RotateAnimation rotateAnimation3(0,360,1000,ANIMATION_INTERPOLATOR_LINEAR);
145 AnimationManager::CheckAnimationSuccessStatus(rotateAnimation3);
146 AnimationManager::InitializeAnimationSettings(rotateAnimation3);
148 r = rotateAnimation3.SetAnchor(0.5,0.5);
149 AnimationManager::CheckAnimationSuccessStatus(r,L"SetAnchor");
151 ControlAnimator* pAnimator1 = __pButton1->GetControlAnimator();
152 AnimationManager::CheckAnimatorSuccessStatus(*pAnimator1);
153 ControlAnimator* pAnimator2 = __pButton2->GetControlAnimator();
154 AnimationManager::CheckAnimatorSuccessStatus(*pAnimator2);
155 ControlAnimator* pAnimator3 = __pButton3->GetControlAnimator();
156 AnimationManager::CheckAnimatorSuccessStatus(*pAnimator3);
157 ControlAnimator* pAnimator4 = __pButton4->GetControlAnimator();
158 AnimationManager::CheckAnimatorSuccessStatus(*pAnimator4);
159 ControlAnimator* pAnimator5 = __pButton5->GetControlAnimator();
160 AnimationManager::CheckAnimatorSuccessStatus(*pAnimator5);
162 r = AnimationTransaction::Begin(__transactionId);
163 CheckAnimationSuccessStatus(r,L"BeginTransaction");
165 r = pAnimator1->StartUserAnimation(ANIMATION_TARGET_POSITION,pointAnimation1);
166 AnimationManager::CheckAnimationSuccessStatus(r,L"StartAnimation");
168 r = pAnimator2->StartUserAnimation(ANIMATION_TARGET_POSITION,pointAnimation2);
169 AnimationManager::CheckAnimationSuccessStatus(r,L"StartAnimation");
171 r = pAnimator3->StartUserAnimation(ANIMATION_TARGET_ROTATION,rotateAnimation3);
172 AnimationManager::CheckAnimationSuccessStatus(r,L"StartAnimation");
174 r = pAnimator4->StartUserAnimation(ANIMATION_TARGET_POSITION,pointAnimation4);
175 AnimationManager::CheckAnimationSuccessStatus(r,L"StartAnimation");
177 r = pAnimator5->StartUserAnimation(ANIMATION_TARGET_POSITION,pointAnimation5);
178 AnimationManager::CheckAnimationSuccessStatus(r,L"StartAnimation");
180 r = AnimationTransaction::Commit();
181 CheckAnimationSuccessStatus(r,L"EndTransaction");
186 SampleTransactionSetAnimation::StopAnimation(void)
188 result result = E_SUCCESS;
190 if (AnimationTransaction::GetStatus(__transactionId) == ANIMATION_TRANSACTION_STATUS_PLAYING)
192 result = AnimationTransaction::Stop(__transactionId);
193 CheckAnimationSuccessStatus(result,L"EndTransaction");