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/internal/event/animation/constraint-source-impl.h>
39 typedef Dali::Vector<ProxyObject*> ProxyObjectContainer;
40 typedef ProxyObjectContainer::Iterator ProxyObjectIter;
47 class AnimatableProperty;
51 * An abstract base class for active constraints.
53 class ActiveConstraintBase : public ProxyObject, public ProxyObject::Observer
57 typedef Dali::Constraint::RemoveAction RemoveAction;
58 typedef Any AnyFunction;
62 * @param[in] messageController Used to send messages to the update-thread.
63 * @param[in] targetPropertyIndex The index of the property being constrained.
64 * @param[in] sources The sources of the input properties.
65 * @param[in] sourceCount The original number of sources; this may not match sources.size() if objects have died.
67 ActiveConstraintBase( EventToUpdate& messageController, Property::Index targetPropertyIndex, SourceContainer& sources, unsigned int sourceCount );
72 virtual ~ActiveConstraintBase();
75 * Clone an active-constraint.
76 * @return A new active-constraint.
78 virtual ActiveConstraintBase* Clone() = 0;
81 * Set a custom "weight" property.
82 * @param[in] weightObject An object with a "weight" float property.
83 * @param[in] weightIndex The index of the weight property.
85 void SetCustomWeightObject( ProxyObject& weightObject, Property::Index weightIndex );
88 * Called when the ActiveConstraint is first applied.
89 * @pre The active-constraint does not already have a parent.
90 * @param[in] parent The parent object.
91 * @param[in] applyTime The apply-time for this constraint.
93 void FirstApply( ProxyObject& parent, TimePeriod applyTime );
96 * Called when the ActiveConstraint is removed.
101 * Called when the target object is destroyed.
103 void OnParentDestroyed();
106 * Called when the target object is connected to the scene-graph
108 void OnParentSceneObjectAdded();
111 * Called when the target object is disconnected from the scene-graph
113 void OnParentSceneObjectRemoved();
116 * Retrieve the parent of the active-constraint.
117 * @return The parent object, or NULL.
119 ProxyObject* GetParent();
122 * @copydoc Dali::Internal::Object::Supports()
124 virtual bool Supports( Object::Capability capability ) const;
127 * @copydoc Dali::ActiveConstraint::GetTargetObject()
129 Dali::Handle GetTargetObject();
132 * @copydoc Dali::ActiveConstraint::GetTargetProperty()
134 Property::Index GetTargetProperty();
137 * @copydoc Dali::ActiveConstraint::SetWeight()
139 void SetWeight( float weight );
142 * @copydoc Dali::ActiveConstraint::GetCurrentWeight()
144 float GetCurrentWeight() const;
147 * @copydoc Dali::ActiveConstraint::AppliedSignal()
149 ActiveConstraintSignalType& AppliedSignal();
152 * @copydoc Dali::Constraint::SetAlphaFunction()
154 void SetAlphaFunction(AlphaFunction func);
157 * @copydoc Dali::Constraint::GetAlphaFunction()
159 AlphaFunction GetAlphaFunction() const;
162 * @copydoc Dali::Constraint::SetRemoveAction()
164 void SetRemoveAction(RemoveAction action);
167 * @copydoc Dali::Constraint::GetRemoveAction()
169 RemoveAction GetRemoveAction() const;
172 * @copydoc Dali::Constraint::SetTag()
174 void SetTag(const unsigned int tag);
177 * @copydoc Dali::Constraint::GetTag()
179 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::GetDefaultPropertyCount()
197 virtual unsigned int GetDefaultPropertyCount() const;
200 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndices()
202 virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
205 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyName()
207 virtual const char* GetDefaultPropertyName( Property::Index index ) const;
210 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndex()
212 virtual Property::Index GetDefaultPropertyIndex( const std::string& name ) const;
215 * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyWritable()
217 virtual bool IsDefaultPropertyWritable( Property::Index index ) const;
220 * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAnimatable()
222 virtual bool IsDefaultPropertyAnimatable( Property::Index index ) const;
225 * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAConstraintInput()
227 virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
230 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyType()
232 virtual Property::Type GetDefaultPropertyType( Property::Index index ) const;
235 * @copydoc Dali::Internal::ProxyObject::SetDefaultProperty()
237 virtual void SetDefaultProperty( Property::Index index, const Property::Value& propertyValue );
240 * @copydoc Dali::Internal::ProxyObject::GetDefaultProperty()
242 virtual Property::Value GetDefaultProperty( Property::Index index ) const;
245 * @copydoc Dali::Internal::ProxyObject::GetSceneObject()
247 virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
250 * @copydoc Dali::Internal::ProxyObject::GetSceneObjectAnimatableProperty()
252 virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
255 * @copydoc Dali::Internal::ProxyObject::GetSceneObjectInputProperty()
257 virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
259 public: // ProxyObject::Observer methods
262 * @copydoc ProxyObject::Observer::SceneObjectAdded()
264 virtual void SceneObjectAdded( ProxyObject& proxy );
267 * @copydoc ProxyObject::Observer::SceneObjectRemoved()
269 virtual void SceneObjectRemoved( ProxyObject& proxy );
272 * @copydoc ProxyObject::Observer::ProxyDestroyed()
274 virtual void ProxyDestroyed( ProxyObject& proxy );
279 * Helper to observe a proxy, if not already observing it
281 void ObserveProxy( ProxyObject& proxy );
284 * Helper to stop observing proxies
286 void StopObservation();
289 * Helper called after the first apply animation.
290 * @param [in] object The active constraint.
292 static void FirstApplyFinished( Object* object );
294 // To be implemented in derived classes
297 * Create and connect a constraint for a scene-object.
299 virtual void ConnectConstraint() = 0;
303 EventToUpdate& mEventToUpdate;
305 Property::Index mTargetPropertyIndex;
306 SourceContainer mSources;
307 const unsigned int mSourceCount;
309 ProxyObject* mTargetProxy; ///< The proxy-object owns the active-constraint.
310 ProxyObjectContainer mObservedProxies; // We don't observe the same object twice
312 const SceneGraph::ConstraintBase* mSceneGraphConstraint;
314 const SceneGraph::AnimatableProperty<float>* mCustomWeight;
316 float mOffstageWeight;
318 AlphaFunction mAlphaFunction;
320 RemoveAction mRemoveAction;
325 ActiveConstraintSignalType mAppliedSignal;
327 Dali::Animation mApplyAnimation; ///< Used to automatically animate weight from 0.0f -> 1.0f
331 } // namespace Internal
333 // Helpers for public-api forwarding methods
335 inline Internal::ActiveConstraintBase& GetImplementation(Dali::ActiveConstraint& constraint)
337 DALI_ASSERT_ALWAYS( constraint && "ActiveConstraint handle is empty" );
339 BaseObject& handle = constraint.GetBaseObject();
341 return static_cast<Internal::ActiveConstraintBase&>(handle);
344 inline const Internal::ActiveConstraintBase& GetImplementation(const Dali::ActiveConstraint& constraint)
346 DALI_ASSERT_ALWAYS( constraint && "ActiveConstraint handle is empty" );
348 const BaseObject& handle = constraint.GetBaseObject();
350 return static_cast<const Internal::ActiveConstraintBase&>(handle);
355 #endif // __DALI_INTERNAL_ACTIVE_CONSTRAINT_BASE_H__