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