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