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 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
45 class AnimatableProperty;
49 * An abstract base class for active constraints.
51 class ActiveConstraintBase : public ProxyObject
55 typedef Dali::Constraint::RemoveAction RemoveAction;
56 typedef Any AnyFunction;
60 * @param[in] messageController Used to send messages to the update-thread.
61 * @param[in] targetPropertyIndex The index of the property being constrained.
63 ActiveConstraintBase( EventToUpdate& messageController, Property::Index targetPropertyIndex );
68 virtual ~ActiveConstraintBase();
71 * Clone an active-constraint.
72 * @return A new active-constraint.
74 virtual ActiveConstraintBase* Clone() = 0;
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.
81 void SetCustomWeightObject( ProxyObject& weightObject, Property::Index weightIndex );
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.
89 void FirstApply( ProxyObject& parent, TimePeriod applyTime );
92 * Called when the ActiveConstraint is removed.
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.
104 * Retrieve the parent of the active-constraint.
105 * @return The parent object, or NULL.
107 ProxyObject* GetParent();
110 * @copydoc Dali::Internal::Object::Supports()
112 virtual bool Supports( Object::Capability capability ) const;
115 * @copydoc Dali::ActiveConstraint::GetTargetObject()
117 Dali::Handle GetTargetObject();
120 * @copydoc Dali::ActiveConstraint::GetTargetProperty()
122 Property::Index GetTargetProperty();
125 * @copydoc Dali::ActiveConstraint::SetWeight()
127 void SetWeight( float weight );
130 * @copydoc Dali::ActiveConstraint::GetCurrentWeight()
132 float GetCurrentWeight() const;
135 * @copydoc Dali::ActiveConstraint::AppliedSignal()
137 ActiveConstraintSignalV2& AppliedSignal();
140 * @copydoc Dali::Constraint::SetRemoveTime()
142 void SetRemoveTime( TimePeriod timePeriod );
145 * @copydoc Dali::Constraint::GetRemoveTime()
147 TimePeriod GetRemoveTime() const;
150 * @copydoc Dali::Constraint::SetAlphaFunction()
152 void SetAlphaFunction(AlphaFunction func);
155 * @copydoc Dali::Constraint::GetAlphaFunction()
157 AlphaFunction GetAlphaFunction() const;
160 * @copydoc Dali::Constraint::SetRemoveAction()
162 void SetRemoveAction(RemoveAction action);
165 * @copydoc Dali::Constraint::GetRemoveAction()
167 RemoveAction GetRemoveAction() const;
170 * @copydoc Dali::Constraint::SetTag()
172 void SetTag(const unsigned int tag);
175 * @copydoc Dali::Constraint::GetTag()
177 unsigned int GetTag() const;
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.
190 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
192 public: // Default property extensions from ProxyObject
195 * @copydoc Dali::Internal::ProxyObject::IsSceneObjectRemovable()
197 virtual bool IsSceneObjectRemovable() const;
200 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyCount()
202 virtual unsigned int GetDefaultPropertyCount() const;
205 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndices()
207 virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
210 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyName()
212 virtual const std::string& GetDefaultPropertyName( Property::Index index ) const;
215 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndex()
217 virtual Property::Index GetDefaultPropertyIndex( const std::string& name ) const;
220 * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyWritable()
222 virtual bool IsDefaultPropertyWritable( Property::Index index ) const;
225 * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAnimatable()
227 virtual bool IsDefaultPropertyAnimatable( Property::Index index ) const;
230 * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAConstraintInput()
232 virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
235 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyType()
237 virtual Property::Type GetDefaultPropertyType( Property::Index index ) const;
240 * @copydoc Dali::Internal::ProxyObject::SetDefaultProperty()
242 virtual void SetDefaultProperty( Property::Index index, const Property::Value& propertyValue );
245 * @copydoc Dali::Internal::ProxyObject::SetCustomProperty()
247 virtual void SetCustomProperty( Property::Index index, const CustomProperty& entry, const Property::Value& value );
250 * @copydoc Dali::Internal::ProxyObject::GetDefaultProperty()
252 virtual Property::Value GetDefaultProperty( Property::Index index ) const;
255 * @copydoc Dali::Internal::ProxyObject::InstallSceneObjectProperty()
257 virtual void InstallSceneObjectProperty( SceneGraph::PropertyBase& newProperty, const std::string& name, unsigned int index );
260 * @copydoc Dali::Internal::ProxyObject::GetSceneObject()
262 virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
265 * @copydoc Dali::Internal::ProxyObject::GetSceneObjectAnimatableProperty()
267 virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
270 * @copydoc Dali::Internal::ProxyObject::GetSceneObjectInputProperty()
272 virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
277 * Helper called after the first apply animation.
278 * @param [in] object The active constraint.
280 static void FirstApplyFinished( Object* object );
283 * Helper called after the remove animation.
284 * @param [in] object The active constraint.
286 static void OnRemoveFinished( Object* object );
288 // To be implemented in derived classes
291 * Used to observe the lifetime of an object with custom "weight" property
292 * @param [in] weightObject The object.
294 virtual void OnCustomWeightSet( ProxyObject& weightObject ) = 0;
297 * Set the parent of the active-constraint; called during OnFirstApply().
298 * @param [in] parent The parent object.
300 virtual void OnFirstApply( ProxyObject& parent ) = 0;
303 * Notification for the derived class, when BeginRemove() is called.
305 virtual void OnBeginRemove() = 0;
309 EventToUpdate& mEventToUpdate;
311 Property::Index mTargetPropertyIndex;
313 ProxyObject* mTargetProxy; ///< The proxy-object owns the active-constraint.
315 const SceneGraph::ConstraintBase* mSceneGraphConstraint;
317 const SceneGraph::AnimatableProperty<float>* mCustomWeight;
319 float mOffstageWeight;
321 TimePeriod mRemoveTime;
323 AlphaFunction mAlphaFunction;
325 RemoveAction mRemoveAction;
330 ActiveConstraintSignalV2 mAppliedSignal;
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
338 } // namespace Internal
340 // Helpers for public-api forwarding methods
342 inline Internal::ActiveConstraintBase& GetImplementation(Dali::ActiveConstraint& constraint)
344 DALI_ASSERT_ALWAYS( constraint && "ActiveConstraint handle is empty" );
346 BaseObject& handle = constraint.GetBaseObject();
348 return static_cast<Internal::ActiveConstraintBase&>(handle);
351 inline const Internal::ActiveConstraintBase& GetImplementation(const Dali::ActiveConstraint& constraint)
353 DALI_ASSERT_ALWAYS( constraint && "ActiveConstraint handle is empty" );
355 const BaseObject& handle = constraint.GetBaseObject();
357 return static_cast<const Internal::ActiveConstraintBase&>(handle);
362 #endif // __DALI_INTERNAL_ACTIVE_CONSTRAINT_BASE_H__