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);
76 Transition::~Transition()
80 void Transition::OnPlay()
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])
87 DALI_LOG_ERROR("The source or destination is not added on the window\n");
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);
97 Matrix destinationWorldTransform = GetWorldTransform(destinationControl);
98 Vector3 destinationPosition, destinationScale;
99 Quaternion destinationOrientation;
100 destinationWorldTransform.GetTransformComponents(destinationPosition, destinationOrientation, destinationScale);
102 Vector3 targetSize = destinationControl[Dali::Actor::Property::SIZE];
103 Vector4 targetColor = GetWorldColor(destinationControl);
104 Property::Map startPropertyMap;
105 Property::Map finishPropertyMap;
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;
116 // Set animation of Transform
117 startPropertyMap.Insert(Dali::Actor::Property::POSITION, sourcePosition);
118 finishPropertyMap.Insert(Dali::Actor::Property::POSITION, destinationPosition);
120 startPropertyMap.Insert(Dali::Actor::Property::ORIENTATION, sourceOrientation);
121 finishPropertyMap.Insert(Dali::Actor::Property::ORIENTATION, destinationOrientation);
123 startPropertyMap.Insert(Dali::Actor::Property::SCALE, sourceScale);
124 finishPropertyMap.Insert(Dali::Actor::Property::SCALE, destinationScale);
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);
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)
134 startPropertyMap.Insert(Dali::Actor::Property::SIZE, sourceSize);
135 finishPropertyMap.Insert(Dali::Actor::Property::SIZE, targetSize);
138 SetStartPropertyMap(startPropertyMap);
139 SetFinishPropertyMap(finishPropertyMap);
141 // source View becomes transparent during transition.
142 if(IsTransitionWithChild())
144 sourceControl[Dali::Actor::Property::VISIBLE] = false;
148 GetImplementation(sourceControl).SetTransparent(true);
151 Dali::Animation animation = GetAnimation();
154 DALI_LOG_ERROR("animation is still not initialized\n");
157 Dali::Toolkit::DevelControl::CreateTransitions(destinationControl, animation, sourceControl, GetAlphaFunction(), GetTimePeriod());
160 void Transition::OnFinished()
162 Dali::Toolkit::Control sourceControl = mSourceControl.GetHandle();
168 if(IsTransitionWithChild())
170 sourceControl[Dali::Actor::Property::VISIBLE] = true;
174 GetImplementation(sourceControl).SetTransparent(false);
178 } // namespace Internal
180 } // namespace Toolkit