Add Scale transition for Page transition
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / transition / scale-transition-impl.cpp
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali-toolkit/internal/transition/scale-transition-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali-toolkit/public-api/controls/control-impl.h>
23 #include <dali/devel-api/actors/actor-devel.h>
24 #include <dali/integration-api/debug.h>
25 #include <dali/public-api/common/dali-common.h>
26 #include <dali/public-api/object/type-registry.h>
27
28 namespace Dali
29 {
30 namespace Toolkit
31 {
32 namespace Internal
33 {
34
35 ScaleTransitionPtr ScaleTransition::New(Dali::Toolkit::Control control, const Vector2& scaleFactor, TimePeriod timePeriod)
36 {
37   float delaySeconds = timePeriod.delaySeconds;
38   if(delaySeconds < 0.0f)
39   {
40     DALI_LOG_WARNING("delay should be greater than 0.0f.\n");
41     delaySeconds = 0.0f;
42   }
43
44   float durationSeconds = timePeriod.durationSeconds;
45   if(durationSeconds < 0.0f)
46   {
47     DALI_LOG_WARNING("duration should be greater than 0.0f.\n");
48     durationSeconds = 0.0f;
49   }
50
51   ScaleTransitionPtr scaleTransition = new ScaleTransition(control, scaleFactor, TimePeriod(delaySeconds, durationSeconds));
52
53   // Second-phase construction
54   scaleTransition->Initialize();
55
56   return scaleTransition;
57 }
58
59 ScaleTransition::ScaleTransition(Dali::Toolkit::Control control, const Vector2& scaleFactor, TimePeriod timePeriod)
60 : TransitionBase(),
61   mTargetControl(control),
62   mScaleFactor(scaleFactor)
63 {
64   SetTarget(control);
65   SetTimePeriod(timePeriod);
66 }
67
68 ScaleTransition::~ScaleTransition()
69 {
70 }
71
72 void ScaleTransition::SetScaleFactor(const Vector2& scaleFactor)
73 {
74   mScaleFactor = scaleFactor;
75 }
76
77 Vector2 ScaleTransition::GetScaleFactor() const
78 {
79   return mScaleFactor;
80 }
81
82 void ScaleTransition::OnPlay()
83 {
84   Dali::Toolkit::Control targetControl = mTargetControl.GetHandle();
85   if(!targetControl || !targetControl[Dali::Actor::Property::CONNECTED_TO_SCENE])
86   {
87     DALI_LOG_ERROR("The Control is not added on the window\n");
88     return;
89   }
90
91   Property::Map startPropertyMap;
92   Property::Map finishPropertyMap;
93
94   Vector3 targetScale = targetControl[Dali::Actor::Property::SCALE];
95   Vector3 scaleFactor = Vector3(mScaleFactor.x, mScaleFactor.y, 1.0f);
96   if(IsAppearingTransition())
97   {
98     startPropertyMap.Insert(Dali::Actor::Property::SCALE, scaleFactor * targetScale);
99     finishPropertyMap.Insert(Dali::Actor::Property::SCALE, targetScale);
100   }
101   else
102   {
103     startPropertyMap.Insert(Dali::Actor::Property::SCALE, targetScale);
104     finishPropertyMap.Insert(Dali::Actor::Property::SCALE, scaleFactor * targetScale);
105   }
106
107   SetStartPropertyMap(startPropertyMap);
108   SetFinishPropertyMap(finishPropertyMap);
109 }
110
111 } // namespace Internal
112
113 } // namespace Toolkit
114
115 } // namespace Dali