2 * Copyright (c) 2018 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>
31 Constrainer::Constrainer()
32 :Object( nullptr ) // we don't have our own scene object
36 Constrainer::~Constrainer()
38 //Remove all the constraints created by the object
39 uint32_t tag = static_cast<uint32_t>( reinterpret_cast<uintptr_t>( this ) ); // taking 32bits of this as tag
40 const ObjectIter end = mObservedObjects.End();
41 for( ObjectIter iter = mObservedObjects.Begin(); iter != end; ++iter )
43 //Remove Constrainer from the observers list of the object
44 (*iter)->RemoveObserver( *this );
47 (*iter)->RemoveConstraints( tag );
51 void Constrainer::ObjectDestroyed( Object& object )
53 //Remove object from the list of observed
54 const ObjectIter end = mObservedObjects.End();
55 for( ObjectIter iter = mObservedObjects.Begin(); iter != end; ++iter )
57 if( *iter == &object )
59 mObservedObjects.Erase(iter);
65 void Constrainer::Remove( Dali::Handle& target )
67 uint32_t tag = static_cast<uint32_t>( reinterpret_cast<uintptr_t>( this ) ); // taking 32bits of this as tag
68 Object& object = GetImplementation(target);
69 const ObjectIter end = mObservedObjects.End();
70 for( ObjectIter iter = mObservedObjects.Begin(); iter != end; ++iter )
72 if( *iter == &object )
74 //Stop observing the object
75 (*iter)->RemoveObserver( *this );
77 //Remove constraints created in the object
78 target.RemoveConstraints( tag );
80 //Remove object from the vector of observed objects
81 mObservedObjects.Erase(iter);
86 void Constrainer::Observe( Dali::Handle& handle )
88 Object& object = GetImplementation(handle);
90 //Add the object to the list of observed objects if it is not in it already
91 const ObjectIter end = mObservedObjects.End();
92 ObjectIter iter = mObservedObjects.Begin();
93 for(; iter != end; ++iter )
95 if( *iter == &object )
103 //Start observing the object
104 object.AddObserver( *this );
106 //Add object in the observed objects vector
107 mObservedObjects.PushBack( &object );
111 } // namespace Internal