Add Layout complex animation.
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / layouting / layout-length.h
1 #ifndef DALI_TOOLKIT_DEVEL_LAYOUT_LENGTH_H
2 #define DALI_TOOLKIT_DEVEL_LAYOUT_LENGTH_H
3
4 /*
5  * Copyright (c) 2018 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 // EXTERNAL INCLUDES
21 #include <cstdint>
22 #include <cmath>
23 #include <iostream>
24
25 namespace Dali
26 {
27
28 namespace Toolkit
29 {
30
31 /**
32  * @brief A type that represents a layout length.
33  *
34  * Currently, this implies pixels, but could be extended to handle device dependent sizes, etc.
35  */
36 class LayoutLength
37 {
38 public:
39
40   /**
41    * @brief default constructor, initialises to 0
42    */
43   LayoutLength()
44   : mValue( 0 )
45   {
46   }
47
48   /**
49    * @brief constructor
50    *
51    * @param value the value to initialise with
52    */
53   LayoutLength( int value )
54   : mValue( value )
55   {
56   }
57
58   /**
59    * @brief constructor from float
60    *
61    * @param value the value to initialise with
62    */
63   LayoutLength( float value )
64   : mValue( value )
65   {
66   }
67
68   /**
69    * @brief constructor
70    *
71    * @param layoutLength the value to initialise with
72    */
73   LayoutLength( const LayoutLength& layoutLength )
74   : mValue( layoutLength.mValue )
75   {
76   }
77
78   /**
79    * @brief assignment operator
80    *
81    * @param rhs LayoutLength to assign
82    * @return reference to itself
83    */
84   LayoutLength& operator=( const LayoutLength& rhs )
85   {
86     if( this != &rhs )
87     {
88       mValue = rhs.mValue;
89     }
90     return *this;
91   }
92
93   /**
94    * @brief assignment operator from int
95    *
96    * @param value the value to assign
97    * @return reference to itself
98    */
99   LayoutLength& operator=( int value )
100   {
101     mValue = value;
102     return *this;
103   }
104
105   /**
106    * @brief assignment operator from float
107    *
108    * @param value the value to assign
109    * @return reference to itself
110    */
111   LayoutLength& operator=( float value )
112   {
113     mValue = value;
114     return *this;
115   }
116
117   /**
118    * @brief plus equals operator
119    *
120    * @param rhs to add to this
121    * @return reference to itself
122    */
123   LayoutLength& operator+=( LayoutLength rhs )
124   {
125     mValue += rhs.mValue;
126     return *this;
127   }
128
129   /**
130    * @brief minus equals operator
131    *
132    * @param rhs to subtract from this
133    * @return reference to itself
134    */
135   LayoutLength& operator-=( LayoutLength rhs )
136   {
137     mValue -= rhs.mValue;
138     return *this;
139   }
140
141   /**
142    * @brief return value as decimal value (full raw value)
143    *
144    * @return the LayoutLength as full decimal value
145    */
146   float AsDecimal() const
147   {
148     return mValue;
149   }
150
151   /**
152    * @brief return value as rounded integer value (whole number)
153    *
154    * @return the LayoutLength rounded to next integer value
155    */
156   float AsInteger() const
157   {
158     return round( mValue );
159   }
160
161   /**
162    * @brief return value as truncated integral value (whole number)
163    *
164    * @return the LayoutLength rounded to next integral value
165    */
166   float AsTruncated() const
167   {
168     return trunc( mValue );
169   }
170
171 private:
172
173   float mValue;
174
175 };
176
177 /**
178  * @brief equal to operator
179  *
180  * @param lhs value to compare
181  * @param rhs value to compare against
182  * @note Using value instead of reference to allow conversions from int and float
183  * @return true if identical, false otherwise
184  */
185 inline bool operator==( LayoutLength lhs, LayoutLength rhs )
186 {
187   return lhs.AsDecimal() == rhs.AsDecimal();
188 }
189
190 /**
191  * @brief not equal to operator
192  *
193  * @param lhs value to compare
194  * @param rhs value to compare against
195  * @note Using value instead of reference to allow conversions from int and float
196  * @return true if value is not identical, false otherwise
197  */
198 inline bool operator!=( LayoutLength lhs, LayoutLength rhs )
199 {
200   return !operator==( lhs, rhs );
201 }
202
203 /**
204  * @brief less than operator
205  *
206  * @param lhs value to compare
207  * @param rhs value to compare against
208  * @note Using value instead of reference to allow conversions from int and float
209  * @return true if lhs value is less, false otherwise
210  */
211 inline bool operator<( LayoutLength lhs, LayoutLength rhs )
212 {
213   return lhs.AsDecimal() < rhs.AsDecimal();
214 }
215
216 /**
217  * @brief greater than operator
218  *
219  * @param lhs value to compare
220  * @param rhs value to compare against
221  * @note Using value instead of reference to allow conversions from int and float
222  * @return true if lhs value is greater, false otherwise
223  */
224 inline bool operator>( LayoutLength lhs, LayoutLength rhs )
225 {
226   return rhs < lhs;
227 }
228
229 /**
230  * @brief less than or equal to operator
231  *
232  * @param lhs value to compare
233  * @param rhs value to compare against
234  * @note Using value instead of reference to allow conversions from int and float
235  * @return true if lhs value is less than or equal to, false otherwise
236  */
237 inline bool operator<=( LayoutLength lhs, LayoutLength rhs )
238 {
239   return !(lhs > rhs);
240 }
241
242 /**
243  * @brief greater than or equal to operator
244  *
245  * @param lhs value to compare
246  * @param rhs value to compare against
247  * @note Using value instead of reference to allow conversions from int and float
248  * @return true if lhs value is greater than or equal to, false otherwise
249  */
250 inline bool operator>=( LayoutLength lhs, LayoutLength rhs )
251 {
252   return !(lhs < rhs);
253 }
254
255 /**
256  * @brief add two LayoutLengths
257  *
258  * @param lhs The LayoutLength to add
259  * @param rhs The LayoutLength to add
260  * @note Using value instead of reference to allow conversions from int and float
261  * @return the resulting LayoutLength
262  */
263 inline LayoutLength operator+( LayoutLength lhs, LayoutLength rhs )
264 {
265   return lhs.AsDecimal() + rhs.AsDecimal();
266 }
267
268 /**
269  * @brief subtract two LayoutLengths
270  *
271  * @param lhs The LayoutLength to subtract from
272  * @param rhs The LayoutLength to subtract
273  * @note Using value instead of reference to allow conversions from int and float
274  * @return the resulting LayoutLength
275  */
276 inline LayoutLength operator-( LayoutLength lhs, LayoutLength rhs )
277 {
278   return lhs.AsDecimal() - rhs.AsDecimal();
279 }
280
281 /**
282  * @brief multiply two LayoutLengths
283  *
284  * @param lhs The LayoutLength to multiply
285  * @param rhs The LayoutLength to multiply
286  * @note Using value instead of reference to allow conversions from int and float
287  * @return the resulting LayoutLength
288  */
289 inline LayoutLength operator*( LayoutLength lhs, LayoutLength rhs )
290 {
291   return lhs.AsDecimal() * rhs.AsDecimal();
292 }
293
294 /**
295  * @brief divide LayoutLength by a LayoutLength
296  *
297  * @param lhs The LayoutLength to divide
298  * @param rhs The LayoutLength to divide by
299  * @note Using value instead of reference to allow conversions from int and float
300  * @return the resulting value as float
301  */
302 inline LayoutLength operator/( LayoutLength lhs, LayoutLength rhs )
303 {
304   return lhs.AsDecimal() / rhs.AsDecimal();
305 }
306
307 /**
308  * @brief Prints a LayoutLength
309  *
310  * @param[in] o The output stream operator
311  * @param[in] layoutLength the layout length to print
312  * @return The output stream operator
313  */
314 inline std::ostream& operator<<( std::ostream& o, const LayoutLength& layoutLength )
315 {
316   return o << layoutLength.AsDecimal();
317 }
318
319 } // namespace Toolkit
320
321 } // namespace Dali
322
323 #endif //DALI_TOOLKIT_DEVEL_LAYOUT_LENGTH_H