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>
45 * An abstract base class for active constraints.
47 class ActiveConstraintBase : public ProxyObject
51 typedef Dali::Constraint::RemoveAction RemoveAction;
52 typedef boost::any AnyFunction;
56 * @param[in] messageController Used to send messages to the update-thread.
57 * @param[in] targetPropertyIndex The index of the property being constrained.
59 ActiveConstraintBase( EventToUpdate& messageController, Property::Index targetPropertyIndex );
64 virtual ~ActiveConstraintBase();
67 * Clone an active-constraint.
68 * @return A new active-constraint.
70 virtual ActiveConstraintBase* Clone() = 0;
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.
79 void FirstApply( ProxyObject& parent, TimePeriod applyTime, ActiveConstraintCallbackType* callback );
82 * Called when the ActiveConstraint is removed.
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.
94 * Retrieve the parent of the active-constraint.
95 * @return The parent object, or NULL.
97 ProxyObject* GetParent();
100 * @copydoc Dali::Internal::Object::Supports()
102 virtual bool Supports( Object::Capability capability ) const;
105 * @copydoc Dali::ActiveConstraint::GetTargetObject()
107 Dali::Handle GetTargetObject();
110 * @copydoc Dali::ActiveConstraint::GetTargetProperty()
112 Property::Index GetTargetProperty();
115 * @copydoc Dali::ActiveConstraint::SetWeight()
117 void SetWeight( float weight );
120 * @copydoc Dali::ActiveConstraint::GetCurrentWeight()
122 float GetCurrentWeight() const;
125 * @copydoc Dali::ActiveConstraint::AppliedSignal()
127 ActiveConstraintSignalV2& AppliedSignal();
130 * @copydoc Dali::Constraint::SetRemoveTime()
132 void SetRemoveTime( TimePeriod timePeriod );
135 * @copydoc Dali::Constraint::GetRemoveTime()
137 TimePeriod GetRemoveTime() const;
140 * @copydoc Dali::Constraint::SetAlphaFunction()
142 void SetAlphaFunction(AlphaFunction func);
145 * @copydoc Dali::Constraint::GetAlphaFunction()
147 AlphaFunction GetAlphaFunction() const;
150 * @copydoc Dali::Constraint::SetRemoveAction()
152 void SetRemoveAction(RemoveAction action);
155 * @copydoc Dali::Constraint::GetRemoveAction()
157 RemoveAction GetRemoveAction() const;
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.
168 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
170 public: // Default property extensions from ProxyObject
173 * @copydoc Dali::Internal::ProxyObject::IsSceneObjectRemovable()
175 virtual bool IsSceneObjectRemovable() const;
178 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyCount()
180 virtual unsigned int GetDefaultPropertyCount() const;
183 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyName()
185 virtual const std::string& GetDefaultPropertyName( Property::Index index ) const;
188 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndex()
190 virtual Property::Index GetDefaultPropertyIndex( const std::string& name ) const;
193 * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyWritable()
195 virtual bool IsDefaultPropertyWritable( Property::Index index ) const;
198 * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAnimatable()
200 virtual bool IsDefaultPropertyAnimatable( Property::Index index ) const;
203 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyType()
205 virtual Property::Type GetDefaultPropertyType( Property::Index index ) const;
208 * @copydoc Dali::Internal::ProxyObject::SetDefaultProperty()
210 virtual void SetDefaultProperty( Property::Index index, const Property::Value& propertyValue );
213 * @copydoc Dali::Internal::ProxyObject::SetCustomProperty()
215 virtual void SetCustomProperty( Property::Index index, const CustomProperty& entry, const Property::Value& value );
218 * @copydoc Dali::Internal::ProxyObject::GetDefaultProperty()
220 virtual Property::Value GetDefaultProperty( Property::Index index ) const;
223 * @copydoc Dali::Internal::ProxyObject::InstallSceneObjectProperty()
225 virtual void InstallSceneObjectProperty( SceneGraph::PropertyBase& newProperty, const std::string& name, unsigned int index );
228 * @copydoc Dali::Internal::ProxyObject::GetSceneObject()
230 virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
233 * @copydoc Dali::Internal::ProxyObject::GetSceneObjectAnimatableProperty()
235 virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
238 * @copydoc Dali::Internal::ProxyObject::GetSceneObjectInputProperty()
240 virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
245 * Helper called after the first apply animation.
246 * @param [in] object The active constraint.
248 static void FirstApplyFinished( Object* object );
251 * Helper called after the remove animation.
252 * @param [in] object The active constraint.
254 static void OnRemoveFinished( Object* object );
256 // To be implemented in derived classes
259 * Set the parent of the active-constraint; called during OnFirstApply().
260 * @param [in] parent The parent object.
262 virtual void OnFirstApply( ProxyObject& parent ) = 0;
265 * Notification for the derived class, when BeginRemove() is called.
267 virtual void OnBeginRemove() = 0;
271 EventToUpdate& mEventToUpdate;
273 Property::Index mTargetPropertyIndex;
275 ProxyObject* mTargetProxy; ///< The proxy-object owns the active-constraint.
277 const SceneGraph::ConstraintBase* mSceneGraphConstraint;
279 float mOffstageWeight;
281 TimePeriod mRemoveTime;
283 AlphaFunction mAlphaFunction;
285 RemoveAction mRemoveAction;
289 ActiveConstraintSignalV2 mAppliedSignal;
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
295 } // namespace Internal
297 // Helpers for public-api forwarding methods
299 inline Internal::ActiveConstraintBase& GetImplementation(Dali::ActiveConstraint& constraint)
301 DALI_ASSERT_ALWAYS( constraint && "ActiveConstraint handle is empty" );
303 BaseObject& handle = constraint.GetBaseObject();
305 return static_cast<Internal::ActiveConstraintBase&>(handle);
308 inline const Internal::ActiveConstraintBase& GetImplementation(const Dali::ActiveConstraint& constraint)
310 DALI_ASSERT_ALWAYS( constraint && "ActiveConstraint handle is empty" );
312 const BaseObject& handle = constraint.GetBaseObject();
314 return static_cast<const Internal::ActiveConstraintBase&>(handle);
319 #endif // __DALI_INTERNAL_ACTIVE_CONSTRAINT_BASE_H__