-#ifndef __DALI_INTERNAL_SCENE_GRAPH_CONSTRAINT_H__
-#define __DALI_INTERNAL_SCENE_GRAPH_CONSTRAINT_H__
+#ifndef DALI_INTERNAL_SCENE_GRAPH_CONSTRAINT_H
+#define DALI_INTERNAL_SCENE_GRAPH_CONSTRAINT_H
/*
- * Copyright (c) 2014 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.
{
public:
- typedef typename PropertyConstraintPtr< PropertyType >::Type ConstraintFunctionPtr;
+ using ConstraintFunctionPtr = typename PropertyConstraintPtr< PropertyType >::Type;
/**
* Create a new scene-graph constraint.
* @param[in] targetProperty The target property.
* @param[in] ownerSet A set of property owners; func is connected to the properties provided by these objects.
* @param[in] func The function to calculate the final constrained value.
+ * @param[in] removeAction Remove action to perform when constraint is removed
* @return A smart-pointer to a newly allocated constraint.
*/
static ConstraintBase* New( const PropertyBase& targetProperty,
PropertyOwnerContainer& ownerContainer,
- ConstraintFunctionPtr func )
+ ConstraintFunctionPtr func,
+ RemoveAction removeAction )
{
// Scene-graph thread can edit these objects
PropertyBase& property = const_cast< PropertyBase& >( targetProperty );
return new Constraint< PropertyType, PropertyAccessorType >( property,
ownerContainer,
- func );
+ func,
+ removeAction );
}
/**
* Virtual destructor.
*/
- virtual ~Constraint()
+ ~Constraint() override
{
}
/**
- * Query whether the constraint needs to be applied. If a constraint depends on a set of properties,
- * then it should be applied when any of those properties have changed.
- */
- bool ApplyNeeded()
- {
- if ( mFirstApply )
- {
- mFirstApply = false;
- return true;
- }
-
- if ( ! mTargetProperty.IsClean() ||
- mFunc->InputsChanged() )
- {
- return true;
- }
-
- // We don't need to reapply constraint if none of the properties changed
- return false;
- }
-
- /**
* @copydoc Dali::Internal::SceneGraph::ConstraintBase::Apply()
*/
- virtual void Apply( BufferIndex updateBufferIndex )
+ void Apply( BufferIndex updateBufferIndex ) override
{
- if ( mDisconnected )
+ if ( !mDisconnected )
{
- return; // Early-out when property owners have been disconnected
- }
-
- if ( mFunc->InputsInitialized() &&
- ApplyNeeded() )
- {
- PropertyType current = mTargetProperty.Get( updateBufferIndex );
- mFunc->Apply( updateBufferIndex, current );
-
- // Optionally bake the final value
- if ( Dali::Constraint::Bake == mRemoveAction )
+ if ( mFunc->InputsInitialized() )
{
- mTargetProperty.Bake( updateBufferIndex, current );
+ PropertyType current = mTargetProperty.Get( updateBufferIndex );
+ mFunc->Apply( updateBufferIndex, current );
+
+ // Optionally bake the final value
+ if ( Dali::Constraint::BAKE == mRemoveAction )
+ {
+ mTargetProperty.Bake( updateBufferIndex, current );
+ }
+ else
+ {
+ mTargetProperty.Set( updateBufferIndex, current );
+ }
+
+ INCREASE_COUNTER(PerformanceMonitor::CONSTRAINTS_APPLIED);
}
else
{
- mTargetProperty.Set( updateBufferIndex, current );
+ INCREASE_COUNTER(PerformanceMonitor::CONSTRAINTS_SKIPPED);
}
-
- INCREASE_COUNTER(PerformanceMonitor::CONSTRAINTS_APPLIED);
- }
- else
- {
- INCREASE_COUNTER(PerformanceMonitor::CONSTRAINTS_SKIPPED);
}
}
*/
Constraint( PropertyBase& targetProperty,
PropertyOwnerContainer& ownerContainer,
- ConstraintFunctionPtr func )
- : ConstraintBase( ownerContainer ),
+ ConstraintFunctionPtr func,
+ RemoveAction removeAction )
+ : ConstraintBase( ownerContainer, removeAction ),
mTargetProperty( &targetProperty ),
mFunc( func )
{
}
// Undefined
- Constraint( const Constraint& constraint );
-
- // Undefined
- Constraint& operator=( const Constraint& rhs );
+ Constraint() = delete;
+ Constraint( const Constraint& constraint ) = delete;
+ Constraint& operator=( const Constraint& rhs ) = delete;
/**
* @copydoc Dali::Internal::SceneGraph::ConstraintBase::OnDisconnect()
*/
- virtual void OnDisconnect()
+ void OnDisconnect() override
{
// Discard target object/property pointers
mTargetProperty.Reset();
- mFunc = NULL;
+ mFunc = nullptr;
}
protected:
PropertyAccessorType mTargetProperty; ///< Raw-pointer to the target property. Not owned.
ConstraintFunctionPtr mFunc;
+
};
} // namespace SceneGraph
} // namespace Dali
-#endif // __DALI_INTERNAL_SCENE_GRAPH_CONSTRAINT_H__
+#endif // DALI_INTERNAL_SCENE_GRAPH_CONSTRAINT_H