2 * Copyright (c) 2015 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/event/animation/constraint-impl.h>
30 #include <dali/internal/event/common/stage-impl.h>
31 #include <dali/internal/event/common/property-notification-impl.h>
32 #include <dali/internal/event/common/type-registry-impl.h>
34 using Dali::Internal::SceneGraph::AnimatableProperty;
35 using Dali::Internal::SceneGraph::PropertyBase;
43 namespace // unnamed namespace
45 const int SUPPORTED_CAPABILITIES = Dali::Handle::DYNAMIC_PROPERTIES; // Object provides this capability
46 typedef Dali::Vector<Object::Observer*>::Iterator ObserverIter;
47 typedef Dali::Vector<Object::Observer*>::ConstIterator ConstObserverIter;
49 #if defined(DEBUG_ENABLED)
50 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_OBJECT" );
52 } // unnamed namespace
55 : mEventThreadServices( *Stage::GetCurrent() ),
58 mPropertyNotifications( NULL )
62 void Object::AddObserver(Observer& observer)
64 // make sure an observer doesn't observe the same object twice
65 // otherwise it will get multiple calls to OnSceneObjectAdd(), OnSceneObjectRemove() and ObjectDestroyed()
66 DALI_ASSERT_DEBUG( mObservers.End() == std::find( mObservers.Begin(), mObservers.End(), &observer));
68 mObservers.PushBack( &observer );
71 void Object::RemoveObserver(Observer& observer)
73 // Find the observer...
74 const ConstObserverIter endIter = mObservers.End();
75 for( ObserverIter iter = mObservers.Begin(); iter != endIter; ++iter)
77 if( (*iter) == &observer)
79 mObservers.Erase( iter );
83 DALI_ASSERT_DEBUG(endIter != mObservers.End());
86 void Object::OnSceneObjectAdd()
88 // Notification for observers
89 for( ConstObserverIter iter = mObservers.Begin(), endIter = mObservers.End(); iter != endIter; ++iter)
91 (*iter)->SceneObjectAdded(*this);
94 // enable property notifications in scene graph
95 EnablePropertyNotifications();
98 void Object::OnSceneObjectRemove()
100 // Notification for observers
101 for( ConstObserverIter iter = mObservers.Begin(), endIter = mObservers.End(); iter != endIter; ++iter )
103 (*iter)->SceneObjectRemoved(*this);
106 // disable property notifications in scene graph
107 DisablePropertyNotifications();
110 int Object::GetPropertyComponentIndex( Property::Index index ) const
112 int componentIndex = Property::INVALID_COMPONENT_INDEX;
114 const TypeInfo* typeInfo( GetTypeInfo() );
117 componentIndex = typeInfo->GetComponentIndex(index);
120 // For animatable property, check whether it is registered already and register it if not yet.
121 if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) && ( NULL == RegisterAnimatableProperty(index) ) )
123 componentIndex = Property::INVALID_COMPONENT_INDEX;
126 return componentIndex;
129 bool Object::Supports( Capability capability ) const
131 return (capability & SUPPORTED_CAPABILITIES);
134 unsigned int Object::GetPropertyCount() const
136 unsigned int count = GetDefaultPropertyCount();
138 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Default Properties: %d\n", count );
140 const TypeInfo* typeInfo( GetTypeInfo() );
143 unsigned int manual( typeInfo->GetPropertyCount() );
146 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Manual Properties: %d\n", manual );
149 unsigned int custom( mCustomProperties.Count() );
151 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Custom Properties: %d\n", custom );
153 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Total Properties: %d\n", count );
158 std::string Object::GetPropertyName( Property::Index index ) const
160 DALI_ASSERT_ALWAYS( index > Property::INVALID_INDEX && "Property index out of bounds" );
162 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
164 return GetDefaultPropertyName( index );
167 if ( ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
168 || ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) ) )
170 const TypeInfo* typeInfo( GetTypeInfo() );
173 return typeInfo->GetPropertyName( index );
177 DALI_ASSERT_ALWAYS( ! "Property index is invalid" );
181 CustomPropertyMetadata* custom = FindCustomProperty( index );
189 Property::Index Object::GetPropertyIndex(const std::string& name) const
191 Property::Index index = GetDefaultPropertyIndex( name );
193 if(index == Property::INVALID_INDEX)
195 const TypeInfo* typeInfo( GetTypeInfo() );
198 index = typeInfo->GetPropertyIndex( name );
199 if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
201 // check whether the animatable property is registered already, if not then register one.
202 if ( NULL == RegisterAnimatableProperty(index) )
204 index = Property::INVALID_INDEX;
210 if( (index == Property::INVALID_INDEX)&&( mCustomProperties.Count() > 0 ) )
212 Property::Index count = PROPERTY_CUSTOM_START_INDEX;
213 const PropertyMetadataLookup::ConstIterator end = mCustomProperties.End();
214 for( PropertyMetadataLookup::ConstIterator iter = mCustomProperties.Begin(); iter != end; ++iter, ++count )
216 CustomPropertyMetadata* custom = static_cast<CustomPropertyMetadata*>(*iter);
217 if ( custom->name == name )
228 bool Object::IsPropertyWritable( Property::Index index ) const
230 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds");
232 bool writable = false;
234 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
236 writable = IsDefaultPropertyWritable( index );
238 else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
240 const TypeInfo* typeInfo( GetTypeInfo() );
243 writable = typeInfo->IsPropertyWritable( index );
247 DALI_ASSERT_ALWAYS( ! "Invalid property index" );
250 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
252 // Type Registry scene-graph properties are writable.
257 CustomPropertyMetadata* custom = FindCustomProperty( index );
260 writable = custom->IsWritable();
267 bool Object::IsPropertyAnimatable( Property::Index index ) const
269 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds");
271 bool animatable = false;
273 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
275 animatable = IsDefaultPropertyAnimatable( index );
277 else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
279 // Type Registry event-thread only properties are not animatable.
282 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
284 // Type Registry scene-graph properties are animatable.
289 CustomPropertyMetadata* custom = FindCustomProperty( index );
292 animatable = custom->IsAnimatable();
299 bool Object::IsPropertyAConstraintInput( Property::Index index ) const
301 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds");
303 bool isConstraintInput = false;
305 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
307 isConstraintInput = IsDefaultPropertyAConstraintInput( index );
309 else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
311 // Type Registry event-thread only properties cannot be used as an input to a constraint.
312 isConstraintInput = false;
314 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
316 // scene graph properties can be used as input to a constraint.
317 isConstraintInput = true;
321 CustomPropertyMetadata* custom = FindCustomProperty( index );
324 // ... custom properties can be used as input to a constraint.
325 isConstraintInput = true;
329 return isConstraintInput;
332 Property::Type Object::GetPropertyType( Property::Index index ) const
334 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds" );
336 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
338 return GetDefaultPropertyType( index );
341 if ( ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
342 || ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) ) )
344 const TypeInfo* typeInfo( GetTypeInfo() );
347 return typeInfo->GetPropertyType( index );
351 DALI_ASSERT_ALWAYS( ! "Cannot find property index" );
355 CustomPropertyMetadata* custom = FindCustomProperty( index );
360 return Property::NONE;
363 void Object::SetProperty( Property::Index index, const Property::Value& propertyValue )
365 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds" );
367 bool propertySet( true );
369 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
371 SetDefaultProperty( index, propertyValue );
373 else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
375 const TypeInfo* typeInfo( GetTypeInfo() );
378 typeInfo->SetProperty( this, index, propertyValue );
382 DALI_LOG_ERROR("Cannot find property index\n");
386 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
388 // check whether the animatable property is registered already, if not then register one.
389 AnimatablePropertyMetadata* animatableProperty = RegisterAnimatableProperty( index );
390 if(!animatableProperty)
392 DALI_LOG_ERROR("Cannot find property index\n");
397 // set the scene graph property value
398 SetSceneGraphProperty( index, *animatableProperty, propertyValue );
403 CustomPropertyMetadata* custom = FindCustomProperty( index );
406 if( custom->IsAnimatable() )
408 // set the scene graph property value
409 SetSceneGraphProperty( index, *custom, propertyValue );
411 else if( custom->IsWritable() )
413 custom->value = propertyValue;
417 // trying to set value on read only property is no-op
423 DALI_LOG_ERROR("Invalid property index\n");
428 // Let derived classes know that a property has been set
429 // 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
432 OnPropertySet(index, propertyValue);
436 Property::Value Object::GetProperty(Property::Index index) const
438 DALI_ASSERT_ALWAYS( index > Property::INVALID_INDEX && "Property index is out of bounds" );
440 Property::Value value;
442 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
444 value = GetDefaultProperty( index );
446 else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
448 const TypeInfo* typeInfo( GetTypeInfo() );
451 value = typeInfo->GetProperty( this, index );
455 DALI_LOG_ERROR("Cannot find property index\n");
458 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
460 // check whether the animatable property is registered already, if not then register one.
461 AnimatablePropertyMetadata* animatableProperty = RegisterAnimatableProperty( index );
462 if(!animatableProperty)
464 DALI_LOG_ERROR("Cannot find property index\n");
468 // get the animatable property value
469 value = GetPropertyValue( animatableProperty );
472 else if(mCustomProperties.Count() > 0)
474 CustomPropertyMetadata* custom = FindCustomProperty( index );
477 // get the custom property value
478 value = GetPropertyValue( custom );
482 DALI_LOG_ERROR("Invalid property index\n");
489 void Object::GetPropertyIndices( Property::IndexContainer& indices ) const
493 // Default Properties
494 GetDefaultPropertyIndices( indices );
497 const TypeInfo* typeInfo( GetTypeInfo() );
500 typeInfo->GetPropertyIndices( indices );
504 if ( mCustomProperties.Count() > 0 )
506 indices.Reserve( indices.Size() + mCustomProperties.Count() );
508 PropertyMetadataLookup::ConstIterator iter = mCustomProperties.Begin();
509 const PropertyMetadataLookup::ConstIterator endIter = mCustomProperties.End();
511 for ( ; iter != endIter; ++iter, ++i )
513 indices.PushBack( PROPERTY_CUSTOM_START_INDEX + i );
518 Property::Index Object::RegisterSceneGraphProperty(const std::string& name, Property::Index index, const Property::Value& propertyValue) const
520 // Create a new property
521 Dali::Internal::OwnerPointer<PropertyBase> newProperty;
523 switch ( propertyValue.GetType() )
525 case Property::BOOLEAN:
527 newProperty = new AnimatableProperty<bool>( propertyValue.Get<bool>() );
531 case Property::INTEGER:
533 newProperty = new AnimatableProperty<int>( propertyValue.Get<int>() );
537 case Property::UNSIGNED_INTEGER:
539 newProperty = new AnimatableProperty<unsigned int>( propertyValue.Get<unsigned int>() );
543 case Property::FLOAT:
545 newProperty = new AnimatableProperty<float>( propertyValue.Get<float>() );
549 case Property::VECTOR2:
551 newProperty = new AnimatableProperty<Vector2>( propertyValue.Get<Vector2>() );
555 case Property::VECTOR3:
557 newProperty = new AnimatableProperty<Vector3>( propertyValue.Get<Vector3>() );
561 case Property::VECTOR4:
563 newProperty = new AnimatableProperty<Vector4>( propertyValue.Get<Vector4>() );
567 case Property::MATRIX:
569 newProperty = new AnimatableProperty<Matrix>( propertyValue.Get<Matrix>() );
573 case Property::MATRIX3:
575 newProperty = new AnimatableProperty<Matrix3>( propertyValue.Get<Matrix3>() );
579 case Property::ROTATION:
581 newProperty = new AnimatableProperty<Quaternion>( propertyValue.Get<Quaternion>() );
585 case Property::RECTANGLE:
586 case Property::STRING:
587 case Property::ARRAY:
590 case Property::TYPE_COUNT:
592 DALI_ASSERT_ALWAYS( !"PropertyType is not animatable" );
597 // get the scene property owner from derived class
598 const SceneGraph::PropertyOwner* scenePropertyOwner = GetPropertyOwner();
599 // we can only pass properties to scene graph side if there is a scene object
600 if( scenePropertyOwner )
602 // keep a local pointer to the property as the OwnerPointer will pass its copy to the message
603 const PropertyBase* property = newProperty.Get();
604 if(index >= PROPERTY_CUSTOM_START_INDEX)
606 mCustomProperties.PushBack( new CustomPropertyMetadata( name, propertyValue.GetType(), property ) );
610 mAnimatableProperties.PushBack( new AnimatablePropertyMetadata( index, Property::INVALID_COMPONENT_INDEX, propertyValue.GetType(), property ) ); // base property
613 // queue a message to add the property
614 InstallCustomPropertyMessage( const_cast<EventThreadServices&>(GetEventThreadServices()), *scenePropertyOwner, newProperty.Release() ); // Message takes ownership
616 // notify the derived class (optional) method in case it needs to do some more work on the new property
617 // note! have to use the local pointer as OwnerPointer now points to NULL as it handed over its ownership
618 NotifyScenePropertyInstalled( *property, name, index );
624 // property was orphaned and killed so return invalid index
625 return Property::INVALID_INDEX;
629 Property::Index Object::RegisterProperty( const std::string& name, const Property::Value& propertyValue)
631 return RegisterSceneGraphProperty(name, PROPERTY_CUSTOM_START_INDEX + mCustomProperties.Count(), propertyValue);
634 Property::Index Object::RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode)
636 Property::Index index = Property::INVALID_INDEX;
638 if(Property::ANIMATABLE == accessMode)
640 index = RegisterProperty(name, propertyValue);
644 // Add entry to the property lookup
645 index = PROPERTY_CUSTOM_START_INDEX + mCustomProperties.Count();
646 mCustomProperties.PushBack( new CustomPropertyMetadata( name, propertyValue, accessMode ) );
652 Dali::PropertyNotification Object::AddPropertyNotification(Property::Index index,
654 const Dali::PropertyCondition& condition)
656 if ( index >= DEFAULT_PROPERTY_MAX_COUNT )
658 if ( index <= PROPERTY_REGISTRATION_MAX_INDEX )
660 DALI_ASSERT_ALWAYS( false && "Property notification added to event side only property." );
662 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
664 // check whether the animatable property is registered already, if not then register one.
665 AnimatablePropertyMetadata* animatable = RegisterAnimatableProperty( index );
666 DALI_ASSERT_ALWAYS( animatable && "Property index is invalid" );
668 else if ( mCustomProperties.Count() > 0 )
670 CustomPropertyMetadata* custom = FindCustomProperty( index );
671 DALI_ASSERT_ALWAYS( custom && "Invalid property index" );
672 DALI_ASSERT_ALWAYS( custom->IsAnimatable() && "Property notification added to event side only property." );
676 Dali::Handle self(this);
677 Property target( self, index );
679 PropertyNotificationPtr internal = PropertyNotification::New( target, componentIndex, condition );
680 Dali::PropertyNotification propertyNotification(internal.Get());
682 if( !mPropertyNotifications )
684 mPropertyNotifications = new PropertyNotificationContainer;
686 mPropertyNotifications->push_back(propertyNotification);
688 return propertyNotification;
691 void Object::RemovePropertyNotification(Dali::PropertyNotification propertyNotification)
693 if( mPropertyNotifications )
695 PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
696 while(iter != mPropertyNotifications->end() )
698 if(*iter == propertyNotification)
700 mPropertyNotifications->erase(iter);
701 // As we can't ensure all references are removed, we can just disable
703 GetImplementation(propertyNotification).Disable();
711 void Object::RemovePropertyNotifications()
713 if( mPropertyNotifications )
715 PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
716 while(iter != mPropertyNotifications->end() )
718 // As we can't ensure all references are removed, we can just disable
720 GetImplementation(*iter).Disable();
724 mPropertyNotifications->clear();
728 void Object::EnablePropertyNotifications()
730 if( mPropertyNotifications )
732 PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
733 PropertyNotificationContainerIter endIter = mPropertyNotifications->end();
735 for( ; iter != endIter; ++iter )
737 GetImplementation(*iter).Enable();
742 void Object::DisablePropertyNotifications()
744 if( mPropertyNotifications )
746 PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
747 PropertyNotificationContainerIter endIter = mPropertyNotifications->end();
749 for( ; iter != endIter; ++iter )
751 GetImplementation(*iter).Disable();
756 Property::Value Object::GetPropertyValue( const PropertyMetadata* entry ) const
758 Property::Value value;
760 DALI_ASSERT_ALWAYS( entry && "Invalid property metadata" );
762 if( !entry->IsAnimatable() )
764 value = entry->value;
768 BufferIndex bufferIndex( GetEventThreadServices().GetEventBufferIndex() );
770 switch ( entry->type )
772 case Property::BOOLEAN:
774 const AnimatableProperty<bool>* property = dynamic_cast< const AnimatableProperty<bool>* >( entry->GetSceneGraphProperty() );
775 DALI_ASSERT_DEBUG( NULL != property );
777 value = (*property)[ bufferIndex ];
781 case Property::INTEGER:
783 const AnimatableProperty<int>* property = dynamic_cast< const AnimatableProperty<int>* >( entry->GetSceneGraphProperty() );
784 DALI_ASSERT_DEBUG( NULL != property );
786 value = (*property)[ bufferIndex ];
790 case Property::UNSIGNED_INTEGER:
792 const AnimatableProperty<unsigned int>* property = dynamic_cast< const AnimatableProperty<unsigned int>* >( entry->GetSceneGraphProperty() );
793 DALI_ASSERT_DEBUG( NULL != property );
795 value = (*property)[ bufferIndex ];
799 case Property::FLOAT:
801 const AnimatableProperty<float>* property = dynamic_cast< const AnimatableProperty<float>* >( entry->GetSceneGraphProperty() );
802 DALI_ASSERT_DEBUG( NULL != property );
804 value = (*property)[ bufferIndex ];
808 case Property::VECTOR2:
810 const AnimatableProperty<Vector2>* property = dynamic_cast< const AnimatableProperty<Vector2>* >( entry->GetSceneGraphProperty() );
811 DALI_ASSERT_DEBUG( NULL != property );
813 if(entry->componentIndex == 0)
815 value = (*property)[ bufferIndex ].x;
817 else if(entry->componentIndex == 1)
819 value = (*property)[ bufferIndex ].y;
823 value = (*property)[ bufferIndex ];
828 case Property::VECTOR3:
830 const AnimatableProperty<Vector3>* property = dynamic_cast< const AnimatableProperty<Vector3>* >( entry->GetSceneGraphProperty() );
831 DALI_ASSERT_DEBUG( NULL != property );
833 if(entry->componentIndex == 0)
835 value = (*property)[ bufferIndex ].x;
837 else if(entry->componentIndex == 1)
839 value = (*property)[ bufferIndex ].y;
841 else if(entry->componentIndex == 2)
843 value = (*property)[ bufferIndex ].z;
847 value = (*property)[ bufferIndex ];
852 case Property::VECTOR4:
854 const AnimatableProperty<Vector4>* property = dynamic_cast< const AnimatableProperty<Vector4>* >( entry->GetSceneGraphProperty() );
855 DALI_ASSERT_DEBUG( NULL != property );
857 if(entry->componentIndex == 0)
859 value = (*property)[ bufferIndex ].x;
861 else if(entry->componentIndex == 1)
863 value = (*property)[ bufferIndex ].y;
865 else if(entry->componentIndex == 2)
867 value = (*property)[ bufferIndex ].z;
869 else if(entry->componentIndex == 3)
871 value = (*property)[ bufferIndex ].w;
875 value = (*property)[ bufferIndex ];
880 case Property::MATRIX:
882 const AnimatableProperty<Matrix>* property = dynamic_cast< const AnimatableProperty<Matrix>* >( entry->GetSceneGraphProperty() );
883 DALI_ASSERT_DEBUG( NULL != property );
885 value = (*property)[ bufferIndex ];
889 case Property::MATRIX3:
891 const AnimatableProperty<Matrix3>* property = dynamic_cast< const AnimatableProperty<Matrix3>* >( entry->GetSceneGraphProperty() );
892 DALI_ASSERT_DEBUG( NULL != property );
894 value = (*property)[ bufferIndex ];
898 case Property::ROTATION:
900 const AnimatableProperty<Quaternion>* property = dynamic_cast< const AnimatableProperty<Quaternion>* >( entry->GetSceneGraphProperty() );
901 DALI_ASSERT_DEBUG( NULL != property );
903 value = (*property)[ bufferIndex ];
909 DALI_ASSERT_ALWAYS( false && "PropertyType enumeration is out of bounds" );
918 void Object::SetSceneGraphProperty( Property::Index index, const PropertyMetadata& entry, const Property::Value& value )
920 switch ( entry.type )
922 case Property::BOOLEAN:
924 const AnimatableProperty<bool>* property = dynamic_cast< const AnimatableProperty<bool>* >( entry.GetSceneGraphProperty() );
925 DALI_ASSERT_DEBUG( NULL != property );
927 // property is being used in a separate thread; queue a message to set the property
928 BakeMessage<bool>( GetEventThreadServices(), *property, value.Get<bool>() );
932 case Property::INTEGER:
934 const AnimatableProperty<int>* property = dynamic_cast< const AnimatableProperty<int>* >( entry.GetSceneGraphProperty() );
935 DALI_ASSERT_DEBUG( NULL != property );
937 // property is being used in a separate thread; queue a message to set the property
938 BakeMessage<int>( GetEventThreadServices(), *property, value.Get<int>() );
942 case Property::UNSIGNED_INTEGER:
944 const AnimatableProperty<unsigned int>* property = dynamic_cast< const AnimatableProperty<unsigned int>* >( entry.GetSceneGraphProperty() );
945 DALI_ASSERT_DEBUG( NULL != property );
947 // property is being used in a separate thread; queue a message to set the property
948 BakeMessage<unsigned int>( GetEventThreadServices(), *property, value.Get<unsigned int>() );
952 case Property::FLOAT:
954 const AnimatableProperty<float>* property = dynamic_cast< const AnimatableProperty<float>* >( entry.GetSceneGraphProperty() );
955 DALI_ASSERT_DEBUG( NULL != property );
957 // property is being used in a separate thread; queue a message to set the property
958 BakeMessage<float>( GetEventThreadServices(), *property, value.Get<float>() );
962 case Property::VECTOR2:
964 const AnimatableProperty<Vector2>* property = dynamic_cast< const AnimatableProperty<Vector2>* >( entry.GetSceneGraphProperty() );
965 DALI_ASSERT_DEBUG( NULL != property );
967 // property is being used in a separate thread; queue a message to set the property
968 if(entry.componentIndex == 0)
970 SetXComponentMessage<Vector2>( GetEventThreadServices(), *property, value.Get<float>() );
972 else if(entry.componentIndex == 1)
974 SetYComponentMessage<Vector2>( GetEventThreadServices(), *property, value.Get<float>() );
978 BakeMessage<Vector2>( GetEventThreadServices(), *property, value.Get<Vector2>() );
983 case Property::VECTOR3:
985 const AnimatableProperty<Vector3>* property = dynamic_cast< const AnimatableProperty<Vector3>* >( entry.GetSceneGraphProperty() );
986 DALI_ASSERT_DEBUG( NULL != property );
988 // property is being used in a separate thread; queue a message to set the property
989 if(entry.componentIndex == 0)
991 SetXComponentMessage<Vector3>( GetEventThreadServices(), *property, value.Get<float>() );
993 else if(entry.componentIndex == 1)
995 SetYComponentMessage<Vector3>( GetEventThreadServices(), *property, value.Get<float>() );
997 else if(entry.componentIndex == 2)
999 SetZComponentMessage<Vector3>( GetEventThreadServices(), *property, value.Get<float>() );
1003 BakeMessage<Vector3>( GetEventThreadServices(), *property, value.Get<Vector3>() );
1009 case Property::VECTOR4:
1011 const AnimatableProperty<Vector4>* property = dynamic_cast< const AnimatableProperty<Vector4>* >( entry.GetSceneGraphProperty() );
1012 DALI_ASSERT_DEBUG( NULL != property );
1014 // property is being used in a separate thread; queue a message to set the property
1015 if(entry.componentIndex == 0)
1017 SetXComponentMessage<Vector4>( GetEventThreadServices(), *property, value.Get<float>() );
1019 else if(entry.componentIndex == 1)
1021 SetYComponentMessage<Vector4>( GetEventThreadServices(), *property, value.Get<float>() );
1023 else if(entry.componentIndex == 2)
1025 SetZComponentMessage<Vector4>( GetEventThreadServices(), *property, value.Get<float>() );
1027 else if(entry.componentIndex == 3)
1029 SetWComponentMessage<Vector4>( GetEventThreadServices(), *property, value.Get<float>() );
1033 BakeMessage<Vector4>( GetEventThreadServices(), *property, value.Get<Vector4>() );
1038 case Property::ROTATION:
1040 const AnimatableProperty<Quaternion>* property = dynamic_cast< const AnimatableProperty<Quaternion>* >( entry.GetSceneGraphProperty() );
1041 DALI_ASSERT_DEBUG( NULL != property );
1043 // property is being used in a separate thread; queue a message to set the property
1044 BakeMessage<Quaternion>( GetEventThreadServices(), *property, value.Get<Quaternion>() );
1048 case Property::MATRIX:
1050 const AnimatableProperty<Matrix>* property = dynamic_cast< const AnimatableProperty<Matrix>* >( entry.GetSceneGraphProperty() );
1051 DALI_ASSERT_DEBUG( NULL != property );
1053 // property is being used in a separate thread; queue a message to set the property
1054 BakeMessage<Matrix>( GetEventThreadServices(), *property, value.Get<Matrix>() );
1058 case Property::MATRIX3:
1060 const AnimatableProperty<Matrix3>* property = dynamic_cast< const AnimatableProperty<Matrix3>* >( entry.GetSceneGraphProperty() );
1061 DALI_ASSERT_DEBUG( NULL != property );
1063 // property is being used in a separate thread; queue a message to set the property
1064 BakeMessage<Matrix3>( GetEventThreadServices(), *property, value.Get<Matrix3>() );
1070 // non-animatable scene graph property, do nothing
1075 const TypeInfo* Object::GetTypeInfo() const
1079 // This uses a dynamic_cast so can be quite expensive so we only really want to do it once
1080 // especially as the type-info does not change during the life-time of an application
1082 Dali::TypeInfo typeInfoHandle = TypeRegistry::Get()->GetTypeInfo( this );
1083 if ( typeInfoHandle )
1085 mTypeInfo = &GetImplementation( typeInfoHandle );
1092 void Object::ApplyConstraint( ConstraintBase& constraint )
1096 mConstraints = new ConstraintContainer;
1098 mConstraints->push_back( Dali::Constraint( &constraint ) );
1101 void Object::RemoveConstraint( ConstraintBase& constraint )
1103 // NULL if the Constraint sources are destroyed before Constraint::Apply()
1106 ConstraintIter it( std::find( mConstraints->begin(), mConstraints->end(), Dali::Constraint( &constraint ) ) );
1107 if( it != mConstraints->end() )
1109 mConstraints->erase( it );
1114 void Object::RemoveConstraints()
1116 // guard against constraint sending messages during core destruction
1117 if( mConstraints && Stage::IsInstalled() )
1119 // If we have nothing in the scene-graph, just clear constraint containers
1120 const SceneGraph::PropertyOwner* propertyOwner = GetSceneObject();
1121 if ( NULL != propertyOwner )
1123 const ConstraintConstIter endIter = mConstraints->end();
1124 for ( ConstraintIter iter = mConstraints->begin(); endIter != iter; ++iter )
1126 GetImplementation( *iter ).RemoveInternal();
1130 delete mConstraints;
1131 mConstraints = NULL;
1135 void Object::RemoveConstraints( unsigned int tag )
1137 // guard against constraint sending messages during core destruction
1138 if( mConstraints && Stage::IsInstalled() )
1140 ConstraintIter iter( mConstraints->begin() );
1141 while(iter != mConstraints->end() )
1143 ConstraintBase& constraint = GetImplementation( *iter );
1144 if( constraint.GetTag() == tag )
1146 GetImplementation( *iter ).RemoveInternal();
1147 iter = mConstraints->erase( iter );
1155 if ( mConstraints->empty() )
1157 delete mConstraints;
1158 mConstraints = NULL;
1163 void Object::SetTypeInfo( const TypeInfo* typeInfo )
1165 mTypeInfo = typeInfo;
1170 // Notification for observers
1171 for( ConstObserverIter iter = mObservers.Begin(), endIter = mObservers.End(); iter != endIter; ++iter)
1173 (*iter)->ObjectDestroyed(*this);
1176 delete mConstraints;
1177 delete mPropertyNotifications;
1180 CustomPropertyMetadata* Object::FindCustomProperty( Property::Index index ) const
1182 CustomPropertyMetadata* property( NULL );
1183 int arrayIndex = index - PROPERTY_CUSTOM_START_INDEX;
1184 if( arrayIndex >= 0 )
1186 if( arrayIndex < (int)mCustomProperties.Count() ) // we can only access the first 2 billion custom properties
1188 property = static_cast<CustomPropertyMetadata*>(mCustomProperties[ arrayIndex ]);
1194 AnimatablePropertyMetadata* Object::FindAnimatableProperty( Property::Index index ) const
1196 for ( int arrayIndex = 0; arrayIndex < (int)mAnimatableProperties.Count(); arrayIndex++ )
1198 AnimatablePropertyMetadata* property = static_cast<AnimatablePropertyMetadata*>( mAnimatableProperties[ arrayIndex ] );
1199 if( property->index == index )
1207 AnimatablePropertyMetadata* Object::RegisterAnimatableProperty(Property::Index index) const
1209 DALI_ASSERT_ALWAYS( (( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ))
1210 && "Property index is out of bounds" );
1212 // check whether the animatable property is registered already, if not then register one.
1213 AnimatablePropertyMetadata* animatableProperty = FindAnimatableProperty( index );
1214 if(!animatableProperty)
1216 const TypeInfo* typeInfo( GetTypeInfo() );
1219 Property::Index basePropertyIndex = typeInfo->GetBasePropertyIndex(index);
1220 if(basePropertyIndex == Property::INVALID_INDEX)
1222 // If the property is not a component of a base property, register the whole property itself.
1223 index = RegisterSceneGraphProperty(typeInfo->GetPropertyName(index), index, Property::Value(typeInfo->GetPropertyType(index)));
1227 // Since the property is a component of a base property, check whether the base property is regsitered.
1228 animatableProperty = FindAnimatableProperty( basePropertyIndex );
1229 if(!animatableProperty)
1231 // If the base property is not registered yet, register the base property first.
1232 if(Property::INVALID_INDEX != RegisterSceneGraphProperty(typeInfo->GetPropertyName(basePropertyIndex), basePropertyIndex, Property::Value(typeInfo->GetPropertyType(basePropertyIndex))))
1234 animatableProperty = static_cast<AnimatablePropertyMetadata*>(mAnimatableProperties[mAnimatableProperties.Size()-1]);
1238 if(animatableProperty)
1240 // Create the metadata for the property component.
1241 mAnimatableProperties.PushBack( new AnimatablePropertyMetadata( index, typeInfo->GetComponentIndex(index), animatableProperty->type, animatableProperty->GetSceneGraphProperty() ) );
1245 // The metadata has just been added and therefore should be in the end of the vector.
1246 animatableProperty = static_cast<AnimatablePropertyMetadata*>(mAnimatableProperties[mAnimatableProperties.Size()-1]);
1250 return animatableProperty;
1253 } // namespace Internal