Tizen 2.1 base
[sdk/ide/native-sample.git] / samples / native / partner / cpp / Sample / Tizen C++ / UiControlAnimator / UiControlAnimator / project / src / SampleTransactionSet.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 "SampleTransactionSetAnimation.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 SampleTransactionSetAnimation::SampleTransactionSetAnimation(AnimationForm& animationForm)
27         : AnimationManager(animationForm)
28         , __pButton1(null)
29         , __pButton2(null)
30         , __pButton3(null)
31         , __pButton4(null)
32         , __pButton5(null)
33 {
34 }
35
36 SampleTransactionSetAnimation::~SampleTransactionSetAnimation(void)
37 {
38 }
39
40 void
41 SampleTransactionSetAnimation::Initialize(void)
42 {
43         int offset = 50;
44
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);
49
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);
54
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);
59
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);
64
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);
69 }
70
71 void
72 SampleTransactionSetAnimation::PlayAnimation(void)
73 {
74         result r = E_SUCCESS;
75
76         int offset = 50;
77
78         Point controlPosition1 = __pButton1->GetPosition();
79         Point controlPosition2 = __pButton2->GetPosition();
80         Point controlPosition4 = __pButton4->GetPosition();
81         Point controlPosition5 = __pButton5->GetPosition();
82
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);
87
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);
96
97         if (AnimationTransaction::GetStatus(__transactionId) == ANIMATION_TRANSACTION_STATUS_STOPPED)
98         {
99                 //Initialize Animation
100                 if (controlPosition1 == finalPosition1)
101                 {
102                         pointAnimation1 = PointAnimation(Point(__clientSize.width-__buttonSize-offset,0+offset),Point(0+offset,0+offset),1000,ANIMATION_INTERPOLATOR_LINEAR);
103                 }
104                 else
105                 {
106                         pointAnimation1 = PointAnimation(Point(0+offset,0+offset),Point(__clientSize.width-__buttonSize-offset,0+offset),1000,ANIMATION_INTERPOLATOR_LINEAR);
107                 }
108                 AnimationManager::CheckAnimationSuccessStatus(pointAnimation1);
109                 AnimationManager::InitializeAnimationSettings(pointAnimation1);
110
111                 if (controlPosition2 == finalPosition2)
112                 {
113                         pointAnimation2 = PointAnimation(Point(__clientSize.width-__buttonSize-offset,__clientSize.height-__buttonSize-offset),Point(__clientSize.width-__buttonSize-offset,0+offset),1000,ANIMATION_INTERPOLATOR_LINEAR);
114                 }
115                 else
116                 {
117                         pointAnimation2 = PointAnimation(Point(__clientSize.width-__buttonSize-offset,0+offset),Point(__clientSize.width-__buttonSize-offset,__clientSize.height-__buttonSize-offset),1000,ANIMATION_INTERPOLATOR_LINEAR);
118                 }
119                 AnimationManager::CheckAnimationSuccessStatus(pointAnimation2);
120                 AnimationManager::InitializeAnimationSettings(pointAnimation2);
121
122                 if (controlPosition4 == finalPosition4)
123                 {
124                         pointAnimation4 = PointAnimation(Point(0+offset,0+offset),Point(0+offset,__clientSize.height-__buttonSize-offset),1000,ANIMATION_INTERPOLATOR_LINEAR);
125                 }
126                 else
127                 {
128                         pointAnimation4 = PointAnimation(Point(0+offset,__clientSize.height-__buttonSize-offset),Point(0+offset,0+offset),1000,ANIMATION_INTERPOLATOR_LINEAR);
129                 }
130                 AnimationManager::CheckAnimationSuccessStatus(pointAnimation4);
131                 AnimationManager::InitializeAnimationSettings(pointAnimation4);
132
133                 if (controlPosition5 == finalPosition5)
134                 {
135                         pointAnimation5 = PointAnimation(Point(0+offset,__clientSize.height-__buttonSize-offset),Point(__clientSize.width-__buttonSize-offset,__clientSize.height-__buttonSize-offset),1000,ANIMATION_INTERPOLATOR_LINEAR);
136                 }
137                 else
138                 {
139                         pointAnimation5 = PointAnimation(Point(__clientSize.width-__buttonSize-offset,__clientSize.height-__buttonSize-offset),Point(0+offset,__clientSize.height-__buttonSize-offset),1000,ANIMATION_INTERPOLATOR_LINEAR);
140                 }
141                 AnimationManager::CheckAnimationSuccessStatus(pointAnimation5);
142                 AnimationManager::InitializeAnimationSettings(pointAnimation5);
143
144                 RotateAnimation rotateAnimation3(0,360,1000,ANIMATION_INTERPOLATOR_LINEAR);
145                 AnimationManager::CheckAnimationSuccessStatus(rotateAnimation3);
146                 AnimationManager::InitializeAnimationSettings(rotateAnimation3);
147
148                 r = rotateAnimation3.SetAnchor(0.5,0.5);
149                 AnimationManager::CheckAnimationSuccessStatus(r,L"SetAnchor");
150
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);
161
162                 r = AnimationTransaction::Begin(__transactionId);
163                 CheckAnimationSuccessStatus(r,L"BeginTransaction");
164
165                 r = pAnimator1->StartUserAnimation(ANIMATION_TARGET_POSITION,pointAnimation1);
166                 AnimationManager::CheckAnimationSuccessStatus(r,L"StartAnimation");
167
168                 r = pAnimator2->StartUserAnimation(ANIMATION_TARGET_POSITION,pointAnimation2);
169                 AnimationManager::CheckAnimationSuccessStatus(r,L"StartAnimation");
170
171                 r = pAnimator3->StartUserAnimation(ANIMATION_TARGET_ROTATION,rotateAnimation3);
172                 AnimationManager::CheckAnimationSuccessStatus(r,L"StartAnimation");
173
174                 r = pAnimator4->StartUserAnimation(ANIMATION_TARGET_POSITION,pointAnimation4);
175                 AnimationManager::CheckAnimationSuccessStatus(r,L"StartAnimation");
176
177                 r = pAnimator5->StartUserAnimation(ANIMATION_TARGET_POSITION,pointAnimation5);
178                 AnimationManager::CheckAnimationSuccessStatus(r,L"StartAnimation");
179
180                 r = AnimationTransaction::Commit();
181                 CheckAnimationSuccessStatus(r,L"EndTransaction");
182         }
183 }
184
185 void
186 SampleTransactionSetAnimation::StopAnimation(void)
187 {
188         result result = E_SUCCESS;
189
190         if (AnimationTransaction::GetStatus(__transactionId) == ANIMATION_TRANSACTION_STATUS_PLAYING)
191         {
192                 result = AnimationTransaction::Stop(__transactionId);
193                 CheckAnimationSuccessStatus(result,L"EndTransaction");
194         }
195 }