X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fevent%2Fanimation%2Fconstraint-impl.h;h=a7cf1e2b2466f4f38101e95532bddbf28d1fba8b;hb=baad1726f5f7f05d98da7ca591f24dbe3c49dab2;hp=cb671d6400485f28ef2a9567753ef768999f6a42;hpb=2415d4f81cf9784289d4a7afbbc8b19cda2e105f;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/event/animation/constraint-impl.h b/dali/internal/event/animation/constraint-impl.h index cb671d6..a7cf1e2 100644 --- a/dali/internal/event/animation/constraint-impl.h +++ b/dali/internal/event/animation/constraint-impl.h @@ -1,8 +1,8 @@ -#ifndef __DALI_INTERNAL_ACTIVE_CONSTRAINT_H__ -#define __DALI_INTERNAL_ACTIVE_CONSTRAINT_H__ +#ifndef DALI_INTERNAL_ACTIVE_CONSTRAINT_H +#define DALI_INTERNAL_ACTIVE_CONSTRAINT_H /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2019 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,9 +30,11 @@ #include #include #include +#include #include #include #include +#include namespace Dali { @@ -41,21 +43,6 @@ namespace Internal { /** - * Helper to add only unique entries to the propertyOwner container - * @param propertyOwners to add the entries to - * @param object to add - */ -inline void AddUnique( SceneGraph::PropertyOwnerContainer& propertyOwners, SceneGraph::PropertyOwner* object ) -{ - const SceneGraph::PropertyOwnerIter iter = std::find( propertyOwners.Begin(), propertyOwners.End(), object ); - if( iter == propertyOwners.End() ) - { - // each owner should only be added once - propertyOwners.PushBack( object ); - } -} - -/** * Connects a constraint which takes another property as an input. */ template < typename PropertyType > @@ -63,10 +50,7 @@ class Constraint : public ConstraintBase { public: - typedef SceneGraph::Constraint< PropertyType, PropertyAccessor > SceneGraphConstraint; - typedef const SceneGraph::AnimatableProperty* ScenePropertyPtr; - typedef typename PropertyConstraintPtr::Type ConstraintFunctionPtr; - typedef const SceneGraph::TransformManagerPropertyHandler TransformManagerProperty; + using ConstraintFunctionPtr = typename PropertyConstraintPtr::Type; /** * Construct a new constraint. @@ -81,42 +65,31 @@ public: SourceContainer& sources, ConstraintFunctionPtr func ) { - return new Constraint< PropertyType >( object, targetIndex, sources, func ); + return new Constraint( object, targetIndex, sources, func ); } /** - * @copydoc ConstraintBase::Clone() + * Virtual destructor. */ - virtual ConstraintBase* Clone( Object& object ) + virtual ~Constraint() { - DALI_ASSERT_ALWAYS( !mSourceDestroyed && "An input source object has been destroyed" ); - - ConstraintBase* clone( NULL ); - - ConstraintFunctionPtr funcPtr( mUserFunction->Clone() ); - - clone = new Constraint< PropertyType >( object, - mTargetIndex, - mSources, - funcPtr ); - - clone->SetRemoveAction(mRemoveAction); - clone->SetTag( mTag ); - - return clone; + // This is not responsible for removing constraints. } +private: /** - * Virtual destructor. + * @copydoc ConstraintBase::DoClone() */ - virtual ~Constraint() + ConstraintBase* DoClone( Object& object ) override final { - // This is not responsible for removing constraints. + ConstraintFunctionPtr funcPtr( mUserFunction->Clone() ); + return new Constraint( object, + mTargetPropertyIndex, + mSources, + funcPtr ); } -private: - /** * Private constructor; see also Constraint::New(). */ @@ -125,80 +98,65 @@ private: SourceContainer& sources, ConstraintFunctionPtr& func ) : ConstraintBase( object, targetIndex, sources ), - mTargetIndex( targetIndex ), mUserFunction( func ) { } // Undefined - Constraint( const Constraint& ); + Constraint() = delete; + Constraint( const Constraint& ) = delete; + Constraint& operator=( const Constraint& rhs ) = delete; - // Undefined - Constraint& operator=( const Constraint& rhs ); /** - * Create and connect a constraint for a scene-object. + * @copydoc ConstraintBase::ConnectConstraint() */ - void ConnectConstraint() + void ConnectConstraint() override final { - // Should not come here if target-object has been destroyed - DALI_ASSERT_DEBUG( NULL != mTargetObject ); + // Should not come here if target object has been destroyed + DALI_ASSERT_DEBUG( nullptr != mTargetObject ); // Guard against double connections - DALI_ASSERT_DEBUG( NULL == mSceneGraphConstraint ); + DALI_ASSERT_DEBUG( nullptr == mSceneGraphConstraint ); - // Short-circuit until the target scene-object exists - SceneGraph::PropertyOwner* targetObject = const_cast< SceneGraph::PropertyOwner* >( mTargetObject->GetSceneObject() ); - if ( NULL == targetObject ) - { - return; - } + SceneGraph::PropertyOwner& targetObject = const_cast< SceneGraph::PropertyOwner& >( mTargetObject->GetSceneObject() ); // Build a container of property-owners, providing the scene-graph properties SceneGraph::PropertyOwnerContainer propertyOwners; - propertyOwners.PushBack( targetObject ); + propertyOwners.PushBack( &targetObject ); // Build the constraint function; this requires a scene-graph property from each source ConstraintFunctionPtr func( ConnectConstraintFunction( propertyOwners ) ); if ( func ) { - // Create the SceneGraphConstraint, and connect to the scene-graph - - const SceneGraph::PropertyBase* targetProperty = mTargetObject->GetSceneObjectAnimatableProperty( mTargetIndex ); - - // The targetProperty should exist, when targetObject exists - DALI_ASSERT_ALWAYS( NULL != targetProperty && "Constraint target property does not exist" ); - + OwnerPointer resetter; + // Create the SceneGraphConstraint and PropertyResetter, and connect them to the scene-graph + const SceneGraph::PropertyBase* targetProperty = mTargetObject->GetSceneObjectAnimatableProperty( mTargetPropertyIndex ); + DALI_ASSERT_ALWAYS( targetProperty && "Constraint target property does not exist" ); if( targetProperty->IsTransformManagerProperty() ) //It is a property managed by the transform manager { // Connect the constraint - SceneGraph::ConstraintBase* sceneGraphConstraint = SceneGraph::Constraint >::New( *targetProperty, - propertyOwners, - func ); - DALI_ASSERT_DEBUG( NULL != sceneGraphConstraint ); - sceneGraphConstraint->SetRemoveAction( mRemoveAction ); - - // object is being used in a separate thread; queue a message to apply the constraint - ApplyConstraintMessage( GetEventThreadServices(), *targetObject, *sceneGraphConstraint ); - - // Keep a raw-pointer to the scene-graph constraint - mSceneGraphConstraint = sceneGraphConstraint; + mSceneGraphConstraint = SceneGraph::Constraint< PropertyType, TransformManagerPropertyAccessor >::New( *targetProperty, + propertyOwners, + func, + mRemoveAction ); + // Don't create a resetter for transform manager property, it's less efficient } else //SceneGraph property { // Connect the constraint - SceneGraph::ConstraintBase* sceneGraphConstraint = SceneGraphConstraint::New( *targetProperty, - propertyOwners, - func ); - DALI_ASSERT_DEBUG( NULL != sceneGraphConstraint ); - sceneGraphConstraint->SetRemoveAction( mRemoveAction ); - - // object is being used in a separate thread; queue a message to apply the constraint - ApplyConstraintMessage( GetEventThreadServices(), *targetObject, *sceneGraphConstraint ); - - // Keep a raw-pointer to the scene-graph constraint - mSceneGraphConstraint = sceneGraphConstraint; + mSceneGraphConstraint = SceneGraph::Constraint< PropertyType, PropertyAccessor >::New( *targetProperty, + propertyOwners, + func, + mRemoveAction ); + resetter = SceneGraph::ConstraintResetter::New( targetObject, *targetProperty, *mSceneGraphConstraint ); + } + OwnerPointer< SceneGraph::ConstraintBase > transferOwnership( const_cast< SceneGraph::ConstraintBase* >( mSceneGraphConstraint ) ); + ApplyConstraintMessage( GetEventThreadServices(), targetObject, transferOwnership ); + if( resetter ) + { + AddResetterMessage( GetEventThreadServices().GetUpdateManager(), resetter ); } } } @@ -207,82 +165,27 @@ private: * Helper for ConnectConstraint. Creates a connected constraint-function. * Also populates the property-owner container, for each input connected to the constraint-function. * @param[out] propertyOwners The container of property-owners providing the scene-graph properties. - * @return A connected constraint-function, or NULL if the scene-graph properties are not available. + * @return A connected constraint-function, or nullptr if the scene-graph properties are not available. */ PropertyConstraint* ConnectConstraintFunction( SceneGraph::PropertyOwnerContainer& propertyOwners ) { PropertyConstraint* func = mUserFunction->Clone(); - for ( SourceIter iter = mSources.begin(); mSources.end() != iter; ++iter ) + for ( auto&& source : mSources ) { - Source& source = *iter; - - PropertyInputImpl* inputProperty( NULL ); - int componentIndex( Property::INVALID_COMPONENT_INDEX ); - - if ( OBJECT_PROPERTY == source.sourceType ) - { - DALI_ASSERT_ALWAYS( source.object->IsPropertyAConstraintInput( source.propertyIndex ) ); - - SceneGraph::PropertyOwner* owner = const_cast< SceneGraph::PropertyOwner* >( source.object->GetSceneObject() ); - - // The property owner will not exist, if the target object is off-stage - if( NULL != owner ) - { - AddUnique( propertyOwners, owner ); - inputProperty = const_cast< PropertyInputImpl* >( source.object->GetSceneObjectInputProperty( source.propertyIndex ) ); - componentIndex = source.object->GetPropertyComponentIndex( source.propertyIndex ); - - // The scene-object property should exist, when the property owner exists - DALI_ASSERT_ALWAYS( NULL != inputProperty && "Constraint source property does not exist" ); - } - } - else if ( LOCAL_PROPERTY == source.sourceType ) - { - DALI_ASSERT_ALWAYS( mTargetObject->IsPropertyAConstraintInput( source.propertyIndex ) ); - - inputProperty = const_cast< PropertyInputImpl* >( mTargetObject->GetSceneObjectInputProperty( source.propertyIndex ) ); - componentIndex = mTargetObject->GetPropertyComponentIndex( source.propertyIndex ); - - // The target scene-object should provide this property - DALI_ASSERT_ALWAYS( NULL != inputProperty && "Constraint source property does not exist" ); - } - else - { - DALI_ASSERT_ALWAYS( PARENT_PROPERTY == source.sourceType && "Constraint source property type is invalid" ); - - Object* objectParent = dynamic_cast< Actor& >( *mTargetObject ).GetParent(); - - // This will not exist, if the target object is off-stage - if ( NULL != objectParent ) - { - DALI_ASSERT_ALWAYS( objectParent->IsPropertyAConstraintInput( source.propertyIndex ) ); - - SceneGraph::PropertyOwner* owner = const_cast< SceneGraph::PropertyOwner* >( objectParent->GetSceneObject() ); - - // The property owner will not exist, if the parent object is off-stage - if ( NULL != owner ) - { - AddUnique( propertyOwners, owner ); - inputProperty = const_cast< PropertyInputImpl* >( objectParent->GetSceneObjectInputProperty( source.propertyIndex ) ); - componentIndex = objectParent->GetPropertyComponentIndex( source.propertyIndex ); + int32_t componentIndex = Property::INVALID_COMPONENT_INDEX; + PropertyInputImpl* inputProperty = AddInputProperty( source, propertyOwners, componentIndex ); - // The scene-object property should exist, when the property owner exists - DALI_ASSERT_ALWAYS( NULL != inputProperty && "Constraint source property does not exist" ); - } - } - } - - if ( NULL == inputProperty ) + if ( nullptr == inputProperty ) { delete func; - func = NULL; + func = nullptr; // Exit if a scene-graph object is not available from one of the sources break; } - func->SetInput( ( iter - mSources.begin() ), componentIndex, *inputProperty ); + func->AddInput( inputProperty, componentIndex ); } return func; @@ -290,20 +193,19 @@ private: protected: - Property::Index mTargetIndex; - ConstraintFunctionPtr mUserFunction; + }; /** - * Variant which allows float components to be animated individually. + * Variant which allows float components to be constrained individually. */ template <> class Constraint : public ConstraintBase { public: - typedef typename PropertyConstraintPtr::Type ConstraintFunctionPtr; + using ConstraintFunctionPtr = typename PropertyConstraintPtr::Type; /** * Construct a new constraint. @@ -318,29 +220,7 @@ public: SourceContainer& sources, ConstraintFunctionPtr func ) { - return new Constraint< float >( object, targetIndex, sources, func ); - } - - /** - * @copydoc ConstraintBase::Clone() - */ - virtual ConstraintBase* Clone( Object& object ) - { - DALI_ASSERT_ALWAYS( !mSourceDestroyed && "An input source object has been destroyed" ); - - ConstraintBase* clone( NULL ); - - ConstraintFunctionPtr funcPtr( mUserFunction->Clone() ); - - clone = new Constraint< float >( object, - mTargetIndex, - mSources, - funcPtr ); - - clone->SetRemoveAction(mRemoveAction); - clone->SetTag( mTag ); - - return clone; + return new Constraint( object, targetIndex, sources, func ); } /** @@ -354,6 +234,18 @@ public: private: /** + * @copydoc ConstraintBase::DoClone() + */ + virtual ConstraintBase* DoClone( Object& object ) override final + { + ConstraintFunctionPtr funcPtr( mUserFunction->Clone() ); + return new Constraint( object, + mTargetPropertyIndex, + mSources, + funcPtr ); + } + + /** * Private constructor; see also Constraint::New(). */ Constraint( Object& object, @@ -361,38 +253,30 @@ private: SourceContainer& sources, ConstraintFunctionPtr& func ) : ConstraintBase( object, targetIndex, sources ), - mTargetIndex( targetIndex ), mUserFunction( func ) { } // Undefined - Constraint( const Constraint& ); - - // Undefined - Constraint& operator=( const Constraint& rhs ); + Constraint() = delete; + Constraint( const Constraint& ) = delete; + Constraint& operator=( const Constraint& rhs ) = delete; /** - * Create and connect a constraint for a scene-object. + * @copydoc ConstraintBase::ConnectConstraint() */ - void ConnectConstraint() + void ConnectConstraint() override final { - // Should not come here if target-object has been destroyed - DALI_ASSERT_DEBUG( NULL != mTargetObject ); - + // Should not come here if target object has been destroyed + DALI_ASSERT_DEBUG( nullptr != mTargetObject ); // Guard against double connections - DALI_ASSERT_DEBUG( NULL == mSceneGraphConstraint ); + DALI_ASSERT_DEBUG( nullptr == mSceneGraphConstraint ); - // Short-circuit until the target scene-object exists - SceneGraph::PropertyOwner* targetObject = const_cast< SceneGraph::PropertyOwner* >( mTargetObject->GetSceneObject() ); - if ( NULL == targetObject ) - { - return; - } + SceneGraph::PropertyOwner& targetObject = const_cast< SceneGraph::PropertyOwner& >( mTargetObject->GetSceneObject() ); // Build a container of property-owners, providing the scene-graph properties SceneGraph::PropertyOwnerContainer propertyOwners; - propertyOwners.PushBack( targetObject ); + propertyOwners.PushBack( &targetObject ); // Build the constraint function; this requires a scene-graph property from each source ConstraintFunctionPtr func( ConnectConstraintFunction( propertyOwners ) ); @@ -400,45 +284,34 @@ private: if ( func ) { // Create the SceneGraphConstraint, and connect to the scene-graph - - const SceneGraph::PropertyBase* targetProperty = mTargetObject->GetSceneObjectAnimatableProperty( mTargetIndex ); - + bool resetterRequired = false; + const SceneGraph::PropertyBase* targetProperty = mTargetObject->GetSceneObjectAnimatableProperty( mTargetPropertyIndex ); // The targetProperty should exist, when targetObject exists - DALI_ASSERT_ALWAYS( NULL != targetProperty && "Constraint target property does not exist" ); - - const int componentIndex = mTargetObject->GetPropertyComponentIndex( mTargetIndex ); - - SceneGraph::ConstraintBase* sceneGraphConstraint( NULL ); - + DALI_ASSERT_ALWAYS( nullptr != targetProperty && "Constraint target property does not exist" ); + const int32_t componentIndex = mTargetObject->GetPropertyComponentIndex( mTargetPropertyIndex ); if ( Property::INVALID_COMPONENT_INDEX == componentIndex ) { // Not a Vector2, Vector3 or Vector4 component, expecting float type DALI_ASSERT_DEBUG( PropertyTypes::Get< float >() == targetProperty->GetType() ); - typedef SceneGraph::Constraint< float, PropertyAccessor > SceneGraphConstraint; - - sceneGraphConstraint = SceneGraphConstraint::New( *targetProperty, - propertyOwners, - func ); + mSceneGraphConstraint = SceneGraph::Constraint< float, PropertyAccessor >::New( *targetProperty, propertyOwners, func, mRemoveAction ); + resetterRequired = true; } else { // Expecting Vector2, Vector3 or Vector4 type - if ( PropertyTypes::Get< Vector2 >() == targetProperty->GetType() ) { // Constrain float component of Vector2 property - if ( 0 == componentIndex ) { - typedef SceneGraph::Constraint< float, PropertyComponentAccessorX > SceneGraphConstraint; - sceneGraphConstraint = SceneGraphConstraint::New( *targetProperty, propertyOwners, func ); + mSceneGraphConstraint = SceneGraph::Constraint< float, PropertyComponentAccessorX >::New( *targetProperty, propertyOwners, func, mRemoveAction ); } else if ( 1 == componentIndex ) { - typedef SceneGraph::Constraint< float, PropertyComponentAccessorY > SceneGraphConstraint; - sceneGraphConstraint = SceneGraphConstraint::New( *targetProperty, propertyOwners, func ); + mSceneGraphConstraint = SceneGraph::Constraint< float, PropertyComponentAccessorY >::New( *targetProperty, propertyOwners, func, mRemoveAction ); } + resetterRequired = (mSceneGraphConstraint != nullptr); } else if ( PropertyTypes::Get< Vector3 >() == targetProperty->GetType() ) { @@ -447,74 +320,77 @@ private: { if ( 0 == componentIndex ) { - typedef SceneGraph::Constraint< float, TransformManagerPropertyComponentAccessor > SceneGraphConstraint; - sceneGraphConstraint = SceneGraphConstraint::New( *targetProperty, propertyOwners, func ); + mSceneGraphConstraint = SceneGraph::Constraint< float, TransformManagerPropertyComponentAccessor >::New( *targetProperty, + propertyOwners, + func, + mRemoveAction ); } else if ( 1 == componentIndex ) { - typedef SceneGraph::Constraint< float, TransformManagerPropertyComponentAccessor > SceneGraphConstraint; - sceneGraphConstraint = SceneGraphConstraint::New( *targetProperty, propertyOwners, func ); + mSceneGraphConstraint = SceneGraph::Constraint< float, TransformManagerPropertyComponentAccessor >::New( *targetProperty, + propertyOwners, + func, + mRemoveAction ); } else if ( 2 == componentIndex ) { - typedef SceneGraph::Constraint< float, TransformManagerPropertyComponentAccessor > SceneGraphConstraint; - sceneGraphConstraint = SceneGraphConstraint::New( *targetProperty, propertyOwners, func ); + mSceneGraphConstraint = SceneGraph::Constraint< float, TransformManagerPropertyComponentAccessor >::New( *targetProperty, + propertyOwners, + func, + mRemoveAction ); } + // Do not create a resetter for transform manager property } else { if ( 0 == componentIndex ) { - typedef SceneGraph::Constraint< float, PropertyComponentAccessorX > SceneGraphConstraint; - sceneGraphConstraint = SceneGraphConstraint::New( *targetProperty, propertyOwners, func ); + mSceneGraphConstraint = SceneGraph::Constraint< float, PropertyComponentAccessorX >::New( *targetProperty, propertyOwners, func, mRemoveAction ); } else if ( 1 == componentIndex ) { - typedef SceneGraph::Constraint< float, PropertyComponentAccessorY > SceneGraphConstraint; - sceneGraphConstraint = SceneGraphConstraint::New( *targetProperty, propertyOwners, func ); + mSceneGraphConstraint = SceneGraph::Constraint< float, PropertyComponentAccessorY >::New( *targetProperty, propertyOwners, func, mRemoveAction ); } else if ( 2 == componentIndex ) { - typedef SceneGraph::Constraint< float, PropertyComponentAccessorZ > SceneGraphConstraint; - sceneGraphConstraint = SceneGraphConstraint::New( *targetProperty, propertyOwners, func ); + mSceneGraphConstraint = SceneGraph::Constraint< float, PropertyComponentAccessorZ >::New( *targetProperty, propertyOwners, func, mRemoveAction ); } + resetterRequired = (mSceneGraphConstraint != nullptr); } } else if ( PropertyTypes::Get< Vector4 >() == targetProperty->GetType() ) { // Constrain float component of Vector4 property - if ( 0 == componentIndex ) { - typedef SceneGraph::Constraint< float, PropertyComponentAccessorX > SceneGraphConstraint; - sceneGraphConstraint = SceneGraphConstraint::New( *targetProperty, propertyOwners, func ); + mSceneGraphConstraint = SceneGraph::Constraint< float, PropertyComponentAccessorX >::New( *targetProperty, propertyOwners, func, mRemoveAction ); } else if ( 1 == componentIndex ) { - typedef SceneGraph::Constraint< float, PropertyComponentAccessorY > SceneGraphConstraint; - sceneGraphConstraint = SceneGraphConstraint::New( *targetProperty, propertyOwners, func ); + mSceneGraphConstraint = SceneGraph::Constraint< float, PropertyComponentAccessorY >::New( *targetProperty, propertyOwners, func, mRemoveAction ); } else if ( 2 == componentIndex ) { - typedef SceneGraph::Constraint< float, PropertyComponentAccessorZ > SceneGraphConstraint; - sceneGraphConstraint = SceneGraphConstraint::New( *targetProperty, propertyOwners, func ); + mSceneGraphConstraint = SceneGraph::Constraint< float, PropertyComponentAccessorZ >::New( *targetProperty, propertyOwners, func, mRemoveAction ); } else if ( 3 == componentIndex ) { - typedef SceneGraph::Constraint< float, PropertyComponentAccessorW > SceneGraphConstraint; - sceneGraphConstraint = SceneGraphConstraint::New( *targetProperty, propertyOwners, func ); + mSceneGraphConstraint = SceneGraph::Constraint< float, PropertyComponentAccessorW >::New( *targetProperty, propertyOwners, func, mRemoveAction ); } + + resetterRequired = (mSceneGraphConstraint != nullptr); + } + } + if( mSceneGraphConstraint ) + { + OwnerPointer< SceneGraph::ConstraintBase > transferOwnership( const_cast< SceneGraph::ConstraintBase* >( mSceneGraphConstraint ) ); + ApplyConstraintMessage( GetEventThreadServices(), targetObject, transferOwnership ); + if( resetterRequired ) + { + OwnerPointer resetter = SceneGraph::ConstraintResetter::New( targetObject, *targetProperty, *mSceneGraphConstraint ); + AddResetterMessage( GetEventThreadServices().GetUpdateManager(), resetter ); } } - - DALI_ASSERT_DEBUG( NULL != sceneGraphConstraint ); - sceneGraphConstraint->SetRemoveAction( mRemoveAction ); - - // object is being used in a separate thread; queue a message to apply the constraint - ApplyConstraintMessage( GetEventThreadServices(), *targetObject, *sceneGraphConstraint ); - - // Keep a raw-pointer to the scene-graph constraint - mSceneGraphConstraint = sceneGraphConstraint; } } @@ -522,82 +398,27 @@ private: * Helper for ConnectConstraint. Creates a connected constraint-function. * Also populates the property-owner container, for each input connected to the constraint-function. * @param[out] propertyOwners The container of property-owners providing the scene-graph properties. - * @return A connected constraint-function, or NULL if the scene-graph properties are not available. + * @return A connected constraint-function, or nullptr if the scene-graph properties are not available. */ PropertyConstraint* ConnectConstraintFunction( SceneGraph::PropertyOwnerContainer& propertyOwners ) { PropertyConstraint* func = mUserFunction->Clone(); - for ( SourceIter iter = mSources.begin(); mSources.end() != iter; ++iter ) + for ( auto&& source : mSources ) { - Source& source = *iter; - - PropertyInputImpl* inputProperty( NULL ); - int componentIndex( Property::INVALID_COMPONENT_INDEX ); - - if ( OBJECT_PROPERTY == source.sourceType ) - { - DALI_ASSERT_ALWAYS( source.object->IsPropertyAConstraintInput( source.propertyIndex ) ); - - SceneGraph::PropertyOwner* owner = const_cast< SceneGraph::PropertyOwner* >( source.object->GetSceneObject() ); - - // The property owner will not exist, if the target object is off-stage - if( NULL != owner ) - { - AddUnique( propertyOwners, owner ); - inputProperty = const_cast< PropertyInputImpl* >( source.object->GetSceneObjectInputProperty( source.propertyIndex ) ); - componentIndex = source.object->GetPropertyComponentIndex( source.propertyIndex ); - - // The scene-object property should exist, when the property owner exists - DALI_ASSERT_ALWAYS( NULL != inputProperty && "Constraint source property does not exist" ); - } - } - else if ( LOCAL_PROPERTY == source.sourceType ) - { - DALI_ASSERT_ALWAYS( mTargetObject->IsPropertyAConstraintInput( source.propertyIndex ) ); - - inputProperty = const_cast< PropertyInputImpl* >( mTargetObject->GetSceneObjectInputProperty( source.propertyIndex ) ); - componentIndex = mTargetObject->GetPropertyComponentIndex( source.propertyIndex ); + int32_t componentIndex = Property::INVALID_COMPONENT_INDEX; + PropertyInputImpl* inputProperty = AddInputProperty( source, propertyOwners, componentIndex ); - // The target scene-object should provide this property - DALI_ASSERT_ALWAYS( NULL != inputProperty && "Constraint source property does not exist" ); - } - else - { - DALI_ASSERT_ALWAYS( PARENT_PROPERTY == source.sourceType && "Constraint source property type is invalid" ); - - Object* objectParent = dynamic_cast< Actor& >( *mTargetObject ).GetParent(); - - // This will not exist, if the target object is off-stage - if ( NULL != objectParent ) - { - DALI_ASSERT_ALWAYS( objectParent->IsPropertyAConstraintInput( source.propertyIndex ) ); - - SceneGraph::PropertyOwner* owner = const_cast< SceneGraph::PropertyOwner* >( objectParent->GetSceneObject() ); - - // The property owner will not exist, if the parent object is off-stage - if ( NULL != owner ) - { - AddUnique( propertyOwners, owner ); - inputProperty = const_cast< PropertyInputImpl* >( objectParent->GetSceneObjectInputProperty( source.propertyIndex ) ); - componentIndex = objectParent->GetPropertyComponentIndex( source.propertyIndex ); - - // The scene-object property should exist, when the property owner exists - DALI_ASSERT_ALWAYS( NULL != inputProperty && "Constraint source property does not exist" ); - } - } - } - - if ( NULL == inputProperty ) + if ( nullptr == inputProperty ) { delete func; - func = NULL; + func = nullptr; // Exit if a scene-graph object is not available from one of the sources break; } - func->SetInput( ( iter - mSources.begin() ), componentIndex, *inputProperty ); + func->AddInput( inputProperty, componentIndex ); } return func; @@ -605,13 +426,12 @@ private: protected: - Property::Index mTargetIndex; - ConstraintFunctionPtr mUserFunction; + }; } // namespace Internal } // namespace Dali -#endif // __DALI_INTERNAL_ACTIVE_CONSTRAINT_H__ +#endif // DALI_INTERNAL_ACTIVE_CONSTRAINT_H