1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_CONSTRAINT_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_CONSTRAINT_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/public-api/common/dali-common.h>
23 #include <dali/public-api/signals/callback.h>
24 #include <dali/internal/event/animation/property-constraint-ptr.h>
25 #include <dali/internal/update/common/animatable-property.h>
26 #include <dali/internal/update/common/property-owner.h>
27 #include <dali/internal/update/animation/scene-graph-constraint-base.h>
28 #include <dali/internal/render/common/performance-monitor.h>
40 * Used to constrain a property of a scene-object.
41 * The constraint function takes another scene-object property as an input.
43 template < class PropertyType, typename PropertyAccessorType >
44 class Constraint : public ConstraintBase
48 typedef typename PropertyConstraintPtr< PropertyType >::Type ConstraintFunctionPtr;
51 * Create a new scene-graph constraint.
52 * @param[in] targetProperty The target property.
53 * @param[in] ownerSet A set of property owners; func is connected to the properties provided by these objects.
54 * @param[in] func The function to calculate the final constrained value.
55 * @return A smart-pointer to a newly allocated constraint.
57 static ConstraintBase* New( const PropertyBase& targetProperty,
58 PropertyOwnerContainer& ownerContainer,
59 ConstraintFunctionPtr func )
61 // Scene-graph thread can edit these objects
62 PropertyBase& property = const_cast< PropertyBase& >( targetProperty );
64 return new Constraint< PropertyType, PropertyAccessorType >( property,
77 * @copydoc Dali::Internal::SceneGraph::ConstraintBase::Apply()
79 virtual void Apply( BufferIndex updateBufferIndex )
83 return; // Early-out when property owners have been disconnected
86 if ( mFunc->InputsInitialized() )
88 PropertyType current = mTargetProperty.Get( updateBufferIndex );
89 mFunc->Apply( updateBufferIndex, current );
91 // Optionally bake the final value
92 if ( Dali::Constraint::Bake == mRemoveAction )
94 mTargetProperty.Bake( updateBufferIndex, current );
98 mTargetProperty.Set( updateBufferIndex, current );
101 INCREASE_COUNTER(PerformanceMonitor::CONSTRAINTS_APPLIED);
105 INCREASE_COUNTER(PerformanceMonitor::CONSTRAINTS_SKIPPED);
112 * @copydoc Dali::Internal::SceneGraph::Constraint::New()
114 Constraint( PropertyBase& targetProperty,
115 PropertyOwnerContainer& ownerContainer,
116 ConstraintFunctionPtr func )
117 : ConstraintBase( ownerContainer ),
118 mTargetProperty( &targetProperty ),
124 Constraint( const Constraint& constraint );
127 Constraint& operator=( const Constraint& rhs );
130 * @copydoc Dali::Internal::SceneGraph::ConstraintBase::OnDisconnect()
132 virtual void OnDisconnect()
134 // Discard target object/property pointers
135 mTargetProperty.Reset();
141 PropertyAccessorType mTargetProperty; ///< Raw-pointer to the target property. Not owned.
143 ConstraintFunctionPtr mFunc;
146 } // namespace SceneGraph
148 } // namespace Internal
152 #endif // __DALI_INTERNAL_SCENE_GRAPH_CONSTRAINT_H__