Actor's Transformation API Cleanup
[platform/core/uifw/dali-toolkit.git] / 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 #include <dali/public-api/animation/animation.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/public-api/controls/cluster/cluster.h>
26
27 namespace Dali
28 {
29
30 namespace // unnamed namespace
31 {
32 // Cluster style one
33
34 const unsigned int STYLE_1_CHILDREN_NUMBER = 8;
35
36 const float STYLE_1_BACKGROUND_IMAGE_OFFSET_Z = 1.0f;
37
38 const float STYLE_1_CHILD_OFFSET_Z = 2.0f;
39 const float STYLE_1_CHILD_GAP_FACTOR = 0.03f;
40 const float STYLE_1_CHILD_SIZE_FACTOR[] = { 0.4f, 0.15f, 0.25f, 0.15f, 0.4f, 0.15f, 0.25f, 0.15f };
41 const Vector3 STYLE_1_CHILD_POSITION_FACTOR[] = { Vector3(0.5f - STYLE_1_CHILD_SIZE_FACTOR[0] - STYLE_1_CHILD_GAP_FACTOR * 0.5f,
42                                                             0.5f - STYLE_1_CHILD_SIZE_FACTOR[0] - STYLE_1_CHILD_GAP_FACTOR * 0.5f,
43                                                             STYLE_1_CHILD_OFFSET_Z),
44                                                     Vector3(0.5f + STYLE_1_CHILD_GAP_FACTOR * 0.5f,
45                                                             0.5f - STYLE_1_CHILD_SIZE_FACTOR[1] - STYLE_1_CHILD_SIZE_FACTOR[2] - STYLE_1_CHILD_GAP_FACTOR * 1.5f,
46                                                             STYLE_1_CHILD_OFFSET_Z + 0.5f),
47                                                     Vector3(0.5f + STYLE_1_CHILD_GAP_FACTOR * 0.5f,
48                                                             0.5f - STYLE_1_CHILD_SIZE_FACTOR[2] - STYLE_1_CHILD_GAP_FACTOR * 0.5f,
49                                                             STYLE_1_CHILD_OFFSET_Z + 1.0f),
50                                                     Vector3(0.5f + STYLE_1_CHILD_SIZE_FACTOR[2] + STYLE_1_CHILD_GAP_FACTOR * 1.5f,
51                                                             0.5f - STYLE_1_CHILD_SIZE_FACTOR[3] - STYLE_1_CHILD_GAP_FACTOR * 0.5f,
52                                                             STYLE_1_CHILD_OFFSET_Z + 1.5f),
53                                                     Vector3(0.5f + STYLE_1_CHILD_GAP_FACTOR * 0.5f,
54                                                             0.5f + STYLE_1_CHILD_GAP_FACTOR * 0.5f,
55                                                             STYLE_1_CHILD_OFFSET_Z + 2.0f),
56                                                     Vector3(0.5f - STYLE_1_CHILD_SIZE_FACTOR[5] - STYLE_1_CHILD_GAP_FACTOR * 0.5f,
57                                                             0.5f + STYLE_1_CHILD_SIZE_FACTOR[6] + STYLE_1_CHILD_GAP_FACTOR * 1.5f,
58                                                             STYLE_1_CHILD_OFFSET_Z + 2.5f),
59                                                     Vector3(0.5f - STYLE_1_CHILD_SIZE_FACTOR[6] - STYLE_1_CHILD_GAP_FACTOR * 0.5f,
60                                                             0.5f + STYLE_1_CHILD_GAP_FACTOR * 0.5f,
61                                                             STYLE_1_CHILD_OFFSET_Z + 3.0f),
62                                                     Vector3(0.5f - STYLE_1_CHILD_SIZE_FACTOR[6] - STYLE_1_CHILD_SIZE_FACTOR[7] - STYLE_1_CHILD_GAP_FACTOR * 1.5f,
63                                                             0.5f + STYLE_1_CHILD_GAP_FACTOR * 0.5f,
64                                                             STYLE_1_CHILD_OFFSET_Z + 3.5f) };
65
66 const Vector3 STYLE_1_TITLE_SIZE_FACTOR = Vector3(0.3f, 0.11f, 1.0f);
67 const Vector3 STYLE_1_TITLE_POSITION_FACTOR = Vector3(0.5f - STYLE_1_CHILD_SIZE_FACTOR[0] - STYLE_1_CHILD_GAP_FACTOR * 0.5f,
68                                                         0.5f - STYLE_1_CHILD_SIZE_FACTOR[0] - STYLE_1_CHILD_GAP_FACTOR * 0.5f - STYLE_1_TITLE_SIZE_FACTOR.height + 0.02f,
69                                                         0.0f);
70 const Vector3 STYLE_1_TITLE_POSITION_OFFSET = Vector3(0.0f, 0.0f, 8.0f);
71
72 // Cluster style two
73
74 const unsigned int STYLE_2_CHILDREN_NUMBER = 6;
75
76 const float STYLE_2_BACKGROUND_IMAGE_OFFSET_Z = 1.0f;
77
78 const float STYLE_2_CHILD_OFFSET_Z = 2.0f;
79 const float STYLE_2_CHILD_GAP_FACTOR = 0.03f;
80 const float STYLE_2_CHILD_SIZE_FACTOR[] = { 0.4f, 0.25f, 0.15f, 0.4f, 0.25f, 0.15f };
81 const Vector3 STYLE_2_CHILD_POSITION_FACTOR[] = { Vector3(0.5f - STYLE_2_CHILD_SIZE_FACTOR[0] - STYLE_2_CHILD_GAP_FACTOR * 0.5f,
82                                                             0.5f - STYLE_2_CHILD_SIZE_FACTOR[0] * 0.75f,
83                                                             STYLE_2_CHILD_OFFSET_Z),
84                                                     Vector3(0.5f + STYLE_2_CHILD_GAP_FACTOR * 0.5f,
85                                                             0.5f - STYLE_2_CHILD_SIZE_FACTOR[1] - STYLE_2_CHILD_SIZE_FACTOR[3] * 0.25f - STYLE_2_CHILD_GAP_FACTOR,
86                                                             STYLE_2_CHILD_OFFSET_Z + 0.5f),
87                                                     Vector3(0.5f + STYLE_2_CHILD_SIZE_FACTOR[1] + STYLE_2_CHILD_GAP_FACTOR * 1.5f,
88                                                             0.5f - STYLE_2_CHILD_SIZE_FACTOR[2] - STYLE_2_CHILD_SIZE_FACTOR[3] * 0.25f - STYLE_2_CHILD_GAP_FACTOR,
89                                                             STYLE_2_CHILD_OFFSET_Z + 1.0f),
90                                                     Vector3(0.5f + STYLE_2_CHILD_GAP_FACTOR * 0.5f,
91                                                             0.5f - STYLE_2_CHILD_SIZE_FACTOR[3] * 0.25f,
92                                                             STYLE_2_CHILD_OFFSET_Z + 1.5f),
93                                                     Vector3(0.5f - STYLE_2_CHILD_SIZE_FACTOR[4] - STYLE_2_CHILD_GAP_FACTOR * 0.5f,
94                                                             0.5f + STYLE_2_CHILD_SIZE_FACTOR[0] * 0.25f + STYLE_2_CHILD_GAP_FACTOR,
95                                                             STYLE_2_CHILD_OFFSET_Z + 2.0f),
96                                                     Vector3(0.5f - STYLE_2_CHILD_SIZE_FACTOR[4] - STYLE_2_CHILD_SIZE_FACTOR[5] - STYLE_2_CHILD_GAP_FACTOR * 1.5f,
97                                                             0.5f + STYLE_2_CHILD_SIZE_FACTOR[0] * 0.25f + STYLE_2_CHILD_GAP_FACTOR,
98                                                             STYLE_2_CHILD_OFFSET_Z + 2.5f) };
99
100 const Vector3 STYLE_2_TITLE_SIZE_FACTOR = Vector3(0.3f, 0.11f, 1.0f);
101 const Vector3 STYLE_2_TITLE_POSITION_FACTOR = Vector3(0.5f - STYLE_2_CHILD_SIZE_FACTOR[0] - STYLE_2_CHILD_GAP_FACTOR * 0.5f,
102                                                         0.5f - STYLE_2_CHILD_SIZE_FACTOR[0] * 0.75f - STYLE_2_TITLE_SIZE_FACTOR.height + 0.02f,
103                                                         0.0f);
104 const Vector3 STYLE_2_TITLE_POSITION_OFFSET = Vector3(0.0f, 0.0f, 8.0f);
105
106 // Cluster style three
107
108 const unsigned int STYLE_3_CHILDREN_NUMBER = 6;
109
110 const Vector3 STYLE_3_TITLE_SIZE_FACTOR = Vector3(0.4f, 0.15f, 1.0f);
111
112 const float STYLE_3_BACKGROUND_IMAGE_OFFSET_Z = 1.0f;
113
114 const float STYLE_3_CHILD_OFFSET_Z = 2.0f;
115 const float STYLE_3_CHILD_GAP_FACTOR = 0.03f;
116 const float STYLE_3_CHILD_SIZE_FACTOR[] = { 0.4f, 0.4f, 0.15f, 0.25f, 0.25f, 0.15f };
117 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;
118 const Vector3 STYLE_3_CHILD_POSITION_FACTOR[] = { Vector3(0.5f - STYLE_3_CHILD_SIZE_FACTOR[0] - STYLE_3_CHILD_GAP_FACTOR * 0.5f,
119                                                               0.5f - STYLE_3_CHILD_SIZE_FACTOR[0] - STYLE_3_CHILD_GAP_FACTOR * 0.5f + STYLE_3_CHILD_POSITION_OFFSET_Y,
120                                                               STYLE_3_CHILD_OFFSET_Z),
121                                                       Vector3(0.5f + STYLE_3_CHILD_GAP_FACTOR * 0.5f,
122                                                               0.5f - STYLE_3_CHILD_SIZE_FACTOR[1] - STYLE_3_CHILD_GAP_FACTOR * 0.5f + STYLE_3_CHILD_POSITION_OFFSET_Y,
123                                                               STYLE_3_CHILD_OFFSET_Z + 0.5f),
124                                                       Vector3(0.5f + STYLE_3_CHILD_SIZE_FACTOR[3] + STYLE_3_CHILD_GAP_FACTOR * 1.5f,
125                                                               0.5f + STYLE_3_CHILD_GAP_FACTOR * 0.5f + STYLE_3_CHILD_POSITION_OFFSET_Y,
126                                                               STYLE_3_CHILD_OFFSET_Z + 1.0f),
127                                                       Vector3(0.5f + STYLE_3_CHILD_GAP_FACTOR * 0.5f,
128                                                               0.5f + STYLE_3_CHILD_GAP_FACTOR * 0.5f + STYLE_3_CHILD_POSITION_OFFSET_Y,
129                                                               STYLE_3_CHILD_OFFSET_Z + 1.5f),
130                                                       Vector3(0.5f - STYLE_3_CHILD_SIZE_FACTOR[4] - STYLE_3_CHILD_GAP_FACTOR * 0.5f,
131                                                               0.5f + STYLE_3_CHILD_GAP_FACTOR * 0.5f + STYLE_3_CHILD_POSITION_OFFSET_Y,
132                                                               STYLE_3_CHILD_OFFSET_Z + 2.0f),
133                                                       Vector3(0.5f - STYLE_3_CHILD_SIZE_FACTOR[4] - STYLE_3_CHILD_SIZE_FACTOR[5] - STYLE_3_CHILD_GAP_FACTOR * 1.5f,
134                                                               0.5f + STYLE_3_CHILD_GAP_FACTOR * 0.5f + STYLE_3_CHILD_POSITION_OFFSET_Y,
135                                                               STYLE_3_CHILD_OFFSET_Z + 2.5f) };
136
137 const Vector3 STYLE_3_TITLE_POSITION_FACTOR = Vector3(0.5f - STYLE_3_CHILD_SIZE_FACTOR[0] - STYLE_3_CHILD_GAP_FACTOR * 0.5f,
138                                                           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,
139                                                           0.0f);
140 const Vector3 STYLE_3_TITLE_POSITION_OFFSET = Vector3(0.0f, 0.0f, 8.0f);
141
142 // Cluster style four
143
144 const unsigned int STYLE_4_CHILDREN_NUMBER = 6;
145
146 const float STYLE_4_BACKGROUND_IMAGE_OFFSET_Z = 1.0f;
147
148 const float STYLE_4_CHILD_OFFSET_Z = 2.0f;
149 const float STYLE_4_CHILD_GAP_FACTOR = 0.03f;
150 const float STYLE_4_CHILD_SIZE_FACTOR[] = { 0.4f, 0.22f, 0.13f, 0.4f, 0.22f, 0.13f };
151 const Vector3 STYLE_4_CHILD_POSITION_FACTOR[] = { Vector3(0.5f - STYLE_4_CHILD_SIZE_FACTOR[0] * 0.9f,
152                                                              0.5f - STYLE_4_CHILD_SIZE_FACTOR[0] - STYLE_4_CHILD_GAP_FACTOR * 0.5f,
153                                                              STYLE_4_CHILD_OFFSET_Z),
154                                                      Vector3(0.5f + STYLE_4_CHILD_SIZE_FACTOR[0] * 0.1f + STYLE_4_CHILD_GAP_FACTOR,
155                                                              0.5f - STYLE_4_CHILD_SIZE_FACTOR[1] - STYLE_4_CHILD_GAP_FACTOR * 0.5f,
156                                                              STYLE_4_CHILD_OFFSET_Z + 0.5f),
157                                                      Vector3(0.5f + STYLE_4_CHILD_SIZE_FACTOR[0] * 0.1f + STYLE_4_CHILD_SIZE_FACTOR[1] + STYLE_4_CHILD_GAP_FACTOR * 2.0f,
158                                                              0.5f - STYLE_4_CHILD_SIZE_FACTOR[2] - STYLE_4_CHILD_GAP_FACTOR * 0.5f,
159                                                              STYLE_4_CHILD_OFFSET_Z + 1.0f),
160                                                      Vector3(0.5f - STYLE_4_CHILD_SIZE_FACTOR[3] * 0.1f,
161                                                              0.5f + STYLE_4_CHILD_GAP_FACTOR * 0.5f,
162                                                              STYLE_4_CHILD_OFFSET_Z + 1.5f),
163                                                      Vector3(0.5f - STYLE_4_CHILD_SIZE_FACTOR[3] * 0.1f - STYLE_4_CHILD_SIZE_FACTOR[4] - STYLE_4_CHILD_GAP_FACTOR,
164                                                              0.5f + STYLE_4_CHILD_GAP_FACTOR * 0.5f,
165                                                              STYLE_4_CHILD_OFFSET_Z + 2.0f),
166                                                      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,
167                                                              0.5f + STYLE_4_CHILD_GAP_FACTOR * 0.5f,
168                                                              STYLE_4_CHILD_OFFSET_Z + 2.5f) };
169
170 const Vector3 STYLE_4_TITLE_SIZE_FACTOR = Vector3(0.3f, 0.11f, 1.0f);
171 const Vector3 STYLE_4_TITLE_POSITION_FACTOR = Vector3(0.5f - STYLE_4_CHILD_SIZE_FACTOR[0] * 0.9f,
172                                                          0.5f - STYLE_4_CHILD_SIZE_FACTOR[0] - STYLE_4_CHILD_GAP_FACTOR * 0.5f - STYLE_4_TITLE_SIZE_FACTOR.height + 0.02f,
173                                                          0.0f);
174 const Vector3 STYLE_4_TITLE_POSITION_OFFSET = Vector3(0.0f, 0.0f, 8.0f);
175 const unsigned int CLUSTER_RANDOM_SEED(0x17eac9f3);         ///< Random seed for cluster data.
176
177 const int STYLE_RANDOM_CHILDREN_NUMBER = 16;
178
179 Vector3 FirstOrderEquation( const Vector3& source, const Vector3& relative, const Vector3& offset = Vector3::ZERO  )
180 {
181   return source * relative + offset;
182 }
183
184 // random data generator //////////////////////////////////////////////////////
185
186 const unsigned int GEN_RAND_CONST = 0x15d9a373;
187
188 unsigned int genRandom(unsigned int& seed, unsigned int offset)
189 {
190   unsigned int shft = offset&31;
191
192   offset++;
193
194   seed^= (seed << (shft) | seed >> (32 - shft)) * (offset * GEN_RAND_CONST);
195
196   return seed;
197 }
198
199 float genRandomFloat(unsigned int& seed, unsigned int offset, float min, float max)
200 {
201   const float f = static_cast<float>(genRandom(seed, offset)) / 0xffffffff;
202   return f * (max - min) + min;
203 }
204
205 } // unnamed namespace
206
207 namespace Toolkit
208 {
209
210 namespace Internal
211 {
212
213 // ClusterStyle ///////////////////////////////////////////////////////////////
214
215 ClusterStyle::ClusterStyle()
216 : mMaxChildren(0),
217   mTitlePositionRelative(Vector3::ONE),
218   mTitlePositionOffset(Vector3::ZERO),
219   mTitleSize(Vector3::ONE),
220   mBackgroundPositionRelative(Vector3::ONE),
221   mBackgroundPositionOffset(Vector3::ZERO),
222   mBackgroundSize(Vector3::ONE),
223   mClusterSize( Vector3::ZERO )
224 {
225 }
226
227 ClusterStyle::~ClusterStyle()
228 {
229
230 }
231
232 void ClusterStyle::SetMaximumNumberOfChildren(unsigned int maxChildren)
233 {
234   mMaxChildren = maxChildren;
235 }
236
237 unsigned int ClusterStyle::GetMaximumNumberOfChildren() const
238 {
239   return mMaxChildren;
240 }
241
242 void ClusterStyle::ApplyStyleToBackground(Actor background, AlphaFunction alpha, const TimePeriod& durationSeconds)
243 {
244   Apply( background,
245          FirstOrderEquation( GetClusterSize(), mBackgroundPositionRelative, mBackgroundPositionOffset ),
246          FirstOrderEquation( GetClusterSize(), mBackgroundSize ),
247          alpha,
248          durationSeconds);
249 }
250
251 void ClusterStyle::ApplyStyleToTitle(Actor title, AlphaFunction alpha, const TimePeriod& durationSeconds)
252 {
253   Apply( title,
254          FirstOrderEquation( GetClusterSize(), mTitlePositionRelative, mTitlePositionOffset ),
255          FirstOrderEquation( GetClusterSize(), mTitleSize ),
256          alpha,
257          durationSeconds);
258 }
259
260 void ClusterStyle::SetTitleProperties(const Vector3& relativePosition,
261                                       const Vector3& offsetPosition,
262                                       const Vector3& size)
263 {
264   mTitlePositionRelative = relativePosition;
265   mTitlePositionOffset = offsetPosition;
266   mTitleSize = size;
267 }
268
269 void ClusterStyle::SetBackgroundProperties(const Vector3& relativePosition,
270                                            const Vector3& offsetPosition,
271                                            const Vector3& size)
272 {
273   mBackgroundPositionRelative = relativePosition;
274   mBackgroundPositionOffset = offsetPosition;
275   mBackgroundSize = size;
276 }
277
278 void ClusterStyle::SetClusterSize( const Vector3& clusterSize )
279 {
280   mClusterSize = clusterSize;
281 }
282
283 Vector3 ClusterStyle::GetClusterSize() const
284 {
285   return mClusterSize;
286 }
287
288 void ClusterStyle::Apply( Actor actor,
289                           const Vector3& position,
290                           const Vector3& size,
291                           AlphaFunction alpha,
292                           const TimePeriod& durationSeconds)
293 {
294   float animationDuration = durationSeconds.delaySeconds + durationSeconds.durationSeconds;
295   if( animationDuration > 0.f )
296   {
297     Animation animation = Animation::New(animationDuration);
298     animation.MoveTo( actor, position, alpha, durationSeconds.delaySeconds, durationSeconds.durationSeconds );
299     animation.Resize( actor, size, alpha, durationSeconds.delaySeconds, durationSeconds.durationSeconds );
300     animation.Play();
301   }
302   else
303   {
304     actor.SetPosition( position );
305     actor.SetSize( size );
306   }
307 }
308
309 void ClusterStyle::Apply( Actor actor,
310                           const Vector3& position,
311                           const Vector3& size,
312                           const Quaternion& rotation,
313                           const Vector3& scale,
314                           AlphaFunction alpha,
315                           const TimePeriod& durationSeconds)
316 {
317   float animationDuration = durationSeconds.delaySeconds + durationSeconds.durationSeconds;
318   if( animationDuration > 0.f )
319   {
320     Animation animation = Animation::New(animationDuration);
321     animation.MoveTo( actor, position, alpha, durationSeconds.delaySeconds, durationSeconds.durationSeconds );
322     animation.Resize( actor, size, alpha, durationSeconds.delaySeconds, durationSeconds.durationSeconds );
323     animation.RotateTo( actor, rotation, alpha, durationSeconds.delaySeconds, durationSeconds.durationSeconds );
324     animation.ScaleTo( actor, scale, alpha, durationSeconds.delaySeconds, durationSeconds.durationSeconds );
325     animation.Play();
326   }
327   else
328   {
329     actor.SetPosition( position );
330     actor.SetSize( size );
331     actor.SetOrientation( rotation );
332     actor.SetScale( scale );
333   }
334 }
335
336 // ClusterStyleStandard ///////////////////////////////////////////////////////
337
338 ClusterStylePtr ClusterStyleStandard::New(StyleType style)
339 {
340   ClusterStylePtr impl( new ClusterStyleStandard(style) );
341
342   return impl;
343 }
344
345 ClusterStyleStandard::ClusterStyleStandard(StyleType style)
346 : ClusterStyle(),
347   mSizes(NULL),
348   mPositions(NULL)
349 {
350   switch(style)
351   {
352     case Toolkit::ClusterStyleStandard::ClusterStyle1:
353     {
354       SetMaximumNumberOfChildren(STYLE_1_CHILDREN_NUMBER);
355       SetSizes(STYLE_1_CHILD_SIZE_FACTOR);
356       SetPositions(STYLE_1_CHILD_POSITION_FACTOR);
357       SetTitleProperties(STYLE_1_TITLE_POSITION_FACTOR,
358                          STYLE_1_TITLE_POSITION_OFFSET,
359                          STYLE_1_TITLE_SIZE_FACTOR);
360       SetBackgroundProperties(Vector3::ZERO,
361                               Vector3(0.0f, 0.0f, STYLE_1_BACKGROUND_IMAGE_OFFSET_Z),
362                               Vector3::ONE);
363       break;
364     }
365     case Toolkit::ClusterStyleStandard::ClusterStyle2:
366     {
367       SetMaximumNumberOfChildren(STYLE_2_CHILDREN_NUMBER);
368       SetSizes(STYLE_2_CHILD_SIZE_FACTOR);
369       SetPositions(STYLE_2_CHILD_POSITION_FACTOR);
370       SetTitleProperties(STYLE_2_TITLE_POSITION_FACTOR,
371                          STYLE_2_TITLE_POSITION_OFFSET,
372                          STYLE_2_TITLE_SIZE_FACTOR);
373       SetBackgroundProperties(Vector3::ZERO,
374                               Vector3(0.0f, 0.0f, STYLE_2_BACKGROUND_IMAGE_OFFSET_Z),
375                               Vector3::ONE);
376       break;
377     }
378     case Toolkit::ClusterStyleStandard::ClusterStyle3:
379     {
380       SetMaximumNumberOfChildren(STYLE_3_CHILDREN_NUMBER);
381       SetSizes(STYLE_3_CHILD_SIZE_FACTOR);
382       SetPositions(STYLE_3_CHILD_POSITION_FACTOR);
383       SetTitleProperties(STYLE_3_TITLE_POSITION_FACTOR,
384                          STYLE_3_TITLE_POSITION_OFFSET,
385                          STYLE_3_TITLE_SIZE_FACTOR);
386       SetBackgroundProperties(Vector3::ZERO,
387                               Vector3(0.0f, 0.0f, STYLE_3_BACKGROUND_IMAGE_OFFSET_Z),
388                               Vector3::ONE);
389       break;
390     }
391     case Toolkit::ClusterStyleStandard::ClusterStyle4:
392     {
393       SetMaximumNumberOfChildren(STYLE_4_CHILDREN_NUMBER);
394       SetSizes(STYLE_4_CHILD_SIZE_FACTOR);
395       SetPositions(STYLE_4_CHILD_POSITION_FACTOR);
396       SetTitleProperties(STYLE_4_TITLE_POSITION_FACTOR,
397                          STYLE_4_TITLE_POSITION_OFFSET,
398                          STYLE_4_TITLE_SIZE_FACTOR);
399       SetBackgroundProperties(Vector3::ZERO,
400                               Vector3(0.0f, 0.0f, STYLE_4_BACKGROUND_IMAGE_OFFSET_Z),
401                               Vector3::ONE);
402       break;
403     }
404     default:
405     {
406       DALI_ASSERT_ALWAYS(false && "Invalid Style");
407       break;
408     }
409   } // end switch
410 }
411
412 void ClusterStyleStandard::SetSizes(const float *sizes)
413 {
414   mSizes = sizes;
415 }
416
417 void ClusterStyleStandard::SetPositions(const Vector3 *positions)
418 {
419   mPositions = positions;
420 }
421
422 void ClusterStyleStandard::ApplyStyle(Actor child, unsigned int index, AlphaFunction alpha, const TimePeriod& durationSeconds)
423 {
424   if(mPositions)
425   {
426     const float& size = mSizes[index];
427     // counter top-left parent origin and top-left anchor point.
428     const Vector3 position = mPositions[index] - Vector3(0.5f, 0.5f, 0.0f) + Vector3(size, size, 0.0f) * 0.5f;
429
430     Apply( child,
431            FirstOrderEquation( GetClusterSize(), Vector3(position.x, position.y, 0.0f), Vector3(0.0f, 0.0f, position.z) ),
432            FirstOrderEquation( GetClusterSize(), Vector3::ONE * size ),
433            Quaternion(),
434            Vector3::ONE,
435            alpha,
436            durationSeconds);
437   }
438 }
439
440 // ClusterStyleRandom /////////////////////////////////////////////////////////
441
442 ClusterStylePtr ClusterStyleRandom::New()
443 {
444   ClusterStylePtr impl( new ClusterStyleRandom() );
445
446   return impl;
447 }
448
449 ClusterStyleRandom::ClusterStyleRandom()
450 : ClusterStyle()
451 {
452   SetMaximumNumberOfChildren(STYLE_RANDOM_CHILDREN_NUMBER);
453   SetTitleProperties(Vector3::ZERO,
454                      Vector3::ZERO,
455                      Vector3::ONE);
456   SetBackgroundProperties(Vector3::ZERO,
457                           Vector3(0.0f, 0.0f, 0.0f),
458                           Vector3::ONE);
459 }
460
461 void ClusterStyleRandom::ApplyStyle(Actor child, unsigned int index, AlphaFunction alpha, const TimePeriod& durationSeconds)
462 {
463   unsigned int seed = CLUSTER_RANDOM_SEED;
464   const float size = 0.5f;
465   const float rotation = genRandomFloat(seed, index, -1.0f, 1.0f) * Math::PI * 0.1; // +/- 18 degrees
466   const Vector3 position(genRandomFloat(seed, index, -0.1f, 0.1f),
467                          genRandomFloat(seed, index, -0.1f, 0.1f),
468                          0.0f);
469
470   Property::Index depthProperty = child.GetPropertyIndex(Toolkit::Cluster::CLUSTER_ACTOR_DEPTH);
471   float depthPropertyValue = child.GetProperty<float>( depthProperty );
472
473   Apply( child,
474          FirstOrderEquation( GetClusterSize(), Vector3(position.x, position.y, 0.0f), Vector3(0.0f, 0.0f, depthPropertyValue) ),
475          FirstOrderEquation( GetClusterSize(), Vector3::ONE * size),
476          Quaternion(rotation, Vector3::ZAXIS),
477          Vector3::ONE,
478          alpha,
479          durationSeconds);
480 }
481
482 } // namespace Internal
483
484 } // namespace Toolkit
485
486 } // namespace Dali