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/object-impl.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>
38 class EventThreadServices;
39 typedef Dali::Vector<Object*> ObjectContainer;
40 typedef ObjectContainer::Iterator ObjectIter;
47 class AnimatableProperty;
51 * An abstract base class for active constraints.
53 class ActiveConstraintBase : public Object, public Object::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( 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( Object& 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( Object& 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.
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 Object
195 * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
197 virtual unsigned int GetDefaultPropertyCount() const;
200 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
202 virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
205 * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
207 virtual const char* GetDefaultPropertyName( Property::Index index ) const;
210 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
212 virtual Property::Index GetDefaultPropertyIndex( const std::string& name ) const;
215 * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
217 virtual bool IsDefaultPropertyWritable( Property::Index index ) const;
220 * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
222 virtual bool IsDefaultPropertyAnimatable( Property::Index index ) const;
225 * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
227 virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
230 * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
232 virtual Property::Type GetDefaultPropertyType( Property::Index index ) const;
235 * @copydoc Dali::Internal::Object::SetDefaultProperty()
237 virtual void SetDefaultProperty( Property::Index index, const Property::Value& propertyValue );
240 * @copydoc Dali::Internal::Object::GetDefaultProperty()
242 virtual Property::Value GetDefaultProperty( Property::Index index ) const;
245 * @copydoc Dali::Internal::Object::GetSceneObject()
247 virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
250 * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
252 virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
255 * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
257 virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
259 public: // Object::Observer methods
262 * @copydoc Object::Observer::SceneObjectAdded()
264 virtual void SceneObjectAdded( Object& object );
267 * @copydoc Object::Observer::SceneObjectRemoved()
269 virtual void SceneObjectRemoved( Object& object );
272 * @copydoc Object::Observer::ObjectDestroyed()
274 virtual void ObjectDestroyed( Object& object );
279 * Helper to observe an object, if not already observing it
281 void ObserveObject( Object& object );
284 * Helper to stop observing objects
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;
302 Property::Index mTargetPropertyIndex;
303 SourceContainer mSources;
304 const unsigned int mSourceCount;
306 Object* mTargetObject; ///< The object owns the active-constraint.
307 ObjectContainer mObservedObjects; // We don't observe the same object twice
309 const SceneGraph::ConstraintBase* mSceneGraphConstraint;
311 const SceneGraph::AnimatableProperty<float>* mCustomWeight;
313 float mOffstageWeight;
315 AlphaFunction mAlphaFunction;
317 RemoveAction mRemoveAction;
322 ActiveConstraintSignalType mAppliedSignal;
324 Dali::Animation mApplyAnimation; ///< Used to automatically animate weight from 0.0f -> 1.0f
328 } // namespace Internal
330 // Helpers for public-api forwarding methods
332 inline Internal::ActiveConstraintBase& GetImplementation(Dali::ActiveConstraint& constraint)
334 DALI_ASSERT_ALWAYS( constraint && "ActiveConstraint handle is empty" );
336 BaseObject& handle = constraint.GetBaseObject();
338 return static_cast<Internal::ActiveConstraintBase&>(handle);
341 inline const Internal::ActiveConstraintBase& GetImplementation(const Dali::ActiveConstraint& constraint)
343 DALI_ASSERT_ALWAYS( constraint && "ActiveConstraint handle is empty" );
345 const BaseObject& handle = constraint.GetBaseObject();
347 return static_cast<const Internal::ActiveConstraintBase&>(handle);
352 #endif // __DALI_INTERNAL_ACTIVE_CONSTRAINT_BASE_H__