1 #ifndef __DALI_INTERNAL_OBJECT_H__
2 #define __DALI_INTERNAL_OBJECT_H__
5 * Copyright (c) 2017 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/constraint.h>
23 #include <dali/public-api/common/dali-vector.h>
24 #include <dali/public-api/common/vector-wrapper.h>
25 #include <dali/public-api/object/base-object.h>
26 #include <dali/public-api/object/handle.h>
27 #include <dali/public-api/object/property.h>
28 #include <dali/public-api/object/property-index-ranges.h>
29 #include <dali/public-api/object/property-input.h>
30 #include <dali/public-api/object/property-notification.h>
31 #include <dali/devel-api/common/owner-container.h>
32 #include <dali/internal/event/common/event-thread-services.h>
33 #include <dali/internal/event/common/property-input-impl.h>
34 #include <dali/internal/event/common/property-metadata.h>
35 #include <dali/internal/update/common/property-base.h>
40 class PropertyNotification;
46 class EventThreadServices;
48 class PropertyCondition;
49 class PropertyInputImpl;
59 typedef std::vector< Dali::Constraint > ConstraintContainer;
60 typedef ConstraintContainer::iterator ConstraintIter;
61 typedef ConstraintContainer::const_iterator ConstraintConstIter;
65 * A base class for objects which optionally provide properties.
66 * The concrete derived class is responsible for implementing the property system methods.
67 * Classes may derive from Dali::BaseObject, until any properties are required.
69 * An object for a property-owning object in the scene-graph.
70 * This provides an interface for observing the addition/removal of scene-objects.
72 * The concrete derived class is responsible for:
73 * 1) Adding & removing an object from the scene-graph. The OnSceneObjectAdd() and OnSceneObjectRemove()
74 * methods should be called by the derived class, to trigger observer callbacks.
75 * 3) Implementing the GetSceneObject() methods, used to access the scene-object.
76 * 4) Providing access to properties stored by the scene-graph object. These should match the properties
77 * reported by the base Dali::Internal::Object methods.
80 class Object : public Dali::BaseObject
84 typedef Dali::Handle::Capability Capability;
91 * Called immediately after the object has created & passed ownership of a scene-graph object.
92 * @param[in] object The object object.
94 virtual void SceneObjectAdded(Object& object) = 0;
97 * Called shortly before the object sends a message to remove its scene object.
98 * @param[in] object The object object.
100 virtual void SceneObjectRemoved(Object& object) = 0;
103 * Called shortly before the object itself is destroyed; no further callbacks will be received.
104 * @param[in] object The object object.
106 virtual void ObjectDestroyed(Object& object) = 0;
113 virtual ~Observer(){}
122 * Add an observer to the object.
123 * @param[in] observer The observer to add.
125 virtual void AddObserver( Observer& observer );
128 * Remove an observer from the object
129 * @pre The observer has already been added.
130 * @param[in] observer The observer to remove.
132 virtual void RemoveObserver( Observer& observer );
135 * @copydoc Dali::Handle::Supports()
137 virtual bool Supports( Capability capability ) const;
140 * @copydoc Dali::Handle::GetPropertyCount()
142 virtual unsigned int GetPropertyCount() const;
145 * @copydoc Dali::Handle::GetPropertyName()
147 virtual std::string GetPropertyName( Property::Index index ) const;
150 * @copydoc Dali::Handle::GetPropertyIndex()
152 virtual Property::Index GetPropertyIndex( const std::string& name ) const;
155 * @copydoc Dali::Handle::GetPropertyIndex()
157 virtual Property::Index GetPropertyIndex( Property::Index key ) const;
160 * @copydoc Dali::Handle::GetPropertyIndex()
162 virtual Property::Index GetPropertyIndex( Property::Key key ) const;
165 * @copydoc Dali::Handle::IsPropertyWritable()
167 virtual bool IsPropertyWritable( Property::Index index ) const;
170 * @copydoc Dali::Handle::IsPropertyAnimatable()
172 virtual bool IsPropertyAnimatable( Property::Index index ) const;
175 * @copydoc Dali::Handle::IsPropertyAConstraintInput()
177 virtual bool IsPropertyAConstraintInput( Property::Index index ) const;
180 * @copydoc Dali::Handle::GetPropertyType()
182 virtual Property::Type GetPropertyType( Property::Index index ) const;
185 * @copydoc Dali::Handle::SetProperty()
187 virtual void SetProperty( Property::Index index, const Property::Value& propertyValue );
190 * @copydoc Dali::Handle::GetProperty()
192 virtual Property::Value GetProperty( Property::Index index ) const;
195 * @brief Retrieves the latest value of the property on the scene-graph.
196 * @param[in] index The index of the property required.
197 * @return The latest value of the property on the scene-graph.
199 virtual Property::Value GetCurrentProperty( Property::Index index ) const;
202 * @copydoc Dali::Handle::GetPropertyIndices()
204 virtual void GetPropertyIndices( Property::IndexContainer& indices ) const;
207 * @copydoc Dali::Handle::RegisterProperty()
209 virtual Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue );
212 * @copydoc Dali::Handle::RegisterProperty()
214 virtual Property::Index RegisterProperty( const std::string& name, Property::Index key, const Property::Value& propertyValue );
217 * @copydoc Dali::Handle::RegisterProperty(std::string name, Property::Value propertyValue, Property::AccessMode accessMode)
219 virtual Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode );
222 * @brief Implementing method for this override
224 virtual Property::Index RegisterProperty( const std::string& name, Property::Index key, const Property::Value& propertyValue, Property::AccessMode accessMode );
227 * @copydoc Dali::Handle::AddPropertyNotification()
229 virtual Dali::PropertyNotification AddPropertyNotification( Property::Index index,
231 const Dali::PropertyCondition& condition );
234 * @copydoc Dali::Handle::RemovePropertyNotification()
236 virtual void RemovePropertyNotification( Dali::PropertyNotification propertyNotification );
239 * @copydoc Dali::Handle::RemovePropertyNotifications()
241 virtual void RemovePropertyNotifications();
244 * Notifies that a property is being animated.
245 * @param[in] animation The animation animating the property.
246 * @param[in] index The index of the property.
247 * @param[in] value The value of the property after the animation.
249 void NotifyPropertyAnimation( Animation& animation, Property::Index index, const Property::Value& value );
251 /******************************** Uniform Mappings ********************************/
254 * @copydoc Dali::Handle::AddUniformMapping()
256 void AddUniformMapping( Property::Index propertyIndex, const std::string& uniformName ) const;
259 * @copydoc Dali::Handle::RemoveUniformMapping( )
261 void RemoveUniformMapping( const std::string& uniformName );
263 /******************************** Constraints ********************************/
266 * Apply a constraint to an Object.
267 * @param[in] constraint The constraint to apply.
269 void ApplyConstraint( ConstraintBase& constraint );
272 * Remove one constraint from an Object.
273 * @param[in] constraint The constraint to remove.
275 void RemoveConstraint( ConstraintBase& constraint );
278 * Remove all constraints from a Object.
280 void RemoveConstraints();
283 * Remove all constraints from a Object with a matching tag
285 void RemoveConstraints( unsigned int tag );
288 * Called by TypeInfo to set the type-info that this object-impl is created by.
289 * @param[in] typeInfo The TypeInfo that creates this object-impl.
291 void SetTypeInfo( const TypeInfo* typeInfo );
294 * @return the index from which custom properties start
296 unsigned int CustomPropertyStartIndex()
298 return PROPERTY_CUSTOM_START_INDEX;
301 /******************** To be overridden by deriving classes ********************/
304 * Retrieve the scene-graph object added by this object.
305 * @return A pointer to the object, or NULL if no object has been added to the scene-graph.
307 virtual const SceneGraph::PropertyOwner* GetSceneObject() const = 0;
310 * Retrieve an animatable property owned by the scene-graph object.
311 * @pre -1 < index < GetPropertyCount().
312 * @param[in] index The index of the property.
313 * @return A dereferenceable pointer to a property, or NULL if a scene-object does not exist with this property.
315 virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const = 0;
318 * Retrieve a constraint input-property owned by the scene-graph object.
319 * @pre -1 < index < GetPropertyCount().
320 * @param[in] index The index of the property.
321 * @return A dereferenceable pointer to an input property, or NULL if a scene-object does not exist with this property.
323 virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const = 0;
326 * Query whether the property is a component of a scene-graph property.
327 * @pre -1 < index < GetPropertyCount().
328 * @param[in] index The index of the property.
329 * @return The index or Property::INVALID_COMPONENT_INDEX.
331 virtual int GetPropertyComponentIndex( Property::Index index ) const;
336 * A reference counted object may only be deleted by calling Unreference()
341 * Called immediately by derived classes, after the scene-object has been created & passed to the scene-graph.
343 void OnSceneObjectAdd();
346 * Called by derived classes, shortly before send a message to remove the scene-object.
348 void OnSceneObjectRemove();
351 * For overriding by derived classes to return the parent of this object.
353 virtual Object* GetParentObject() const
355 // By default the Object does not have a parent
360 * For use in derived classes.
361 * This is called after a property is set.
362 * @param [in] index The index of the property.
363 * @param [in] propertyValue The value of the property.
365 virtual void OnPropertySet( Property::Index index, Property::Value propertyValue ) {}
368 * Retrieves the TypeInfo for this object. Only retrieves it from the type-registry once and then stores a pointer
369 * to it locally there-after. The type info will not change during the life-time of the application.
370 * @return The type-info for this object (Can be NULL)
372 const TypeInfo* GetTypeInfo() const;
375 * Helper to find custom property
377 * @return pointer to the property
379 CustomPropertyMetadata* FindCustomProperty( Property::Index index ) const;
382 * Helper to find animatable property
384 * @return pointer to the property
386 AnimatablePropertyMetadata* FindAnimatableProperty( Property::Index index ) const;
389 * Helper to register a scene-graph property
390 * @param [in] name The name of the property.
391 * @param [in] key The key of the property
392 * @param [in] index The index of the property
393 * @param [in] value The value of the property.
394 * @return The index of the registered property or Property::INVALID_INDEX if registration failed.
396 Property::Index RegisterSceneGraphProperty(const std::string& name, Property::Index key, Property::Index index, const Property::Value& propertyValue) const;
399 * Check whether the animatable property is registered already, if not then register one.
400 * @param [in] index The index of the property
401 * @return pointer to the property.
403 AnimatablePropertyMetadata* RegisterAnimatableProperty(Property::Index index) const;
406 * Resolve the index and name of child properties if any.
408 void ResolveChildProperties();
410 private: // Default property extensions for derived classes
413 * Query how many default properties the derived class supports.
414 * @return The number of default properties.
416 virtual unsigned int GetDefaultPropertyCount() const = 0;
419 * Retrieve all the indices that are associated with the default properties supported by the derived class.
420 * @return A container of default property indices.
421 * @note The deriving class must not modify the existing elements in the container.
423 virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const = 0;
426 * Query how many default properties the derived class supports.
427 * @return The number of default properties.
429 virtual const char* GetDefaultPropertyName( Property::Index index ) const = 0;
432 * Query the index of a default property.
433 * @param [in] name The name of the property.
434 * @return The index of the property, or Property::INVALID_INDEX if no default property exists with the given name.
436 virtual Property::Index GetDefaultPropertyIndex( const std::string& name ) const = 0;
439 * Query whether a default property is writable.
440 * @param [in] index The index of the property.
441 * @return True if the property is animatable.
443 virtual bool IsDefaultPropertyWritable( Property::Index index ) const = 0;
446 * Query whether a default property is animatable.
447 * This determines whether the property can be the target of an animation or constraint.
448 * @param [in] index The index of the property.
449 * @return True if the property is animatable.
451 virtual bool IsDefaultPropertyAnimatable( Property::Index index ) const = 0;
454 * @brief Query whether a default property can be used as an input to a constraint.
456 * @param [in] index The index of the property.
457 * @return True if the property can be used as an input to a constraint.
459 virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const = 0;
462 * Query the type of a default property.
463 * @param [in] index The index of the property.
464 * @return The type of the property.
466 virtual Property::Type GetDefaultPropertyType( Property::Index index ) const = 0;
469 * Set the value of a default property.
470 * @pre The property types match i.e. propertyValue.GetType() is equal to GetPropertyType(index).
471 * @param [in] index The index of the property.
472 * @param [in] propertyValue The new value of the property.
474 virtual void SetDefaultProperty( Property::Index index, const Property::Value& propertyValue ) = 0;
477 * Retrieve a default property value.
478 * @param [in] index The index of the property.
479 * @return The property value.
481 virtual Property::Value GetDefaultProperty( Property::Index index ) const = 0;
484 * Retrieve the latest scene-graph value of a default property.
485 * @param[in] index The index of the property.
486 * @return The latest scene-graph value of a default property.
488 virtual Property::Value GetDefaultPropertyCurrentValue( Property::Index index ) const = 0;
491 * Notifies that a default property is being animated so the deriving class should update the cached value.
492 * @param[in] animation The animation animating the property.
493 * @param[in] index The index of the property.
494 * @param[in] value The value of the property after the animation.
496 virtual void OnNotifyDefaultPropertyAnimation( Animation& animation, Property::Index index, const Property::Value& value )
500 * @todo this is virtual so that for now actor can override it,
501 * it needs to be removed and only have GetSceneObject but that requires changing actor and constraint logic
502 * Retrieve the scene-graph object added by this object.
503 * @return A pointer to the object, or NULL if no object has been added to the scene-graph.
505 virtual const SceneGraph::PropertyOwner* GetPropertyOwner() const
507 return GetSceneObject();
511 * Notify derived class of installation of a new scene-object property.
512 * This method is called after the message is to sent to install the property
513 * @param [in] newProperty A newly allocated scene-object property. Ownership is obviously not passed.
514 * @param [in] name The name allocated to this custom property.
515 * @param [in] index The index allocated to this custom property.
517 virtual void NotifyScenePropertyInstalled( const SceneGraph::PropertyBase& newProperty, const std::string& name, unsigned int index ) const
523 Object(const Object& rhs);
526 Object& operator=(const Object& rhs);
529 * Enable property notifications in scene graph
531 void EnablePropertyNotifications();
534 * Enable property notifications in scene graph
536 void DisablePropertyNotifications();
539 * Get the latest value of the property on the scene-graph.
540 * @param[in] entry An entry from the property lookup container.
541 * @return The latest value of the property.
543 Property::Value GetCurrentPropertyValue( const PropertyMetadata* entry ) const;
546 * Set the value of scene graph property.
547 * @param [in] index The index of the property.
548 * @param [in] entry An entry from the property lookup container.
549 * @param [in] value The new value of the property.
551 virtual void SetSceneGraphProperty( Property::Index index, const PropertyMetadata& entry, const Property::Value& value );
555 * Get the event thread services object - used for sending messages to the scene graph
556 * Assert if called from the wrong thread.
557 * This is intentionally inline for performance reasons.
559 * @return The event thread services object
561 inline EventThreadServices& GetEventThreadServices()
563 DALI_ASSERT_DEBUG( EventThreadServices::IsCoreRunning() );
564 return mEventThreadServices;
568 * Get the event thread services object - used for sending messages to the scene graph
569 * Assert if called from the wrong thread
570 * This is intentionally inline for performance reasons.
572 * @return The event thread services object
574 inline const EventThreadServices& GetEventThreadServices() const
576 DALI_ASSERT_DEBUG( EventThreadServices::IsCoreRunning() );
577 return mEventThreadServices;
581 EventThreadServices& mEventThreadServices;
585 typedef OwnerContainer<PropertyMetadata*> PropertyMetadataLookup;
586 mutable PropertyMetadataLookup mCustomProperties; ///< Used for accessing custom Node properties
587 mutable PropertyMetadataLookup mAnimatableProperties; ///< Used for accessing animatable Node properties
588 mutable TypeInfo const * mTypeInfo; ///< The type-info for this object, mutable so it can be lazy initialized from const method if it is required
590 Dali::Vector<Observer*> mObservers;
592 ConstraintContainer* mConstraints; ///< Container of owned -constraints.
594 typedef std::vector< Dali::PropertyNotification > PropertyNotificationContainer;
595 typedef PropertyNotificationContainer::iterator PropertyNotificationContainerIter;
596 typedef PropertyNotificationContainer::const_iterator PropertyNotificationContainerConstIter;
597 PropertyNotificationContainer* mPropertyNotifications; ///< Container of owned property notifications.
599 } // namespace Internal
601 // Helpers for public-api forwarding methods
603 inline Internal::Object& GetImplementation(Dali::Handle& object)
605 DALI_ASSERT_ALWAYS( object && "Object handle is empty" );
607 BaseObject& handle = object.GetBaseObject();
609 return static_cast<Internal::Object&>(handle);
612 inline const Internal::Object& GetImplementation(const Dali::Handle& object)
614 DALI_ASSERT_ALWAYS( object && "Object handle is empty" );
616 const BaseObject& handle = object.GetBaseObject();
618 return static_cast<const Internal::Object&>(handle);
623 #endif // __DALI_INTERNAL_OBJECT_H__