Merge "Fix VD svace problem." into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / transition / 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/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 // INTERNAL INCLUDES
29 #include <dali-toolkit/devel-api/controls/control-devel.h>
30
31 namespace Dali
32 {
33 namespace Toolkit
34 {
35 namespace Internal
36 {
37 namespace
38 {
39 const Dali::AlphaFunction DEFAULT_ALPHA_FUNCTION(Dali::AlphaFunction::DEFAULT);
40
41 } // anonymous namespace
42
43 TransitionPtr Transition::New(Dali::Toolkit::Control source, Dali::Toolkit::Control destination, TimePeriod timePeriod)
44 {
45   float delaySeconds = timePeriod.delaySeconds;
46   if(delaySeconds < 0.0f)
47   {
48     DALI_LOG_WARNING("delay should be greater than 0.0f.\n");
49     delaySeconds = 0.0f;
50   }
51
52   float durationSeconds = timePeriod.durationSeconds;
53   if(durationSeconds < 0.0f)
54   {
55     DALI_LOG_WARNING("duration should be greater than 0.0f.\n");
56     durationSeconds = 0.0f;
57   }
58
59   TransitionPtr transition = new Transition(source, destination, TimePeriod(delaySeconds, durationSeconds));
60
61   // Second-phase construction
62   transition->Initialize();
63
64   return transition;
65 }
66
67 Transition::Transition(Dali::Toolkit::Control source, Dali::Toolkit::Control destination, TimePeriod timePeriod)
68 : TransitionBase(),
69   mSourceControl(source),
70   mDestinationControl(destination)
71 {
72   SetTarget(destination);
73   SetTimePeriod(timePeriod);
74   SetPairTransition(true);
75 }
76
77 Transition::~Transition()
78 {
79 }
80
81 void Transition::OnPlay()
82 {
83   Dali::Toolkit::Control sourceControl = mSourceControl.GetHandle();
84   Dali::Toolkit::Control destinationControl = mDestinationControl.GetHandle();
85   if(!sourceControl || !sourceControl[Dali::Actor::Property::CONNECTED_TO_SCENE] ||
86      !destinationControl || !destinationControl[Dali::Actor::Property::CONNECTED_TO_SCENE])
87   {
88     DALI_LOG_ERROR("The source or destination is not added on the window\n");
89     return;
90   }
91
92   //Make startPropertyMap and finishPropertyMap to use for property animation.
93   Matrix     sourceWorldTransform = sourceControl[Dali::Actor::Property::WORLD_MATRIX];
94   Vector3    sourcePosition, sourceScale;
95   Quaternion sourceOrientation;
96   sourceWorldTransform.GetTransformComponents(sourcePosition, sourceOrientation, sourceScale);
97
98   Vector3    destinationPosition    = destinationControl[Dali::Actor::Property::POSITION];
99   Vector3    destinationScale       = destinationControl[Dali::Actor::Property::SCALE];
100   Quaternion destinationOrientation = destinationControl[Dali::Actor::Property::ORIENTATION];
101   Vector4    targetColor            = destinationControl[Dali::Actor::Property::COLOR];
102   Vector3    targetSize             = destinationControl[Dali::Actor::Property::SIZE];
103
104   Property::Map startPropertyMap;
105   Property::Map finishPropertyMap;
106
107   // Set animation of Transform
108   startPropertyMap.Insert(Dali::Actor::Property::POSITION, sourcePosition);
109   finishPropertyMap.Insert(Dali::Actor::Property::POSITION, destinationPosition);
110
111   startPropertyMap.Insert(Dali::Actor::Property::ORIENTATION, sourceOrientation);
112   finishPropertyMap.Insert(Dali::Actor::Property::ORIENTATION, destinationOrientation);
113
114   startPropertyMap.Insert(Dali::Actor::Property::SCALE, sourceScale);
115   finishPropertyMap.Insert(Dali::Actor::Property::SCALE, destinationScale);
116
117   Vector4 sourceColor = sourceControl.GetCurrentProperty<Vector4>(Dali::Actor::Property::WORLD_COLOR);
118   startPropertyMap.Insert(Dali::Actor::Property::COLOR, sourceColor);
119   finishPropertyMap.Insert(Dali::Actor::Property::COLOR, targetColor);
120
121   // Set animation for other properties if source and destination is different.
122   Vector3 sourceSize = sourceControl.GetCurrentProperty<Vector3>(Dali::Actor::Property::SIZE);
123   if(sourceSize != targetSize)
124   {
125     startPropertyMap.Insert(Dali::Actor::Property::SIZE, sourceSize);
126     finishPropertyMap.Insert(Dali::Actor::Property::SIZE, targetSize);
127   }
128
129   SetStartPropertyMap(startPropertyMap);
130   SetFinishPropertyMap(finishPropertyMap);
131
132   // source View becomes transparent during transition.
133   if(IsTransitionWithChild())
134   {
135     sourceControl[Dali::Actor::Property::VISIBLE] = false;
136   }
137   else
138   {
139     GetImplementation(sourceControl).SetTransparent(true);
140   }
141
142   Dali::Animation animation = GetAnimation();
143   if(!animation)
144   {
145     DALI_LOG_ERROR("animation is still not initialized\n");
146     return;
147   }
148   Dali::Toolkit::DevelControl::CreateTransitions(destinationControl, animation, sourceControl, GetAlphaFunction(), GetTimePeriod());
149 }
150
151 void Transition::OnFinished()
152 {
153   Dali::Toolkit::Control sourceControl = mSourceControl.GetHandle();
154   if(!sourceControl)
155   {
156     return;
157   }
158
159   if(IsTransitionWithChild())
160   {
161     sourceControl[Dali::Actor::Property::VISIBLE] = true;
162   }
163   else
164   {
165     GetImplementation(sourceControl).SetTransparent(false);
166   }
167 }
168
169 } // namespace Internal
170
171 } // namespace Toolkit
172
173 } // namespace Dali