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/internal/event/animation/constrainer.h>
22 #include <dali/internal/event/animation/constraint-source-impl.h>
23 #include <dali/public-api/animation/constraint.h>
29 Constrainer::Constrainer()
30 : Object(nullptr) // we don't have our own scene object
34 Constrainer::~Constrainer()
36 //Remove all the constraints created by the object
37 uint32_t tag = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(this)); // taking 32bits of this as tag
38 const ObjectIter end = mObservedObjects.End();
39 for(ObjectIter iter = mObservedObjects.Begin(); iter != end; ++iter)
41 //Remove Constrainer from the observers list of the object
42 (*iter)->RemoveObserver(*this);
45 (*iter)->RemoveConstraints(tag);
49 void Constrainer::ObjectDestroyed(Object& object)
51 //Remove object from the list of observed
52 const ObjectIter end = mObservedObjects.End();
53 for(ObjectIter iter = mObservedObjects.Begin(); iter != end; ++iter)
57 mObservedObjects.Erase(iter);
63 void Constrainer::Remove(Dali::Handle& target)
65 uint32_t tag = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(this)); // taking 32bits of this as tag
66 Object& object = GetImplementation(target);
67 const ObjectIter end = mObservedObjects.End();
68 for(ObjectIter iter = mObservedObjects.Begin(); iter != end; ++iter)
72 //Stop observing the object
73 (*iter)->RemoveObserver(*this);
75 //Remove constraints created in the object
76 target.RemoveConstraints(tag);
78 //Remove object from the vector of observed objects
79 mObservedObjects.Erase(iter);
84 void Constrainer::Observe(Dali::Handle& handle)
86 Object& object = GetImplementation(handle);
88 //Add the object to the list of observed objects if it is not in it already
89 const ObjectIter end = mObservedObjects.End();
90 ObjectIter iter = mObservedObjects.Begin();
91 for(; iter != end; ++iter)
101 //Start observing the object
102 object.AddObserver(*this);
104 //Add object in the observed objects vector
105 mObservedObjects.PushBack(&object);
109 } // namespace Internal