1 #ifndef __DALI_INTERNAL_ACTIVE_CONSTRAINT_BASE_H__
2 #define __DALI_INTERNAL_ACTIVE_CONSTRAINT_BASE_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 // http://floralicense.org/license/
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.
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>
44 class AnimatableProperty;
48 * An abstract base class for active constraints.
50 class ActiveConstraintBase : public ProxyObject
54 typedef Dali::Constraint::RemoveAction RemoveAction;
55 typedef Any AnyFunction;
59 * @param[in] messageController Used to send messages to the update-thread.
60 * @param[in] targetPropertyIndex The index of the property being constrained.
62 ActiveConstraintBase( EventToUpdate& messageController, Property::Index targetPropertyIndex );
67 virtual ~ActiveConstraintBase();
70 * Clone an active-constraint.
71 * @return A new active-constraint.
73 virtual ActiveConstraintBase* Clone() = 0;
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.
80 void SetCustomWeightObject( ProxyObject& weightObject, Property::Index weightIndex );
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.
88 void FirstApply( ProxyObject& parent, TimePeriod applyTime );
91 * Called when the ActiveConstraint is removed.
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.
103 * Retrieve the parent of the active-constraint.
104 * @return The parent object, or NULL.
106 ProxyObject* GetParent();
109 * @copydoc Dali::Internal::Object::Supports()
111 virtual bool Supports( Object::Capability capability ) const;
114 * @copydoc Dali::ActiveConstraint::GetTargetObject()
116 Dali::Handle GetTargetObject();
119 * @copydoc Dali::ActiveConstraint::GetTargetProperty()
121 Property::Index GetTargetProperty();
124 * @copydoc Dali::ActiveConstraint::SetWeight()
126 void SetWeight( float weight );
129 * @copydoc Dali::ActiveConstraint::GetCurrentWeight()
131 float GetCurrentWeight() const;
134 * @copydoc Dali::ActiveConstraint::AppliedSignal()
136 ActiveConstraintSignalV2& AppliedSignal();
139 * @copydoc Dali::Constraint::SetRemoveTime()
141 void SetRemoveTime( TimePeriod timePeriod );
144 * @copydoc Dali::Constraint::GetRemoveTime()
146 TimePeriod GetRemoveTime() const;
149 * @copydoc Dali::Constraint::SetAlphaFunction()
151 void SetAlphaFunction(AlphaFunction func);
154 * @copydoc Dali::Constraint::GetAlphaFunction()
156 AlphaFunction GetAlphaFunction() const;
159 * @copydoc Dali::Constraint::SetRemoveAction()
161 void SetRemoveAction(RemoveAction action);
164 * @copydoc Dali::Constraint::GetRemoveAction()
166 RemoveAction GetRemoveAction() const;
169 * @copydoc Dali::Constraint::SetTag()
171 void SetTag(const unsigned int tag);
174 * @copydoc Dali::Constraint::GetTag()
176 unsigned int GetTag() const;
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.
189 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
191 public: // Default property extensions from ProxyObject
194 * @copydoc Dali::Internal::ProxyObject::IsSceneObjectRemovable()
196 virtual bool IsSceneObjectRemovable() const;
199 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyCount()
201 virtual unsigned int GetDefaultPropertyCount() const;
204 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndices()
206 virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
209 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyName()
211 virtual const std::string& GetDefaultPropertyName( Property::Index index ) const;
214 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndex()
216 virtual Property::Index GetDefaultPropertyIndex( const std::string& name ) const;
219 * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyWritable()
221 virtual bool IsDefaultPropertyWritable( Property::Index index ) const;
224 * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAnimatable()
226 virtual bool IsDefaultPropertyAnimatable( Property::Index index ) const;
229 * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAConstraintInput()
231 virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
234 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyType()
236 virtual Property::Type GetDefaultPropertyType( Property::Index index ) const;
239 * @copydoc Dali::Internal::ProxyObject::SetDefaultProperty()
241 virtual void SetDefaultProperty( Property::Index index, const Property::Value& propertyValue );
244 * @copydoc Dali::Internal::ProxyObject::SetCustomProperty()
246 virtual void SetCustomProperty( Property::Index index, const CustomProperty& entry, const Property::Value& value );
249 * @copydoc Dali::Internal::ProxyObject::GetDefaultProperty()
251 virtual Property::Value GetDefaultProperty( Property::Index index ) const;
254 * @copydoc Dali::Internal::ProxyObject::InstallSceneObjectProperty()
256 virtual void InstallSceneObjectProperty( SceneGraph::PropertyBase& newProperty, const std::string& name, unsigned int index );
259 * @copydoc Dali::Internal::ProxyObject::GetSceneObject()
261 virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
264 * @copydoc Dali::Internal::ProxyObject::GetSceneObjectAnimatableProperty()
266 virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
269 * @copydoc Dali::Internal::ProxyObject::GetSceneObjectInputProperty()
271 virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
276 * Helper called after the first apply animation.
277 * @param [in] object The active constraint.
279 static void FirstApplyFinished( Object* object );
282 * Helper called after the remove animation.
283 * @param [in] object The active constraint.
285 static void OnRemoveFinished( Object* object );
287 // To be implemented in derived classes
290 * Used to observe the lifetime of an object with custom "weight" property
291 * @param [in] weightObject The object.
293 virtual void OnCustomWeightSet( ProxyObject& weightObject ) = 0;
296 * Set the parent of the active-constraint; called during OnFirstApply().
297 * @param [in] parent The parent object.
299 virtual void OnFirstApply( ProxyObject& parent ) = 0;
302 * Notification for the derived class, when BeginRemove() is called.
304 virtual void OnBeginRemove() = 0;
308 EventToUpdate& mEventToUpdate;
310 Property::Index mTargetPropertyIndex;
312 ProxyObject* mTargetProxy; ///< The proxy-object owns the active-constraint.
314 const SceneGraph::ConstraintBase* mSceneGraphConstraint;
316 const SceneGraph::AnimatableProperty<float>* mCustomWeight;
318 float mOffstageWeight;
320 TimePeriod mRemoveTime;
322 AlphaFunction mAlphaFunction;
324 RemoveAction mRemoveAction;
329 ActiveConstraintSignalV2 mAppliedSignal;
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
337 } // namespace Internal
339 // Helpers for public-api forwarding methods
341 inline Internal::ActiveConstraintBase& GetImplementation(Dali::ActiveConstraint& constraint)
343 DALI_ASSERT_ALWAYS( constraint && "ActiveConstraint handle is empty" );
345 BaseObject& handle = constraint.GetBaseObject();
347 return static_cast<Internal::ActiveConstraintBase&>(handle);
350 inline const Internal::ActiveConstraintBase& GetImplementation(const Dali::ActiveConstraint& constraint)
352 DALI_ASSERT_ALWAYS( constraint && "ActiveConstraint handle is empty" );
354 const BaseObject& handle = constraint.GetBaseObject();
356 return static_cast<const Internal::ActiveConstraintBase&>(handle);
361 #endif // __DALI_INTERNAL_ACTIVE_CONSTRAINT_BASE_H__