2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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
8 // http://floralicense.org/license/
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.
18 #include <dali/dali.h>
19 #include <dali-toolkit/internal/controls/cluster/cluster-style-impl.h>
20 #include <dali-toolkit/public-api/controls/cluster/cluster.h>
25 namespace // unnamed namespace
29 const unsigned int STYLE_1_CHILDREN_NUMBER = 8;
31 const float STYLE_1_BACKGROUND_IMAGE_OFFSET_Z = 1.0f;
33 const float STYLE_1_CHILD_OFFSET_Z = 2.0f;
34 const float STYLE_1_CHILD_GAP_FACTOR = 0.03f;
35 const float STYLE_1_CHILD_SIZE_FACTOR[] = { 0.4f, 0.15f, 0.25f, 0.15f, 0.4f, 0.15f, 0.25f, 0.15f };
36 const Vector3 STYLE_1_CHILD_POSITION_FACTOR[] = { Vector3(0.5f - STYLE_1_CHILD_SIZE_FACTOR[0] - STYLE_1_CHILD_GAP_FACTOR * 0.5f,
37 0.5f - STYLE_1_CHILD_SIZE_FACTOR[0] - STYLE_1_CHILD_GAP_FACTOR * 0.5f,
38 STYLE_1_CHILD_OFFSET_Z),
39 Vector3(0.5f + STYLE_1_CHILD_GAP_FACTOR * 0.5f,
40 0.5f - STYLE_1_CHILD_SIZE_FACTOR[1] - STYLE_1_CHILD_SIZE_FACTOR[2] - STYLE_1_CHILD_GAP_FACTOR * 1.5f,
41 STYLE_1_CHILD_OFFSET_Z + 0.5f),
42 Vector3(0.5f + STYLE_1_CHILD_GAP_FACTOR * 0.5f,
43 0.5f - STYLE_1_CHILD_SIZE_FACTOR[2] - STYLE_1_CHILD_GAP_FACTOR * 0.5f,
44 STYLE_1_CHILD_OFFSET_Z + 1.0f),
45 Vector3(0.5f + STYLE_1_CHILD_SIZE_FACTOR[2] + STYLE_1_CHILD_GAP_FACTOR * 1.5f,
46 0.5f - STYLE_1_CHILD_SIZE_FACTOR[3] - STYLE_1_CHILD_GAP_FACTOR * 0.5f,
47 STYLE_1_CHILD_OFFSET_Z + 1.5f),
48 Vector3(0.5f + STYLE_1_CHILD_GAP_FACTOR * 0.5f,
49 0.5f + STYLE_1_CHILD_GAP_FACTOR * 0.5f,
50 STYLE_1_CHILD_OFFSET_Z + 2.0f),
51 Vector3(0.5f - STYLE_1_CHILD_SIZE_FACTOR[5] - STYLE_1_CHILD_GAP_FACTOR * 0.5f,
52 0.5f + STYLE_1_CHILD_SIZE_FACTOR[6] + STYLE_1_CHILD_GAP_FACTOR * 1.5f,
53 STYLE_1_CHILD_OFFSET_Z + 2.5f),
54 Vector3(0.5f - STYLE_1_CHILD_SIZE_FACTOR[6] - STYLE_1_CHILD_GAP_FACTOR * 0.5f,
55 0.5f + STYLE_1_CHILD_GAP_FACTOR * 0.5f,
56 STYLE_1_CHILD_OFFSET_Z + 3.0f),
57 Vector3(0.5f - STYLE_1_CHILD_SIZE_FACTOR[6] - STYLE_1_CHILD_SIZE_FACTOR[7] - STYLE_1_CHILD_GAP_FACTOR * 1.5f,
58 0.5f + STYLE_1_CHILD_GAP_FACTOR * 0.5f,
59 STYLE_1_CHILD_OFFSET_Z + 3.5f) };
61 const Vector3 STYLE_1_TITLE_SIZE_FACTOR = Vector3(0.3f, 0.11f, 1.0f);
62 const Vector3 STYLE_1_TITLE_POSITION_FACTOR = Vector3(0.5f - STYLE_1_CHILD_SIZE_FACTOR[0] - STYLE_1_CHILD_GAP_FACTOR * 0.5f,
63 0.5f - STYLE_1_CHILD_SIZE_FACTOR[0] - STYLE_1_CHILD_GAP_FACTOR * 0.5f - STYLE_1_TITLE_SIZE_FACTOR.height + 0.02f,
65 const Vector3 STYLE_1_TITLE_POSITION_OFFSET = Vector3(0.0f, 0.0f, 8.0f);
69 const unsigned int STYLE_2_CHILDREN_NUMBER = 6;
71 const float STYLE_2_BACKGROUND_IMAGE_OFFSET_Z = 1.0f;
73 const float STYLE_2_CHILD_OFFSET_Z = 2.0f;
74 const float STYLE_2_CHILD_GAP_FACTOR = 0.03f;
75 const float STYLE_2_CHILD_SIZE_FACTOR[] = { 0.4f, 0.25f, 0.15f, 0.4f, 0.25f, 0.15f };
76 const Vector3 STYLE_2_CHILD_POSITION_FACTOR[] = { Vector3(0.5f - STYLE_2_CHILD_SIZE_FACTOR[0] - STYLE_2_CHILD_GAP_FACTOR * 0.5f,
77 0.5f - STYLE_2_CHILD_SIZE_FACTOR[0] * 0.75f,
78 STYLE_2_CHILD_OFFSET_Z),
79 Vector3(0.5f + STYLE_2_CHILD_GAP_FACTOR * 0.5f,
80 0.5f - STYLE_2_CHILD_SIZE_FACTOR[1] - STYLE_2_CHILD_SIZE_FACTOR[3] * 0.25f - STYLE_2_CHILD_GAP_FACTOR,
81 STYLE_2_CHILD_OFFSET_Z + 0.5f),
82 Vector3(0.5f + STYLE_2_CHILD_SIZE_FACTOR[1] + STYLE_2_CHILD_GAP_FACTOR * 1.5f,
83 0.5f - STYLE_2_CHILD_SIZE_FACTOR[2] - STYLE_2_CHILD_SIZE_FACTOR[3] * 0.25f - STYLE_2_CHILD_GAP_FACTOR,
84 STYLE_2_CHILD_OFFSET_Z + 1.0f),
85 Vector3(0.5f + STYLE_2_CHILD_GAP_FACTOR * 0.5f,
86 0.5f - STYLE_2_CHILD_SIZE_FACTOR[3] * 0.25f,
87 STYLE_2_CHILD_OFFSET_Z + 1.5f),
88 Vector3(0.5f - STYLE_2_CHILD_SIZE_FACTOR[4] - STYLE_2_CHILD_GAP_FACTOR * 0.5f,
89 0.5f + STYLE_2_CHILD_SIZE_FACTOR[0] * 0.25f + STYLE_2_CHILD_GAP_FACTOR,
90 STYLE_2_CHILD_OFFSET_Z + 2.0f),
91 Vector3(0.5f - STYLE_2_CHILD_SIZE_FACTOR[4] - STYLE_2_CHILD_SIZE_FACTOR[5] - STYLE_2_CHILD_GAP_FACTOR * 1.5f,
92 0.5f + STYLE_2_CHILD_SIZE_FACTOR[0] * 0.25f + STYLE_2_CHILD_GAP_FACTOR,
93 STYLE_2_CHILD_OFFSET_Z + 2.5f) };
95 const Vector3 STYLE_2_TITLE_SIZE_FACTOR = Vector3(0.3f, 0.11f, 1.0f);
96 const Vector3 STYLE_2_TITLE_POSITION_FACTOR = Vector3(0.5f - STYLE_2_CHILD_SIZE_FACTOR[0] - STYLE_2_CHILD_GAP_FACTOR * 0.5f,
97 0.5f - STYLE_2_CHILD_SIZE_FACTOR[0] * 0.75f - STYLE_2_TITLE_SIZE_FACTOR.height + 0.02f,
99 const Vector3 STYLE_2_TITLE_POSITION_OFFSET = Vector3(0.0f, 0.0f, 8.0f);
101 // Cluster style three
103 const unsigned int STYLE_3_CHILDREN_NUMBER = 6;
105 const Vector3 STYLE_3_TITLE_SIZE_FACTOR = Vector3(0.4f, 0.15f, 1.0f);
107 const float STYLE_3_BACKGROUND_IMAGE_OFFSET_Z = 1.0f;
109 const float STYLE_3_CHILD_OFFSET_Z = 2.0f;
110 const float STYLE_3_CHILD_GAP_FACTOR = 0.03f;
111 const float STYLE_3_CHILD_SIZE_FACTOR[] = { 0.4f, 0.4f, 0.15f, 0.25f, 0.25f, 0.15f };
112 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;
113 const Vector3 STYLE_3_CHILD_POSITION_FACTOR[] = { Vector3(0.5f - STYLE_3_CHILD_SIZE_FACTOR[0] - STYLE_3_CHILD_GAP_FACTOR * 0.5f,
114 0.5f - STYLE_3_CHILD_SIZE_FACTOR[0] - STYLE_3_CHILD_GAP_FACTOR * 0.5f + STYLE_3_CHILD_POSITION_OFFSET_Y,
115 STYLE_3_CHILD_OFFSET_Z),
116 Vector3(0.5f + STYLE_3_CHILD_GAP_FACTOR * 0.5f,
117 0.5f - STYLE_3_CHILD_SIZE_FACTOR[1] - STYLE_3_CHILD_GAP_FACTOR * 0.5f + STYLE_3_CHILD_POSITION_OFFSET_Y,
118 STYLE_3_CHILD_OFFSET_Z + 0.5f),
119 Vector3(0.5f + STYLE_3_CHILD_SIZE_FACTOR[3] + STYLE_3_CHILD_GAP_FACTOR * 1.5f,
120 0.5f + STYLE_3_CHILD_GAP_FACTOR * 0.5f + STYLE_3_CHILD_POSITION_OFFSET_Y,
121 STYLE_3_CHILD_OFFSET_Z + 1.0f),
122 Vector3(0.5f + STYLE_3_CHILD_GAP_FACTOR * 0.5f,
123 0.5f + STYLE_3_CHILD_GAP_FACTOR * 0.5f + STYLE_3_CHILD_POSITION_OFFSET_Y,
124 STYLE_3_CHILD_OFFSET_Z + 1.5f),
125 Vector3(0.5f - STYLE_3_CHILD_SIZE_FACTOR[4] - STYLE_3_CHILD_GAP_FACTOR * 0.5f,
126 0.5f + STYLE_3_CHILD_GAP_FACTOR * 0.5f + STYLE_3_CHILD_POSITION_OFFSET_Y,
127 STYLE_3_CHILD_OFFSET_Z + 2.0f),
128 Vector3(0.5f - STYLE_3_CHILD_SIZE_FACTOR[4] - STYLE_3_CHILD_SIZE_FACTOR[5] - STYLE_3_CHILD_GAP_FACTOR * 1.5f,
129 0.5f + STYLE_3_CHILD_GAP_FACTOR * 0.5f + STYLE_3_CHILD_POSITION_OFFSET_Y,
130 STYLE_3_CHILD_OFFSET_Z + 2.5f) };
132 const Vector3 STYLE_3_TITLE_POSITION_FACTOR = Vector3(0.5f - STYLE_3_CHILD_SIZE_FACTOR[0] - STYLE_3_CHILD_GAP_FACTOR * 0.5f,
133 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 const Vector3 STYLE_3_TITLE_POSITION_OFFSET = Vector3(0.0f, 0.0f, 8.0f);
137 // Cluster style four
139 const unsigned int STYLE_4_CHILDREN_NUMBER = 6;
141 const float STYLE_4_BACKGROUND_IMAGE_OFFSET_Z = 1.0f;
143 const float STYLE_4_CHILD_OFFSET_Z = 2.0f;
144 const float STYLE_4_CHILD_GAP_FACTOR = 0.03f;
145 const float STYLE_4_CHILD_SIZE_FACTOR[] = { 0.4f, 0.22f, 0.13f, 0.4f, 0.22f, 0.13f };
146 const Vector3 STYLE_4_CHILD_POSITION_FACTOR[] = { Vector3(0.5f - STYLE_4_CHILD_SIZE_FACTOR[0] * 0.9f,
147 0.5f - STYLE_4_CHILD_SIZE_FACTOR[0] - STYLE_4_CHILD_GAP_FACTOR * 0.5f,
148 STYLE_4_CHILD_OFFSET_Z),
149 Vector3(0.5f + STYLE_4_CHILD_SIZE_FACTOR[0] * 0.1f + STYLE_4_CHILD_GAP_FACTOR,
150 0.5f - STYLE_4_CHILD_SIZE_FACTOR[1] - STYLE_4_CHILD_GAP_FACTOR * 0.5f,
151 STYLE_4_CHILD_OFFSET_Z + 0.5f),
152 Vector3(0.5f + STYLE_4_CHILD_SIZE_FACTOR[0] * 0.1f + STYLE_4_CHILD_SIZE_FACTOR[1] + STYLE_4_CHILD_GAP_FACTOR * 2.0f,
153 0.5f - STYLE_4_CHILD_SIZE_FACTOR[2] - STYLE_4_CHILD_GAP_FACTOR * 0.5f,
154 STYLE_4_CHILD_OFFSET_Z + 1.0f),
155 Vector3(0.5f - STYLE_4_CHILD_SIZE_FACTOR[3] * 0.1f,
156 0.5f + STYLE_4_CHILD_GAP_FACTOR * 0.5f,
157 STYLE_4_CHILD_OFFSET_Z + 1.5f),
158 Vector3(0.5f - STYLE_4_CHILD_SIZE_FACTOR[3] * 0.1f - STYLE_4_CHILD_SIZE_FACTOR[4] - STYLE_4_CHILD_GAP_FACTOR,
159 0.5f + STYLE_4_CHILD_GAP_FACTOR * 0.5f,
160 STYLE_4_CHILD_OFFSET_Z + 2.0f),
161 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,
162 0.5f + STYLE_4_CHILD_GAP_FACTOR * 0.5f,
163 STYLE_4_CHILD_OFFSET_Z + 2.5f) };
165 const Vector3 STYLE_4_TITLE_SIZE_FACTOR = Vector3(0.3f, 0.11f, 1.0f);
166 const Vector3 STYLE_4_TITLE_POSITION_FACTOR = Vector3(0.5f - STYLE_4_CHILD_SIZE_FACTOR[0] * 0.9f,
167 0.5f - STYLE_4_CHILD_SIZE_FACTOR[0] - STYLE_4_CHILD_GAP_FACTOR * 0.5f - STYLE_4_TITLE_SIZE_FACTOR.height + 0.02f,
169 const Vector3 STYLE_4_TITLE_POSITION_OFFSET = Vector3(0.0f, 0.0f, 8.0f);
170 const unsigned int CLUSTER_RANDOM_SEED(0x17eac9f3); ///< Random seed for cluster data.
172 const int STYLE_RANDOM_CHILDREN_NUMBER = 16;
177 * First order equation of the form y = Mx + C
178 * current' = current * relative + offset
180 struct FirstOrderEquationConstraint
183 * @param relative The relative multiplier of the source property
184 * @param offset The offset to add onto the result.
186 FirstOrderEquationConstraint(Vector3 relative, Vector3 offset = Vector3::ZERO)
187 : mRelative(relative),
192 Vector3 operator()(const Vector3& current,
193 const PropertyInput& sourceProperty)
195 const Vector3 source = sourceProperty.GetVector3();
197 return source * mRelative + mOffset;
208 * current' = current.xy | + Vector3::ONE.z
210 struct DepthConstraint
219 Vector3 operator()(const Vector3& current,
220 const PropertyInput& depthProperty)
222 Vector3 position(current);
223 position.z = depthProperty.GetFloat();
230 * Position Constraint.
231 * current' = current * relative + offset
233 struct PositionConstraint
236 * @param relative The relative multiplier of the source property
237 * @param offset The offset to add onto the result.
239 PositionConstraint(Vector3 relative, Vector3 offset = Vector3::ZERO)
240 : mRelative(relative),
245 Vector3 operator()(const Vector3& current,
246 const PropertyInput& sourceProperty,
247 const PropertyInput& depthProperty)
249 const Vector3 source = sourceProperty.GetVector3();
251 Vector3 position(source * mRelative + mOffset);
252 position.z += depthProperty.GetFloat();
265 SetConstraint(T value)
271 T operator()(const T& current)
279 // random data generator //////////////////////////////////////////////////////
281 const unsigned int GEN_RAND_CONST = 0x15d9a373;
283 unsigned int genRandom(unsigned int& seed, unsigned int offset)
285 unsigned int shft = offset&31;
289 seed^= (seed << (shft) | seed >> (32 - shft)) * (offset * GEN_RAND_CONST);
294 float genRandomFloat(unsigned int& seed, unsigned int offset)
296 return static_cast<float>(genRandom(seed, offset)) / 0xffffffff;
299 float genRandomFloat(unsigned int& seed, unsigned int offset, float min, float max)
301 const float f = static_cast<float>(genRandom(seed, offset)) / 0xffffffff;
302 return f * (max - min) + min;
305 } // unnamed namespace
313 // ClusterStyle ///////////////////////////////////////////////////////////////
315 ClusterStyle::ClusterStyle()
317 mTitlePositionRelative(Vector3::ONE),
318 mTitlePositionOffset(Vector3::ZERO),
319 mTitleSize(Vector3::ONE),
320 mBackgroundPositionRelative(Vector3::ONE),
321 mBackgroundPositionOffset(Vector3::ZERO),
322 mBackgroundSize(Vector3::ONE)
326 ClusterStyle::~ClusterStyle()
331 void ClusterStyle::SetMaximumNumberOfChildren(unsigned int maxChildren)
333 mMaxChildren = maxChildren;
336 unsigned int ClusterStyle::GetMaximumNumberOfChildren() const
341 void ClusterStyle::SetTitleProperties(const Vector3& relativePosition,
342 const Vector3& offsetPosition,
345 mTitlePositionRelative = relativePosition;
346 mTitlePositionOffset = offsetPosition;
350 void ClusterStyle::SetBackgroundProperties(const Vector3& relativePosition,
351 const Vector3& offsetPosition,
354 mBackgroundPositionRelative = relativePosition;
355 mBackgroundPositionOffset = offsetPosition;
356 mBackgroundSize = size;
359 // ClusterStyleStandard ///////////////////////////////////////////////////////
361 ClusterStylePtr ClusterStyleStandard::New(StyleType style)
363 ClusterStylePtr impl( new ClusterStyleStandard(style) );
368 ClusterStyleStandard::ClusterStyleStandard(StyleType style)
375 case Toolkit::ClusterStyleStandard::ClusterStyle1:
377 SetMaximumNumberOfChildren(STYLE_1_CHILDREN_NUMBER);
378 SetSizes(STYLE_1_CHILD_SIZE_FACTOR);
379 SetPositions(STYLE_1_CHILD_POSITION_FACTOR);
380 SetTitleProperties(STYLE_1_TITLE_POSITION_FACTOR,
381 STYLE_1_TITLE_POSITION_OFFSET,
382 STYLE_1_TITLE_SIZE_FACTOR);
383 SetBackgroundProperties(Vector3::ZERO,
384 Vector3(0.0f, 0.0f, STYLE_1_BACKGROUND_IMAGE_OFFSET_Z),
388 case Toolkit::ClusterStyleStandard::ClusterStyle2:
390 SetMaximumNumberOfChildren(STYLE_2_CHILDREN_NUMBER);
391 SetSizes(STYLE_2_CHILD_SIZE_FACTOR);
392 SetPositions(STYLE_2_CHILD_POSITION_FACTOR);
393 SetTitleProperties(STYLE_2_TITLE_POSITION_FACTOR,
394 STYLE_2_TITLE_POSITION_OFFSET,
395 STYLE_2_TITLE_SIZE_FACTOR);
396 SetBackgroundProperties(Vector3::ZERO,
397 Vector3(0.0f, 0.0f, STYLE_2_BACKGROUND_IMAGE_OFFSET_Z),
401 case Toolkit::ClusterStyleStandard::ClusterStyle3:
403 SetMaximumNumberOfChildren(STYLE_3_CHILDREN_NUMBER);
404 SetSizes(STYLE_3_CHILD_SIZE_FACTOR);
405 SetPositions(STYLE_3_CHILD_POSITION_FACTOR);
406 SetTitleProperties(STYLE_3_TITLE_POSITION_FACTOR,
407 STYLE_3_TITLE_POSITION_OFFSET,
408 STYLE_3_TITLE_SIZE_FACTOR);
409 SetBackgroundProperties(Vector3::ZERO,
410 Vector3(0.0f, 0.0f, STYLE_3_BACKGROUND_IMAGE_OFFSET_Z),
414 case Toolkit::ClusterStyleStandard::ClusterStyle4:
416 SetMaximumNumberOfChildren(STYLE_4_CHILDREN_NUMBER);
417 SetSizes(STYLE_4_CHILD_SIZE_FACTOR);
418 SetPositions(STYLE_4_CHILD_POSITION_FACTOR);
419 SetTitleProperties(STYLE_4_TITLE_POSITION_FACTOR,
420 STYLE_4_TITLE_POSITION_OFFSET,
421 STYLE_4_TITLE_SIZE_FACTOR);
422 SetBackgroundProperties(Vector3::ZERO,
423 Vector3(0.0f, 0.0f, STYLE_4_BACKGROUND_IMAGE_OFFSET_Z),
429 DALI_ASSERT_ALWAYS(false && "Invalid Style");
435 void ClusterStyleStandard::SetSizes(const float *sizes)
440 void ClusterStyleStandard::SetPositions(const Vector3 *positions)
442 mPositions = positions;
445 void ClusterStyleStandard::ApplyStyle(Actor child, unsigned int index, AlphaFunction alpha, const TimePeriod& durationSeconds)
449 const float& size = mSizes[index];
450 // counter top-left parent origin and top-left anchor point.
451 const Vector3 position = mPositions[index] - Vector3(0.5f, 0.5f, 0.0f) + Vector3(size, size, 0.0f) * 0.5f;
453 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
454 ParentSource( Actor::SIZE ),
455 FirstOrderEquationConstraint(Vector3(position.x, position.y, 0.0f),
456 Vector3(0.0f, 0.0f, position.z)) );
458 constraint.SetApplyTime(durationSeconds);
459 constraint.SetAlphaFunction(alpha);
460 constraint.SetRemoveAction(Constraint::Bake);
461 child.ApplyConstraint(constraint);
463 constraint = Constraint::New<Vector3>( Actor::SIZE,
464 ParentSource( Actor::SIZE ),
465 FirstOrderEquationConstraint(Vector3::ONE * size) );
466 constraint.SetApplyTime(durationSeconds);
467 constraint.SetAlphaFunction(alpha);
468 constraint.SetRemoveAction(Constraint::Bake);
469 child.ApplyConstraint(constraint);
471 constraint = Constraint::New<Quaternion>( Actor::ROTATION,
472 SetConstraint<Quaternion>(Quaternion()) );
473 constraint.SetApplyTime(durationSeconds);
474 constraint.SetAlphaFunction(alpha);
475 constraint.SetRemoveAction(Constraint::Bake);
476 child.ApplyConstraint(constraint);
478 constraint = Constraint::New<Vector3>( Actor::SCALE,
479 SetConstraint<Vector3>(Vector3::ONE) );
480 constraint.SetApplyTime(durationSeconds);
481 constraint.SetAlphaFunction(alpha);
482 constraint.SetRemoveAction(Constraint::Bake);
483 child.ApplyConstraint(constraint);
487 void ClusterStyleStandard::ApplyStyleToBackground(Actor background, AlphaFunction alpha, const TimePeriod& durationSeconds)
489 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
490 ParentSource( Actor::SIZE ),
491 FirstOrderEquationConstraint(mBackgroundPositionRelative, mBackgroundPositionOffset) );
492 constraint.SetApplyTime(durationSeconds);
493 constraint.SetAlphaFunction(alpha);
494 constraint.SetRemoveAction(Constraint::Bake);
495 background.ApplyConstraint(constraint);
497 constraint = Constraint::New<Vector3>( Actor::SIZE,
498 ParentSource( Actor::SIZE ),
499 FirstOrderEquationConstraint(mBackgroundSize) );
500 constraint.SetApplyTime(durationSeconds);
501 constraint.SetAlphaFunction(alpha);
502 constraint.SetRemoveAction(Constraint::Bake);
503 background.ApplyConstraint(constraint);
506 void ClusterStyleStandard::ApplyStyleToTitle(Actor title, AlphaFunction alpha, const TimePeriod& durationSeconds)
508 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
509 ParentSource( Actor::SIZE ),
510 FirstOrderEquationConstraint(mTitlePositionRelative, mTitlePositionOffset) );
511 constraint.SetApplyTime(durationSeconds);
512 constraint.SetAlphaFunction(alpha);
513 constraint.SetRemoveAction(Constraint::Bake);
514 title.ApplyConstraint(constraint);
516 constraint = Constraint::New<Vector3>( Actor::SIZE,
517 ParentSource( Actor::SIZE ),
518 FirstOrderEquationConstraint(mTitleSize) );
519 constraint.SetApplyTime(durationSeconds);
520 constraint.SetAlphaFunction(alpha);
521 constraint.SetRemoveAction(Constraint::Bake);
522 title.ApplyConstraint(constraint);
525 // ClusterStyleRandom /////////////////////////////////////////////////////////
527 ClusterStylePtr ClusterStyleRandom::New()
529 ClusterStylePtr impl( new ClusterStyleRandom() );
534 ClusterStyleRandom::ClusterStyleRandom()
537 SetMaximumNumberOfChildren(STYLE_RANDOM_CHILDREN_NUMBER);
538 SetTitleProperties(Vector3::ZERO,
541 SetBackgroundProperties(Vector3::ZERO,
542 Vector3(0.0f, 0.0f, 0.0f),
546 void ClusterStyleRandom::ApplyStyle(Actor child, unsigned int index, AlphaFunction alpha, const TimePeriod& durationSeconds)
548 unsigned int seed = CLUSTER_RANDOM_SEED;
549 const float size = 0.5f;
550 const float rotation = genRandomFloat(seed, index, -1.0f, 1.0f) * Math::PI * 0.1; // +/- 18 degrees
551 const Vector3 position(genRandomFloat(seed, index, -0.1f, 0.1f),
552 genRandomFloat(seed, index, -0.1f, 0.1f),
555 Property::Index depthProperty = child.GetPropertyIndex(Toolkit::Cluster::CLUSTER_ACTOR_DEPTH);
557 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
558 ParentSource( Actor::SIZE ),
559 FirstOrderEquationConstraint( Vector3(position.x, position.y, 0.0f),
560 Vector3(0.0f, 0.0f, position.z) ) );
562 constraint.SetApplyTime(durationSeconds);
563 constraint.SetAlphaFunction(alpha);
564 constraint.SetRemoveAction(Constraint::Bake);
565 child.ApplyConstraint(constraint);
567 // this constraint overrides the Z position. setting it to cluster-actor-depth
568 constraint = Constraint::New<Vector3>( Actor::POSITION,
569 LocalSource( depthProperty ),
572 constraint.SetAlphaFunction(alpha);
573 constraint.SetRemoveAction(Constraint::Bake);
574 child.ApplyConstraint(constraint);
576 constraint = Constraint::New<Vector3>( Actor::SIZE,
577 ParentSource( Actor::SIZE ),
578 FirstOrderEquationConstraint(Vector3::ONE * size) );
579 constraint.SetApplyTime(durationSeconds);
580 constraint.SetAlphaFunction(alpha);
581 constraint.SetRemoveAction(Constraint::Bake);
582 child.ApplyConstraint(constraint);
584 constraint = Constraint::New<Quaternion>( Actor::ROTATION,
585 SetConstraint<Quaternion>(Quaternion(rotation, Vector3::ZAXIS)) );
586 constraint.SetApplyTime(durationSeconds);
587 constraint.SetAlphaFunction(alpha);
588 constraint.SetRemoveAction(Constraint::Bake);
589 child.ApplyConstraint(constraint);
591 constraint = Constraint::New<Vector3>( Actor::SCALE,
592 SetConstraint<Vector3>(Vector3::ONE) );
593 constraint.SetApplyTime(durationSeconds);
594 constraint.SetAlphaFunction(alpha);
595 constraint.SetRemoveAction(Constraint::Bake);
596 child.ApplyConstraint(constraint);
599 void ClusterStyleRandom::ApplyStyleToBackground(Actor background, AlphaFunction alpha, const TimePeriod& durationSeconds)
601 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
602 ParentSource( Actor::SIZE ),
603 FirstOrderEquationConstraint(mBackgroundPositionRelative, mBackgroundPositionOffset) );
604 constraint.SetApplyTime(durationSeconds);
605 constraint.SetAlphaFunction(alpha);
606 constraint.SetRemoveAction(Constraint::Bake);
607 background.ApplyConstraint(constraint);
609 constraint = Constraint::New<Vector3>( Actor::SIZE,
610 ParentSource( Actor::SIZE ),
611 FirstOrderEquationConstraint(mBackgroundSize) );
612 constraint.SetApplyTime(durationSeconds);
613 constraint.SetAlphaFunction(alpha);
614 constraint.SetRemoveAction(Constraint::Bake);
615 background.ApplyConstraint(constraint);
618 void ClusterStyleRandom::ApplyStyleToTitle(Actor title, AlphaFunction alpha, const TimePeriod& durationSeconds)
620 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
621 ParentSource( Actor::SIZE ),
622 FirstOrderEquationConstraint(mTitlePositionRelative, mTitlePositionOffset) );
623 constraint.SetApplyTime(durationSeconds);
624 constraint.SetAlphaFunction(alpha);
625 constraint.SetRemoveAction(Constraint::Bake);
626 title.ApplyConstraint(constraint);
628 constraint = Constraint::New<Vector3>( Actor::SIZE,
629 ParentSource( Actor::SIZE ),
630 FirstOrderEquationConstraint(mTitleSize) );
631 constraint.SetApplyTime(durationSeconds);
632 constraint.SetAlphaFunction(alpha);
633 constraint.SetRemoveAction(Constraint::Bake);
634 title.ApplyConstraint(constraint);
637 } // namespace Internal
639 } // namespace Toolkit