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 mCustomProperties.PushBack( new CustomPropertyMetadata( name, propertyValue.GetType(), property ) );
655 mAnimatableProperties.PushBack( new AnimatablePropertyMetadata( index, Property::INVALID_COMPONENT_INDEX, propertyValue.GetType(), property ) ); // base property
658 // queue a message to add the property
659 InstallCustomPropertyMessage( const_cast<EventThreadServices&>(GetEventThreadServices()), *scenePropertyOwner, newProperty.Release() ); // Message takes ownership
661 // notify the derived class (optional) method in case it needs to do some more work on the new property
662 // note! have to use the local pointer as OwnerPointer now points to NULL as it handed over its ownership
663 NotifyScenePropertyInstalled( *property, name, index );
669 // property was orphaned and killed so return invalid index
670 return Property::INVALID_INDEX;
674 Property::Index Object::RegisterProperty( const std::string& name, const Property::Value& propertyValue )
676 return RegisterProperty( name, propertyValue, Property::ANIMATABLE );
679 Property::Index Object::RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode )
681 // If property with the required name already exists, then just set it.
682 Property::Index index = GetPropertyIndex( name );
683 if( index != Property::INVALID_INDEX )
685 SetProperty( index, propertyValue );
689 // Otherwise register the property
691 if(Property::ANIMATABLE == accessMode)
693 index = RegisterSceneGraphProperty( name, PROPERTY_CUSTOM_START_INDEX + mCustomProperties.Count(), propertyValue );
694 AddUniformMapping( index, name );
698 // Add entry to the property lookup
699 index = PROPERTY_CUSTOM_START_INDEX + mCustomProperties.Count();
701 CustomPropertyMetadata* customProperty = new CustomPropertyMetadata( name, propertyValue, accessMode );
703 // Resolve index for the child property
704 Object* parent = GetParentObject();
707 const TypeInfo* parentTypeInfo( parent->GetTypeInfo() );
710 Property::Index childPropertyIndex = parentTypeInfo->GetChildPropertyIndex( name );
711 if( childPropertyIndex != Property::INVALID_INDEX )
713 customProperty->childPropertyIndex = childPropertyIndex;
714 index = childPropertyIndex;
719 mCustomProperties.PushBack( customProperty );
726 Dali::PropertyNotification Object::AddPropertyNotification(Property::Index index,
728 const Dali::PropertyCondition& condition)
730 if ( index >= DEFAULT_PROPERTY_MAX_COUNT )
732 if ( index <= PROPERTY_REGISTRATION_MAX_INDEX )
734 DALI_ASSERT_ALWAYS( false && "Property notification added to event side only property." );
736 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
738 // check whether the animatable property is registered already, if not then register one.
739 AnimatablePropertyMetadata* animatable = RegisterAnimatableProperty( index );
740 DALI_ASSERT_ALWAYS( animatable && "Property index is invalid" );
742 else if ( mCustomProperties.Count() > 0 )
744 CustomPropertyMetadata* custom = FindCustomProperty( index );
745 DALI_ASSERT_ALWAYS( custom && "Invalid property index" );
746 DALI_ASSERT_ALWAYS( custom->IsAnimatable() && "Property notification added to event side only property." );
750 Dali::Handle self(this);
751 Property target( self, index );
753 PropertyNotificationPtr internal = PropertyNotification::New( target, componentIndex, condition );
754 Dali::PropertyNotification propertyNotification(internal.Get());
756 if( !mPropertyNotifications )
758 mPropertyNotifications = new PropertyNotificationContainer;
760 mPropertyNotifications->push_back(propertyNotification);
762 return propertyNotification;
765 void Object::RemovePropertyNotification(Dali::PropertyNotification propertyNotification)
767 if( mPropertyNotifications )
769 PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
770 while(iter != mPropertyNotifications->end() )
772 if(*iter == propertyNotification)
774 mPropertyNotifications->erase(iter);
775 // As we can't ensure all references are removed, we can just disable
777 GetImplementation(propertyNotification).Disable();
785 void Object::RemovePropertyNotifications()
787 if( mPropertyNotifications )
789 PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
790 while(iter != mPropertyNotifications->end() )
792 // As we can't ensure all references are removed, we can just disable
794 GetImplementation(*iter).Disable();
798 mPropertyNotifications->clear();
802 void Object::EnablePropertyNotifications()
804 if( mPropertyNotifications )
806 PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
807 PropertyNotificationContainerIter endIter = mPropertyNotifications->end();
809 for( ; iter != endIter; ++iter )
811 GetImplementation(*iter).Enable();
816 void Object::DisablePropertyNotifications()
818 if( mPropertyNotifications )
820 PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
821 PropertyNotificationContainerIter endIter = mPropertyNotifications->end();
823 for( ; iter != endIter; ++iter )
825 GetImplementation(*iter).Disable();
830 void Object::AddUniformMapping( Property::Index propertyIndex, const std::string& uniformName ) const
832 // Get the address of the property if it's a scene property
833 const PropertyInputImpl* propertyPtr = GetSceneObjectInputProperty( propertyIndex );
835 // Check instead for newly registered properties
836 if( propertyPtr == NULL )
838 PropertyMetadata* animatable = FindAnimatableProperty( propertyIndex );
839 if( animatable != NULL )
841 propertyPtr = animatable->GetSceneGraphProperty();
845 if( propertyPtr == NULL )
847 PropertyMetadata* custom = FindCustomProperty( propertyIndex );
850 propertyPtr = custom->GetSceneGraphProperty();
854 if( propertyPtr != NULL )
856 const SceneGraph::PropertyOwner* sceneObject = GetPropertyOwner();
858 if( sceneObject != NULL )
860 SceneGraph::UniformPropertyMapping* map = new SceneGraph::UniformPropertyMapping( uniformName, propertyPtr );
861 // Message takes ownership of Uniform map (and will delete it after copy)
862 AddUniformMapMessage( const_cast<EventThreadServices&>(GetEventThreadServices()), *sceneObject, map);
866 DALI_ASSERT_ALWAYS(0 && "MESH_REWORK - Need to store property whilst off-stage" );
871 void Object::RemoveUniformMapping( const std::string& uniformName )
873 const SceneGraph::PropertyOwner* sceneObject = GetSceneObject();
874 RemoveUniformMapMessage( GetEventThreadServices(), *sceneObject, uniformName);
877 Property::Value Object::GetPropertyValue( const PropertyMetadata* entry ) const
879 Property::Value value;
881 DALI_ASSERT_ALWAYS( entry && "Invalid property metadata" );
883 if( !entry->IsAnimatable() )
885 value = entry->value;
889 BufferIndex bufferIndex( GetEventThreadServices().GetEventBufferIndex() );
891 switch ( entry->GetType() )
893 case Property::BOOLEAN:
895 const AnimatableProperty<bool>* property = static_cast< const AnimatableProperty<bool>* >( entry->GetSceneGraphProperty() );
896 DALI_ASSERT_DEBUG( NULL != property );
898 value = (*property)[ bufferIndex ];
902 case Property::INTEGER:
904 const AnimatableProperty<int>* property = static_cast< const AnimatableProperty<int>* >( entry->GetSceneGraphProperty() );
905 DALI_ASSERT_DEBUG( NULL != property );
907 value = (*property)[ bufferIndex ];
911 case Property::FLOAT:
913 const AnimatableProperty<float>* property = static_cast< const AnimatableProperty<float>* >( entry->GetSceneGraphProperty() );
914 DALI_ASSERT_DEBUG( NULL != property );
916 value = (*property)[ bufferIndex ];
920 case Property::VECTOR2:
922 const AnimatableProperty<Vector2>* property = static_cast< const AnimatableProperty<Vector2>* >( entry->GetSceneGraphProperty() );
923 DALI_ASSERT_DEBUG( NULL != property );
925 if(entry->componentIndex == 0)
927 value = (*property)[ bufferIndex ].x;
929 else if(entry->componentIndex == 1)
931 value = (*property)[ bufferIndex ].y;
935 value = (*property)[ bufferIndex ];
940 case Property::VECTOR3:
942 const AnimatableProperty<Vector3>* property = static_cast< const AnimatableProperty<Vector3>* >( entry->GetSceneGraphProperty() );
943 DALI_ASSERT_DEBUG( NULL != property );
945 if(entry->componentIndex == 0)
947 value = (*property)[ bufferIndex ].x;
949 else if(entry->componentIndex == 1)
951 value = (*property)[ bufferIndex ].y;
953 else if(entry->componentIndex == 2)
955 value = (*property)[ bufferIndex ].z;
959 value = (*property)[ bufferIndex ];
964 case Property::VECTOR4:
966 const AnimatableProperty<Vector4>* property = static_cast< const AnimatableProperty<Vector4>* >( entry->GetSceneGraphProperty() );
967 DALI_ASSERT_DEBUG( NULL != property );
969 if(entry->componentIndex == 0)
971 value = (*property)[ bufferIndex ].x;
973 else if(entry->componentIndex == 1)
975 value = (*property)[ bufferIndex ].y;
977 else if(entry->componentIndex == 2)
979 value = (*property)[ bufferIndex ].z;
981 else if(entry->componentIndex == 3)
983 value = (*property)[ bufferIndex ].w;
987 value = (*property)[ bufferIndex ];
992 case Property::MATRIX:
994 const AnimatableProperty<Matrix>* property = static_cast< const AnimatableProperty<Matrix>* >( entry->GetSceneGraphProperty() );
995 DALI_ASSERT_DEBUG( NULL != property );
997 value = (*property)[ bufferIndex ];
1001 case Property::MATRIX3:
1003 const AnimatableProperty<Matrix3>* property = static_cast< const AnimatableProperty<Matrix3>* >( entry->GetSceneGraphProperty() );
1004 DALI_ASSERT_DEBUG( NULL != property );
1006 value = (*property)[ bufferIndex ];
1010 case Property::ROTATION:
1012 const AnimatableProperty<Quaternion>* property = static_cast< const AnimatableProperty<Quaternion>* >( entry->GetSceneGraphProperty() );
1013 DALI_ASSERT_DEBUG( NULL != property );
1015 value = (*property)[ bufferIndex ];
1021 DALI_ASSERT_ALWAYS( false && "PropertyType enumeration is out of bounds" );
1030 void Object::SetSceneGraphProperty( Property::Index index, const PropertyMetadata& entry, const Property::Value& value )
1032 switch ( entry.GetType() )
1034 case Property::BOOLEAN:
1036 const AnimatableProperty<bool>* property = dynamic_cast< const AnimatableProperty<bool>* >( entry.GetSceneGraphProperty() );
1037 DALI_ASSERT_DEBUG( NULL != property );
1039 // property is being used in a separate thread; queue a message to set the property
1040 BakeMessage<bool>( GetEventThreadServices(), *property, value.Get<bool>() );
1044 case Property::INTEGER:
1046 const AnimatableProperty<int>* property = dynamic_cast< const AnimatableProperty<int>* >( entry.GetSceneGraphProperty() );
1047 DALI_ASSERT_DEBUG( NULL != property );
1049 // property is being used in a separate thread; queue a message to set the property
1050 BakeMessage<int>( GetEventThreadServices(), *property, value.Get<int>() );
1054 case Property::FLOAT:
1056 const AnimatableProperty<float>* property = dynamic_cast< const AnimatableProperty<float>* >( entry.GetSceneGraphProperty() );
1057 DALI_ASSERT_DEBUG( NULL != property );
1059 // property is being used in a separate thread; queue a message to set the property
1060 BakeMessage<float>( GetEventThreadServices(), *property, value.Get<float>() );
1064 case Property::VECTOR2:
1066 const AnimatableProperty<Vector2>* property = dynamic_cast< const AnimatableProperty<Vector2>* >( entry.GetSceneGraphProperty() );
1067 DALI_ASSERT_DEBUG( NULL != property );
1069 // property is being used in a separate thread; queue a message to set the property
1070 if(entry.componentIndex == 0)
1072 SetXComponentMessage<Vector2>( GetEventThreadServices(), *property, value.Get<float>() );
1074 else if(entry.componentIndex == 1)
1076 SetYComponentMessage<Vector2>( GetEventThreadServices(), *property, value.Get<float>() );
1080 BakeMessage<Vector2>( GetEventThreadServices(), *property, value.Get<Vector2>() );
1085 case Property::VECTOR3:
1087 const AnimatableProperty<Vector3>* property = dynamic_cast< const AnimatableProperty<Vector3>* >( entry.GetSceneGraphProperty() );
1088 DALI_ASSERT_DEBUG( NULL != property );
1090 // property is being used in a separate thread; queue a message to set the property
1091 if(entry.componentIndex == 0)
1093 SetXComponentMessage<Vector3>( GetEventThreadServices(), *property, value.Get<float>() );
1095 else if(entry.componentIndex == 1)
1097 SetYComponentMessage<Vector3>( GetEventThreadServices(), *property, value.Get<float>() );
1099 else if(entry.componentIndex == 2)
1101 SetZComponentMessage<Vector3>( GetEventThreadServices(), *property, value.Get<float>() );
1105 BakeMessage<Vector3>( GetEventThreadServices(), *property, value.Get<Vector3>() );
1111 case Property::VECTOR4:
1113 const AnimatableProperty<Vector4>* property = dynamic_cast< const AnimatableProperty<Vector4>* >( entry.GetSceneGraphProperty() );
1114 DALI_ASSERT_DEBUG( NULL != property );
1116 // property is being used in a separate thread; queue a message to set the property
1117 if(entry.componentIndex == 0)
1119 SetXComponentMessage<Vector4>( GetEventThreadServices(), *property, value.Get<float>() );
1121 else if(entry.componentIndex == 1)
1123 SetYComponentMessage<Vector4>( GetEventThreadServices(), *property, value.Get<float>() );
1125 else if(entry.componentIndex == 2)
1127 SetZComponentMessage<Vector4>( GetEventThreadServices(), *property, value.Get<float>() );
1129 else if(entry.componentIndex == 3)
1131 SetWComponentMessage<Vector4>( GetEventThreadServices(), *property, value.Get<float>() );
1135 BakeMessage<Vector4>( GetEventThreadServices(), *property, value.Get<Vector4>() );
1140 case Property::ROTATION:
1142 const AnimatableProperty<Quaternion>* property = dynamic_cast< const AnimatableProperty<Quaternion>* >( entry.GetSceneGraphProperty() );
1143 DALI_ASSERT_DEBUG( NULL != property );
1145 // property is being used in a separate thread; queue a message to set the property
1146 BakeMessage<Quaternion>( GetEventThreadServices(), *property, value.Get<Quaternion>() );
1150 case Property::MATRIX:
1152 const AnimatableProperty<Matrix>* property = dynamic_cast< const AnimatableProperty<Matrix>* >( 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 BakeMessage<Matrix>( GetEventThreadServices(), *property, value.Get<Matrix>() );
1160 case Property::MATRIX3:
1162 const AnimatableProperty<Matrix3>* property = dynamic_cast< const AnimatableProperty<Matrix3>* >( entry.GetSceneGraphProperty() );
1163 DALI_ASSERT_DEBUG( NULL != property );
1165 // property is being used in a separate thread; queue a message to set the property
1166 BakeMessage<Matrix3>( GetEventThreadServices(), *property, value.Get<Matrix3>() );
1172 // non-animatable scene graph property, do nothing
1177 const TypeInfo* Object::GetTypeInfo() const
1181 // This uses a dynamic_cast so can be quite expensive so we only really want to do it once
1182 // especially as the type-info does not change during the life-time of an application
1184 Dali::TypeInfo typeInfoHandle = TypeRegistry::Get()->GetTypeInfo( this );
1185 if ( typeInfoHandle )
1187 mTypeInfo = &GetImplementation( typeInfoHandle );
1194 void Object::ApplyConstraint( ConstraintBase& constraint )
1198 mConstraints = new ConstraintContainer;
1200 mConstraints->push_back( Dali::Constraint( &constraint ) );
1203 void Object::RemoveConstraint( ConstraintBase& constraint )
1205 // NULL if the Constraint sources are destroyed before Constraint::Apply()
1208 ConstraintIter it( std::find( mConstraints->begin(), mConstraints->end(), Dali::Constraint( &constraint ) ) );
1209 if( it != mConstraints->end() )
1211 mConstraints->erase( it );
1216 void Object::RemoveConstraints()
1218 // guard against constraint sending messages during core destruction
1219 if( mConstraints && Stage::IsInstalled() )
1221 // If we have nothing in the scene-graph, just clear constraint containers
1222 const SceneGraph::PropertyOwner* propertyOwner = GetSceneObject();
1223 if ( NULL != propertyOwner )
1225 const ConstraintConstIter endIter = mConstraints->end();
1226 for ( ConstraintIter iter = mConstraints->begin(); endIter != iter; ++iter )
1228 GetImplementation( *iter ).RemoveInternal();
1232 delete mConstraints;
1233 mConstraints = NULL;
1237 void Object::RemoveConstraints( unsigned int tag )
1239 // guard against constraint sending messages during core destruction
1240 if( mConstraints && Stage::IsInstalled() )
1242 ConstraintIter iter( mConstraints->begin() );
1243 while(iter != mConstraints->end() )
1245 ConstraintBase& constraint = GetImplementation( *iter );
1246 if( constraint.GetTag() == tag )
1248 GetImplementation( *iter ).RemoveInternal();
1249 iter = mConstraints->erase( iter );
1257 if ( mConstraints->empty() )
1259 delete mConstraints;
1260 mConstraints = NULL;
1265 void Object::SetTypeInfo( const TypeInfo* typeInfo )
1267 mTypeInfo = typeInfo;
1272 // Notification for observers
1273 for( ConstObserverIter iter = mObservers.Begin(), endIter = mObservers.End(); iter != endIter; ++iter)
1275 (*iter)->ObjectDestroyed(*this);
1278 delete mConstraints;
1279 delete mPropertyNotifications;
1282 CustomPropertyMetadata* Object::FindCustomProperty( Property::Index index ) const
1284 CustomPropertyMetadata* property( NULL );
1286 if ( ( index >= CHILD_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= CHILD_PROPERTY_REGISTRATION_MAX_INDEX ) )
1288 for ( arrayIndex = 0; arrayIndex < (int)mCustomProperties.Count(); arrayIndex++ )
1290 CustomPropertyMetadata* custom = static_cast<CustomPropertyMetadata*>( mCustomProperties[ arrayIndex ] );
1291 if( custom->childPropertyIndex == index )
1299 arrayIndex = index - PROPERTY_CUSTOM_START_INDEX;
1300 if( arrayIndex >= 0 )
1302 if( arrayIndex < (int)mCustomProperties.Count() ) // we can only access the first 2 billion custom properties
1304 property = static_cast<CustomPropertyMetadata*>(mCustomProperties[ arrayIndex ]);
1311 AnimatablePropertyMetadata* Object::FindAnimatableProperty( Property::Index index ) const
1313 for ( int arrayIndex = 0; arrayIndex < (int)mAnimatableProperties.Count(); arrayIndex++ )
1315 AnimatablePropertyMetadata* property = static_cast<AnimatablePropertyMetadata*>( mAnimatableProperties[ arrayIndex ] );
1316 if( property->index == index )
1324 AnimatablePropertyMetadata* Object::RegisterAnimatableProperty(Property::Index index) const
1326 DALI_ASSERT_ALWAYS( (( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ))
1327 && "Property index is out of bounds" );
1329 // check whether the animatable property is registered already, if not then register one.
1330 AnimatablePropertyMetadata* animatableProperty = FindAnimatableProperty( index );
1331 if(!animatableProperty)
1333 const TypeInfo* typeInfo( GetTypeInfo() );
1336 Property::Index basePropertyIndex = typeInfo->GetBasePropertyIndex(index);
1337 if(basePropertyIndex == Property::INVALID_INDEX)
1339 // If the property is not a component of a base property, register the whole property itself.
1340 const std::string& propertyName = typeInfo->GetPropertyName(index);
1341 RegisterSceneGraphProperty(propertyName, index, typeInfo->GetPropertyDefaultValue(index));
1342 AddUniformMapping( index, propertyName );
1346 // Since the property is a component of a base property, check whether the base property is regsitered.
1347 animatableProperty = FindAnimatableProperty( basePropertyIndex );
1348 if(!animatableProperty)
1350 // If the base property is not registered yet, register the base property first.
1351 const std::string& basePropertyName = typeInfo->GetPropertyName(basePropertyIndex);
1352 if(Property::INVALID_INDEX != RegisterSceneGraphProperty(basePropertyName, basePropertyIndex, Property::Value(typeInfo->GetPropertyType(basePropertyIndex))))
1354 animatableProperty = static_cast<AnimatablePropertyMetadata*>(mAnimatableProperties[mAnimatableProperties.Size()-1]);
1355 AddUniformMapping( basePropertyIndex, basePropertyName );
1359 if(animatableProperty)
1361 // Create the metadata for the property component.
1362 mAnimatableProperties.PushBack( new AnimatablePropertyMetadata( index, typeInfo->GetComponentIndex(index), animatableProperty->GetType(), animatableProperty->GetSceneGraphProperty() ) );
1366 // The metadata has just been added and therefore should be in the end of the vector.
1367 animatableProperty = static_cast<AnimatablePropertyMetadata*>(mAnimatableProperties[mAnimatableProperties.Size()-1]);
1371 return animatableProperty;
1374 void Object::ResolveChildProperties()
1376 // Resolve index for the child property
1377 Object* parent = GetParentObject();
1380 const TypeInfo* parentTypeInfo( parent->GetTypeInfo() );
1381 if( parentTypeInfo )
1383 // Go through each custom property
1384 for ( int arrayIndex = 0; arrayIndex < (int)mCustomProperties.Count(); arrayIndex++ )
1386 CustomPropertyMetadata* customProperty = static_cast<CustomPropertyMetadata*>( mCustomProperties[ arrayIndex ] );
1388 if( customProperty->name == "" )
1390 if( customProperty->childPropertyIndex != Property::INVALID_INDEX )
1392 // Resolve name for any child property with no name
1393 customProperty->name = parentTypeInfo->GetChildPropertyName( customProperty->childPropertyIndex );
1398 Property::Index childPropertyIndex = parentTypeInfo->GetChildPropertyIndex( customProperty->name );
1399 if( childPropertyIndex != Property::INVALID_INDEX )
1401 // Resolve index for any property with a name that matches the parent's child property name
1402 customProperty->childPropertyIndex = childPropertyIndex;
1410 } // namespace Internal