2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
26 namespace // unnamed namespace
30 const unsigned int STYLE_1_CHILDREN_NUMBER = 8;
32 const float STYLE_1_BACKGROUND_IMAGE_OFFSET_Z = 1.0f;
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) };
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,
66 const Vector3 STYLE_1_TITLE_POSITION_OFFSET = Vector3(0.0f, 0.0f, 8.0f);
70 const unsigned int STYLE_2_CHILDREN_NUMBER = 6;
72 const float STYLE_2_BACKGROUND_IMAGE_OFFSET_Z = 1.0f;
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) };
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,
100 const Vector3 STYLE_2_TITLE_POSITION_OFFSET = Vector3(0.0f, 0.0f, 8.0f);
102 // Cluster style three
104 const unsigned int STYLE_3_CHILDREN_NUMBER = 6;
106 const Vector3 STYLE_3_TITLE_SIZE_FACTOR = Vector3(0.4f, 0.15f, 1.0f);
108 const float STYLE_3_BACKGROUND_IMAGE_OFFSET_Z = 1.0f;
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) };
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,
136 const Vector3 STYLE_3_TITLE_POSITION_OFFSET = Vector3(0.0f, 0.0f, 8.0f);
138 // Cluster style four
140 const unsigned int STYLE_4_CHILDREN_NUMBER = 6;
142 const float STYLE_4_BACKGROUND_IMAGE_OFFSET_Z = 1.0f;
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) };
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,
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.
173 const int STYLE_RANDOM_CHILDREN_NUMBER = 16;
178 * First order equation of the form y = Mx + C
179 * current' = current * relative + offset
181 struct FirstOrderEquationConstraint
184 * @param relative The relative multiplier of the source property
185 * @param offset The offset to add onto the result.
187 FirstOrderEquationConstraint(Vector3 relative, Vector3 offset = Vector3::ZERO)
188 : mRelative(relative),
193 Vector3 operator()(const Vector3& current,
194 const PropertyInput& sourceProperty)
196 const Vector3 source = sourceProperty.GetVector3();
198 return source * mRelative + mOffset;
209 * current' = current.xy | + Vector3::ONE.z
211 struct DepthConstraint
220 Vector3 operator()(const Vector3& current,
221 const PropertyInput& depthProperty)
223 Vector3 position(current);
224 position.z = depthProperty.GetFloat();
231 * Position Constraint.
232 * current' = current * relative + offset
234 struct PositionConstraint
237 * @param relative The relative multiplier of the source property
238 * @param offset The offset to add onto the result.
240 PositionConstraint(Vector3 relative, Vector3 offset = Vector3::ZERO)
241 : mRelative(relative),
246 Vector3 operator()(const Vector3& current,
247 const PropertyInput& sourceProperty,
248 const PropertyInput& depthProperty)
250 const Vector3 source = sourceProperty.GetVector3();
252 Vector3 position(source * mRelative + mOffset);
253 position.z += depthProperty.GetFloat();
266 SetConstraint(T value)
272 T operator()(const T& current)
280 // random data generator //////////////////////////////////////////////////////
282 const unsigned int GEN_RAND_CONST = 0x15d9a373;
284 unsigned int genRandom(unsigned int& seed, unsigned int offset)
286 unsigned int shft = offset&31;
290 seed^= (seed << (shft) | seed >> (32 - shft)) * (offset * GEN_RAND_CONST);
295 float genRandomFloat(unsigned int& seed, unsigned int offset)
297 return static_cast<float>(genRandom(seed, offset)) / 0xffffffff;
300 float genRandomFloat(unsigned int& seed, unsigned int offset, float min, float max)
302 const float f = static_cast<float>(genRandom(seed, offset)) / 0xffffffff;
303 return f * (max - min) + min;
306 } // unnamed namespace
314 // ClusterStyle ///////////////////////////////////////////////////////////////
316 ClusterStyle::ClusterStyle()
318 mTitlePositionRelative(Vector3::ONE),
319 mTitlePositionOffset(Vector3::ZERO),
320 mTitleSize(Vector3::ONE),
321 mBackgroundPositionRelative(Vector3::ONE),
322 mBackgroundPositionOffset(Vector3::ZERO),
323 mBackgroundSize(Vector3::ONE)
327 ClusterStyle::~ClusterStyle()
332 void ClusterStyle::SetMaximumNumberOfChildren(unsigned int maxChildren)
334 mMaxChildren = maxChildren;
337 unsigned int ClusterStyle::GetMaximumNumberOfChildren() const
342 void ClusterStyle::SetTitleProperties(const Vector3& relativePosition,
343 const Vector3& offsetPosition,
346 mTitlePositionRelative = relativePosition;
347 mTitlePositionOffset = offsetPosition;
351 void ClusterStyle::SetBackgroundProperties(const Vector3& relativePosition,
352 const Vector3& offsetPosition,
355 mBackgroundPositionRelative = relativePosition;
356 mBackgroundPositionOffset = offsetPosition;
357 mBackgroundSize = size;
360 // ClusterStyleStandard ///////////////////////////////////////////////////////
362 ClusterStylePtr ClusterStyleStandard::New(StyleType style)
364 ClusterStylePtr impl( new ClusterStyleStandard(style) );
369 ClusterStyleStandard::ClusterStyleStandard(StyleType style)
376 case Toolkit::ClusterStyleStandard::ClusterStyle1:
378 SetMaximumNumberOfChildren(STYLE_1_CHILDREN_NUMBER);
379 SetSizes(STYLE_1_CHILD_SIZE_FACTOR);
380 SetPositions(STYLE_1_CHILD_POSITION_FACTOR);
381 SetTitleProperties(STYLE_1_TITLE_POSITION_FACTOR,
382 STYLE_1_TITLE_POSITION_OFFSET,
383 STYLE_1_TITLE_SIZE_FACTOR);
384 SetBackgroundProperties(Vector3::ZERO,
385 Vector3(0.0f, 0.0f, STYLE_1_BACKGROUND_IMAGE_OFFSET_Z),
389 case Toolkit::ClusterStyleStandard::ClusterStyle2:
391 SetMaximumNumberOfChildren(STYLE_2_CHILDREN_NUMBER);
392 SetSizes(STYLE_2_CHILD_SIZE_FACTOR);
393 SetPositions(STYLE_2_CHILD_POSITION_FACTOR);
394 SetTitleProperties(STYLE_2_TITLE_POSITION_FACTOR,
395 STYLE_2_TITLE_POSITION_OFFSET,
396 STYLE_2_TITLE_SIZE_FACTOR);
397 SetBackgroundProperties(Vector3::ZERO,
398 Vector3(0.0f, 0.0f, STYLE_2_BACKGROUND_IMAGE_OFFSET_Z),
402 case Toolkit::ClusterStyleStandard::ClusterStyle3:
404 SetMaximumNumberOfChildren(STYLE_3_CHILDREN_NUMBER);
405 SetSizes(STYLE_3_CHILD_SIZE_FACTOR);
406 SetPositions(STYLE_3_CHILD_POSITION_FACTOR);
407 SetTitleProperties(STYLE_3_TITLE_POSITION_FACTOR,
408 STYLE_3_TITLE_POSITION_OFFSET,
409 STYLE_3_TITLE_SIZE_FACTOR);
410 SetBackgroundProperties(Vector3::ZERO,
411 Vector3(0.0f, 0.0f, STYLE_3_BACKGROUND_IMAGE_OFFSET_Z),
415 case Toolkit::ClusterStyleStandard::ClusterStyle4:
417 SetMaximumNumberOfChildren(STYLE_4_CHILDREN_NUMBER);
418 SetSizes(STYLE_4_CHILD_SIZE_FACTOR);
419 SetPositions(STYLE_4_CHILD_POSITION_FACTOR);
420 SetTitleProperties(STYLE_4_TITLE_POSITION_FACTOR,
421 STYLE_4_TITLE_POSITION_OFFSET,
422 STYLE_4_TITLE_SIZE_FACTOR);
423 SetBackgroundProperties(Vector3::ZERO,
424 Vector3(0.0f, 0.0f, STYLE_4_BACKGROUND_IMAGE_OFFSET_Z),
430 DALI_ASSERT_ALWAYS(false && "Invalid Style");
436 void ClusterStyleStandard::SetSizes(const float *sizes)
441 void ClusterStyleStandard::SetPositions(const Vector3 *positions)
443 mPositions = positions;
446 void ClusterStyleStandard::ApplyStyle(Actor child, unsigned int index, AlphaFunction alpha, const TimePeriod& durationSeconds)
450 const float& size = mSizes[index];
451 // counter top-left parent origin and top-left anchor point.
452 const Vector3 position = mPositions[index] - Vector3(0.5f, 0.5f, 0.0f) + Vector3(size, size, 0.0f) * 0.5f;
454 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
455 ParentSource( Actor::SIZE ),
456 FirstOrderEquationConstraint(Vector3(position.x, position.y, 0.0f),
457 Vector3(0.0f, 0.0f, position.z)) );
459 constraint.SetApplyTime(durationSeconds);
460 constraint.SetAlphaFunction(alpha);
461 constraint.SetRemoveAction(Constraint::Bake);
462 child.ApplyConstraint(constraint);
464 constraint = Constraint::New<Vector3>( Actor::SIZE,
465 ParentSource( Actor::SIZE ),
466 FirstOrderEquationConstraint(Vector3::ONE * size) );
467 constraint.SetApplyTime(durationSeconds);
468 constraint.SetAlphaFunction(alpha);
469 constraint.SetRemoveAction(Constraint::Bake);
470 child.ApplyConstraint(constraint);
472 constraint = Constraint::New<Quaternion>( Actor::ROTATION,
473 SetConstraint<Quaternion>(Quaternion()) );
474 constraint.SetApplyTime(durationSeconds);
475 constraint.SetAlphaFunction(alpha);
476 constraint.SetRemoveAction(Constraint::Bake);
477 child.ApplyConstraint(constraint);
479 constraint = Constraint::New<Vector3>( Actor::SCALE,
480 SetConstraint<Vector3>(Vector3::ONE) );
481 constraint.SetApplyTime(durationSeconds);
482 constraint.SetAlphaFunction(alpha);
483 constraint.SetRemoveAction(Constraint::Bake);
484 child.ApplyConstraint(constraint);
488 void ClusterStyleStandard::ApplyStyleToBackground(Actor background, AlphaFunction alpha, const TimePeriod& durationSeconds)
490 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
491 ParentSource( Actor::SIZE ),
492 FirstOrderEquationConstraint(mBackgroundPositionRelative, mBackgroundPositionOffset) );
493 constraint.SetApplyTime(durationSeconds);
494 constraint.SetAlphaFunction(alpha);
495 constraint.SetRemoveAction(Constraint::Bake);
496 background.ApplyConstraint(constraint);
498 constraint = Constraint::New<Vector3>( Actor::SIZE,
499 ParentSource( Actor::SIZE ),
500 FirstOrderEquationConstraint(mBackgroundSize) );
501 constraint.SetApplyTime(durationSeconds);
502 constraint.SetAlphaFunction(alpha);
503 constraint.SetRemoveAction(Constraint::Bake);
504 background.ApplyConstraint(constraint);
507 void ClusterStyleStandard::ApplyStyleToTitle(Actor title, AlphaFunction alpha, const TimePeriod& durationSeconds)
509 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
510 ParentSource( Actor::SIZE ),
511 FirstOrderEquationConstraint(mTitlePositionRelative, mTitlePositionOffset) );
512 constraint.SetApplyTime(durationSeconds);
513 constraint.SetAlphaFunction(alpha);
514 constraint.SetRemoveAction(Constraint::Bake);
515 title.ApplyConstraint(constraint);
517 constraint = Constraint::New<Vector3>( Actor::SIZE,
518 ParentSource( Actor::SIZE ),
519 FirstOrderEquationConstraint(mTitleSize) );
520 constraint.SetApplyTime(durationSeconds);
521 constraint.SetAlphaFunction(alpha);
522 constraint.SetRemoveAction(Constraint::Bake);
523 title.ApplyConstraint(constraint);
526 // ClusterStyleRandom /////////////////////////////////////////////////////////
528 ClusterStylePtr ClusterStyleRandom::New()
530 ClusterStylePtr impl( new ClusterStyleRandom() );
535 ClusterStyleRandom::ClusterStyleRandom()
538 SetMaximumNumberOfChildren(STYLE_RANDOM_CHILDREN_NUMBER);
539 SetTitleProperties(Vector3::ZERO,
542 SetBackgroundProperties(Vector3::ZERO,
543 Vector3(0.0f, 0.0f, 0.0f),
547 void ClusterStyleRandom::ApplyStyle(Actor child, unsigned int index, AlphaFunction alpha, const TimePeriod& durationSeconds)
549 unsigned int seed = CLUSTER_RANDOM_SEED;
550 const float size = 0.5f;
551 const float rotation = genRandomFloat(seed, index, -1.0f, 1.0f) * Math::PI * 0.1; // +/- 18 degrees
552 const Vector3 position(genRandomFloat(seed, index, -0.1f, 0.1f),
553 genRandomFloat(seed, index, -0.1f, 0.1f),
556 Property::Index depthProperty = child.GetPropertyIndex(Toolkit::Cluster::CLUSTER_ACTOR_DEPTH);
558 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
559 ParentSource( Actor::SIZE ),
560 FirstOrderEquationConstraint( Vector3(position.x, position.y, 0.0f),
561 Vector3(0.0f, 0.0f, position.z) ) );
563 constraint.SetApplyTime(durationSeconds);
564 constraint.SetAlphaFunction(alpha);
565 constraint.SetRemoveAction(Constraint::Bake);
566 child.ApplyConstraint(constraint);
568 // this constraint overrides the Z position. setting it to cluster-actor-depth
569 constraint = Constraint::New<Vector3>( Actor::POSITION,
570 LocalSource( depthProperty ),
573 constraint.SetAlphaFunction(alpha);
574 constraint.SetRemoveAction(Constraint::Bake);
575 child.ApplyConstraint(constraint);
577 constraint = Constraint::New<Vector3>( Actor::SIZE,
578 ParentSource( Actor::SIZE ),
579 FirstOrderEquationConstraint(Vector3::ONE * size) );
580 constraint.SetApplyTime(durationSeconds);
581 constraint.SetAlphaFunction(alpha);
582 constraint.SetRemoveAction(Constraint::Bake);
583 child.ApplyConstraint(constraint);
585 constraint = Constraint::New<Quaternion>( Actor::ROTATION,
586 SetConstraint<Quaternion>(Quaternion(rotation, Vector3::ZAXIS)) );
587 constraint.SetApplyTime(durationSeconds);
588 constraint.SetAlphaFunction(alpha);
589 constraint.SetRemoveAction(Constraint::Bake);
590 child.ApplyConstraint(constraint);
592 constraint = Constraint::New<Vector3>( Actor::SCALE,
593 SetConstraint<Vector3>(Vector3::ONE) );
594 constraint.SetApplyTime(durationSeconds);
595 constraint.SetAlphaFunction(alpha);
596 constraint.SetRemoveAction(Constraint::Bake);
597 child.ApplyConstraint(constraint);
600 void ClusterStyleRandom::ApplyStyleToBackground(Actor background, AlphaFunction alpha, const TimePeriod& durationSeconds)
602 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
603 ParentSource( Actor::SIZE ),
604 FirstOrderEquationConstraint(mBackgroundPositionRelative, mBackgroundPositionOffset) );
605 constraint.SetApplyTime(durationSeconds);
606 constraint.SetAlphaFunction(alpha);
607 constraint.SetRemoveAction(Constraint::Bake);
608 background.ApplyConstraint(constraint);
610 constraint = Constraint::New<Vector3>( Actor::SIZE,
611 ParentSource( Actor::SIZE ),
612 FirstOrderEquationConstraint(mBackgroundSize) );
613 constraint.SetApplyTime(durationSeconds);
614 constraint.SetAlphaFunction(alpha);
615 constraint.SetRemoveAction(Constraint::Bake);
616 background.ApplyConstraint(constraint);
619 void ClusterStyleRandom::ApplyStyleToTitle(Actor title, AlphaFunction alpha, const TimePeriod& durationSeconds)
621 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
622 ParentSource( Actor::SIZE ),
623 FirstOrderEquationConstraint(mTitlePositionRelative, mTitlePositionOffset) );
624 constraint.SetApplyTime(durationSeconds);
625 constraint.SetAlphaFunction(alpha);
626 constraint.SetRemoveAction(Constraint::Bake);
627 title.ApplyConstraint(constraint);
629 constraint = Constraint::New<Vector3>( Actor::SIZE,
630 ParentSource( Actor::SIZE ),
631 FirstOrderEquationConstraint(mTitleSize) );
632 constraint.SetApplyTime(durationSeconds);
633 constraint.SetAlphaFunction(alpha);
634 constraint.SetRemoveAction(Constraint::Bake);
635 title.ApplyConstraint(constraint);
638 } // namespace Internal
640 } // namespace Toolkit