Remove a dead virtual method from proxy object
[platform/core/uifw/dali-core.git] / dali / internal / event / animation / active-constraint-base.h
1 #ifndef __DALI_INTERNAL_ACTIVE_CONSTRAINT_BASE_H__
2 #define __DALI_INTERNAL_ACTIVE_CONSTRAINT_BASE_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 // INTERNAL INCLUDES
22 #include <dali/internal/common/owner-pointer.h>
23 #include <dali/internal/event/common/proxy-object.h>
24 #include <dali/public-api/animation/active-constraint.h>
25 #include <dali/public-api/animation/alpha-functions.h>
26 #include <dali/public-api/animation/animation.h>
27 #include <dali/public-api/animation/constraint.h>
28 #include <dali/public-api/animation/time-period.h>
29 #include <dali/public-api/common/dali-common.h>
30 #include <dali/internal/event/animation/constraint-source-impl.h>
31
32 namespace Dali
33 {
34
35 namespace Internal
36 {
37
38 class EventToUpdate;
39 typedef Dali::Vector<ProxyObject*>     ProxyObjectContainer;
40 typedef ProxyObjectContainer::Iterator ProxyObjectIter;
41
42 namespace SceneGraph
43 {
44 class ConstraintBase;
45
46 template <typename T>
47 class AnimatableProperty;
48 }
49
50 /**
51  * An abstract base class for active constraints.
52  */
53 class ActiveConstraintBase : public ProxyObject, public ProxyObject::Observer
54 {
55 public:
56
57   typedef Dali::Constraint::RemoveAction RemoveAction;
58   typedef Any AnyFunction;
59
60   /**
61    * Constructor.
62    * @param[in] messageController Used to send messages to the update-thread.
63    * @param[in] targetPropertyIndex The index of the property being constrained.
64    * @param[in] sources The sources of the input properties.
65    * @param[in] sourceCount The original number of sources; this may not match sources.size() if objects have died.
66    */
67   ActiveConstraintBase( EventToUpdate& messageController, Property::Index targetPropertyIndex, SourceContainer& sources, unsigned int sourceCount );
68
69   /**
70    * Virtual destructor.
71    */
72   virtual ~ActiveConstraintBase();
73
74   /**
75    * Clone an active-constraint.
76    * @return A new active-constraint.
77    */
78   virtual ActiveConstraintBase* Clone() = 0;
79
80   /**
81    * Set a custom "weight" property.
82    * @param[in] weightObject An object with a "weight" float property.
83    * @param[in] weightIndex The index of the weight property.
84    */
85   void SetCustomWeightObject( ProxyObject& weightObject, Property::Index weightIndex );
86
87   /**
88    * Called when the ActiveConstraint is first applied.
89    * @pre The active-constraint does not already have a parent.
90    * @param[in] parent The parent object.
91    * @param[in] applyTime The apply-time for this constraint.
92    */
93   void FirstApply( ProxyObject& parent, TimePeriod applyTime );
94
95   /**
96    * Called when the ActiveConstraint is removed.
97    */
98   void BeginRemove();
99
100   /**
101    * Called when the target object is destroyed.
102    */
103   void OnParentDestroyed();
104
105   /**
106    * Called when the target object is connected to the scene-graph
107    */
108   void OnParentSceneObjectAdded();
109
110   /**
111    * Called when the target object is disconnected from the scene-graph
112    */
113   void OnParentSceneObjectRemoved();
114
115   /**
116    * Retrieve the parent of the active-constraint.
117    * @return The parent object, or NULL.
118    */
119   ProxyObject* GetParent();
120
121   /**
122    * @copydoc Dali::Internal::Object::Supports()
123    */
124   virtual bool Supports( Object::Capability capability ) const;
125
126   /**
127    * @copydoc Dali::ActiveConstraint::GetTargetObject()
128    */
129   Dali::Handle GetTargetObject();
130
131   /**
132    * @copydoc Dali::ActiveConstraint::GetTargetProperty()
133    */
134   Property::Index GetTargetProperty();
135
136   /**
137    * @copydoc Dali::ActiveConstraint::SetWeight()
138    */
139   void SetWeight( float weight );
140
141   /**
142    * @copydoc Dali::ActiveConstraint::GetCurrentWeight()
143    */
144   float GetCurrentWeight() const;
145
146   /**
147    * @copydoc Dali::ActiveConstraint::AppliedSignal()
148    */
149   ActiveConstraintSignalV2& AppliedSignal();
150
151   /**
152    * @copydoc Dali::Constraint::SetAlphaFunction()
153    */
154   void SetAlphaFunction(AlphaFunction func);
155
156   /**
157    * @copydoc Dali::Constraint::GetAlphaFunction()
158    */
159   AlphaFunction GetAlphaFunction() const;
160
161   /**
162    * @copydoc Dali::Constraint::SetRemoveAction()
163    */
164   void SetRemoveAction(RemoveAction action);
165
166   /**
167    * @copydoc Dali::Constraint::GetRemoveAction()
168    */
169   RemoveAction GetRemoveAction() const;
170
171   /**
172    * @copydoc Dali::Constraint::SetTag()
173    */
174   void SetTag(const unsigned int tag);
175
176   /**
177    * @copydoc Dali::Constraint::GetTag()
178    */
179   unsigned int GetTag() const;
180
181   /**
182    * Connects a callback function with the object's signals.
183    * @param[in] object The object providing the signal.
184    * @param[in] tracker Used to disconnect the signal.
185    * @param[in] signalName The signal to connect to.
186    * @param[in] functor A newly allocated FunctorDelegate.
187    * @return True if the signal was connected.
188    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
189    */
190   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
191
192 public: // Default property extensions from ProxyObject
193
194   /**
195    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyCount()
196    */
197   virtual unsigned int GetDefaultPropertyCount() const;
198
199   /**
200    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndices()
201    */
202   virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
203
204   /**
205    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyName()
206    */
207   virtual const char* GetDefaultPropertyName( Property::Index index ) const;
208
209   /**
210    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndex()
211    */
212   virtual Property::Index GetDefaultPropertyIndex( const std::string& name ) const;
213
214   /**
215    * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyWritable()
216    */
217   virtual bool IsDefaultPropertyWritable( Property::Index index ) const;
218
219   /**
220    * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAnimatable()
221    */
222   virtual bool IsDefaultPropertyAnimatable( Property::Index index ) const;
223
224   /**
225    * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAConstraintInput()
226    */
227   virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
228
229   /**
230    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyType()
231    */
232   virtual Property::Type GetDefaultPropertyType( Property::Index index ) const;
233
234   /**
235    * @copydoc Dali::Internal::ProxyObject::SetDefaultProperty()
236    */
237   virtual void SetDefaultProperty( Property::Index index, const Property::Value& propertyValue );
238
239   /**
240    * @copydoc Dali::Internal::ProxyObject::SetCustomProperty()
241    */
242   virtual void SetCustomProperty( Property::Index index, const CustomProperty& entry, const Property::Value& value );
243
244   /**
245    * @copydoc Dali::Internal::ProxyObject::GetDefaultProperty()
246    */
247   virtual Property::Value GetDefaultProperty( Property::Index index ) const;
248
249   /**
250    * @copydoc Dali::Internal::ProxyObject::InstallSceneObjectProperty()
251    */
252   virtual void InstallSceneObjectProperty( SceneGraph::PropertyBase& newProperty, const std::string& name, unsigned int index );
253
254   /**
255    * @copydoc Dali::Internal::ProxyObject::GetSceneObject()
256    */
257   virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
258
259   /**
260    * @copydoc Dali::Internal::ProxyObject::GetSceneObjectAnimatableProperty()
261    */
262   virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
263
264   /**
265    * @copydoc Dali::Internal::ProxyObject::GetSceneObjectInputProperty()
266    */
267   virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
268
269 public: // ProxyObject::Observer methods
270
271   /**
272    * @copydoc ProxyObject::Observer::SceneObjectAdded()
273    */
274   virtual void SceneObjectAdded( ProxyObject& proxy );
275
276   /**
277    * @copydoc ProxyObject::Observer::SceneObjectRemoved()
278    */
279   virtual void SceneObjectRemoved( ProxyObject& proxy );
280
281   /**
282    * @copydoc ProxyObject::Observer::ProxyDestroyed()
283    */
284   virtual void ProxyDestroyed( ProxyObject& proxy );
285
286 private:
287
288   /**
289    * Helper to observe a proxy, if not already observing it
290    */
291   void ObserveProxy( ProxyObject& proxy );
292
293   /**
294    * Helper to stop observing proxies
295    */
296   void StopObservation();
297
298   /**
299    * Helper called after the first apply animation.
300    * @param [in] object The active constraint.
301    */
302   static void FirstApplyFinished( Object* object );
303
304   // To be implemented in derived classes
305
306   /**
307    * Create and connect a constraint for a scene-object.
308    */
309   virtual void ConnectConstraint() = 0;
310
311 protected:
312
313   EventToUpdate& mEventToUpdate;
314
315   Property::Index mTargetPropertyIndex;
316   SourceContainer mSources;
317   const unsigned int mSourceCount;
318
319   ProxyObject* mTargetProxy; ///< The proxy-object owns the active-constraint.
320   ProxyObjectContainer mObservedProxies; // We don't observe the same object twice
321
322   const SceneGraph::ConstraintBase* mSceneGraphConstraint;
323
324   const SceneGraph::AnimatableProperty<float>* mCustomWeight;
325
326   float mOffstageWeight;
327
328   AlphaFunction mAlphaFunction;
329
330   RemoveAction mRemoveAction;
331   unsigned int mTag;
332
333 private:
334
335   ActiveConstraintSignalV2 mAppliedSignal;
336
337   Dali::Animation mApplyAnimation;  ///< Used to automatically animate weight from 0.0f -> 1.0f
338
339 };
340
341 } // namespace Internal
342
343 // Helpers for public-api forwarding methods
344
345 inline Internal::ActiveConstraintBase& GetImplementation(Dali::ActiveConstraint& constraint)
346 {
347   DALI_ASSERT_ALWAYS( constraint && "ActiveConstraint handle is empty" );
348
349   BaseObject& handle = constraint.GetBaseObject();
350
351   return static_cast<Internal::ActiveConstraintBase&>(handle);
352 }
353
354 inline const Internal::ActiveConstraintBase& GetImplementation(const Dali::ActiveConstraint& constraint)
355 {
356   DALI_ASSERT_ALWAYS( constraint && "ActiveConstraint handle is empty" );
357
358   const BaseObject& handle = constraint.GetBaseObject();
359
360   return static_cast<const Internal::ActiveConstraintBase&>(handle);
361 }
362
363 } // namespace Dali
364
365 #endif // __DALI_INTERNAL_ACTIVE_CONSTRAINT_BASE_H__