#define DALI_INTERNAL_SCENEGRAPH_PROPERTY_RESETTER_H
/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
// EXTERNAL INCLDUES
#include <cstdint> // int8_t
-#include <dali/internal/update/animation/scene-graph-animator.h>
-#include <dali/internal/update/animation/scene-graph-constraint-base.h>
#include <dali/internal/update/animation/property-accessor.h>
#include <dali/internal/update/animation/property-component-accessor.h>
+#include <dali/internal/update/animation/scene-graph-animator.h>
+#include <dali/internal/update/animation/scene-graph-constraint-base.h>
#include <dali/internal/update/common/property-owner.h>
namespace Dali
{
namespace SceneGraph
{
-
/**
* Class to reset the watched property to it's base value. Used by UpdateManager to
* reset animating and constrained properties. The derived classes AnimatorResetter and
*/
~PropertyResetterBase() override
{
- if( mPropertyOwner != nullptr )
+ if(mPropertyOwner != nullptr)
{
mPropertyOwner->RemoveObserver(*this);
}
* Reset the property to it's base value if the property owner is still alive and on stage
* @param[in] updateBufferIndex the current buffer index
*/
- void ResetToBaseValue( BufferIndex updateBufferIndex )
+ virtual void ResetToBaseValue(BufferIndex updateBufferIndex)
{
- if( mPropertyOwner != nullptr && mActive )
+ if(mPropertyOwner != nullptr && mActive)
{
// If property-owner has disconnected, start aging.
// We need to reset the property for two frames after disconnection to ensure both
// property values are set appropriately.
- if( mDisconnected )
+ if(mDisconnected)
{
--mActive;
}
- mBaseProperty->ResetToBaseValue( updateBufferIndex );
+ mBaseProperty->ResetToBaseValue(updateBufferIndex);
}
};
*
* @param[in] owner The property owner
*/
- void PropertyOwnerConnected( PropertyOwner& owner ) override
+ void PropertyOwnerConnected(PropertyOwner& owner) override
{
mDisconnected = false;
- mActive = ACTIVE;
+ mActive = ACTIVE;
}
/**
* @param[in] bufferIndex the current buffer index
* @param[in] owner The property owner
*/
- void PropertyOwnerDisconnected( BufferIndex bufferIndex, PropertyOwner& owner ) override
+ void PropertyOwnerDisconnected(BufferIndex bufferIndex, PropertyOwner& owner) override
{
mDisconnected = true;
}
* Called shortly before the propertyOwner is destroyed
* @param[in] owner The property owner
*/
- void PropertyOwnerDestroyed( PropertyOwner& owner ) override
+ void PropertyOwnerDestroyed(PropertyOwner& owner) override
{
- mDisconnected = true;
+ mDisconnected = true;
mPropertyOwner = nullptr;
// Don't need to wait another frame as the property is being destroyed
- mActive = STOPPED;
+ mActive = STOPPED;
mRunning = STOPPED;
}
*/
virtual bool IsFinished()
{
- bool finished = mRunning <= STOPPED;
- if( mRunning == AGING )
- {
- mRunning = STOPPED;
- }
- return finished;
+ return mRunning <= STOPPED;
}
-protected:
-
enum
{
STOPPED = 0,
ACTIVE = 2,
};
+protected:
/**
* Constructor
*
* @param[in] propertyOwner The property owner storing the base property
* @param[in] baseProperty The base property
*/
- PropertyResetterBase( PropertyOwner* propertyOwner,
- PropertyBase* baseProperty )
- : mPropertyOwner( propertyOwner ),
- mBaseProperty( baseProperty ),
- mRunning( ACTIVE ),
- mActive( ACTIVE ),
- mDisconnected( false )
+ PropertyResetterBase(PropertyOwner* propertyOwner,
+ PropertyBase* baseProperty)
+ : mPropertyOwner(propertyOwner),
+ mBaseProperty(baseProperty),
+ mRunning(ACTIVE),
+ mActive(ACTIVE),
+ mDisconnected(false)
{
}
PropertyOwner* mPropertyOwner; ///< The property owner
- PropertyBase* mBaseProperty; ///< The base property being animated or constrained
- int8_t mRunning; ///< Used to determine if we should finish or not, 2 if running, 1 if aging, 0 if stopped
- int8_t mActive; ///< 2 if active, 1 if aging, 0 if stopped
- bool mDisconnected; ///< True if the property owner has been disconnected
+ PropertyBase* mBaseProperty; ///< The base property being animated or constrained
+ int8_t mRunning; ///< Used to determine if we should finish or not, 2 if running, 1 if aging, 0 if stopped
+ int8_t mActive; ///< 2 if active, 1 if aging, 0 if stopped
+ bool mDisconnected; ///< True if the property owner has been disconnected
};
+class BakerResetter : public PropertyResetterBase
+{
+public:
+ enum class Lifetime
+ {
+ BAKE,
+ SET
+ };
+
+ /**
+ * New method.
+ * @param[in] propertyOwner The owner of the property
+ * @param[in] baseProperty The property being animated
+ * @param[in] lifetime How long this resetter stays alive (1 or 2 frames)
+ * @return the new property resetter
+ */
+ static PropertyResetterBase* New(const PropertyOwner& propertyOwner,
+ const PropertyBase& baseProperty,
+ Lifetime lifetime)
+ {
+ return new BakerResetter(const_cast<PropertyOwner*>(&propertyOwner),
+ const_cast<PropertyBase*>(&baseProperty),
+ lifetime);
+ }
+
+ /**
+ * Constructor
+ * @param[in] propertyOwner The owner of the property
+ * @param[in] baseProperty The property being animated
+ * @param[in] lifetime How many frames this stays alive for
+ */
+ BakerResetter(PropertyOwner* propertyOwner,
+ PropertyBase* baseProperty,
+ Lifetime lifetime)
+ : PropertyResetterBase(propertyOwner, baseProperty)
+ {
+ mRunning = lifetime == Lifetime::BAKE ? ACTIVE : AGING;
+ }
+
+ /**
+ * Virtual destructor.
+ */
+ ~BakerResetter() override = default;
+
+ /**
+ * @param updateBufferIndex
+ */
+ void ResetToBaseValue(BufferIndex updateBufferIndex) override
+ {
+ if(mPropertyOwner && mRunning > 0)
+ {
+ mRunning--;
+ mBaseProperty->ResetToBaseValue(updateBufferIndex);
+
+ // @todo Consider adding mPropertyOwner->SetUpdated(true) here.
+ }
+ }
+};
/**
* Specialization of Resetter based on templated modifier type (either Constraint or Animator)
*/
-template< typename ModifierType>
+template<typename ModifierType>
class Resetter : public PropertyResetterBase, public ModifierType::LifecycleObserver
{
public:
-
/**
* New method.
* @param[in] propertyOwner The owner of the property
* @param[in] modifier The scene-graph animator/constraint of the property
* @return the new property resetter
*/
- static PropertyResetterBase* New( const PropertyOwner& propertyOwner,
- const PropertyBase& baseProperty,
- const ModifierType& modifier )
+ static PropertyResetterBase* New(const PropertyOwner& propertyOwner,
+ const PropertyBase& baseProperty,
+ const ModifierType& modifier)
{
- return new Resetter<ModifierType>( const_cast<PropertyOwner*>( &propertyOwner ),
- const_cast<PropertyBase*>( &baseProperty ),
- const_cast<ModifierType*>( &modifier ) );
+ return new Resetter<ModifierType>(const_cast<PropertyOwner*>(&propertyOwner),
+ const_cast<PropertyBase*>(&baseProperty),
+ const_cast<ModifierType*>(&modifier));
}
/**
{
// Disconnect from modifier object. Although this resetter should match the lifecycle of the modifier object,
// there are situations where it is deleted first (e.g. if the property owner is destroyed)
- if( mModifier )
+ if(mModifier)
{
mModifier->RemoveLifecycleObserver(*this);
}
* @param[in] baseProperty The property being animated
* @param[in] modifier The scene-graph animator/constraint of the property
*/
- Resetter( PropertyOwner* propertyOwner,
- PropertyBase* baseProperty,
- ModifierType* modifier )
- : PropertyResetterBase( propertyOwner, baseProperty ),
- mModifier( modifier )
+ Resetter(PropertyOwner* propertyOwner,
+ PropertyBase* baseProperty,
+ ModifierType* modifier)
+ : PropertyResetterBase(propertyOwner, baseProperty),
+ mModifier(modifier)
{
// Track the lifecycle of the modifying object
mModifier->AddLifecycleObserver(*this);