2 * Copyright (c) 2018 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/devel-api/object/handle-devel.h>
27 #include <dali/internal/update/animation/scene-graph-constraint-base.h>
28 #include <dali/internal/update/common/animatable-property.h>
29 #include <dali/internal/update/common/property-owner-messages.h>
30 #include <dali/internal/update/common/uniform-map.h>
31 #include <dali/internal/event/animation/constraint-impl.h>
32 #include <dali/internal/event/common/stage-impl.h>
33 #include <dali/internal/event/common/property-notification-impl.h>
34 #include <dali/internal/event/common/type-registry-impl.h>
36 using Dali::Internal::SceneGraph::AnimatableProperty;
37 using Dali::Internal::SceneGraph::PropertyBase;
45 namespace // unnamed namespace
47 const int SUPPORTED_CAPABILITIES = Dali::Handle::DYNAMIC_PROPERTIES; // Object provides this capability
48 typedef Dali::Vector<Object::Observer*>::Iterator ObserverIter;
49 typedef Dali::Vector<Object::Observer*>::ConstIterator ConstObserverIter;
51 #if defined(DEBUG_ENABLED)
52 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_OBJECT" );
56 } // unnamed namespace
59 : mEventThreadServices( *Stage::GetCurrent() ),
62 mPropertyNotifications( NULL )
66 void Object::AddObserver(Observer& observer)
68 // make sure an observer doesn't observe the same object twice
69 // otherwise it will get multiple calls to OnSceneObjectAdd(), OnSceneObjectRemove() and ObjectDestroyed()
70 DALI_ASSERT_DEBUG( mObservers.End() == std::find( mObservers.Begin(), mObservers.End(), &observer));
72 mObservers.PushBack( &observer );
75 void Object::RemoveObserver(Observer& observer)
77 // Find the observer...
78 const ConstObserverIter endIter = mObservers.End();
79 for( ObserverIter iter = mObservers.Begin(); iter != endIter; ++iter)
81 if( (*iter) == &observer)
83 mObservers.Erase( iter );
87 DALI_ASSERT_DEBUG(endIter != mObservers.End());
90 void Object::OnSceneObjectAdd()
92 // Notification for observers
93 for( ConstObserverIter iter = mObservers.Begin(), endIter = mObservers.End(); iter != endIter; ++iter)
95 (*iter)->SceneObjectAdded(*this);
98 // enable property notifications in scene graph
99 EnablePropertyNotifications();
102 void Object::OnSceneObjectRemove()
104 // Notification for observers
105 for( ConstObserverIter iter = mObservers.Begin(), endIter = mObservers.End(); iter != endIter; ++iter )
107 (*iter)->SceneObjectRemoved(*this);
110 // disable property notifications in scene graph
111 DisablePropertyNotifications();
114 int Object::GetPropertyComponentIndex( Property::Index index ) const
116 int componentIndex = Property::INVALID_COMPONENT_INDEX;
118 const TypeInfo* typeInfo( GetTypeInfo() );
121 componentIndex = typeInfo->GetComponentIndex(index);
124 // For animatable property, check whether it is registered already and register it if not yet.
125 if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) && ( NULL == RegisterAnimatableProperty(index) ) )
127 componentIndex = Property::INVALID_COMPONENT_INDEX;
130 return componentIndex;
133 bool Object::Supports( Capability capability ) const
135 return (capability & SUPPORTED_CAPABILITIES);
138 uint32_t Object::GetPropertyCount() const
140 uint32_t count = GetDefaultPropertyCount();
142 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Default Properties: %d\n", count );
144 const TypeInfo* typeInfo( GetTypeInfo() );
147 uint32_t manual( typeInfo->GetPropertyCount() );
150 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Manual Properties: %d\n", manual );
153 uint32_t custom = static_cast<uint32_t>( mCustomProperties.Count() );
155 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Custom Properties: %d\n", custom );
157 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Total Properties: %d\n", count );
162 std::string Object::GetPropertyName( Property::Index index ) const
164 DALI_ASSERT_ALWAYS( index > Property::INVALID_INDEX && "Property index out of bounds" );
166 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
170 const char * propertyName = GetDefaultPropertyName( index );
173 string = propertyName;
178 if ( ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
179 || ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) ) )
181 const TypeInfo* typeInfo( GetTypeInfo() );
184 return typeInfo->GetPropertyName( index );
188 DALI_ASSERT_ALWAYS( ! "Property index is invalid" );
192 CustomPropertyMetadata* custom = FindCustomProperty( index );
200 Property::Index Object::GetPropertyIndex(const std::string& name) const
202 Property::Index index = GetDefaultPropertyIndex( name );
204 if(index == Property::INVALID_INDEX)
206 const TypeInfo* typeInfo( GetTypeInfo() );
209 index = typeInfo->GetPropertyIndex( name );
210 if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
212 // check whether the animatable property is registered already, if not then register one.
213 if ( NULL == RegisterAnimatableProperty(index) )
215 index = Property::INVALID_INDEX;
221 if( (index == Property::INVALID_INDEX)&&( mCustomProperties.Count() > 0 ) )
223 Property::Index count = PROPERTY_CUSTOM_START_INDEX;
224 const PropertyMetadataLookup::ConstIterator end = mCustomProperties.End();
225 for( PropertyMetadataLookup::ConstIterator iter = mCustomProperties.Begin(); iter != end; ++iter, ++count )
227 CustomPropertyMetadata* custom = static_cast<CustomPropertyMetadata*>(*iter);
228 if ( custom->name == name )
230 if ( custom->childPropertyIndex != Property::INVALID_INDEX )
232 // If it is a child property, return the child property index
233 index = custom->childPropertyIndex;
247 Property::Index Object::GetPropertyIndex( Property::Index key ) const
249 Property::Index index = Property::INVALID_INDEX;
251 if( mCustomProperties.Count() > 0 )
253 Property::Index count = PROPERTY_CUSTOM_START_INDEX;
254 const PropertyMetadataLookup::ConstIterator end = mCustomProperties.End();
255 for( PropertyMetadataLookup::ConstIterator iter = mCustomProperties.Begin(); iter != end; ++iter, ++count )
257 CustomPropertyMetadata* custom = static_cast<CustomPropertyMetadata*>(*iter);
258 if( custom->key == key )
260 if( custom->childPropertyIndex != Property::INVALID_INDEX )
262 // If it is a child property, return the child property index
263 index = custom->childPropertyIndex;
277 Property::Index Object::GetPropertyIndex( Property::Key key ) const
279 Property::Index index = Property::INVALID_INDEX;
280 if( key.type == Property::Key::INDEX )
282 index = GetPropertyIndex( key.indexKey );
286 index = GetPropertyIndex( key.stringKey );
291 bool Object::IsPropertyWritable( Property::Index index ) const
293 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds");
295 bool writable = false;
297 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
299 writable = IsDefaultPropertyWritable( index );
301 else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
303 const TypeInfo* typeInfo( GetTypeInfo() );
306 writable = typeInfo->IsPropertyWritable( index );
310 DALI_ASSERT_ALWAYS( ! "Invalid property index" );
313 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
315 // Type Registry scene-graph properties are writable.
320 CustomPropertyMetadata* custom = FindCustomProperty( index );
323 writable = custom->IsWritable();
330 bool Object::IsPropertyAnimatable( Property::Index index ) const
332 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds");
334 bool animatable = false;
336 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
338 animatable = IsDefaultPropertyAnimatable( index );
340 else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
342 // Type Registry event-thread only properties are not animatable.
345 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
347 // Type Registry scene-graph properties are animatable.
352 CustomPropertyMetadata* custom = FindCustomProperty( index );
355 animatable = custom->IsAnimatable();
362 bool Object::IsPropertyAConstraintInput( Property::Index index ) const
364 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds");
366 bool isConstraintInput = false;
368 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
370 isConstraintInput = IsDefaultPropertyAConstraintInput( index );
372 else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
374 // Type Registry event-thread only properties cannot be used as an input to a constraint.
375 isConstraintInput = false;
377 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
379 // scene graph properties can be used as input to a constraint.
380 isConstraintInput = true;
384 CustomPropertyMetadata* custom = FindCustomProperty( index );
387 // ... custom properties can be used as input to a constraint.
388 isConstraintInput = true;
392 return isConstraintInput;
395 Property::Type Object::GetPropertyType( Property::Index index ) const
397 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds" );
399 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
401 return GetDefaultPropertyType( index );
404 if ( ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
405 || ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) ) )
407 const TypeInfo* typeInfo( GetTypeInfo() );
410 return typeInfo->GetPropertyType( index );
414 DALI_ASSERT_ALWAYS( ! "Cannot find property index" );
418 CustomPropertyMetadata* custom = FindCustomProperty( index );
421 return custom->GetType();
424 return Property::NONE;
427 DevelHandle::PropertySetSignalType& Object::PropertySetSignal()
429 return mPropertySetSignal;
432 void Object::SetProperty( Property::Index index, const Property::Value& propertyValue )
434 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds" );
436 bool propertySet( true );
438 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
440 SetDefaultProperty( index, propertyValue );
442 else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
444 const TypeInfo* typeInfo( GetTypeInfo() );
447 typeInfo->SetProperty( this, index, propertyValue );
451 DALI_LOG_ERROR("Cannot find property index\n");
455 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
457 // check whether the animatable property is registered already, if not then register one.
458 AnimatablePropertyMetadata* animatableProperty = RegisterAnimatableProperty( index );
459 if(!animatableProperty)
461 DALI_LOG_ERROR("Cannot find property index\n");
466 // update the cached property value
467 animatableProperty->SetPropertyValue( propertyValue );
469 // set the scene graph property value
470 SetSceneGraphProperty( index, *animatableProperty, propertyValue );
475 CustomPropertyMetadata* custom = FindCustomProperty( index );
477 if ( ( index >= CHILD_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= CHILD_PROPERTY_REGISTRATION_MAX_INDEX ) )
481 // If the child property is not registered yet, register it.
482 custom = new CustomPropertyMetadata( "", propertyValue, Property::READ_WRITE );
483 mCustomProperties.PushBack( custom );
486 custom->childPropertyIndex = index;
488 // Resolve name for the child property
489 Object* parent = GetParentObject();
492 const TypeInfo* parentTypeInfo( parent->GetTypeInfo() );
495 custom->name = parentTypeInfo->GetChildPropertyName( index );
502 if( custom->IsAnimatable() )
504 // update the cached property value
505 custom->SetPropertyValue( propertyValue );
507 // set the scene graph property value
508 SetSceneGraphProperty( index, *custom, propertyValue );
510 else if( custom->IsWritable() )
512 // update the cached property value
513 custom->SetPropertyValue( propertyValue );
517 // trying to set value on read only property is no-op
523 DALI_LOG_ERROR("Invalid property index\n");
528 // Let derived classes know that a property has been set
529 // 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
532 OnPropertySet( index, propertyValue );
533 Dali::Handle handle( this );
534 mPropertySetSignal.Emit( handle, index, propertyValue );
538 Property::Value Object::GetProperty(Property::Index index) const
540 DALI_ASSERT_ALWAYS( index > Property::INVALID_INDEX && "Property index is out of bounds" );
542 Property::Value value;
544 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
546 value = GetDefaultProperty( index );
548 else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
550 const TypeInfo* typeInfo( GetTypeInfo() );
553 value = typeInfo->GetProperty( this, index );
557 DALI_LOG_ERROR("Cannot find property index\n");
560 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
562 // check whether the animatable property is registered already, if not then register one.
563 AnimatablePropertyMetadata* animatableProperty = RegisterAnimatableProperty( index );
564 if(!animatableProperty)
566 DALI_LOG_ERROR("Cannot find property index\n");
570 // get the cached animatable property value
571 value = animatableProperty->GetPropertyValue();
574 else if(mCustomProperties.Count() > 0)
576 CustomPropertyMetadata* custom = FindCustomProperty( index );
579 // get the cached custom property value
580 value = custom->GetPropertyValue();
584 DALI_LOG_ERROR("Invalid property index\n");
591 Property::Value Object::GetCurrentProperty( Property::Index index ) const
593 DALI_ASSERT_ALWAYS( index > Property::INVALID_INDEX && "Property index is out of bounds" );
595 Property::Value value;
597 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
599 value = GetDefaultPropertyCurrentValue( index );
601 else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
603 const TypeInfo* typeInfo( GetTypeInfo() );
606 value = typeInfo->GetProperty( this, index );
610 DALI_LOG_ERROR("Cannot find property index\n");
613 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
615 // check whether the animatable property is registered already, if not then register one.
616 AnimatablePropertyMetadata* animatableProperty = RegisterAnimatableProperty( index );
617 if(!animatableProperty)
619 DALI_LOG_ERROR("Cannot find property index\n");
623 // get the animatable property value
624 value = GetCurrentPropertyValue( animatableProperty );
627 else if(mCustomProperties.Count() > 0)
629 CustomPropertyMetadata* custom = FindCustomProperty( index );
632 // get the custom property value
633 value = GetCurrentPropertyValue( custom );
637 DALI_LOG_ERROR("Invalid property index\n");
644 void Object::GetPropertyIndices( Property::IndexContainer& indices ) const
648 // Default Properties
649 GetDefaultPropertyIndices( indices );
652 const TypeInfo* typeInfo( GetTypeInfo() );
655 typeInfo->GetPropertyIndices( indices );
659 if ( mCustomProperties.Count() > 0 )
661 indices.Reserve( indices.Size() + mCustomProperties.Count() );
663 PropertyMetadataLookup::ConstIterator iter = mCustomProperties.Begin();
664 const PropertyMetadataLookup::ConstIterator endIter = mCustomProperties.End();
666 for ( ; iter != endIter; ++iter, ++i )
668 CustomPropertyMetadata* custom = static_cast<CustomPropertyMetadata*>( *iter );
669 if ( custom->childPropertyIndex != Property::INVALID_INDEX )
671 // If it is a child property, add the child property index
672 indices.PushBack( custom->childPropertyIndex );
676 indices.PushBack( PROPERTY_CUSTOM_START_INDEX + i );
682 bool Object::DoesCustomPropertyExist( Property::Index index )
684 auto metadata = FindCustomProperty( index );
685 return metadata != nullptr;
688 Property::Index Object::RegisterSceneGraphProperty(const std::string& name, Property::Index key, Property::Index index, const Property::Value& propertyValue) const
690 // Create a new property
691 Dali::Internal::OwnerPointer<PropertyBase> newProperty;
693 switch ( propertyValue.GetType() )
695 case Property::BOOLEAN:
697 newProperty = new AnimatableProperty<bool>( propertyValue.Get<bool>() );
701 case Property::INTEGER:
703 newProperty = new AnimatableProperty<int>( propertyValue.Get<int>() );
707 case Property::FLOAT:
709 newProperty = new AnimatableProperty<float>( propertyValue.Get<float>() );
713 case Property::VECTOR2:
715 newProperty = new AnimatableProperty<Vector2>( propertyValue.Get<Vector2>() );
719 case Property::VECTOR3:
721 newProperty = new AnimatableProperty<Vector3>( propertyValue.Get<Vector3>() );
725 case Property::VECTOR4:
727 newProperty = new AnimatableProperty<Vector4>( propertyValue.Get<Vector4>() );
731 case Property::MATRIX:
733 newProperty = new AnimatableProperty<Matrix>( propertyValue.Get<Matrix>() );
737 case Property::MATRIX3:
739 newProperty = new AnimatableProperty<Matrix3>( propertyValue.Get<Matrix3>() );
743 case Property::ROTATION:
745 newProperty = new AnimatableProperty<Quaternion>( propertyValue.Get<Quaternion>() );
749 case Property::RECTANGLE:
750 case Property::STRING:
751 case Property::ARRAY:
753 case Property::EXTENTS:
756 DALI_ASSERT_ALWAYS( !"PropertyType is not animatable" );
761 // get the scene property owner from derived class
762 const SceneGraph::PropertyOwner* scenePropertyOwner = GetPropertyOwner();
763 // we can only pass properties to scene graph side if there is a scene object
764 if( scenePropertyOwner )
766 // keep a local pointer to the property as the OwnerPointer will pass its copy to the message
767 const PropertyBase* property = newProperty.Get();
768 if(index >= PROPERTY_CUSTOM_START_INDEX)
770 DALI_ASSERT_ALWAYS( index <= PROPERTY_CUSTOM_MAX_INDEX && "Too many custom properties have been registered" );
772 mCustomProperties.PushBack( new CustomPropertyMetadata( name, key, propertyValue, property ) );
776 mAnimatableProperties.PushBack( new AnimatablePropertyMetadata( index, propertyValue, property ) );
779 // queue a message to add the property
780 InstallCustomPropertyMessage( const_cast<EventThreadServices&>(GetEventThreadServices()), *scenePropertyOwner, newProperty ); // Message takes ownership
786 // property was orphaned and killed so return invalid index
787 return Property::INVALID_INDEX;
791 Property::Index Object::RegisterProperty( const std::string& name, const Property::Value& propertyValue )
793 return RegisterProperty( name, Property::INVALID_KEY, propertyValue, Property::ANIMATABLE );
796 Property::Index Object::RegisterProperty( const std::string& name, Property::Index key, const Property::Value& propertyValue )
798 return RegisterProperty( name, key, propertyValue, Property::ANIMATABLE );
801 Property::Index Object::RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode )
803 return RegisterProperty( name, Property::INVALID_KEY, propertyValue, accessMode );
806 Property::Index Object::RegisterProperty( const std::string& name, Property::Index key, const Property::Value& propertyValue, Property::AccessMode accessMode )
808 // If property with the required key already exists, then just set it.
809 Property::Index index = Property::INVALID_INDEX;
810 if( key != Property::INVALID_KEY ) // Try integer key first if it's valid
812 index = GetPropertyIndex( key );
814 if( index == Property::INVALID_INDEX ) // If it wasn't valid, or doesn't exist, try name
816 index = GetPropertyIndex( name );
819 if( index != Property::INVALID_INDEX ) // If there was a valid index found by either key, set it.
821 SetProperty( index, propertyValue );
825 // Otherwise register the property
827 if( Property::ANIMATABLE == accessMode )
829 index = RegisterSceneGraphProperty( name, key, PROPERTY_CUSTOM_START_INDEX + static_cast<Property::Index>( mCustomProperties.Count() ), propertyValue );
830 AddUniformMapping( index, name );
834 // Add entry to the property lookup
835 index = PROPERTY_CUSTOM_START_INDEX + static_cast<Property::Index>( mCustomProperties.Count() );
837 CustomPropertyMetadata* customProperty = new CustomPropertyMetadata( name, propertyValue, accessMode );
839 // Resolve index for the child property
840 Object* parent = GetParentObject();
843 const TypeInfo* parentTypeInfo( parent->GetTypeInfo() );
846 Property::Index childPropertyIndex = parentTypeInfo->GetChildPropertyIndex( name );
847 if( childPropertyIndex != Property::INVALID_INDEX )
849 customProperty->childPropertyIndex = childPropertyIndex;
850 index = childPropertyIndex;
855 mCustomProperties.PushBack( customProperty );
862 Dali::PropertyNotification Object::AddPropertyNotification(Property::Index index,
864 const Dali::PropertyCondition& condition)
866 if ( index >= DEFAULT_PROPERTY_MAX_COUNT )
868 if ( index <= PROPERTY_REGISTRATION_MAX_INDEX )
870 DALI_ABORT( "Property notification added to event side only property." );
872 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
874 // check whether the animatable property is registered already, if not then register one.
875 AnimatablePropertyMetadata* animatable = RegisterAnimatableProperty( index );
876 DALI_ASSERT_ALWAYS( animatable && "Property index is invalid" );
878 else if ( mCustomProperties.Count() > 0 )
880 CustomPropertyMetadata* custom = FindCustomProperty( index );
881 DALI_ASSERT_ALWAYS( custom && "Invalid property index" );
882 DALI_ASSERT_ALWAYS( custom->IsAnimatable() && "Property notification added to event side only property." );
886 Dali::Handle self(this);
887 Property target( self, index );
889 PropertyNotificationPtr internal = PropertyNotification::New( target, componentIndex, condition );
890 Dali::PropertyNotification propertyNotification(internal.Get());
892 if( !mPropertyNotifications )
894 mPropertyNotifications = new PropertyNotificationContainer;
896 mPropertyNotifications->push_back(propertyNotification);
898 return propertyNotification;
901 void Object::RemovePropertyNotification(Dali::PropertyNotification propertyNotification)
903 if( mPropertyNotifications )
905 PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
906 while(iter != mPropertyNotifications->end() )
908 if(*iter == propertyNotification)
910 mPropertyNotifications->erase(iter);
911 // As we can't ensure all references are removed, we can just disable
913 GetImplementation(propertyNotification).Disable();
921 void Object::RemovePropertyNotifications()
923 if( mPropertyNotifications )
925 PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
926 while(iter != mPropertyNotifications->end() )
928 // As we can't ensure all references are removed, we can just disable
930 GetImplementation(*iter).Disable();
934 mPropertyNotifications->clear();
938 void Object::NotifyPropertyAnimation( Animation& animation, Property::Index index, const Property::Value& value, Animation::Type animationType )
940 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
942 OnNotifyDefaultPropertyAnimation( animation, index, value, animationType );
946 PropertyMetadata* propertyMetadata = NULL;
947 if( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
949 propertyMetadata = FindAnimatableProperty( index );
953 CustomPropertyMetadata* custom = FindCustomProperty( index );
954 if( custom && custom->IsAnimatable() )
956 propertyMetadata = custom;
960 if( propertyMetadata )
962 switch( animationType )
965 case Animation::BETWEEN:
967 // Update the cached property value
968 propertyMetadata->SetPropertyValue( value );
973 // Adjust the cached property value
974 propertyMetadata->AdjustPropertyValueBy( value );
982 void Object::EnablePropertyNotifications()
984 if( mPropertyNotifications )
986 PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
987 PropertyNotificationContainerIter endIter = mPropertyNotifications->end();
989 for( ; iter != endIter; ++iter )
991 GetImplementation(*iter).Enable();
996 void Object::DisablePropertyNotifications()
998 if( mPropertyNotifications )
1000 PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
1001 PropertyNotificationContainerIter endIter = mPropertyNotifications->end();
1003 for( ; iter != endIter; ++iter )
1005 GetImplementation(*iter).Disable();
1010 void Object::AddUniformMapping( Property::Index propertyIndex, const std::string& uniformName ) const
1012 // Get the address of the property if it's a scene property
1013 const PropertyInputImpl* propertyPtr = GetSceneObjectInputProperty( propertyIndex );
1015 // Check instead for newly registered properties
1016 if( propertyPtr == NULL )
1018 PropertyMetadata* animatable = FindAnimatableProperty( propertyIndex );
1019 if( animatable != NULL )
1021 propertyPtr = animatable->GetSceneGraphProperty();
1025 if( propertyPtr == NULL )
1027 PropertyMetadata* custom = FindCustomProperty( propertyIndex );
1028 if( custom != NULL )
1030 propertyPtr = custom->GetSceneGraphProperty();
1034 if( propertyPtr != NULL )
1036 const SceneGraph::PropertyOwner* sceneObject = GetPropertyOwner();
1038 if( sceneObject != NULL )
1040 OwnerPointer< SceneGraph::UniformPropertyMapping > map = new SceneGraph::UniformPropertyMapping( uniformName, propertyPtr );
1041 // Message takes ownership of Uniform map (and will delete it after copy)
1042 AddUniformMapMessage( const_cast<EventThreadServices&>(GetEventThreadServices()), *sceneObject, map );
1046 DALI_ASSERT_ALWAYS(0 && "MESH_REWORK - Need to store property whilst off-stage" );
1051 void Object::RemoveUniformMapping( const std::string& uniformName )
1053 const SceneGraph::PropertyOwner* sceneObject = GetSceneObject();
1054 RemoveUniformMapMessage( GetEventThreadServices(), *sceneObject, uniformName);
1057 Property::Value Object::GetCurrentPropertyValue( const PropertyMetadata* entry ) const
1059 Property::Value value;
1061 DALI_ASSERT_ALWAYS( entry && "Invalid property metadata" );
1063 if( !entry->IsAnimatable() )
1065 value = entry->GetPropertyValue();
1069 BufferIndex bufferIndex( GetEventThreadServices().GetEventBufferIndex() );
1071 switch ( entry->GetType() )
1073 case Property::BOOLEAN:
1075 const AnimatableProperty<bool>* property = static_cast< const AnimatableProperty<bool>* >( entry->GetSceneGraphProperty() );
1076 DALI_ASSERT_DEBUG( NULL != property );
1078 value = (*property)[ bufferIndex ];
1082 case Property::INTEGER:
1084 const AnimatableProperty<int>* property = static_cast< const AnimatableProperty<int>* >( entry->GetSceneGraphProperty() );
1085 DALI_ASSERT_DEBUG( NULL != property );
1087 value = (*property)[ bufferIndex ];
1091 case Property::FLOAT:
1093 const AnimatableProperty<float>* property = static_cast< const AnimatableProperty<float>* >( entry->GetSceneGraphProperty() );
1094 DALI_ASSERT_DEBUG( NULL != property );
1096 value = (*property)[ bufferIndex ];
1100 case Property::VECTOR2:
1102 const AnimatableProperty<Vector2>* property = static_cast< const AnimatableProperty<Vector2>* >( entry->GetSceneGraphProperty() );
1103 DALI_ASSERT_DEBUG( NULL != property );
1105 if(entry->componentIndex == 0)
1107 value = (*property)[ bufferIndex ].x;
1109 else if(entry->componentIndex == 1)
1111 value = (*property)[ bufferIndex ].y;
1115 value = (*property)[ bufferIndex ];
1120 case Property::VECTOR3:
1122 const AnimatableProperty<Vector3>* property = static_cast< const AnimatableProperty<Vector3>* >( entry->GetSceneGraphProperty() );
1123 DALI_ASSERT_DEBUG( NULL != property );
1125 if(entry->componentIndex == 0)
1127 value = (*property)[ bufferIndex ].x;
1129 else if(entry->componentIndex == 1)
1131 value = (*property)[ bufferIndex ].y;
1133 else if(entry->componentIndex == 2)
1135 value = (*property)[ bufferIndex ].z;
1139 value = (*property)[ bufferIndex ];
1144 case Property::VECTOR4:
1146 const AnimatableProperty<Vector4>* property = static_cast< const AnimatableProperty<Vector4>* >( entry->GetSceneGraphProperty() );
1147 DALI_ASSERT_DEBUG( NULL != property );
1149 if(entry->componentIndex == 0)
1151 value = (*property)[ bufferIndex ].x;
1153 else if(entry->componentIndex == 1)
1155 value = (*property)[ bufferIndex ].y;
1157 else if(entry->componentIndex == 2)
1159 value = (*property)[ bufferIndex ].z;
1161 else if(entry->componentIndex == 3)
1163 value = (*property)[ bufferIndex ].w;
1167 value = (*property)[ bufferIndex ];
1172 case Property::MATRIX:
1174 const AnimatableProperty<Matrix>* property = static_cast< const AnimatableProperty<Matrix>* >( entry->GetSceneGraphProperty() );
1175 DALI_ASSERT_DEBUG( NULL != property );
1177 value = (*property)[ bufferIndex ];
1181 case Property::MATRIX3:
1183 const AnimatableProperty<Matrix3>* property = static_cast< const AnimatableProperty<Matrix3>* >( entry->GetSceneGraphProperty() );
1184 DALI_ASSERT_DEBUG( NULL != property );
1186 value = (*property)[ bufferIndex ];
1190 case Property::ROTATION:
1192 const AnimatableProperty<Quaternion>* property = static_cast< const AnimatableProperty<Quaternion>* >( entry->GetSceneGraphProperty() );
1193 DALI_ASSERT_DEBUG( NULL != property );
1195 value = (*property)[ bufferIndex ];
1201 // unreachable code due to higher level logic
1209 void Object::SetSceneGraphProperty( Property::Index index, const PropertyMetadata& entry, const Property::Value& value )
1211 switch ( entry.GetType() )
1213 case Property::BOOLEAN:
1215 const AnimatableProperty<bool>* property = dynamic_cast< const AnimatableProperty<bool>* >( entry.GetSceneGraphProperty() );
1216 DALI_ASSERT_DEBUG( NULL != property );
1218 // property is being used in a separate thread; queue a message to set the property
1219 BakeMessage<bool>( GetEventThreadServices(), *property, value.Get<bool>() );
1223 case Property::INTEGER:
1225 const AnimatableProperty<int>* property = dynamic_cast< const AnimatableProperty<int>* >( entry.GetSceneGraphProperty() );
1226 DALI_ASSERT_DEBUG( NULL != property );
1228 // property is being used in a separate thread; queue a message to set the property
1229 BakeMessage<int>( GetEventThreadServices(), *property, value.Get<int>() );
1233 case Property::FLOAT:
1235 const AnimatableProperty<float>* property = dynamic_cast< const AnimatableProperty<float>* >( entry.GetSceneGraphProperty() );
1236 DALI_ASSERT_DEBUG( NULL != property );
1238 // property is being used in a separate thread; queue a message to set the property
1239 BakeMessage<float>( GetEventThreadServices(), *property, value.Get<float>() );
1243 case Property::VECTOR2:
1245 const AnimatableProperty<Vector2>* property = dynamic_cast< const AnimatableProperty<Vector2>* >( entry.GetSceneGraphProperty() );
1246 DALI_ASSERT_DEBUG( NULL != property );
1248 // property is being used in a separate thread; queue a message to set the property
1249 if(entry.componentIndex == 0)
1251 SetXComponentMessage<Vector2>( GetEventThreadServices(), *property, value.Get<float>() );
1253 else if(entry.componentIndex == 1)
1255 SetYComponentMessage<Vector2>( GetEventThreadServices(), *property, value.Get<float>() );
1259 BakeMessage<Vector2>( GetEventThreadServices(), *property, value.Get<Vector2>() );
1264 case Property::VECTOR3:
1266 const AnimatableProperty<Vector3>* property = dynamic_cast< const AnimatableProperty<Vector3>* >( entry.GetSceneGraphProperty() );
1267 DALI_ASSERT_DEBUG( NULL != property );
1269 // property is being used in a separate thread; queue a message to set the property
1270 if(entry.componentIndex == 0)
1272 SetXComponentMessage<Vector3>( GetEventThreadServices(), *property, value.Get<float>() );
1274 else if(entry.componentIndex == 1)
1276 SetYComponentMessage<Vector3>( GetEventThreadServices(), *property, value.Get<float>() );
1278 else if(entry.componentIndex == 2)
1280 SetZComponentMessage<Vector3>( GetEventThreadServices(), *property, value.Get<float>() );
1284 BakeMessage<Vector3>( GetEventThreadServices(), *property, value.Get<Vector3>() );
1290 case Property::VECTOR4:
1292 const AnimatableProperty<Vector4>* property = dynamic_cast< const AnimatableProperty<Vector4>* >( entry.GetSceneGraphProperty() );
1293 DALI_ASSERT_DEBUG( NULL != property );
1295 // property is being used in a separate thread; queue a message to set the property
1296 if(entry.componentIndex == 0)
1298 SetXComponentMessage<Vector4>( GetEventThreadServices(), *property, value.Get<float>() );
1300 else if(entry.componentIndex == 1)
1302 SetYComponentMessage<Vector4>( GetEventThreadServices(), *property, value.Get<float>() );
1304 else if(entry.componentIndex == 2)
1306 SetZComponentMessage<Vector4>( GetEventThreadServices(), *property, value.Get<float>() );
1308 else if(entry.componentIndex == 3)
1310 SetWComponentMessage<Vector4>( GetEventThreadServices(), *property, value.Get<float>() );
1314 BakeMessage<Vector4>( GetEventThreadServices(), *property, value.Get<Vector4>() );
1319 case Property::ROTATION:
1321 const AnimatableProperty<Quaternion>* property = dynamic_cast< const AnimatableProperty<Quaternion>* >( entry.GetSceneGraphProperty() );
1322 DALI_ASSERT_DEBUG( NULL != property );
1324 // property is being used in a separate thread; queue a message to set the property
1325 BakeMessage<Quaternion>( GetEventThreadServices(), *property, value.Get<Quaternion>() );
1329 case Property::MATRIX:
1331 const AnimatableProperty<Matrix>* property = dynamic_cast< const AnimatableProperty<Matrix>* >( entry.GetSceneGraphProperty() );
1332 DALI_ASSERT_DEBUG( NULL != property );
1334 // property is being used in a separate thread; queue a message to set the property
1335 BakeMessage<Matrix>( GetEventThreadServices(), *property, value.Get<Matrix>() );
1339 case Property::MATRIX3:
1341 const AnimatableProperty<Matrix3>* property = dynamic_cast< const AnimatableProperty<Matrix3>* >( entry.GetSceneGraphProperty() );
1342 DALI_ASSERT_DEBUG( NULL != property );
1344 // property is being used in a separate thread; queue a message to set the property
1345 BakeMessage<Matrix3>( GetEventThreadServices(), *property, value.Get<Matrix3>() );
1351 // non-animatable scene graph property, do nothing
1356 const TypeInfo* Object::GetTypeInfo() const
1360 // This uses a dynamic_cast so can be quite expensive so we only really want to do it once
1361 // especially as the type-info does not change during the life-time of an application
1363 Dali::TypeInfo typeInfoHandle = TypeRegistry::Get()->GetTypeInfo( this );
1364 if ( typeInfoHandle )
1366 mTypeInfo = &GetImplementation( typeInfoHandle );
1373 void Object::ApplyConstraint( ConstraintBase& constraint )
1377 mConstraints = new ConstraintContainer;
1379 mConstraints->push_back( Dali::Constraint( &constraint ) );
1382 void Object::RemoveConstraint( ConstraintBase& constraint )
1384 // NULL if the Constraint sources are destroyed before Constraint::Apply()
1387 ConstraintIter it( std::find( mConstraints->begin(), mConstraints->end(), Dali::Constraint( &constraint ) ) );
1388 if( it != mConstraints->end() )
1390 mConstraints->erase( it );
1395 void Object::RemoveConstraints()
1397 // guard against constraint sending messages during core destruction
1398 if( mConstraints && Stage::IsInstalled() )
1400 // If we have nothing in the scene-graph, just clear constraint containers
1401 const SceneGraph::PropertyOwner* propertyOwner = GetSceneObject();
1402 if ( NULL != propertyOwner )
1404 const ConstraintConstIter endIter = mConstraints->end();
1405 for ( ConstraintIter iter = mConstraints->begin(); endIter != iter; ++iter )
1407 GetImplementation( *iter ).RemoveInternal();
1411 delete mConstraints;
1412 mConstraints = NULL;
1416 void Object::RemoveConstraints( uint32_t tag )
1418 // guard against constraint sending messages during core destruction
1419 if( mConstraints && Stage::IsInstalled() )
1421 ConstraintIter iter( mConstraints->begin() );
1422 while(iter != mConstraints->end() )
1424 ConstraintBase& constraint = GetImplementation( *iter );
1425 if( constraint.GetTag() == tag )
1427 GetImplementation( *iter ).RemoveInternal();
1428 iter = mConstraints->erase( iter );
1436 if ( mConstraints->empty() )
1438 delete mConstraints;
1439 mConstraints = NULL;
1444 void Object::SetTypeInfo( const TypeInfo* typeInfo )
1446 mTypeInfo = typeInfo;
1451 // Notification for observers
1452 for( ConstObserverIter iter = mObservers.Begin(), endIter = mObservers.End(); iter != endIter; ++iter)
1454 (*iter)->ObjectDestroyed(*this);
1457 delete mConstraints;
1458 delete mPropertyNotifications;
1461 CustomPropertyMetadata* Object::FindCustomProperty( Property::Index index ) const
1463 CustomPropertyMetadata* property( NULL );
1464 if ( ( index >= CHILD_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= CHILD_PROPERTY_REGISTRATION_MAX_INDEX ) )
1466 for ( std::size_t arrayIndex = 0; arrayIndex < mCustomProperties.Count(); arrayIndex++ )
1468 CustomPropertyMetadata* custom = static_cast<CustomPropertyMetadata*>( mCustomProperties[ arrayIndex ] );
1469 if( custom->childPropertyIndex == index )
1477 int arrayIndex = index - PROPERTY_CUSTOM_START_INDEX;
1478 if( arrayIndex >= 0 )
1480 if( arrayIndex < static_cast<int>( mCustomProperties.Count() ) ) // we can only access the first 2 billion custom properties
1482 property = static_cast<CustomPropertyMetadata*>(mCustomProperties[ arrayIndex ]);
1489 AnimatablePropertyMetadata* Object::FindAnimatableProperty( Property::Index index ) const
1491 const PropertyMetadataLookup::SizeType count = mAnimatableProperties.Count();
1492 for ( PropertyMetadataLookup::SizeType arrayIndex = 0; arrayIndex < count; ++arrayIndex )
1494 AnimatablePropertyMetadata* property = static_cast<AnimatablePropertyMetadata*>( mAnimatableProperties[ arrayIndex ] );
1495 if( property->index == index )
1503 AnimatablePropertyMetadata* Object::RegisterAnimatableProperty(Property::Index index) const
1505 DALI_ASSERT_ALWAYS( (( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ))
1506 && "Property index is out of bounds" );
1508 // check whether the animatable property is registered already, if not then register one.
1509 AnimatablePropertyMetadata* animatableProperty = FindAnimatableProperty( index );
1510 if( !animatableProperty )
1512 const TypeInfo* typeInfo( GetTypeInfo() );
1515 Property::Index basePropertyIndex = typeInfo->GetBasePropertyIndex(index);
1516 if( basePropertyIndex == Property::INVALID_INDEX )
1518 // If the property is not a component of a base property, register the whole property itself.
1519 const std::string& propertyName = typeInfo->GetPropertyName(index);
1520 RegisterSceneGraphProperty(propertyName, Property::INVALID_KEY, index, typeInfo->GetPropertyDefaultValue(index));
1521 AddUniformMapping( index, propertyName );
1525 // Since the property is a component of a base property, check whether the base property is registered.
1526 animatableProperty = FindAnimatableProperty( basePropertyIndex );
1527 if( !animatableProperty )
1529 // If the base property is not registered yet, register the base property first.
1530 const std::string& basePropertyName = typeInfo->GetPropertyName(basePropertyIndex);
1532 if( Property::INVALID_INDEX != RegisterSceneGraphProperty( basePropertyName, Property::INVALID_KEY, basePropertyIndex, typeInfo->GetPropertyDefaultValue( basePropertyIndex ) ) )
1534 animatableProperty = static_cast<AnimatablePropertyMetadata*>(mAnimatableProperties[mAnimatableProperties.Size()-1]);
1535 AddUniformMapping( basePropertyIndex, basePropertyName );
1539 if(animatableProperty)
1541 // Create the metadata for the property component.
1542 mAnimatableProperties.PushBack( new AnimatablePropertyMetadata( index, typeInfo->GetComponentIndex(index), animatableProperty->value, animatableProperty->GetSceneGraphProperty() ) );
1546 // The metadata has just been added and therefore should be in the end of the vector.
1547 animatableProperty = static_cast<AnimatablePropertyMetadata*>(mAnimatableProperties[mAnimatableProperties.Size()-1]);
1551 return animatableProperty;
1554 void Object::ResolveChildProperties()
1556 // Resolve index for the child property
1557 Object* parent = GetParentObject();
1560 const TypeInfo* parentTypeInfo( parent->GetTypeInfo() );
1561 if( parentTypeInfo )
1563 // Go through each custom property
1564 const PropertyMetadataLookup::SizeType count = mCustomProperties.Count();
1565 for ( PropertyMetadataLookup::SizeType arrayIndex = 0; arrayIndex < count; ++arrayIndex )
1567 CustomPropertyMetadata* customProperty = static_cast<CustomPropertyMetadata*>( mCustomProperties[ arrayIndex ] );
1569 if( customProperty->name == "" )
1571 if( customProperty->childPropertyIndex != Property::INVALID_INDEX )
1573 // Resolve name for any child property with no name
1574 customProperty->name = parentTypeInfo->GetChildPropertyName( customProperty->childPropertyIndex );
1579 Property::Index childPropertyIndex = parentTypeInfo->GetChildPropertyIndex( customProperty->name );
1580 if( childPropertyIndex != Property::INVALID_INDEX )
1582 // Resolve index for any property with a name that matches the parent's child property name
1583 customProperty->childPropertyIndex = childPropertyIndex;
1591 } // namespace Internal