Merge "Internal animation changes" into tizen
[platform/core/uifw/dali-core.git] / dali / internal / update / common / property-owner.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/update/common/property-owner.h>
20
21 // EXTERNAL INCLUDES
22 #include <algorithm>
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/common/dali-common.h>
26 #include <dali/internal/update/animation/scene-graph-constraint-base.h>
27
28 namespace Dali
29 {
30
31 namespace Internal
32 {
33
34 namespace SceneGraph
35 {
36
37 PropertyOwner* PropertyOwner::New()
38 {
39   return new PropertyOwner();
40 }
41
42 PropertyOwner::~PropertyOwner()
43 {
44   Destroy();
45 }
46
47 void PropertyOwner::AddObserver(Observer& observer)
48 {
49   //Check for duplicates in debug builds
50   DALI_ASSERT_DEBUG( mObservers.End() == std::find( mObservers.Begin(), mObservers.End(), &observer ) );
51
52   mObservers.PushBack( &observer );
53 }
54
55 void PropertyOwner::RemoveObserver(Observer& observer)
56 {
57   // Find the observer...
58   const ConstObserverIter endIter =  mObservers.End();
59   for( ObserverIter iter = mObservers.Begin(); iter != endIter; ++iter)
60   {
61     if( (*iter) == &observer)
62     {
63       // erase it
64       mObservers.Erase(iter);
65       break;
66     }
67   }
68 }
69
70 bool PropertyOwner::IsObserved()
71 {
72   return mObservers.Count() != 0u;
73 }
74
75 void PropertyOwner::Destroy()
76 {
77   // Notification for observers
78   const ConstObserverIter endIter = mObservers.End();
79   for( ConstObserverIter iter = mObservers.Begin(); iter != endIter; ++iter)
80   {
81     (*iter)->PropertyOwnerDestroyed(*this);
82   }
83
84   mObservers.Clear();
85
86   // Remove all constraints when disconnected from scene-graph
87   mConstraints.Clear();
88 }
89
90 void PropertyOwner::ConnectToSceneGraph()
91 {
92   // Notification for observers
93   const ConstObserverIter endIter = mObservers.End();
94   for( ConstObserverIter iter = mObservers.Begin(); iter != endIter; ++iter)
95   {
96     (*iter)->PropertyOwnerConnected( *this );
97   }
98 }
99
100 void PropertyOwner::DisconnectFromSceneGraph( BufferIndex updateBufferIndex )
101 {
102   // Notification for observers
103   const ConstObserverIter endIter = mObservers.End();
104   for( ConstObserverIter iter = mObservers.Begin(); iter != endIter; ++iter)
105   {
106     (*iter)->PropertyOwnerDisconnected( updateBufferIndex, *this );
107   }
108
109   // Remove all constraints when disconnected from scene-graph
110   mConstraints.Clear();
111 }
112
113 void PropertyOwner::InstallCustomProperty(PropertyBase* property)
114 {
115   DALI_ASSERT_DEBUG( NULL != property );
116
117   mCustomProperties.PushBack( property );
118 }
119
120 void PropertyOwner::ResetToBaseValues( BufferIndex updateBufferIndex )
121 {
122   // Reset custom properties
123   const OwnedPropertyIter endIter = mCustomProperties.End();
124   for ( OwnedPropertyIter iter = mCustomProperties.Begin(); endIter != iter; ++iter )
125   {
126     (*iter)->ResetToBaseValue( updateBufferIndex );
127   }
128
129   // Reset constraint weights
130   const ConstraintIter constraintEndIter = mConstraints.End();
131   for( ConstraintIter iter = mConstraints.Begin(); constraintEndIter != iter; ++iter )
132   {
133     (*iter)->mWeight.ResetToBaseValue( updateBufferIndex );
134   }
135
136   // Notification for derived classes, to reset default properties
137   ResetDefaultProperties( updateBufferIndex );
138 }
139
140 ConstraintOwnerContainer& PropertyOwner::GetConstraints()
141 {
142   return mConstraints;
143 }
144
145 void PropertyOwner::ApplyConstraint( ConstraintBase* constraint )
146 {
147   mConstraints.PushBack( constraint );
148
149   constraint->OnConnect();
150 }
151
152 void PropertyOwner::RemoveConstraint( ConstraintBase* constraint )
153 {
154   // Reset constraint weights
155   const ConstraintIter constraintEndIter = mConstraints.End();
156   for( ConstraintIter iter = mConstraints.Begin(); constraintEndIter != iter; ++iter )
157   {
158     if ( *iter == constraint )
159     {
160       mConstraints.Erase( iter );
161       return; // We're finished
162     }
163   }
164
165   // Should not come here
166   DALI_ASSERT_DEBUG( false && "Constraint missing in RemoveConstraint" );
167 }
168
169 PropertyOwner::PropertyOwner()
170 {
171 }
172
173 } // namespace SceneGraph
174
175 } // namespace Internal
176
177 } // namespace Dali