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