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-set-impl.h>
22 #include <dali/integration-api/adaptor-framework/adaptor.h>
23 #include <dali/integration-api/debug.h>
24 #include <dali/public-api/object/type-registry.h>
35 static constexpr std::string_view SIGNAL_FINISHED = "finished";
39 return Dali::Toolkit::TransitionSet::New();
42 TypeRegistration mType(typeid(Dali::Toolkit::TransitionSet), typeid(Dali::BaseHandle), Create);
44 SignalConnectorType signalConnector1(mType, std::string(SIGNAL_FINISHED), &TransitionSet::DoConnectSignal);
46 } // anonymous namespace
48 TransitionSetPtr TransitionSet::New()
50 TransitionSetPtr transitionSet = new TransitionSet();
55 TransitionSet::TransitionSet()
59 TransitionSet::~TransitionSet()
65 void TransitionSet::AddTransition(TransitionBasePtr transition)
67 mTransitions.push_back(transition);
70 TransitionBase* TransitionSet::GetTransitionAt(uint32_t index) const
72 TransitionBase* result(nullptr);
73 if(index < GetTransitionCount())
75 result = mTransitions[index].Get();
79 DALI_LOG_ERROR("Error: Invalid index to TextureSet::GetTexture\n");
85 uint32_t TransitionSet::GetTransitionCount() const
87 return mTransitions.size();
90 void TransitionSet::QueueToPlay()
92 for(auto&& transition : mTransitions)
94 transition->SetPlay(Dali::Toolkit::TransitionSet(this));
97 Adaptor::Get().RegisterProcessor(*this, true);
98 Adaptor::Get().RegisterProcessor(*this, false);
101 void TransitionSet::TransitionPreProcess()
103 float lastDuration = 0.0f;
104 for(auto&& transition : mTransitions)
106 if(lastDuration <= transition->GetDuration() + transition->GetDelay())
108 lastDuration = transition->GetDuration() + transition->GetDelay();
111 mAnimation = Dali::Animation::New(lastDuration);
113 for(auto&& transition : mTransitions)
115 transition->PreProcess(mAnimation);
119 void TransitionSet::TransitionStart()
122 for(auto&& transition : mTransitions)
124 mPlaylist.push_back(transition);
128 mAnimation.FinishedSignal().Connect(this, &TransitionSet::TransitionFinished);
132 void TransitionSet::TransitionFinished(Dali::Animation& source)
134 for(auto&& transition : mTransitions)
136 transition->TransitionFinished();
143 Dali::Toolkit::TransitionSet::TransitionSetSignalType& TransitionSet::FinishedSignal()
145 return mFinishedSignal;
148 void TransitionSet::EmitSignalFinish()
150 if(!mFinishedSignal.Empty())
152 Dali::Toolkit::TransitionSet handle(this);
153 mFinishedSignal.Emit(handle);
157 bool TransitionSet::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor)
159 bool connected(false);
160 TransitionSet* transitionSet = static_cast<TransitionSet*>(object); // TypeRegistry guarantees that this is the correct type.
162 if(SIGNAL_FINISHED == signalName)
164 transitionSet->FinishedSignal().Connect(tracker, functor);
171 void TransitionSet::Process(bool postProcessor)
175 TransitionPreProcess();
182 if(Adaptor::IsAvailable())
184 Adaptor::Get().UnregisterProcessor(*this, postProcessor);
188 } // namespace Internal
190 } // namespace Toolkit