1 #ifndef __DALI_INTERNAL_OBJECT_H__
2 #define __DALI_INTERNAL_OBJECT_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/public-api/animation/active-constraint.h>
23 #include <dali/public-api/animation/constraint.h>
24 #include <dali/public-api/common/dali-vector.h>
25 #include <dali/public-api/common/vector-wrapper.h>
26 #include <dali/public-api/object/base-object.h>
27 #include <dali/public-api/object/handle.h>
28 #include <dali/public-api/object/property.h>
29 #include <dali/public-api/object/property-input.h>
30 #include <dali/public-api/object/property-notification.h>
31 #include <dali/internal/common/owner-container.h>
32 #include <dali/internal/event/common/object-impl.h>
33 #include <dali/internal/event/common/custom-property.h>
34 #include <dali/internal/event/common/property-input-impl.h>
35 #include <dali/internal/update/common/property-base.h>
40 class PropertyNotification;
46 class PropertyCondition;
47 class PropertyInputImpl;
57 typedef std::vector< Dali::ActiveConstraint > ActiveConstraintContainer;
58 typedef ActiveConstraintContainer::iterator ActiveConstraintIter;
59 typedef ActiveConstraintContainer::const_iterator ActiveConstraintConstIter;
62 * A base class for objects which optionally provide properties.
63 * The concrete derived class is responsible for implementing the property system methods.
64 * Classes may derive from Dali::BaseObject, until any properties are required.
66 * An object for a property-owning object in the scene-graph.
67 * This provides an interface for observing the addition/removal of scene-objects.
69 * The concrete derived class is responsible for:
70 * 1) Adding & removing an object from the scene-graph. The OnSceneObjectAdd() and OnSceneObjectRemove()
71 * methods should be called by the derived class, to trigger observer callbacks.
72 * 3) Implementing the GetSceneObject() methods, used to access the scene-object.
73 * 4) Providing access to properties stored by the scene-graph object. These should match the properties
74 * reported by the base Dali::Internal::Object methods.
77 class Object : public Dali::BaseObject
81 typedef Dali::Handle::Capability Capability;
88 * Called immediately after the object has created & passed ownership of a scene-graph object.
89 * @param[in] object The object object.
91 virtual void SceneObjectAdded(Object& object) = 0;
94 * Called shortly before the object sends a message to remove its scene object.
95 * @param[in] object The object object.
97 virtual void SceneObjectRemoved(Object& object) = 0;
100 * Called shortly before the object itself is destroyed; no further callbacks will be received.
101 * @param[in] object The object object.
103 virtual void ObjectDestroyed(Object& object) = 0;
110 virtual ~Observer(){}
119 * Add an observer to the object.
120 * @param[in] observer The observer to add.
122 virtual void AddObserver( Observer& observer );
125 * Remove an observer from the object
126 * @pre The observer has already been added.
127 * @param[in] observer The observer to remove.
129 virtual void RemoveObserver( Observer& observer );
132 * @copydoc Dali::Handle::Supports()
134 virtual bool Supports( Capability capability ) const;
137 * @copydoc Dali::Handle::GetPropertyCount()
139 virtual unsigned int GetPropertyCount() const;
142 * @copydoc Dali::Handle::GetPropertyName()
144 virtual std::string GetPropertyName( Property::Index index ) const;
147 * @copydoc Dali::Handle::GetPropertyIndex()
149 virtual Property::Index GetPropertyIndex( const std::string& name ) const;
152 * @copydoc Dali::Handle::IsPropertyWritable()
154 virtual bool IsPropertyWritable( Property::Index index ) const;
157 * @copydoc Dali::Handle::IsPropertyAnimatable()
159 virtual bool IsPropertyAnimatable( Property::Index index ) const;
162 * @copydoc Dali::Handle::IsPropertyAConstraintInput()
164 virtual bool IsPropertyAConstraintInput( Property::Index index ) const;
167 * @copydoc Dali::Handle::GetPropertyType()
169 virtual Property::Type GetPropertyType( Property::Index index ) const;
172 * @copydoc Dali::Handle::SetProperty()
174 virtual void SetProperty( Property::Index index, const Property::Value& propertyValue );
177 * @copydoc Dali::Handle::GetProperty()
179 virtual Property::Value GetProperty( Property::Index index ) const;
182 * @copydoc Dali::Handle::GetPropertyIndices()
184 virtual void GetPropertyIndices( Property::IndexContainer& indices ) const;
187 * @copydoc Dali::Handle::RegisterProperty()
189 virtual Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue );
192 * @copydoc Dali::Handle::RegisterProperty(std::string name, Property::Value propertyValue, Property::AccessMode accessMode)
194 virtual Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode );
197 * @copydoc Dali::Handle::AddPropertyNotification()
199 virtual Dali::PropertyNotification AddPropertyNotification( Property::Index index,
201 const Dali::PropertyCondition& condition );
204 * @copydoc Dali::Handle::RemovePropertyNotification()
206 virtual void RemovePropertyNotification( Dali::PropertyNotification propertyNotification );
209 * @copydoc Dali::Handle::RemovePropertyNotifications()
211 virtual void RemovePropertyNotifications();
216 * Apply a constraint to a Object.
217 * @param[in] constraint The constraint to apply.
219 Dali::ActiveConstraint ApplyConstraint( Constraint& constraint );
222 * Apply a constraint to a Object.
223 * @param[in] constraint The constraint to apply.
224 * @param[in] weightObject An object with a "weight" float property.
226 Dali::ActiveConstraint ApplyConstraint( Constraint& constraint, Dali::Handle weightObject );
229 * Remove one constraint from a Object.
230 * @param[in] activeConstraint The active constraint to remove.
232 void RemoveConstraint( Dali::ActiveConstraint activeConstraint );
235 * Remove all constraints from a Object.
237 void RemoveConstraints();
240 * Remove all constraints from a Object with a matching tag
242 void RemoveConstraints( unsigned int tag );
245 * Called by TypeInfo to set the type-info that this object-impl is created by.
246 * @param[in] typeInfo The TypeInfo that creates this object-impl.
248 void SetTypeInfo( const TypeInfo* typeInfo );
251 * @return the index from which custom properties start
253 unsigned int CustomPropertyStartIndex()
255 return PROPERTY_CUSTOM_START_INDEX;
258 // To be overridden by deriving classes
261 * Retrieve the scene-graph object added by this object.
262 * @return A pointer to the object, or NULL if no object has been added to the scene-graph.
264 virtual const SceneGraph::PropertyOwner* GetSceneObject() const = 0;
267 * Retrieve an animatable property owned by the scene-graph object.
268 * @pre -1 < index < GetPropertyCount().
269 * @param[in] index The index of the property.
270 * @return A dereferenceable pointer to a property, or NULL if a scene-object does not exist with this property.
272 virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const = 0;
275 * Retrieve an constraint input-property owned by the scene-graph object.
276 * @pre -1 < index < GetPropertyCount().
277 * @param[in] index The index of the property.
278 * @return A dereferenceable pointer to an input property, or NULL if a scene-object does not exist with this property.
280 virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const = 0;
283 * Query whether the property is a component of a scene-graph property.
284 * @pre -1 < index < GetPropertyCount().
285 * @param[in] index The index of the property.
286 * @return The index or Property::INVALID_COMPONENT_INDEX.
288 virtual int GetPropertyComponentIndex( Property::Index index ) const;
293 * A reference counted object may only be deleted by calling Unreference()
298 * Called immediately by derived classes, after the scene-object has been created & passed to the scene-graph.
300 void OnSceneObjectAdd();
303 * Called by derived classes, shortly before send a message to remove the scene-object.
305 void OnSceneObjectRemove();
308 * For use in derived classes.
309 * This is called after a non animatable custom property is set.
310 * @param [in] index The index of the property.
311 * @param [in] propertyValue The value of the property.
313 virtual void OnPropertySet( Property::Index index, Property::Value propertyValue ) {}
316 * Retrieves the TypeInfo for this object. Only retrieves it from the type-registry once and then stores a pointer
317 * to it locally there-after. The type info will not change during the life-time of the application.
318 * @return The type-info for this object (Can be NULL)
320 const TypeInfo* GetTypeInfo() const;
323 * Helper to find custom property
325 * @return pointer to the property
327 CustomProperty* FindCustomProperty( Property::Index index ) const;
329 private: // Default property extensions for derived classes
332 * Query how many default properties the derived class supports.
333 * @return The number of default properties.
335 virtual unsigned int GetDefaultPropertyCount() const = 0;
338 * Retrieve all the indices that are associated with the default properties supported by the derived class.
339 * @return A container of default property indices.
340 * @note The deriving class must not modify the existing elements in the container.
342 virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const = 0;
345 * Query how many default properties the derived class supports.
346 * @return The number of default properties.
348 virtual const char* GetDefaultPropertyName( Property::Index index ) const = 0;
351 * Query the index of a default property.
352 * @param [in] name The name of the property.
353 * @return The index of the property, or Property::INVALID_INDEX if no default property exists with the given name.
355 virtual Property::Index GetDefaultPropertyIndex( const std::string& name ) const = 0;
358 * Query whether a default property is writable.
359 * @param [in] index The index of the property.
360 * @return True if the property is animatable.
362 virtual bool IsDefaultPropertyWritable( Property::Index index ) const = 0;
365 * Query whether a default property is animatable.
366 * This determines whether the property can be the target of an animation or constraint.
367 * @param [in] index The index of the property.
368 * @return True if the property is animatable.
370 virtual bool IsDefaultPropertyAnimatable( Property::Index index ) const = 0;
373 * @brief Query whether a default property can be used as an input to a constraint.
375 * @param [in] index The index of the property.
376 * @return True if the property can be used as an input to a constraint.
378 virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const = 0;
381 * Query the type of a default property.
382 * @param [in] index The index of the property.
383 * @return The type of the property.
385 virtual Property::Type GetDefaultPropertyType( Property::Index index ) const = 0;
388 * Set the value of a default property.
389 * @pre The property types match i.e. propertyValue.GetType() is equal to GetPropertyType(index).
390 * @param [in] index The index of the property.
391 * @param [in] propertyValue The new value of the property.
393 virtual void SetDefaultProperty( Property::Index index, const Property::Value& propertyValue ) = 0;
396 * Retrieve a default property value.
397 * @param [in] index The index of the property.
398 * @return The property value.
400 virtual Property::Value GetDefaultProperty( Property::Index index ) const = 0;
403 * @todo this is virtual so that for now actor can override it,
404 * it needs to be removed and only have GetSceneObject but that requires changing actor and constraint logic
405 * Retrieve the scene-graph object added by this object.
406 * @return A pointer to the object, or NULL if no object has been added to the scene-graph.
408 virtual const SceneGraph::PropertyOwner* GetPropertyOwner() const
410 return GetSceneObject();
414 * Notify derived class of installation of a new scene-object property.
415 * This method is called after the message is to sent to install the property
416 * @param [in] newProperty A newly allocated scene-object property. Ownership is obviously not passed.
417 * @param [in] name The name allocated to this custom property.
418 * @param [in] index The index allocated to this custom property.
420 virtual void NotifyScenePropertyInstalled( const SceneGraph::PropertyBase& newProperty, const std::string& name, unsigned int index )
426 Object(const Object& rhs);
429 Object& operator=(const Object& rhs);
432 * Enable property notifications in scene graph
434 void EnablePropertyNotifications();
437 * Enable property notifications in scene graph
439 void DisablePropertyNotifications();
442 * Helper for ApplyConstraint overloads.
443 * @param[in] constraint The constraint to apply.
444 * @param[in] weightObject An object with a "weight" float property, or an empty handle.
445 * @return The new active-constraint which is owned by Object.
447 ActiveConstraintBase* DoApplyConstraint( Constraint& constraint, Dali::Handle weightObject );
450 * Helper to remove active constraints
452 void RemoveConstraint( ActiveConstraint& constraint, bool isInScenegraph );
455 * Set the value of scene graph property.
456 * @param [in] index The index of the property.
457 * @param [in] entry An entry from the CustomPropertyLookup.
458 * @param [in] value The new value of the property.
460 virtual void SetSceneGraphProperty( Property::Index index, const CustomProperty& entry, const Property::Value& value );
464 typedef OwnerContainer<CustomProperty*> CustomPropertyLookup;
465 CustomPropertyLookup mCustomProperties; ///< Used for accessing custom Node properties
466 mutable TypeInfo const * mTypeInfo; ///< The type-info for this object, mutable so it can be lazy initialized from const method if it is required
468 Dali::Vector<Observer*> mObservers;
470 ActiveConstraintContainer* mConstraints; ///< Container of owned active-constraints.
472 typedef std::vector< Dali::PropertyNotification > PropertyNotificationContainer;
473 typedef PropertyNotificationContainer::iterator PropertyNotificationContainerIter;
474 typedef PropertyNotificationContainer::const_iterator PropertyNotificationContainerConstIter;
475 PropertyNotificationContainer* mPropertyNotifications; ///< Container of owned property notifications.
478 } // namespace Internal
480 // Helpers for public-api forwarding methods
482 inline Internal::Object& GetImplementation(Dali::Handle& object)
484 DALI_ASSERT_ALWAYS( object && "Object handle is empty" );
486 BaseObject& handle = object.GetBaseObject();
488 return static_cast<Internal::Object&>(handle);
491 inline const Internal::Object& GetImplementation(const Dali::Handle& object)
493 DALI_ASSERT_ALWAYS( object && "Object handle is empty" );
495 const BaseObject& handle = object.GetBaseObject();
497 return static_cast<const Internal::Object&>(handle);
502 #endif // __DALI_INTERNAL_OBJECT_H__