2ebc1b730198f31d211f4781a0c1335af959a9b1
[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
31 namespace Dali
32 {
33
34 namespace Internal
35 {
36
37 class EventToUpdate;
38 class ProxyObject;
39
40 namespace SceneGraph
41 {
42 class ConstraintBase;
43
44 template <typename T>
45 class AnimatableProperty;
46 }
47
48 /**
49  * An abstract base class for active constraints.
50  */
51 class ActiveConstraintBase : public ProxyObject
52 {
53 public:
54
55   typedef Dali::Constraint::RemoveAction RemoveAction;
56   typedef Any AnyFunction;
57
58   /**
59    * Constructor.
60    * @param[in] messageController Used to send messages to the update-thread.
61    * @param[in] targetPropertyIndex The index of the property being constrained.
62    */
63   ActiveConstraintBase( EventToUpdate& messageController, Property::Index targetPropertyIndex );
64
65   /**
66    * Virtual destructor.
67    */
68   virtual ~ActiveConstraintBase();
69
70   /**
71    * Clone an active-constraint.
72    * @return A new active-constraint.
73    */
74   virtual ActiveConstraintBase* Clone() = 0;
75
76   /**
77    * Set a custom "weight" property.
78    * @param[in] weightObject An object with a "weight" float property.
79    * @param[in] weightIndex The index of the weight property.
80    */
81   void SetCustomWeightObject( ProxyObject& weightObject, Property::Index weightIndex );
82
83   /**
84    * Called when the ActiveConstraint is first applied.
85    * @pre The active-constraint does not already have a parent.
86    * @param[in] parent The parent object.
87    * @param[in] applyTime The apply-time for this constraint.
88    */
89   void FirstApply( ProxyObject& parent, TimePeriod applyTime );
90
91   /**
92    * Called when the ActiveConstraint is removed.
93    */
94   void BeginRemove();
95
96   /**
97    * Query whether the constraint is being removed.
98    * This is only possible if mRemoveTime.durationSeconds is non-zero.
99    * @return True if constraint is being removed.
100    */
101   bool IsRemoving();
102
103   /**
104    * Retrieve the parent of the active-constraint.
105    * @return The parent object, or NULL.
106    */
107   ProxyObject* GetParent();
108
109   /**
110    * @copydoc Dali::Internal::Object::Supports()
111    */
112   virtual bool Supports( Object::Capability capability ) const;
113
114   /**
115    * @copydoc Dali::ActiveConstraint::GetTargetObject()
116    */
117   Dali::Handle GetTargetObject();
118
119   /**
120    * @copydoc Dali::ActiveConstraint::GetTargetProperty()
121    */
122   Property::Index GetTargetProperty();
123
124   /**
125    * @copydoc Dali::ActiveConstraint::SetWeight()
126    */
127   void SetWeight( float weight );
128
129   /**
130    * @copydoc Dali::ActiveConstraint::GetCurrentWeight()
131    */
132   float GetCurrentWeight() const;
133
134   /**
135    * @copydoc Dali::ActiveConstraint::AppliedSignal()
136    */
137   ActiveConstraintSignalV2& AppliedSignal();
138
139   /**
140    * @copydoc Dali::Constraint::SetRemoveTime()
141    */
142   void SetRemoveTime( TimePeriod timePeriod );
143
144   /**
145    * @copydoc Dali::Constraint::GetRemoveTime()
146    */
147   TimePeriod GetRemoveTime() const;
148
149   /**
150    * @copydoc Dali::Constraint::SetAlphaFunction()
151    */
152   void SetAlphaFunction(AlphaFunction func);
153
154   /**
155    * @copydoc Dali::Constraint::GetAlphaFunction()
156    */
157   AlphaFunction GetAlphaFunction() const;
158
159   /**
160    * @copydoc Dali::Constraint::SetRemoveAction()
161    */
162   void SetRemoveAction(RemoveAction action);
163
164   /**
165    * @copydoc Dali::Constraint::GetRemoveAction()
166    */
167   RemoveAction GetRemoveAction() const;
168
169   /**
170    * @copydoc Dali::Constraint::SetTag()
171    */
172   void SetTag(const unsigned int tag);
173
174   /**
175    * @copydoc Dali::Constraint::GetTag()
176    */
177   unsigned int GetTag() const;
178
179
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::IsSceneObjectRemovable()
196    */
197   virtual bool IsSceneObjectRemovable() const;
198
199   /**
200    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyCount()
201    */
202   virtual unsigned int GetDefaultPropertyCount() const;
203
204   /**
205    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndices()
206    */
207   virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
208
209   /**
210    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyName()
211    */
212   virtual const std::string& GetDefaultPropertyName( Property::Index index ) const;
213
214   /**
215    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndex()
216    */
217   virtual Property::Index GetDefaultPropertyIndex( const std::string& name ) const;
218
219   /**
220    * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyWritable()
221    */
222   virtual bool IsDefaultPropertyWritable( Property::Index index ) const;
223
224   /**
225    * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAnimatable()
226    */
227   virtual bool IsDefaultPropertyAnimatable( Property::Index index ) const;
228
229   /**
230    * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAConstraintInput()
231    */
232   virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
233
234   /**
235    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyType()
236    */
237   virtual Property::Type GetDefaultPropertyType( Property::Index index ) const;
238
239   /**
240    * @copydoc Dali::Internal::ProxyObject::SetDefaultProperty()
241    */
242   virtual void SetDefaultProperty( Property::Index index, const Property::Value& propertyValue );
243
244   /**
245    * @copydoc Dali::Internal::ProxyObject::SetCustomProperty()
246    */
247   virtual void SetCustomProperty( Property::Index index, const CustomProperty& entry, const Property::Value& value );
248
249   /**
250    * @copydoc Dali::Internal::ProxyObject::GetDefaultProperty()
251    */
252   virtual Property::Value GetDefaultProperty( Property::Index index ) const;
253
254   /**
255    * @copydoc Dali::Internal::ProxyObject::InstallSceneObjectProperty()
256    */
257   virtual void InstallSceneObjectProperty( SceneGraph::PropertyBase& newProperty, const std::string& name, unsigned int index );
258
259   /**
260    * @copydoc Dali::Internal::ProxyObject::GetSceneObject()
261    */
262   virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
263
264   /**
265    * @copydoc Dali::Internal::ProxyObject::GetSceneObjectAnimatableProperty()
266    */
267   virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
268
269   /**
270    * @copydoc Dali::Internal::ProxyObject::GetSceneObjectInputProperty()
271    */
272   virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
273
274 private:
275
276   /**
277    * Helper called after the first apply animation.
278    * @param [in] object The active constraint.
279    */
280   static void FirstApplyFinished( Object* object );
281
282   /**
283    * Helper called after the remove animation.
284    * @param [in] object The active constraint.
285    */
286   static void OnRemoveFinished( Object* object );
287
288   // To be implemented in derived classes
289
290   /**
291    * Used to observe the lifetime of an object with custom "weight" property
292    * @param [in] weightObject The object.
293    */
294   virtual void OnCustomWeightSet( ProxyObject& weightObject ) = 0;
295
296   /**
297    * Set the parent of the active-constraint; called during OnFirstApply().
298    * @param [in] parent The parent object.
299    */
300   virtual void OnFirstApply( ProxyObject& parent ) = 0;
301
302   /**
303    * Notification for the derived class, when BeginRemove() is called.
304    */
305   virtual void OnBeginRemove() = 0;
306
307 protected:
308
309   EventToUpdate& mEventToUpdate;
310
311   Property::Index mTargetPropertyIndex;
312
313   ProxyObject* mTargetProxy; ///< The proxy-object owns the active-constraint.
314
315   const SceneGraph::ConstraintBase* mSceneGraphConstraint;
316
317   const SceneGraph::AnimatableProperty<float>* mCustomWeight;
318
319   float mOffstageWeight;
320
321   TimePeriod mRemoveTime;
322
323   AlphaFunction mAlphaFunction;
324
325   RemoveAction mRemoveAction;
326   unsigned int mTag;
327
328 private:
329
330   ActiveConstraintSignalV2 mAppliedSignal;
331
332   Dali::Animation mApplyAnimation;  ///< Used to automatically animate weight from 0.0f -> 1.0f
333   Dali::Animation mRemoveAnimation; ///< Used to automatically animate weight back to 0.0f
334
335
336 };
337
338 } // namespace Internal
339
340 // Helpers for public-api forwarding methods
341
342 inline Internal::ActiveConstraintBase& GetImplementation(Dali::ActiveConstraint& constraint)
343 {
344   DALI_ASSERT_ALWAYS( constraint && "ActiveConstraint handle is empty" );
345
346   BaseObject& handle = constraint.GetBaseObject();
347
348   return static_cast<Internal::ActiveConstraintBase&>(handle);
349 }
350
351 inline const Internal::ActiveConstraintBase& GetImplementation(const Dali::ActiveConstraint& constraint)
352 {
353   DALI_ASSERT_ALWAYS( constraint && "ActiveConstraint handle is empty" );
354
355   const BaseObject& handle = constraint.GetBaseObject();
356
357   return static_cast<const Internal::ActiveConstraintBase&>(handle);
358 }
359
360 } // namespace Dali
361
362 #endif // __DALI_INTERNAL_ACTIVE_CONSTRAINT_BASE_H__