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 bool Object::IsPropertyWritable( Property::Index index ) const
248 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds");
250 bool writable = false;
252 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
254 writable = IsDefaultPropertyWritable( index );
256 else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
258 const TypeInfo* typeInfo( GetTypeInfo() );
261 writable = typeInfo->IsPropertyWritable( index );
265 DALI_ASSERT_ALWAYS( ! "Invalid property index" );
268 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
270 // Type Registry scene-graph properties are writable.
275 CustomPropertyMetadata* custom = FindCustomProperty( index );
278 writable = custom->IsWritable();
285 bool Object::IsPropertyAnimatable( Property::Index index ) const
287 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds");
289 bool animatable = false;
291 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
293 animatable = IsDefaultPropertyAnimatable( index );
295 else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
297 // Type Registry event-thread only properties are not animatable.
300 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
302 // Type Registry scene-graph properties are animatable.
307 CustomPropertyMetadata* custom = FindCustomProperty( index );
310 animatable = custom->IsAnimatable();
317 bool Object::IsPropertyAConstraintInput( Property::Index index ) const
319 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds");
321 bool isConstraintInput = false;
323 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
325 isConstraintInput = IsDefaultPropertyAConstraintInput( index );
327 else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
329 // Type Registry event-thread only properties cannot be used as an input to a constraint.
330 isConstraintInput = false;
332 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
334 // scene graph properties can be used as input to a constraint.
335 isConstraintInput = true;
339 CustomPropertyMetadata* custom = FindCustomProperty( index );
342 // ... custom properties can be used as input to a constraint.
343 isConstraintInput = true;
347 return isConstraintInput;
350 Property::Type Object::GetPropertyType( Property::Index index ) const
352 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds" );
354 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
356 return GetDefaultPropertyType( index );
359 if ( ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
360 || ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) ) )
362 const TypeInfo* typeInfo( GetTypeInfo() );
365 return typeInfo->GetPropertyType( index );
369 DALI_ASSERT_ALWAYS( ! "Cannot find property index" );
373 CustomPropertyMetadata* custom = FindCustomProperty( index );
376 return custom->GetType();
379 return Property::NONE;
382 void Object::SetProperty( Property::Index index, const Property::Value& propertyValue )
384 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds" );
386 bool propertySet( true );
388 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
390 SetDefaultProperty( index, propertyValue );
392 else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
394 const TypeInfo* typeInfo( GetTypeInfo() );
397 typeInfo->SetProperty( this, index, propertyValue );
401 DALI_LOG_ERROR("Cannot find property index\n");
405 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
407 // check whether the animatable property is registered already, if not then register one.
408 AnimatablePropertyMetadata* animatableProperty = RegisterAnimatableProperty( index );
409 if(!animatableProperty)
411 DALI_LOG_ERROR("Cannot find property index\n");
416 // set the scene graph property value
417 SetSceneGraphProperty( index, *animatableProperty, propertyValue );
422 CustomPropertyMetadata* custom = FindCustomProperty( index );
424 if ( ( index >= CHILD_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= CHILD_PROPERTY_REGISTRATION_MAX_INDEX ) )
428 // If the child property is not registered yet, register it.
429 custom = new CustomPropertyMetadata( "", propertyValue, Property::READ_WRITE );
430 mCustomProperties.PushBack( custom );
433 custom->childPropertyIndex = index;
435 // Resolve name for the child property
436 Object* parent = GetParentObject();
439 const TypeInfo* parentTypeInfo( parent->GetTypeInfo() );
442 custom->name = parentTypeInfo->GetChildPropertyName( index );
449 if( custom->IsAnimatable() )
451 // set the scene graph property value
452 SetSceneGraphProperty( index, *custom, propertyValue );
454 else if( custom->IsWritable() )
456 custom->value = propertyValue;
460 // trying to set value on read only property is no-op
466 DALI_LOG_ERROR("Invalid property index\n");
471 // Let derived classes know that a property has been set
472 // 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
475 OnPropertySet(index, propertyValue);
479 Property::Value Object::GetProperty(Property::Index index) const
481 DALI_ASSERT_ALWAYS( index > Property::INVALID_INDEX && "Property index is out of bounds" );
483 Property::Value value;
485 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
487 value = GetDefaultProperty( index );
489 else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
491 const TypeInfo* typeInfo( GetTypeInfo() );
494 value = typeInfo->GetProperty( this, index );
498 DALI_LOG_ERROR("Cannot find property index\n");
501 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
503 // check whether the animatable property is registered already, if not then register one.
504 AnimatablePropertyMetadata* animatableProperty = RegisterAnimatableProperty( index );
505 if(!animatableProperty)
507 DALI_LOG_ERROR("Cannot find property index\n");
511 // get the animatable property value
512 value = GetPropertyValue( animatableProperty );
515 else if(mCustomProperties.Count() > 0)
517 CustomPropertyMetadata* custom = FindCustomProperty( index );
520 // get the custom property value
521 value = GetPropertyValue( custom );
525 DALI_LOG_ERROR("Invalid property index\n");
532 void Object::GetPropertyIndices( Property::IndexContainer& indices ) const
536 // Default Properties
537 GetDefaultPropertyIndices( indices );
540 const TypeInfo* typeInfo( GetTypeInfo() );
543 typeInfo->GetPropertyIndices( indices );
547 if ( mCustomProperties.Count() > 0 )
549 indices.Reserve( indices.Size() + mCustomProperties.Count() );
551 PropertyMetadataLookup::ConstIterator iter = mCustomProperties.Begin();
552 const PropertyMetadataLookup::ConstIterator endIter = mCustomProperties.End();
554 for ( ; iter != endIter; ++iter, ++i )
556 CustomPropertyMetadata* custom = static_cast<CustomPropertyMetadata*>( *iter );
557 if ( custom->childPropertyIndex != Property::INVALID_INDEX )
559 // If it is a child property, add the child property index
560 indices.PushBack( custom->childPropertyIndex );
564 indices.PushBack( PROPERTY_CUSTOM_START_INDEX + i );
570 Property::Index Object::RegisterSceneGraphProperty(const std::string& name, Property::Index index, const Property::Value& propertyValue) const
572 // Create a new property
573 Dali::Internal::OwnerPointer<PropertyBase> newProperty;
575 switch ( propertyValue.GetType() )
577 case Property::BOOLEAN:
579 newProperty = new AnimatableProperty<bool>( propertyValue.Get<bool>() );
583 case Property::INTEGER:
585 newProperty = new AnimatableProperty<int>( propertyValue.Get<int>() );
589 case Property::FLOAT:
591 newProperty = new AnimatableProperty<float>( propertyValue.Get<float>() );
595 case Property::VECTOR2:
597 newProperty = new AnimatableProperty<Vector2>( propertyValue.Get<Vector2>() );
601 case Property::VECTOR3:
603 newProperty = new AnimatableProperty<Vector3>( propertyValue.Get<Vector3>() );
607 case Property::VECTOR4:
609 newProperty = new AnimatableProperty<Vector4>( propertyValue.Get<Vector4>() );
613 case Property::MATRIX:
615 newProperty = new AnimatableProperty<Matrix>( propertyValue.Get<Matrix>() );
619 case Property::MATRIX3:
621 newProperty = new AnimatableProperty<Matrix3>( propertyValue.Get<Matrix3>() );
625 case Property::ROTATION:
627 newProperty = new AnimatableProperty<Quaternion>( propertyValue.Get<Quaternion>() );
631 case Property::RECTANGLE:
632 case Property::STRING:
633 case Property::ARRAY:
637 DALI_ASSERT_ALWAYS( !"PropertyType is not animatable" );
642 // get the scene property owner from derived class
643 const SceneGraph::PropertyOwner* scenePropertyOwner = GetPropertyOwner();
644 // we can only pass properties to scene graph side if there is a scene object
645 if( scenePropertyOwner )
647 // keep a local pointer to the property as the OwnerPointer will pass its copy to the message
648 const PropertyBase* property = newProperty.Get();
649 if(index >= PROPERTY_CUSTOM_START_INDEX)
651 DALI_ASSERT_ALWAYS( index <= PROPERTY_CUSTOM_MAX_INDEX && "Too many custom properties have been registered" );
653 mCustomProperties.PushBack( new CustomPropertyMetadata( name, propertyValue.GetType(), property ) );
657 mAnimatableProperties.PushBack( new AnimatablePropertyMetadata( index, Property::INVALID_COMPONENT_INDEX, propertyValue.GetType(), property ) ); // base property
660 // queue a message to add the property
661 InstallCustomPropertyMessage( const_cast<EventThreadServices&>(GetEventThreadServices()), *scenePropertyOwner, newProperty.Release() ); // Message takes ownership
663 // notify the derived class (optional) method in case it needs to do some more work on the new property
664 // note! have to use the local pointer as OwnerPointer now points to NULL as it handed over its ownership
665 NotifyScenePropertyInstalled( *property, name, index );
671 // property was orphaned and killed so return invalid index
672 return Property::INVALID_INDEX;
676 Property::Index Object::RegisterProperty( const std::string& name, const Property::Value& propertyValue )
678 return RegisterProperty( name, propertyValue, Property::ANIMATABLE );
681 Property::Index Object::RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode )
683 // If property with the required name already exists, then just set it.
684 Property::Index index = GetPropertyIndex( name );
685 if( index != Property::INVALID_INDEX )
687 SetProperty( index, propertyValue );
691 // Otherwise register the property
693 if(Property::ANIMATABLE == accessMode)
695 index = RegisterSceneGraphProperty( name, PROPERTY_CUSTOM_START_INDEX + mCustomProperties.Count(), propertyValue );
696 AddUniformMapping( index, name );
700 // Add entry to the property lookup
701 index = PROPERTY_CUSTOM_START_INDEX + mCustomProperties.Count();
703 CustomPropertyMetadata* customProperty = new CustomPropertyMetadata( name, propertyValue, accessMode );
705 // Resolve index for the child property
706 Object* parent = GetParentObject();
709 const TypeInfo* parentTypeInfo( parent->GetTypeInfo() );
712 Property::Index childPropertyIndex = parentTypeInfo->GetChildPropertyIndex( name );
713 if( childPropertyIndex != Property::INVALID_INDEX )
715 customProperty->childPropertyIndex = childPropertyIndex;
716 index = childPropertyIndex;
721 mCustomProperties.PushBack( customProperty );
728 Dali::PropertyNotification Object::AddPropertyNotification(Property::Index index,
730 const Dali::PropertyCondition& condition)
732 if ( index >= DEFAULT_PROPERTY_MAX_COUNT )
734 if ( index <= PROPERTY_REGISTRATION_MAX_INDEX )
736 DALI_ASSERT_ALWAYS( false && "Property notification added to event side only property." );
738 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
740 // check whether the animatable property is registered already, if not then register one.
741 AnimatablePropertyMetadata* animatable = RegisterAnimatableProperty( index );
742 DALI_ASSERT_ALWAYS( animatable && "Property index is invalid" );
744 else if ( mCustomProperties.Count() > 0 )
746 CustomPropertyMetadata* custom = FindCustomProperty( index );
747 DALI_ASSERT_ALWAYS( custom && "Invalid property index" );
748 DALI_ASSERT_ALWAYS( custom->IsAnimatable() && "Property notification added to event side only property." );
752 Dali::Handle self(this);
753 Property target( self, index );
755 PropertyNotificationPtr internal = PropertyNotification::New( target, componentIndex, condition );
756 Dali::PropertyNotification propertyNotification(internal.Get());
758 if( !mPropertyNotifications )
760 mPropertyNotifications = new PropertyNotificationContainer;
762 mPropertyNotifications->push_back(propertyNotification);
764 return propertyNotification;
767 void Object::RemovePropertyNotification(Dali::PropertyNotification propertyNotification)
769 if( mPropertyNotifications )
771 PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
772 while(iter != mPropertyNotifications->end() )
774 if(*iter == propertyNotification)
776 mPropertyNotifications->erase(iter);
777 // As we can't ensure all references are removed, we can just disable
779 GetImplementation(propertyNotification).Disable();
787 void Object::RemovePropertyNotifications()
789 if( mPropertyNotifications )
791 PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
792 while(iter != mPropertyNotifications->end() )
794 // As we can't ensure all references are removed, we can just disable
796 GetImplementation(*iter).Disable();
800 mPropertyNotifications->clear();
804 void Object::EnablePropertyNotifications()
806 if( mPropertyNotifications )
808 PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
809 PropertyNotificationContainerIter endIter = mPropertyNotifications->end();
811 for( ; iter != endIter; ++iter )
813 GetImplementation(*iter).Enable();
818 void Object::DisablePropertyNotifications()
820 if( mPropertyNotifications )
822 PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
823 PropertyNotificationContainerIter endIter = mPropertyNotifications->end();
825 for( ; iter != endIter; ++iter )
827 GetImplementation(*iter).Disable();
832 void Object::AddUniformMapping( Property::Index propertyIndex, const std::string& uniformName ) const
834 // Get the address of the property if it's a scene property
835 const PropertyInputImpl* propertyPtr = GetSceneObjectInputProperty( propertyIndex );
837 // Check instead for newly registered properties
838 if( propertyPtr == NULL )
840 PropertyMetadata* animatable = FindAnimatableProperty( propertyIndex );
841 if( animatable != NULL )
843 propertyPtr = animatable->GetSceneGraphProperty();
847 if( propertyPtr == NULL )
849 PropertyMetadata* custom = FindCustomProperty( propertyIndex );
852 propertyPtr = custom->GetSceneGraphProperty();
856 if( propertyPtr != NULL )
858 const SceneGraph::PropertyOwner* sceneObject = GetPropertyOwner();
860 if( sceneObject != NULL )
862 SceneGraph::UniformPropertyMapping* map = new SceneGraph::UniformPropertyMapping( uniformName, propertyPtr );
863 // Message takes ownership of Uniform map (and will delete it after copy)
864 AddUniformMapMessage( const_cast<EventThreadServices&>(GetEventThreadServices()), *sceneObject, map);
868 DALI_ASSERT_ALWAYS(0 && "MESH_REWORK - Need to store property whilst off-stage" );
873 void Object::RemoveUniformMapping( const std::string& uniformName )
875 const SceneGraph::PropertyOwner* sceneObject = GetSceneObject();
876 RemoveUniformMapMessage( GetEventThreadServices(), *sceneObject, uniformName);
879 Property::Value Object::GetPropertyValue( const PropertyMetadata* entry ) const
881 Property::Value value;
883 DALI_ASSERT_ALWAYS( entry && "Invalid property metadata" );
885 if( !entry->IsAnimatable() )
887 value = entry->value;
891 BufferIndex bufferIndex( GetEventThreadServices().GetEventBufferIndex() );
893 switch ( entry->GetType() )
895 case Property::BOOLEAN:
897 const AnimatableProperty<bool>* property = static_cast< const AnimatableProperty<bool>* >( entry->GetSceneGraphProperty() );
898 DALI_ASSERT_DEBUG( NULL != property );
900 value = (*property)[ bufferIndex ];
904 case Property::INTEGER:
906 const AnimatableProperty<int>* property = static_cast< const AnimatableProperty<int>* >( entry->GetSceneGraphProperty() );
907 DALI_ASSERT_DEBUG( NULL != property );
909 value = (*property)[ bufferIndex ];
913 case Property::FLOAT:
915 const AnimatableProperty<float>* property = static_cast< const AnimatableProperty<float>* >( entry->GetSceneGraphProperty() );
916 DALI_ASSERT_DEBUG( NULL != property );
918 value = (*property)[ bufferIndex ];
922 case Property::VECTOR2:
924 const AnimatableProperty<Vector2>* property = static_cast< const AnimatableProperty<Vector2>* >( entry->GetSceneGraphProperty() );
925 DALI_ASSERT_DEBUG( NULL != property );
927 if(entry->componentIndex == 0)
929 value = (*property)[ bufferIndex ].x;
931 else if(entry->componentIndex == 1)
933 value = (*property)[ bufferIndex ].y;
937 value = (*property)[ bufferIndex ];
942 case Property::VECTOR3:
944 const AnimatableProperty<Vector3>* property = static_cast< const AnimatableProperty<Vector3>* >( entry->GetSceneGraphProperty() );
945 DALI_ASSERT_DEBUG( NULL != property );
947 if(entry->componentIndex == 0)
949 value = (*property)[ bufferIndex ].x;
951 else if(entry->componentIndex == 1)
953 value = (*property)[ bufferIndex ].y;
955 else if(entry->componentIndex == 2)
957 value = (*property)[ bufferIndex ].z;
961 value = (*property)[ bufferIndex ];
966 case Property::VECTOR4:
968 const AnimatableProperty<Vector4>* property = static_cast< const AnimatableProperty<Vector4>* >( entry->GetSceneGraphProperty() );
969 DALI_ASSERT_DEBUG( NULL != property );
971 if(entry->componentIndex == 0)
973 value = (*property)[ bufferIndex ].x;
975 else if(entry->componentIndex == 1)
977 value = (*property)[ bufferIndex ].y;
979 else if(entry->componentIndex == 2)
981 value = (*property)[ bufferIndex ].z;
983 else if(entry->componentIndex == 3)
985 value = (*property)[ bufferIndex ].w;
989 value = (*property)[ bufferIndex ];
994 case Property::MATRIX:
996 const AnimatableProperty<Matrix>* property = static_cast< const AnimatableProperty<Matrix>* >( entry->GetSceneGraphProperty() );
997 DALI_ASSERT_DEBUG( NULL != property );
999 value = (*property)[ bufferIndex ];
1003 case Property::MATRIX3:
1005 const AnimatableProperty<Matrix3>* property = static_cast< const AnimatableProperty<Matrix3>* >( entry->GetSceneGraphProperty() );
1006 DALI_ASSERT_DEBUG( NULL != property );
1008 value = (*property)[ bufferIndex ];
1012 case Property::ROTATION:
1014 const AnimatableProperty<Quaternion>* property = static_cast< const AnimatableProperty<Quaternion>* >( entry->GetSceneGraphProperty() );
1015 DALI_ASSERT_DEBUG( NULL != property );
1017 value = (*property)[ bufferIndex ];
1023 DALI_ASSERT_ALWAYS( false && "PropertyType enumeration is out of bounds" );
1032 void Object::SetSceneGraphProperty( Property::Index index, const PropertyMetadata& entry, const Property::Value& value )
1034 switch ( entry.GetType() )
1036 case Property::BOOLEAN:
1038 const AnimatableProperty<bool>* property = dynamic_cast< const AnimatableProperty<bool>* >( entry.GetSceneGraphProperty() );
1039 DALI_ASSERT_DEBUG( NULL != property );
1041 // property is being used in a separate thread; queue a message to set the property
1042 BakeMessage<bool>( GetEventThreadServices(), *property, value.Get<bool>() );
1046 case Property::INTEGER:
1048 const AnimatableProperty<int>* property = dynamic_cast< const AnimatableProperty<int>* >( entry.GetSceneGraphProperty() );
1049 DALI_ASSERT_DEBUG( NULL != property );
1051 // property is being used in a separate thread; queue a message to set the property
1052 BakeMessage<int>( GetEventThreadServices(), *property, value.Get<int>() );
1056 case Property::FLOAT:
1058 const AnimatableProperty<float>* property = dynamic_cast< const AnimatableProperty<float>* >( entry.GetSceneGraphProperty() );
1059 DALI_ASSERT_DEBUG( NULL != property );
1061 // property is being used in a separate thread; queue a message to set the property
1062 BakeMessage<float>( GetEventThreadServices(), *property, value.Get<float>() );
1066 case Property::VECTOR2:
1068 const AnimatableProperty<Vector2>* property = dynamic_cast< const AnimatableProperty<Vector2>* >( entry.GetSceneGraphProperty() );
1069 DALI_ASSERT_DEBUG( NULL != property );
1071 // property is being used in a separate thread; queue a message to set the property
1072 if(entry.componentIndex == 0)
1074 SetXComponentMessage<Vector2>( GetEventThreadServices(), *property, value.Get<float>() );
1076 else if(entry.componentIndex == 1)
1078 SetYComponentMessage<Vector2>( GetEventThreadServices(), *property, value.Get<float>() );
1082 BakeMessage<Vector2>( GetEventThreadServices(), *property, value.Get<Vector2>() );
1087 case Property::VECTOR3:
1089 const AnimatableProperty<Vector3>* property = dynamic_cast< const AnimatableProperty<Vector3>* >( entry.GetSceneGraphProperty() );
1090 DALI_ASSERT_DEBUG( NULL != property );
1092 // property is being used in a separate thread; queue a message to set the property
1093 if(entry.componentIndex == 0)
1095 SetXComponentMessage<Vector3>( GetEventThreadServices(), *property, value.Get<float>() );
1097 else if(entry.componentIndex == 1)
1099 SetYComponentMessage<Vector3>( GetEventThreadServices(), *property, value.Get<float>() );
1101 else if(entry.componentIndex == 2)
1103 SetZComponentMessage<Vector3>( GetEventThreadServices(), *property, value.Get<float>() );
1107 BakeMessage<Vector3>( GetEventThreadServices(), *property, value.Get<Vector3>() );
1113 case Property::VECTOR4:
1115 const AnimatableProperty<Vector4>* property = dynamic_cast< const AnimatableProperty<Vector4>* >( entry.GetSceneGraphProperty() );
1116 DALI_ASSERT_DEBUG( NULL != property );
1118 // property is being used in a separate thread; queue a message to set the property
1119 if(entry.componentIndex == 0)
1121 SetXComponentMessage<Vector4>( GetEventThreadServices(), *property, value.Get<float>() );
1123 else if(entry.componentIndex == 1)
1125 SetYComponentMessage<Vector4>( GetEventThreadServices(), *property, value.Get<float>() );
1127 else if(entry.componentIndex == 2)
1129 SetZComponentMessage<Vector4>( GetEventThreadServices(), *property, value.Get<float>() );
1131 else if(entry.componentIndex == 3)
1133 SetWComponentMessage<Vector4>( GetEventThreadServices(), *property, value.Get<float>() );
1137 BakeMessage<Vector4>( GetEventThreadServices(), *property, value.Get<Vector4>() );
1142 case Property::ROTATION:
1144 const AnimatableProperty<Quaternion>* property = dynamic_cast< const AnimatableProperty<Quaternion>* >( entry.GetSceneGraphProperty() );
1145 DALI_ASSERT_DEBUG( NULL != property );
1147 // property is being used in a separate thread; queue a message to set the property
1148 BakeMessage<Quaternion>( GetEventThreadServices(), *property, value.Get<Quaternion>() );
1152 case Property::MATRIX:
1154 const AnimatableProperty<Matrix>* property = dynamic_cast< const AnimatableProperty<Matrix>* >( entry.GetSceneGraphProperty() );
1155 DALI_ASSERT_DEBUG( NULL != property );
1157 // property is being used in a separate thread; queue a message to set the property
1158 BakeMessage<Matrix>( GetEventThreadServices(), *property, value.Get<Matrix>() );
1162 case Property::MATRIX3:
1164 const AnimatableProperty<Matrix3>* property = dynamic_cast< const AnimatableProperty<Matrix3>* >( entry.GetSceneGraphProperty() );
1165 DALI_ASSERT_DEBUG( NULL != property );
1167 // property is being used in a separate thread; queue a message to set the property
1168 BakeMessage<Matrix3>( GetEventThreadServices(), *property, value.Get<Matrix3>() );
1174 // non-animatable scene graph property, do nothing
1179 const TypeInfo* Object::GetTypeInfo() const
1183 // This uses a dynamic_cast so can be quite expensive so we only really want to do it once
1184 // especially as the type-info does not change during the life-time of an application
1186 Dali::TypeInfo typeInfoHandle = TypeRegistry::Get()->GetTypeInfo( this );
1187 if ( typeInfoHandle )
1189 mTypeInfo = &GetImplementation( typeInfoHandle );
1196 void Object::ApplyConstraint( ConstraintBase& constraint )
1200 mConstraints = new ConstraintContainer;
1202 mConstraints->push_back( Dali::Constraint( &constraint ) );
1205 void Object::RemoveConstraint( ConstraintBase& constraint )
1207 // NULL if the Constraint sources are destroyed before Constraint::Apply()
1210 ConstraintIter it( std::find( mConstraints->begin(), mConstraints->end(), Dali::Constraint( &constraint ) ) );
1211 if( it != mConstraints->end() )
1213 mConstraints->erase( it );
1218 void Object::RemoveConstraints()
1220 // guard against constraint sending messages during core destruction
1221 if( mConstraints && Stage::IsInstalled() )
1223 // If we have nothing in the scene-graph, just clear constraint containers
1224 const SceneGraph::PropertyOwner* propertyOwner = GetSceneObject();
1225 if ( NULL != propertyOwner )
1227 const ConstraintConstIter endIter = mConstraints->end();
1228 for ( ConstraintIter iter = mConstraints->begin(); endIter != iter; ++iter )
1230 GetImplementation( *iter ).RemoveInternal();
1234 delete mConstraints;
1235 mConstraints = NULL;
1239 void Object::RemoveConstraints( unsigned int tag )
1241 // guard against constraint sending messages during core destruction
1242 if( mConstraints && Stage::IsInstalled() )
1244 ConstraintIter iter( mConstraints->begin() );
1245 while(iter != mConstraints->end() )
1247 ConstraintBase& constraint = GetImplementation( *iter );
1248 if( constraint.GetTag() == tag )
1250 GetImplementation( *iter ).RemoveInternal();
1251 iter = mConstraints->erase( iter );
1259 if ( mConstraints->empty() )
1261 delete mConstraints;
1262 mConstraints = NULL;
1267 void Object::SetTypeInfo( const TypeInfo* typeInfo )
1269 mTypeInfo = typeInfo;
1274 // Notification for observers
1275 for( ConstObserverIter iter = mObservers.Begin(), endIter = mObservers.End(); iter != endIter; ++iter)
1277 (*iter)->ObjectDestroyed(*this);
1280 delete mConstraints;
1281 delete mPropertyNotifications;
1284 CustomPropertyMetadata* Object::FindCustomProperty( Property::Index index ) const
1286 CustomPropertyMetadata* property( NULL );
1287 if ( ( index >= CHILD_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= CHILD_PROPERTY_REGISTRATION_MAX_INDEX ) )
1289 for ( std::size_t arrayIndex = 0; arrayIndex < mCustomProperties.Count(); arrayIndex++ )
1291 CustomPropertyMetadata* custom = static_cast<CustomPropertyMetadata*>( mCustomProperties[ arrayIndex ] );
1292 if( custom->childPropertyIndex == index )
1300 int arrayIndex = index - PROPERTY_CUSTOM_START_INDEX;
1301 if( arrayIndex >= 0 )
1303 if( arrayIndex < (int)mCustomProperties.Count() ) // we can only access the first 2 billion custom properties
1305 property = static_cast<CustomPropertyMetadata*>(mCustomProperties[ arrayIndex ]);
1312 AnimatablePropertyMetadata* Object::FindAnimatableProperty( Property::Index index ) const
1314 for ( int arrayIndex = 0; arrayIndex < (int)mAnimatableProperties.Count(); arrayIndex++ )
1316 AnimatablePropertyMetadata* property = static_cast<AnimatablePropertyMetadata*>( mAnimatableProperties[ arrayIndex ] );
1317 if( property->index == index )
1325 AnimatablePropertyMetadata* Object::RegisterAnimatableProperty(Property::Index index) const
1327 DALI_ASSERT_ALWAYS( (( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ))
1328 && "Property index is out of bounds" );
1330 // check whether the animatable property is registered already, if not then register one.
1331 AnimatablePropertyMetadata* animatableProperty = FindAnimatableProperty( index );
1332 if(!animatableProperty)
1334 const TypeInfo* typeInfo( GetTypeInfo() );
1337 Property::Index basePropertyIndex = typeInfo->GetBasePropertyIndex(index);
1338 if(basePropertyIndex == Property::INVALID_INDEX)
1340 // If the property is not a component of a base property, register the whole property itself.
1341 const std::string& propertyName = typeInfo->GetPropertyName(index);
1342 RegisterSceneGraphProperty(propertyName, index, typeInfo->GetPropertyDefaultValue(index));
1343 AddUniformMapping( index, propertyName );
1347 // Since the property is a component of a base property, check whether the base property is regsitered.
1348 animatableProperty = FindAnimatableProperty( basePropertyIndex );
1349 if(!animatableProperty)
1351 // If the base property is not registered yet, register the base property first.
1352 const std::string& basePropertyName = typeInfo->GetPropertyName(basePropertyIndex);
1353 if(Property::INVALID_INDEX != RegisterSceneGraphProperty(basePropertyName, basePropertyIndex, Property::Value(typeInfo->GetPropertyType(basePropertyIndex))))
1355 animatableProperty = static_cast<AnimatablePropertyMetadata*>(mAnimatableProperties[mAnimatableProperties.Size()-1]);
1356 AddUniformMapping( basePropertyIndex, basePropertyName );
1360 if(animatableProperty)
1362 // Create the metadata for the property component.
1363 mAnimatableProperties.PushBack( new AnimatablePropertyMetadata( index, typeInfo->GetComponentIndex(index), animatableProperty->GetType(), animatableProperty->GetSceneGraphProperty() ) );
1367 // The metadata has just been added and therefore should be in the end of the vector.
1368 animatableProperty = static_cast<AnimatablePropertyMetadata*>(mAnimatableProperties[mAnimatableProperties.Size()-1]);
1372 return animatableProperty;
1375 void Object::ResolveChildProperties()
1377 // Resolve index for the child property
1378 Object* parent = GetParentObject();
1381 const TypeInfo* parentTypeInfo( parent->GetTypeInfo() );
1382 if( parentTypeInfo )
1384 // Go through each custom property
1385 for ( int arrayIndex = 0; arrayIndex < (int)mCustomProperties.Count(); arrayIndex++ )
1387 CustomPropertyMetadata* customProperty = static_cast<CustomPropertyMetadata*>( mCustomProperties[ arrayIndex ] );
1389 if( customProperty->name == "" )
1391 if( customProperty->childPropertyIndex != Property::INVALID_INDEX )
1393 // Resolve name for any child property with no name
1394 customProperty->name = parentTypeInfo->GetChildPropertyName( customProperty->childPropertyIndex );
1399 Property::Index childPropertyIndex = parentTypeInfo->GetChildPropertyIndex( customProperty->name );
1400 if( childPropertyIndex != Property::INVALID_INDEX )
1402 // Resolve index for any property with a name that matches the parent's child property name
1403 customProperty->childPropertyIndex = childPropertyIndex;
1411 } // namespace Internal