2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
18 #include <dali/internal/update/common/property-owner.h>
24 #include <dali/public-api/common/dali-common.h>
25 #include <dali/internal/update/animation/scene-graph-constraint-base.h>
36 PropertyOwner::~PropertyOwner()
38 DisconnectFromSceneGraph();
41 void PropertyOwner::AddObserver(Observer& observer)
43 //Check for duplicates in debug builds
44 DALI_ASSERT_DEBUG( mObservers.End() == std::find( mObservers.Begin(), mObservers.End(), &observer ) );
46 mObservers.PushBack( &observer );
49 void PropertyOwner::RemoveObserver(Observer& observer)
51 // Find the observer...
52 const ConstObserverIter endIter = mObservers.End();
53 for( ObserverIter iter = mObservers.Begin(); iter != endIter; ++iter)
55 if( (*iter) == &observer)
58 mObservers.Erase(iter);
64 bool PropertyOwner::IsObserved()
66 return mObservers.Count() != 0u;
69 void PropertyOwner::DisconnectFromSceneGraph()
71 // Notification for observers
72 const ConstObserverIter endIter = mObservers.End();
73 for( ConstObserverIter iter = mObservers.Begin(); iter != endIter; ++iter)
75 (*iter)->PropertyOwnerDestroyed(*this);
80 // Remove all constraints when disconnected from scene-graph
84 void PropertyOwner::InstallCustomProperty(PropertyBase* property)
86 DALI_ASSERT_DEBUG( NULL != property );
88 mCustomProperties.PushBack( property );
91 void PropertyOwner::ResetToBaseValues( BufferIndex updateBufferIndex )
93 // Reset custom properties
94 const OwnedPropertyIter endIter = mCustomProperties.End();
95 for ( OwnedPropertyIter iter = mCustomProperties.Begin(); endIter != iter; ++iter )
97 (*iter)->ResetToBaseValue( updateBufferIndex );
100 // Reset constraint weights
101 const ConstraintIter constraintEndIter = mConstraints.End();
102 for( ConstraintIter iter = mConstraints.Begin(); constraintEndIter != iter; ++iter )
104 (*iter)->mWeight.ResetToBaseValue( updateBufferIndex );
107 // Notification for derived classes, to reset default properties
108 ResetDefaultProperties( updateBufferIndex );
111 ConstraintOwnerContainer& PropertyOwner::GetConstraints()
116 void PropertyOwner::ApplyConstraint( ConstraintBase* constraint )
118 mConstraints.PushBack( constraint );
120 constraint->OnConnect();
123 void PropertyOwner::RemoveConstraint( ConstraintBase* constraint )
125 // Reset constraint weights
126 const ConstraintIter constraintEndIter = mConstraints.End();
127 for( ConstraintIter iter = mConstraints.Begin(); constraintEndIter != iter; ++iter )
129 if ( *iter == constraint )
131 mConstraints.Erase( iter );
132 return; // We're finished
136 // Should not come here
137 DALI_ASSERT_DEBUG( false && "Constraint missing in RemoveConstraint" );
140 PropertyOwner::PropertyOwner()
144 } // namespace SceneGraph
146 } // namespace Internal