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/common/dali-vector.h>
26 #include <dali/public-api/common/vector-wrapper.h>
27 #include <dali/public-api/animation/active-constraint.h>
28 #include <dali/public-api/animation/animation.h>
29 #include <dali/public-api/animation/constraint.h>
30 #include <dali/public-api/object/constrainable.h>
31 #include <dali/public-api/object/property-input.h>
32 #include <dali/public-api/object/property-notification.h>
33 #include <dali/internal/event/common/object-impl.h>
34 #include <dali/internal/event/common/custom-property.h>
35 #include <dali/internal/event/common/property-input-impl.h>
36 #include <dali/internal/update/common/property-base.h>
45 class PropertyInputImpl;
56 typedef std::vector< Dali::ActiveConstraint > ActiveConstraintContainer;
57 typedef ActiveConstraintContainer::iterator ActiveConstraintIter;
58 typedef ActiveConstraintContainer::const_iterator ActiveConstraintConstIter;
61 * A proxy for a property-owning object in the scene-graph.
62 * This provides an interface for observing the addition/removal of scene-objects.
64 * The concrete derived class is responsible for:
65 * 1) Adding & removing an object from the scene-graph. The OnSceneObjectAdd() and OnSceneObjectRemove()
66 * methods should be called by the derived class, to trigger observer callbacks.
67 * 3) Implementing the GetSceneObject() methods, used to access the scene-object.
68 * 4) Providing access to properties stored by the scene-graph object. These should match the properties
69 * reported by the base Dali::Internal::Object methods.
71 class ProxyObject : public Object
80 * Called immediately after the proxy has created & passed ownership of a scene-graph object.
81 * @param[in] proxy The proxy object.
83 virtual void SceneObjectAdded(ProxyObject& proxy) = 0;
86 * Called shortly before the proxy sends a message to remove its scene object.
87 * @param[in] proxy The proxy object.
89 virtual void SceneObjectRemoved(ProxyObject& proxy) = 0;
92 * Called shortly before the proxy itself is destroyed; no further callbacks will be received.
93 * @param[in] proxy The proxy object.
95 virtual void ProxyDestroyed(ProxyObject& proxy) = 0;
101 virtual ~Observer(){}
110 * Query whether the proxy object removes (& re-adds) its associated scene-object.
111 * Otherwise the scene-object lifetime is expected to match that of the proxy.
112 * @return True if scene-objects are removed.
114 virtual bool IsSceneObjectRemovable() const = 0;
117 * Add an observer to the proxy.
118 * @param[in] observer The observer to add.
120 virtual void AddObserver(Observer& observer);
123 * Remove an observer from the proxy
124 * @pre The observer has already been added.
125 * @param[in] observer The observer to remove.
127 virtual void RemoveObserver(Observer& observer);
130 * Retrieve the scene-graph object added by this proxy.
131 * @return A pointer to the object, or NULL if no object has been added to the scene-graph.
133 virtual const SceneGraph::PropertyOwner* GetSceneObject() const = 0;
136 * Retrieve an animatable property owned by the scene-graph object.
137 * @pre -1 < index < GetPropertyCount().
138 * @param[in] index The index of the property.
139 * @return A dereferenceable pointer to a property, or NULL if a scene-object does not exist with this property.
141 virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const = 0;
144 * Retrieve an constraint input-property owned by the scene-graph object.
145 * @pre -1 < index < GetPropertyCount().
146 * @param[in] index The index of the property.
147 * @return A dereferenceable pointer to an input property, or NULL if a scene-object does not exist with this property.
149 virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const = 0;
152 * Query whether the property is a component of a scene-graph property.
153 * @pre -1 < index < GetPropertyCount().
154 * @param[in] index The index of the property.
155 * @return The index or Property::INVALID_COMPONENT_INDEX.
157 virtual int GetPropertyComponentIndex( Property::Index index ) const;
159 public: // Property system interface from Internal::Object
162 * @copydoc Dali::Internal::Object::Supports()
164 virtual bool Supports( Object::Capability capability ) const;
167 * @copydoc Dali::Internal::Object::GetPropertyCount()
169 virtual unsigned int GetPropertyCount() const;
172 * @copydoc Dali::Internal::Object::GetPropertyName()
174 virtual const std::string& GetPropertyName( Property::Index index ) const;
177 * @copydoc Dali::Internal::Object::GetPropertyIndex()
179 virtual Property::Index GetPropertyIndex(const std::string& name) const;
182 * @copydoc Dali::Internal::Object::IsPropertyWritable()
184 virtual bool IsPropertyWritable(Property::Index index) const;
187 * @copydoc Dali::Internal::Object::IsPropertyAnimatable()
189 virtual bool IsPropertyAnimatable(Property::Index index) const;
192 * @copydoc Dali::Internal::Object::IsPropertyAConstraintInput()
194 virtual bool IsPropertyAConstraintInput(Property::Index index) const;
197 * @copydoc Dali::Internal::Object::GetPropertyType()
199 virtual Property::Type GetPropertyType(Property::Index index) const;
202 * @copydoc Dali::Internal::Object::SetProperty()
204 virtual void SetProperty(Property::Index index, const Property::Value& propertyValue);
207 * @copydoc Dali::Internal::Object::GetProperty()
209 virtual Property::Value GetProperty(Property::Index index) const;
212 * @copydoc Dali::Handle::GetPropertyIndices()
214 virtual void GetPropertyIndices( Property::IndexContainer& indices ) const;
217 * @copydoc Dali::Internal::Object::RegisterProperty()
219 virtual Property::Index RegisterProperty(std::string name, const Property::Value& propertyValue);
222 * @copydoc Dali::Handle::RegisterProperty(std::string name, Property::Value propertyValue, Property::AccessMode accessMode)
224 virtual Property::Index RegisterProperty(std::string name, 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 void RemovePropertyNotifications();
245 * Enable property notifications in scene graph
247 void EnablePropertyNotifications();
250 * Enable property notifications in scene graph
252 void DisablePropertyNotifications();
254 public: // Constraints
257 * Apply a constraint to a ProxyObject.
258 * @param[in] constraint The constraint to apply.
260 Dali::ActiveConstraint ApplyConstraint( Constraint& constraint );
263 * Apply a constraint to a ProxyObject.
264 * @param[in] constraint The constraint to apply.
265 * @param[in] weightObject An object with a "weight" float property.
267 Dali::ActiveConstraint ApplyConstraint( Constraint& constraint, Dali::Constrainable weightObject );
270 * Remove one constraint from a ProxyObject.
271 * @param[in] activeConstraint The active constraint to remove.
273 void RemoveConstraint( Dali::ActiveConstraint activeConstraint );
276 * Remove all constraints from a ProxyObject.
278 void RemoveConstraints();
281 * Remove all constraints from a ProxyObject with a matching tag
283 void RemoveConstraints( unsigned int tag );
285 public: // Called by TypeInfo
288 * Called by TypeInfo to set the type-info that this proxy-object is created by.
289 * @param[in] typeInfo The TypeInfo that creates this proxy-object.
291 void SetTypeInfo( const TypeInfo* typeInfo );
296 * Called immediately by derived classes, after the scene-object has been created & passed to the scene-graph.
298 void OnSceneObjectAdd();
301 * Called by derived classes, shortly before send a message to remove the scene-object.
303 void OnSceneObjectRemove();
306 * A reference counted object may only be deleted by calling Unreference()
308 virtual ~ProxyObject();
313 ProxyObject(const ProxyObject&);
316 ProxyObject& operator=(const ProxyObject& rhs);
319 * Helper for ApplyConstraint overloads.
320 * @param[in] constraint The constraint to apply.
321 * @param[in] weightObject An object with a "weight" float property, or an empty handle.
322 * @return The new active-constraint which is owned by ProxyObject.
324 ActiveConstraintBase* DoApplyConstraint( Constraint& constraint, Dali::Constrainable weightObject );
327 * Helper to remove active constraints
329 void RemoveConstraint( ActiveConstraint& constraint, bool isInScenegraph );
332 private: // Default property extensions for derived classes
335 * Query how many default properties the derived class supports.
336 * @return The number of default properties.
338 virtual unsigned int GetDefaultPropertyCount() const = 0;
341 * Retrieve all the indices that are associated with the default properties supported by the derived class.
342 * @return A container of default property indices.
343 * @note The deriving class must not modify the existing elements in the container.
345 virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const = 0;
348 * Query how many default properties the derived class supports.
349 * @return The number of default properties.
351 virtual const std::string& GetDefaultPropertyName( Property::Index index ) const = 0;
354 * Query the index of a default property.
355 * @param [in] name The name of the property.
356 * @return The index of the property, or Property::INVALID_INDEX if no default property exists with the given name.
358 virtual Property::Index GetDefaultPropertyIndex( const std::string& name ) const = 0;
361 * Query whether a default property is writable.
362 * @param [in] index The index of the property.
363 * @return True if the property is animatable.
365 virtual bool IsDefaultPropertyWritable( Property::Index index ) const = 0;
368 * Query whether a default property is animatable.
369 * This determines whether the property can be the target of an animation or constraint.
370 * @param [in] index The index of the property.
371 * @return True if the property is animatable.
373 virtual bool IsDefaultPropertyAnimatable( Property::Index index ) const = 0;
376 * @brief Query whether a default property can be used as an input to a constraint.
378 * @param [in] index The index of the property.
379 * @return True if the property can be used as an input to a constraint.
381 virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const = 0;
384 * Query the type of a default property.
385 * @param [in] index The index of the property.
386 * @return The type of the property.
388 virtual Property::Type GetDefaultPropertyType( Property::Index index ) const = 0;
391 * Set the value of a default property.
392 * @pre The property types match i.e. propertyValue.GetType() is equal to GetPropertyType(index).
393 * @param [in] index The index of the property.
394 * @param [in] propertyValue The new value of the property.
396 virtual void SetDefaultProperty( Property::Index index, const Property::Value& propertyValue ) = 0;
399 * Set the value of custom property.
400 * @param [in] index The index of the property.
401 * @param [in] entry An entry from the CustomPropertyLookup.
402 * @param [in] value The new value of the property.
404 virtual void SetCustomProperty( Property::Index index, const CustomProperty& entry, const Property::Value& value );
407 * Retrieve a default property value.
408 * @param [in] index The index of the property.
409 * @return The property value.
411 virtual Property::Value GetDefaultProperty( Property::Index index ) const = 0;
414 * Install a newly allocated scene-object property.
415 * The derived class is responsible for this, since the type of scene-object is not known to this base class.
416 * @param [in] newProperty A newly allocated scene-object property.
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 InstallSceneObjectProperty( SceneGraph::PropertyBase& newProperty, const std::string& name, unsigned int index ) = 0;
425 * Not all proxy objects will have custom properties so we want to only create the lookup when its actually needed
426 * @return the custom property lookup
428 CustomPropertyLookup& GetCustomPropertyLookup() const;
431 * Retrieves the TypeInfo for this object. Only retrieves it from the type-registry once and then stores a pointer
432 * to it locally there-after. The type info will not change during the life-time of the application.
433 * @return The type-info for this object (Can be NULL)
435 const TypeInfo* GetTypeInfo() const;
439 Property::Index mNextCustomPropertyIndex; ///< The ID of the next custom property to be registered
441 mutable CustomPropertyLookup* mCustomProperties; ///< Used for accessing custom Node properties, mutable so it can be lazy initialized from const function
442 mutable TypeInfo const * mTypeInfo; ///< The type-info for this object, mutable so it can be lazy initialized from const method if it is required
444 Dali::Vector<Observer*> mObservers;
446 ActiveConstraintContainer* mConstraints; ///< Container of owned active-constraints.
448 typedef std::vector< Dali::PropertyNotification > PropertyNotificationContainer;
449 typedef PropertyNotificationContainer::iterator PropertyNotificationContainerIter;
450 typedef PropertyNotificationContainer::const_iterator PropertyNotificationContainerConstIter;
451 PropertyNotificationContainer* mPropertyNotifications; ///< Container of owned property notifications.
454 } // namespace Internal
456 inline Internal::ProxyObject& GetImplementation(Dali::Constrainable& object)
458 DALI_ASSERT_ALWAYS( object && "ProxyObject handle is empty" );
459 BaseObject& handle = object.GetBaseObject();
460 return static_cast<Internal::ProxyObject&>(handle);
463 inline const Internal::ProxyObject& GetImplementation(const Dali::Constrainable& object)
465 DALI_ASSERT_ALWAYS( object && "ProxyObject handle is empty" );
466 const BaseObject& handle = object.GetBaseObject();
467 return static_cast<const Internal::ProxyObject&>(handle);
473 #endif // __DALI_INTERNAL_PROXY_OBJECT_H__