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>
36 const Dali::AlphaFunction DEFAULT_ALPHA_FUNCTION(Dali::AlphaFunction::DEFAULT);
38 } // anonymous namespace
40 TransitionPtr Transition::New(Dali::Toolkit::Control source, Dali::Toolkit::Control destination, TimePeriod timePeriod)
42 float durationSeconds = timePeriod.durationSeconds;
43 if(durationSeconds < 0.0f)
45 DALI_LOG_WARNING("duration should be greater than 0.0f.\n");
46 durationSeconds = 0.0f;
49 TransitionPtr transition = new Transition(source, destination, timePeriod);
51 // Second-phase construction
52 transition->Initialize();
57 Transition::Transition(Dali::Toolkit::Control source, Dali::Toolkit::Control destination, TimePeriod timePeriod)
60 mDestinationView(destination),
61 mShowSourceAfterFinished(true)
63 SetTargetView(destination);
64 SetDuration(timePeriod.durationSeconds);
65 SetDelay(timePeriod.delaySeconds);
68 Transition::~Transition()
72 void Transition::OnPlay()
74 if(!mSourceView[Dali::Actor::Property::CONNECTED_TO_SCENE] ||
75 !mDestinationView[Dali::Actor::Property::CONNECTED_TO_SCENE])
77 DALI_LOG_ERROR("The source or destination is not added on the window\n");
81 //Make startPropertyMap and finishPropertyMap to use for property animation.
82 Matrix sourceWorldTransform = mSourceView[Dali::Actor::Property::WORLD_MATRIX];
83 Vector3 sourcePosition, sourceScale;
84 Quaternion sourceOrientation;
85 sourceWorldTransform.GetTransformComponents(sourcePosition, sourceOrientation, sourceScale);
87 Matrix destinationWorldTransform = GetWorldTransform(mDestinationView);
88 Vector3 destinationPosition, destinationScale;
89 Quaternion destinationOrientation;
90 destinationWorldTransform.GetTransformComponents(destinationPosition, destinationOrientation, destinationScale);
92 Vector3 targetSize = mDestinationView[Dali::Actor::Property::SIZE];
93 Vector4 targetColor = GetWorldColor(mDestinationView);
94 Property::Map startPropertyMap;
95 Property::Map finishPropertyMap;
97 // Use world transform if this transition requires animation of transform.
98 mDestinationView[Dali::Actor::Property::ANCHOR_POINT] = AnchorPoint::CENTER;
99 mDestinationView[Dali::Actor::Property::PARENT_ORIGIN] = ParentOrigin::CENTER;
100 mDestinationView[Dali::Actor::Property::POSITION_USES_ANCHOR_POINT] = true;
101 mDestinationView[Dali::Actor::Property::INHERIT_POSITION] = false;
102 mDestinationView[Dali::Actor::Property::INHERIT_ORIENTATION] = false;
103 mDestinationView[Dali::Actor::Property::INHERIT_SCALE] = false;
104 mDestinationView[Dali::Actor::Property::COLOR_MODE] = Dali::ColorMode::USE_OWN_COLOR;
106 // Set animation of Transform
107 startPropertyMap.Insert(Dali::Actor::Property::POSITION, sourcePosition);
108 finishPropertyMap.Insert(Dali::Actor::Property::POSITION, destinationPosition);
110 startPropertyMap.Insert(Dali::Actor::Property::ORIENTATION, sourceOrientation);
111 finishPropertyMap.Insert(Dali::Actor::Property::ORIENTATION, destinationOrientation);
113 startPropertyMap.Insert(Dali::Actor::Property::SCALE, sourceScale);
114 finishPropertyMap.Insert(Dali::Actor::Property::SCALE, destinationScale);
116 Vector4 sourceColor = mSourceView.GetCurrentProperty<Vector4>(Dali::Actor::Property::WORLD_COLOR);
117 startPropertyMap.Insert(Dali::Actor::Property::COLOR, sourceColor);
118 finishPropertyMap.Insert(Dali::Actor::Property::COLOR, targetColor);
120 // Set animation for other properties if source and destination is different.
121 Vector3 sourceSize = mSourceView.GetCurrentProperty<Vector3>(Dali::Actor::Property::SIZE);
122 if(sourceSize != targetSize)
124 startPropertyMap.Insert(Dali::Actor::Property::SIZE, sourceSize);
125 finishPropertyMap.Insert(Dali::Actor::Property::SIZE, targetSize);
128 SetStartPropertyMap(startPropertyMap);
129 SetFinishPropertyMap(finishPropertyMap);
131 // source View becomes transparent during transition.
132 GetImplementation(mSourceView).SetTransparent(true);
134 Dali::Animation animation = GetAnimation();
137 DALI_LOG_ERROR("animation is still not initialized\n");
140 GetImplementation(mDestinationView).CreateTransitions(animation, mSourceView, GetAlphaFunction(), TimePeriod(GetDelay(), GetDuration()));
143 void Transition::OnFinished()
145 if(mShowSourceAfterFinished)
147 GetImplementation(mSourceView).SetTransparent(false);
151 void Transition::ShowSourceAfterFinished(bool showSourceAfterFinished)
153 mShowSourceAfterFinished = showSourceAfterFinished;
156 } // namespace Internal
158 } // namespace Toolkit