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 ActiveConstraintSignalV2& 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::SetCustomProperty()
242 virtual void SetCustomProperty( Property::Index index, const CustomProperty& entry, const Property::Value& value );
245 * @copydoc Dali::Internal::ProxyObject::GetDefaultProperty()
247 virtual Property::Value GetDefaultProperty( Property::Index index ) const;
250 * @copydoc Dali::Internal::ProxyObject::InstallSceneObjectProperty()
252 virtual void InstallSceneObjectProperty( SceneGraph::PropertyBase& newProperty, const std::string& name, unsigned int index );
255 * @copydoc Dali::Internal::ProxyObject::GetSceneObject()
257 virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
260 * @copydoc Dali::Internal::ProxyObject::GetSceneObjectAnimatableProperty()
262 virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
265 * @copydoc Dali::Internal::ProxyObject::GetSceneObjectInputProperty()
267 virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
269 public: // ProxyObject::Observer methods
272 * @copydoc ProxyObject::Observer::SceneObjectAdded()
274 virtual void SceneObjectAdded( ProxyObject& proxy );
277 * @copydoc ProxyObject::Observer::SceneObjectRemoved()
279 virtual void SceneObjectRemoved( ProxyObject& proxy );
282 * @copydoc ProxyObject::Observer::ProxyDestroyed()
284 virtual void ProxyDestroyed( ProxyObject& proxy );
289 * Helper to observe a proxy, if not already observing it
291 void ObserveProxy( ProxyObject& proxy );
294 * Helper to stop observing proxies
296 void StopObservation();
299 * Helper called after the first apply animation.
300 * @param [in] object The active constraint.
302 static void FirstApplyFinished( Object* object );
304 // To be implemented in derived classes
307 * Create and connect a constraint for a scene-object.
309 virtual void ConnectConstraint() = 0;
313 EventToUpdate& mEventToUpdate;
315 Property::Index mTargetPropertyIndex;
316 SourceContainer mSources;
317 const unsigned int mSourceCount;
319 ProxyObject* mTargetProxy; ///< The proxy-object owns the active-constraint.
320 ProxyObjectContainer mObservedProxies; // We don't observe the same object twice
322 const SceneGraph::ConstraintBase* mSceneGraphConstraint;
324 const SceneGraph::AnimatableProperty<float>* mCustomWeight;
326 float mOffstageWeight;
328 AlphaFunction mAlphaFunction;
330 RemoveAction mRemoveAction;
335 ActiveConstraintSignalV2 mAppliedSignal;
337 Dali::Animation mApplyAnimation; ///< Used to automatically animate weight from 0.0f -> 1.0f
341 } // namespace Internal
343 // Helpers for public-api forwarding methods
345 inline Internal::ActiveConstraintBase& GetImplementation(Dali::ActiveConstraint& constraint)
347 DALI_ASSERT_ALWAYS( constraint && "ActiveConstraint handle is empty" );
349 BaseObject& handle = constraint.GetBaseObject();
351 return static_cast<Internal::ActiveConstraintBase&>(handle);
354 inline const Internal::ActiveConstraintBase& GetImplementation(const Dali::ActiveConstraint& constraint)
356 DALI_ASSERT_ALWAYS( constraint && "ActiveConstraint handle is empty" );
358 const BaseObject& handle = constraint.GetBaseObject();
360 return static_cast<const Internal::ActiveConstraintBase&>(handle);
365 #endif // __DALI_INTERNAL_ACTIVE_CONSTRAINT_BASE_H__