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>
30 #include <dali/public-api/common/set-wrapper.h>
31 #include <dali/internal/event/animation/constraint-source-impl.h>
40 typedef std::set<ProxyObject*> ProxyObjectContainer;
41 typedef ProxyObjectContainer::iterator ProxyObjectIter;
48 class AnimatableProperty;
52 * An abstract base class for active constraints.
54 class ActiveConstraintBase : public ProxyObject, public ProxyObject::Observer
58 typedef Dali::Constraint::RemoveAction RemoveAction;
59 typedef Any AnyFunction;
63 * @param[in] messageController Used to send messages to the update-thread.
64 * @param[in] targetPropertyIndex The index of the property being constrained.
65 * @param[in] sources The sources of the input properties.
66 * @param[in] sourceCount The original number of sources; this may not match sources.size() if objects have died.
68 ActiveConstraintBase( EventToUpdate& messageController, Property::Index targetPropertyIndex, SourceContainer& sources, unsigned int sourceCount );
73 virtual ~ActiveConstraintBase();
76 * Clone an active-constraint.
77 * @return A new active-constraint.
79 virtual ActiveConstraintBase* Clone() = 0;
82 * Set a custom "weight" property.
83 * @param[in] weightObject An object with a "weight" float property.
84 * @param[in] weightIndex The index of the weight property.
86 void SetCustomWeightObject( ProxyObject& weightObject, Property::Index weightIndex );
89 * Called when the ActiveConstraint is first applied.
90 * @pre The active-constraint does not already have a parent.
91 * @param[in] parent The parent object.
92 * @param[in] applyTime The apply-time for this constraint.
94 void FirstApply( ProxyObject& parent, TimePeriod applyTime );
97 * Called when the ActiveConstraint is removed.
102 * Called when the target object is destroyed.
104 void OnParentDestroyed();
107 * Called when the target object is connected to the scene-graph
109 void OnParentSceneObjectAdded();
112 * Called when the target object is disconnected from the scene-graph
114 void OnParentSceneObjectRemoved();
117 * Retrieve the parent of the active-constraint.
118 * @return The parent object, or NULL.
120 ProxyObject* GetParent();
123 * @copydoc Dali::Internal::Object::Supports()
125 virtual bool Supports( Object::Capability capability ) const;
128 * @copydoc Dali::ActiveConstraint::GetTargetObject()
130 Dali::Handle GetTargetObject();
133 * @copydoc Dali::ActiveConstraint::GetTargetProperty()
135 Property::Index GetTargetProperty();
138 * @copydoc Dali::ActiveConstraint::SetWeight()
140 void SetWeight( float weight );
143 * @copydoc Dali::ActiveConstraint::GetCurrentWeight()
145 float GetCurrentWeight() const;
148 * @copydoc Dali::ActiveConstraint::AppliedSignal()
150 ActiveConstraintSignalV2& AppliedSignal();
153 * @copydoc Dali::Constraint::SetAlphaFunction()
155 void SetAlphaFunction(AlphaFunction func);
158 * @copydoc Dali::Constraint::GetAlphaFunction()
160 AlphaFunction GetAlphaFunction() const;
163 * @copydoc Dali::Constraint::SetRemoveAction()
165 void SetRemoveAction(RemoveAction action);
168 * @copydoc Dali::Constraint::GetRemoveAction()
170 RemoveAction GetRemoveAction() const;
173 * @copydoc Dali::Constraint::SetTag()
175 void SetTag(const unsigned int tag);
178 * @copydoc Dali::Constraint::GetTag()
180 unsigned int GetTag() const;
183 * Connects a callback function with the object's signals.
184 * @param[in] object The object providing the signal.
185 * @param[in] tracker Used to disconnect the signal.
186 * @param[in] signalName The signal to connect to.
187 * @param[in] functor A newly allocated FunctorDelegate.
188 * @return True if the signal was connected.
189 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
191 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
193 public: // Default property extensions from ProxyObject
196 * @copydoc Dali::Internal::ProxyObject::IsSceneObjectRemovable()
198 virtual bool IsSceneObjectRemovable() const;
201 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyCount()
203 virtual unsigned int GetDefaultPropertyCount() const;
206 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndices()
208 virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
211 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyName()
213 virtual const std::string& GetDefaultPropertyName( Property::Index index ) const;
216 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndex()
218 virtual Property::Index GetDefaultPropertyIndex( const std::string& name ) const;
221 * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyWritable()
223 virtual bool IsDefaultPropertyWritable( Property::Index index ) const;
226 * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAnimatable()
228 virtual bool IsDefaultPropertyAnimatable( Property::Index index ) const;
231 * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAConstraintInput()
233 virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
236 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyType()
238 virtual Property::Type GetDefaultPropertyType( Property::Index index ) const;
241 * @copydoc Dali::Internal::ProxyObject::SetDefaultProperty()
243 virtual void SetDefaultProperty( Property::Index index, const Property::Value& propertyValue );
246 * @copydoc Dali::Internal::ProxyObject::SetCustomProperty()
248 virtual void SetCustomProperty( Property::Index index, const CustomProperty& entry, const Property::Value& value );
251 * @copydoc Dali::Internal::ProxyObject::GetDefaultProperty()
253 virtual Property::Value GetDefaultProperty( Property::Index index ) const;
256 * @copydoc Dali::Internal::ProxyObject::InstallSceneObjectProperty()
258 virtual void InstallSceneObjectProperty( SceneGraph::PropertyBase& newProperty, const std::string& name, unsigned int index );
261 * @copydoc Dali::Internal::ProxyObject::GetSceneObject()
263 virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
266 * @copydoc Dali::Internal::ProxyObject::GetSceneObjectAnimatableProperty()
268 virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
271 * @copydoc Dali::Internal::ProxyObject::GetSceneObjectInputProperty()
273 virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
275 public: // ProxyObject::Observer methods
278 * @copydoc ProxyObject::Observer::SceneObjectAdded()
280 virtual void SceneObjectAdded( ProxyObject& proxy );
283 * @copydoc ProxyObject::Observer::SceneObjectRemoved()
285 virtual void SceneObjectRemoved( ProxyObject& proxy );
288 * @copydoc ProxyObject::Observer::ProxyDestroyed()
290 virtual void ProxyDestroyed( ProxyObject& proxy );
295 * Helper to observe a proxy, if not already observing it
297 void ObserveProxy( ProxyObject& proxy );
300 * Helper to stop observing proxies
302 void StopObservation();
305 * Helper called after the first apply animation.
306 * @param [in] object The active constraint.
308 static void FirstApplyFinished( Object* object );
310 // To be implemented in derived classes
313 * Create and connect a constraint for a scene-object.
315 virtual void ConnectConstraint() = 0;
319 EventToUpdate& mEventToUpdate;
321 Property::Index mTargetPropertyIndex;
322 SourceContainer mSources;
323 const unsigned int mSourceCount;
325 ProxyObject* mTargetProxy; ///< The proxy-object owns the active-constraint.
326 ProxyObjectContainer mObservedProxies; // We don't observe the same object twice
328 const SceneGraph::ConstraintBase* mSceneGraphConstraint;
330 const SceneGraph::AnimatableProperty<float>* mCustomWeight;
332 float mOffstageWeight;
334 AlphaFunction mAlphaFunction;
336 RemoveAction mRemoveAction;
341 ActiveConstraintSignalV2 mAppliedSignal;
343 Dali::Animation mApplyAnimation; ///< Used to automatically animate weight from 0.0f -> 1.0f
347 } // namespace Internal
349 // Helpers for public-api forwarding methods
351 inline Internal::ActiveConstraintBase& GetImplementation(Dali::ActiveConstraint& constraint)
353 DALI_ASSERT_ALWAYS( constraint && "ActiveConstraint handle is empty" );
355 BaseObject& handle = constraint.GetBaseObject();
357 return static_cast<Internal::ActiveConstraintBase&>(handle);
360 inline const Internal::ActiveConstraintBase& GetImplementation(const Dali::ActiveConstraint& constraint)
362 DALI_ASSERT_ALWAYS( constraint && "ActiveConstraint handle is empty" );
364 const BaseObject& handle = constraint.GetBaseObject();
366 return static_cast<const Internal::ActiveConstraintBase&>(handle);
371 #endif // __DALI_INTERNAL_ACTIVE_CONSTRAINT_BASE_H__