1 #ifndef DALI_INTERNAL_SCENE_GRAPH_PROPERTY_ACCESSOR_H
2 #define DALI_INTERNAL_SCENE_GRAPH_PROPERTY_ACCESSOR_H
5 * Copyright (c) 2019 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/internal/update/common/animatable-property.h>
24 #include <dali/internal/update/manager/transform-manager-property.h>
33 * A wrapper class for getting/setting a property.
34 * Animators use this instead of accessing properties directly.
36 template < typename PropertyType >
37 class PropertyAccessor
42 * Create a property component.
43 * @param [in] property The property to access.
45 PropertyAccessor( SceneGraph::PropertyBase* property )
46 : mProperty( static_cast< SceneGraph::AnimatableProperty<PropertyType>* >(property) ) // we know the type
51 * Non-virtual destructor; PropertyAccessor is not suitable as a base class.
58 * Query whether the accessor is set.
59 * @return True if set.
63 return mProperty != nullptr;
67 * Reset the property accessor
68 * @post Calling any other PropertyAccessor is invalid.
76 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
80 return mProperty->IsClean();
84 * Read access to the property.
85 * @param [in] bufferIndex The current update buffer index.
87 const PropertyType& Get( BufferIndex bufferIndex ) const
89 DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyAccessor::Get() mProperty was nullptr" );
90 return mProperty->Get( bufferIndex );
94 * @copydoc AnimatableProperty<float>::Set()
96 void Set( BufferIndex bufferIndex, const PropertyType& value ) const
98 DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyAccessor::Set() mProperty was nullptr" );
99 mProperty->Set( bufferIndex, value );
103 * @copydoc AnimatableProperty<float>::Bake()
105 void Bake( BufferIndex bufferIndex, const PropertyType& value ) const
107 DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyAccessor::Bake() mProperty was nullptr" );
108 mProperty->Bake( bufferIndex, value );
114 PropertyAccessor() = delete;
115 PropertyAccessor(const PropertyAccessor& property) = delete;
116 PropertyAccessor& operator=(const PropertyAccessor& rhs) = delete;
120 SceneGraph::AnimatableProperty<PropertyType>* mProperty; ///< The real property
125 * A wrapper class for getting/setting a transform manager property
126 * Animators use this instead of accessing properties directly.
128 template <typename T>
129 class TransformManagerPropertyAccessor
134 * Create a property component.
135 * @param [in] property The property to access.
137 TransformManagerPropertyAccessor( SceneGraph::PropertyBase* property )
138 : mProperty( static_cast< SceneGraph::TransformManagerPropertyHandler<T>* >(property) ) // we know the type
143 * Non-virtual destructor; PropertyAccessor is not suitable as a base class.
145 ~TransformManagerPropertyAccessor()
150 * Query whether the accessor is set.
151 * @return True if set.
155 return mProperty != nullptr;
159 * Reset the property accessor
160 * @post Calling any other PropertyAccessor is invalid.
168 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
172 return mProperty->IsClean();
176 * Read access to the property.
177 * @param [in] bufferIndex The current update buffer index.
178 * @return The value of the property
180 const T& Get( BufferIndex bufferIndex ) const
182 DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyAccessor::Get() mProperty was nullptr" );
183 return mProperty->Get( bufferIndex );
187 * @copydoc AnimatableProperty<float>::Set()
189 void Set( BufferIndex bufferIndex, const T& value ) const
191 DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyAccessor::Set() mProperty was nullptr" );
192 mProperty->Set( bufferIndex, value );
196 * @copydoc AnimatableProperty<float>::Bake()
198 void Bake( BufferIndex bufferIndex, const T& value ) const
200 DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyAccessor::Bake() mProperty was nullptr" );
201 mProperty->Bake( bufferIndex, value );
207 TransformManagerPropertyAccessor() = delete;
208 TransformManagerPropertyAccessor(const TransformManagerPropertyAccessor& property) = delete;
209 TransformManagerPropertyAccessor& operator=(const TransformManagerPropertyAccessor& rhs) = delete;
213 SceneGraph::TransformManagerPropertyHandler<T>* mProperty; ///< The real property
218 * A wrapper class for getting/setting a transform manager property component
219 * Animators use this instead of accessing properties directly.
221 template <typename T, uint32_t COMPONENT>
222 class TransformManagerPropertyComponentAccessor
227 * Create a property component.
228 * @param [in] property The property to access.
230 TransformManagerPropertyComponentAccessor( SceneGraph::PropertyBase* property )
231 : mProperty( static_cast< SceneGraph::TransformManagerPropertyHandler<T>* >(property) ) // we know the type
236 * Non-virtual destructor; PropertyAccessor is not suitable as a base class.
238 ~TransformManagerPropertyComponentAccessor()
243 * Query whether the accessor is set.
244 * @return True if set.
248 return mProperty != nullptr;
252 * Reset the property accessor
253 * @post Calling any other PropertyAccessor is invalid.
261 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
265 return mProperty->IsClean();
269 * Read access to the property.
270 * @param [in] bufferIndex The current update buffer index.
271 * @return The value of the component of the property
273 float Get( BufferIndex bufferIndex ) const
275 DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyAccessor::Get() mProperty was nullptr" );
276 return mProperty->GetFloatComponent( COMPONENT );
280 * @copydoc AnimatableProperty<float>::Set()
282 void Set( BufferIndex bufferIndex, float value ) const
284 DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyAccessor::Set() mProperty was nullptr" );
285 mProperty->SetFloatComponent( value, COMPONENT );
289 * @copydoc AnimatableProperty<float>::Bake()
291 void Bake( BufferIndex bufferIndex, float value ) const
293 DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyAccessor::Bake() mProperty was nullptr" );
294 mProperty->BakeFloatComponent( value, COMPONENT );
300 TransformManagerPropertyComponentAccessor() = delete;
301 TransformManagerPropertyComponentAccessor(const TransformManagerPropertyComponentAccessor& property) = delete;
302 TransformManagerPropertyComponentAccessor& operator=(const TransformManagerPropertyComponentAccessor& rhs) = delete;
306 SceneGraph::TransformManagerPropertyHandler<T>* mProperty; ///< The real property
310 } // namespace Internal
314 #endif // DALI_INTERNAL_SCENE_GRAPH_PROPERTY_ACCESSOR_H