Add API to UpdateProxy
[platform/core/uifw/dali-core.git] / dali / devel-api / update / update-proxy.h
1 #ifndef DALI_UPDATE_PROXY_H
2 #define DALI_UPDATE_PROXY_H
3
4 /*
5  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <cstdint>
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/common/dali-common.h>
26 #include <dali/public-api/math/matrix.h>
27 #include <dali/public-api/math/vector3.h>
28
29 namespace Dali
30 {
31 namespace Internal DALI_INTERNAL
32 {
33 class UpdateProxy;
34 }
35
36 /**
37  * @brief This class is used to access data of the actors from the update-thread.
38  *
39  * The Actor API _CANNOT_ be called directly from the update-thread.
40  * This class can be used as a proxy to that required Actor data.
41  * An actor's data can be accessed using the Actor's Unique ID.
42  * The unique ID should be passed to the callback using this class in a thread-safe manner
43  * (as you cannot call Actor::GetId from the update-thread).
44  */
45 class DALI_CORE_API UpdateProxy
46 {
47 public:
48   /**
49    * @brief Given the Actor ID, this retrieves that Actor's local position.
50    * @param[in]   id        The Actor ID
51    * @param[out]  position  Set to the Actor's current position, if Actor ID is valid
52    * @return Whether the method call was successful or not.
53    */
54   bool GetPosition(uint32_t id, Vector3& position) const;
55
56   /**
57    * @brief Allows setting an Actor's local position from the Frame callback function for the current frame only.
58    * @param[in]  id        The Actor ID
59    * @param[in]  position  The position to set
60    * @return Whether the method call was successful or not.
61    * @note This will get reset to the internally calculated or previously baked value in the next frame, so will have to be set again.
62    */
63   bool SetPosition(uint32_t id, const Vector3& position);
64
65   /**
66    * @brief Allows baking an Actor's local position from the Frame callback function.
67    * @param[in]  id        The Actor ID
68    * @param[in]  position  The position to bake
69    * @return Whether the method call was successful or not.
70    * @note The value is saved so will cause undesired effects if this property is being animated.
71    */
72   bool BakePosition(uint32_t id, const Vector3& position);
73
74   /**
75    * @brief Given the Actor ID, this retrieves that Actor's size.
76    * @param[in]   id    The Actor ID
77    * @param[out]  size  Set to the Actor's current size, if Actor ID is valid
78    * @return Whether the method call was successful or not.
79    */
80   bool GetSize(uint32_t id, Vector3& size) const;
81
82   /**
83    * @brief Allows setting an Actor's size from the Frame callback function for the current frame only.
84    * @param[in]  id    The Actor ID
85    * @param[in]  size  The size to set
86    * @return Whether the method call was successful or not.
87    * @note This will get reset to the internally calculated or previously baked value in the next frame, so will have to be set again.
88    */
89   bool SetSize(uint32_t id, const Vector3& size);
90
91   /**
92    * @brief Allows baking an Actor's size from the Frame callback function.
93    * @param[in]  id    The Actor ID
94    * @param[in]  size  The size to bake
95    * @return Whether the method call was successful or not.
96    * @note The value is saved so will cause undesired effects if this property is being animated.
97    */
98   bool BakeSize(uint32_t id, const Vector3& size);
99
100   /**
101    * @brief Given the Actor ID, this retrieves that Actor's local position and size.
102    * @param[in]   id        The Actor ID
103    * @param[out]  position  Set to the Actor's current position, if Actor ID is valid
104    * @param[out]  size      Set to the Actor's current size, if Actor ID is valid
105    * @return Whether the method call was successful or not.
106    */
107   bool GetPositionAndSize(uint32_t id, Vector3& position, Vector3& size) const;
108
109   /**
110    * @brief Given the Actor ID, this retrieves that Actor's world position and size.
111    * @param[in]   id        The Actor ID
112    * @param[out]  position  Set to the Actor's current world position, if Actor ID is valid
113    * @param[out]  scale     Set to the Actor's current world scale, if Actor ID is valid
114    * @param[out]  size      Set to the Actor's current size, if Actor ID is valid
115    * @return Whether the method call was successful or not.
116    */
117   bool GetWorldPositionScaleAndSize(uint32_t id, Vector3& position, Vector3& scale, Vector3& size) const;
118
119   /**
120    * @brief Given the Actor ID, this retrieves that Actor's local scale.
121    * @param[in]   id     The Actor ID
122    * @param[out]  scale  Set to the Actor's current scale, if Actor ID is valid
123    * @return Whether the method call was successful or not.
124    */
125   bool GetScale(uint32_t id, Vector3& scale) const;
126
127   /**
128    * @brief Allows setting an Actor's local scale from the Frame callback function for the current frame only.
129    * @param[in]  id     The Actor ID
130    * @param[in]  scale  The scale to set
131    * @return Whether the method call was successful or not.
132    * @note This will get reset to the internally calculated or previously baked value in the next frame, so will have to be set again.
133    */
134   bool SetScale(uint32_t id, const Vector3& scale);
135
136   /**
137    * @brief Allows baking an Actor's local scale from the Frame callback function.
138    * @param[in]  id     The Actor ID
139    * @param[in]  scale  The scale to bake
140    * @return Whether the method call was successful or not.
141    * @note The value is saved so will cause undesired effects if this property is being animated.
142    */
143   bool BakeScale(uint32_t id, const Vector3& scale);
144
145   /**
146    * @brief Given the Actor ID, this retrieves that Actor's local color.
147    * @param[in]   id     The Actor ID
148    * @param[out]  color  Set to the Actor's current color, if Actor ID is valid
149    * @return Whether the method call was successful or not.
150    */
151   bool GetColor(uint32_t id, Vector4& color) const;
152
153   /**
154    * @brief Allows setting an Actor's local color from the Frame callback function for the current frame only.
155    * @param[in]  id     The Actor ID
156    * @param[in]  color  The color to set
157    * @return Whether the method call was successful or not.
158    * @note This will get reset to the internally calculated or previously baked value in the next frame, so will have to be set again.
159    */
160   bool SetColor(uint32_t id, const Vector4& color);
161
162   /**
163    * @brief Allows baking an Actor's local color from the Frame callback function.
164    * @param[in]  id     The Actor ID
165    * @param[in]  color  The color to bake
166    * @return Whether the method call was successful or not.
167    * @note The value is saved so will cause undesired effects if this property is being animated.
168    */
169   bool BakeColor(uint32_t id, const Vector4& color);
170
171 public: // Not intended for application developers
172   /// @cond internal
173
174   /**
175    * @brief Constructor.
176    * @param[in]  impl  A reference to the internal object.
177    */
178   DALI_INTERNAL UpdateProxy(Internal::UpdateProxy& impl);
179
180   /**
181    * @brief Destructor.
182    */
183   DALI_INTERNAL ~UpdateProxy();
184
185   // Not copyable or movable
186
187   UpdateProxy(const UpdateProxy&) = delete;            ///< Deleted copy constructor
188   UpdateProxy(UpdateProxy&&)      = delete;            ///< Deleted move constructor
189   UpdateProxy& operator=(const UpdateProxy&) = delete; ///< Deleted copy assignment operator
190   UpdateProxy& operator=(UpdateProxy&&) = delete;      ///< Deleted move assignment operator
191
192   /// @endcond
193
194 private:
195   /// @cond internal
196   Internal::UpdateProxy& mImpl;
197   /// @endcond
198 };
199
200 } // namespace Dali
201
202 #endif // DALI_UPDATE_PROXY_H