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;
45 class EventThreadServices;
47 class PropertyCondition;
48 class PropertyInputImpl;
58 typedef std::vector< Dali::Constraint > ConstraintContainer;
59 typedef ConstraintContainer::iterator ConstraintIter;
60 typedef ConstraintContainer::const_iterator ConstraintConstIter;
64 * A base class for objects which optionally provide properties.
65 * The concrete derived class is responsible for implementing the property system methods.
66 * Classes may derive from Dali::BaseObject, until any properties are required.
68 * An object for a property-owning object in the scene-graph.
69 * This provides an interface for observing the addition/removal of scene-objects.
71 * The concrete derived class is responsible for:
72 * 1) Adding & removing an object from the scene-graph. The OnSceneObjectAdd() and OnSceneObjectRemove()
73 * methods should be called by the derived class, to trigger observer callbacks.
74 * 3) Implementing the GetSceneObject() methods, used to access the scene-object.
75 * 4) Providing access to properties stored by the scene-graph object. These should match the properties
76 * reported by the base Dali::Internal::Object methods.
79 class Object : public Dali::BaseObject
83 typedef Dali::Handle::Capability Capability;
90 * Called immediately after the object has created & passed ownership of a scene-graph object.
91 * @param[in] object The object object.
93 virtual void SceneObjectAdded(Object& object) = 0;
96 * Called shortly before the object sends a message to remove its scene object.
97 * @param[in] object The object object.
99 virtual void SceneObjectRemoved(Object& object) = 0;
102 * Called shortly before the object itself is destroyed; no further callbacks will be received.
103 * @param[in] object The object object.
105 virtual void ObjectDestroyed(Object& object) = 0;
112 virtual ~Observer(){}
121 * Add an observer to the object.
122 * @param[in] observer The observer to add.
124 virtual void AddObserver( Observer& observer );
127 * Remove an observer from the object
128 * @pre The observer has already been added.
129 * @param[in] observer The observer to remove.
131 virtual void RemoveObserver( Observer& observer );
134 * @copydoc Dali::Handle::Supports()
136 virtual bool Supports( Capability capability ) const;
139 * @copydoc Dali::Handle::GetPropertyCount()
141 virtual unsigned int GetPropertyCount() const;
144 * @copydoc Dali::Handle::GetPropertyName()
146 virtual std::string GetPropertyName( Property::Index index ) const;
149 * @copydoc Dali::Handle::GetPropertyIndex()
151 virtual Property::Index GetPropertyIndex( const std::string& name ) const;
154 * @copydoc Dali::Handle::GetPropertyIndex()
156 virtual Property::Index GetPropertyIndex( Property::Index key ) const;
159 * @copydoc Dali::Handle::GetPropertyIndex()
161 virtual Property::Index GetPropertyIndex( Property::Key key ) const;
164 * @copydoc Dali::Handle::IsPropertyWritable()
166 virtual bool IsPropertyWritable( Property::Index index ) const;
169 * @copydoc Dali::Handle::IsPropertyAnimatable()
171 virtual bool IsPropertyAnimatable( Property::Index index ) const;
174 * @copydoc Dali::Handle::IsPropertyAConstraintInput()
176 virtual bool IsPropertyAConstraintInput( Property::Index index ) const;
179 * @copydoc Dali::Handle::GetPropertyType()
181 virtual Property::Type GetPropertyType( Property::Index index ) const;
184 * @copydoc Dali::Handle::SetProperty()
186 virtual void SetProperty( Property::Index index, const Property::Value& propertyValue );
189 * @copydoc Dali::Handle::GetProperty()
191 virtual Property::Value GetProperty( Property::Index index ) const;
194 * @brief Retrieves the latest value of the property on the scene-graph.
195 * @param[in] index The index of the property required.
196 * @return The latest value of the property on the scene-graph.
198 virtual Property::Value GetCurrentProperty( Property::Index index ) const;
201 * @copydoc Dali::Handle::GetPropertyIndices()
203 virtual void GetPropertyIndices( Property::IndexContainer& indices ) const;
206 * @copydoc Dali::Handle::RegisterProperty()
208 virtual Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue );
211 * @copydoc Dali::Handle::RegisterProperty()
213 virtual Property::Index RegisterProperty( const std::string& name, Property::Index key, const Property::Value& propertyValue );
216 * @copydoc Dali::Handle::RegisterProperty(std::string name, Property::Value propertyValue, Property::AccessMode accessMode)
218 virtual Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode );
221 * @brief Implementing method for this override
223 virtual Property::Index RegisterProperty( const std::string& name, Property::Index key, const Property::Value& propertyValue, Property::AccessMode accessMode );
226 * @copydoc Dali::Handle::AddPropertyNotification()
228 virtual Dali::PropertyNotification AddPropertyNotification( Property::Index index,
230 const Dali::PropertyCondition& condition );
233 * @copydoc Dali::Handle::RemovePropertyNotification()
235 virtual void RemovePropertyNotification( Dali::PropertyNotification propertyNotification );
238 * @copydoc Dali::Handle::RemovePropertyNotifications()
240 virtual void RemovePropertyNotifications();
242 /******************************** Uniform Mappings ********************************/
245 * @copydoc Dali::Handle::AddUniformMapping()
247 void AddUniformMapping( Property::Index propertyIndex, const std::string& uniformName ) const;
250 * @copydoc Dali::Handle::RemoveUniformMapping( )
252 void RemoveUniformMapping( const std::string& uniformName );
254 /******************************** Constraints ********************************/
257 * Apply a constraint to an Object.
258 * @param[in] constraint The constraint to apply.
260 void ApplyConstraint( ConstraintBase& constraint );
263 * Remove one constraint from an Object.
264 * @param[in] constraint The constraint to remove.
266 void RemoveConstraint( ConstraintBase& constraint );
269 * Remove all constraints from a Object.
271 void RemoveConstraints();
274 * Remove all constraints from a Object with a matching tag
276 void RemoveConstraints( unsigned int tag );
279 * Called by TypeInfo to set the type-info that this object-impl is created by.
280 * @param[in] typeInfo The TypeInfo that creates this object-impl.
282 void SetTypeInfo( const TypeInfo* typeInfo );
285 * @return the index from which custom properties start
287 unsigned int CustomPropertyStartIndex()
289 return PROPERTY_CUSTOM_START_INDEX;
292 /******************** To be overridden by deriving classes ********************/
295 * Retrieve the scene-graph object added by this object.
296 * @return A pointer to the object, or NULL if no object has been added to the scene-graph.
298 virtual const SceneGraph::PropertyOwner* GetSceneObject() const = 0;
301 * Retrieve an animatable property owned by the scene-graph object.
302 * @pre -1 < index < GetPropertyCount().
303 * @param[in] index The index of the property.
304 * @return A dereferenceable pointer to a property, or NULL if a scene-object does not exist with this property.
306 virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const = 0;
309 * Retrieve a constraint input-property owned by the scene-graph object.
310 * @pre -1 < index < GetPropertyCount().
311 * @param[in] index The index of the property.
312 * @return A dereferenceable pointer to an input property, or NULL if a scene-object does not exist with this property.
314 virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const = 0;
317 * Query whether the property is a component of a scene-graph property.
318 * @pre -1 < index < GetPropertyCount().
319 * @param[in] index The index of the property.
320 * @return The index or Property::INVALID_COMPONENT_INDEX.
322 virtual int GetPropertyComponentIndex( Property::Index index ) const;
327 * A reference counted object may only be deleted by calling Unreference()
332 * Called immediately by derived classes, after the scene-object has been created & passed to the scene-graph.
334 void OnSceneObjectAdd();
337 * Called by derived classes, shortly before send a message to remove the scene-object.
339 void OnSceneObjectRemove();
342 * For overriding by derived classes to return the parent of this object.
344 virtual Object* GetParentObject() const
346 // By default the Object does not have a parent
351 * For use in derived classes.
352 * This is called after a property is set.
353 * @param [in] index The index of the property.
354 * @param [in] propertyValue The value of the property.
356 virtual void OnPropertySet( Property::Index index, Property::Value propertyValue ) {}
359 * Retrieves the TypeInfo for this object. Only retrieves it from the type-registry once and then stores a pointer
360 * to it locally there-after. The type info will not change during the life-time of the application.
361 * @return The type-info for this object (Can be NULL)
363 const TypeInfo* GetTypeInfo() const;
366 * Helper to find custom property
368 * @return pointer to the property
370 CustomPropertyMetadata* FindCustomProperty( Property::Index index ) const;
373 * Helper to find animatable property
375 * @return pointer to the property
377 AnimatablePropertyMetadata* FindAnimatableProperty( Property::Index index ) const;
380 * Helper to register a scene-graph property
381 * @param [in] name The name of the property.
382 * @param [in] key The key of the property
383 * @param [in] index The index of the property
384 * @param [in] value The value of the property.
385 * @return The index of the registered property or Property::INVALID_INDEX if registration failed.
387 Property::Index RegisterSceneGraphProperty(const std::string& name, Property::Index key, Property::Index index, const Property::Value& propertyValue) const;
390 * Check whether the animatable property is registered already, if not then register one.
391 * @param [in] index The index of the property
392 * @return pointer to the property.
394 AnimatablePropertyMetadata* RegisterAnimatableProperty(Property::Index index) const;
397 * Resolve the index and name of child properties if any.
399 void ResolveChildProperties();
401 private: // Default property extensions for derived classes
404 * Query how many default properties the derived class supports.
405 * @return The number of default properties.
407 virtual unsigned int GetDefaultPropertyCount() const = 0;
410 * Retrieve all the indices that are associated with the default properties supported by the derived class.
411 * @return A container of default property indices.
412 * @note The deriving class must not modify the existing elements in the container.
414 virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const = 0;
417 * Query how many default properties the derived class supports.
418 * @return The number of default properties.
420 virtual const char* GetDefaultPropertyName( Property::Index index ) const = 0;
423 * Query the index of a default property.
424 * @param [in] name The name of the property.
425 * @return The index of the property, or Property::INVALID_INDEX if no default property exists with the given name.
427 virtual Property::Index GetDefaultPropertyIndex( const std::string& name ) const = 0;
430 * Query whether a default property is writable.
431 * @param [in] index The index of the property.
432 * @return True if the property is animatable.
434 virtual bool IsDefaultPropertyWritable( Property::Index index ) const = 0;
437 * Query whether a default property is animatable.
438 * This determines whether the property can be the target of an animation or constraint.
439 * @param [in] index The index of the property.
440 * @return True if the property is animatable.
442 virtual bool IsDefaultPropertyAnimatable( Property::Index index ) const = 0;
445 * @brief Query whether a default property can be used as an input to a constraint.
447 * @param [in] index The index of the property.
448 * @return True if the property can be used as an input to a constraint.
450 virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const = 0;
453 * Query the type of a default property.
454 * @param [in] index The index of the property.
455 * @return The type of the property.
457 virtual Property::Type GetDefaultPropertyType( Property::Index index ) const = 0;
460 * Set the value of a default property.
461 * @pre The property types match i.e. propertyValue.GetType() is equal to GetPropertyType(index).
462 * @param [in] index The index of the property.
463 * @param [in] propertyValue The new value of the property.
465 virtual void SetDefaultProperty( Property::Index index, const Property::Value& propertyValue ) = 0;
468 * Retrieve a default property value.
469 * @param [in] index The index of the property.
470 * @return The property value.
472 virtual Property::Value GetDefaultProperty( Property::Index index ) const = 0;
475 * Retrieve the latest scene-graph value of a default property.
476 * @param[in] index The index of the property.
477 * @return The latest scene-graph value of a default property.
479 virtual Property::Value GetDefaultPropertyCurrentValue( Property::Index index ) const = 0;
482 * @todo this is virtual so that for now actor can override it,
483 * it needs to be removed and only have GetSceneObject but that requires changing actor and constraint logic
484 * Retrieve the scene-graph object added by this object.
485 * @return A pointer to the object, or NULL if no object has been added to the scene-graph.
487 virtual const SceneGraph::PropertyOwner* GetPropertyOwner() const
489 return GetSceneObject();
493 * Notify derived class of installation of a new scene-object property.
494 * This method is called after the message is to sent to install the property
495 * @param [in] newProperty A newly allocated scene-object property. Ownership is obviously not passed.
496 * @param [in] name The name allocated to this custom property.
497 * @param [in] index The index allocated to this custom property.
499 virtual void NotifyScenePropertyInstalled( const SceneGraph::PropertyBase& newProperty, const std::string& name, unsigned int index ) const
505 Object(const Object& rhs);
508 Object& operator=(const Object& rhs);
511 * Enable property notifications in scene graph
513 void EnablePropertyNotifications();
516 * Enable property notifications in scene graph
518 void DisablePropertyNotifications();
521 * Get the latest value of the property on the scene-graph.
522 * @param[in] entry An entry from the property lookup container.
523 * @return The latest value of the property.
525 Property::Value GetCurrentPropertyValue( const PropertyMetadata* entry ) const;
528 * Set the value of scene graph property.
529 * @param [in] index The index of the property.
530 * @param [in] entry An entry from the property lookup container.
531 * @param [in] value The new value of the property.
533 virtual void SetSceneGraphProperty( Property::Index index, const PropertyMetadata& entry, const Property::Value& value );
537 * Get the event thread services object - used for sending messages to the scene graph
538 * Assert if called from the wrong thread.
539 * This is intentionally inline for performance reasons.
541 * @return The event thread services object
543 inline EventThreadServices& GetEventThreadServices()
545 DALI_ASSERT_DEBUG( EventThreadServices::IsCoreRunning() );
546 return mEventThreadServices;
550 * Get the event thread services object - used for sending messages to the scene graph
551 * Assert if called from the wrong thread
552 * This is intentionally inline for performance reasons.
554 * @return The event thread services object
556 inline const EventThreadServices& GetEventThreadServices() const
558 DALI_ASSERT_DEBUG( EventThreadServices::IsCoreRunning() );
559 return mEventThreadServices;
563 EventThreadServices& mEventThreadServices;
567 typedef OwnerContainer<PropertyMetadata*> PropertyMetadataLookup;
568 mutable PropertyMetadataLookup mCustomProperties; ///< Used for accessing custom Node properties
569 mutable PropertyMetadataLookup mAnimatableProperties; ///< Used for accessing animatable Node properties
570 mutable TypeInfo const * mTypeInfo; ///< The type-info for this object, mutable so it can be lazy initialized from const method if it is required
572 Dali::Vector<Observer*> mObservers;
574 ConstraintContainer* mConstraints; ///< Container of owned -constraints.
576 typedef std::vector< Dali::PropertyNotification > PropertyNotificationContainer;
577 typedef PropertyNotificationContainer::iterator PropertyNotificationContainerIter;
578 typedef PropertyNotificationContainer::const_iterator PropertyNotificationContainerConstIter;
579 PropertyNotificationContainer* mPropertyNotifications; ///< Container of owned property notifications.
581 } // namespace Internal
583 // Helpers for public-api forwarding methods
585 inline Internal::Object& GetImplementation(Dali::Handle& object)
587 DALI_ASSERT_ALWAYS( object && "Object handle is empty" );
589 BaseObject& handle = object.GetBaseObject();
591 return static_cast<Internal::Object&>(handle);
594 inline const Internal::Object& GetImplementation(const Dali::Handle& object)
596 DALI_ASSERT_ALWAYS( object && "Object handle is empty" );
598 const BaseObject& handle = object.GetBaseObject();
600 return static_cast<const Internal::Object&>(handle);
605 #endif // __DALI_INTERNAL_OBJECT_H__