Merge "Fix invalid update to TextUpdateInfo in SELECTING state." 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 }
75
76 Transition::~Transition()
77 {
78 }
79
80 void Transition::OnPlay()
81 {
82   Dali::Toolkit::Control sourceControl = mSourceControl.GetHandle();
83   Dali::Toolkit::Control destinationControl = mDestinationControl.GetHandle();
84   if(!sourceControl || !sourceControl[Dali::Actor::Property::CONNECTED_TO_SCENE] ||
85      !destinationControl || !destinationControl[Dali::Actor::Property::CONNECTED_TO_SCENE])
86   {
87     DALI_LOG_ERROR("The source or destination is not added on the window\n");
88     return;
89   }
90
91   //Make startPropertyMap and finishPropertyMap to use for property animation.
92   Matrix     sourceWorldTransform = sourceControl[Dali::Actor::Property::WORLD_MATRIX];
93   Vector3    sourcePosition, sourceScale;
94   Quaternion sourceOrientation;
95   sourceWorldTransform.GetTransformComponents(sourcePosition, sourceOrientation, sourceScale);
96
97   Matrix     destinationWorldTransform = GetWorldTransform(destinationControl);
98   Vector3    destinationPosition, destinationScale;
99   Quaternion destinationOrientation;
100   destinationWorldTransform.GetTransformComponents(destinationPosition, destinationOrientation, destinationScale);
101
102   Vector3       targetSize  = destinationControl[Dali::Actor::Property::SIZE];
103   Vector4       targetColor = GetWorldColor(destinationControl);
104   Property::Map startPropertyMap;
105   Property::Map finishPropertyMap;
106
107   // Use world transform if this transition requires animation of transform.
108   destinationControl[Dali::Actor::Property::ANCHOR_POINT]               = AnchorPoint::CENTER;
109   destinationControl[Dali::Actor::Property::PARENT_ORIGIN]              = ParentOrigin::CENTER;
110   destinationControl[Dali::Actor::Property::POSITION_USES_ANCHOR_POINT] = true;
111   destinationControl[Dali::Actor::Property::INHERIT_POSITION]           = false;
112   destinationControl[Dali::Actor::Property::INHERIT_ORIENTATION]        = false;
113   destinationControl[Dali::Actor::Property::INHERIT_SCALE]              = false;
114   destinationControl[Dali::Actor::Property::COLOR_MODE]                 = Dali::ColorMode::USE_OWN_COLOR;
115
116   // Set animation of Transform
117   startPropertyMap.Insert(Dali::Actor::Property::POSITION, sourcePosition);
118   finishPropertyMap.Insert(Dali::Actor::Property::POSITION, destinationPosition);
119
120   startPropertyMap.Insert(Dali::Actor::Property::ORIENTATION, sourceOrientation);
121   finishPropertyMap.Insert(Dali::Actor::Property::ORIENTATION, destinationOrientation);
122
123   startPropertyMap.Insert(Dali::Actor::Property::SCALE, sourceScale);
124   finishPropertyMap.Insert(Dali::Actor::Property::SCALE, destinationScale);
125
126   Vector4 sourceColor = sourceControl.GetCurrentProperty<Vector4>(Dali::Actor::Property::WORLD_COLOR);
127   startPropertyMap.Insert(Dali::Actor::Property::COLOR, sourceColor);
128   finishPropertyMap.Insert(Dali::Actor::Property::COLOR, targetColor);
129
130   // Set animation for other properties if source and destination is different.
131   Vector3 sourceSize = sourceControl.GetCurrentProperty<Vector3>(Dali::Actor::Property::SIZE);
132   if(sourceSize != targetSize)
133   {
134     startPropertyMap.Insert(Dali::Actor::Property::SIZE, sourceSize);
135     finishPropertyMap.Insert(Dali::Actor::Property::SIZE, targetSize);
136   }
137
138   SetStartPropertyMap(startPropertyMap);
139   SetFinishPropertyMap(finishPropertyMap);
140
141   // source View becomes transparent during transition.
142   if(IsTransitionWithChild())
143   {
144     sourceControl[Dali::Actor::Property::VISIBLE] = false;
145   }
146   else
147   {
148     GetImplementation(sourceControl).SetTransparent(true);
149   }
150
151   Dali::Animation animation = GetAnimation();
152   if(!animation)
153   {
154     DALI_LOG_ERROR("animation is still not initialized\n");
155     return;
156   }
157   Dali::Toolkit::DevelControl::CreateTransitions(destinationControl, animation, sourceControl, GetAlphaFunction(), GetTimePeriod());
158 }
159
160 void Transition::OnFinished()
161 {
162   Dali::Toolkit::Control sourceControl = mSourceControl.GetHandle();
163   if(!sourceControl)
164   {
165     return;
166   }
167
168   if(IsTransitionWithChild())
169   {
170     sourceControl[Dali::Actor::Property::VISIBLE] = true;
171   }
172   else
173   {
174     GetImplementation(sourceControl).SetTransparent(false);
175   }
176 }
177
178 } // namespace Internal
179
180 } // namespace Toolkit
181
182 } // namespace Dali