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 bool Object::IsPropertyWritable( Property::Index index ) const
278 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds");
280 bool writable = false;
282 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
284 writable = IsDefaultPropertyWritable( index );
286 else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
288 const TypeInfo* typeInfo( GetTypeInfo() );
291 writable = typeInfo->IsPropertyWritable( index );
295 DALI_ASSERT_ALWAYS( ! "Invalid property index" );
298 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
300 // Type Registry scene-graph properties are writable.
305 CustomPropertyMetadata* custom = FindCustomProperty( index );
308 writable = custom->IsWritable();
315 bool Object::IsPropertyAnimatable( Property::Index index ) const
317 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds");
319 bool animatable = false;
321 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
323 animatable = IsDefaultPropertyAnimatable( index );
325 else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
327 // Type Registry event-thread only properties are not animatable.
330 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
332 // Type Registry scene-graph properties are animatable.
337 CustomPropertyMetadata* custom = FindCustomProperty( index );
340 animatable = custom->IsAnimatable();
347 bool Object::IsPropertyAConstraintInput( Property::Index index ) const
349 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds");
351 bool isConstraintInput = false;
353 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
355 isConstraintInput = IsDefaultPropertyAConstraintInput( index );
357 else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
359 // Type Registry event-thread only properties cannot be used as an input to a constraint.
360 isConstraintInput = false;
362 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
364 // scene graph properties can be used as input to a constraint.
365 isConstraintInput = true;
369 CustomPropertyMetadata* custom = FindCustomProperty( index );
372 // ... custom properties can be used as input to a constraint.
373 isConstraintInput = true;
377 return isConstraintInput;
380 Property::Type Object::GetPropertyType( Property::Index index ) const
382 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds" );
384 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
386 return GetDefaultPropertyType( index );
389 if ( ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
390 || ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) ) )
392 const TypeInfo* typeInfo( GetTypeInfo() );
395 return typeInfo->GetPropertyType( index );
399 DALI_ASSERT_ALWAYS( ! "Cannot find property index" );
403 CustomPropertyMetadata* custom = FindCustomProperty( index );
406 return custom->GetType();
409 return Property::NONE;
412 void Object::SetProperty( Property::Index index, const Property::Value& propertyValue )
414 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds" );
416 bool propertySet( true );
418 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
420 SetDefaultProperty( index, propertyValue );
422 else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
424 const TypeInfo* typeInfo( GetTypeInfo() );
427 typeInfo->SetProperty( this, index, propertyValue );
431 DALI_LOG_ERROR("Cannot find property index\n");
435 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
437 // check whether the animatable property is registered already, if not then register one.
438 AnimatablePropertyMetadata* animatableProperty = RegisterAnimatableProperty( index );
439 if(!animatableProperty)
441 DALI_LOG_ERROR("Cannot find property index\n");
446 // set the scene graph property value
447 SetSceneGraphProperty( index, *animatableProperty, propertyValue );
452 CustomPropertyMetadata* custom = FindCustomProperty( index );
454 if ( ( index >= CHILD_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= CHILD_PROPERTY_REGISTRATION_MAX_INDEX ) )
458 // If the child property is not registered yet, register it.
459 custom = new CustomPropertyMetadata( "", propertyValue, Property::READ_WRITE );
460 mCustomProperties.PushBack( custom );
463 custom->childPropertyIndex = index;
465 // Resolve name for the child property
466 Object* parent = GetParentObject();
469 const TypeInfo* parentTypeInfo( parent->GetTypeInfo() );
472 custom->name = parentTypeInfo->GetChildPropertyName( index );
479 if( custom->IsAnimatable() )
481 // set the scene graph property value
482 SetSceneGraphProperty( index, *custom, propertyValue );
484 else if( custom->IsWritable() )
486 custom->value = propertyValue;
490 // trying to set value on read only property is no-op
496 DALI_LOG_ERROR("Invalid property index\n");
501 // Let derived classes know that a property has been set
502 // 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
505 OnPropertySet(index, propertyValue);
509 Property::Value Object::GetProperty(Property::Index index) const
511 DALI_ASSERT_ALWAYS( index > Property::INVALID_INDEX && "Property index is out of bounds" );
513 Property::Value value;
515 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
517 value = GetDefaultProperty( index );
519 else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
521 const TypeInfo* typeInfo( GetTypeInfo() );
524 value = typeInfo->GetProperty( this, index );
528 DALI_LOG_ERROR("Cannot find property index\n");
531 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
533 // check whether the animatable property is registered already, if not then register one.
534 AnimatablePropertyMetadata* animatableProperty = RegisterAnimatableProperty( index );
535 if(!animatableProperty)
537 DALI_LOG_ERROR("Cannot find property index\n");
541 // get the animatable property value
542 value = GetPropertyValue( animatableProperty );
545 else if(mCustomProperties.Count() > 0)
547 CustomPropertyMetadata* custom = FindCustomProperty( index );
550 // get the custom property value
551 value = GetPropertyValue( custom );
555 DALI_LOG_ERROR("Invalid property index\n");
562 void Object::GetPropertyIndices( Property::IndexContainer& indices ) const
566 // Default Properties
567 GetDefaultPropertyIndices( indices );
570 const TypeInfo* typeInfo( GetTypeInfo() );
573 typeInfo->GetPropertyIndices( indices );
577 if ( mCustomProperties.Count() > 0 )
579 indices.Reserve( indices.Size() + mCustomProperties.Count() );
581 PropertyMetadataLookup::ConstIterator iter = mCustomProperties.Begin();
582 const PropertyMetadataLookup::ConstIterator endIter = mCustomProperties.End();
584 for ( ; iter != endIter; ++iter, ++i )
586 CustomPropertyMetadata* custom = static_cast<CustomPropertyMetadata*>( *iter );
587 if ( custom->childPropertyIndex != Property::INVALID_INDEX )
589 // If it is a child property, add the child property index
590 indices.PushBack( custom->childPropertyIndex );
594 indices.PushBack( PROPERTY_CUSTOM_START_INDEX + i );
600 Property::Index Object::RegisterSceneGraphProperty(const std::string& name, Property::Index key, Property::Index index, const Property::Value& propertyValue) const
602 // Create a new property
603 Dali::Internal::OwnerPointer<PropertyBase> newProperty;
605 switch ( propertyValue.GetType() )
607 case Property::BOOLEAN:
609 newProperty = new AnimatableProperty<bool>( propertyValue.Get<bool>() );
613 case Property::INTEGER:
615 newProperty = new AnimatableProperty<int>( propertyValue.Get<int>() );
619 case Property::FLOAT:
621 newProperty = new AnimatableProperty<float>( propertyValue.Get<float>() );
625 case Property::VECTOR2:
627 newProperty = new AnimatableProperty<Vector2>( propertyValue.Get<Vector2>() );
631 case Property::VECTOR3:
633 newProperty = new AnimatableProperty<Vector3>( propertyValue.Get<Vector3>() );
637 case Property::VECTOR4:
639 newProperty = new AnimatableProperty<Vector4>( propertyValue.Get<Vector4>() );
643 case Property::MATRIX:
645 newProperty = new AnimatableProperty<Matrix>( propertyValue.Get<Matrix>() );
649 case Property::MATRIX3:
651 newProperty = new AnimatableProperty<Matrix3>( propertyValue.Get<Matrix3>() );
655 case Property::ROTATION:
657 newProperty = new AnimatableProperty<Quaternion>( propertyValue.Get<Quaternion>() );
661 case Property::RECTANGLE:
662 case Property::STRING:
663 case Property::ARRAY:
667 DALI_ASSERT_ALWAYS( !"PropertyType is not animatable" );
672 // get the scene property owner from derived class
673 const SceneGraph::PropertyOwner* scenePropertyOwner = GetPropertyOwner();
674 // we can only pass properties to scene graph side if there is a scene object
675 if( scenePropertyOwner )
677 // keep a local pointer to the property as the OwnerPointer will pass its copy to the message
678 const PropertyBase* property = newProperty.Get();
679 if(index >= PROPERTY_CUSTOM_START_INDEX)
681 DALI_ASSERT_ALWAYS( index <= PROPERTY_CUSTOM_MAX_INDEX && "Too many custom properties have been registered" );
683 mCustomProperties.PushBack( new CustomPropertyMetadata( name, key, propertyValue.GetType(), property ) );
687 mAnimatableProperties.PushBack( new AnimatablePropertyMetadata( index, Property::INVALID_COMPONENT_INDEX, propertyValue.GetType(), property ) ); // base property
690 // queue a message to add the property
691 InstallCustomPropertyMessage( const_cast<EventThreadServices&>(GetEventThreadServices()), *scenePropertyOwner, newProperty.Release() ); // Message takes ownership
693 // notify the derived class (optional) method in case it needs to do some more work on the new property
694 // note! have to use the local pointer as OwnerPointer now points to NULL as it handed over its ownership
695 NotifyScenePropertyInstalled( *property, name, index );
701 // property was orphaned and killed so return invalid index
702 return Property::INVALID_INDEX;
706 Property::Index Object::RegisterProperty( const std::string& name, const Property::Value& propertyValue )
708 return RegisterProperty( name, Property::INVALID_KEY, propertyValue, Property::ANIMATABLE );
711 Property::Index Object::RegisterProperty( const std::string& name, Property::Index key, const Property::Value& propertyValue )
713 return RegisterProperty( name, key, propertyValue, Property::ANIMATABLE );
716 Property::Index Object::RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode )
718 return RegisterProperty( name, Property::INVALID_KEY, propertyValue, accessMode );
721 Property::Index Object::RegisterProperty( const std::string& name, Property::Index key, const Property::Value& propertyValue, Property::AccessMode accessMode )
723 // If property with the required key already exists, then just set it.
724 Property::Index index = Property::INVALID_INDEX;
725 if( key != Property::INVALID_KEY ) // Try integer key first if it's valid
727 index = GetPropertyIndex( key );
729 if( index == Property::INVALID_INDEX ) // If it wasn't valid, or doesn't exist, try name
731 index = GetPropertyIndex( name );
734 if( index != Property::INVALID_INDEX ) // If there was a valid index found by either key, set it.
736 SetProperty( index, propertyValue );
740 // Otherwise register the property
742 if( Property::ANIMATABLE == accessMode )
744 index = RegisterSceneGraphProperty( name, key, PROPERTY_CUSTOM_START_INDEX + mCustomProperties.Count(), propertyValue );
745 AddUniformMapping( index, name );
749 // Add entry to the property lookup
750 index = PROPERTY_CUSTOM_START_INDEX + mCustomProperties.Count();
752 CustomPropertyMetadata* customProperty = new CustomPropertyMetadata( name, propertyValue, accessMode );
754 // Resolve index for the child property
755 Object* parent = GetParentObject();
758 const TypeInfo* parentTypeInfo( parent->GetTypeInfo() );
761 Property::Index childPropertyIndex = parentTypeInfo->GetChildPropertyIndex( name );
762 if( childPropertyIndex != Property::INVALID_INDEX )
764 customProperty->childPropertyIndex = childPropertyIndex;
765 index = childPropertyIndex;
770 mCustomProperties.PushBack( customProperty );
777 Dali::PropertyNotification Object::AddPropertyNotification(Property::Index index,
779 const Dali::PropertyCondition& condition)
781 if ( index >= DEFAULT_PROPERTY_MAX_COUNT )
783 if ( index <= PROPERTY_REGISTRATION_MAX_INDEX )
785 DALI_ASSERT_ALWAYS( false && "Property notification added to event side only property." );
787 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
789 // check whether the animatable property is registered already, if not then register one.
790 AnimatablePropertyMetadata* animatable = RegisterAnimatableProperty( index );
791 DALI_ASSERT_ALWAYS( animatable && "Property index is invalid" );
793 else if ( mCustomProperties.Count() > 0 )
795 CustomPropertyMetadata* custom = FindCustomProperty( index );
796 DALI_ASSERT_ALWAYS( custom && "Invalid property index" );
797 DALI_ASSERT_ALWAYS( custom->IsAnimatable() && "Property notification added to event side only property." );
801 Dali::Handle self(this);
802 Property target( self, index );
804 PropertyNotificationPtr internal = PropertyNotification::New( target, componentIndex, condition );
805 Dali::PropertyNotification propertyNotification(internal.Get());
807 if( !mPropertyNotifications )
809 mPropertyNotifications = new PropertyNotificationContainer;
811 mPropertyNotifications->push_back(propertyNotification);
813 return propertyNotification;
816 void Object::RemovePropertyNotification(Dali::PropertyNotification propertyNotification)
818 if( mPropertyNotifications )
820 PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
821 while(iter != mPropertyNotifications->end() )
823 if(*iter == propertyNotification)
825 mPropertyNotifications->erase(iter);
826 // As we can't ensure all references are removed, we can just disable
828 GetImplementation(propertyNotification).Disable();
836 void Object::RemovePropertyNotifications()
838 if( mPropertyNotifications )
840 PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
841 while(iter != mPropertyNotifications->end() )
843 // As we can't ensure all references are removed, we can just disable
845 GetImplementation(*iter).Disable();
849 mPropertyNotifications->clear();
853 void Object::EnablePropertyNotifications()
855 if( mPropertyNotifications )
857 PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
858 PropertyNotificationContainerIter endIter = mPropertyNotifications->end();
860 for( ; iter != endIter; ++iter )
862 GetImplementation(*iter).Enable();
867 void Object::DisablePropertyNotifications()
869 if( mPropertyNotifications )
871 PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
872 PropertyNotificationContainerIter endIter = mPropertyNotifications->end();
874 for( ; iter != endIter; ++iter )
876 GetImplementation(*iter).Disable();
881 void Object::AddUniformMapping( Property::Index propertyIndex, const std::string& uniformName ) const
883 // Get the address of the property if it's a scene property
884 const PropertyInputImpl* propertyPtr = GetSceneObjectInputProperty( propertyIndex );
886 // Check instead for newly registered properties
887 if( propertyPtr == NULL )
889 PropertyMetadata* animatable = FindAnimatableProperty( propertyIndex );
890 if( animatable != NULL )
892 propertyPtr = animatable->GetSceneGraphProperty();
896 if( propertyPtr == NULL )
898 PropertyMetadata* custom = FindCustomProperty( propertyIndex );
901 propertyPtr = custom->GetSceneGraphProperty();
905 if( propertyPtr != NULL )
907 const SceneGraph::PropertyOwner* sceneObject = GetPropertyOwner();
909 if( sceneObject != NULL )
911 SceneGraph::UniformPropertyMapping* map = new SceneGraph::UniformPropertyMapping( uniformName, propertyPtr );
912 // Message takes ownership of Uniform map (and will delete it after copy)
913 AddUniformMapMessage( const_cast<EventThreadServices&>(GetEventThreadServices()), *sceneObject, map);
917 DALI_ASSERT_ALWAYS(0 && "MESH_REWORK - Need to store property whilst off-stage" );
922 void Object::RemoveUniformMapping( const std::string& uniformName )
924 const SceneGraph::PropertyOwner* sceneObject = GetSceneObject();
925 RemoveUniformMapMessage( GetEventThreadServices(), *sceneObject, uniformName);
928 Property::Value Object::GetPropertyValue( const PropertyMetadata* entry ) const
930 Property::Value value;
932 DALI_ASSERT_ALWAYS( entry && "Invalid property metadata" );
934 if( !entry->IsAnimatable() )
936 value = entry->value;
940 BufferIndex bufferIndex( GetEventThreadServices().GetEventBufferIndex() );
942 switch ( entry->GetType() )
944 case Property::BOOLEAN:
946 const AnimatableProperty<bool>* property = static_cast< const AnimatableProperty<bool>* >( entry->GetSceneGraphProperty() );
947 DALI_ASSERT_DEBUG( NULL != property );
949 value = (*property)[ bufferIndex ];
953 case Property::INTEGER:
955 const AnimatableProperty<int>* property = static_cast< const AnimatableProperty<int>* >( entry->GetSceneGraphProperty() );
956 DALI_ASSERT_DEBUG( NULL != property );
958 value = (*property)[ bufferIndex ];
962 case Property::FLOAT:
964 const AnimatableProperty<float>* property = static_cast< const AnimatableProperty<float>* >( entry->GetSceneGraphProperty() );
965 DALI_ASSERT_DEBUG( NULL != property );
967 value = (*property)[ bufferIndex ];
971 case Property::VECTOR2:
973 const AnimatableProperty<Vector2>* property = static_cast< const AnimatableProperty<Vector2>* >( entry->GetSceneGraphProperty() );
974 DALI_ASSERT_DEBUG( NULL != property );
976 if(entry->componentIndex == 0)
978 value = (*property)[ bufferIndex ].x;
980 else if(entry->componentIndex == 1)
982 value = (*property)[ bufferIndex ].y;
986 value = (*property)[ bufferIndex ];
991 case Property::VECTOR3:
993 const AnimatableProperty<Vector3>* property = static_cast< const AnimatableProperty<Vector3>* >( entry->GetSceneGraphProperty() );
994 DALI_ASSERT_DEBUG( NULL != property );
996 if(entry->componentIndex == 0)
998 value = (*property)[ bufferIndex ].x;
1000 else if(entry->componentIndex == 1)
1002 value = (*property)[ bufferIndex ].y;
1004 else if(entry->componentIndex == 2)
1006 value = (*property)[ bufferIndex ].z;
1010 value = (*property)[ bufferIndex ];
1015 case Property::VECTOR4:
1017 const AnimatableProperty<Vector4>* property = static_cast< const AnimatableProperty<Vector4>* >( entry->GetSceneGraphProperty() );
1018 DALI_ASSERT_DEBUG( NULL != property );
1020 if(entry->componentIndex == 0)
1022 value = (*property)[ bufferIndex ].x;
1024 else if(entry->componentIndex == 1)
1026 value = (*property)[ bufferIndex ].y;
1028 else if(entry->componentIndex == 2)
1030 value = (*property)[ bufferIndex ].z;
1032 else if(entry->componentIndex == 3)
1034 value = (*property)[ bufferIndex ].w;
1038 value = (*property)[ bufferIndex ];
1043 case Property::MATRIX:
1045 const AnimatableProperty<Matrix>* property = static_cast< const AnimatableProperty<Matrix>* >( entry->GetSceneGraphProperty() );
1046 DALI_ASSERT_DEBUG( NULL != property );
1048 value = (*property)[ bufferIndex ];
1052 case Property::MATRIX3:
1054 const AnimatableProperty<Matrix3>* property = static_cast< const AnimatableProperty<Matrix3>* >( entry->GetSceneGraphProperty() );
1055 DALI_ASSERT_DEBUG( NULL != property );
1057 value = (*property)[ bufferIndex ];
1061 case Property::ROTATION:
1063 const AnimatableProperty<Quaternion>* property = static_cast< const AnimatableProperty<Quaternion>* >( entry->GetSceneGraphProperty() );
1064 DALI_ASSERT_DEBUG( NULL != property );
1066 value = (*property)[ bufferIndex ];
1072 DALI_ASSERT_ALWAYS( false && "PropertyType enumeration is out of bounds" );
1081 void Object::SetSceneGraphProperty( Property::Index index, const PropertyMetadata& entry, const Property::Value& value )
1083 switch ( entry.GetType() )
1085 case Property::BOOLEAN:
1087 const AnimatableProperty<bool>* property = dynamic_cast< const AnimatableProperty<bool>* >( 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 BakeMessage<bool>( GetEventThreadServices(), *property, value.Get<bool>() );
1095 case Property::INTEGER:
1097 const AnimatableProperty<int>* property = dynamic_cast< const AnimatableProperty<int>* >( entry.GetSceneGraphProperty() );
1098 DALI_ASSERT_DEBUG( NULL != property );
1100 // property is being used in a separate thread; queue a message to set the property
1101 BakeMessage<int>( GetEventThreadServices(), *property, value.Get<int>() );
1105 case Property::FLOAT:
1107 const AnimatableProperty<float>* property = dynamic_cast< const AnimatableProperty<float>* >( entry.GetSceneGraphProperty() );
1108 DALI_ASSERT_DEBUG( NULL != property );
1110 // property is being used in a separate thread; queue a message to set the property
1111 BakeMessage<float>( GetEventThreadServices(), *property, value.Get<float>() );
1115 case Property::VECTOR2:
1117 const AnimatableProperty<Vector2>* property = dynamic_cast< const AnimatableProperty<Vector2>* >( entry.GetSceneGraphProperty() );
1118 DALI_ASSERT_DEBUG( NULL != property );
1120 // property is being used in a separate thread; queue a message to set the property
1121 if(entry.componentIndex == 0)
1123 SetXComponentMessage<Vector2>( GetEventThreadServices(), *property, value.Get<float>() );
1125 else if(entry.componentIndex == 1)
1127 SetYComponentMessage<Vector2>( GetEventThreadServices(), *property, value.Get<float>() );
1131 BakeMessage<Vector2>( GetEventThreadServices(), *property, value.Get<Vector2>() );
1136 case Property::VECTOR3:
1138 const AnimatableProperty<Vector3>* property = dynamic_cast< const AnimatableProperty<Vector3>* >( entry.GetSceneGraphProperty() );
1139 DALI_ASSERT_DEBUG( NULL != property );
1141 // property is being used in a separate thread; queue a message to set the property
1142 if(entry.componentIndex == 0)
1144 SetXComponentMessage<Vector3>( GetEventThreadServices(), *property, value.Get<float>() );
1146 else if(entry.componentIndex == 1)
1148 SetYComponentMessage<Vector3>( GetEventThreadServices(), *property, value.Get<float>() );
1150 else if(entry.componentIndex == 2)
1152 SetZComponentMessage<Vector3>( GetEventThreadServices(), *property, value.Get<float>() );
1156 BakeMessage<Vector3>( GetEventThreadServices(), *property, value.Get<Vector3>() );
1162 case Property::VECTOR4:
1164 const AnimatableProperty<Vector4>* property = dynamic_cast< const AnimatableProperty<Vector4>* >( 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 if(entry.componentIndex == 0)
1170 SetXComponentMessage<Vector4>( GetEventThreadServices(), *property, value.Get<float>() );
1172 else if(entry.componentIndex == 1)
1174 SetYComponentMessage<Vector4>( GetEventThreadServices(), *property, value.Get<float>() );
1176 else if(entry.componentIndex == 2)
1178 SetZComponentMessage<Vector4>( GetEventThreadServices(), *property, value.Get<float>() );
1180 else if(entry.componentIndex == 3)
1182 SetWComponentMessage<Vector4>( GetEventThreadServices(), *property, value.Get<float>() );
1186 BakeMessage<Vector4>( GetEventThreadServices(), *property, value.Get<Vector4>() );
1191 case Property::ROTATION:
1193 const AnimatableProperty<Quaternion>* property = dynamic_cast< const AnimatableProperty<Quaternion>* >( entry.GetSceneGraphProperty() );
1194 DALI_ASSERT_DEBUG( NULL != property );
1196 // property is being used in a separate thread; queue a message to set the property
1197 BakeMessage<Quaternion>( GetEventThreadServices(), *property, value.Get<Quaternion>() );
1201 case Property::MATRIX:
1203 const AnimatableProperty<Matrix>* property = dynamic_cast< const AnimatableProperty<Matrix>* >( entry.GetSceneGraphProperty() );
1204 DALI_ASSERT_DEBUG( NULL != property );
1206 // property is being used in a separate thread; queue a message to set the property
1207 BakeMessage<Matrix>( GetEventThreadServices(), *property, value.Get<Matrix>() );
1211 case Property::MATRIX3:
1213 const AnimatableProperty<Matrix3>* property = dynamic_cast< const AnimatableProperty<Matrix3>* >( entry.GetSceneGraphProperty() );
1214 DALI_ASSERT_DEBUG( NULL != property );
1216 // property is being used in a separate thread; queue a message to set the property
1217 BakeMessage<Matrix3>( GetEventThreadServices(), *property, value.Get<Matrix3>() );
1223 // non-animatable scene graph property, do nothing
1228 const TypeInfo* Object::GetTypeInfo() const
1232 // This uses a dynamic_cast so can be quite expensive so we only really want to do it once
1233 // especially as the type-info does not change during the life-time of an application
1235 Dali::TypeInfo typeInfoHandle = TypeRegistry::Get()->GetTypeInfo( this );
1236 if ( typeInfoHandle )
1238 mTypeInfo = &GetImplementation( typeInfoHandle );
1245 void Object::ApplyConstraint( ConstraintBase& constraint )
1249 mConstraints = new ConstraintContainer;
1251 mConstraints->push_back( Dali::Constraint( &constraint ) );
1254 void Object::RemoveConstraint( ConstraintBase& constraint )
1256 // NULL if the Constraint sources are destroyed before Constraint::Apply()
1259 ConstraintIter it( std::find( mConstraints->begin(), mConstraints->end(), Dali::Constraint( &constraint ) ) );
1260 if( it != mConstraints->end() )
1262 mConstraints->erase( it );
1267 void Object::RemoveConstraints()
1269 // guard against constraint sending messages during core destruction
1270 if( mConstraints && Stage::IsInstalled() )
1272 // If we have nothing in the scene-graph, just clear constraint containers
1273 const SceneGraph::PropertyOwner* propertyOwner = GetSceneObject();
1274 if ( NULL != propertyOwner )
1276 const ConstraintConstIter endIter = mConstraints->end();
1277 for ( ConstraintIter iter = mConstraints->begin(); endIter != iter; ++iter )
1279 GetImplementation( *iter ).RemoveInternal();
1283 delete mConstraints;
1284 mConstraints = NULL;
1288 void Object::RemoveConstraints( unsigned int tag )
1290 // guard against constraint sending messages during core destruction
1291 if( mConstraints && Stage::IsInstalled() )
1293 ConstraintIter iter( mConstraints->begin() );
1294 while(iter != mConstraints->end() )
1296 ConstraintBase& constraint = GetImplementation( *iter );
1297 if( constraint.GetTag() == tag )
1299 GetImplementation( *iter ).RemoveInternal();
1300 iter = mConstraints->erase( iter );
1308 if ( mConstraints->empty() )
1310 delete mConstraints;
1311 mConstraints = NULL;
1316 void Object::SetTypeInfo( const TypeInfo* typeInfo )
1318 mTypeInfo = typeInfo;
1323 // Notification for observers
1324 for( ConstObserverIter iter = mObservers.Begin(), endIter = mObservers.End(); iter != endIter; ++iter)
1326 (*iter)->ObjectDestroyed(*this);
1329 delete mConstraints;
1330 delete mPropertyNotifications;
1333 CustomPropertyMetadata* Object::FindCustomProperty( Property::Index index ) const
1335 CustomPropertyMetadata* property( NULL );
1336 if ( ( index >= CHILD_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= CHILD_PROPERTY_REGISTRATION_MAX_INDEX ) )
1338 for ( std::size_t arrayIndex = 0; arrayIndex < mCustomProperties.Count(); arrayIndex++ )
1340 CustomPropertyMetadata* custom = static_cast<CustomPropertyMetadata*>( mCustomProperties[ arrayIndex ] );
1341 if( custom->childPropertyIndex == index )
1349 int arrayIndex = index - PROPERTY_CUSTOM_START_INDEX;
1350 if( arrayIndex >= 0 )
1352 if( arrayIndex < (int)mCustomProperties.Count() ) // we can only access the first 2 billion custom properties
1354 property = static_cast<CustomPropertyMetadata*>(mCustomProperties[ arrayIndex ]);
1361 AnimatablePropertyMetadata* Object::FindAnimatableProperty( Property::Index index ) const
1363 for ( int arrayIndex = 0; arrayIndex < (int)mAnimatableProperties.Count(); arrayIndex++ )
1365 AnimatablePropertyMetadata* property = static_cast<AnimatablePropertyMetadata*>( mAnimatableProperties[ arrayIndex ] );
1366 if( property->index == index )
1374 AnimatablePropertyMetadata* Object::RegisterAnimatableProperty(Property::Index index) const
1376 DALI_ASSERT_ALWAYS( (( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ))
1377 && "Property index is out of bounds" );
1379 // check whether the animatable property is registered already, if not then register one.
1380 AnimatablePropertyMetadata* animatableProperty = FindAnimatableProperty( index );
1381 if( !animatableProperty )
1383 const TypeInfo* typeInfo( GetTypeInfo() );
1386 Property::Index basePropertyIndex = typeInfo->GetBasePropertyIndex(index);
1387 if( basePropertyIndex == Property::INVALID_INDEX )
1389 // If the property is not a component of a base property, register the whole property itself.
1390 const std::string& propertyName = typeInfo->GetPropertyName(index);
1391 RegisterSceneGraphProperty(propertyName, Property::INVALID_KEY, index, typeInfo->GetPropertyDefaultValue(index));
1392 AddUniformMapping( index, propertyName );
1396 // Since the property is a component of a base property, check whether the base property is registered.
1397 animatableProperty = FindAnimatableProperty( basePropertyIndex );
1398 if( !animatableProperty )
1400 // If the base property is not registered yet, register the base property first.
1401 const std::string& basePropertyName = typeInfo->GetPropertyName(basePropertyIndex);
1403 if( Property::INVALID_INDEX != RegisterSceneGraphProperty( basePropertyName, Property::INVALID_KEY, basePropertyIndex, Property::Value(typeInfo->GetPropertyType( basePropertyIndex ) ) ) )
1405 animatableProperty = static_cast<AnimatablePropertyMetadata*>(mAnimatableProperties[mAnimatableProperties.Size()-1]);
1406 AddUniformMapping( basePropertyIndex, basePropertyName );
1410 if(animatableProperty)
1412 // Create the metadata for the property component.
1413 mAnimatableProperties.PushBack( new AnimatablePropertyMetadata( index, typeInfo->GetComponentIndex(index), animatableProperty->GetType(), animatableProperty->GetSceneGraphProperty() ) );
1417 // The metadata has just been added and therefore should be in the end of the vector.
1418 animatableProperty = static_cast<AnimatablePropertyMetadata*>(mAnimatableProperties[mAnimatableProperties.Size()-1]);
1422 return animatableProperty;
1425 void Object::ResolveChildProperties()
1427 // Resolve index for the child property
1428 Object* parent = GetParentObject();
1431 const TypeInfo* parentTypeInfo( parent->GetTypeInfo() );
1432 if( parentTypeInfo )
1434 // Go through each custom property
1435 for ( int arrayIndex = 0; arrayIndex < (int)mCustomProperties.Count(); arrayIndex++ )
1437 CustomPropertyMetadata* customProperty = static_cast<CustomPropertyMetadata*>( mCustomProperties[ arrayIndex ] );
1439 if( customProperty->name == "" )
1441 if( customProperty->childPropertyIndex != Property::INVALID_INDEX )
1443 // Resolve name for any child property with no name
1444 customProperty->name = parentTypeInfo->GetChildPropertyName( customProperty->childPropertyIndex );
1449 Property::Index childPropertyIndex = parentTypeInfo->GetChildPropertyIndex( customProperty->name );
1450 if( childPropertyIndex != Property::INVALID_INDEX )
1452 // Resolve index for any property with a name that matches the parent's child property name
1453 customProperty->childPropertyIndex = childPropertyIndex;
1461 } // namespace Internal