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::New()
38 return new PropertyOwner();
41 PropertyOwner::~PropertyOwner()
43 DisconnectFromSceneGraph();
46 void PropertyOwner::AddObserver(Observer& observer)
48 //Check for duplicates in debug builds
49 DALI_ASSERT_DEBUG( mObservers.End() == std::find( mObservers.Begin(), mObservers.End(), &observer ) );
51 mObservers.PushBack( &observer );
54 void PropertyOwner::RemoveObserver(Observer& observer)
56 // Find the observer...
57 const ConstObserverIter endIter = mObservers.End();
58 for( ObserverIter iter = mObservers.Begin(); iter != endIter; ++iter)
60 if( (*iter) == &observer)
63 mObservers.Erase(iter);
69 bool PropertyOwner::IsObserved()
71 return mObservers.Count() != 0u;
74 void PropertyOwner::DisconnectFromSceneGraph()
76 // Notification for observers
77 const ConstObserverIter endIter = mObservers.End();
78 for( ConstObserverIter iter = mObservers.Begin(); iter != endIter; ++iter)
80 (*iter)->PropertyOwnerDestroyed(*this);
85 // Remove all constraints when disconnected from scene-graph
89 void PropertyOwner::InstallCustomProperty(PropertyBase* property)
91 DALI_ASSERT_DEBUG( NULL != property );
93 mCustomProperties.PushBack( property );
96 void PropertyOwner::ResetToBaseValues( BufferIndex updateBufferIndex )
98 // Reset custom properties
99 const OwnedPropertyIter endIter = mCustomProperties.End();
100 for ( OwnedPropertyIter iter = mCustomProperties.Begin(); endIter != iter; ++iter )
102 (*iter)->ResetToBaseValue( updateBufferIndex );
105 // Reset constraint weights
106 const ConstraintIter constraintEndIter = mConstraints.End();
107 for( ConstraintIter iter = mConstraints.Begin(); constraintEndIter != iter; ++iter )
109 (*iter)->mWeight.ResetToBaseValue( updateBufferIndex );
112 // Notification for derived classes, to reset default properties
113 ResetDefaultProperties( updateBufferIndex );
116 ConstraintOwnerContainer& PropertyOwner::GetConstraints()
121 void PropertyOwner::ApplyConstraint( ConstraintBase* constraint )
123 mConstraints.PushBack( constraint );
125 constraint->OnConnect();
128 void PropertyOwner::RemoveConstraint( ConstraintBase* constraint )
130 // Reset constraint weights
131 const ConstraintIter constraintEndIter = mConstraints.End();
132 for( ConstraintIter iter = mConstraints.Begin(); constraintEndIter != iter; ++iter )
134 if ( *iter == constraint )
136 mConstraints.Erase( iter );
137 return; // We're finished
141 // Should not come here
142 DALI_ASSERT_DEBUG( false && "Constraint missing in RemoveConstraint" );
145 PropertyOwner::PropertyOwner()
149 } // namespace SceneGraph
151 } // namespace Internal