1 #ifndef __DALI_INTERNAL_PROXY_OBJECT_H__
2 #define __DALI_INTERNAL_PROXY_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.
25 #include <dali/public-api/animation/active-constraint.h>
26 #include <dali/public-api/animation/constraint.h>
27 #include <dali/public-api/common/dali-vector.h>
28 #include <dali/public-api/common/vector-wrapper.h>
29 #include <dali/public-api/object/constrainable.h>
30 #include <dali/public-api/object/property-index.h>
31 #include <dali/public-api/object/property-input.h>
32 #include <dali/public-api/object/property-notification.h>
33 #include <dali/internal/common/owner-container.h>
34 #include <dali/internal/event/common/object-impl.h>
35 #include <dali/internal/event/common/custom-property.h>
36 #include <dali/internal/event/common/property-input-impl.h>
37 #include <dali/internal/update/common/property-base.h>
46 class PropertyInputImpl;
52 * @brief Structure for setting up default properties and their details.
54 struct PropertyDetails
56 const char* name; ///< The name of the property.
57 Property::Type type; ///< The property type.
58 bool writable:1; ///< Whether the property is writable
59 bool animatable:1; ///< Whether the property is animatable.
60 bool constraintInput:1; ///< Whether the property can be used as an input to a constraint.
69 typedef std::vector< Dali::ActiveConstraint > ActiveConstraintContainer;
70 typedef ActiveConstraintContainer::iterator ActiveConstraintIter;
71 typedef ActiveConstraintContainer::const_iterator ActiveConstraintConstIter;
74 * A proxy for a property-owning object in the scene-graph.
75 * This provides an interface for observing the addition/removal of scene-objects.
77 * The concrete derived class is responsible for:
78 * 1) Adding & removing an object from the scene-graph. The OnSceneObjectAdd() and OnSceneObjectRemove()
79 * methods should be called by the derived class, to trigger observer callbacks.
80 * 3) Implementing the GetSceneObject() methods, used to access the scene-object.
81 * 4) Providing access to properties stored by the scene-graph object. These should match the properties
82 * reported by the base Dali::Internal::Object methods.
84 class ProxyObject : public Object
93 * Called immediately after the proxy has created & passed ownership of a scene-graph object.
94 * @param[in] proxy The proxy object.
96 virtual void SceneObjectAdded(ProxyObject& proxy) = 0;
99 * Called shortly before the proxy sends a message to remove its scene object.
100 * @param[in] proxy The proxy object.
102 virtual void SceneObjectRemoved(ProxyObject& proxy) = 0;
105 * Called shortly before the proxy itself is destroyed; no further callbacks will be received.
106 * @param[in] proxy The proxy object.
108 virtual void ProxyDestroyed(ProxyObject& proxy) = 0;
114 virtual ~Observer(){}
123 * Query whether the proxy object removes (& re-adds) its associated scene-object.
124 * Otherwise the scene-object lifetime is expected to match that of the proxy.
125 * @return True if scene-objects are removed.
127 virtual bool IsSceneObjectRemovable() const = 0;
130 * Add an observer to the proxy.
131 * @param[in] observer The observer to add.
133 virtual void AddObserver(Observer& observer);
136 * Remove an observer from the proxy
137 * @pre The observer has already been added.
138 * @param[in] observer The observer to remove.
140 virtual void RemoveObserver(Observer& observer);
143 * Retrieve the scene-graph object added by this proxy.
144 * @return A pointer to the object, or NULL if no object has been added to the scene-graph.
146 virtual const SceneGraph::PropertyOwner* GetSceneObject() const = 0;
149 * Retrieve an animatable property owned by the scene-graph object.
150 * @pre -1 < index < GetPropertyCount().
151 * @param[in] index The index of the property.
152 * @return A dereferenceable pointer to a property, or NULL if a scene-object does not exist with this property.
154 virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const = 0;
157 * Retrieve an constraint input-property owned by the scene-graph object.
158 * @pre -1 < index < GetPropertyCount().
159 * @param[in] index The index of the property.
160 * @return A dereferenceable pointer to an input property, or NULL if a scene-object does not exist with this property.
162 virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const = 0;
165 * Query whether the property is a component of a scene-graph property.
166 * @pre -1 < index < GetPropertyCount().
167 * @param[in] index The index of the property.
168 * @return The index or Property::INVALID_COMPONENT_INDEX.
170 virtual int GetPropertyComponentIndex( Property::Index index ) const;
172 public: // Property system interface from Internal::Object
175 * @copydoc Dali::Internal::Object::Supports()
177 virtual bool Supports( Object::Capability capability ) const;
180 * @copydoc Dali::Internal::Object::GetPropertyCount()
182 virtual unsigned int GetPropertyCount() const;
185 * @copydoc Dali::Internal::Object::GetPropertyName()
187 virtual std::string GetPropertyName( Property::Index index ) const;
190 * @copydoc Dali::Internal::Object::GetPropertyIndex()
192 virtual Property::Index GetPropertyIndex(const std::string& name) const;
195 * @copydoc Dali::Internal::Object::IsPropertyWritable()
197 virtual bool IsPropertyWritable(Property::Index index) const;
200 * @copydoc Dali::Internal::Object::IsPropertyAnimatable()
202 virtual bool IsPropertyAnimatable(Property::Index index) const;
205 * @copydoc Dali::Internal::Object::IsPropertyAConstraintInput()
207 virtual bool IsPropertyAConstraintInput(Property::Index index) const;
210 * @copydoc Dali::Internal::Object::GetPropertyType()
212 virtual Property::Type GetPropertyType(Property::Index index) const;
215 * @copydoc Dali::Internal::Object::SetProperty()
217 virtual void SetProperty(Property::Index index, const Property::Value& propertyValue);
220 * @copydoc Dali::Internal::Object::GetProperty()
222 virtual Property::Value GetProperty(Property::Index index) const;
225 * @copydoc Dali::Handle::GetPropertyIndices()
227 virtual void GetPropertyIndices( Property::IndexContainer& indices ) const;
230 * @copydoc Dali::Internal::Object::RegisterProperty()
232 virtual Property::Index RegisterProperty(std::string name, const Property::Value& propertyValue);
235 * @copydoc Dali::Internal::Object::RegisterProperty(std::string name, Property::Value propertyValue, Property::AccessMode accessMode)
237 virtual Property::Index RegisterProperty(std::string name, const Property::Value& propertyValue, Property::AccessMode accessMode);
240 * @copydoc Dali::Internal::Object::AddPropertyNotification()
242 virtual Dali::PropertyNotification AddPropertyNotification(Property::Index index,
244 const Dali::PropertyCondition& condition);
247 * @copydoc Dali::Internal::Object::RemovePropertyNotification()
249 virtual void RemovePropertyNotification(Dali::PropertyNotification propertyNotification);
252 * @copydoc Dali::Internal::Object::RemovePropertyNotifications()
254 void RemovePropertyNotifications();
258 * Enable property notifications in scene graph
260 void EnablePropertyNotifications();
263 * Enable property notifications in scene graph
265 void DisablePropertyNotifications();
267 public: // Constraints
270 * Apply a constraint to a ProxyObject.
271 * @param[in] constraint The constraint to apply.
273 Dali::ActiveConstraint ApplyConstraint( Constraint& constraint );
276 * Apply a constraint to a ProxyObject.
277 * @param[in] constraint The constraint to apply.
278 * @param[in] weightObject An object with a "weight" float property.
280 Dali::ActiveConstraint ApplyConstraint( Constraint& constraint, Dali::Constrainable weightObject );
283 * Remove one constraint from a ProxyObject.
284 * @param[in] activeConstraint The active constraint to remove.
286 void RemoveConstraint( Dali::ActiveConstraint activeConstraint );
289 * Remove all constraints from a ProxyObject.
291 void RemoveConstraints();
294 * Remove all constraints from a ProxyObject with a matching tag
296 void RemoveConstraints( unsigned int tag );
301 * Called by TypeInfo to set the type-info that this proxy-object is created by.
302 * @param[in] typeInfo The TypeInfo that creates this proxy-object.
304 void SetTypeInfo( const TypeInfo* typeInfo );
307 * @return the index from which custom properties start
309 unsigned int CustomPropertyStartIndex()
311 return PROPERTY_CUSTOM_START_INDEX;
317 * Called immediately by derived classes, after the scene-object has been created & passed to the scene-graph.
319 void OnSceneObjectAdd();
322 * Called by derived classes, shortly before send a message to remove the scene-object.
324 void OnSceneObjectRemove();
327 * A reference counted object may only be deleted by calling Unreference()
329 virtual ~ProxyObject();
334 ProxyObject(const ProxyObject&);
337 ProxyObject& operator=(const ProxyObject& rhs);
340 * Helper for ApplyConstraint overloads.
341 * @param[in] constraint The constraint to apply.
342 * @param[in] weightObject An object with a "weight" float property, or an empty handle.
343 * @return The new active-constraint which is owned by ProxyObject.
345 ActiveConstraintBase* DoApplyConstraint( Constraint& constraint, Dali::Constrainable weightObject );
348 * Helper to remove active constraints
350 void RemoveConstraint( ActiveConstraint& constraint, bool isInScenegraph );
353 private: // Default property extensions for derived classes
356 * Query how many default properties the derived class supports.
357 * @return The number of default properties.
359 virtual unsigned int GetDefaultPropertyCount() const = 0;
362 * Retrieve all the indices that are associated with the default properties supported by the derived class.
363 * @return A container of default property indices.
364 * @note The deriving class must not modify the existing elements in the container.
366 virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const = 0;
369 * Query how many default properties the derived class supports.
370 * @return The number of default properties.
372 virtual const char* GetDefaultPropertyName( Property::Index index ) const = 0;
375 * Query the index of a default property.
376 * @param [in] name The name of the property.
377 * @return The index of the property, or Property::INVALID_INDEX if no default property exists with the given name.
379 virtual Property::Index GetDefaultPropertyIndex( const std::string& name ) const = 0;
382 * Query whether a default property is writable.
383 * @param [in] index The index of the property.
384 * @return True if the property is animatable.
386 virtual bool IsDefaultPropertyWritable( Property::Index index ) const = 0;
389 * Query whether a default property is animatable.
390 * This determines whether the property can be the target of an animation or constraint.
391 * @param [in] index The index of the property.
392 * @return True if the property is animatable.
394 virtual bool IsDefaultPropertyAnimatable( Property::Index index ) const = 0;
397 * @brief Query whether a default property can be used as an input to a constraint.
399 * @param [in] index The index of the property.
400 * @return True if the property can be used as an input to a constraint.
402 virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const = 0;
405 * Query the type of a default property.
406 * @param [in] index The index of the property.
407 * @return The type of the property.
409 virtual Property::Type GetDefaultPropertyType( Property::Index index ) const = 0;
412 * Set the value of a default property.
413 * @pre The property types match i.e. propertyValue.GetType() is equal to GetPropertyType(index).
414 * @param [in] index The index of the property.
415 * @param [in] propertyValue The new value of the property.
417 virtual void SetDefaultProperty( Property::Index index, const Property::Value& propertyValue ) = 0;
420 * Set the value of custom property.
421 * @param [in] index The index of the property.
422 * @param [in] entry An entry from the CustomPropertyLookup.
423 * @param [in] value The new value of the property.
425 virtual void SetCustomProperty( Property::Index index, const CustomProperty& entry, const Property::Value& value );
428 * Retrieve a default property value.
429 * @param [in] index The index of the property.
430 * @return The property value.
432 virtual Property::Value GetDefaultProperty( Property::Index index ) const = 0;
435 * Install a newly allocated scene-object property.
436 * The derived class is responsible for this, since the type of scene-object is not known to this base class.
437 * @param [in] newProperty A newly allocated scene-object property.
438 * @param [in] name The name allocated to this custom property.
439 * @param [in] index The index allocated to this custom property.
441 virtual void InstallSceneObjectProperty( SceneGraph::PropertyBase& newProperty, const std::string& name, unsigned int index ) = 0;
446 * Retrieves the TypeInfo for this object. Only retrieves it from the type-registry once and then stores a pointer
447 * to it locally there-after. The type info will not change during the life-time of the application.
448 * @return The type-info for this object (Can be NULL)
450 const TypeInfo* GetTypeInfo() const;
453 * Helper to find custom property
455 * @return pointer to the property
457 CustomProperty* FindCustomProperty( Property::Index index ) const;
461 typedef OwnerContainer<CustomProperty*> CustomPropertyLookup;
462 CustomPropertyLookup mCustomProperties; ///< Used for accessing custom Node properties
463 mutable TypeInfo const * mTypeInfo; ///< The type-info for this object, mutable so it can be lazy initialized from const method if it is required
465 Dali::Vector<Observer*> mObservers;
467 ActiveConstraintContainer* mConstraints; ///< Container of owned active-constraints.
469 typedef std::vector< Dali::PropertyNotification > PropertyNotificationContainer;
470 typedef PropertyNotificationContainer::iterator PropertyNotificationContainerIter;
471 typedef PropertyNotificationContainer::const_iterator PropertyNotificationContainerConstIter;
472 PropertyNotificationContainer* mPropertyNotifications; ///< Container of owned property notifications.
475 } // namespace Internal
477 inline Internal::ProxyObject& GetImplementation(Dali::Constrainable& object)
479 DALI_ASSERT_ALWAYS( object && "ProxyObject handle is empty" );
480 BaseObject& handle = object.GetBaseObject();
481 return static_cast<Internal::ProxyObject&>(handle);
484 inline const Internal::ProxyObject& GetImplementation(const Dali::Constrainable& object)
486 DALI_ASSERT_ALWAYS( object && "ProxyObject handle is empty" );
487 const BaseObject& handle = object.GetBaseObject();
488 return static_cast<const Internal::ProxyObject&>(handle);
494 #endif // __DALI_INTERNAL_PROXY_OBJECT_H__