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:
591 DALI_ASSERT_ALWAYS( !"PropertyType is not animatable" );
596 // get the scene property owner from derived class
597 const SceneGraph::PropertyOwner* scenePropertyOwner = GetPropertyOwner();
598 // we can only pass properties to scene graph side if there is a scene object
599 if( scenePropertyOwner )
601 // keep a local pointer to the property as the OwnerPointer will pass its copy to the message
602 const PropertyBase* property = newProperty.Get();
603 if(index >= PROPERTY_CUSTOM_START_INDEX)
605 mCustomProperties.PushBack( new CustomPropertyMetadata( name, propertyValue.GetType(), property ) );
609 mAnimatableProperties.PushBack( new AnimatablePropertyMetadata( index, Property::INVALID_COMPONENT_INDEX, propertyValue.GetType(), property ) ); // base property
612 // queue a message to add the property
613 InstallCustomPropertyMessage( const_cast<EventThreadServices&>(GetEventThreadServices()), *scenePropertyOwner, newProperty.Release() ); // Message takes ownership
615 // notify the derived class (optional) method in case it needs to do some more work on the new property
616 // note! have to use the local pointer as OwnerPointer now points to NULL as it handed over its ownership
617 NotifyScenePropertyInstalled( *property, name, index );
623 // property was orphaned and killed so return invalid index
624 return Property::INVALID_INDEX;
628 Property::Index Object::RegisterProperty( const std::string& name, const Property::Value& propertyValue)
630 return RegisterSceneGraphProperty(name, PROPERTY_CUSTOM_START_INDEX + mCustomProperties.Count(), propertyValue);
633 Property::Index Object::RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode)
635 Property::Index index = Property::INVALID_INDEX;
637 if(Property::ANIMATABLE == accessMode)
639 index = RegisterProperty(name, propertyValue);
643 // Add entry to the property lookup
644 index = PROPERTY_CUSTOM_START_INDEX + mCustomProperties.Count();
645 mCustomProperties.PushBack( new CustomPropertyMetadata( name, propertyValue, accessMode ) );
651 Dali::PropertyNotification Object::AddPropertyNotification(Property::Index index,
653 const Dali::PropertyCondition& condition)
655 if ( index >= DEFAULT_PROPERTY_MAX_COUNT )
657 if ( index <= PROPERTY_REGISTRATION_MAX_INDEX )
659 DALI_ASSERT_ALWAYS( false && "Property notification added to event side only property." );
661 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
663 // check whether the animatable property is registered already, if not then register one.
664 AnimatablePropertyMetadata* animatable = RegisterAnimatableProperty( index );
665 DALI_ASSERT_ALWAYS( animatable && "Property index is invalid" );
667 else if ( mCustomProperties.Count() > 0 )
669 CustomPropertyMetadata* custom = FindCustomProperty( index );
670 DALI_ASSERT_ALWAYS( custom && "Invalid property index" );
671 DALI_ASSERT_ALWAYS( custom->IsAnimatable() && "Property notification added to event side only property." );
675 Dali::Handle self(this);
676 Property target( self, index );
678 PropertyNotificationPtr internal = PropertyNotification::New( target, componentIndex, condition );
679 Dali::PropertyNotification propertyNotification(internal.Get());
681 if( !mPropertyNotifications )
683 mPropertyNotifications = new PropertyNotificationContainer;
685 mPropertyNotifications->push_back(propertyNotification);
687 return propertyNotification;
690 void Object::RemovePropertyNotification(Dali::PropertyNotification propertyNotification)
692 if( mPropertyNotifications )
694 PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
695 while(iter != mPropertyNotifications->end() )
697 if(*iter == propertyNotification)
699 mPropertyNotifications->erase(iter);
700 // As we can't ensure all references are removed, we can just disable
702 GetImplementation(propertyNotification).Disable();
710 void Object::RemovePropertyNotifications()
712 if( mPropertyNotifications )
714 PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
715 while(iter != mPropertyNotifications->end() )
717 // As we can't ensure all references are removed, we can just disable
719 GetImplementation(*iter).Disable();
723 mPropertyNotifications->clear();
727 void Object::EnablePropertyNotifications()
729 if( mPropertyNotifications )
731 PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
732 PropertyNotificationContainerIter endIter = mPropertyNotifications->end();
734 for( ; iter != endIter; ++iter )
736 GetImplementation(*iter).Enable();
741 void Object::DisablePropertyNotifications()
743 if( mPropertyNotifications )
745 PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
746 PropertyNotificationContainerIter endIter = mPropertyNotifications->end();
748 for( ; iter != endIter; ++iter )
750 GetImplementation(*iter).Disable();
755 Property::Value Object::GetPropertyValue( const PropertyMetadata* entry ) const
757 Property::Value value;
759 DALI_ASSERT_ALWAYS( entry && "Invalid property metadata" );
761 if( !entry->IsAnimatable() )
763 value = entry->value;
767 BufferIndex bufferIndex( GetEventThreadServices().GetEventBufferIndex() );
769 switch ( entry->type )
771 case Property::BOOLEAN:
773 const AnimatableProperty<bool>* property = dynamic_cast< const AnimatableProperty<bool>* >( entry->GetSceneGraphProperty() );
774 DALI_ASSERT_DEBUG( NULL != property );
776 value = (*property)[ bufferIndex ];
780 case Property::INTEGER:
782 const AnimatableProperty<int>* property = dynamic_cast< const AnimatableProperty<int>* >( entry->GetSceneGraphProperty() );
783 DALI_ASSERT_DEBUG( NULL != property );
785 value = (*property)[ bufferIndex ];
789 case Property::UNSIGNED_INTEGER:
791 const AnimatableProperty<unsigned int>* property = dynamic_cast< const AnimatableProperty<unsigned int>* >( entry->GetSceneGraphProperty() );
792 DALI_ASSERT_DEBUG( NULL != property );
794 value = (*property)[ bufferIndex ];
798 case Property::FLOAT:
800 const AnimatableProperty<float>* property = dynamic_cast< const AnimatableProperty<float>* >( entry->GetSceneGraphProperty() );
801 DALI_ASSERT_DEBUG( NULL != property );
803 value = (*property)[ bufferIndex ];
807 case Property::VECTOR2:
809 const AnimatableProperty<Vector2>* property = dynamic_cast< const AnimatableProperty<Vector2>* >( entry->GetSceneGraphProperty() );
810 DALI_ASSERT_DEBUG( NULL != property );
812 if(entry->componentIndex == 0)
814 value = (*property)[ bufferIndex ].x;
816 else if(entry->componentIndex == 1)
818 value = (*property)[ bufferIndex ].y;
822 value = (*property)[ bufferIndex ];
827 case Property::VECTOR3:
829 const AnimatableProperty<Vector3>* property = dynamic_cast< const AnimatableProperty<Vector3>* >( entry->GetSceneGraphProperty() );
830 DALI_ASSERT_DEBUG( NULL != property );
832 if(entry->componentIndex == 0)
834 value = (*property)[ bufferIndex ].x;
836 else if(entry->componentIndex == 1)
838 value = (*property)[ bufferIndex ].y;
840 else if(entry->componentIndex == 2)
842 value = (*property)[ bufferIndex ].z;
846 value = (*property)[ bufferIndex ];
851 case Property::VECTOR4:
853 const AnimatableProperty<Vector4>* property = dynamic_cast< const AnimatableProperty<Vector4>* >( entry->GetSceneGraphProperty() );
854 DALI_ASSERT_DEBUG( NULL != property );
856 if(entry->componentIndex == 0)
858 value = (*property)[ bufferIndex ].x;
860 else if(entry->componentIndex == 1)
862 value = (*property)[ bufferIndex ].y;
864 else if(entry->componentIndex == 2)
866 value = (*property)[ bufferIndex ].z;
868 else if(entry->componentIndex == 3)
870 value = (*property)[ bufferIndex ].w;
874 value = (*property)[ bufferIndex ];
879 case Property::MATRIX:
881 const AnimatableProperty<Matrix>* property = dynamic_cast< const AnimatableProperty<Matrix>* >( entry->GetSceneGraphProperty() );
882 DALI_ASSERT_DEBUG( NULL != property );
884 value = (*property)[ bufferIndex ];
888 case Property::MATRIX3:
890 const AnimatableProperty<Matrix3>* property = dynamic_cast< const AnimatableProperty<Matrix3>* >( entry->GetSceneGraphProperty() );
891 DALI_ASSERT_DEBUG( NULL != property );
893 value = (*property)[ bufferIndex ];
897 case Property::ROTATION:
899 const AnimatableProperty<Quaternion>* property = dynamic_cast< const AnimatableProperty<Quaternion>* >( entry->GetSceneGraphProperty() );
900 DALI_ASSERT_DEBUG( NULL != property );
902 value = (*property)[ bufferIndex ];
908 DALI_ASSERT_ALWAYS( false && "PropertyType enumeration is out of bounds" );
917 void Object::SetSceneGraphProperty( Property::Index index, const PropertyMetadata& entry, const Property::Value& value )
919 switch ( entry.type )
921 case Property::BOOLEAN:
923 const AnimatableProperty<bool>* property = dynamic_cast< const AnimatableProperty<bool>* >( entry.GetSceneGraphProperty() );
924 DALI_ASSERT_DEBUG( NULL != property );
926 // property is being used in a separate thread; queue a message to set the property
927 BakeMessage<bool>( GetEventThreadServices(), *property, value.Get<bool>() );
931 case Property::INTEGER:
933 const AnimatableProperty<int>* property = dynamic_cast< const AnimatableProperty<int>* >( entry.GetSceneGraphProperty() );
934 DALI_ASSERT_DEBUG( NULL != property );
936 // property is being used in a separate thread; queue a message to set the property
937 BakeMessage<int>( GetEventThreadServices(), *property, value.Get<int>() );
941 case Property::UNSIGNED_INTEGER:
943 const AnimatableProperty<unsigned int>* property = dynamic_cast< const AnimatableProperty<unsigned int>* >( entry.GetSceneGraphProperty() );
944 DALI_ASSERT_DEBUG( NULL != property );
946 // property is being used in a separate thread; queue a message to set the property
947 BakeMessage<unsigned int>( GetEventThreadServices(), *property, value.Get<unsigned int>() );
951 case Property::FLOAT:
953 const AnimatableProperty<float>* property = dynamic_cast< const AnimatableProperty<float>* >( entry.GetSceneGraphProperty() );
954 DALI_ASSERT_DEBUG( NULL != property );
956 // property is being used in a separate thread; queue a message to set the property
957 BakeMessage<float>( GetEventThreadServices(), *property, value.Get<float>() );
961 case Property::VECTOR2:
963 const AnimatableProperty<Vector2>* property = dynamic_cast< const AnimatableProperty<Vector2>* >( entry.GetSceneGraphProperty() );
964 DALI_ASSERT_DEBUG( NULL != property );
966 // property is being used in a separate thread; queue a message to set the property
967 if(entry.componentIndex == 0)
969 SetXComponentMessage<Vector2>( GetEventThreadServices(), *property, value.Get<float>() );
971 else if(entry.componentIndex == 1)
973 SetYComponentMessage<Vector2>( GetEventThreadServices(), *property, value.Get<float>() );
977 BakeMessage<Vector2>( GetEventThreadServices(), *property, value.Get<Vector2>() );
982 case Property::VECTOR3:
984 const AnimatableProperty<Vector3>* property = dynamic_cast< const AnimatableProperty<Vector3>* >( entry.GetSceneGraphProperty() );
985 DALI_ASSERT_DEBUG( NULL != property );
987 // property is being used in a separate thread; queue a message to set the property
988 if(entry.componentIndex == 0)
990 SetXComponentMessage<Vector3>( GetEventThreadServices(), *property, value.Get<float>() );
992 else if(entry.componentIndex == 1)
994 SetYComponentMessage<Vector3>( GetEventThreadServices(), *property, value.Get<float>() );
996 else if(entry.componentIndex == 2)
998 SetZComponentMessage<Vector3>( GetEventThreadServices(), *property, value.Get<float>() );
1002 BakeMessage<Vector3>( GetEventThreadServices(), *property, value.Get<Vector3>() );
1008 case Property::VECTOR4:
1010 const AnimatableProperty<Vector4>* property = dynamic_cast< const AnimatableProperty<Vector4>* >( entry.GetSceneGraphProperty() );
1011 DALI_ASSERT_DEBUG( NULL != property );
1013 // property is being used in a separate thread; queue a message to set the property
1014 if(entry.componentIndex == 0)
1016 SetXComponentMessage<Vector4>( GetEventThreadServices(), *property, value.Get<float>() );
1018 else if(entry.componentIndex == 1)
1020 SetYComponentMessage<Vector4>( GetEventThreadServices(), *property, value.Get<float>() );
1022 else if(entry.componentIndex == 2)
1024 SetZComponentMessage<Vector4>( GetEventThreadServices(), *property, value.Get<float>() );
1026 else if(entry.componentIndex == 3)
1028 SetWComponentMessage<Vector4>( GetEventThreadServices(), *property, value.Get<float>() );
1032 BakeMessage<Vector4>( GetEventThreadServices(), *property, value.Get<Vector4>() );
1037 case Property::ROTATION:
1039 const AnimatableProperty<Quaternion>* property = dynamic_cast< const AnimatableProperty<Quaternion>* >( entry.GetSceneGraphProperty() );
1040 DALI_ASSERT_DEBUG( NULL != property );
1042 // property is being used in a separate thread; queue a message to set the property
1043 BakeMessage<Quaternion>( GetEventThreadServices(), *property, value.Get<Quaternion>() );
1047 case Property::MATRIX:
1049 const AnimatableProperty<Matrix>* property = dynamic_cast< const AnimatableProperty<Matrix>* >( entry.GetSceneGraphProperty() );
1050 DALI_ASSERT_DEBUG( NULL != property );
1052 // property is being used in a separate thread; queue a message to set the property
1053 BakeMessage<Matrix>( GetEventThreadServices(), *property, value.Get<Matrix>() );
1057 case Property::MATRIX3:
1059 const AnimatableProperty<Matrix3>* property = dynamic_cast< const AnimatableProperty<Matrix3>* >( entry.GetSceneGraphProperty() );
1060 DALI_ASSERT_DEBUG( NULL != property );
1062 // property is being used in a separate thread; queue a message to set the property
1063 BakeMessage<Matrix3>( GetEventThreadServices(), *property, value.Get<Matrix3>() );
1069 // non-animatable scene graph property, do nothing
1074 const TypeInfo* Object::GetTypeInfo() const
1078 // This uses a dynamic_cast so can be quite expensive so we only really want to do it once
1079 // especially as the type-info does not change during the life-time of an application
1081 Dali::TypeInfo typeInfoHandle = TypeRegistry::Get()->GetTypeInfo( this );
1082 if ( typeInfoHandle )
1084 mTypeInfo = &GetImplementation( typeInfoHandle );
1091 void Object::ApplyConstraint( ConstraintBase& constraint )
1095 mConstraints = new ConstraintContainer;
1097 mConstraints->push_back( Dali::Constraint( &constraint ) );
1100 void Object::RemoveConstraint( ConstraintBase& constraint )
1102 // NULL if the Constraint sources are destroyed before Constraint::Apply()
1105 ConstraintIter it( std::find( mConstraints->begin(), mConstraints->end(), Dali::Constraint( &constraint ) ) );
1106 if( it != mConstraints->end() )
1108 mConstraints->erase( it );
1113 void Object::RemoveConstraints()
1115 // guard against constraint sending messages during core destruction
1116 if( mConstraints && Stage::IsInstalled() )
1118 // If we have nothing in the scene-graph, just clear constraint containers
1119 const SceneGraph::PropertyOwner* propertyOwner = GetSceneObject();
1120 if ( NULL != propertyOwner )
1122 const ConstraintConstIter endIter = mConstraints->end();
1123 for ( ConstraintIter iter = mConstraints->begin(); endIter != iter; ++iter )
1125 GetImplementation( *iter ).RemoveInternal();
1129 delete mConstraints;
1130 mConstraints = NULL;
1134 void Object::RemoveConstraints( unsigned int tag )
1136 // guard against constraint sending messages during core destruction
1137 if( mConstraints && Stage::IsInstalled() )
1139 ConstraintIter iter( mConstraints->begin() );
1140 while(iter != mConstraints->end() )
1142 ConstraintBase& constraint = GetImplementation( *iter );
1143 if( constraint.GetTag() == tag )
1145 GetImplementation( *iter ).RemoveInternal();
1146 iter = mConstraints->erase( iter );
1154 if ( mConstraints->empty() )
1156 delete mConstraints;
1157 mConstraints = NULL;
1162 void Object::SetTypeInfo( const TypeInfo* typeInfo )
1164 mTypeInfo = typeInfo;
1169 // Notification for observers
1170 for( ConstObserverIter iter = mObservers.Begin(), endIter = mObservers.End(); iter != endIter; ++iter)
1172 (*iter)->ObjectDestroyed(*this);
1175 delete mConstraints;
1176 delete mPropertyNotifications;
1179 CustomPropertyMetadata* Object::FindCustomProperty( Property::Index index ) const
1181 CustomPropertyMetadata* property( NULL );
1182 int arrayIndex = index - PROPERTY_CUSTOM_START_INDEX;
1183 if( arrayIndex >= 0 )
1185 if( arrayIndex < (int)mCustomProperties.Count() ) // we can only access the first 2 billion custom properties
1187 property = static_cast<CustomPropertyMetadata*>(mCustomProperties[ arrayIndex ]);
1193 AnimatablePropertyMetadata* Object::FindAnimatableProperty( Property::Index index ) const
1195 for ( int arrayIndex = 0; arrayIndex < (int)mAnimatableProperties.Count(); arrayIndex++ )
1197 AnimatablePropertyMetadata* property = static_cast<AnimatablePropertyMetadata*>( mAnimatableProperties[ arrayIndex ] );
1198 if( property->index == index )
1206 AnimatablePropertyMetadata* Object::RegisterAnimatableProperty(Property::Index index) const
1208 DALI_ASSERT_ALWAYS( (( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ))
1209 && "Property index is out of bounds" );
1211 // check whether the animatable property is registered already, if not then register one.
1212 AnimatablePropertyMetadata* animatableProperty = FindAnimatableProperty( index );
1213 if(!animatableProperty)
1215 const TypeInfo* typeInfo( GetTypeInfo() );
1218 Property::Index basePropertyIndex = typeInfo->GetBasePropertyIndex(index);
1219 if(basePropertyIndex == Property::INVALID_INDEX)
1221 // If the property is not a component of a base property, register the whole property itself.
1222 index = RegisterSceneGraphProperty(typeInfo->GetPropertyName(index), index, Property::Value(typeInfo->GetPropertyType(index)));
1226 // Since the property is a component of a base property, check whether the base property is regsitered.
1227 animatableProperty = FindAnimatableProperty( basePropertyIndex );
1228 if(!animatableProperty)
1230 // If the base property is not registered yet, register the base property first.
1231 if(Property::INVALID_INDEX != RegisterSceneGraphProperty(typeInfo->GetPropertyName(basePropertyIndex), basePropertyIndex, Property::Value(typeInfo->GetPropertyType(basePropertyIndex))))
1233 animatableProperty = static_cast<AnimatablePropertyMetadata*>(mAnimatableProperties[mAnimatableProperties.Size()-1]);
1237 if(animatableProperty)
1239 // Create the metadata for the property component.
1240 mAnimatableProperties.PushBack( new AnimatablePropertyMetadata( index, typeInfo->GetComponentIndex(index), animatableProperty->type, animatableProperty->GetSceneGraphProperty() ) );
1244 // The metadata has just been added and therefore should be in the end of the vector.
1245 animatableProperty = static_cast<AnimatablePropertyMetadata*>(mAnimatableProperties[mAnimatableProperties.Size()-1]);
1249 return animatableProperty;
1252 } // namespace Internal