1 #ifndef DALI_INTERNAL_SCENE_GRAPH_PROPERTY_ACCESSOR_H
2 #define DALI_INTERNAL_SCENE_GRAPH_PROPERTY_ACCESSOR_H
5 * Copyright (c) 2021 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/internal/update/common/animatable-property.h>
23 #include <dali/internal/update/manager/transform-manager-property.h>
24 #include <dali/public-api/common/dali-common.h>
31 * A wrapper class for getting/setting a property.
32 * Animators use this instead of accessing properties directly.
34 template<typename PropertyType>
35 class PropertyAccessor
39 * Create a property component.
40 * @param [in] property The property to access.
42 PropertyAccessor(SceneGraph::PropertyBase* property)
43 : mProperty(static_cast<SceneGraph::AnimatableProperty<PropertyType>*>(property)) // we know the type
48 * Non-virtual destructor; PropertyAccessor is not suitable as a base class.
50 ~PropertyAccessor() = default;
53 * Query whether the accessor is set.
54 * @return True if set.
58 return mProperty != nullptr;
62 * Reset the property accessor
63 * @post Calling any other PropertyAccessor is invalid.
71 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
75 return mProperty->IsClean();
79 * Read access to the property.
80 * @param [in] bufferIndex The current update buffer index.
82 const PropertyType& Get(BufferIndex bufferIndex) const
84 DALI_ASSERT_DEBUG(nullptr != mProperty && "PropertyAccessor::Get() mProperty was nullptr");
85 const SceneGraph::AnimatableProperty<PropertyType>* property = mProperty;
86 return property->Get(bufferIndex);
90 * @copydoc AnimatableProperty<float>::Set()
92 void Set(BufferIndex bufferIndex, const PropertyType& value) const
94 DALI_ASSERT_DEBUG(nullptr != mProperty && "PropertyAccessor::Set() mProperty was nullptr");
95 mProperty->Set(bufferIndex, value);
99 * @copydoc AnimatableProperty<float>::Bake()
101 void Bake(BufferIndex bufferIndex, const PropertyType& value) const
103 DALI_ASSERT_DEBUG(nullptr != mProperty && "PropertyAccessor::Bake() mProperty was nullptr");
104 mProperty->Bake(bufferIndex, value);
109 PropertyAccessor() = delete;
110 PropertyAccessor(const PropertyAccessor& property) = delete;
111 PropertyAccessor& operator=(const PropertyAccessor& rhs) = delete;
114 SceneGraph::AnimatableProperty<PropertyType>* mProperty; ///< The real property
118 * A wrapper class for getting/setting a transform manager property
119 * Animators use this instead of accessing properties directly.
122 class TransformManagerPropertyAccessor
126 * Create a property component.
127 * @param [in] property The property to access.
129 TransformManagerPropertyAccessor(SceneGraph::PropertyBase* property)
130 : mProperty(static_cast<SceneGraph::TransformManagerPropertyHandler<T>*>(property)) // we know the type
135 * Non-virtual destructor; PropertyAccessor is not suitable as a base class.
137 ~TransformManagerPropertyAccessor() = default;
140 * Query whether the accessor is set.
141 * @return True if set.
145 return mProperty != nullptr;
149 * Reset the property accessor
150 * @post Calling any other PropertyAccessor is invalid.
158 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
162 return mProperty->IsClean();
166 * Read access to the property.
167 * @param [in] bufferIndex The current update buffer index.
168 * @return The value of the property
170 const T& Get(BufferIndex bufferIndex) const
172 DALI_ASSERT_DEBUG(nullptr != mProperty && "PropertyAccessor::Get() mProperty was nullptr");
173 const SceneGraph::TransformManagerPropertyHandler<T>* property = mProperty;
174 return property->Get(bufferIndex);
178 * @copydoc AnimatableProperty<float>::Set()
180 void Set(BufferIndex bufferIndex, const T& value) const
182 DALI_ASSERT_DEBUG(nullptr != mProperty && "PropertyAccessor::Set() mProperty was nullptr");
183 mProperty->Set(bufferIndex, value);
187 * @copydoc AnimatableProperty<float>::Bake()
189 void Bake(BufferIndex bufferIndex, const T& value) const
191 DALI_ASSERT_DEBUG(nullptr != mProperty && "PropertyAccessor::Bake() mProperty was nullptr");
192 mProperty->Bake(bufferIndex, value);
197 TransformManagerPropertyAccessor() = delete;
198 TransformManagerPropertyAccessor(const TransformManagerPropertyAccessor& property) = delete;
199 TransformManagerPropertyAccessor& operator=(const TransformManagerPropertyAccessor& rhs) = delete;
202 SceneGraph::TransformManagerPropertyHandler<T>* mProperty; ///< The real property
206 * A wrapper class for getting/setting a transform manager property component
207 * Animators use this instead of accessing properties directly.
209 template<typename T, uint32_t COMPONENT>
210 class TransformManagerPropertyComponentAccessor
214 * Create a property component.
215 * @param [in] property The property to access.
217 TransformManagerPropertyComponentAccessor(SceneGraph::PropertyBase* property)
218 : mProperty(static_cast<SceneGraph::TransformManagerPropertyHandler<T>*>(property)) // we know the type
223 * Non-virtual destructor; PropertyAccessor is not suitable as a base class.
225 ~TransformManagerPropertyComponentAccessor() = default;
228 * Query whether the accessor is set.
229 * @return True if set.
233 return mProperty != nullptr;
237 * Reset the property accessor
238 * @post Calling any other PropertyAccessor is invalid.
246 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
250 return mProperty->IsClean();
254 * Read access to the property.
255 * @param [in] bufferIndex The current update buffer index.
256 * @return The value of the component of the property
258 float Get(BufferIndex bufferIndex) const
260 DALI_ASSERT_DEBUG(nullptr != mProperty && "PropertyAccessor::Get() mProperty was nullptr");
261 const SceneGraph::TransformManagerPropertyHandler<T>* property = mProperty;
262 return property->GetFloatComponent(COMPONENT);
266 * @copydoc AnimatableProperty<float>::Set()
268 void Set(BufferIndex bufferIndex, float value) const
270 DALI_ASSERT_DEBUG(nullptr != mProperty && "PropertyAccessor::Set() mProperty was nullptr");
271 mProperty->SetFloatComponent(value, COMPONENT);
275 * @copydoc AnimatableProperty<float>::Bake()
277 void Bake(BufferIndex bufferIndex, float value) const
279 DALI_ASSERT_DEBUG(nullptr != mProperty && "PropertyAccessor::Bake() mProperty was nullptr");
280 mProperty->BakeFloatComponent(value, COMPONENT);
285 TransformManagerPropertyComponentAccessor() = delete;
286 TransformManagerPropertyComponentAccessor(const TransformManagerPropertyComponentAccessor& property) = delete;
287 TransformManagerPropertyComponentAccessor& operator=(const TransformManagerPropertyComponentAccessor& rhs) = delete;
290 SceneGraph::TransformManagerPropertyHandler<T>* mProperty; ///< The real property
293 } // namespace Internal
297 #endif // DALI_INTERNAL_SCENE_GRAPH_PROPERTY_ACCESSOR_H