2 * Copyright (c) 2014 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/update/common/property-owner.h>
25 #include <dali/public-api/common/dali-common.h>
26 #include <dali/internal/update/animation/scene-graph-constraint-base.h>
37 PropertyOwner* PropertyOwner::New()
39 return new PropertyOwner();
42 PropertyOwner::~PropertyOwner()
47 void PropertyOwner::AddObserver(Observer& observer)
49 //Check for duplicates in debug builds
50 DALI_ASSERT_DEBUG( mObservers.End() == std::find( mObservers.Begin(), mObservers.End(), &observer ) );
52 mObservers.PushBack( &observer );
55 void PropertyOwner::RemoveObserver(Observer& observer)
57 // Find the observer...
58 const ConstObserverIter endIter = mObservers.End();
59 for( ObserverIter iter = mObservers.Begin(); iter != endIter; ++iter)
61 if( (*iter) == &observer)
64 mObservers.Erase(iter);
70 bool PropertyOwner::IsObserved()
72 return mObservers.Count() != 0u;
75 void PropertyOwner::Destroy()
77 // Notification for observers
78 const ConstObserverIter endIter = mObservers.End();
79 for( ConstObserverIter iter = mObservers.Begin(); iter != endIter; ++iter)
81 (*iter)->PropertyOwnerDestroyed(*this);
86 // Remove all constraints when disconnected from scene-graph
90 void PropertyOwner::ConnectToSceneGraph()
92 // Notification for observers
93 const ConstObserverIter endIter = mObservers.End();
94 for( ConstObserverIter iter = mObservers.Begin(); iter != endIter; ++iter)
96 (*iter)->PropertyOwnerConnected( *this );
100 void PropertyOwner::DisconnectFromSceneGraph( BufferIndex updateBufferIndex )
102 // Notification for observers
103 const ConstObserverIter endIter = mObservers.End();
104 for( ConstObserverIter iter = mObservers.Begin(); iter != endIter; ++iter)
106 (*iter)->PropertyOwnerDisconnected( updateBufferIndex, *this );
109 // Remove all constraints when disconnected from scene-graph
110 mConstraints.Clear();
113 void PropertyOwner::InstallCustomProperty(PropertyBase* property)
115 DALI_ASSERT_DEBUG( NULL != property );
117 mCustomProperties.PushBack( property );
120 void PropertyOwner::ResetToBaseValues( BufferIndex updateBufferIndex )
122 // Reset custom properties
123 const OwnedPropertyIter endIter = mCustomProperties.End();
124 for ( OwnedPropertyIter iter = mCustomProperties.Begin(); endIter != iter; ++iter )
126 (*iter)->ResetToBaseValue( updateBufferIndex );
129 // Notification for derived classes, to reset default properties
130 ResetDefaultProperties( updateBufferIndex );
133 ConstraintOwnerContainer& PropertyOwner::GetConstraints()
138 void PropertyOwner::ApplyConstraint( ConstraintBase* constraint )
140 mConstraints.PushBack( constraint );
142 constraint->OnConnect();
145 void PropertyOwner::RemoveConstraint( ConstraintBase* constraint )
147 const ConstraintIter constraintEndIter = mConstraints.End();
148 for( ConstraintIter iter = mConstraints.Begin(); constraintEndIter != iter; ++iter )
150 if ( *iter == constraint )
152 mConstraints.Erase( iter );
153 return; // We're finished
157 //it may be that the constraint has already been removed e.g. from disconnection from scene graph, so nothing needs to be done
160 PropertyOwner::PropertyOwner()
164 void PropertyOwner::AddUniformMapping( UniformPropertyMapping* map )
166 mUniformMaps.Add( map );
169 void PropertyOwner::RemoveUniformMapping( const std::string& uniformName )
171 mUniformMaps.Remove( uniformName );
174 const UniformMap& PropertyOwner::GetUniformMap() const
179 void PropertyOwner::AddUniformMapObserver( UniformMap::Observer& observer )
181 mUniformMaps.AddObserver( observer );
184 void PropertyOwner::RemoveUniformMapObserver( UniformMap::Observer& observer )
186 mUniformMaps.RemoveObserver( observer );
191 } // namespace SceneGraph
193 } // namespace Internal