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 )
169 const char * propertyName = GetDefaultPropertyName( index );
172 string = propertyName;
177 if ( ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
178 || ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) ) )
180 const TypeInfo* typeInfo( GetTypeInfo() );
183 return typeInfo->GetPropertyName( index );
187 DALI_ASSERT_ALWAYS( ! "Property index is invalid" );
191 CustomPropertyMetadata* custom = FindCustomProperty( index );
199 Property::Index Object::GetPropertyIndex(const std::string& name) const
201 Property::Index index = GetDefaultPropertyIndex( name );
203 if(index == Property::INVALID_INDEX)
205 const TypeInfo* typeInfo( GetTypeInfo() );
208 index = typeInfo->GetPropertyIndex( name );
209 if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
211 // check whether the animatable property is registered already, if not then register one.
212 if ( NULL == RegisterAnimatableProperty(index) )
214 index = Property::INVALID_INDEX;
220 if( (index == Property::INVALID_INDEX)&&( mCustomProperties.Count() > 0 ) )
222 Property::Index count = PROPERTY_CUSTOM_START_INDEX;
223 const PropertyMetadataLookup::ConstIterator end = mCustomProperties.End();
224 for( PropertyMetadataLookup::ConstIterator iter = mCustomProperties.Begin(); iter != end; ++iter, ++count )
226 CustomPropertyMetadata* custom = static_cast<CustomPropertyMetadata*>(*iter);
227 if ( custom->name == name )
229 if ( custom->childPropertyIndex != Property::INVALID_INDEX )
231 // If it is a child property, return the child property index
232 index = custom->childPropertyIndex;
246 Property::Index Object::GetPropertyIndex( Property::Index key ) const
248 Property::Index index = Property::INVALID_INDEX;
250 if( mCustomProperties.Count() > 0 )
252 Property::Index count = PROPERTY_CUSTOM_START_INDEX;
253 const PropertyMetadataLookup::ConstIterator end = mCustomProperties.End();
254 for( PropertyMetadataLookup::ConstIterator iter = mCustomProperties.Begin(); iter != end; ++iter, ++count )
256 CustomPropertyMetadata* custom = static_cast<CustomPropertyMetadata*>(*iter);
257 if( custom->key == key )
259 if( custom->childPropertyIndex != Property::INVALID_INDEX )
261 // If it is a child property, return the child property index
262 index = custom->childPropertyIndex;
276 Property::Index Object::GetPropertyIndex( Property::Key key ) const
278 Property::Index index = Property::INVALID_INDEX;
279 if( key.type == Property::Key::INDEX )
281 index = GetPropertyIndex( key.indexKey );
285 index = GetPropertyIndex( key.stringKey );
290 bool Object::IsPropertyWritable( Property::Index index ) const
292 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds");
294 bool writable = false;
296 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
298 writable = IsDefaultPropertyWritable( index );
300 else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
302 const TypeInfo* typeInfo( GetTypeInfo() );
305 writable = typeInfo->IsPropertyWritable( index );
309 DALI_ASSERT_ALWAYS( ! "Invalid property index" );
312 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
314 // Type Registry scene-graph properties are writable.
319 CustomPropertyMetadata* custom = FindCustomProperty( index );
322 writable = custom->IsWritable();
329 bool Object::IsPropertyAnimatable( Property::Index index ) const
331 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds");
333 bool animatable = false;
335 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
337 animatable = IsDefaultPropertyAnimatable( index );
339 else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
341 // Type Registry event-thread only properties are not animatable.
344 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
346 // Type Registry scene-graph properties are animatable.
351 CustomPropertyMetadata* custom = FindCustomProperty( index );
354 animatable = custom->IsAnimatable();
361 bool Object::IsPropertyAConstraintInput( Property::Index index ) const
363 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds");
365 bool isConstraintInput = false;
367 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
369 isConstraintInput = IsDefaultPropertyAConstraintInput( index );
371 else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
373 // Type Registry event-thread only properties cannot be used as an input to a constraint.
374 isConstraintInput = false;
376 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
378 // scene graph properties can be used as input to a constraint.
379 isConstraintInput = true;
383 CustomPropertyMetadata* custom = FindCustomProperty( index );
386 // ... custom properties can be used as input to a constraint.
387 isConstraintInput = true;
391 return isConstraintInput;
394 Property::Type Object::GetPropertyType( Property::Index index ) const
396 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds" );
398 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
400 return GetDefaultPropertyType( index );
403 if ( ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
404 || ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) ) )
406 const TypeInfo* typeInfo( GetTypeInfo() );
409 return typeInfo->GetPropertyType( index );
413 DALI_ASSERT_ALWAYS( ! "Cannot find property index" );
417 CustomPropertyMetadata* custom = FindCustomProperty( index );
420 return custom->GetType();
423 return Property::NONE;
426 void Object::SetProperty( Property::Index index, const Property::Value& propertyValue )
428 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds" );
430 bool propertySet( true );
432 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
434 SetDefaultProperty( index, propertyValue );
436 else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
438 const TypeInfo* typeInfo( GetTypeInfo() );
441 typeInfo->SetProperty( this, index, propertyValue );
445 DALI_LOG_ERROR("Cannot find property index\n");
449 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
451 // check whether the animatable property is registered already, if not then register one.
452 AnimatablePropertyMetadata* animatableProperty = RegisterAnimatableProperty( index );
453 if(!animatableProperty)
455 DALI_LOG_ERROR("Cannot find property index\n");
460 // set the scene graph property value
461 SetSceneGraphProperty( index, *animatableProperty, propertyValue );
466 CustomPropertyMetadata* custom = FindCustomProperty( index );
468 if ( ( index >= CHILD_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= CHILD_PROPERTY_REGISTRATION_MAX_INDEX ) )
472 // If the child property is not registered yet, register it.
473 custom = new CustomPropertyMetadata( "", propertyValue, Property::READ_WRITE );
474 mCustomProperties.PushBack( custom );
477 custom->childPropertyIndex = index;
479 // Resolve name for the child property
480 Object* parent = GetParentObject();
483 const TypeInfo* parentTypeInfo( parent->GetTypeInfo() );
486 custom->name = parentTypeInfo->GetChildPropertyName( index );
493 if( custom->IsAnimatable() )
495 // set the scene graph property value
496 SetSceneGraphProperty( index, *custom, propertyValue );
498 else if( custom->IsWritable() )
500 custom->value = propertyValue;
504 // trying to set value on read only property is no-op
510 DALI_LOG_ERROR("Invalid property index\n");
515 // Let derived classes know that a property has been set
516 // 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
519 OnPropertySet(index, propertyValue);
523 Property::Value Object::GetProperty(Property::Index index) const
525 DALI_ASSERT_ALWAYS( index > Property::INVALID_INDEX && "Property index is out of bounds" );
527 Property::Value value;
529 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
531 value = GetDefaultProperty( index );
533 else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
535 const TypeInfo* typeInfo( GetTypeInfo() );
538 value = typeInfo->GetProperty( this, index );
542 DALI_LOG_ERROR("Cannot find property index\n");
545 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
547 // check whether the animatable property is registered already, if not then register one.
548 AnimatablePropertyMetadata* animatableProperty = RegisterAnimatableProperty( index );
549 if(!animatableProperty)
551 DALI_LOG_ERROR("Cannot find property index\n");
555 // get the animatable property value
556 value = GetPropertyValue( animatableProperty );
559 else if(mCustomProperties.Count() > 0)
561 CustomPropertyMetadata* custom = FindCustomProperty( index );
564 // get the custom property value
565 value = GetPropertyValue( custom );
569 DALI_LOG_ERROR("Invalid property index\n");
576 void Object::GetPropertyIndices( Property::IndexContainer& indices ) const
580 // Default Properties
581 GetDefaultPropertyIndices( indices );
584 const TypeInfo* typeInfo( GetTypeInfo() );
587 typeInfo->GetPropertyIndices( indices );
591 if ( mCustomProperties.Count() > 0 )
593 indices.Reserve( indices.Size() + mCustomProperties.Count() );
595 PropertyMetadataLookup::ConstIterator iter = mCustomProperties.Begin();
596 const PropertyMetadataLookup::ConstIterator endIter = mCustomProperties.End();
598 for ( ; iter != endIter; ++iter, ++i )
600 CustomPropertyMetadata* custom = static_cast<CustomPropertyMetadata*>( *iter );
601 if ( custom->childPropertyIndex != Property::INVALID_INDEX )
603 // If it is a child property, add the child property index
604 indices.PushBack( custom->childPropertyIndex );
608 indices.PushBack( PROPERTY_CUSTOM_START_INDEX + i );
614 Property::Index Object::RegisterSceneGraphProperty(const std::string& name, Property::Index key, Property::Index index, const Property::Value& propertyValue) const
616 // Create a new property
617 Dali::Internal::OwnerPointer<PropertyBase> newProperty;
619 switch ( propertyValue.GetType() )
621 case Property::BOOLEAN:
623 newProperty = new AnimatableProperty<bool>( propertyValue.Get<bool>() );
627 case Property::INTEGER:
629 newProperty = new AnimatableProperty<int>( propertyValue.Get<int>() );
633 case Property::FLOAT:
635 newProperty = new AnimatableProperty<float>( propertyValue.Get<float>() );
639 case Property::VECTOR2:
641 newProperty = new AnimatableProperty<Vector2>( propertyValue.Get<Vector2>() );
645 case Property::VECTOR3:
647 newProperty = new AnimatableProperty<Vector3>( propertyValue.Get<Vector3>() );
651 case Property::VECTOR4:
653 newProperty = new AnimatableProperty<Vector4>( propertyValue.Get<Vector4>() );
657 case Property::MATRIX:
659 newProperty = new AnimatableProperty<Matrix>( propertyValue.Get<Matrix>() );
663 case Property::MATRIX3:
665 newProperty = new AnimatableProperty<Matrix3>( propertyValue.Get<Matrix3>() );
669 case Property::ROTATION:
671 newProperty = new AnimatableProperty<Quaternion>( propertyValue.Get<Quaternion>() );
675 case Property::RECTANGLE:
676 case Property::STRING:
677 case Property::ARRAY:
681 DALI_ASSERT_ALWAYS( !"PropertyType is not animatable" );
686 // get the scene property owner from derived class
687 const SceneGraph::PropertyOwner* scenePropertyOwner = GetPropertyOwner();
688 // we can only pass properties to scene graph side if there is a scene object
689 if( scenePropertyOwner )
691 // keep a local pointer to the property as the OwnerPointer will pass its copy to the message
692 const PropertyBase* property = newProperty.Get();
693 if(index >= PROPERTY_CUSTOM_START_INDEX)
695 DALI_ASSERT_ALWAYS( index <= PROPERTY_CUSTOM_MAX_INDEX && "Too many custom properties have been registered" );
697 mCustomProperties.PushBack( new CustomPropertyMetadata( name, key, propertyValue.GetType(), property ) );
701 mAnimatableProperties.PushBack( new AnimatablePropertyMetadata( index, Property::INVALID_COMPONENT_INDEX, propertyValue.GetType(), property ) ); // base property
704 // queue a message to add the property
705 InstallCustomPropertyMessage( const_cast<EventThreadServices&>(GetEventThreadServices()), *scenePropertyOwner, newProperty.Release() ); // Message takes ownership
707 // notify the derived class (optional) method in case it needs to do some more work on the new property
708 // note! have to use the local pointer as OwnerPointer now points to NULL as it handed over its ownership
709 NotifyScenePropertyInstalled( *property, name, index );
715 // property was orphaned and killed so return invalid index
716 return Property::INVALID_INDEX;
720 Property::Index Object::RegisterProperty( const std::string& name, const Property::Value& propertyValue )
722 return RegisterProperty( name, Property::INVALID_KEY, propertyValue, Property::ANIMATABLE );
725 Property::Index Object::RegisterProperty( const std::string& name, Property::Index key, const Property::Value& propertyValue )
727 return RegisterProperty( name, key, propertyValue, Property::ANIMATABLE );
730 Property::Index Object::RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode )
732 return RegisterProperty( name, Property::INVALID_KEY, propertyValue, accessMode );
735 Property::Index Object::RegisterProperty( const std::string& name, Property::Index key, const Property::Value& propertyValue, Property::AccessMode accessMode )
737 // If property with the required key already exists, then just set it.
738 Property::Index index = Property::INVALID_INDEX;
739 if( key != Property::INVALID_KEY ) // Try integer key first if it's valid
741 index = GetPropertyIndex( key );
743 if( index == Property::INVALID_INDEX ) // If it wasn't valid, or doesn't exist, try name
745 index = GetPropertyIndex( name );
748 if( index != Property::INVALID_INDEX ) // If there was a valid index found by either key, set it.
750 SetProperty( index, propertyValue );
754 // Otherwise register the property
756 if( Property::ANIMATABLE == accessMode )
758 index = RegisterSceneGraphProperty( name, key, PROPERTY_CUSTOM_START_INDEX + mCustomProperties.Count(), propertyValue );
759 AddUniformMapping( index, name );
763 // Add entry to the property lookup
764 index = PROPERTY_CUSTOM_START_INDEX + mCustomProperties.Count();
766 CustomPropertyMetadata* customProperty = new CustomPropertyMetadata( name, propertyValue, accessMode );
768 // Resolve index for the child property
769 Object* parent = GetParentObject();
772 const TypeInfo* parentTypeInfo( parent->GetTypeInfo() );
775 Property::Index childPropertyIndex = parentTypeInfo->GetChildPropertyIndex( name );
776 if( childPropertyIndex != Property::INVALID_INDEX )
778 customProperty->childPropertyIndex = childPropertyIndex;
779 index = childPropertyIndex;
784 mCustomProperties.PushBack( customProperty );
791 Dali::PropertyNotification Object::AddPropertyNotification(Property::Index index,
793 const Dali::PropertyCondition& condition)
795 if ( index >= DEFAULT_PROPERTY_MAX_COUNT )
797 if ( index <= PROPERTY_REGISTRATION_MAX_INDEX )
799 DALI_ASSERT_ALWAYS( false && "Property notification added to event side only property." );
801 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
803 // check whether the animatable property is registered already, if not then register one.
804 AnimatablePropertyMetadata* animatable = RegisterAnimatableProperty( index );
805 DALI_ASSERT_ALWAYS( animatable && "Property index is invalid" );
807 else if ( mCustomProperties.Count() > 0 )
809 CustomPropertyMetadata* custom = FindCustomProperty( index );
810 DALI_ASSERT_ALWAYS( custom && "Invalid property index" );
811 DALI_ASSERT_ALWAYS( custom->IsAnimatable() && "Property notification added to event side only property." );
815 Dali::Handle self(this);
816 Property target( self, index );
818 PropertyNotificationPtr internal = PropertyNotification::New( target, componentIndex, condition );
819 Dali::PropertyNotification propertyNotification(internal.Get());
821 if( !mPropertyNotifications )
823 mPropertyNotifications = new PropertyNotificationContainer;
825 mPropertyNotifications->push_back(propertyNotification);
827 return propertyNotification;
830 void Object::RemovePropertyNotification(Dali::PropertyNotification propertyNotification)
832 if( mPropertyNotifications )
834 PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
835 while(iter != mPropertyNotifications->end() )
837 if(*iter == propertyNotification)
839 mPropertyNotifications->erase(iter);
840 // As we can't ensure all references are removed, we can just disable
842 GetImplementation(propertyNotification).Disable();
850 void Object::RemovePropertyNotifications()
852 if( mPropertyNotifications )
854 PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
855 while(iter != mPropertyNotifications->end() )
857 // As we can't ensure all references are removed, we can just disable
859 GetImplementation(*iter).Disable();
863 mPropertyNotifications->clear();
867 void Object::EnablePropertyNotifications()
869 if( mPropertyNotifications )
871 PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
872 PropertyNotificationContainerIter endIter = mPropertyNotifications->end();
874 for( ; iter != endIter; ++iter )
876 GetImplementation(*iter).Enable();
881 void Object::DisablePropertyNotifications()
883 if( mPropertyNotifications )
885 PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
886 PropertyNotificationContainerIter endIter = mPropertyNotifications->end();
888 for( ; iter != endIter; ++iter )
890 GetImplementation(*iter).Disable();
895 void Object::AddUniformMapping( Property::Index propertyIndex, const std::string& uniformName ) const
897 // Get the address of the property if it's a scene property
898 const PropertyInputImpl* propertyPtr = GetSceneObjectInputProperty( propertyIndex );
900 // Check instead for newly registered properties
901 if( propertyPtr == NULL )
903 PropertyMetadata* animatable = FindAnimatableProperty( propertyIndex );
904 if( animatable != NULL )
906 propertyPtr = animatable->GetSceneGraphProperty();
910 if( propertyPtr == NULL )
912 PropertyMetadata* custom = FindCustomProperty( propertyIndex );
915 propertyPtr = custom->GetSceneGraphProperty();
919 if( propertyPtr != NULL )
921 const SceneGraph::PropertyOwner* sceneObject = GetPropertyOwner();
923 if( sceneObject != NULL )
925 SceneGraph::UniformPropertyMapping* map = new SceneGraph::UniformPropertyMapping( uniformName, propertyPtr );
926 // Message takes ownership of Uniform map (and will delete it after copy)
927 AddUniformMapMessage( const_cast<EventThreadServices&>(GetEventThreadServices()), *sceneObject, map);
931 DALI_ASSERT_ALWAYS(0 && "MESH_REWORK - Need to store property whilst off-stage" );
936 void Object::RemoveUniformMapping( const std::string& uniformName )
938 const SceneGraph::PropertyOwner* sceneObject = GetSceneObject();
939 RemoveUniformMapMessage( GetEventThreadServices(), *sceneObject, uniformName);
942 Property::Value Object::GetPropertyValue( const PropertyMetadata* entry ) const
944 Property::Value value;
946 DALI_ASSERT_ALWAYS( entry && "Invalid property metadata" );
948 if( !entry->IsAnimatable() )
950 value = entry->value;
954 BufferIndex bufferIndex( GetEventThreadServices().GetEventBufferIndex() );
956 switch ( entry->GetType() )
958 case Property::BOOLEAN:
960 const AnimatableProperty<bool>* property = static_cast< const AnimatableProperty<bool>* >( entry->GetSceneGraphProperty() );
961 DALI_ASSERT_DEBUG( NULL != property );
963 value = (*property)[ bufferIndex ];
967 case Property::INTEGER:
969 const AnimatableProperty<int>* property = static_cast< const AnimatableProperty<int>* >( entry->GetSceneGraphProperty() );
970 DALI_ASSERT_DEBUG( NULL != property );
972 value = (*property)[ bufferIndex ];
976 case Property::FLOAT:
978 const AnimatableProperty<float>* property = static_cast< const AnimatableProperty<float>* >( entry->GetSceneGraphProperty() );
979 DALI_ASSERT_DEBUG( NULL != property );
981 value = (*property)[ bufferIndex ];
985 case Property::VECTOR2:
987 const AnimatableProperty<Vector2>* property = static_cast< const AnimatableProperty<Vector2>* >( entry->GetSceneGraphProperty() );
988 DALI_ASSERT_DEBUG( NULL != property );
990 if(entry->componentIndex == 0)
992 value = (*property)[ bufferIndex ].x;
994 else if(entry->componentIndex == 1)
996 value = (*property)[ bufferIndex ].y;
1000 value = (*property)[ bufferIndex ];
1005 case Property::VECTOR3:
1007 const AnimatableProperty<Vector3>* property = static_cast< const AnimatableProperty<Vector3>* >( entry->GetSceneGraphProperty() );
1008 DALI_ASSERT_DEBUG( NULL != property );
1010 if(entry->componentIndex == 0)
1012 value = (*property)[ bufferIndex ].x;
1014 else if(entry->componentIndex == 1)
1016 value = (*property)[ bufferIndex ].y;
1018 else if(entry->componentIndex == 2)
1020 value = (*property)[ bufferIndex ].z;
1024 value = (*property)[ bufferIndex ];
1029 case Property::VECTOR4:
1031 const AnimatableProperty<Vector4>* property = static_cast< const AnimatableProperty<Vector4>* >( entry->GetSceneGraphProperty() );
1032 DALI_ASSERT_DEBUG( NULL != property );
1034 if(entry->componentIndex == 0)
1036 value = (*property)[ bufferIndex ].x;
1038 else if(entry->componentIndex == 1)
1040 value = (*property)[ bufferIndex ].y;
1042 else if(entry->componentIndex == 2)
1044 value = (*property)[ bufferIndex ].z;
1046 else if(entry->componentIndex == 3)
1048 value = (*property)[ bufferIndex ].w;
1052 value = (*property)[ bufferIndex ];
1057 case Property::MATRIX:
1059 const AnimatableProperty<Matrix>* property = static_cast< const AnimatableProperty<Matrix>* >( entry->GetSceneGraphProperty() );
1060 DALI_ASSERT_DEBUG( NULL != property );
1062 value = (*property)[ bufferIndex ];
1066 case Property::MATRIX3:
1068 const AnimatableProperty<Matrix3>* property = static_cast< const AnimatableProperty<Matrix3>* >( entry->GetSceneGraphProperty() );
1069 DALI_ASSERT_DEBUG( NULL != property );
1071 value = (*property)[ bufferIndex ];
1075 case Property::ROTATION:
1077 const AnimatableProperty<Quaternion>* property = static_cast< const AnimatableProperty<Quaternion>* >( entry->GetSceneGraphProperty() );
1078 DALI_ASSERT_DEBUG( NULL != property );
1080 value = (*property)[ bufferIndex ];
1086 DALI_ASSERT_ALWAYS( false && "PropertyType enumeration is out of bounds" );
1095 void Object::SetSceneGraphProperty( Property::Index index, const PropertyMetadata& entry, const Property::Value& value )
1097 switch ( entry.GetType() )
1099 case Property::BOOLEAN:
1101 const AnimatableProperty<bool>* property = dynamic_cast< const AnimatableProperty<bool>* >( entry.GetSceneGraphProperty() );
1102 DALI_ASSERT_DEBUG( NULL != property );
1104 // property is being used in a separate thread; queue a message to set the property
1105 BakeMessage<bool>( GetEventThreadServices(), *property, value.Get<bool>() );
1109 case Property::INTEGER:
1111 const AnimatableProperty<int>* property = dynamic_cast< const AnimatableProperty<int>* >( entry.GetSceneGraphProperty() );
1112 DALI_ASSERT_DEBUG( NULL != property );
1114 // property is being used in a separate thread; queue a message to set the property
1115 BakeMessage<int>( GetEventThreadServices(), *property, value.Get<int>() );
1119 case Property::FLOAT:
1121 const AnimatableProperty<float>* property = dynamic_cast< const AnimatableProperty<float>* >( entry.GetSceneGraphProperty() );
1122 DALI_ASSERT_DEBUG( NULL != property );
1124 // property is being used in a separate thread; queue a message to set the property
1125 BakeMessage<float>( GetEventThreadServices(), *property, value.Get<float>() );
1129 case Property::VECTOR2:
1131 const AnimatableProperty<Vector2>* property = dynamic_cast< const AnimatableProperty<Vector2>* >( entry.GetSceneGraphProperty() );
1132 DALI_ASSERT_DEBUG( NULL != property );
1134 // property is being used in a separate thread; queue a message to set the property
1135 if(entry.componentIndex == 0)
1137 SetXComponentMessage<Vector2>( GetEventThreadServices(), *property, value.Get<float>() );
1139 else if(entry.componentIndex == 1)
1141 SetYComponentMessage<Vector2>( GetEventThreadServices(), *property, value.Get<float>() );
1145 BakeMessage<Vector2>( GetEventThreadServices(), *property, value.Get<Vector2>() );
1150 case Property::VECTOR3:
1152 const AnimatableProperty<Vector3>* property = dynamic_cast< const AnimatableProperty<Vector3>* >( entry.GetSceneGraphProperty() );
1153 DALI_ASSERT_DEBUG( NULL != property );
1155 // property is being used in a separate thread; queue a message to set the property
1156 if(entry.componentIndex == 0)
1158 SetXComponentMessage<Vector3>( GetEventThreadServices(), *property, value.Get<float>() );
1160 else if(entry.componentIndex == 1)
1162 SetYComponentMessage<Vector3>( GetEventThreadServices(), *property, value.Get<float>() );
1164 else if(entry.componentIndex == 2)
1166 SetZComponentMessage<Vector3>( GetEventThreadServices(), *property, value.Get<float>() );
1170 BakeMessage<Vector3>( GetEventThreadServices(), *property, value.Get<Vector3>() );
1176 case Property::VECTOR4:
1178 const AnimatableProperty<Vector4>* property = dynamic_cast< const AnimatableProperty<Vector4>* >( entry.GetSceneGraphProperty() );
1179 DALI_ASSERT_DEBUG( NULL != property );
1181 // property is being used in a separate thread; queue a message to set the property
1182 if(entry.componentIndex == 0)
1184 SetXComponentMessage<Vector4>( GetEventThreadServices(), *property, value.Get<float>() );
1186 else if(entry.componentIndex == 1)
1188 SetYComponentMessage<Vector4>( GetEventThreadServices(), *property, value.Get<float>() );
1190 else if(entry.componentIndex == 2)
1192 SetZComponentMessage<Vector4>( GetEventThreadServices(), *property, value.Get<float>() );
1194 else if(entry.componentIndex == 3)
1196 SetWComponentMessage<Vector4>( GetEventThreadServices(), *property, value.Get<float>() );
1200 BakeMessage<Vector4>( GetEventThreadServices(), *property, value.Get<Vector4>() );
1205 case Property::ROTATION:
1207 const AnimatableProperty<Quaternion>* property = dynamic_cast< const AnimatableProperty<Quaternion>* >( entry.GetSceneGraphProperty() );
1208 DALI_ASSERT_DEBUG( NULL != property );
1210 // property is being used in a separate thread; queue a message to set the property
1211 BakeMessage<Quaternion>( GetEventThreadServices(), *property, value.Get<Quaternion>() );
1215 case Property::MATRIX:
1217 const AnimatableProperty<Matrix>* property = dynamic_cast< const AnimatableProperty<Matrix>* >( entry.GetSceneGraphProperty() );
1218 DALI_ASSERT_DEBUG( NULL != property );
1220 // property is being used in a separate thread; queue a message to set the property
1221 BakeMessage<Matrix>( GetEventThreadServices(), *property, value.Get<Matrix>() );
1225 case Property::MATRIX3:
1227 const AnimatableProperty<Matrix3>* property = dynamic_cast< const AnimatableProperty<Matrix3>* >( entry.GetSceneGraphProperty() );
1228 DALI_ASSERT_DEBUG( NULL != property );
1230 // property is being used in a separate thread; queue a message to set the property
1231 BakeMessage<Matrix3>( GetEventThreadServices(), *property, value.Get<Matrix3>() );
1237 // non-animatable scene graph property, do nothing
1242 const TypeInfo* Object::GetTypeInfo() const
1246 // This uses a dynamic_cast so can be quite expensive so we only really want to do it once
1247 // especially as the type-info does not change during the life-time of an application
1249 Dali::TypeInfo typeInfoHandle = TypeRegistry::Get()->GetTypeInfo( this );
1250 if ( typeInfoHandle )
1252 mTypeInfo = &GetImplementation( typeInfoHandle );
1259 void Object::ApplyConstraint( ConstraintBase& constraint )
1263 mConstraints = new ConstraintContainer;
1265 mConstraints->push_back( Dali::Constraint( &constraint ) );
1268 void Object::RemoveConstraint( ConstraintBase& constraint )
1270 // NULL if the Constraint sources are destroyed before Constraint::Apply()
1273 ConstraintIter it( std::find( mConstraints->begin(), mConstraints->end(), Dali::Constraint( &constraint ) ) );
1274 if( it != mConstraints->end() )
1276 mConstraints->erase( it );
1281 void Object::RemoveConstraints()
1283 // guard against constraint sending messages during core destruction
1284 if( mConstraints && Stage::IsInstalled() )
1286 // If we have nothing in the scene-graph, just clear constraint containers
1287 const SceneGraph::PropertyOwner* propertyOwner = GetSceneObject();
1288 if ( NULL != propertyOwner )
1290 const ConstraintConstIter endIter = mConstraints->end();
1291 for ( ConstraintIter iter = mConstraints->begin(); endIter != iter; ++iter )
1293 GetImplementation( *iter ).RemoveInternal();
1297 delete mConstraints;
1298 mConstraints = NULL;
1302 void Object::RemoveConstraints( unsigned int tag )
1304 // guard against constraint sending messages during core destruction
1305 if( mConstraints && Stage::IsInstalled() )
1307 ConstraintIter iter( mConstraints->begin() );
1308 while(iter != mConstraints->end() )
1310 ConstraintBase& constraint = GetImplementation( *iter );
1311 if( constraint.GetTag() == tag )
1313 GetImplementation( *iter ).RemoveInternal();
1314 iter = mConstraints->erase( iter );
1322 if ( mConstraints->empty() )
1324 delete mConstraints;
1325 mConstraints = NULL;
1330 void Object::SetTypeInfo( const TypeInfo* typeInfo )
1332 mTypeInfo = typeInfo;
1337 // Notification for observers
1338 for( ConstObserverIter iter = mObservers.Begin(), endIter = mObservers.End(); iter != endIter; ++iter)
1340 (*iter)->ObjectDestroyed(*this);
1343 delete mConstraints;
1344 delete mPropertyNotifications;
1347 CustomPropertyMetadata* Object::FindCustomProperty( Property::Index index ) const
1349 CustomPropertyMetadata* property( NULL );
1350 if ( ( index >= CHILD_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= CHILD_PROPERTY_REGISTRATION_MAX_INDEX ) )
1352 for ( std::size_t arrayIndex = 0; arrayIndex < mCustomProperties.Count(); arrayIndex++ )
1354 CustomPropertyMetadata* custom = static_cast<CustomPropertyMetadata*>( mCustomProperties[ arrayIndex ] );
1355 if( custom->childPropertyIndex == index )
1363 int arrayIndex = index - PROPERTY_CUSTOM_START_INDEX;
1364 if( arrayIndex >= 0 )
1366 if( arrayIndex < (int)mCustomProperties.Count() ) // we can only access the first 2 billion custom properties
1368 property = static_cast<CustomPropertyMetadata*>(mCustomProperties[ arrayIndex ]);
1375 AnimatablePropertyMetadata* Object::FindAnimatableProperty( Property::Index index ) const
1377 for ( int arrayIndex = 0; arrayIndex < (int)mAnimatableProperties.Count(); arrayIndex++ )
1379 AnimatablePropertyMetadata* property = static_cast<AnimatablePropertyMetadata*>( mAnimatableProperties[ arrayIndex ] );
1380 if( property->index == index )
1388 AnimatablePropertyMetadata* Object::RegisterAnimatableProperty(Property::Index index) const
1390 DALI_ASSERT_ALWAYS( (( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ))
1391 && "Property index is out of bounds" );
1393 // check whether the animatable property is registered already, if not then register one.
1394 AnimatablePropertyMetadata* animatableProperty = FindAnimatableProperty( index );
1395 if( !animatableProperty )
1397 const TypeInfo* typeInfo( GetTypeInfo() );
1400 Property::Index basePropertyIndex = typeInfo->GetBasePropertyIndex(index);
1401 if( basePropertyIndex == Property::INVALID_INDEX )
1403 // If the property is not a component of a base property, register the whole property itself.
1404 const std::string& propertyName = typeInfo->GetPropertyName(index);
1405 RegisterSceneGraphProperty(propertyName, Property::INVALID_KEY, index, typeInfo->GetPropertyDefaultValue(index));
1406 AddUniformMapping( index, propertyName );
1410 // Since the property is a component of a base property, check whether the base property is registered.
1411 animatableProperty = FindAnimatableProperty( basePropertyIndex );
1412 if( !animatableProperty )
1414 // If the base property is not registered yet, register the base property first.
1415 const std::string& basePropertyName = typeInfo->GetPropertyName(basePropertyIndex);
1417 if( Property::INVALID_INDEX != RegisterSceneGraphProperty( basePropertyName, Property::INVALID_KEY, basePropertyIndex, Property::Value(typeInfo->GetPropertyType( basePropertyIndex ) ) ) )
1419 animatableProperty = static_cast<AnimatablePropertyMetadata*>(mAnimatableProperties[mAnimatableProperties.Size()-1]);
1420 AddUniformMapping( basePropertyIndex, basePropertyName );
1424 if(animatableProperty)
1426 // Create the metadata for the property component.
1427 mAnimatableProperties.PushBack( new AnimatablePropertyMetadata( index, typeInfo->GetComponentIndex(index), animatableProperty->GetType(), animatableProperty->GetSceneGraphProperty() ) );
1431 // The metadata has just been added and therefore should be in the end of the vector.
1432 animatableProperty = static_cast<AnimatablePropertyMetadata*>(mAnimatableProperties[mAnimatableProperties.Size()-1]);
1436 return animatableProperty;
1439 void Object::ResolveChildProperties()
1441 // Resolve index for the child property
1442 Object* parent = GetParentObject();
1445 const TypeInfo* parentTypeInfo( parent->GetTypeInfo() );
1446 if( parentTypeInfo )
1448 // Go through each custom property
1449 for ( int arrayIndex = 0; arrayIndex < (int)mCustomProperties.Count(); arrayIndex++ )
1451 CustomPropertyMetadata* customProperty = static_cast<CustomPropertyMetadata*>( mCustomProperties[ arrayIndex ] );
1453 if( customProperty->name == "" )
1455 if( customProperty->childPropertyIndex != Property::INVALID_INDEX )
1457 // Resolve name for any child property with no name
1458 customProperty->name = parentTypeInfo->GetChildPropertyName( customProperty->childPropertyIndex );
1463 Property::Index childPropertyIndex = parentTypeInfo->GetChildPropertyIndex( customProperty->name );
1464 if( childPropertyIndex != Property::INVALID_INDEX )
1466 // Resolve index for any property with a name that matches the parent's child property name
1467 customProperty->childPropertyIndex = childPropertyIndex;
1475 } // namespace Internal