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/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::ActiveConstraint > ActiveConstraintContainer;
59 typedef ActiveConstraintContainer::iterator ActiveConstraintIter;
60 typedef ActiveConstraintContainer::const_iterator ActiveConstraintConstIter;
63 * A base class for objects which optionally provide properties.
64 * The concrete derived class is responsible for implementing the property system methods.
65 * Classes may derive from Dali::BaseObject, until any properties are required.
67 * An object for a property-owning object in the scene-graph.
68 * This provides an interface for observing the addition/removal of scene-objects.
70 * The concrete derived class is responsible for:
71 * 1) Adding & removing an object from the scene-graph. The OnSceneObjectAdd() and OnSceneObjectRemove()
72 * methods should be called by the derived class, to trigger observer callbacks.
73 * 3) Implementing the GetSceneObject() methods, used to access the scene-object.
74 * 4) Providing access to properties stored by the scene-graph object. These should match the properties
75 * reported by the base Dali::Internal::Object methods.
78 class Object : public Dali::BaseObject
82 typedef Dali::Handle::Capability Capability;
89 * Called immediately after the object has created & passed ownership of a scene-graph object.
90 * @param[in] object The object object.
92 virtual void SceneObjectAdded(Object& object) = 0;
95 * Called shortly before the object sends a message to remove its scene object.
96 * @param[in] object The object object.
98 virtual void SceneObjectRemoved(Object& object) = 0;
101 * Called shortly before the object itself is destroyed; no further callbacks will be received.
102 * @param[in] object The object object.
104 virtual void ObjectDestroyed(Object& object) = 0;
111 virtual ~Observer(){}
120 * Add an observer to the object.
121 * @param[in] observer The observer to add.
123 virtual void AddObserver( Observer& observer );
126 * Remove an observer from the object
127 * @pre The observer has already been added.
128 * @param[in] observer The observer to remove.
130 virtual void RemoveObserver( Observer& observer );
133 * @copydoc Dali::Handle::Supports()
135 virtual bool Supports( Capability capability ) const;
138 * @copydoc Dali::Handle::GetPropertyCount()
140 virtual unsigned int GetPropertyCount() const;
143 * @copydoc Dali::Handle::GetPropertyName()
145 virtual std::string GetPropertyName( Property::Index index ) const;
148 * @copydoc Dali::Handle::GetPropertyIndex()
150 virtual Property::Index GetPropertyIndex( const std::string& name ) const;
153 * @copydoc Dali::Handle::IsPropertyWritable()
155 virtual bool IsPropertyWritable( Property::Index index ) const;
158 * @copydoc Dali::Handle::IsPropertyAnimatable()
160 virtual bool IsPropertyAnimatable( Property::Index index ) const;
163 * @copydoc Dali::Handle::IsPropertyAConstraintInput()
165 virtual bool IsPropertyAConstraintInput( Property::Index index ) const;
168 * @copydoc Dali::Handle::GetPropertyType()
170 virtual Property::Type GetPropertyType( Property::Index index ) const;
173 * @copydoc Dali::Handle::SetProperty()
175 virtual void SetProperty( Property::Index index, const Property::Value& propertyValue );
178 * @copydoc Dali::Handle::GetProperty()
180 virtual Property::Value GetProperty( Property::Index index ) const;
183 * @copydoc Dali::Handle::GetPropertyIndices()
185 virtual void GetPropertyIndices( Property::IndexContainer& indices ) const;
188 * @copydoc Dali::Handle::RegisterProperty()
190 virtual Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue );
193 * @copydoc Dali::Handle::RegisterProperty(std::string name, Property::Value propertyValue, Property::AccessMode accessMode)
195 virtual Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode );
198 * @copydoc Dali::Handle::AddPropertyNotification()
200 virtual Dali::PropertyNotification AddPropertyNotification( Property::Index index,
202 const Dali::PropertyCondition& condition );
205 * @copydoc Dali::Handle::RemovePropertyNotification()
207 virtual void RemovePropertyNotification( Dali::PropertyNotification propertyNotification );
210 * @copydoc Dali::Handle::RemovePropertyNotifications()
212 virtual void RemovePropertyNotifications();
217 * Apply a constraint to a Object.
218 * @param[in] constraint The constraint to apply.
220 Dali::ActiveConstraint ApplyConstraint( Constraint& constraint );
223 * Apply a constraint to a Object.
224 * @param[in] constraint The constraint to apply.
225 * @param[in] weightObject An object with a "weight" float property.
227 Dali::ActiveConstraint ApplyConstraint( Constraint& constraint, Dali::Handle weightObject );
230 * Remove one constraint from a Object.
231 * @param[in] activeConstraint The active constraint to remove.
233 void RemoveConstraint( Dali::ActiveConstraint activeConstraint );
236 * Remove all constraints from a Object.
238 void RemoveConstraints();
241 * Remove all constraints from a Object with a matching tag
243 void RemoveConstraints( unsigned int tag );
246 * Called by TypeInfo to set the type-info that this object-impl is created by.
247 * @param[in] typeInfo The TypeInfo that creates this object-impl.
249 void SetTypeInfo( const TypeInfo* typeInfo );
252 * @return the index from which custom properties start
254 unsigned int CustomPropertyStartIndex()
256 return PROPERTY_CUSTOM_START_INDEX;
259 // To be overridden by deriving classes
262 * Retrieve the scene-graph object added by this object.
263 * @return A pointer to the object, or NULL if no object has been added to the scene-graph.
265 virtual const SceneGraph::PropertyOwner* GetSceneObject() const = 0;
268 * Retrieve an animatable property owned by the scene-graph object.
269 * @pre -1 < index < GetPropertyCount().
270 * @param[in] index The index of the property.
271 * @return A dereferenceable pointer to a property, or NULL if a scene-object does not exist with this property.
273 virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const = 0;
276 * Retrieve an constraint input-property owned by the scene-graph object.
277 * @pre -1 < index < GetPropertyCount().
278 * @param[in] index The index of the property.
279 * @return A dereferenceable pointer to an input property, or NULL if a scene-object does not exist with this property.
281 virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const = 0;
284 * Query whether the property is a component of a scene-graph property.
285 * @pre -1 < index < GetPropertyCount().
286 * @param[in] index The index of the property.
287 * @return The index or Property::INVALID_COMPONENT_INDEX.
289 virtual int GetPropertyComponentIndex( Property::Index index ) const;
294 * A reference counted object may only be deleted by calling Unreference()
299 * Called immediately by derived classes, after the scene-object has been created & passed to the scene-graph.
301 void OnSceneObjectAdd();
304 * Called by derived classes, shortly before send a message to remove the scene-object.
306 void OnSceneObjectRemove();
309 * For use in derived classes.
310 * This is called after a non animatable custom property is set.
311 * @param [in] index The index of the property.
312 * @param [in] propertyValue The value of the property.
314 virtual void OnPropertySet( Property::Index index, Property::Value propertyValue ) {}
317 * Retrieves the TypeInfo for this object. Only retrieves it from the type-registry once and then stores a pointer
318 * to it locally there-after. The type info will not change during the life-time of the application.
319 * @return The type-info for this object (Can be NULL)
321 const TypeInfo* GetTypeInfo() const;
324 * Helper to find custom property
326 * @return pointer to the property
328 CustomPropertyMetadata* FindCustomProperty( Property::Index index ) const;
331 * Helper to find animatable property
333 * @return pointer to the property
335 AnimatablePropertyMetadata* FindAnimatableProperty( Property::Index index ) const;
338 * Helper to register a scene-graph property
339 * @param [in] name The name of the property.
340 * @param [in] index The index of the property
341 * @param [in] value The value of the property.
342 * @return The index of the registered property or Property::INVALID_INDEX if registration failed.
344 Property::Index RegisterSceneGraphProperty(const std::string& name, Property::Index index, const Property::Value& propertyValue) const;
346 private: // Default property extensions for derived classes
349 * Query how many default properties the derived class supports.
350 * @return The number of default properties.
352 virtual unsigned int GetDefaultPropertyCount() const = 0;
355 * Retrieve all the indices that are associated with the default properties supported by the derived class.
356 * @return A container of default property indices.
357 * @note The deriving class must not modify the existing elements in the container.
359 virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const = 0;
362 * Query how many default properties the derived class supports.
363 * @return The number of default properties.
365 virtual const char* GetDefaultPropertyName( Property::Index index ) const = 0;
368 * Query the index of a default property.
369 * @param [in] name The name of the property.
370 * @return The index of the property, or Property::INVALID_INDEX if no default property exists with the given name.
372 virtual Property::Index GetDefaultPropertyIndex( const std::string& name ) const = 0;
375 * Query whether a default property is writable.
376 * @param [in] index The index of the property.
377 * @return True if the property is animatable.
379 virtual bool IsDefaultPropertyWritable( Property::Index index ) const = 0;
382 * Query whether a default property is animatable.
383 * This determines whether the property can be the target of an animation or constraint.
384 * @param [in] index The index of the property.
385 * @return True if the property is animatable.
387 virtual bool IsDefaultPropertyAnimatable( Property::Index index ) const = 0;
390 * @brief Query whether a default property can be used as an input to a constraint.
392 * @param [in] index The index of the property.
393 * @return True if the property can be used as an input to a constraint.
395 virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const = 0;
398 * Query the type of a default property.
399 * @param [in] index The index of the property.
400 * @return The type of the property.
402 virtual Property::Type GetDefaultPropertyType( Property::Index index ) const = 0;
405 * Set the value of a default property.
406 * @pre The property types match i.e. propertyValue.GetType() is equal to GetPropertyType(index).
407 * @param [in] index The index of the property.
408 * @param [in] propertyValue The new value of the property.
410 virtual void SetDefaultProperty( Property::Index index, const Property::Value& propertyValue ) = 0;
413 * Retrieve a default property value.
414 * @param [in] index The index of the property.
415 * @return The property value.
417 virtual Property::Value GetDefaultProperty( Property::Index index ) const = 0;
420 * @todo this is virtual so that for now actor can override it,
421 * it needs to be removed and only have GetSceneObject but that requires changing actor and constraint logic
422 * Retrieve the scene-graph object added by this object.
423 * @return A pointer to the object, or NULL if no object has been added to the scene-graph.
425 virtual const SceneGraph::PropertyOwner* GetPropertyOwner() const
427 return GetSceneObject();
431 * Notify derived class of installation of a new scene-object property.
432 * This method is called after the message is to sent to install the property
433 * @param [in] newProperty A newly allocated scene-object property. Ownership is obviously not passed.
434 * @param [in] name The name allocated to this custom property.
435 * @param [in] index The index allocated to this custom property.
437 virtual void NotifyScenePropertyInstalled( const SceneGraph::PropertyBase& newProperty, const std::string& name, unsigned int index ) const
443 Object(const Object& rhs);
446 Object& operator=(const Object& rhs);
449 * Enable property notifications in scene graph
451 void EnablePropertyNotifications();
454 * Enable property notifications in scene graph
456 void DisablePropertyNotifications();
459 * Helper for ApplyConstraint overloads.
460 * @param[in] constraint The constraint to apply.
461 * @param[in] weightObject An object with a "weight" float property, or an empty handle.
462 * @return The new active-constraint which is owned by Object.
464 ActiveConstraintBase* DoApplyConstraint( Constraint& constraint, Dali::Handle weightObject );
467 * Helper to remove active constraints
469 void RemoveConstraint( ActiveConstraint& constraint, bool isInScenegraph );
472 * Get the value of the property.
473 * @param [in] entry An entry from the property lookup container.
474 * @return The new value of the property.
476 Property::Value GetPropertyValue( const PropertyMetadata* entry ) const;
479 * Set the value of scene graph property.
480 * @param [in] index The index of the property.
481 * @param [in] entry An entry from the property lookup container.
482 * @param [in] value The new value of the property.
484 virtual void SetSceneGraphProperty( Property::Index index, const PropertyMetadata& entry, const Property::Value& value );
488 * Get the event thread services object - used for sending messages to the scene graph
489 * Assert if called from the wrong thread.
490 * This is intentionally inline for performance reasons.
492 * @return The event thread services object
494 inline EventThreadServices& GetEventThreadServices()
496 DALI_ASSERT_DEBUG( EventThreadServices::IsCoreRunning() );
497 return mEventThreadServices;
501 * Get the event thread services object - used for sending messages to the scene graph
502 * Assert if called from the wrong thread
503 * This is intentionally inline for performance reasons.
505 * @return The event thread services object
507 inline const EventThreadServices& GetEventThreadServices() const
509 DALI_ASSERT_DEBUG( EventThreadServices::IsCoreRunning() );
510 return mEventThreadServices;
514 EventThreadServices& mEventThreadServices;
518 typedef OwnerContainer<PropertyMetadata*> PropertyMetadataLookup;
519 mutable PropertyMetadataLookup mCustomProperties; ///< Used for accessing custom Node properties
520 mutable PropertyMetadataLookup mAnimatableProperties; ///< Used for accessing animatable Node properties
521 mutable TypeInfo const * mTypeInfo; ///< The type-info for this object, mutable so it can be lazy initialized from const method if it is required
523 Dali::Vector<Observer*> mObservers;
525 ActiveConstraintContainer* mConstraints; ///< Container of owned active-constraints.
527 typedef std::vector< Dali::PropertyNotification > PropertyNotificationContainer;
528 typedef PropertyNotificationContainer::iterator PropertyNotificationContainerIter;
529 typedef PropertyNotificationContainer::const_iterator PropertyNotificationContainerConstIter;
530 PropertyNotificationContainer* mPropertyNotifications; ///< Container of owned property notifications.
533 } // namespace Internal
535 // Helpers for public-api forwarding methods
537 inline Internal::Object& GetImplementation(Dali::Handle& object)
539 DALI_ASSERT_ALWAYS( object && "Object handle is empty" );
541 BaseObject& handle = object.GetBaseObject();
543 return static_cast<Internal::Object&>(handle);
546 inline const Internal::Object& GetImplementation(const Dali::Handle& object)
548 DALI_ASSERT_ALWAYS( object && "Object handle is empty" );
550 const BaseObject& handle = object.GetBaseObject();
552 return static_cast<const Internal::Object&>(handle);
557 #endif // __DALI_INTERNAL_OBJECT_H__