[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / public-api / model-motion / motion-value.h
1 #ifndef DALI_SCENE3D_MODEL_MOTION_MOTION_VALUE_H
2 #define DALI_SCENE3D_MODEL_MOTION_MOTION_VALUE_H
3
4 /*
5  * Copyright (c) 2023 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 <dali/public-api/animation/key-frames.h>
23 #include <dali/public-api/common/dali-common.h>
24 #include <dali/public-api/object/base-handle.h>
25 #include <dali/public-api/object/property-value.h>
26
27 // INTERNAL INCLUDES
28 #include <dali-scene3d/public-api/api.h>
29
30 namespace Dali
31 {
32 namespace Scene3D
33 {
34 //Forward declarations.
35 namespace Internal
36 {
37 class MotionValue;
38 } // namespace Internal
39
40 /**
41  * @addtogroup dali_scene3d_model_motion_motion_value
42  * @{
43  */
44
45 /**
46  * @brief This MotionValue be used for target value of each MotionIndex.
47  * We can get and set MotionValue as 2 types : Property::Value and KeyFrames.
48  *
49  * Each types will be cross-converted internally.
50  * For example, when we set Property::Value, we can get KeyFrames with 2 frames, and target value is setted.
51  *
52  * @note The type of property should be matched with MotionIndex required.
53  * @SINCE_2_2.34
54  */
55 class DALI_SCENE3D_API MotionValue : public Dali::BaseHandle
56 {
57 public:
58   /**
59    * @brief Determine whether current stored value is PropertyValue, or KeyFrames.
60    * @SINCE_2_2.34
61    */
62   enum class ValueType
63   {
64     INVALID = -1, ///< Value is null, or invalid.
65
66     PROPERTY_VALUE = 0, ///< Value is PropertyValue.
67     KEY_FRAMES,         ///< Value is KeyFrames.
68   };
69
70 public: // Creation & Destruction
71   /**
72    * @brief Create an initialized MotionValue.
73    *
74    * @SINCE_2_2.34
75    * @return A handle to a newly allocated Dali resource
76    */
77   static MotionValue New();
78
79   /**
80    * @brief Create an initialized MotionValue with Property::Value.
81    *
82    * @SINCE_2_2.34
83    * @param[in] propertyValue The static value.
84    * @return A handle to a newly allocated Dali resource
85    */
86   static MotionValue New(Property::Value propertyValue);
87
88   /**
89    * @brief Create an initialized MotionValue with KeyFrames.
90    *
91    * @SINCE_2_2.34
92    * @param[in] keyFrames The keyframes value.
93    * @return A handle to a newly allocated Dali resource
94    */
95   static MotionValue New(KeyFrames keyFrames);
96
97   /**
98    * @brief Creates an uninitialized MotionValue.
99    *
100    * Only derived versions can be instantiated. Calling member
101    * functions with an uninitialized Dali::Object is not allowed.
102    *
103    * @SINCE_2_2.34
104    */
105   MotionValue();
106
107   /**
108    * @brief Destructor.
109    *
110    * This is non-virtual since derived Handle types must not contain data or virtual methods.
111    *
112    * @SINCE_2_2.34
113    */
114   ~MotionValue();
115
116   /**
117    * @brief Copy constructor.
118    *
119    * @SINCE_2_2.34
120    * @param[in] motionValue Handle to an object
121    */
122   MotionValue(const MotionValue& motionValue);
123
124   /**
125    * @brief Move constructor
126    *
127    * @SINCE_2_2.34
128    * @param[in] rhs A reference to the moved handle
129    */
130   MotionValue(MotionValue&& rhs) noexcept;
131
132   /**
133    * @brief Assignment operator.
134    *
135    * @SINCE_2_2.34
136    * @param[in] motionValue Handle to an object
137    * @return reference to this
138    */
139   MotionValue& operator=(const MotionValue& motionValue);
140
141   /**
142    * @brief Move assignment
143    *
144    * @SINCE_2_2.34
145    * @param[in] rhs A reference to the moved handle
146    * @return A reference to this
147    */
148   MotionValue& operator=(MotionValue&& rhs) noexcept;
149
150   /**
151    * @brief Downcasts an Object handle to MotionValue.
152    *
153    * If handle points to a MotionValue, the downcast produces valid handle.
154    * If not, the returned handle is left uninitialized.
155    *
156    * @SINCE_2_2.34
157    * @param[in] handle Handle to an object
158    * @return Handle to a MotionValue or an uninitialized handle
159    */
160   static MotionValue DownCast(BaseHandle handle);
161
162 public: // Public Method
163   /**
164    * @brief Get the type of value this MotionValue hold.
165    * The type of value will be changed what we set.
166    *
167    * @SINCE_2_2.34
168    * @return Type of value.
169    */
170   ValueType GetValueType() const;
171
172   /**
173    * @brief Set the value as Property::Value type.
174    *
175    * @SINCE_2_2.34
176    * @param[in] propertyValue The static value.
177    */
178   void SetValue(Property::Value propertyValue);
179
180   /**
181    * @brief Set the value as KeyFrames type.
182    *
183    * @SINCE_2_2.34
184    * @param[in] keyFrames The keyframes value.
185    */
186   void SetValue(KeyFrames keyFrames);
187
188   /**
189    * @brief Make value as Invalid type.
190    *
191    * @SINCE_2_2.34
192    */
193   void Invalidate();
194
195   /**
196    * @brief Make value as Invalid type.
197    * @see Dali::Scene3D::MotionValue::Invalidate()
198    *
199    * @SINCE_2_2.34
200    */
201   void Clear();
202
203   /**
204    * @brief Get the value as Property::Value.
205    * If ValueType is KEY_FRAMES, it will return last value of stored KeyFrames.
206    *
207    * @SINCE_2_2.34
208    * @return Property value, or empty if it is invalid.
209    */
210   Property::Value GetPropertyValue() const;
211
212   /**
213    * @brief Get the value as KeyFrames
214    * If ValueType is PROPERTY_VALUE, it will create new KeyFrames by stored Property::Value.
215    *
216    * @SINCE_2_2.34
217    * @return Keyframes handle, or empty if it is invalid.
218    */
219   KeyFrames GetKeyFrames() const;
220
221 public: // Not intended for application developers
222   /// @cond internal
223   /**
224    * @brief Creates a handle using the Scene3D::Internal implementation.
225    *
226    * @param[in] implementation The MotionValue implementation
227    */
228   DALI_INTERNAL MotionValue(Dali::Scene3D::Internal::MotionValue* implementation);
229   /// @endcond
230 };
231
232 /**
233  * @}
234  */
235
236 } // namespace Scene3D
237
238 } // namespace Dali
239
240 #endif // DALI_SCENE3D_MODEL_MOTION_MOTION_VALUE_H