License conversion from Flora to Apache 2.0
[platform/core/uifw/dali-core.git] / capi / dali / public-api / animation / constraints.h
1 #ifndef __DALI_CONSTRAINTS_H__
2 #define __DALI_CONSTRAINTS_H__
3
4 /*
5  * Copyright (c) 2014 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 /**
22  * @addtogroup CAPI_DALI_ANIMATION_MODULE
23  * @{
24  */
25
26 // INTERNAL INCLUDES
27 #include <dali/public-api/math/vector3.h>
28 #include <dali/public-api/math/quaternion.h>
29
30 namespace Dali DALI_IMPORT_API
31 {
32
33 class PropertyInput;
34 class Quaternion;
35 class Matrix;
36 class Matrix3;
37
38 /**
39  * @brief Scale To Fit constraint.
40  *
41  * Scales an Actor, such that it fits within it's Parent's Size.
42  * f(current, size, parentSize) = parentSize / size
43  */
44 struct DALI_IMPORT_API ScaleToFitConstraint
45 {
46   /**
47    * @brief Constructor.
48    */
49   ScaleToFitConstraint();
50
51   /**
52    * @brief Functor operator
53    *
54    * @param[in] current The actor's current scale
55    * @param[in] sizeProperty The actor's current size
56    * @param[in] parentSizeProperty The parent's current size.
57    * @return The actor's new scale
58    */
59   Vector3 operator()(const Vector3&    current,
60                      const PropertyInput& sizeProperty,
61                      const PropertyInput& parentSizeProperty);
62
63 };
64
65 /**
66  * @brief Scale To Fit Keep Aspect Ratio constraint.
67  *
68  * Scales an Actor, such that it fits within its Parent's Size Keeping the aspect ratio.
69  * f(current, size, parentSize) = Vector3( min( parentSizeX / sizeX, min( parentSizeY / sizeY, parentSizeZ / sizeZ ) )
70  */
71 struct DALI_IMPORT_API ScaleToFitKeepAspectRatioConstraint
72 {
73   /**
74    * @brief Constructor.
75    */
76   ScaleToFitKeepAspectRatioConstraint();
77
78   /**
79    * @brief Functor operator
80    *
81    * @param[in] current The actor's current scale
82    * @param[in] sizeProperty The actor's current size
83    * @param[in] parentSizeProperty The parent's current size.
84    * @return The actor's new scale
85    */
86   Vector3 operator()(const Vector3&    current,
87                      const PropertyInput& sizeProperty,
88                      const PropertyInput& parentSizeProperty);
89 };
90
91 /**
92  * @brief Scale To Fill Keep Aspect Ratio constraint.
93  *
94  * Scales an Actor, such that it fill its Parent's Size Keeping the aspect ratio.
95  * f(current, size, parentSize) = Vector3( max( parentSizeX / sizeX, max( parentSizeY / sizeY, parentSizeZ / sizeZ ) )
96  */
97 struct DALI_IMPORT_API ScaleToFillKeepAspectRatioConstraint
98 {
99   /**
100    * @brief Constructor.
101    */
102   ScaleToFillKeepAspectRatioConstraint();
103
104   /**
105    * @param[in] current The actor's current scale
106    * @param[in] sizeProperty The actor's current size
107    * @param[in] parentSizeProperty The parent's current size.
108    * @return The actor's new scale
109    */
110   Vector3 operator()(const Vector3&    current,
111                      const PropertyInput& sizeProperty,
112                      const PropertyInput& parentSizeProperty);
113 };
114
115 /**
116  * @brief Scale To Fill XY Keep Aspect Ratio constraint.
117  *
118  * Scales an Actor, such that it fill its Parent's Size in the X and Y coordinates Keeping the aspect ratio.
119  * f(current, size, parentSize) = Vector3( max( parentSizeX / sizeX, max( parentSizeY / sizeY, parentSizeZ / sizeZ ) )
120  */
121 struct DALI_IMPORT_API ScaleToFillXYKeepAspectRatioConstraint
122 {
123   /**
124    * @brief Constructor.
125    */
126   ScaleToFillXYKeepAspectRatioConstraint();
127
128   /**
129    * @param[in] current The actor's current scale
130    * @param[in] sizeProperty The actor's current size
131    * @param[in] parentSizeProperty The parent's current size.
132    * @return The actor's new scale
133    */
134   Vector3 operator()(const Vector3&    current,
135                      const PropertyInput& sizeProperty,
136                      const PropertyInput& parentSizeProperty);
137 };
138
139 /**
140  * @brief Shrinks source size inside the target size maintaining aspect ratio of source.
141  * If source is smaller than target it returns source
142  */
143 struct ShrinkInsideKeepAspectRatioConstraint
144 {
145   /**
146    * @brief Constructor.
147    */
148   ShrinkInsideKeepAspectRatioConstraint();
149
150   /**
151    * @param[in] current The actor's current scale
152    * @param[in] sizeProperty The actor's current size
153    * @param[in] parentSizeProperty The parent's current size.
154    * @return The actor's new scale
155    */
156   Vector3 operator()(const Vector3&    current,
157                      const PropertyInput& sizeProperty,
158                      const PropertyInput& parentSizeProperty);
159 };
160
161 /**
162  * @brief MultiplyConstraint
163  *
164  * f(current, property) = current * property
165  */
166 struct DALI_IMPORT_API MultiplyConstraint
167 {
168   /**
169    * @brief Constructor.
170    */
171   MultiplyConstraint();
172
173   /**
174    * @param[in] current The object's current property value
175    * @param[in] property The property to multiply by.
176    * @return The object's new property value
177    */
178   Vector3 operator()(const Vector3&    current,
179                      const PropertyInput& property);
180 };
181
182 /**
183  * @brief DivideConstraint
184  *
185  * f(current, property) = current / property
186  */
187 struct DALI_IMPORT_API DivideConstraint
188 {
189   /**
190    * @brief Constructor.
191    */
192   DivideConstraint();
193
194   /**
195    * @param[in] current The object's current property value
196    * @param[in] property The property to divide by.
197    * @return The object's new property value
198    */
199   Vector3 operator()(const Vector3&    current,
200                      const PropertyInput& property);
201 };
202
203 /**
204  * @brief EqualToConstraint
205  *
206  * f(current, property) = property
207  */
208 struct DALI_IMPORT_API EqualToConstraint
209 {
210   /**
211    * @brief Constructor.
212    */
213   EqualToConstraint();
214
215   /**
216    * @brief override functor for float properties
217    *
218    * @param[in] current The current property value
219    * @param[in] property The property to copy
220    * @return The copy of the input property
221    */
222   float operator()(const float current, const PropertyInput& property);
223
224   /**
225    * @brief override functor for float properties
226    *
227    * @param[in] current The current property value
228    * @param[in] property The property to copy
229    * @return The copy of the input property
230    */
231   Vector3 operator()(const Vector3& current, const PropertyInput& property);
232
233   /**
234    * @brief override functor for float properties
235    *
236    * @param[in] current The current property value
237    * @param[in] property The property to copy
238    * @return The copy of the input property
239    */
240   Vector4 operator()(const Vector4& current, const PropertyInput& property);
241
242   /**
243    * @brief override functor for float properties
244    *
245    * @param[in] current The current property value
246    * @param[in] property The property to copy
247    * @return The copy of the input property
248    */
249   Quaternion operator()(const Quaternion& current, const PropertyInput& property);
250
251   /**
252    * @brief override functor for float properties
253    *
254    * @param[in] current The current property value
255    * @param[in] property The property to copy
256    * @return The copy of the input property
257    */
258   Matrix3 operator()(const Matrix3& current, const PropertyInput& property);
259
260   /**
261    * @brief override functor for float properties
262    *
263    * @param[in] current The current property value
264    * @param[in] property The property to copy
265    * @return The copy of the input property
266    */
267   Matrix operator()(const Matrix& current, const PropertyInput& property);
268 };
269
270 /**
271  * @brief RelativeToConstraint for Vector3 properties
272  *
273  * f(current, property, scale) = property * scale
274  */
275 struct DALI_IMPORT_API RelativeToConstraint
276 {
277   /**
278    * @brief Constructor.
279    */
280   RelativeToConstraint( float scale );
281
282   /**
283    * @brief Constructor.
284    */
285   RelativeToConstraint( const Vector3& scale );
286
287   /**
288    * @brief Functor.
289    */
290   Vector3 operator()(const Vector3& current, const PropertyInput& property);
291
292   Vector3 mScale; ///< Component-wise scale factor
293 };
294
295 /**
296  * @brief RelativeToConstraint for float properties
297  */
298 struct DALI_IMPORT_API RelativeToConstraintFloat
299 {
300   /**
301    * @brief Constructor.
302    */
303   RelativeToConstraintFloat( float scale );
304
305   /**
306    * @brief Functor.
307    */
308   float operator()(const float current, const PropertyInput& property);
309
310   float mScale; ///< Scale factor
311 };
312
313 /**
314  * @brief InverseOfConstraint
315  *
316  * f(current, property) = 1 / property
317  */
318 struct DALI_IMPORT_API InverseOfConstraint
319 {
320   /**
321    * @brief Constructor.
322    */
323   InverseOfConstraint();
324
325   /**
326    * @brief Functor.
327    */
328   Vector3 operator()(const Vector3&    current,
329                      const PropertyInput& property);
330 };
331
332 /**
333  * @brief Constraint which sets width to be another actor's width,
334  * and the height to a fixed height.
335  */
336 struct DALI_IMPORT_API SourceWidthFixedHeight
337 {
338   /**
339    * @brief Constructor.
340    */
341   SourceWidthFixedHeight( float height );
342
343   /**
344    * @brief Functor.
345    */
346   Vector3 operator()(const Vector3& current,
347                      const PropertyInput& sourceSize);
348
349   float mFixedHeight; ///< the fixed height
350 };
351
352 /**
353  * @brief Constraint which sets height to be another actor's height,
354  * and the width to a fixed width.
355  */
356 struct DALI_IMPORT_API SourceHeightFixedWidth
357 {
358   /**
359    * @brief Constructor
360    */
361   SourceHeightFixedWidth( float width );
362
363   /**
364    * @brief Functor
365    */
366   Vector3 operator()(const Vector3& current,
367                      const PropertyInput& sourceSize);
368
369   float mFixedWidth; ///< the fixed width
370 };
371
372 /**
373  * @brief Constraint function to aim a camera at a target.
374  *
375  * Constraint which sets camera's rotation given camera world position
376  * and a target world position.  Uses target's up vector to orient the
377  * constrained actor along the vector between camera position and
378  * target position.
379  *
380  * @param[in] current The current rotation property value
381  * @param[in] targetPosition World position of target
382  * @param[in] cameraPosition World position of camera
383  * @param[in] targetRotation World rotation of the target
384  * @return The orientation of the camera
385  */
386 DALI_IMPORT_API Dali::Quaternion LookAt( const Dali::Quaternion& current,
387                                          const PropertyInput& targetPosition,
388                                          const PropertyInput& cameraPosition,
389                                          const PropertyInput& targetRotation );
390
391
392 /**
393  * @brief Constraint functor to aim a camera at a target.
394  *
395  * Constraint which sets rotation given camera world position,
396  * target world position (usually the looked at actor's world position)
397  * and the angle parameter (how much the camera is offset with respect
398  * to the target's up vector).
399  */
400 struct DALI_IMPORT_API OrientedLookAt
401 {
402   /**
403    * @brief Functor constructor.
404    *
405    * @param[in] angle The angle of the camera's up vector with regards
406    * to the target's up vector in radians. Positive angles rotate the
407    * camera clockwise, negative angles rotate anti-clockwise.
408    */
409   OrientedLookAt( float angle );
410
411   /**
412    * @brief Functor.
413    *
414    * @param[in] current The current rotation property value
415    * @param[in] targetPosition World position of target
416    * @param[in] cameraPosition World position of camera
417    * @param[in] targetRotation World rotation of the target
418    * @return The orientation of the camera
419    */
420   Dali::Quaternion operator()(const Dali::Quaternion& current,
421                               const PropertyInput& targetPosition,
422                               const PropertyInput& cameraPosition,
423                               const PropertyInput& targetRotation );
424
425   float mAngle; ///< camera angle offset
426 };
427
428
429 } // namespace Dali
430
431 /**
432  * @}
433  */
434 #endif // __DALI_CONSTRAINTS_H__