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 "SamplePanelTransitionAnimation.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 SamplePanelTransitionAnimation::SamplePanelTransitionAnimation(AnimationForm& animationForm)
27 : AnimationManager(animationForm)
28 , __panelCurrentlyVisible(1)
29 , __animationDuration(500)
31 , __pPanelCenter(null)
36 SamplePanelTransitionAnimation::~SamplePanelTransitionAnimation(void)
41 SamplePanelTransitionAnimation::Initialize(void)
43 Rectangle formBounds = __pAnimationForm->GetClientAreaBounds();
45 __pPanelLeft = new (std::nothrow) Panel();
46 __pPanelLeft->Construct(Rectangle(-formBounds.width,0,formBounds.width,formBounds.height));
47 __pPanelLeft->SetBackgroundColor(Color::GetColor(COLOR_ID_RED));
48 __pAnimationForm->AddControl(*__pPanelLeft);
50 __pPanelCenter = new (std::nothrow) Panel();
51 __pPanelCenter->Construct(Rectangle(0,0,formBounds.width,formBounds.height));
52 __pPanelCenter->SetBackgroundColor(Color::GetColor(COLOR_ID_GREEN));
53 __pAnimationForm->AddControl(*__pPanelCenter);
55 __pPanelRight = new (std::nothrow) Panel();
56 __pPanelRight->Construct(Rectangle(formBounds.width,0,formBounds.width,formBounds.height));
57 __pPanelRight->SetBackgroundColor(Color::GetColor(COLOR_ID_BLUE));
58 __pAnimationForm->AddControl(*__pPanelRight);
60 Button* pButtonLeft = new (std::nothrow) Button();
61 pButtonLeft->Construct(Rectangle(50,20,formBounds.width-100,50),L"Panel Left");
62 __pPanelLeft->AddControl(*pButtonLeft);
64 Button* pButtonCenter = new (std::nothrow) Button();
65 pButtonCenter->Construct(Rectangle(50,20,formBounds.width-100,50),L"Panel Center");
66 __pPanelCenter->AddControl(*pButtonCenter);
68 Button* pButtonRight = new (std::nothrow) Button();
69 pButtonRight->Construct(Rectangle(50,20,formBounds.width-100,50),L"Panel Right");
70 __pPanelRight->AddControl(*pButtonRight);
72 __pAnimationForm->RequestRedraw();
76 SamplePanelTransitionAnimation::PlayAnimation(void)
81 SamplePanelTransitionAnimation::StopAnimation(void)
86 SamplePanelTransitionAnimation::TranslatePanelRight(void)
90 if (__pPanelLeft->GetControlAnimator()->GetStatus() == ANIMATOR_STATUS_PLAYING ||
91 __pPanelCenter->GetControlAnimator()->GetStatus() == ANIMATOR_STATUS_PLAYING ||
92 __pPanelRight->GetControlAnimator()->GetStatus() == ANIMATOR_STATUS_PLAYING)
97 if (__panelCurrentlyVisible == 0)
99 Point panelLeftInitialPosition = __pPanelLeft->GetBounds().GetTopLeft();
100 Point panelLeftFinalPosition = panelLeftInitialPosition + Point(100,0);
102 PointAnimation pointAnimationRightEnd(panelLeftInitialPosition,panelLeftFinalPosition,__animationDuration/2,ANIMATION_INTERPOLATOR_LINEAR);
103 pointAnimationRightEnd.SetAutoReverseEnabled(true);
104 AnimationManager::CheckAnimationSuccessStatus(pointAnimationRightEnd);
106 ControlAnimator* pAnimatorLeft = __pPanelLeft->GetControlAnimator();
107 AnimationManager::CheckAnimatorSuccessStatus(*pAnimatorLeft);
109 if (__pPanelLeft->GetControlAnimator()->GetStatus() == ANIMATOR_STATUS_PLAYING)
114 r = pAnimatorLeft->StartUserAnimation(ANIMATION_TARGET_POSITION,pointAnimationRightEnd);
115 AnimationManager::CheckAnimationSuccessStatus(r,L"StartAnimation");
119 __panelCurrentlyVisible--;
121 Point panelLeftInitialPosition = __pPanelLeft->GetBounds().GetTopLeft();
122 Point panelLeftFinalPosition = panelLeftInitialPosition + Point(__pPanelLeft->GetBounds().width,0);
124 Point panelCenterInitialPosition = __pPanelCenter->GetBounds().GetTopLeft();
125 Point panelCenterFinalPosition = panelCenterInitialPosition + Point(__pPanelCenter->GetBounds().width,0);
127 Point panelRightInitialPosition = __pPanelRight->GetBounds().GetTopLeft();
128 Point panelRightFinalPosition = panelRightInitialPosition + Point(__pPanelRight->GetBounds().width,0);
130 //Initialize Animation
131 PointAnimation pointAnimationLeft(panelLeftInitialPosition,panelLeftFinalPosition,__animationDuration,ANIMATION_INTERPOLATOR_LINEAR);
132 AnimationManager::CheckAnimationSuccessStatus(pointAnimationLeft);
134 PointAnimation pointAnimationCenter(panelCenterInitialPosition,panelCenterFinalPosition,__animationDuration,ANIMATION_INTERPOLATOR_LINEAR);
135 AnimationManager::CheckAnimationSuccessStatus(pointAnimationCenter);
137 PointAnimation pointAnimationRight(panelRightInitialPosition,panelRightFinalPosition,__animationDuration,ANIMATION_INTERPOLATOR_LINEAR);
138 AnimationManager::CheckAnimationSuccessStatus(pointAnimationRight);
140 //Initialize Animator
141 ControlAnimator* pAnimatorLeft = __pPanelLeft->GetControlAnimator();
142 AnimationManager::CheckAnimatorSuccessStatus(*pAnimatorLeft);
144 ControlAnimator* pAnimatorCenter = __pPanelCenter->GetControlAnimator();
145 AnimationManager::CheckAnimatorSuccessStatus(*pAnimatorCenter);
147 ControlAnimator* pAnimatorRight = __pPanelRight->GetControlAnimator();
148 AnimationManager::CheckAnimatorSuccessStatus(*pAnimatorRight);
152 r = AnimationTransaction::Begin(id);
153 CheckAnimationSuccessStatus(r,L"BeginTransaction");
156 r = pAnimatorLeft->StartUserAnimation(ANIMATION_TARGET_POSITION,pointAnimationLeft);
157 AnimationManager::CheckAnimationSuccessStatus(r,L"StartAnimation");
159 r = pAnimatorCenter->StartUserAnimation(ANIMATION_TARGET_POSITION,pointAnimationCenter);
160 AnimationManager::CheckAnimationSuccessStatus(r,L"StartAnimation");
162 r = pAnimatorRight->StartUserAnimation(ANIMATION_TARGET_POSITION,pointAnimationRight);
163 AnimationManager::CheckAnimationSuccessStatus(r,L"StartAnimation");
166 r = AnimationTransaction::Commit();
167 CheckAnimationSuccessStatus(r,L"EndTransaction");
172 SamplePanelTransitionAnimation::TranslatePanelLeft(void)
174 result r = E_SUCCESS;
176 if (__pPanelLeft->GetControlAnimator()->GetStatus() == ANIMATOR_STATUS_PLAYING ||
177 __pPanelCenter->GetControlAnimator()->GetStatus() == ANIMATOR_STATUS_PLAYING ||
178 __pPanelRight->GetControlAnimator()->GetStatus() == ANIMATOR_STATUS_PLAYING)
183 if (__panelCurrentlyVisible == 2)
185 Point panelRightInitialPosition = __pPanelRight->GetBounds().GetTopLeft();
186 Point panelRightFinalPosition = panelRightInitialPosition - Point(100,0);
188 PointAnimation pointAnimationRightEnd(panelRightInitialPosition,panelRightFinalPosition,__animationDuration/2,ANIMATION_INTERPOLATOR_LINEAR);
189 pointAnimationRightEnd.SetAutoReverseEnabled(true);
190 AnimationManager::CheckAnimationSuccessStatus(pointAnimationRightEnd);
192 ControlAnimator* pAnimatorRight = __pPanelRight->GetControlAnimator();
193 AnimationManager::CheckAnimatorSuccessStatus(*pAnimatorRight);
195 if (__pPanelRight->GetControlAnimator()->GetStatus() == ANIMATOR_STATUS_PLAYING)
200 r = pAnimatorRight->StartUserAnimation(ANIMATION_TARGET_POSITION,pointAnimationRightEnd);
201 AnimationManager::CheckAnimationSuccessStatus(r,L"StartAnimation");
205 __panelCurrentlyVisible++;
207 Point panelLeftInitialPosition = __pPanelLeft->GetBounds().GetTopLeft();
208 Point panelLeftFinalPosition = panelLeftInitialPosition - Point(__pPanelLeft->GetBounds().width,0);
210 Point panelCenterInitialPosition = __pPanelCenter->GetBounds().GetTopLeft();
211 Point panelCenterFinalPosition = panelCenterInitialPosition - Point(__pPanelCenter->GetBounds().width,0);
213 Point panelRightInitialPosition = __pPanelRight->GetBounds().GetTopLeft();
214 Point panelRightFinalPosition = panelRightInitialPosition - Point(__pPanelRight->GetBounds().width,0);
216 //Initialize Animation
217 PointAnimation pointAnimationLeft(panelLeftInitialPosition,panelLeftFinalPosition,__animationDuration,ANIMATION_INTERPOLATOR_LINEAR);
218 AnimationManager::CheckAnimationSuccessStatus(pointAnimationLeft);
220 PointAnimation pointAnimationCenter(panelCenterInitialPosition,panelCenterFinalPosition,__animationDuration,ANIMATION_INTERPOLATOR_LINEAR);
221 AnimationManager::CheckAnimationSuccessStatus(pointAnimationCenter);
223 PointAnimation pointAnimationRight(panelRightInitialPosition,panelRightFinalPosition,__animationDuration,ANIMATION_INTERPOLATOR_LINEAR);
224 AnimationManager::CheckAnimationSuccessStatus(pointAnimationRight);
226 //Initialize Animator
227 ControlAnimator* pAnimatorLeft = __pPanelLeft->GetControlAnimator();
228 AnimationManager::CheckAnimatorSuccessStatus(*pAnimatorLeft);
230 ControlAnimator* pAnimatorCenter = __pPanelCenter->GetControlAnimator();
231 AnimationManager::CheckAnimatorSuccessStatus(*pAnimatorCenter);
233 ControlAnimator* pAnimatorRight = __pPanelRight->GetControlAnimator();
234 AnimationManager::CheckAnimatorSuccessStatus(*pAnimatorRight);
238 r = AnimationTransaction::Begin(id);
239 CheckAnimationSuccessStatus(r,L"BeginTransaction");
242 r = pAnimatorRight->StartUserAnimation(ANIMATION_TARGET_POSITION,pointAnimationRight);
243 AnimationManager::CheckAnimationSuccessStatus(r,L"StartAnimation");
245 r = pAnimatorCenter->StartUserAnimation(ANIMATION_TARGET_POSITION,pointAnimationCenter);
246 AnimationManager::CheckAnimationSuccessStatus(r,L"StartAnimation");
248 r = pAnimatorLeft->StartUserAnimation(ANIMATION_TARGET_POSITION,pointAnimationLeft);
249 AnimationManager::CheckAnimationSuccessStatus(r,L"StartAnimation");
252 r = AnimationTransaction::Commit();
253 CheckAnimationSuccessStatus(r,L"EndTransaction");