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 "SampleKeyFrameAnimation.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 SampleKeyFrameAnimation::SampleKeyFrameAnimation(AnimationForm& animationForm)
27 : AnimationManager(animationForm)
33 SampleKeyFrameAnimation::~SampleKeyFrameAnimation(void)
38 SampleKeyFrameAnimation::Initialize(void)
42 __pButton1 = new (std::nothrow) Button();
43 __pButton1->Construct(Rectangle(0+offset,0+offset,__buttonSize,__buttonSize),L"I");
44 __pAnimationForm->AddControl(*__pButton1);
46 __pButton2 = new (std::nothrow) Button();
47 __pButton2->Construct(Rectangle(__clientSize.width-__buttonSize-offset,0+offset,__buttonSize,__buttonSize),L"II");
48 __pAnimationForm->AddControl(*__pButton2);
52 SampleKeyFrameAnimation::PlayAnimation(void)
58 Point controlPosition1 = __pButton1->GetPosition();
59 Point controlPosition2 = __pButton2->GetPosition();
61 Point finalPosition1(0+offset,__clientSize.height-__buttonSize-offset);
62 Point finalPosition2(__clientSize.width-__buttonSize-offset,__clientSize.height-__buttonSize-offset);
64 PointAnimation pointAnimation1(__clientCenter,__clientCenter,1000,ANIMATION_INTERPOLATOR_LINEAR);
65 AnimationManager::CheckAnimationSuccessStatus(pointAnimation1);
66 PointAnimation pointAnimation2(__clientCenter,__clientCenter,1000,ANIMATION_INTERPOLATOR_LINEAR);
67 AnimationManager::CheckAnimationSuccessStatus(pointAnimation2);
69 //Initialize Animation
70 if (controlPosition1 == finalPosition1)
72 pointAnimation1 = PointAnimation(Point(0+offset,__clientSize.height-__buttonSize-offset),Point(0+offset,0+offset),1000,ANIMATION_INTERPOLATOR_LINEAR);
76 pointAnimation1 = PointAnimation(Point(0+offset,0+offset),Point(0+offset,__clientSize.height-__buttonSize-offset),1000,ANIMATION_INTERPOLATOR_LINEAR);
78 AnimationManager::CheckAnimationSuccessStatus(pointAnimation1);
79 AnimationManager::InitializeAnimationSettings(pointAnimation1);
81 if (controlPosition2 == finalPosition2)
83 pointAnimation2 = PointAnimation(Point(__clientSize.width-__buttonSize-offset,__clientSize.height-__buttonSize-offset),Point(__clientSize.width-__buttonSize-offset,0+offset),1000,ANIMATION_INTERPOLATOR_LINEAR);
87 pointAnimation2 = PointAnimation(Point(__clientSize.width-__buttonSize-offset,0+offset),Point(__clientSize.width-__buttonSize-offset,__clientSize.height-__buttonSize-offset),1000,ANIMATION_INTERPOLATOR_LINEAR);
89 AnimationManager::CheckAnimationSuccessStatus(pointAnimation2);
90 AnimationManager::InitializeAnimationSettings(pointAnimation2);
92 //Add KeyFrame to Animation
93 pointAnimation1.AddKeyFrame(__duration/2,__clientCenter);
94 pointAnimation2.AddKeyFrame(__duration/2,__clientCenter);
97 ControlAnimator* pAnimator1 = __pButton1->GetControlAnimator();
98 AnimationManager::CheckAnimatorSuccessStatus(*pAnimator1);
99 ControlAnimator* pAnimator2 = __pButton2->GetControlAnimator();
100 AnimationManager::CheckAnimatorSuccessStatus(*pAnimator2);
103 r = pAnimator1->StartUserAnimation(ANIMATION_TARGET_POSITION,pointAnimation1);
104 AnimationManager::CheckAnimationSuccessStatus(r,L"StartAnimation");
106 r = pAnimator2->StartUserAnimation(ANIMATION_TARGET_POSITION,pointAnimation2);
107 AnimationManager::CheckAnimationSuccessStatus(r,L"StartAnimation");
111 SampleKeyFrameAnimation::StopAnimation(void)
113 result r = E_SUCCESS;
115 for (int i=0; i<__pAnimationForm->GetControlCount(); ++i)
117 Control* pControl = __pAnimationForm->GetControl(i);
118 ControlAnimator* pAnimator = pControl->GetControlAnimator();
119 AnimationManager::CheckAnimatorSuccessStatus(*pAnimator);
121 if (pAnimator->GetStatus() == ANIMATOR_STATUS_PLAYING)
123 r = pAnimator->StopAllAnimations();
124 CheckAnimationSuccessStatus(r,L"StopAnimation");