2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali-toolkit/internal/transition/transition-impl.h>
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>
29 #include <dali-toolkit/devel-api/controls/control-devel.h>
39 const Dali::AlphaFunction DEFAULT_ALPHA_FUNCTION(Dali::AlphaFunction::DEFAULT);
41 } // anonymous namespace
43 TransitionPtr Transition::New(Dali::Toolkit::Control source, Dali::Toolkit::Control destination, TimePeriod timePeriod)
45 float delaySeconds = timePeriod.delaySeconds;
46 if(delaySeconds < 0.0f)
48 DALI_LOG_WARNING("delay should be greater than 0.0f.\n");
52 float durationSeconds = timePeriod.durationSeconds;
53 if(durationSeconds < 0.0f)
55 DALI_LOG_WARNING("duration should be greater than 0.0f.\n");
56 durationSeconds = 0.0f;
59 TransitionPtr transition = new Transition(source, destination, TimePeriod(delaySeconds, durationSeconds));
61 // Second-phase construction
62 transition->Initialize();
67 Transition::Transition(Dali::Toolkit::Control source, Dali::Toolkit::Control destination, TimePeriod timePeriod)
69 mSourceControl(source),
70 mDestinationControl(destination)
72 SetTarget(destination);
73 SetTimePeriod(timePeriod);
74 SetPairTransition(true);
77 Transition::~Transition()
81 void Transition::OnPlay()
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])
88 DALI_LOG_ERROR("The source or destination is not added on the window\n");
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);
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];
104 Property::Map startPropertyMap;
105 Property::Map finishPropertyMap;
107 // Set animation of Transform
108 startPropertyMap.Insert(Dali::Actor::Property::POSITION, sourcePosition);
109 finishPropertyMap.Insert(Dali::Actor::Property::POSITION, destinationPosition);
111 startPropertyMap.Insert(Dali::Actor::Property::ORIENTATION, sourceOrientation);
112 finishPropertyMap.Insert(Dali::Actor::Property::ORIENTATION, destinationOrientation);
114 startPropertyMap.Insert(Dali::Actor::Property::SCALE, sourceScale);
115 finishPropertyMap.Insert(Dali::Actor::Property::SCALE, destinationScale);
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);
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)
125 startPropertyMap.Insert(Dali::Actor::Property::SIZE, sourceSize);
126 finishPropertyMap.Insert(Dali::Actor::Property::SIZE, targetSize);
129 SetStartPropertyMap(startPropertyMap);
130 SetFinishPropertyMap(finishPropertyMap);
132 // source View becomes transparent during transition.
133 if(IsTransitionWithChild())
135 sourceControl[Dali::Actor::Property::VISIBLE] = false;
139 GetImplementation(sourceControl).SetTransparent(true);
142 Dali::Animation animation = GetAnimation();
145 DALI_LOG_ERROR("animation is still not initialized\n");
148 Dali::Toolkit::DevelControl::CreateTransitions(destinationControl, animation, sourceControl, GetAlphaFunction(), GetTimePeriod());
151 void Transition::OnFinished()
153 Dali::Toolkit::Control sourceControl = mSourceControl.GetHandle();
159 if(IsTransitionWithChild())
161 sourceControl[Dali::Actor::Property::VISIBLE] = true;
165 GetImplementation(sourceControl).SetTransparent(false);
169 } // namespace Internal
171 } // namespace Toolkit