Internal animation changes
[platform/core/uifw/dali-core.git] / dali / internal / update / common / property-owner.h
1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22
23 // INTERNAL INCLUDES
24 #include <dali/public-api/common/dali-vector.h>
25 #include <dali/internal/common/message.h>
26 #include <dali/internal/common/owner-container.h>
27 #include <dali/internal/update/common/property-base.h>
28 #include <dali/internal/update/common/scene-graph-buffers.h>
29 #include <dali/internal/update/animation/scene-graph-constraint-declarations.h>
30
31 namespace Dali
32 {
33
34 namespace Internal
35 {
36
37 namespace SceneGraph
38 {
39
40 class PropertyOwner;
41
42 typedef OwnerContainer< PropertyBase* > OwnedPropertyContainer;
43 typedef OwnedPropertyContainer::Iterator  OwnedPropertyIter;
44
45 /**
46  * An update-thread object which own properties.
47  * This allows observers to track the lifetime of the object & its properties.
48  */
49 class PropertyOwner
50 {
51 public:
52
53   class Observer
54   {
55   public:
56
57     /**
58      * Called when the observable object is connected to the scene graph.
59      * @param[in] owner A reference to the connected PropertyOwner
60      */
61     virtual void PropertyOwnerConnected( PropertyOwner& owner ) = 0;
62
63     /**
64      * Called when the observable object is disconnected from the scene graph.
65      * @param[in] currentBufferIndex The buffer to reset.
66      * @param[in] owner A reference to the disconnected PropertyOwner
67      */
68     virtual void PropertyOwnerDisconnected( BufferIndex updateBufferIndex, PropertyOwner& owner ) = 0;
69
70     /**
71      * Called shortly before the observable object is destroyed.
72      *
73      * @note Cleanup should be done in both this and PropertyOwnerDisconnected as PropertyOwnerDisconnected
74      * may not be called (i.e. when shutting down).
75      */
76     virtual void PropertyOwnerDestroyed( PropertyOwner& owner ) = 0;
77   };
78
79   /**
80    * Create a property owner.
81    * @return A newly allocated object.
82    */
83   static PropertyOwner* New();
84
85   /**
86    * Virtual destructor; this is intended as a base class.
87    */
88   virtual ~PropertyOwner();
89
90   /**
91    * Add an observer.
92    * The observer is responsible for calling RemoveObserver(*this) during its own destruction.
93    * Connecting an actor-side object as an observer is not allowed, due to thread-safety issues.
94    * @param[in] observer The observer.
95    */
96   void AddObserver(Observer& observer);
97
98   /**
99    * Remove an observer.
100    * @param[in] observer The observer.
101    */
102   void RemoveObserver(Observer& observer);
103
104   /**
105    * This method can be used to determine if there is an animation or
106    * constraint that is using this property owner.
107    * @return true if there are observers.
108    */
109   bool IsObserved();
110
111   /**
112    * Called just before destruction to disconnect all observers and remove constraints.
113    * This occurs when the object is in the process of being destroyed.
114    */
115   void Destroy();
116
117   /**
118    * Notify all observers that the object has been connected
119    * This occurs when the object is connected to the scene-graph during UpdateManager::Update().
120    */
121   void ConnectToSceneGraph();
122
123   /**
124    * Notify all observers that the object has been disconnected and remove constraints.
125    * This occurs when the object is disconnected from the scene-graph during UpdateManager::Update().
126    * @param[in] currentBufferIndex The current update buffer.
127    */
128   void DisconnectFromSceneGraph( BufferIndex updateBufferIndex );
129
130   /**
131    * Install a custom property.
132    * @post The PropertyOwner takes ownership of the property.
133    * @param[in] property A pointer to a newly allocated property.
134    */
135   void InstallCustomProperty(PropertyBase* property);
136
137   /**
138    * Retrieve the custom properties owned by the object.
139    * @return A container of properties.
140    */
141   OwnedPropertyContainer& GetCustomProperties()
142   {
143     return mCustomProperties;
144   }
145
146   /**
147    * Retrieve the custom properties owned by the object.
148    * @return A container of properties.
149    */
150   const OwnedPropertyContainer& GetCustomProperties() const
151   {
152     return mCustomProperties;
153   }
154
155   /**
156    * Reset animatable properties to the corresponding base values.
157    * @param[in] currentBufferIndex The buffer to reset.
158    * @post The ResetDefaultProperties method is called, during which derived classes can reset default properties.
159    */
160   void ResetToBaseValues( BufferIndex updateBufferIndex );
161
162   // Constraints
163
164   /**
165    * Apply a constraint.
166    * @param[in] constraint The constraint to apply.
167    */
168   void ApplyConstraint( ConstraintBase* constraint );
169
170   /**
171    * Begin removal of constraints.
172    * @param[in] constraint The constraint to remove.
173    */
174   void RemoveConstraint( ConstraintBase* constraint );
175
176   /**
177    * Retrieve the constraints that are currently applied.
178    * @return A container of constraints.
179    */
180   ConstraintOwnerContainer& GetConstraints();
181
182 protected:
183
184   /**
185    * Protected constructor.
186    */
187   PropertyOwner();
188
189 private:
190
191   // Undefined
192   PropertyOwner(const PropertyOwner&);
193
194   // Undefined
195   PropertyOwner& operator=(const PropertyOwner& rhs);
196
197   /**
198    * Called after ResetToBaseValues; derived classes should reset any default properties.
199    * @param[in] currentBufferIndex The buffer to reset.
200    */
201   virtual void ResetDefaultProperties( BufferIndex updateBufferIndex ) {}
202
203 protected:
204
205   OwnedPropertyContainer mCustomProperties; ///< Properties provided with InstallCustomProperty()
206
207 private:
208
209   typedef Dali::Vector<PropertyOwner::Observer*> ObserverContainer;
210   typedef ObserverContainer::Iterator ObserverIter;
211   typedef ObserverContainer::ConstIterator ConstObserverIter;
212
213   ObserverContainer mObservers; ///< Container of observer raw-pointers (not owned)
214
215   ConstraintOwnerContainer mConstraints; ///< Container of owned constraints
216
217 };
218
219 } // namespace SceneGraph
220
221 } // namespace Internal
222
223 } // namespace Dali
224
225 #endif // __DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_H__