X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fevent%2Fanimation%2Fanimator-connector-base.h;h=ebcc4e0d324db9904a003b5d28f9a47f28812a8a;hb=890779675a856169eb171483af614178e558d212;hp=15cee6f71d4542b7d490b29951db812c7fe1ed68;hpb=c114bfe4714e8f02c54b25e381a41d80bdcb2d93;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/event/animation/animator-connector-base.h b/dali/internal/event/animation/animator-connector-base.h index 15cee6f..ebcc4e0 100644 --- a/dali/internal/event/animation/animator-connector-base.h +++ b/dali/internal/event/animation/animator-connector-base.h @@ -2,7 +2,7 @@ #define __DALI_INTERNAL_ANIMATOR_CONNECTOR_BASE_H__ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2018 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. @@ -19,10 +19,13 @@ */ // INTERNAL INCLUDES -#include #include #include #include +#include +#include +#include + namespace Dali { @@ -33,10 +36,11 @@ namespace Internal class Animation; /** - * An abstract base class for animator connectors. + * An abstract base class to create animator connectors and property re-setters for them when needed. * * The scene-graph objects are created by a Object e.g. Actor is a proxy for SceneGraph::Node. - * AnimatorConnectorBase observes the proxy object, in order to detect when a scene-graph object is created. + * AnimatorConnectorBase observes the proxy object, in order to detect when a scene-graph object is created + * to avoid having unnecessary animations on the scene-graph and allow apps to create animations in initialisation */ class AnimatorConnectorBase: public Object::Observer { @@ -48,11 +52,14 @@ public: AnimatorConnectorBase( Object& object, Property::Index propertyIndex, - int componentIndex, + int32_t componentIndex, + Internal::AnimatorFunctionBase* animatorFunction, AlphaFunction alpha, const TimePeriod& period) - : mParent( NULL ), + : mParent( nullptr ), mObject( &object ), + mAnimator( nullptr ), + mAnimatorFunction( animatorFunction ), mAlphaFunction(alpha), mTimePeriod(period), mPropertyIndex( propertyIndex ), @@ -66,14 +73,84 @@ public: */ virtual ~AnimatorConnectorBase() { + if( mObject ) + { + mObject->RemoveObserver( *this ); + } + + // If there is not a SceneGraph::Animator, the AnimatorConnector is responsible for deleting the mAnimatorFunction + // otherwise, the animator function ownership is transferred to the SceneGraph::Animator + if( !mAnimator ) + { + delete mAnimatorFunction; + } + } + + /** + * Helper function to create a Scenegraph::Animator and PropertyResetter and add it to its correspondent + * SceneGraph::Animation. + * + * @note This function will only be called the first time the object is added to the scene or at creation time if + * the object was already in the scene + */ + void CreateAnimator() + { + DALI_ASSERT_DEBUG( mAnimator == NULL ); + DALI_ASSERT_DEBUG( mAnimatorFunction != NULL ); + DALI_ASSERT_DEBUG( mParent != NULL ); + + //Get the PropertyOwner the animator is going to animate + const SceneGraph::PropertyOwner& propertyOwner = mObject->GetSceneObject(); + + // Get SceneGraph::BaseProperty + const SceneGraph::PropertyBase* baseProperty = mObject->GetSceneObjectAnimatableProperty( mPropertyIndex ); + DALI_ASSERT_ALWAYS( baseProperty && "Property is not animatable" ); + + // Check if property is a component of another property + const int32_t componentIndex = mObject->GetPropertyComponentIndex( mPropertyIndex ); + if( componentIndex != Property::INVALID_COMPONENT_INDEX ) + { + mComponentIndex = componentIndex; + } + + // call the type specific method to create the concrete animator + bool resetterRequired = DoCreateAnimator( propertyOwner, *baseProperty ); + + DALI_ASSERT_DEBUG( mAnimator != NULL ); + + // Add the new SceneGraph::Animator to its correspondent SceneGraph::Animation via message + const SceneGraph::Animation* animation = mParent->GetSceneObject(); + DALI_ASSERT_DEBUG( NULL != animation ); + AddAnimatorMessage( mParent->GetEventThreadServices(), *animation, *mAnimator ); + + // Add the new SceneGraph::PropertyResetter to the update manager via message + if( resetterRequired ) + { + OwnerPointer resetter = SceneGraph::AnimatorResetter::New( propertyOwner, *baseProperty, *mAnimator ); + AddResetterMessage( mParent->GetEventThreadServices().GetUpdateManager(), resetter ); + } } /** + * Type specific extension of animator creation + */ + virtual bool DoCreateAnimator( const SceneGraph::PropertyOwner& propertyOwner, const SceneGraph::PropertyBase& baseProperty ) = 0; + + /** * Set the parent of the AnimatorConnector. * @pre The connector does not already have a parent. * @param [in] parent The parent object. */ - virtual void SetParent(Animation& parent) = 0; + void SetParent( Animation& parent ) + { + DALI_ASSERT_ALWAYS( mParent == NULL && "AnimationConnector already has a parent" ); + mParent = &parent; + + if( mObject ) + { + CreateAnimator(); + } + } /** * Retrieve the parent of the AnimatorConnector. @@ -94,7 +171,7 @@ public: return mPropertyIndex; } - int GetComponentIndex() const + int32_t GetComponentIndex() const { return mComponentIndex; } @@ -104,14 +181,19 @@ private: /** * From Object::Observer */ - virtual void SceneObjectAdded( Object& object ) + virtual void SceneObjectAdded( Object& object ) override final { + // If the animator has not been created yet, create it now. + if( !mAnimator && mObject ) + { + CreateAnimator(); + } } /** * From Object::Observer */ - virtual void SceneObjectRemoved( Object& object ) + virtual void SceneObjectRemoved( Object& object ) override final { } @@ -120,19 +202,21 @@ private: */ virtual void ObjectDestroyed( Object& object ) { - mObject = NULL; + mObject = nullptr; } protected: Animation* mParent; ///< The parent owns the connector. Object* mObject; ///< Not owned by the animator connector. Valid until ObjectDestroyed() is called. + SceneGraph::AnimatorBase* mAnimator; + Internal::AnimatorFunctionBase* mAnimatorFunction; ///< Owned by the animator connector until an Scenegraph::Animator is created AlphaFunction mAlphaFunction; TimePeriod mTimePeriod; Property::Index mPropertyIndex; - int mComponentIndex; + int32_t mComponentIndex; };