Merge "Completely remove use of Adaptor class" into tizen
[platform/core/uifw/dali-toolkit.git] / optional / dali-toolkit / internal / controls / cluster / cluster-style-impl.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // INTERNAL INCLUDES
19 #include <dali/dali.h>
20 #include <dali-toolkit/internal/controls/cluster/cluster-style-impl.h>
21 #include <dali-toolkit/public-api/controls/cluster/cluster.h>
22
23 namespace Dali
24 {
25
26 namespace // unnamed namespace
27 {
28 // Cluster style one
29
30 const unsigned int STYLE_1_CHILDREN_NUMBER = 8;
31
32 const float STYLE_1_BACKGROUND_IMAGE_OFFSET_Z = 1.0f;
33
34 const float STYLE_1_CHILD_OFFSET_Z = 2.0f;
35 const float STYLE_1_CHILD_GAP_FACTOR = 0.03f;
36 const float STYLE_1_CHILD_SIZE_FACTOR[] = { 0.4f, 0.15f, 0.25f, 0.15f, 0.4f, 0.15f, 0.25f, 0.15f };
37 const Vector3 STYLE_1_CHILD_POSITION_FACTOR[] = { Vector3(0.5f - STYLE_1_CHILD_SIZE_FACTOR[0] - STYLE_1_CHILD_GAP_FACTOR * 0.5f,
38                                                             0.5f - STYLE_1_CHILD_SIZE_FACTOR[0] - STYLE_1_CHILD_GAP_FACTOR * 0.5f,
39                                                             STYLE_1_CHILD_OFFSET_Z),
40                                                     Vector3(0.5f + STYLE_1_CHILD_GAP_FACTOR * 0.5f,
41                                                             0.5f - STYLE_1_CHILD_SIZE_FACTOR[1] - STYLE_1_CHILD_SIZE_FACTOR[2] - STYLE_1_CHILD_GAP_FACTOR * 1.5f,
42                                                             STYLE_1_CHILD_OFFSET_Z + 0.5f),
43                                                     Vector3(0.5f + STYLE_1_CHILD_GAP_FACTOR * 0.5f,
44                                                             0.5f - STYLE_1_CHILD_SIZE_FACTOR[2] - STYLE_1_CHILD_GAP_FACTOR * 0.5f,
45                                                             STYLE_1_CHILD_OFFSET_Z + 1.0f),
46                                                     Vector3(0.5f + STYLE_1_CHILD_SIZE_FACTOR[2] + STYLE_1_CHILD_GAP_FACTOR * 1.5f,
47                                                             0.5f - STYLE_1_CHILD_SIZE_FACTOR[3] - STYLE_1_CHILD_GAP_FACTOR * 0.5f,
48                                                             STYLE_1_CHILD_OFFSET_Z + 1.5f),
49                                                     Vector3(0.5f + STYLE_1_CHILD_GAP_FACTOR * 0.5f,
50                                                             0.5f + STYLE_1_CHILD_GAP_FACTOR * 0.5f,
51                                                             STYLE_1_CHILD_OFFSET_Z + 2.0f),
52                                                     Vector3(0.5f - STYLE_1_CHILD_SIZE_FACTOR[5] - STYLE_1_CHILD_GAP_FACTOR * 0.5f,
53                                                             0.5f + STYLE_1_CHILD_SIZE_FACTOR[6] + STYLE_1_CHILD_GAP_FACTOR * 1.5f,
54                                                             STYLE_1_CHILD_OFFSET_Z + 2.5f),
55                                                     Vector3(0.5f - STYLE_1_CHILD_SIZE_FACTOR[6] - STYLE_1_CHILD_GAP_FACTOR * 0.5f,
56                                                             0.5f + STYLE_1_CHILD_GAP_FACTOR * 0.5f,
57                                                             STYLE_1_CHILD_OFFSET_Z + 3.0f),
58                                                     Vector3(0.5f - STYLE_1_CHILD_SIZE_FACTOR[6] - STYLE_1_CHILD_SIZE_FACTOR[7] - STYLE_1_CHILD_GAP_FACTOR * 1.5f,
59                                                             0.5f + STYLE_1_CHILD_GAP_FACTOR * 0.5f,
60                                                             STYLE_1_CHILD_OFFSET_Z + 3.5f) };
61
62 const Vector3 STYLE_1_TITLE_SIZE_FACTOR = Vector3(0.3f, 0.11f, 1.0f);
63 const Vector3 STYLE_1_TITLE_POSITION_FACTOR = Vector3(0.5f - STYLE_1_CHILD_SIZE_FACTOR[0] - STYLE_1_CHILD_GAP_FACTOR * 0.5f,
64                                                         0.5f - STYLE_1_CHILD_SIZE_FACTOR[0] - STYLE_1_CHILD_GAP_FACTOR * 0.5f - STYLE_1_TITLE_SIZE_FACTOR.height + 0.02f,
65                                                         0.0f);
66 const Vector3 STYLE_1_TITLE_POSITION_OFFSET = Vector3(0.0f, 0.0f, 8.0f);
67
68 // Cluster style two
69
70 const unsigned int STYLE_2_CHILDREN_NUMBER = 6;
71
72 const float STYLE_2_BACKGROUND_IMAGE_OFFSET_Z = 1.0f;
73
74 const float STYLE_2_CHILD_OFFSET_Z = 2.0f;
75 const float STYLE_2_CHILD_GAP_FACTOR = 0.03f;
76 const float STYLE_2_CHILD_SIZE_FACTOR[] = { 0.4f, 0.25f, 0.15f, 0.4f, 0.25f, 0.15f };
77 const Vector3 STYLE_2_CHILD_POSITION_FACTOR[] = { Vector3(0.5f - STYLE_2_CHILD_SIZE_FACTOR[0] - STYLE_2_CHILD_GAP_FACTOR * 0.5f,
78                                                             0.5f - STYLE_2_CHILD_SIZE_FACTOR[0] * 0.75f,
79                                                             STYLE_2_CHILD_OFFSET_Z),
80                                                     Vector3(0.5f + STYLE_2_CHILD_GAP_FACTOR * 0.5f,
81                                                             0.5f - STYLE_2_CHILD_SIZE_FACTOR[1] - STYLE_2_CHILD_SIZE_FACTOR[3] * 0.25f - STYLE_2_CHILD_GAP_FACTOR,
82                                                             STYLE_2_CHILD_OFFSET_Z + 0.5f),
83                                                     Vector3(0.5f + STYLE_2_CHILD_SIZE_FACTOR[1] + STYLE_2_CHILD_GAP_FACTOR * 1.5f,
84                                                             0.5f - STYLE_2_CHILD_SIZE_FACTOR[2] - STYLE_2_CHILD_SIZE_FACTOR[3] * 0.25f - STYLE_2_CHILD_GAP_FACTOR,
85                                                             STYLE_2_CHILD_OFFSET_Z + 1.0f),
86                                                     Vector3(0.5f + STYLE_2_CHILD_GAP_FACTOR * 0.5f,
87                                                             0.5f - STYLE_2_CHILD_SIZE_FACTOR[3] * 0.25f,
88                                                             STYLE_2_CHILD_OFFSET_Z + 1.5f),
89                                                     Vector3(0.5f - STYLE_2_CHILD_SIZE_FACTOR[4] - STYLE_2_CHILD_GAP_FACTOR * 0.5f,
90                                                             0.5f + STYLE_2_CHILD_SIZE_FACTOR[0] * 0.25f + STYLE_2_CHILD_GAP_FACTOR,
91                                                             STYLE_2_CHILD_OFFSET_Z + 2.0f),
92                                                     Vector3(0.5f - STYLE_2_CHILD_SIZE_FACTOR[4] - STYLE_2_CHILD_SIZE_FACTOR[5] - STYLE_2_CHILD_GAP_FACTOR * 1.5f,
93                                                             0.5f + STYLE_2_CHILD_SIZE_FACTOR[0] * 0.25f + STYLE_2_CHILD_GAP_FACTOR,
94                                                             STYLE_2_CHILD_OFFSET_Z + 2.5f) };
95
96 const Vector3 STYLE_2_TITLE_SIZE_FACTOR = Vector3(0.3f, 0.11f, 1.0f);
97 const Vector3 STYLE_2_TITLE_POSITION_FACTOR = Vector3(0.5f - STYLE_2_CHILD_SIZE_FACTOR[0] - STYLE_2_CHILD_GAP_FACTOR * 0.5f,
98                                                         0.5f - STYLE_2_CHILD_SIZE_FACTOR[0] * 0.75f - STYLE_2_TITLE_SIZE_FACTOR.height + 0.02f,
99                                                         0.0f);
100 const Vector3 STYLE_2_TITLE_POSITION_OFFSET = Vector3(0.0f, 0.0f, 8.0f);
101
102 // Cluster style three
103
104 const unsigned int STYLE_3_CHILDREN_NUMBER = 6;
105
106 const Vector3 STYLE_3_TITLE_SIZE_FACTOR = Vector3(0.4f, 0.15f, 1.0f);
107
108 const float STYLE_3_BACKGROUND_IMAGE_OFFSET_Z = 1.0f;
109
110 const float STYLE_3_CHILD_OFFSET_Z = 2.0f;
111 const float STYLE_3_CHILD_GAP_FACTOR = 0.03f;
112 const float STYLE_3_CHILD_SIZE_FACTOR[] = { 0.4f, 0.4f, 0.15f, 0.25f, 0.25f, 0.15f };
113 const float STYLE_3_CHILD_POSITION_OFFSET_Y = (1.0f - STYLE_3_CHILD_SIZE_FACTOR[0] - STYLE_3_CHILD_SIZE_FACTOR[3] - STYLE_3_CHILD_GAP_FACTOR - STYLE_3_TITLE_SIZE_FACTOR.height) * 0.5f;
114 const Vector3 STYLE_3_CHILD_POSITION_FACTOR[] = { Vector3(0.5f - STYLE_3_CHILD_SIZE_FACTOR[0] - STYLE_3_CHILD_GAP_FACTOR * 0.5f,
115                                                               0.5f - STYLE_3_CHILD_SIZE_FACTOR[0] - STYLE_3_CHILD_GAP_FACTOR * 0.5f + STYLE_3_CHILD_POSITION_OFFSET_Y,
116                                                               STYLE_3_CHILD_OFFSET_Z),
117                                                       Vector3(0.5f + STYLE_3_CHILD_GAP_FACTOR * 0.5f,
118                                                               0.5f - STYLE_3_CHILD_SIZE_FACTOR[1] - STYLE_3_CHILD_GAP_FACTOR * 0.5f + STYLE_3_CHILD_POSITION_OFFSET_Y,
119                                                               STYLE_3_CHILD_OFFSET_Z + 0.5f),
120                                                       Vector3(0.5f + STYLE_3_CHILD_SIZE_FACTOR[3] + STYLE_3_CHILD_GAP_FACTOR * 1.5f,
121                                                               0.5f + STYLE_3_CHILD_GAP_FACTOR * 0.5f + STYLE_3_CHILD_POSITION_OFFSET_Y,
122                                                               STYLE_3_CHILD_OFFSET_Z + 1.0f),
123                                                       Vector3(0.5f + STYLE_3_CHILD_GAP_FACTOR * 0.5f,
124                                                               0.5f + STYLE_3_CHILD_GAP_FACTOR * 0.5f + STYLE_3_CHILD_POSITION_OFFSET_Y,
125                                                               STYLE_3_CHILD_OFFSET_Z + 1.5f),
126                                                       Vector3(0.5f - STYLE_3_CHILD_SIZE_FACTOR[4] - STYLE_3_CHILD_GAP_FACTOR * 0.5f,
127                                                               0.5f + STYLE_3_CHILD_GAP_FACTOR * 0.5f + STYLE_3_CHILD_POSITION_OFFSET_Y,
128                                                               STYLE_3_CHILD_OFFSET_Z + 2.0f),
129                                                       Vector3(0.5f - STYLE_3_CHILD_SIZE_FACTOR[4] - STYLE_3_CHILD_SIZE_FACTOR[5] - STYLE_3_CHILD_GAP_FACTOR * 1.5f,
130                                                               0.5f + STYLE_3_CHILD_GAP_FACTOR * 0.5f + STYLE_3_CHILD_POSITION_OFFSET_Y,
131                                                               STYLE_3_CHILD_OFFSET_Z + 2.5f) };
132
133 const Vector3 STYLE_3_TITLE_POSITION_FACTOR = Vector3(0.5f - STYLE_3_CHILD_SIZE_FACTOR[0] - STYLE_3_CHILD_GAP_FACTOR * 0.5f,
134                                                           0.5f - STYLE_3_CHILD_SIZE_FACTOR[0] - STYLE_3_CHILD_GAP_FACTOR * 0.5f + STYLE_3_CHILD_POSITION_OFFSET_Y - STYLE_3_TITLE_SIZE_FACTOR.height + 0.02f,
135                                                           0.0f);
136 const Vector3 STYLE_3_TITLE_POSITION_OFFSET = Vector3(0.0f, 0.0f, 8.0f);
137
138 // Cluster style four
139
140 const unsigned int STYLE_4_CHILDREN_NUMBER = 6;
141
142 const float STYLE_4_BACKGROUND_IMAGE_OFFSET_Z = 1.0f;
143
144 const float STYLE_4_CHILD_OFFSET_Z = 2.0f;
145 const float STYLE_4_CHILD_GAP_FACTOR = 0.03f;
146 const float STYLE_4_CHILD_SIZE_FACTOR[] = { 0.4f, 0.22f, 0.13f, 0.4f, 0.22f, 0.13f };
147 const Vector3 STYLE_4_CHILD_POSITION_FACTOR[] = { Vector3(0.5f - STYLE_4_CHILD_SIZE_FACTOR[0] * 0.9f,
148                                                              0.5f - STYLE_4_CHILD_SIZE_FACTOR[0] - STYLE_4_CHILD_GAP_FACTOR * 0.5f,
149                                                              STYLE_4_CHILD_OFFSET_Z),
150                                                      Vector3(0.5f + STYLE_4_CHILD_SIZE_FACTOR[0] * 0.1f + STYLE_4_CHILD_GAP_FACTOR,
151                                                              0.5f - STYLE_4_CHILD_SIZE_FACTOR[1] - STYLE_4_CHILD_GAP_FACTOR * 0.5f,
152                                                              STYLE_4_CHILD_OFFSET_Z + 0.5f),
153                                                      Vector3(0.5f + STYLE_4_CHILD_SIZE_FACTOR[0] * 0.1f + STYLE_4_CHILD_SIZE_FACTOR[1] + STYLE_4_CHILD_GAP_FACTOR * 2.0f,
154                                                              0.5f - STYLE_4_CHILD_SIZE_FACTOR[2] - STYLE_4_CHILD_GAP_FACTOR * 0.5f,
155                                                              STYLE_4_CHILD_OFFSET_Z + 1.0f),
156                                                      Vector3(0.5f - STYLE_4_CHILD_SIZE_FACTOR[3] * 0.1f,
157                                                              0.5f + STYLE_4_CHILD_GAP_FACTOR * 0.5f,
158                                                              STYLE_4_CHILD_OFFSET_Z + 1.5f),
159                                                      Vector3(0.5f - STYLE_4_CHILD_SIZE_FACTOR[3] * 0.1f - STYLE_4_CHILD_SIZE_FACTOR[4] - STYLE_4_CHILD_GAP_FACTOR,
160                                                              0.5f + STYLE_4_CHILD_GAP_FACTOR * 0.5f,
161                                                              STYLE_4_CHILD_OFFSET_Z + 2.0f),
162                                                      Vector3(0.5f - STYLE_4_CHILD_SIZE_FACTOR[3] * 0.1f - STYLE_4_CHILD_SIZE_FACTOR[4] - STYLE_4_CHILD_SIZE_FACTOR[5] - STYLE_4_CHILD_GAP_FACTOR * 2.0f,
163                                                              0.5f + STYLE_4_CHILD_GAP_FACTOR * 0.5f,
164                                                              STYLE_4_CHILD_OFFSET_Z + 2.5f) };
165
166 const Vector3 STYLE_4_TITLE_SIZE_FACTOR = Vector3(0.3f, 0.11f, 1.0f);
167 const Vector3 STYLE_4_TITLE_POSITION_FACTOR = Vector3(0.5f - STYLE_4_CHILD_SIZE_FACTOR[0] * 0.9f,
168                                                          0.5f - STYLE_4_CHILD_SIZE_FACTOR[0] - STYLE_4_CHILD_GAP_FACTOR * 0.5f - STYLE_4_TITLE_SIZE_FACTOR.height + 0.02f,
169                                                          0.0f);
170 const Vector3 STYLE_4_TITLE_POSITION_OFFSET = Vector3(0.0f, 0.0f, 8.0f);
171 const unsigned int CLUSTER_RANDOM_SEED(0x17eac9f3);         ///< Random seed for cluster data.
172
173 const int STYLE_RANDOM_CHILDREN_NUMBER = 16;
174
175 // Constraints
176
177 /**
178  * First order equation of the form y = Mx + C
179  * current' = current * relative + offset
180  */
181 struct FirstOrderEquationConstraint
182 {
183   /**
184    * @param relative The relative multiplier of the source property
185    * @param offset The offset to add onto the result.
186    */
187   FirstOrderEquationConstraint(Vector3 relative, Vector3 offset = Vector3::ZERO)
188   : mRelative(relative),
189     mOffset(offset)
190   {
191   }
192
193   Vector3 operator()(const Vector3&    current,
194                      const PropertyInput& sourceProperty)
195   {
196     const Vector3 source = sourceProperty.GetVector3();
197
198     return source * mRelative + mOffset;
199   }
200
201 public:
202
203   Vector3 mRelative;
204   Vector3 mOffset;
205 };
206
207 /**
208  * Depth Constraint.
209  * current' = current.xy | + Vector3::ONE.z
210  */
211 struct DepthConstraint
212 {
213   /**
214    * constructor
215    */
216   DepthConstraint()
217   {
218   }
219
220   Vector3 operator()(const Vector3&    current,
221                      const PropertyInput& depthProperty)
222   {
223     Vector3 position(current);
224     position.z = depthProperty.GetFloat();
225     return position;
226   }
227 };
228
229
230 /**
231  * Position Constraint.
232  * current' = current * relative + offset
233  */
234 struct PositionConstraint
235 {
236   /**
237    * @param relative The relative multiplier of the source property
238    * @param offset The offset to add onto the result.
239    */
240   PositionConstraint(Vector3 relative, Vector3 offset = Vector3::ZERO)
241   : mRelative(relative),
242     mOffset(offset)
243   {
244   }
245
246   Vector3 operator()(const Vector3&    current,
247                      const PropertyInput& sourceProperty,
248                      const PropertyInput& depthProperty)
249   {
250     const Vector3 source = sourceProperty.GetVector3();
251
252     Vector3 position(source * mRelative + mOffset);
253     position.z += depthProperty.GetFloat();
254     return position;
255   }
256
257 public:
258
259   Vector3 mRelative;
260   Vector3 mOffset;
261 };
262
263 template <class T>
264 struct SetConstraint
265 {
266   SetConstraint(T value)
267   : mValue(value)
268   {
269
270   }
271
272   T operator()(const T&    current)
273   {
274     return mValue;
275   }
276
277   T mValue;
278 };
279
280 // random data generator //////////////////////////////////////////////////////
281
282 const unsigned int GEN_RAND_CONST = 0x15d9a373;
283
284 unsigned int genRandom(unsigned int& seed, unsigned int offset)
285 {
286   unsigned int shft = offset&31;
287
288   offset++;
289
290   seed^= (seed << (shft) | seed >> (32 - shft)) * (offset * GEN_RAND_CONST);
291
292   return seed;
293 }
294
295 float genRandomFloat(unsigned int& seed, unsigned int offset, float min, float max)
296 {
297   const float f = static_cast<float>(genRandom(seed, offset)) / 0xffffffff;
298   return f * (max - min) + min;
299 }
300
301 } // unnamed namespace
302
303 namespace Toolkit
304 {
305
306 namespace Internal
307 {
308
309 // ClusterStyle ///////////////////////////////////////////////////////////////
310
311 ClusterStyle::ClusterStyle()
312 : mMaxChildren(0),
313   mTitlePositionRelative(Vector3::ONE),
314   mTitlePositionOffset(Vector3::ZERO),
315   mTitleSize(Vector3::ONE),
316   mBackgroundPositionRelative(Vector3::ONE),
317   mBackgroundPositionOffset(Vector3::ZERO),
318   mBackgroundSize(Vector3::ONE)
319 {
320 }
321
322 ClusterStyle::~ClusterStyle()
323 {
324
325 }
326
327 void ClusterStyle::SetMaximumNumberOfChildren(unsigned int maxChildren)
328 {
329   mMaxChildren = maxChildren;
330 }
331
332 unsigned int ClusterStyle::GetMaximumNumberOfChildren() const
333 {
334   return mMaxChildren;
335 }
336
337 void ClusterStyle::SetTitleProperties(const Vector3& relativePosition,
338                                       const Vector3& offsetPosition,
339                                       const Vector3& size)
340 {
341   mTitlePositionRelative = relativePosition;
342   mTitlePositionOffset = offsetPosition;
343   mTitleSize = size;
344 }
345
346 void ClusterStyle::SetBackgroundProperties(const Vector3& relativePosition,
347                                            const Vector3& offsetPosition,
348                                            const Vector3& size)
349 {
350   mBackgroundPositionRelative = relativePosition;
351   mBackgroundPositionOffset = offsetPosition;
352   mBackgroundSize = size;
353 }
354
355 // ClusterStyleStandard ///////////////////////////////////////////////////////
356
357 ClusterStylePtr ClusterStyleStandard::New(StyleType style)
358 {
359   ClusterStylePtr impl( new ClusterStyleStandard(style) );
360
361   return impl;
362 }
363
364 ClusterStyleStandard::ClusterStyleStandard(StyleType style)
365 : ClusterStyle(),
366   mSizes(NULL),
367   mPositions(NULL)
368 {
369   switch(style)
370   {
371     case Toolkit::ClusterStyleStandard::ClusterStyle1:
372     {
373       SetMaximumNumberOfChildren(STYLE_1_CHILDREN_NUMBER);
374       SetSizes(STYLE_1_CHILD_SIZE_FACTOR);
375       SetPositions(STYLE_1_CHILD_POSITION_FACTOR);
376       SetTitleProperties(STYLE_1_TITLE_POSITION_FACTOR,
377                          STYLE_1_TITLE_POSITION_OFFSET,
378                          STYLE_1_TITLE_SIZE_FACTOR);
379       SetBackgroundProperties(Vector3::ZERO,
380                               Vector3(0.0f, 0.0f, STYLE_1_BACKGROUND_IMAGE_OFFSET_Z),
381                               Vector3::ONE);
382       break;
383     }
384     case Toolkit::ClusterStyleStandard::ClusterStyle2:
385     {
386       SetMaximumNumberOfChildren(STYLE_2_CHILDREN_NUMBER);
387       SetSizes(STYLE_2_CHILD_SIZE_FACTOR);
388       SetPositions(STYLE_2_CHILD_POSITION_FACTOR);
389       SetTitleProperties(STYLE_2_TITLE_POSITION_FACTOR,
390                          STYLE_2_TITLE_POSITION_OFFSET,
391                          STYLE_2_TITLE_SIZE_FACTOR);
392       SetBackgroundProperties(Vector3::ZERO,
393                               Vector3(0.0f, 0.0f, STYLE_2_BACKGROUND_IMAGE_OFFSET_Z),
394                               Vector3::ONE);
395       break;
396     }
397     case Toolkit::ClusterStyleStandard::ClusterStyle3:
398     {
399       SetMaximumNumberOfChildren(STYLE_3_CHILDREN_NUMBER);
400       SetSizes(STYLE_3_CHILD_SIZE_FACTOR);
401       SetPositions(STYLE_3_CHILD_POSITION_FACTOR);
402       SetTitleProperties(STYLE_3_TITLE_POSITION_FACTOR,
403                          STYLE_3_TITLE_POSITION_OFFSET,
404                          STYLE_3_TITLE_SIZE_FACTOR);
405       SetBackgroundProperties(Vector3::ZERO,
406                               Vector3(0.0f, 0.0f, STYLE_3_BACKGROUND_IMAGE_OFFSET_Z),
407                               Vector3::ONE);
408       break;
409     }
410     case Toolkit::ClusterStyleStandard::ClusterStyle4:
411     {
412       SetMaximumNumberOfChildren(STYLE_4_CHILDREN_NUMBER);
413       SetSizes(STYLE_4_CHILD_SIZE_FACTOR);
414       SetPositions(STYLE_4_CHILD_POSITION_FACTOR);
415       SetTitleProperties(STYLE_4_TITLE_POSITION_FACTOR,
416                          STYLE_4_TITLE_POSITION_OFFSET,
417                          STYLE_4_TITLE_SIZE_FACTOR);
418       SetBackgroundProperties(Vector3::ZERO,
419                               Vector3(0.0f, 0.0f, STYLE_4_BACKGROUND_IMAGE_OFFSET_Z),
420                               Vector3::ONE);
421       break;
422     }
423     default:
424     {
425       DALI_ASSERT_ALWAYS(false && "Invalid Style");
426       break;
427     }
428   } // end switch
429 }
430
431 void ClusterStyleStandard::SetSizes(const float *sizes)
432 {
433   mSizes = sizes;
434 }
435
436 void ClusterStyleStandard::SetPositions(const Vector3 *positions)
437 {
438   mPositions = positions;
439 }
440
441 void ClusterStyleStandard::ApplyStyle(Actor child, unsigned int index, AlphaFunction alpha, const TimePeriod& durationSeconds)
442 {
443   if(mPositions)
444   {
445     const float& size = mSizes[index];
446     // counter top-left parent origin and top-left anchor point.
447     const Vector3 position = mPositions[index] - Vector3(0.5f, 0.5f, 0.0f) + Vector3(size, size, 0.0f) * 0.5f;
448
449     Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
450                                                       ParentSource( Actor::SIZE ),
451                                                       FirstOrderEquationConstraint(Vector3(position.x, position.y, 0.0f),
452                                                                                    Vector3(0.0f, 0.0f, position.z)) );
453
454     constraint.SetApplyTime(durationSeconds);
455     constraint.SetAlphaFunction(alpha);
456     constraint.SetRemoveAction(Constraint::Bake);
457     child.ApplyConstraint(constraint);
458
459     constraint = Constraint::New<Vector3>( Actor::SIZE,
460                                            ParentSource( Actor::SIZE ),
461                                            FirstOrderEquationConstraint(Vector3::ONE * size) );
462     constraint.SetApplyTime(durationSeconds);
463     constraint.SetAlphaFunction(alpha);
464     constraint.SetRemoveAction(Constraint::Bake);
465     child.ApplyConstraint(constraint);
466
467     constraint = Constraint::New<Quaternion>( Actor::ROTATION,
468                                               SetConstraint<Quaternion>(Quaternion()) );
469     constraint.SetApplyTime(durationSeconds);
470     constraint.SetAlphaFunction(alpha);
471     constraint.SetRemoveAction(Constraint::Bake);
472     child.ApplyConstraint(constraint);
473
474     constraint = Constraint::New<Vector3>( Actor::SCALE,
475                                            SetConstraint<Vector3>(Vector3::ONE) );
476     constraint.SetApplyTime(durationSeconds);
477     constraint.SetAlphaFunction(alpha);
478     constraint.SetRemoveAction(Constraint::Bake);
479     child.ApplyConstraint(constraint);
480   }
481 }
482
483 void ClusterStyleStandard::ApplyStyleToBackground(Actor background, AlphaFunction alpha, const TimePeriod& durationSeconds)
484 {
485   Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
486                                          ParentSource( Actor::SIZE ),
487                                          FirstOrderEquationConstraint(mBackgroundPositionRelative, mBackgroundPositionOffset) );
488   constraint.SetApplyTime(durationSeconds);
489   constraint.SetAlphaFunction(alpha);
490   constraint.SetRemoveAction(Constraint::Bake);
491   background.ApplyConstraint(constraint);
492
493   constraint = Constraint::New<Vector3>( Actor::SIZE,
494                                          ParentSource( Actor::SIZE ),
495                                          FirstOrderEquationConstraint(mBackgroundSize) );
496   constraint.SetApplyTime(durationSeconds);
497   constraint.SetAlphaFunction(alpha);
498   constraint.SetRemoveAction(Constraint::Bake);
499   background.ApplyConstraint(constraint);
500 }
501
502 void ClusterStyleStandard::ApplyStyleToTitle(Actor title, AlphaFunction alpha, const TimePeriod& durationSeconds)
503 {
504   Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
505                                          ParentSource( Actor::SIZE ),
506                                          FirstOrderEquationConstraint(mTitlePositionRelative, mTitlePositionOffset) );
507   constraint.SetApplyTime(durationSeconds);
508   constraint.SetAlphaFunction(alpha);
509   constraint.SetRemoveAction(Constraint::Bake);
510   title.ApplyConstraint(constraint);
511
512   constraint = Constraint::New<Vector3>( Actor::SIZE,
513                                          ParentSource( Actor::SIZE ),
514                                          FirstOrderEquationConstraint(mTitleSize) );
515   constraint.SetApplyTime(durationSeconds);
516   constraint.SetAlphaFunction(alpha);
517   constraint.SetRemoveAction(Constraint::Bake);
518   title.ApplyConstraint(constraint);
519 }
520
521 // ClusterStyleRandom /////////////////////////////////////////////////////////
522
523 ClusterStylePtr ClusterStyleRandom::New()
524 {
525   ClusterStylePtr impl( new ClusterStyleRandom() );
526
527   return impl;
528 }
529
530 ClusterStyleRandom::ClusterStyleRandom()
531 : ClusterStyle()
532 {
533   SetMaximumNumberOfChildren(STYLE_RANDOM_CHILDREN_NUMBER);
534   SetTitleProperties(Vector3::ZERO,
535                      Vector3::ZERO,
536                      Vector3::ONE);
537   SetBackgroundProperties(Vector3::ZERO,
538                           Vector3(0.0f, 0.0f, 0.0f),
539                           Vector3::ONE);
540 }
541
542 void ClusterStyleRandom::ApplyStyle(Actor child, unsigned int index, AlphaFunction alpha, const TimePeriod& durationSeconds)
543 {
544   unsigned int seed = CLUSTER_RANDOM_SEED;
545   const float size = 0.5f;
546   const float rotation = genRandomFloat(seed, index, -1.0f, 1.0f) * Math::PI * 0.1; // +/- 18 degrees
547   const Vector3 position(genRandomFloat(seed, index, -0.1f, 0.1f),
548                          genRandomFloat(seed, index, -0.1f, 0.1f),
549                          0.0f);
550
551   Property::Index depthProperty = child.GetPropertyIndex(Toolkit::Cluster::CLUSTER_ACTOR_DEPTH);
552
553   Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
554                                                     ParentSource( Actor::SIZE ),
555                                                     FirstOrderEquationConstraint( Vector3(position.x, position.y, 0.0f),
556                                                                                   Vector3(0.0f, 0.0f, position.z) ) );
557
558   constraint.SetApplyTime(durationSeconds);
559   constraint.SetAlphaFunction(alpha);
560   constraint.SetRemoveAction(Constraint::Bake);
561   child.ApplyConstraint(constraint);
562
563   // this constraint overrides the Z position. setting it to cluster-actor-depth
564   constraint = Constraint::New<Vector3>( Actor::POSITION,
565                                          LocalSource( depthProperty ),
566                                          DepthConstraint() );
567
568   constraint.SetAlphaFunction(alpha);
569   constraint.SetRemoveAction(Constraint::Bake);
570   child.ApplyConstraint(constraint);
571
572   constraint = Constraint::New<Vector3>( Actor::SIZE,
573                                          ParentSource( Actor::SIZE ),
574                                          FirstOrderEquationConstraint(Vector3::ONE * size) );
575   constraint.SetApplyTime(durationSeconds);
576   constraint.SetAlphaFunction(alpha);
577   constraint.SetRemoveAction(Constraint::Bake);
578   child.ApplyConstraint(constraint);
579
580   constraint = Constraint::New<Quaternion>( Actor::ROTATION,
581                                             SetConstraint<Quaternion>(Quaternion(rotation, Vector3::ZAXIS)) );
582   constraint.SetApplyTime(durationSeconds);
583   constraint.SetAlphaFunction(alpha);
584   constraint.SetRemoveAction(Constraint::Bake);
585   child.ApplyConstraint(constraint);
586
587   constraint = Constraint::New<Vector3>( Actor::SCALE,
588                                          SetConstraint<Vector3>(Vector3::ONE) );
589   constraint.SetApplyTime(durationSeconds);
590   constraint.SetAlphaFunction(alpha);
591   constraint.SetRemoveAction(Constraint::Bake);
592   child.ApplyConstraint(constraint);
593 }
594
595 void ClusterStyleRandom::ApplyStyleToBackground(Actor background, AlphaFunction alpha, const TimePeriod& durationSeconds)
596 {
597   Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
598                                          ParentSource( Actor::SIZE ),
599                                          FirstOrderEquationConstraint(mBackgroundPositionRelative, mBackgroundPositionOffset) );
600   constraint.SetApplyTime(durationSeconds);
601   constraint.SetAlphaFunction(alpha);
602   constraint.SetRemoveAction(Constraint::Bake);
603   background.ApplyConstraint(constraint);
604
605   constraint = Constraint::New<Vector3>( Actor::SIZE,
606                                          ParentSource( Actor::SIZE ),
607                                          FirstOrderEquationConstraint(mBackgroundSize) );
608   constraint.SetApplyTime(durationSeconds);
609   constraint.SetAlphaFunction(alpha);
610   constraint.SetRemoveAction(Constraint::Bake);
611   background.ApplyConstraint(constraint);
612 }
613
614 void ClusterStyleRandom::ApplyStyleToTitle(Actor title, AlphaFunction alpha, const TimePeriod& durationSeconds)
615 {
616   Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
617                                          ParentSource( Actor::SIZE ),
618                                          FirstOrderEquationConstraint(mTitlePositionRelative, mTitlePositionOffset) );
619   constraint.SetApplyTime(durationSeconds);
620   constraint.SetAlphaFunction(alpha);
621   constraint.SetRemoveAction(Constraint::Bake);
622   title.ApplyConstraint(constraint);
623
624   constraint = Constraint::New<Vector3>( Actor::SIZE,
625                                          ParentSource( Actor::SIZE ),
626                                          FirstOrderEquationConstraint(mTitleSize) );
627   constraint.SetApplyTime(durationSeconds);
628   constraint.SetAlphaFunction(alpha);
629   constraint.SetRemoveAction(Constraint::Bake);
630   title.ApplyConstraint(constraint);
631 }
632
633 } // namespace Internal
634
635 } // namespace Toolkit
636
637 } // namespace Dali