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