Tizen 2.1 base
[sdk/ide/native-sample.git] / samples / native / cpp / Sample / Tizen C++ / UiControlAnimator / UiControlAnimator / project / src / SamplePanelTransitionAnimation.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 "SamplePanelTransitionAnimation.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 SamplePanelTransitionAnimation::SamplePanelTransitionAnimation(AnimationForm& animationForm)
27         : AnimationManager(animationForm)
28         , __panelCurrentlyVisible(1)
29         , __animationDuration(500)
30         , __pPanelLeft(null)
31         , __pPanelCenter(null)
32         , __pPanelRight(null)
33 {
34 }
35
36 SamplePanelTransitionAnimation::~SamplePanelTransitionAnimation(void)
37 {
38 }
39
40 void
41 SamplePanelTransitionAnimation::Initialize(void)
42 {
43         Rectangle formBounds = __pAnimationForm->GetClientAreaBounds();
44
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);
49
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);
54
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);
59
60         Button* pButtonLeft = new (std::nothrow) Button();
61         pButtonLeft->Construct(Rectangle(50,20,formBounds.width-100,50),L"Panel Left");
62         __pPanelLeft->AddControl(*pButtonLeft);
63
64         Button* pButtonCenter = new (std::nothrow) Button();
65         pButtonCenter->Construct(Rectangle(50,20,formBounds.width-100,50),L"Panel Center");
66         __pPanelCenter->AddControl(*pButtonCenter);
67
68         Button* pButtonRight = new (std::nothrow) Button();
69         pButtonRight->Construct(Rectangle(50,20,formBounds.width-100,50),L"Panel Right");
70         __pPanelRight->AddControl(*pButtonRight);
71
72         __pAnimationForm->RequestRedraw();
73 }
74
75 void
76 SamplePanelTransitionAnimation::PlayAnimation(void)
77 {
78 }
79
80 void
81 SamplePanelTransitionAnimation::StopAnimation(void)
82 {
83 }
84
85 void
86 SamplePanelTransitionAnimation::TranslatePanelRight(void)
87 {
88         result r = E_SUCCESS;
89
90         if (__pPanelLeft->GetControlAnimator()->GetStatus() == ANIMATOR_STATUS_PLAYING ||
91                 __pPanelCenter->GetControlAnimator()->GetStatus() == ANIMATOR_STATUS_PLAYING ||
92                 __pPanelRight->GetControlAnimator()->GetStatus() == ANIMATOR_STATUS_PLAYING)
93         {
94                 return;
95         }
96
97         if (__panelCurrentlyVisible == 0)
98         {
99                 Point panelLeftInitialPosition = __pPanelLeft->GetBounds().GetTopLeft();
100                 Point panelLeftFinalPosition   = panelLeftInitialPosition + Point(100,0);
101
102                 PointAnimation pointAnimationRightEnd(panelLeftInitialPosition,panelLeftFinalPosition,__animationDuration/2,ANIMATION_INTERPOLATOR_LINEAR);
103                 pointAnimationRightEnd.SetAutoReverseEnabled(true);
104                 AnimationManager::CheckAnimationSuccessStatus(pointAnimationRightEnd);
105
106                 ControlAnimator* pAnimatorLeft = __pPanelLeft->GetControlAnimator();
107                 AnimationManager::CheckAnimatorSuccessStatus(*pAnimatorLeft);
108
109                 if (__pPanelLeft->GetControlAnimator()->GetStatus() == ANIMATOR_STATUS_PLAYING)
110                 {
111                         return;
112                 }
113
114                 r = pAnimatorLeft->StartUserAnimation(ANIMATION_TARGET_POSITION,pointAnimationRightEnd);
115                 AnimationManager::CheckAnimationSuccessStatus(r,L"StartAnimation");
116         }
117         else
118         {
119                 __panelCurrentlyVisible--;
120
121                 Point panelLeftInitialPosition = __pPanelLeft->GetBounds().GetTopLeft();
122                 Point panelLeftFinalPosition   = panelLeftInitialPosition + Point(__pPanelLeft->GetBounds().width,0);
123
124                 Point panelCenterInitialPosition = __pPanelCenter->GetBounds().GetTopLeft();
125                 Point panelCenterFinalPosition   = panelCenterInitialPosition + Point(__pPanelCenter->GetBounds().width,0);
126
127                 Point panelRightInitialPosition = __pPanelRight->GetBounds().GetTopLeft();
128                 Point panelRightFinalPosition   = panelRightInitialPosition + Point(__pPanelRight->GetBounds().width,0);
129
130                 //Initialize Animation
131                 PointAnimation pointAnimationLeft(panelLeftInitialPosition,panelLeftFinalPosition,__animationDuration,ANIMATION_INTERPOLATOR_LINEAR);
132                 AnimationManager::CheckAnimationSuccessStatus(pointAnimationLeft);
133
134                 PointAnimation pointAnimationCenter(panelCenterInitialPosition,panelCenterFinalPosition,__animationDuration,ANIMATION_INTERPOLATOR_LINEAR);
135                 AnimationManager::CheckAnimationSuccessStatus(pointAnimationCenter);
136
137                 PointAnimation pointAnimationRight(panelRightInitialPosition,panelRightFinalPosition,__animationDuration,ANIMATION_INTERPOLATOR_LINEAR);
138                 AnimationManager::CheckAnimationSuccessStatus(pointAnimationRight);
139
140                 //Initialize Animator
141                 ControlAnimator* pAnimatorLeft = __pPanelLeft->GetControlAnimator();
142                 AnimationManager::CheckAnimatorSuccessStatus(*pAnimatorLeft);
143
144                 ControlAnimator* pAnimatorCenter = __pPanelCenter->GetControlAnimator();
145                 AnimationManager::CheckAnimatorSuccessStatus(*pAnimatorCenter);
146
147                 ControlAnimator* pAnimatorRight = __pPanelRight->GetControlAnimator();
148                 AnimationManager::CheckAnimatorSuccessStatus(*pAnimatorRight);
149
150                 //Begin Transaction
151                 int id;
152                 r = AnimationTransaction::Begin(id);
153                 CheckAnimationSuccessStatus(r,L"BeginTransaction");
154
155                 //Start Animation
156                 r = pAnimatorLeft->StartUserAnimation(ANIMATION_TARGET_POSITION,pointAnimationLeft);
157                 AnimationManager::CheckAnimationSuccessStatus(r,L"StartAnimation");
158
159                 r = pAnimatorCenter->StartUserAnimation(ANIMATION_TARGET_POSITION,pointAnimationCenter);
160                 AnimationManager::CheckAnimationSuccessStatus(r,L"StartAnimation");
161
162                 r = pAnimatorRight->StartUserAnimation(ANIMATION_TARGET_POSITION,pointAnimationRight);
163                 AnimationManager::CheckAnimationSuccessStatus(r,L"StartAnimation");
164
165                 //End Transaction
166                 r = AnimationTransaction::Commit();
167                 CheckAnimationSuccessStatus(r,L"EndTransaction");
168         }
169 }
170
171 void
172 SamplePanelTransitionAnimation::TranslatePanelLeft(void)
173 {
174         result r = E_SUCCESS;
175
176         if (__pPanelLeft->GetControlAnimator()->GetStatus() == ANIMATOR_STATUS_PLAYING ||
177                 __pPanelCenter->GetControlAnimator()->GetStatus() == ANIMATOR_STATUS_PLAYING ||
178                 __pPanelRight->GetControlAnimator()->GetStatus() == ANIMATOR_STATUS_PLAYING)
179         {
180                 return;
181         }
182
183         if (__panelCurrentlyVisible == 2)
184         {
185                 Point panelRightInitialPosition = __pPanelRight->GetBounds().GetTopLeft();
186                 Point panelRightFinalPosition   = panelRightInitialPosition - Point(100,0);
187
188                 PointAnimation pointAnimationRightEnd(panelRightInitialPosition,panelRightFinalPosition,__animationDuration/2,ANIMATION_INTERPOLATOR_LINEAR);
189                 pointAnimationRightEnd.SetAutoReverseEnabled(true);
190                 AnimationManager::CheckAnimationSuccessStatus(pointAnimationRightEnd);
191
192                 ControlAnimator* pAnimatorRight = __pPanelRight->GetControlAnimator();
193                 AnimationManager::CheckAnimatorSuccessStatus(*pAnimatorRight);
194
195                 if (__pPanelRight->GetControlAnimator()->GetStatus() == ANIMATOR_STATUS_PLAYING)
196                 {
197                         return;
198                 }
199
200                 r = pAnimatorRight->StartUserAnimation(ANIMATION_TARGET_POSITION,pointAnimationRightEnd);
201                 AnimationManager::CheckAnimationSuccessStatus(r,L"StartAnimation");
202         }
203         else
204         {
205                 __panelCurrentlyVisible++;
206
207                 Point panelLeftInitialPosition = __pPanelLeft->GetBounds().GetTopLeft();
208                 Point panelLeftFinalPosition   = panelLeftInitialPosition - Point(__pPanelLeft->GetBounds().width,0);
209
210                 Point panelCenterInitialPosition = __pPanelCenter->GetBounds().GetTopLeft();
211                 Point panelCenterFinalPosition   = panelCenterInitialPosition - Point(__pPanelCenter->GetBounds().width,0);
212
213                 Point panelRightInitialPosition = __pPanelRight->GetBounds().GetTopLeft();
214                 Point panelRightFinalPosition   = panelRightInitialPosition - Point(__pPanelRight->GetBounds().width,0);
215
216                 //Initialize Animation
217                 PointAnimation pointAnimationLeft(panelLeftInitialPosition,panelLeftFinalPosition,__animationDuration,ANIMATION_INTERPOLATOR_LINEAR);
218                 AnimationManager::CheckAnimationSuccessStatus(pointAnimationLeft);
219
220                 PointAnimation pointAnimationCenter(panelCenterInitialPosition,panelCenterFinalPosition,__animationDuration,ANIMATION_INTERPOLATOR_LINEAR);
221                 AnimationManager::CheckAnimationSuccessStatus(pointAnimationCenter);
222
223                 PointAnimation pointAnimationRight(panelRightInitialPosition,panelRightFinalPosition,__animationDuration,ANIMATION_INTERPOLATOR_LINEAR);
224                 AnimationManager::CheckAnimationSuccessStatus(pointAnimationRight);
225
226                 //Initialize Animator
227                 ControlAnimator* pAnimatorLeft = __pPanelLeft->GetControlAnimator();
228                 AnimationManager::CheckAnimatorSuccessStatus(*pAnimatorLeft);
229
230                 ControlAnimator* pAnimatorCenter = __pPanelCenter->GetControlAnimator();
231                 AnimationManager::CheckAnimatorSuccessStatus(*pAnimatorCenter);
232
233                 ControlAnimator* pAnimatorRight = __pPanelRight->GetControlAnimator();
234                 AnimationManager::CheckAnimatorSuccessStatus(*pAnimatorRight);
235
236                 //Begin Transaction
237                 int id;
238                 r = AnimationTransaction::Begin(id);
239                 CheckAnimationSuccessStatus(r,L"BeginTransaction");
240
241                 //Start Animation
242                 r = pAnimatorRight->StartUserAnimation(ANIMATION_TARGET_POSITION,pointAnimationRight);
243                 AnimationManager::CheckAnimationSuccessStatus(r,L"StartAnimation");
244
245                 r = pAnimatorCenter->StartUserAnimation(ANIMATION_TARGET_POSITION,pointAnimationCenter);
246                 AnimationManager::CheckAnimationSuccessStatus(r,L"StartAnimation");
247
248                 r = pAnimatorLeft->StartUserAnimation(ANIMATION_TARGET_POSITION,pointAnimationLeft);
249                 AnimationManager::CheckAnimationSuccessStatus(r,L"StartAnimation");
250
251                 //End Transaction
252                 r = AnimationTransaction::Commit();
253                 CheckAnimationSuccessStatus(r,L"EndTransaction");
254         }
255 }