2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/event/common/object-impl.h>
25 #include <dali/integration-api/debug.h>
26 #include <dali/internal/update/animation/scene-graph-constraint-base.h>
27 #include <dali/internal/update/common/animatable-property.h>
28 #include <dali/internal/update/common/property-owner-messages.h>
29 #include <dali/internal/update/common/uniform-map.h>
30 #include <dali/internal/event/animation/constraint-impl.h>
31 #include <dali/internal/event/common/stage-impl.h>
32 #include <dali/internal/event/common/property-notification-impl.h>
33 #include <dali/internal/event/common/type-registry-impl.h>
35 using Dali::Internal::SceneGraph::AnimatableProperty;
36 using Dali::Internal::SceneGraph::PropertyBase;
44 namespace // unnamed namespace
46 const int SUPPORTED_CAPABILITIES = Dali::Handle::DYNAMIC_PROPERTIES; // Object provides this capability
47 typedef Dali::Vector<Object::Observer*>::Iterator ObserverIter;
48 typedef Dali::Vector<Object::Observer*>::ConstIterator ConstObserverIter;
50 #if defined(DEBUG_ENABLED)
51 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_OBJECT" );
55 } // unnamed namespace
58 : mEventThreadServices( *Stage::GetCurrent() ),
61 mPropertyNotifications( NULL )
65 void Object::AddObserver(Observer& observer)
67 // make sure an observer doesn't observe the same object twice
68 // otherwise it will get multiple calls to OnSceneObjectAdd(), OnSceneObjectRemove() and ObjectDestroyed()
69 DALI_ASSERT_DEBUG( mObservers.End() == std::find( mObservers.Begin(), mObservers.End(), &observer));
71 mObservers.PushBack( &observer );
74 void Object::RemoveObserver(Observer& observer)
76 // Find the observer...
77 const ConstObserverIter endIter = mObservers.End();
78 for( ObserverIter iter = mObservers.Begin(); iter != endIter; ++iter)
80 if( (*iter) == &observer)
82 mObservers.Erase( iter );
86 DALI_ASSERT_DEBUG(endIter != mObservers.End());
89 void Object::OnSceneObjectAdd()
91 // Notification for observers
92 for( ConstObserverIter iter = mObservers.Begin(), endIter = mObservers.End(); iter != endIter; ++iter)
94 (*iter)->SceneObjectAdded(*this);
97 // enable property notifications in scene graph
98 EnablePropertyNotifications();
101 void Object::OnSceneObjectRemove()
103 // Notification for observers
104 for( ConstObserverIter iter = mObservers.Begin(), endIter = mObservers.End(); iter != endIter; ++iter )
106 (*iter)->SceneObjectRemoved(*this);
109 // disable property notifications in scene graph
110 DisablePropertyNotifications();
113 int Object::GetPropertyComponentIndex( Property::Index index ) const
115 int componentIndex = Property::INVALID_COMPONENT_INDEX;
117 const TypeInfo* typeInfo( GetTypeInfo() );
120 componentIndex = typeInfo->GetComponentIndex(index);
123 // For animatable property, check whether it is registered already and register it if not yet.
124 if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) && ( NULL == RegisterAnimatableProperty(index) ) )
126 componentIndex = Property::INVALID_COMPONENT_INDEX;
129 return componentIndex;
132 bool Object::Supports( Capability capability ) const
134 return (capability & SUPPORTED_CAPABILITIES);
137 unsigned int Object::GetPropertyCount() const
139 unsigned int count = GetDefaultPropertyCount();
141 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Default Properties: %d\n", count );
143 const TypeInfo* typeInfo( GetTypeInfo() );
146 unsigned int manual( typeInfo->GetPropertyCount() );
149 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Manual Properties: %d\n", manual );
152 unsigned int custom( mCustomProperties.Count() );
154 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Custom Properties: %d\n", custom );
156 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Total Properties: %d\n", count );
161 std::string Object::GetPropertyName( Property::Index index ) const
163 DALI_ASSERT_ALWAYS( index > Property::INVALID_INDEX && "Property index out of bounds" );
165 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
167 return GetDefaultPropertyName( index );
170 if ( ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
171 || ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) ) )
173 const TypeInfo* typeInfo( GetTypeInfo() );
176 return typeInfo->GetPropertyName( index );
180 DALI_ASSERT_ALWAYS( ! "Property index is invalid" );
184 CustomPropertyMetadata* custom = FindCustomProperty( index );
192 Property::Index Object::GetPropertyIndex(const std::string& name) const
194 Property::Index index = GetDefaultPropertyIndex( name );
196 if(index == Property::INVALID_INDEX)
198 const TypeInfo* typeInfo( GetTypeInfo() );
201 index = typeInfo->GetPropertyIndex( name );
202 if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
204 // check whether the animatable property is registered already, if not then register one.
205 if ( NULL == RegisterAnimatableProperty(index) )
207 index = Property::INVALID_INDEX;
213 if( (index == Property::INVALID_INDEX)&&( mCustomProperties.Count() > 0 ) )
215 Property::Index count = PROPERTY_CUSTOM_START_INDEX;
216 const PropertyMetadataLookup::ConstIterator end = mCustomProperties.End();
217 for( PropertyMetadataLookup::ConstIterator iter = mCustomProperties.Begin(); iter != end; ++iter, ++count )
219 CustomPropertyMetadata* custom = static_cast<CustomPropertyMetadata*>(*iter);
220 if ( custom->name == name )
222 if ( custom->childPropertyIndex != Property::INVALID_INDEX )
224 // If it is a child property, return the child property index
225 index = custom->childPropertyIndex;
239 bool Object::IsPropertyWritable( Property::Index index ) const
241 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds");
243 bool writable = false;
245 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
247 writable = IsDefaultPropertyWritable( index );
249 else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
251 const TypeInfo* typeInfo( GetTypeInfo() );
254 writable = typeInfo->IsPropertyWritable( index );
258 DALI_ASSERT_ALWAYS( ! "Invalid property index" );
261 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
263 // Type Registry scene-graph properties are writable.
268 CustomPropertyMetadata* custom = FindCustomProperty( index );
271 writable = custom->IsWritable();
278 bool Object::IsPropertyAnimatable( Property::Index index ) const
280 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds");
282 bool animatable = false;
284 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
286 animatable = IsDefaultPropertyAnimatable( index );
288 else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
290 // Type Registry event-thread only properties are not animatable.
293 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
295 // Type Registry scene-graph properties are animatable.
300 CustomPropertyMetadata* custom = FindCustomProperty( index );
303 animatable = custom->IsAnimatable();
310 bool Object::IsPropertyAConstraintInput( Property::Index index ) const
312 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds");
314 bool isConstraintInput = false;
316 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
318 isConstraintInput = IsDefaultPropertyAConstraintInput( index );
320 else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
322 // Type Registry event-thread only properties cannot be used as an input to a constraint.
323 isConstraintInput = false;
325 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
327 // scene graph properties can be used as input to a constraint.
328 isConstraintInput = true;
332 CustomPropertyMetadata* custom = FindCustomProperty( index );
335 // ... custom properties can be used as input to a constraint.
336 isConstraintInput = true;
340 return isConstraintInput;
343 Property::Type Object::GetPropertyType( Property::Index index ) const
345 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds" );
347 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
349 return GetDefaultPropertyType( index );
352 if ( ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
353 || ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) ) )
355 const TypeInfo* typeInfo( GetTypeInfo() );
358 return typeInfo->GetPropertyType( index );
362 DALI_ASSERT_ALWAYS( ! "Cannot find property index" );
366 CustomPropertyMetadata* custom = FindCustomProperty( index );
369 return custom->GetType();
372 return Property::NONE;
375 void Object::SetProperty( Property::Index index, const Property::Value& propertyValue )
377 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds" );
379 bool propertySet( true );
381 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
383 SetDefaultProperty( index, propertyValue );
385 else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
387 const TypeInfo* typeInfo( GetTypeInfo() );
390 typeInfo->SetProperty( this, index, propertyValue );
394 DALI_LOG_ERROR("Cannot find property index\n");
398 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
400 // check whether the animatable property is registered already, if not then register one.
401 AnimatablePropertyMetadata* animatableProperty = RegisterAnimatableProperty( index );
402 if(!animatableProperty)
404 DALI_LOG_ERROR("Cannot find property index\n");
409 // set the scene graph property value
410 SetSceneGraphProperty( index, *animatableProperty, propertyValue );
415 CustomPropertyMetadata* custom = FindCustomProperty( index );
417 if ( ( index >= CHILD_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= CHILD_PROPERTY_REGISTRATION_MAX_INDEX ) )
421 // If the child property is not registered yet, register it.
422 custom = new CustomPropertyMetadata( "", propertyValue, Property::READ_WRITE );
423 mCustomProperties.PushBack( custom );
426 custom->childPropertyIndex = index;
428 // Resolve name for the child property
429 Object* parent = GetParentObject();
432 const TypeInfo* parentTypeInfo( parent->GetTypeInfo() );
435 custom->name = parentTypeInfo->GetChildPropertyName( index );
442 if( custom->IsAnimatable() )
444 // set the scene graph property value
445 SetSceneGraphProperty( index, *custom, propertyValue );
447 else if( custom->IsWritable() )
449 custom->value = propertyValue;
453 // trying to set value on read only property is no-op
459 DALI_LOG_ERROR("Invalid property index\n");
464 // Let derived classes know that a property has been set
465 // TODO: We should not call this for read-only properties, SetDefaultProperty() && TypeInfo::SetProperty() should return a bool, which would be true if the property is set
468 OnPropertySet(index, propertyValue);
472 Property::Value Object::GetProperty(Property::Index index) const
474 DALI_ASSERT_ALWAYS( index > Property::INVALID_INDEX && "Property index is out of bounds" );
476 Property::Value value;
478 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
480 value = GetDefaultProperty( index );
482 else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
484 const TypeInfo* typeInfo( GetTypeInfo() );
487 value = typeInfo->GetProperty( this, index );
491 DALI_LOG_ERROR("Cannot find property index\n");
494 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
496 // check whether the animatable property is registered already, if not then register one.
497 AnimatablePropertyMetadata* animatableProperty = RegisterAnimatableProperty( index );
498 if(!animatableProperty)
500 DALI_LOG_ERROR("Cannot find property index\n");
504 // get the animatable property value
505 value = GetPropertyValue( animatableProperty );
508 else if(mCustomProperties.Count() > 0)
510 CustomPropertyMetadata* custom = FindCustomProperty( index );
513 // get the custom property value
514 value = GetPropertyValue( custom );
518 DALI_LOG_ERROR("Invalid property index\n");
525 void Object::GetPropertyIndices( Property::IndexContainer& indices ) const
529 // Default Properties
530 GetDefaultPropertyIndices( indices );
533 const TypeInfo* typeInfo( GetTypeInfo() );
536 typeInfo->GetPropertyIndices( indices );
540 if ( mCustomProperties.Count() > 0 )
542 indices.Reserve( indices.Size() + mCustomProperties.Count() );
544 PropertyMetadataLookup::ConstIterator iter = mCustomProperties.Begin();
545 const PropertyMetadataLookup::ConstIterator endIter = mCustomProperties.End();
547 for ( ; iter != endIter; ++iter, ++i )
549 CustomPropertyMetadata* custom = static_cast<CustomPropertyMetadata*>( *iter );
550 if ( custom->childPropertyIndex != Property::INVALID_INDEX )
552 // If it is a child property, add the child property index
553 indices.PushBack( custom->childPropertyIndex );
557 indices.PushBack( PROPERTY_CUSTOM_START_INDEX + i );
563 Property::Index Object::RegisterSceneGraphProperty(const std::string& name, Property::Index index, const Property::Value& propertyValue) const
565 // Create a new property
566 Dali::Internal::OwnerPointer<PropertyBase> newProperty;
568 switch ( propertyValue.GetType() )
570 case Property::BOOLEAN:
572 newProperty = new AnimatableProperty<bool>( propertyValue.Get<bool>() );
576 case Property::INTEGER:
578 newProperty = new AnimatableProperty<int>( propertyValue.Get<int>() );
582 case Property::FLOAT:
584 newProperty = new AnimatableProperty<float>( propertyValue.Get<float>() );
588 case Property::VECTOR2:
590 newProperty = new AnimatableProperty<Vector2>( propertyValue.Get<Vector2>() );
594 case Property::VECTOR3:
596 newProperty = new AnimatableProperty<Vector3>( propertyValue.Get<Vector3>() );
600 case Property::VECTOR4:
602 newProperty = new AnimatableProperty<Vector4>( propertyValue.Get<Vector4>() );
606 case Property::MATRIX:
608 newProperty = new AnimatableProperty<Matrix>( propertyValue.Get<Matrix>() );
612 case Property::MATRIX3:
614 newProperty = new AnimatableProperty<Matrix3>( propertyValue.Get<Matrix3>() );
618 case Property::ROTATION:
620 newProperty = new AnimatableProperty<Quaternion>( propertyValue.Get<Quaternion>() );
624 case Property::RECTANGLE:
625 case Property::STRING:
626 case Property::ARRAY:
630 DALI_ASSERT_ALWAYS( !"PropertyType is not animatable" );
635 // get the scene property owner from derived class
636 const SceneGraph::PropertyOwner* scenePropertyOwner = GetPropertyOwner();
637 // we can only pass properties to scene graph side if there is a scene object
638 if( scenePropertyOwner )
640 // keep a local pointer to the property as the OwnerPointer will pass its copy to the message
641 const PropertyBase* property = newProperty.Get();
642 if(index >= PROPERTY_CUSTOM_START_INDEX)
644 mCustomProperties.PushBack( new CustomPropertyMetadata( name, propertyValue.GetType(), property ) );
648 mAnimatableProperties.PushBack( new AnimatablePropertyMetadata( index, Property::INVALID_COMPONENT_INDEX, propertyValue.GetType(), property ) ); // base property
651 // queue a message to add the property
652 InstallCustomPropertyMessage( const_cast<EventThreadServices&>(GetEventThreadServices()), *scenePropertyOwner, newProperty.Release() ); // Message takes ownership
654 // notify the derived class (optional) method in case it needs to do some more work on the new property
655 // note! have to use the local pointer as OwnerPointer now points to NULL as it handed over its ownership
656 NotifyScenePropertyInstalled( *property, name, index );
662 // property was orphaned and killed so return invalid index
663 return Property::INVALID_INDEX;
667 Property::Index Object::RegisterProperty( const std::string& name, const Property::Value& propertyValue )
669 return RegisterProperty( name, propertyValue, Property::ANIMATABLE );
672 Property::Index Object::RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode )
674 // If property with the required name already exists, then just set it.
675 Property::Index index = GetPropertyIndex( name );
676 if( index != Property::INVALID_INDEX )
678 SetProperty( index, propertyValue );
682 // Otherwise register the property
684 if(Property::ANIMATABLE == accessMode)
686 index = RegisterSceneGraphProperty( name, PROPERTY_CUSTOM_START_INDEX + mCustomProperties.Count(), propertyValue );
687 AddUniformMapping( index, name );
691 // Add entry to the property lookup
692 index = PROPERTY_CUSTOM_START_INDEX + mCustomProperties.Count();
694 CustomPropertyMetadata* customProperty = new CustomPropertyMetadata( name, propertyValue, accessMode );
696 // Resolve index for the child property
697 Object* parent = GetParentObject();
700 const TypeInfo* parentTypeInfo( parent->GetTypeInfo() );
703 Property::Index childPropertyIndex = parentTypeInfo->GetChildPropertyIndex( name );
704 if( childPropertyIndex != Property::INVALID_INDEX )
706 customProperty->childPropertyIndex = childPropertyIndex;
707 index = childPropertyIndex;
712 mCustomProperties.PushBack( customProperty );
719 Dali::PropertyNotification Object::AddPropertyNotification(Property::Index index,
721 const Dali::PropertyCondition& condition)
723 if ( index >= DEFAULT_PROPERTY_MAX_COUNT )
725 if ( index <= PROPERTY_REGISTRATION_MAX_INDEX )
727 DALI_ASSERT_ALWAYS( false && "Property notification added to event side only property." );
729 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
731 // check whether the animatable property is registered already, if not then register one.
732 AnimatablePropertyMetadata* animatable = RegisterAnimatableProperty( index );
733 DALI_ASSERT_ALWAYS( animatable && "Property index is invalid" );
735 else if ( mCustomProperties.Count() > 0 )
737 CustomPropertyMetadata* custom = FindCustomProperty( index );
738 DALI_ASSERT_ALWAYS( custom && "Invalid property index" );
739 DALI_ASSERT_ALWAYS( custom->IsAnimatable() && "Property notification added to event side only property." );
743 Dali::Handle self(this);
744 Property target( self, index );
746 PropertyNotificationPtr internal = PropertyNotification::New( target, componentIndex, condition );
747 Dali::PropertyNotification propertyNotification(internal.Get());
749 if( !mPropertyNotifications )
751 mPropertyNotifications = new PropertyNotificationContainer;
753 mPropertyNotifications->push_back(propertyNotification);
755 return propertyNotification;
758 void Object::RemovePropertyNotification(Dali::PropertyNotification propertyNotification)
760 if( mPropertyNotifications )
762 PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
763 while(iter != mPropertyNotifications->end() )
765 if(*iter == propertyNotification)
767 mPropertyNotifications->erase(iter);
768 // As we can't ensure all references are removed, we can just disable
770 GetImplementation(propertyNotification).Disable();
778 void Object::RemovePropertyNotifications()
780 if( mPropertyNotifications )
782 PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
783 while(iter != mPropertyNotifications->end() )
785 // As we can't ensure all references are removed, we can just disable
787 GetImplementation(*iter).Disable();
791 mPropertyNotifications->clear();
795 void Object::EnablePropertyNotifications()
797 if( mPropertyNotifications )
799 PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
800 PropertyNotificationContainerIter endIter = mPropertyNotifications->end();
802 for( ; iter != endIter; ++iter )
804 GetImplementation(*iter).Enable();
809 void Object::DisablePropertyNotifications()
811 if( mPropertyNotifications )
813 PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
814 PropertyNotificationContainerIter endIter = mPropertyNotifications->end();
816 for( ; iter != endIter; ++iter )
818 GetImplementation(*iter).Disable();
823 void Object::AddUniformMapping( Property::Index propertyIndex, const std::string& uniformName ) const
825 // Get the address of the property if it's a scene property
826 const PropertyInputImpl* propertyPtr = GetSceneObjectInputProperty( propertyIndex );
828 // Check instead for newly registered properties
829 if( propertyPtr == NULL )
831 PropertyMetadata* animatable = FindAnimatableProperty( propertyIndex );
832 if( animatable != NULL )
834 propertyPtr = animatable->GetSceneGraphProperty();
838 if( propertyPtr == NULL )
840 PropertyMetadata* custom = FindCustomProperty( propertyIndex );
843 propertyPtr = custom->GetSceneGraphProperty();
847 if( propertyPtr != NULL )
849 const SceneGraph::PropertyOwner* sceneObject = GetPropertyOwner();
851 if( sceneObject != NULL )
853 SceneGraph::UniformPropertyMapping* map = new SceneGraph::UniformPropertyMapping( uniformName, propertyPtr );
854 // Message takes ownership of Uniform map (and will delete it after copy)
855 AddUniformMapMessage( const_cast<EventThreadServices&>(GetEventThreadServices()), *sceneObject, map);
859 DALI_ASSERT_ALWAYS(0 && "MESH_REWORK - Need to store property whilst off-stage" );
864 void Object::RemoveUniformMapping( const std::string& uniformName )
866 const SceneGraph::PropertyOwner* sceneObject = GetSceneObject();
867 RemoveUniformMapMessage( GetEventThreadServices(), *sceneObject, uniformName);
870 Property::Value Object::GetPropertyValue( const PropertyMetadata* entry ) const
872 Property::Value value;
874 DALI_ASSERT_ALWAYS( entry && "Invalid property metadata" );
876 if( !entry->IsAnimatable() )
878 value = entry->value;
882 BufferIndex bufferIndex( GetEventThreadServices().GetEventBufferIndex() );
884 switch ( entry->GetType() )
886 case Property::BOOLEAN:
888 const AnimatableProperty<bool>* property = static_cast< const AnimatableProperty<bool>* >( entry->GetSceneGraphProperty() );
889 DALI_ASSERT_DEBUG( NULL != property );
891 value = (*property)[ bufferIndex ];
895 case Property::INTEGER:
897 const AnimatableProperty<int>* property = static_cast< const AnimatableProperty<int>* >( entry->GetSceneGraphProperty() );
898 DALI_ASSERT_DEBUG( NULL != property );
900 value = (*property)[ bufferIndex ];
904 case Property::FLOAT:
906 const AnimatableProperty<float>* property = static_cast< const AnimatableProperty<float>* >( entry->GetSceneGraphProperty() );
907 DALI_ASSERT_DEBUG( NULL != property );
909 value = (*property)[ bufferIndex ];
913 case Property::VECTOR2:
915 const AnimatableProperty<Vector2>* property = static_cast< const AnimatableProperty<Vector2>* >( entry->GetSceneGraphProperty() );
916 DALI_ASSERT_DEBUG( NULL != property );
918 if(entry->componentIndex == 0)
920 value = (*property)[ bufferIndex ].x;
922 else if(entry->componentIndex == 1)
924 value = (*property)[ bufferIndex ].y;
928 value = (*property)[ bufferIndex ];
933 case Property::VECTOR3:
935 const AnimatableProperty<Vector3>* property = static_cast< const AnimatableProperty<Vector3>* >( entry->GetSceneGraphProperty() );
936 DALI_ASSERT_DEBUG( NULL != property );
938 if(entry->componentIndex == 0)
940 value = (*property)[ bufferIndex ].x;
942 else if(entry->componentIndex == 1)
944 value = (*property)[ bufferIndex ].y;
946 else if(entry->componentIndex == 2)
948 value = (*property)[ bufferIndex ].z;
952 value = (*property)[ bufferIndex ];
957 case Property::VECTOR4:
959 const AnimatableProperty<Vector4>* property = static_cast< const AnimatableProperty<Vector4>* >( entry->GetSceneGraphProperty() );
960 DALI_ASSERT_DEBUG( NULL != property );
962 if(entry->componentIndex == 0)
964 value = (*property)[ bufferIndex ].x;
966 else if(entry->componentIndex == 1)
968 value = (*property)[ bufferIndex ].y;
970 else if(entry->componentIndex == 2)
972 value = (*property)[ bufferIndex ].z;
974 else if(entry->componentIndex == 3)
976 value = (*property)[ bufferIndex ].w;
980 value = (*property)[ bufferIndex ];
985 case Property::MATRIX:
987 const AnimatableProperty<Matrix>* property = static_cast< const AnimatableProperty<Matrix>* >( entry->GetSceneGraphProperty() );
988 DALI_ASSERT_DEBUG( NULL != property );
990 value = (*property)[ bufferIndex ];
994 case Property::MATRIX3:
996 const AnimatableProperty<Matrix3>* property = static_cast< const AnimatableProperty<Matrix3>* >( entry->GetSceneGraphProperty() );
997 DALI_ASSERT_DEBUG( NULL != property );
999 value = (*property)[ bufferIndex ];
1003 case Property::ROTATION:
1005 const AnimatableProperty<Quaternion>* property = static_cast< const AnimatableProperty<Quaternion>* >( entry->GetSceneGraphProperty() );
1006 DALI_ASSERT_DEBUG( NULL != property );
1008 value = (*property)[ bufferIndex ];
1014 DALI_ASSERT_ALWAYS( false && "PropertyType enumeration is out of bounds" );
1023 void Object::SetSceneGraphProperty( Property::Index index, const PropertyMetadata& entry, const Property::Value& value )
1025 switch ( entry.GetType() )
1027 case Property::BOOLEAN:
1029 const AnimatableProperty<bool>* property = dynamic_cast< const AnimatableProperty<bool>* >( entry.GetSceneGraphProperty() );
1030 DALI_ASSERT_DEBUG( NULL != property );
1032 // property is being used in a separate thread; queue a message to set the property
1033 BakeMessage<bool>( GetEventThreadServices(), *property, value.Get<bool>() );
1037 case Property::INTEGER:
1039 const AnimatableProperty<int>* property = dynamic_cast< const AnimatableProperty<int>* >( entry.GetSceneGraphProperty() );
1040 DALI_ASSERT_DEBUG( NULL != property );
1042 // property is being used in a separate thread; queue a message to set the property
1043 BakeMessage<int>( GetEventThreadServices(), *property, value.Get<int>() );
1047 case Property::FLOAT:
1049 const AnimatableProperty<float>* property = dynamic_cast< const AnimatableProperty<float>* >( entry.GetSceneGraphProperty() );
1050 DALI_ASSERT_DEBUG( NULL != property );
1052 // property is being used in a separate thread; queue a message to set the property
1053 BakeMessage<float>( GetEventThreadServices(), *property, value.Get<float>() );
1057 case Property::VECTOR2:
1059 const AnimatableProperty<Vector2>* property = dynamic_cast< const AnimatableProperty<Vector2>* >( entry.GetSceneGraphProperty() );
1060 DALI_ASSERT_DEBUG( NULL != property );
1062 // property is being used in a separate thread; queue a message to set the property
1063 if(entry.componentIndex == 0)
1065 SetXComponentMessage<Vector2>( GetEventThreadServices(), *property, value.Get<float>() );
1067 else if(entry.componentIndex == 1)
1069 SetYComponentMessage<Vector2>( GetEventThreadServices(), *property, value.Get<float>() );
1073 BakeMessage<Vector2>( GetEventThreadServices(), *property, value.Get<Vector2>() );
1078 case Property::VECTOR3:
1080 const AnimatableProperty<Vector3>* property = dynamic_cast< const AnimatableProperty<Vector3>* >( entry.GetSceneGraphProperty() );
1081 DALI_ASSERT_DEBUG( NULL != property );
1083 // property is being used in a separate thread; queue a message to set the property
1084 if(entry.componentIndex == 0)
1086 SetXComponentMessage<Vector3>( GetEventThreadServices(), *property, value.Get<float>() );
1088 else if(entry.componentIndex == 1)
1090 SetYComponentMessage<Vector3>( GetEventThreadServices(), *property, value.Get<float>() );
1092 else if(entry.componentIndex == 2)
1094 SetZComponentMessage<Vector3>( GetEventThreadServices(), *property, value.Get<float>() );
1098 BakeMessage<Vector3>( GetEventThreadServices(), *property, value.Get<Vector3>() );
1104 case Property::VECTOR4:
1106 const AnimatableProperty<Vector4>* property = dynamic_cast< const AnimatableProperty<Vector4>* >( entry.GetSceneGraphProperty() );
1107 DALI_ASSERT_DEBUG( NULL != property );
1109 // property is being used in a separate thread; queue a message to set the property
1110 if(entry.componentIndex == 0)
1112 SetXComponentMessage<Vector4>( GetEventThreadServices(), *property, value.Get<float>() );
1114 else if(entry.componentIndex == 1)
1116 SetYComponentMessage<Vector4>( GetEventThreadServices(), *property, value.Get<float>() );
1118 else if(entry.componentIndex == 2)
1120 SetZComponentMessage<Vector4>( GetEventThreadServices(), *property, value.Get<float>() );
1122 else if(entry.componentIndex == 3)
1124 SetWComponentMessage<Vector4>( GetEventThreadServices(), *property, value.Get<float>() );
1128 BakeMessage<Vector4>( GetEventThreadServices(), *property, value.Get<Vector4>() );
1133 case Property::ROTATION:
1135 const AnimatableProperty<Quaternion>* property = dynamic_cast< const AnimatableProperty<Quaternion>* >( entry.GetSceneGraphProperty() );
1136 DALI_ASSERT_DEBUG( NULL != property );
1138 // property is being used in a separate thread; queue a message to set the property
1139 BakeMessage<Quaternion>( GetEventThreadServices(), *property, value.Get<Quaternion>() );
1143 case Property::MATRIX:
1145 const AnimatableProperty<Matrix>* property = dynamic_cast< const AnimatableProperty<Matrix>* >( entry.GetSceneGraphProperty() );
1146 DALI_ASSERT_DEBUG( NULL != property );
1148 // property is being used in a separate thread; queue a message to set the property
1149 BakeMessage<Matrix>( GetEventThreadServices(), *property, value.Get<Matrix>() );
1153 case Property::MATRIX3:
1155 const AnimatableProperty<Matrix3>* property = dynamic_cast< const AnimatableProperty<Matrix3>* >( entry.GetSceneGraphProperty() );
1156 DALI_ASSERT_DEBUG( NULL != property );
1158 // property is being used in a separate thread; queue a message to set the property
1159 BakeMessage<Matrix3>( GetEventThreadServices(), *property, value.Get<Matrix3>() );
1165 // non-animatable scene graph property, do nothing
1170 const TypeInfo* Object::GetTypeInfo() const
1174 // This uses a dynamic_cast so can be quite expensive so we only really want to do it once
1175 // especially as the type-info does not change during the life-time of an application
1177 Dali::TypeInfo typeInfoHandle = TypeRegistry::Get()->GetTypeInfo( this );
1178 if ( typeInfoHandle )
1180 mTypeInfo = &GetImplementation( typeInfoHandle );
1187 void Object::ApplyConstraint( ConstraintBase& constraint )
1191 mConstraints = new ConstraintContainer;
1193 mConstraints->push_back( Dali::Constraint( &constraint ) );
1196 void Object::RemoveConstraint( ConstraintBase& constraint )
1198 // NULL if the Constraint sources are destroyed before Constraint::Apply()
1201 ConstraintIter it( std::find( mConstraints->begin(), mConstraints->end(), Dali::Constraint( &constraint ) ) );
1202 if( it != mConstraints->end() )
1204 mConstraints->erase( it );
1209 void Object::RemoveConstraints()
1211 // guard against constraint sending messages during core destruction
1212 if( mConstraints && Stage::IsInstalled() )
1214 // If we have nothing in the scene-graph, just clear constraint containers
1215 const SceneGraph::PropertyOwner* propertyOwner = GetSceneObject();
1216 if ( NULL != propertyOwner )
1218 const ConstraintConstIter endIter = mConstraints->end();
1219 for ( ConstraintIter iter = mConstraints->begin(); endIter != iter; ++iter )
1221 GetImplementation( *iter ).RemoveInternal();
1225 delete mConstraints;
1226 mConstraints = NULL;
1230 void Object::RemoveConstraints( unsigned int tag )
1232 // guard against constraint sending messages during core destruction
1233 if( mConstraints && Stage::IsInstalled() )
1235 ConstraintIter iter( mConstraints->begin() );
1236 while(iter != mConstraints->end() )
1238 ConstraintBase& constraint = GetImplementation( *iter );
1239 if( constraint.GetTag() == tag )
1241 GetImplementation( *iter ).RemoveInternal();
1242 iter = mConstraints->erase( iter );
1250 if ( mConstraints->empty() )
1252 delete mConstraints;
1253 mConstraints = NULL;
1258 void Object::SetTypeInfo( const TypeInfo* typeInfo )
1260 mTypeInfo = typeInfo;
1265 // Notification for observers
1266 for( ConstObserverIter iter = mObservers.Begin(), endIter = mObservers.End(); iter != endIter; ++iter)
1268 (*iter)->ObjectDestroyed(*this);
1271 delete mConstraints;
1272 delete mPropertyNotifications;
1275 CustomPropertyMetadata* Object::FindCustomProperty( Property::Index index ) const
1277 CustomPropertyMetadata* property( NULL );
1279 if ( ( index >= CHILD_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= CHILD_PROPERTY_REGISTRATION_MAX_INDEX ) )
1281 for ( arrayIndex = 0; arrayIndex < (int)mCustomProperties.Count(); arrayIndex++ )
1283 CustomPropertyMetadata* custom = static_cast<CustomPropertyMetadata*>( mCustomProperties[ arrayIndex ] );
1284 if( custom->childPropertyIndex == index )
1292 arrayIndex = index - PROPERTY_CUSTOM_START_INDEX;
1293 if( arrayIndex >= 0 )
1295 if( arrayIndex < (int)mCustomProperties.Count() ) // we can only access the first 2 billion custom properties
1297 property = static_cast<CustomPropertyMetadata*>(mCustomProperties[ arrayIndex ]);
1304 AnimatablePropertyMetadata* Object::FindAnimatableProperty( Property::Index index ) const
1306 for ( int arrayIndex = 0; arrayIndex < (int)mAnimatableProperties.Count(); arrayIndex++ )
1308 AnimatablePropertyMetadata* property = static_cast<AnimatablePropertyMetadata*>( mAnimatableProperties[ arrayIndex ] );
1309 if( property->index == index )
1317 AnimatablePropertyMetadata* Object::RegisterAnimatableProperty(Property::Index index) const
1319 DALI_ASSERT_ALWAYS( (( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ))
1320 && "Property index is out of bounds" );
1322 // check whether the animatable property is registered already, if not then register one.
1323 AnimatablePropertyMetadata* animatableProperty = FindAnimatableProperty( index );
1324 if(!animatableProperty)
1326 const TypeInfo* typeInfo( GetTypeInfo() );
1329 Property::Index basePropertyIndex = typeInfo->GetBasePropertyIndex(index);
1330 if(basePropertyIndex == Property::INVALID_INDEX)
1332 // If the property is not a component of a base property, register the whole property itself.
1333 const std::string& propertyName = typeInfo->GetPropertyName(index);
1334 RegisterSceneGraphProperty(propertyName, index, typeInfo->GetPropertyDefaultValue(index));
1335 AddUniformMapping( index, propertyName );
1339 // Since the property is a component of a base property, check whether the base property is regsitered.
1340 animatableProperty = FindAnimatableProperty( basePropertyIndex );
1341 if(!animatableProperty)
1343 // If the base property is not registered yet, register the base property first.
1344 const std::string& basePropertyName = typeInfo->GetPropertyName(basePropertyIndex);
1345 if(Property::INVALID_INDEX != RegisterSceneGraphProperty(basePropertyName, basePropertyIndex, Property::Value(typeInfo->GetPropertyType(basePropertyIndex))))
1347 animatableProperty = static_cast<AnimatablePropertyMetadata*>(mAnimatableProperties[mAnimatableProperties.Size()-1]);
1348 AddUniformMapping( basePropertyIndex, basePropertyName );
1352 if(animatableProperty)
1354 // Create the metadata for the property component.
1355 mAnimatableProperties.PushBack( new AnimatablePropertyMetadata( index, typeInfo->GetComponentIndex(index), animatableProperty->GetType(), animatableProperty->GetSceneGraphProperty() ) );
1359 // The metadata has just been added and therefore should be in the end of the vector.
1360 animatableProperty = static_cast<AnimatablePropertyMetadata*>(mAnimatableProperties[mAnimatableProperties.Size()-1]);
1364 return animatableProperty;
1367 void Object::ResolveChildProperties()
1369 // Resolve index for the child property
1370 Object* parent = GetParentObject();
1373 const TypeInfo* parentTypeInfo( parent->GetTypeInfo() );
1374 if( parentTypeInfo )
1376 // Go through each custom property
1377 for ( int arrayIndex = 0; arrayIndex < (int)mCustomProperties.Count(); arrayIndex++ )
1379 CustomPropertyMetadata* customProperty = static_cast<CustomPropertyMetadata*>( mCustomProperties[ arrayIndex ] );
1381 if( customProperty->name == "" )
1383 if( customProperty->childPropertyIndex != Property::INVALID_INDEX )
1385 // Resolve name for any child property with no name
1386 customProperty->name = parentTypeInfo->GetChildPropertyName( customProperty->childPropertyIndex );
1391 Property::Index childPropertyIndex = parentTypeInfo->GetChildPropertyIndex( customProperty->name );
1392 if( childPropertyIndex != Property::INVALID_INDEX )
1394 // Resolve index for any property with a name that matches the parent's child property name
1395 customProperty->childPropertyIndex = childPropertyIndex;
1403 } // namespace Internal