Commit f44aff0bbc47e057f0bbd1f5bb7446431c944141

Authored by Kingsley Stephens
1 parent 9c2ab463

Delete view from toolkit and move cluster into demo

Change-Id: I54fd5e2f166a4f487a6b1e7e5193ad25f5411bd6
examples/animated-shapes/animated-shapes-example.cpp
... ... @@ -55,16 +55,14 @@ public:
55 55 Stage stage = Stage::GetCurrent();
56 56  
57 57 //Create a view
58   - mView = Dali::Toolkit::View::New();
  58 + mView = Dali::Toolkit::Control::New();
  59 + mView.SetAnchorPoint( Dali::AnchorPoint::CENTER );
  60 + mView.SetParentOrigin( Dali::ParentOrigin::CENTER );
59 61 mView.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
60 62 stage.Add( mView );
61 63  
62 64 //Set background image for the view
63   - Image image = ResourceImage::New( BACKGROUND_IMAGE );
64   -
65   -
66   - Dali::ImageActor backgroundImageActor = Dali::ImageActor::New( image );
67   - mView.SetBackground( backgroundImageActor );
  65 + mView.SetBackgroundImage( ResourceImage::New( BACKGROUND_IMAGE ) );
68 66  
69 67 CreateTriangleMorph(Vector3( stage.GetSize().x*0.5f,stage.GetSize().y*0.15f,0.0f), 100.0f );
70 68 CreateCircleMorph( Vector3( stage.GetSize().x*0.5f,stage.GetSize().y*0.85f,0.0f), 60.0f );
... ... @@ -364,7 +362,7 @@ public:
364 362  
365 363 private:
366 364 Application& mApplication;
367   - Toolkit::View mView;
  365 + Toolkit::Control mView;
368 366 };
369 367  
370 368 void RunTest( Application& application )
... ...
examples/atlas/atlas-example.cpp
... ... @@ -207,7 +207,7 @@ private:
207 207 Application& mApplication;
208 208 PanGestureDetector mPanGestureDetector;
209 209  
210   - Toolkit::View mView; ///< The View instance.
  210 + Toolkit::Control mView; ///< The View instance.
211 211 Toolkit::ToolBar mToolBar; ///< The View's Toolbar.
212 212 Layer mContentLayer; ///< Content layer (scrolling cluster content)
213 213 Toolkit::PushButton mLoseContextButton;
... ...
examples/blocks/blocks-example.cpp
... ... @@ -806,7 +806,7 @@ private:
806 806 private:
807 807  
808 808 Application& mApplication; ///< Application instance
809   - Toolkit::View mView; ///< The View instance.
  809 + Toolkit::Control mView; ///< The View instance.
810 810 Layer mContentLayer; ///< The content layer (contains game actors)
811 811 ImageActor mBall; ///< The Moving ball image.
812 812 Vector3 mBallStartPosition; ///< Ball Start position
... ...
examples/bubble-effect/bubble-effect-example.cpp
... ... @@ -101,7 +101,7 @@ private:
101 101 // Creates a default view with a default tool bar.
102 102 // The view is added to the stage.
103 103 Toolkit::ToolBar toolBar;
104   - Toolkit::View view;
  104 + Toolkit::Control view;
105 105 Layer content = DemoHelper::CreateView( app,
106 106 view,
107 107 toolBar,
... ... @@ -141,8 +141,8 @@ private:
141 141 content.Add( bubbleRoot );
142 142  
143 143 // Add the background image actor to stage
144   - mBackgroundActor = ImageActor::New( mBackgroundImage );
145   - view.SetBackground( mBackgroundActor );
  144 + view.SetBackgroundImage( mBackgroundImage );
  145 + mBackgroundActor = ImageActor::DownCast( view.GetBackgroundActor() );
146 146  
147 147 // Set up the timer to emit bubble regularly when the finger is touched down but not moved
148 148 mTimerForBubbleEmission = Timer::New( mTimerInterval );
... ...
examples/builder/examples.cpp
... ... @@ -587,7 +587,7 @@ private:
587 587 GridLayoutPtr mGridLayout;
588 588 ItemView mItemView;
589 589  
590   - Toolkit::View mView;
  590 + Toolkit::Control mView;
591 591 unsigned int mOrientation;
592 592  
593 593 Toolkit::ToolBar mToolBar;
... ...
examples/buttons/buttons-example.cpp
... ... @@ -497,7 +497,7 @@ class ButtonsController: public ConnectionTracker
497 497 private:
498 498  
499 499 Application& mApplication;
500   - Toolkit::View mView; ///< The View instance.
  500 + Toolkit::Control mView; ///< The View instance.
501 501 Toolkit::ToolBar mToolBar; ///< The View's Toolbar.
502 502 Layer mContentLayer; ///< Content layer
503 503  
... ...
examples/cluster/cluster-example.cpp
... ... @@ -22,7 +22,12 @@
22 22 #include <dali/dali.h>
23 23 #include <dali-toolkit/dali-toolkit.h>
24 24  
  25 +#include "cluster.h"
  26 +#include "cluster-style.h"
  27 +
  28 +
25 29 using namespace Dali;
  30 +using namespace Dali::Demo;
26 31 using namespace Dali::Toolkit;
27 32 using namespace DemoHelper;
28 33  
... ... @@ -449,8 +454,6 @@ public:
449 454  
450 455 Stage::GetCurrent().KeyEventSignal().Connect(this, &ClusterController::OnKeyEvent);
451 456  
452   - Vector2 stageSize = Stage::GetCurrent().GetSize();
453   -
454 457 // The Init signal is received once (only) during the Application lifetime
455 458  
456 459 // Hide the indicator bar
... ... @@ -477,7 +480,7 @@ public:
477 480  
478 481 // create and setup the scroll view...
479 482 mScrollView = ScrollView::New();
480   - mScrollView.SetSize(stageSize);
  483 + mScrollView.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
481 484  
482 485 // attach Wobble Effect to ScrollView
483 486 mScrollViewEffect = ScrollViewWobbleEffect::New();
... ... @@ -842,9 +845,9 @@ public:
842 845 private:
843 846  
844 847 Application& mApplication; ///< Application instance
845   - Toolkit::View mView; ///< The View instance.
  848 + Toolkit::Control mView; ///< The View instance.
846 849 Toolkit::ToolBar mToolBar; ///< The View's Toolbar.
847   - TextLabel mTitleActor; ///< The Toolbar's Title.
  850 + TextLabel mTitleActor; ///< The Toolbar's Title.
848 851  
849 852 Layer mContentLayer; ///< Content layer (scrolling cluster content)
850 853  
... ...
examples/cluster/cluster-impl.cpp 0 โ†’ 100644
  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 "cluster-impl.h"
  20 +
  21 +// EXTERNAL INCLUDES
  22 +#include <algorithm>
  23 +#include <cstring> // for strcmp
  24 +#include <dali/public-api/animation/animation.h>
  25 +#include <dali/public-api/object/type-registry.h>
  26 +#include <dali/public-api/object/type-registry-helper.h>
  27 +#include <dali/integration-api/debug.h>
  28 +
  29 +// INTERNAL INCLUDES
  30 +#include "cluster-style.h"
  31 +#include "cluster-style-impl.h"
  32 +
  33 +using namespace Dali;
  34 +
  35 +namespace Dali
  36 +{
  37 +
  38 +namespace Demo
  39 +{
  40 +
  41 +namespace Internal
  42 +{
  43 +
  44 +namespace
  45 +{
  46 +
  47 +BaseHandle Create()
  48 +{
  49 + Demo::ClusterStyleStandard s = Demo::ClusterStyleStandard::New( Demo::ClusterStyleStandard::ClusterStyle1 );
  50 + return Demo::Cluster::New( s );
  51 +}
  52 +
  53 +DALI_TYPE_REGISTRATION_BEGIN( Demo::Cluster, Toolkit::Control, Create )
  54 +
  55 +DALI_ACTION_REGISTRATION( Demo, Cluster, "expand", ACTION_EXPAND )
  56 +DALI_ACTION_REGISTRATION( Demo, Cluster, "collapse", ACTION_COLLAPSE )
  57 +DALI_ACTION_REGISTRATION( Demo, Cluster, "transform", ACTION_TRANSFORM )
  58 +
  59 +DALI_TYPE_REGISTRATION_END()
  60 +
  61 +const float CLUSTER_STYLE_CONSTRAINT_DURATION = 1.0f;
  62 +
  63 +}
  64 +
  65 +///////////////////////////////////////////////////////////////////////////////////////////////////
  66 +// Cluster
  67 +///////////////////////////////////////////////////////////////////////////////////////////////////
  68 +
  69 +Dali::Demo::Cluster Cluster::New(Demo::ClusterStyle& style)
  70 +{
  71 + // Create the implementation
  72 + ClusterPtr cluster(new Cluster(style));
  73 +
  74 + // Pass ownership to CustomActor via derived handle
  75 + Dali::Demo::Cluster handle(*cluster);
  76 +
  77 + // Second-phase init of the implementation
  78 + // This can only be done after the CustomActor connection has been made...
  79 + cluster->Initialize();
  80 +
  81 + return handle;
  82 +}
  83 +
  84 +Cluster::Cluster(Demo::ClusterStyle& style)
  85 +: Toolkit::Internal::Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS | DISABLE_SIZE_NEGOTIATION ) ),
  86 + mClusterStyle(style),
  87 + mExpandedCount(0)
  88 +{
  89 +}
  90 +
  91 +void Cluster::OnInitialize()
  92 +{
  93 +}
  94 +
  95 +void Cluster::OnControlSizeSet( const Vector3& targetSize )
  96 +{
  97 + mClusterSize = targetSize;
  98 + GetImpl(mClusterStyle).SetClusterSize(targetSize);
  99 +
  100 + for(ChildInfoIter iter = mChildren.begin(); iter != mChildren.end(); ++iter)
  101 + {
  102 +
  103 + if((*iter).mActor)
  104 + {
  105 + mClusterStyle.ApplyStyle( (*iter).mActor,
  106 + (*iter).mPositionIndex,
  107 + AlphaFunctions::EaseOut,
  108 + 0.f );
  109 + }
  110 + }
  111 +
  112 + UpdateBackground(0.f);
  113 + UpdateTitle(0.f);
  114 +}
  115 +
  116 +Cluster::~Cluster()
  117 +{
  118 +}
  119 +
  120 +void Cluster::AddChild( Actor child )
  121 +{
  122 + // automatically add child with a position at end.
  123 + AddChild( child, mChildren.size() );
  124 +}
  125 +
  126 +void Cluster::AddChild( Actor child, unsigned int positionIndex )
  127 +{
  128 + AddChildInfo( ChildInfo(child, positionIndex) );
  129 +}
  130 +
  131 +void Cluster::AddChildAt( Actor child, unsigned int index )
  132 +{
  133 + // automatically add child with a position at end.
  134 + AddChild( child, mChildren.size() );
  135 +}
  136 +
  137 +void Cluster::AddChildAt( Actor child, unsigned int positionIndex, unsigned int index )
  138 +{
  139 + AddChildInfoAt( ChildInfo(child, positionIndex), index );
  140 +}
  141 +
  142 +void Cluster::AddChildInfo( ChildInfo childInfo )
  143 +{
  144 + AddChildInfoAt(childInfo, mChildren.size());
  145 +}
  146 +
  147 +void Cluster::AddChildInfoAt( ChildInfo childInfo, unsigned int index )
  148 +{
  149 + // check that the child is valid
  150 + DALI_ASSERT_ALWAYS( childInfo.mActor );
  151 +
  152 + ChildInfoIter offset = index < mChildren.size() ? (mChildren.begin() + index) : mChildren.end();
  153 + // now perform customization on this child.
  154 +
  155 + // adopt the child
  156 + if(childInfo.mActor.GetParent() != Self())
  157 + {
  158 + Actor& child = childInfo.mActor;
  159 + const float depth = std::distance(mChildren.begin(), offset);
  160 +
  161 + Property::Index depthProperty = child.GetPropertyIndex(Demo::Cluster::CLUSTER_ACTOR_DEPTH);
  162 + if(depthProperty == Property::INVALID_INDEX)
  163 + {
  164 + child.RegisterProperty(Demo::Cluster::CLUSTER_ACTOR_DEPTH, depth);
  165 + }
  166 +
  167 + // not added prior
  168 + Self().Add( childInfo.mActor );
  169 + mChildren.insert( offset, childInfo );
  170 +
  171 + // Use parent position plus relative position.
  172 + child.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
  173 +
  174 + // remove old constraints
  175 + child.RemoveConstraints();
  176 +
  177 + // apply new constraints to the child
  178 + mClusterStyle.ApplyStyle(child, childInfo.mPositionIndex, AlphaFunctions::EaseOut, 0.0f);
  179 + }
  180 + else
  181 + {
  182 + // already added.
  183 + ChildInfoContainer mNewChildren;
  184 + ChildInfoIter iter = mChildren.begin();
  185 + float depth = 0.0f;
  186 +
  187 + for( ; iter != mChildren.end(); ++iter)
  188 + {
  189 + if(iter == offset)
  190 + {
  191 + SetDepth(childInfo, depth);
  192 + depth++;
  193 + // insert the new childInfo before offset.
  194 + mNewChildren.push_back(childInfo);
  195 + }
  196 + // copy all children except the one that we wish to move.
  197 + if((*iter).mActor != childInfo.mActor)
  198 + {
  199 + SetDepth(*iter, depth);
  200 + depth++;
  201 + mNewChildren.push_back(*iter);
  202 + }
  203 + } // end for.
  204 +
  205 + if(iter == offset)
  206 + {
  207 + SetDepth(childInfo, depth);
  208 + // insert the new childInfo before offset (end).
  209 + mNewChildren.push_back(childInfo);
  210 + }
  211 +
  212 + mChildren = mNewChildren;
  213 +
  214 + // Todo somehow adjust their perceived depth.
  215 + }
  216 +}
  217 +
  218 +void Cluster::SetDepth( ChildInfo& childInfo, float depth )
  219 +{
  220 + Property::Index depthProperty = childInfo.mActor.GetPropertyIndex(Demo::Cluster::CLUSTER_ACTOR_DEPTH);
  221 + childInfo.mActor.SetProperty( depthProperty, depth );
  222 +}
  223 +
  224 +ChildInfo Cluster::GetChildInfoAt( unsigned int index )
  225 +{
  226 + // check if we have this position in the cluster
  227 + if( index < mChildren.size() )
  228 + {
  229 + // return the child handle
  230 + return mChildren[ index ];
  231 + }
  232 +
  233 + // return an empty handle
  234 + return ChildInfo();
  235 +}
  236 +
  237 +Actor Cluster::GetChildAt( unsigned int index )
  238 +{
  239 + // check if we have this position in the cluster
  240 + if( index < mChildren.size() )
  241 + {
  242 + // return the child handle
  243 + return mChildren[ index ].mActor;
  244 + }
  245 +
  246 + // return an empty handle
  247 + return Actor();
  248 +}
  249 +
  250 +Actor Cluster::RemoveChildAt( unsigned int index )
  251 +{
  252 + DALI_ASSERT_ALWAYS( index < mChildren.size() );
  253 +
  254 + ChildInfoIter iter = mChildren.begin() + index;
  255 + Actor child = (*iter).mActor;
  256 + mChildren.erase( iter );
  257 + Self().Remove(child);
  258 + // note: constraints will automatically be removed in OnControlChildRemove
  259 +
  260 + // update depths.
  261 + float depth = 0.0f;
  262 +
  263 + for(ChildInfoIter iter = mChildren.begin(); iter != mChildren.end(); ++iter)
  264 + {
  265 + SetDepth(*iter, depth);
  266 + depth++;
  267 + } // end for.
  268 +
  269 + return child;
  270 +}
  271 +
  272 +void Cluster::ExpandChild( unsigned int index )
  273 +{
  274 + if( index < mChildren.size() )
  275 + {
  276 + ChildInfo& childInfo = mChildren[ index ];
  277 + DALI_ASSERT_ALWAYS(childInfo.mActor);
  278 +
  279 + if(!childInfo.mExpanded)
  280 + {
  281 + // expand child to a random position/angle.
  282 + const Vector3 clusterSize = Self().GetCurrentSize();
  283 + const float length = clusterSize.Length() * 0.1f;
  284 + const float zOffset = 50.0f;
  285 + const float angle = (rand()%360) * Math::PI / 180.0f;
  286 + Vector3 position(sin(angle) * length, -cos(angle) * length, zOffset);
  287 + const float scale(1.2f);
  288 + const Radian rotate( Degree( (rand()%30) - 15 ) );
  289 +
  290 + position += childInfo.mActor.GetCurrentPosition();
  291 +
  292 + TransformChild(index,
  293 + position,
  294 + Vector3::ONE * scale,
  295 + Quaternion(rotate, Vector3::ZAXIS),
  296 + AlphaFunctions::EaseOut,
  297 + 0.5f);
  298 + }
  299 + }
  300 +}
  301 +
  302 +void Cluster::ExpandAllChildren()
  303 +{
  304 + for(unsigned int index = 0;index < mChildren.size(); index++)
  305 + {
  306 + ExpandChild( index );
  307 + }
  308 +}
  309 +
  310 +void Cluster::CollapseChild( unsigned int index, bool front )
  311 +{
  312 + if( index < mChildren.size() )
  313 + {
  314 + RestoreChild(index,
  315 + AlphaFunctions::EaseOut,
  316 + 0.25f,
  317 + front);
  318 + }
  319 +}
  320 +
  321 +void Cluster::CollapseAllChildren( bool front )
  322 +{
  323 + for(unsigned int index = 0;index < mChildren.size(); index++)
  324 + {
  325 + RestoreChild(index,
  326 + AlphaFunctions::EaseOut,
  327 + 0.25f,
  328 + front);
  329 + }
  330 +}
  331 +
  332 +void Cluster::TransformChild( unsigned int index, const Vector3& position, const Vector3& scale, const Quaternion& rotation, AlphaFunction alpha, const TimePeriod& period )
  333 +{
  334 + if( index < mChildren.size() )
  335 + {
  336 + ChildInfo& childInfo = mChildren[ index ];
  337 + DALI_ASSERT_ALWAYS(childInfo.mActor);
  338 +
  339 + if(!childInfo.mExpanded)
  340 + {
  341 + Actor child = childInfo.mActor;
  342 + childInfo.mExpanded = true;
  343 + mExpandedCount++;
  344 +
  345 + child.RemoveConstraints();
  346 + Animation animation = Animation::New(period.delaySeconds + period.durationSeconds);
  347 + animation.AnimateTo( Property(child, Actor::Property::POSITION), position, AlphaFunctions::EaseOut, period);
  348 + animation.AnimateTo( Property(child, Actor::Property::SCALE), scale, AlphaFunctions::EaseOut, period);
  349 + animation.AnimateTo( Property(child, Actor::Property::ORIENTATION), rotation, AlphaFunctions::EaseOut, period);
  350 + animation.Play();
  351 + }
  352 + }
  353 +}
  354 +
  355 +void Cluster::RestoreChild( unsigned int index, AlphaFunction alpha, const TimePeriod& period, bool front )
  356 +{
  357 + if( index < mChildren.size() )
  358 + {
  359 + ChildInfo& childInfo = mChildren[ index ];
  360 + DALI_ASSERT_ALWAYS(childInfo.mActor);
  361 +
  362 + if(childInfo.mExpanded)
  363 + {
  364 + Actor child = childInfo.mActor;
  365 + childInfo.mExpanded = false;
  366 + mExpandedCount--;
  367 + mClusterStyle.ApplyStyle( child, childInfo.mPositionIndex, alpha, period );
  368 +
  369 + const unsigned int hideIndex = front ? mChildren.size() : 0;
  370 + AddChildInfoAt(childInfo, hideIndex); // move child info to the back or front of the pack.
  371 + }
  372 + }
  373 +}
  374 +
  375 +void Cluster::SetBackgroundImage( Actor image )
  376 +{
  377 + // Replaces the background image.
  378 + if(mBackgroundImage && mBackgroundImage.GetParent())
  379 + {
  380 + mBackgroundImage.GetParent().Remove(mBackgroundImage);
  381 + }
  382 +
  383 + mBackgroundImage = image;
  384 + Self().Add(mBackgroundImage);
  385 +
  386 + mBackgroundImage.SetAnchorPoint( AnchorPoint::TOP_LEFT );
  387 + mBackgroundImage.SetParentOrigin( ParentOrigin::TOP_LEFT );
  388 +
  389 + UpdateBackground(0.0f);
  390 +}
  391 +
  392 +void Cluster::SetTitle( Actor text )
  393 +{
  394 + // Replaces the title actor.
  395 + if(mTitle && mTitle.GetParent())
  396 + {
  397 + mTitle.GetParent().Remove( mTitle );
  398 + }
  399 +
  400 + mTitle = text;
  401 + Self().Add( mTitle );
  402 +
  403 + mTitle.SetAnchorPoint( AnchorPoint::TOP_LEFT );
  404 + mTitle.SetParentOrigin( ParentOrigin::TOP_LEFT );
  405 +
  406 + UpdateTitle(0.0f);
  407 +}
  408 +
  409 +void Cluster::SetStyle(Demo::ClusterStyle style)
  410 +{
  411 + unsigned int previousChildrenNum = mChildren.size();
  412 + mClusterStyle = style;
  413 + GetImpl(mClusterStyle).SetClusterSize(mClusterSize);
  414 + unsigned int newChildrenNum = mClusterStyle.GetMaximumNumberOfChildren();
  415 +
  416 + // New style supports less children (remove those that no longer belong)
  417 + if(newChildrenNum < previousChildrenNum)
  418 + {
  419 + ChildInfoIter removeStart = mChildren.begin() + newChildrenNum;
  420 +
  421 + for(ChildInfoIter iter = removeStart; iter != mChildren.end(); ++iter)
  422 + {
  423 + Actor child = (*iter).mActor;
  424 + child.RemoveConstraints();
  425 + Self().Remove(child);
  426 + }
  427 +
  428 + mChildren.erase( removeStart, mChildren.end() );
  429 + }
  430 +
  431 + for(ChildInfoIter iter = mChildren.begin(); iter != mChildren.end(); ++iter)
  432 + {
  433 +
  434 + if((*iter).mActor)
  435 + {
  436 + mClusterStyle.ApplyStyle( (*iter).mActor,
  437 + (*iter).mPositionIndex,
  438 + AlphaFunctions::EaseOut,
  439 + CLUSTER_STYLE_CONSTRAINT_DURATION );
  440 + }
  441 + }
  442 +
  443 + UpdateBackground(CLUSTER_STYLE_CONSTRAINT_DURATION);
  444 + UpdateTitle(CLUSTER_STYLE_CONSTRAINT_DURATION);
  445 +}
  446 +
  447 +Demo::ClusterStyle Cluster::GetStyle() const
  448 +{
  449 + return mClusterStyle;
  450 +}
  451 +
  452 +unsigned int Cluster::GetExpandedCount() const
  453 +{
  454 + return mExpandedCount;
  455 +}
  456 +
  457 +unsigned int Cluster::GetTotalCount() const
  458 +{
  459 + return mChildren.size();
  460 +}
  461 +
  462 +void Cluster::UpdateBackground(float duration)
  463 +{
  464 + if (mBackgroundImage)
  465 + {
  466 + mClusterStyle.ApplyStyleToBackground(mBackgroundImage, AlphaFunctions::EaseOut, duration);
  467 + }
  468 +}
  469 +
  470 +void Cluster::UpdateTitle(float duration)
  471 +{
  472 + if (mTitle)
  473 + {
  474 + mClusterStyle.ApplyStyleToTitle(mTitle, AlphaFunctions::EaseOut, duration);
  475 + }
  476 +}
  477 +
  478 +void Cluster::DoExpandAction(const PropertyValueContainer& attributes)
  479 +{
  480 + if(attributes.size() >= 1)
  481 + {
  482 + for(PropertyValueConstIter iter = attributes.begin(); iter != attributes.end(); ++iter)
  483 + {
  484 + const Property::Value& value = *iter;
  485 +
  486 + DALI_ASSERT_ALWAYS(value.GetType() == Property::FLOAT);
  487 + unsigned int index = value.Get<float>();
  488 + ExpandChild( index );
  489 + }
  490 + }
  491 + else
  492 + {
  493 + ExpandAllChildren();
  494 + }
  495 +}
  496 +
  497 +void Cluster::DoCollapseAction(const PropertyValueContainer& attributes)
  498 +{
  499 + if(attributes.size() >= 1)
  500 + {
  501 + for(PropertyValueConstIter iter = attributes.begin(); iter != attributes.end(); ++iter)
  502 + {
  503 + const Property::Value& value = *iter;
  504 +
  505 + DALI_ASSERT_ALWAYS(value.GetType() == Property::FLOAT);
  506 + unsigned int index = value.Get<float>();
  507 + CollapseChild( index, false );
  508 + }
  509 + }
  510 + else
  511 + {
  512 + CollapseAllChildren( false );
  513 + }
  514 +}
  515 +
  516 +void Cluster::DoTransformAction(const PropertyValueContainer& attributes)
  517 +{
  518 + DALI_ASSERT_ALWAYS(attributes.size() >= 2);
  519 +
  520 + DALI_ASSERT_ALWAYS(attributes[0].GetType() == Property::FLOAT);
  521 + unsigned int index = attributes[0].Get<float>();
  522 + Vector3 position;
  523 + Vector3 scale(Vector3::ONE);
  524 + Quaternion rotation( Dali::ANGLE_0, Vector3::ZAXIS );
  525 +
  526 + DALI_ASSERT_ALWAYS(attributes[1].GetType() == Property::VECTOR3);
  527 + attributes[1].Get(position);
  528 +
  529 + if(attributes.size()>2)
  530 + {
  531 + attributes[2].Get(scale);
  532 + }
  533 +
  534 + if(attributes.size()>3)
  535 + {
  536 + attributes[3].Get(rotation);
  537 + }
  538 +
  539 + // wrap index around -1 => size - 1
  540 + index%= mChildren.size();
  541 +
  542 + TransformChild(index, position, scale, rotation, AlphaFunctions::EaseOut, 0.5f);
  543 +}
  544 +
  545 +void Cluster::OnControlChildRemove(Actor& child)
  546 +{
  547 + child.RemoveConstraints();
  548 +}
  549 +
  550 +bool Cluster::DoAction(BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes)
  551 +{
  552 + bool ret = false;
  553 +
  554 + Dali::BaseHandle handle( object );
  555 +
  556 + Demo::Cluster cluster = Demo::Cluster::DownCast( handle );
  557 +
  558 + DALI_ASSERT_ALWAYS( cluster );
  559 +
  560 + if( 0 == strcmp( actionName.c_str(), ACTION_EXPAND ) )
  561 + {
  562 + GetImpl( cluster ).DoExpandAction( attributes );
  563 + ret = true;
  564 + }
  565 + else if( 0 == strcmp( actionName.c_str(), ACTION_COLLAPSE ) )
  566 + {
  567 + GetImpl( cluster ).DoCollapseAction( attributes );
  568 + ret = true;
  569 + }
  570 + else if( 0 == strcmp( actionName.c_str(), ACTION_TRANSFORM ) )
  571 + {
  572 + GetImpl( cluster ).DoTransformAction( attributes );
  573 + ret = true;
  574 + }
  575 +
  576 + return ret;
  577 +}
  578 +
  579 +} // namespace Internal
  580 +
  581 +} // namespace Demo
  582 +
  583 +} // namespace Dali
... ...
examples/cluster/cluster-impl.h 0 โ†’ 100644
  1 +#ifndef __DALI_DEMO_INTERNAL_CLUSTER_H__
  2 +#define __DALI_DEMO_INTERNAL_CLUSTER_H__
  3 +
  4 +/*
  5 + * Copyright (c) 2014 Samsung Electronics Co., Ltd.
  6 + *
  7 + * Licensed under the Apache License, Version 2.0 (the "License");
  8 + * you may not use this file except in compliance with the License.
  9 + * You may obtain a copy of the License at
  10 + *
  11 + * http://www.apache.org/licenses/LICENSE-2.0
  12 + *
  13 + * Unless required by applicable law or agreed to in writing, software
  14 + * distributed under the License is distributed on an "AS IS" BASIS,
  15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16 + * See the License for the specific language governing permissions and
  17 + * limitations under the License.
  18 + *
  19 + */
  20 +
  21 +// EXTERNAL INCLUDES
  22 +#include <dali/public-api/object/ref-object.h>
  23 +
  24 +// INTERNAL INCLUDES
  25 +#include "cluster.h"
  26 +#include "cluster-style.h"
  27 +#include <dali-toolkit/public-api/controls/control-impl.h>
  28 +
  29 +namespace Dali
  30 +{
  31 +
  32 +namespace Demo
  33 +{
  34 +
  35 +namespace Internal
  36 +{
  37 +
  38 +class Cluster;
  39 +
  40 +typedef IntrusivePtr<Cluster> ClusterPtr;
  41 +
  42 +class ChildInfo
  43 +{
  44 +
  45 +public:
  46 +
  47 + ChildInfo()
  48 + : mExpanded(false)
  49 + {
  50 + }
  51 +
  52 + ChildInfo(Actor actor, unsigned int positionIndex)
  53 + : mActor(actor),
  54 + mExpanded(false),
  55 + mPositionIndex(positionIndex)
  56 + {
  57 + }
  58 +
  59 + Actor mActor;
  60 + bool mExpanded;
  61 + unsigned int mPositionIndex;
  62 +};
  63 +
  64 +typedef std::vector<ChildInfo> ChildInfoContainer;
  65 +typedef ChildInfoContainer::iterator ChildInfoIter;
  66 +typedef ChildInfoContainer::const_iterator ChildInfoConstIter;
  67 +
  68 +/**
  69 + * Cluster is a container of grouped actors positioned in different cluster styles.
  70 + * Multiple cluster styles may be provided, to determine the position, size, rotation, scale, color and visibility
  71 + * of the child actors in the cluster.
  72 + */
  73 +class Cluster : public Toolkit::Internal::Control
  74 +{
  75 +public:
  76 +
  77 + /**
  78 + * Create a new Cluster.
  79 + * @param[in] style of the cluster
  80 + * @return A public handle to the newly allocated Cluster.
  81 + */
  82 + static Dali::Demo::Cluster New(Demo::ClusterStyle& style);
  83 +
  84 + /**
  85 + * @copydoc Demo::Cluster::AddChild( Actor child )
  86 + */
  87 + void AddChild( Actor child );
  88 +
  89 + /**
  90 + * @copydoc Demo::Cluster::AddChild( Actor child, unsigned int positionIndex )
  91 + */
  92 + void AddChild( Actor child, unsigned int positionIndex );
  93 +
  94 + /**
  95 + * @copydoc Demo::Cluster::AddChildAt( Actor child, unsigned int index );
  96 + */
  97 + void AddChildAt( Actor child, unsigned int index );
  98 +
  99 + /**
  100 + * @copydoc Demo::Cluster::AddChildAt( Actor child, unsigned int positionIndex, unsigned int index );
  101 + */
  102 + void AddChildAt( Actor child, unsigned int positionIndex, unsigned int index );
  103 +
  104 + /**
  105 + * Adds a ChildInfo struct to the end of the children list.
  106 + * @param[in] childInfo the child info to that to children list.
  107 + */
  108 + void AddChildInfo( ChildInfo childInfo );
  109 +
  110 + /**
  111 + * Adds a ChildInfo struct before the specified index.
  112 + * @param[in] childInfo the child info to that to children list.
  113 + * @param[in] index the index within the children list to insert
  114 + * ChildInfo
  115 + */
  116 + void AddChildInfoAt( ChildInfo childInfo, unsigned int index );
  117 +
  118 + /**
  119 + * @copydoc Demo::Cluster::GetChildAt
  120 + */
  121 + Actor GetChildAt( unsigned int index );
  122 +
  123 + /**
  124 + * @copydoc Demo::Cluster::RemoveChildAt
  125 + */
  126 + Actor RemoveChildAt( unsigned int index );
  127 +
  128 + /**
  129 + * @copydoc Demo::Cluster::ExpandChild
  130 + */
  131 + void ExpandChild( unsigned int index );
  132 +
  133 + /**
  134 + * @copydoc Demo::Cluster::ExpandAllChildren
  135 + */
  136 + void ExpandAllChildren();
  137 +
  138 + /**
  139 + * @copydoc Demo::Cluster::CollapseChild
  140 + */
  141 + void CollapseChild( unsigned int index, bool front );
  142 +
  143 + /**
  144 + * @copydoc Demo::Cluster::CollapseAllChildren
  145 + */
  146 + void CollapseAllChildren( bool front );
  147 +
  148 + /**
  149 + * @copydoc Demo::Cluster::TransformChild
  150 + */
  151 + void TransformChild( unsigned int index, const Vector3& position, const Vector3& scale, const Quaternion& rotation, AlphaFunction alpha, const TimePeriod& period );
  152 +
  153 + /**
  154 + * @copydoc Demo::Cluster::RestoreChild
  155 + */
  156 + void RestoreChild( unsigned int index, AlphaFunction alpha, const TimePeriod& period, bool front );
  157 +
  158 + /**
  159 + * @copydoc Demo::Cluster::SetBackgroundImage
  160 + */
  161 + void SetBackgroundImage( Actor image );
  162 +
  163 + /**
  164 + * @copydoc Demo::Cluster::SetTitle
  165 + */
  166 + void SetTitle( Actor text );
  167 +
  168 + /**
  169 + * @copydoc Demo::Cluster::SetStyle
  170 + */
  171 + void SetStyle(Demo::ClusterStyle style);
  172 +
  173 + /**
  174 + * @copydoc Demo::Cluster::GetStyle
  175 + */
  176 + Demo::ClusterStyle GetStyle() const;
  177 +
  178 + /**
  179 + * @copydoc Demo::Cluster::GetExpandedCount
  180 + */
  181 + unsigned int GetExpandedCount() const;
  182 +
  183 + /**
  184 + * @copydoc Demo::Cluster::GetTotalCount
  185 + */
  186 + unsigned int GetTotalCount() const;
  187 +
  188 +private:
  189 +
  190 + ChildInfo GetChildInfoAt( unsigned int index );
  191 +
  192 + void SetDepth( ChildInfo& childInfo, float depth );
  193 +
  194 + /**
  195 + * Updates the style of the Background
  196 + * (occurs when either background changes or style changes)
  197 + * @param[in] duration apply duration for style
  198 + */
  199 + void UpdateBackground(float duration);
  200 +
  201 + /**
  202 + * Updates the style of the Title
  203 + * (occurs when either background changes or style changes)
  204 + * @param[in] duration apply duration for style
  205 + */
  206 + void UpdateTitle(float duration);
  207 +
  208 + /**
  209 + * Action: Expand
  210 + * Expands one or more actors.
  211 + *
  212 + * @param[in] attributes list of indices of actors to expand.
  213 + * (if no attributes specifies, then all actors expand)
  214 + */
  215 + void DoExpandAction(const PropertyValueContainer& attributes);
  216 +
  217 + /**
  218 + * Action: Collapse
  219 + * Collapses one or more actors.
  220 + *
  221 + * @param[in] attributes list of indices of actors to collapse.
  222 + * (if no attributes specifies, then all actors collapse)
  223 + */
  224 + void DoCollapseAction(const PropertyValueContainer& attributes);
  225 +
  226 + /**
  227 + * Action: Transform
  228 + * Transforms one actor (index) to a specified position (Vector3),
  229 + * scale (Vector3), and rotation (Quaternion).
  230 + *
  231 + * @param[in] attributes index and transform values.
  232 + */
  233 + void DoTransformAction(const PropertyValueContainer& attributes);
  234 +
  235 +private: // From Control
  236 + /**
  237 + * From Control; called shortly before a child is removed from the owning actor.
  238 + * @param[in] child The child being removed.Ptr
  239 + */
  240 + virtual void OnControlChildRemove(Actor& child);
  241 +
  242 +public:
  243 +
  244 + /**
  245 + * Performs actions as requested using the action name.
  246 + * @param[in] object The object on which to perform the action.
  247 + * @param[in] actionName The action to perform.
  248 + * @param[in] attributes The attributes with which to perfrom this action.
  249 + * @return true if action has been accepted by this control
  250 + */
  251 + static bool DoAction(BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes);
  252 +
  253 +private: // From Control
  254 +
  255 + /**
  256 + * @copydoc Demo::Control::OnInitialize()
  257 + */
  258 + virtual void OnInitialize();
  259 +
  260 + /**
  261 + *
  262 + * @copydoc Demo::Control::OnControlSizeSet( const Vector3& targetSize )
  263 + */
  264 + virtual void OnControlSizeSet( const Vector3& targetSize );
  265 +
  266 +protected:
  267 +
  268 + /**
  269 + * Construct a new Cluster.
  270 + * @param[in] style of the cluster
  271 + */
  272 + Cluster(Demo::ClusterStyle& style);
  273 +
  274 + /**
  275 + * A reference counted object may only be deleted by calling Unreference()
  276 + */
  277 + virtual ~Cluster();
  278 +
  279 +private:
  280 +
  281 + // Undefined
  282 + Cluster(const Cluster&);
  283 +
  284 + // Undefined
  285 + Cluster& operator=(const Cluster& rhs);
  286 +
  287 +private:
  288 +
  289 + Demo::ClusterStyle mClusterStyle;
  290 + ChildInfoContainer mChildren;
  291 + Vector3 mClusterSize;
  292 +
  293 + Actor mBackgroundImage; ///< Stores the background image.
  294 + Actor mTitle; ///< Stores the text title.
  295 + unsigned int mExpandedCount; ///< A count of how many children have been expanded.
  296 +
  297 +};
  298 +
  299 +} // namespace Internal
  300 +
  301 +// Helpers for public-api forwarding methods
  302 +
  303 +inline Demo::Internal::Cluster& GetImpl(Demo::Cluster& cluster)
  304 +{
  305 + DALI_ASSERT_ALWAYS(cluster);
  306 +
  307 + Dali::RefObject& handle = cluster.GetImplementation();
  308 +
  309 + return static_cast<Demo::Internal::Cluster&>(handle);
  310 +}
  311 +
  312 +inline const Demo::Internal::Cluster& GetImpl(const Demo::Cluster& cluster)
  313 +{
  314 + DALI_ASSERT_ALWAYS(cluster);
  315 +
  316 + const Dali::RefObject& handle = cluster.GetImplementation();
  317 +
  318 + return static_cast<const Demo::Internal::Cluster&>(handle);
  319 +}
  320 +
  321 +} // namespace Demo
  322 +
  323 +} // namespace Dali
  324 +
  325 +#endif // __DALI_TOOLKIT_INTERNAL_CLUSTER_H__
... ...
examples/cluster/cluster-style-impl.cpp 0 โ†’ 100644
  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 "cluster-style-impl.h"
  20 +
  21 +// EXTERNAL INCLUDES
  22 +#include <dali/public-api/animation/animation.h>
  23 +
  24 +// INTERNAL INCLUDES
  25 +#include "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 Demo
  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.AnimateTo( Property( actor, Actor::Property::POSITION ), position, alpha, TimePeriod( durationSeconds.delaySeconds, durationSeconds.durationSeconds ) );
  299 + animation.AnimateTo( Property( actor, Actor::Property::SIZE ), size, alpha, TimePeriod( 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.AnimateTo( Property( actor, Actor::Property::POSITION ), position, alpha, TimePeriod( durationSeconds.delaySeconds, durationSeconds.durationSeconds ) );
  322 + animation.AnimateTo( Property( actor, Actor::Property::SIZE ), size, alpha, TimePeriod( durationSeconds.delaySeconds, durationSeconds.durationSeconds ) );
  323 + animation.AnimateTo( Property( actor, Actor::Property::ORIENTATION ), rotation, alpha, TimePeriod( durationSeconds.delaySeconds, durationSeconds.durationSeconds ) );
  324 + animation.AnimateTo( Property( actor, Actor::Property::SCALE ), scale, alpha, TimePeriod( 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 Demo::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 Demo::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 Demo::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 Demo::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(Demo::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( Radian( rotation ), Vector3::ZAXIS ),
  477 + Vector3::ONE,
  478 + alpha,
  479 + durationSeconds);
  480 +}
  481 +
  482 +} // namespace Internal
  483 +
  484 +} // namespace Demo
  485 +
  486 +} // namespace Dali
... ...
examples/cluster/cluster-style-impl.h 0 โ†’ 100644
  1 +/*
  2 + * Copyright (c) 2015 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 +// EXTERNAL INCLUDES
  19 +#include <dali/public-api/object/ref-object.h>
  20 +#include <dali/public-api/common/dali-common.h>
  21 +#include <dali/public-api/math/vector3.h>
  22 +#include <dali/public-api/object/base-object.h>
  23 +
  24 +// INTERNAL INCLUDES
  25 +#include "cluster-style.h"
  26 +
  27 +namespace Dali
  28 +{
  29 +
  30 +namespace Demo
  31 +{
  32 +
  33 +namespace Internal
  34 +{
  35 +
  36 +class ClusterStyle;
  37 +
  38 +typedef IntrusivePtr<ClusterStyle> ClusterStylePtr;
  39 +
  40 +/**
  41 + * ClusterStyle internal implementation
  42 + */
  43 +class ClusterStyle : public Dali::BaseObject
  44 +{
  45 +public:
  46 +
  47 + /**
  48 + * @copydoc Demo::ClusterStyle::GetMaximumNumberOfChildren
  49 + */
  50 + unsigned int GetMaximumNumberOfChildren() const;
  51 +
  52 + /**
  53 + * @copydoc Demo::ClusterStyle::ApplyStyle
  54 + */
  55 + virtual void ApplyStyle(Actor child, unsigned int index, AlphaFunction alpha, const TimePeriod& durationSeconds) = 0;
  56 +
  57 + /**
  58 + * @copydoc Demo::ClusterStyle::ApplyStyleToBackground
  59 + */
  60 + virtual void ApplyStyleToBackground(Actor background, AlphaFunction alpha, const TimePeriod& durationSeconds);
  61 +
  62 + /**
  63 + * @copydoc Demo::ClusterStyle::ApplyStyleToTitle
  64 + */
  65 + virtual void ApplyStyleToTitle(Actor title, AlphaFunction alpha, const TimePeriod& durationSeconds);
  66 +
  67 + /**
  68 + * Set the size of cluster
  69 + */
  70 + void SetClusterSize( const Vector3& clusterSize );
  71 +
  72 +protected:
  73 +
  74 + /**
  75 + * Set the maximum number of children this Style can handle.
  76 + * @param[in] The maximum number of children.
  77 + */
  78 + void SetMaximumNumberOfChildren(unsigned int children);
  79 +
  80 + /**
  81 + * Set the title properties
  82 + * @param[in] relativePosition Relative position of the title
  83 + * @param[in] offsetPosition Offset position of the title
  84 + * @param[in] size The size of the title
  85 + */
  86 + void SetTitleProperties(const Vector3& relativePosition,
  87 + const Vector3& offsetPosition,
  88 + const Vector3& size);
  89 +
  90 + /**
  91 + * Set the background properties
  92 + * @param[in] relativePosition Relative position of the background
  93 + * @param[in] offsetPosition Offset position of the background
  94 + * @param[in] size The size of the title
  95 + */
  96 + void SetBackgroundProperties(const Vector3& relativePosition,
  97 + const Vector3& offsetPosition,
  98 + const Vector3& size);
  99 +
  100 + /**
  101 + * Get the size of cluster.
  102 + * @return the cluster size
  103 + */
  104 + Vector3 GetClusterSize() const;
  105 +
  106 + /**
  107 + * Apply the given position & size to the actor
  108 + * @param[in] position The target position
  109 + * @param[in] size The target size
  110 + * @param[in] size The size to resize to
  111 + * @param[in] alpha The alpha function to use.
  112 + * @param[in] durationSeconds The time period to apply this style.
  113 + */
  114 + void Apply( Actor actor,
  115 + const Vector3& position,
  116 + const Vector3& size,
  117 + AlphaFunction alpha,
  118 + const TimePeriod& durationSeconds);
  119 + /**
  120 + * Apply the given position & size to the actor
  121 + * @param[in] actor The actor to apply the changes
  122 + * @param[in] position The target position
  123 + * @param[in] size The target size
  124 + * @param[in] rotation The target Quaternion value
  125 + * @param[in] scale The target scale
  126 + * @param[in] alpha The alpha function to use.
  127 + * @param[in] durationSeconds The time period to apply this style.
  128 + */
  129 + void Apply( Actor actor,
  130 + const Vector3& position,
  131 + const Vector3& size,
  132 + const Quaternion& rotation,
  133 + const Vector3& scale,
  134 + AlphaFunction alpha,
  135 + const TimePeriod& durationSeconds);
  136 +
  137 +protected:
  138 +
  139 + /**
  140 + * Protected constructor see ClusterStyle::New().
  141 + */
  142 + ClusterStyle();
  143 +
  144 + /**
  145 + * A reference counted object may only be deleted by calling Unreference()
  146 + */
  147 + virtual ~ClusterStyle();
  148 +
  149 +protected:
  150 +
  151 + unsigned int mMaxChildren; ///< Maximum number of children that this style supports
  152 + Vector3 mTitlePositionRelative; ///< Title's position relative to size of cluster
  153 + Vector3 mTitlePositionOffset; ///< Title's position offset
  154 + Vector3 mTitleSize; ///< Title's size relative to size of cluster
  155 + Vector3 mBackgroundPositionRelative; ///< Background's position relative to size of cluster
  156 + Vector3 mBackgroundPositionOffset; ///< Background's position offset
  157 + Vector3 mBackgroundSize; ///< Background's size relative to size of cluster
  158 + Vector3 mClusterSize; ///< The size of cluster
  159 +};
  160 +
  161 +/**
  162 + * ClusterStyleStandard internal implementation
  163 + */
  164 +class ClusterStyleStandard : public ClusterStyle
  165 +{
  166 +public:
  167 +
  168 + typedef Demo::ClusterStyleStandard::StyleType StyleType;
  169 +
  170 +public:
  171 +
  172 + /**
  173 + * Create a new cluster style.
  174 + * @param[in] style The style type to create.
  175 + * @return A smart-pointer to the newly allocated ClusterStyle.
  176 + */
  177 + static ClusterStylePtr New(StyleType style);
  178 +
  179 +public:
  180 +
  181 + /**
  182 + * @copydoc Demo::ClusterStyle::ApplyStyle
  183 + */
  184 + void ApplyStyle(Actor child, unsigned int index, AlphaFunction alpha, const TimePeriod& durationSeconds);
  185 +
  186 +private:
  187 +
  188 + /**
  189 + * Set the relative sizes of the children
  190 + * @param[in] size The list of sizes for the children
  191 + */
  192 + void SetSizes(const float *sizes);
  193 +
  194 + /**
  195 + * Set the relative positions of the children
  196 + * @param[in] positions The list of positions for the children
  197 + */
  198 + void SetPositions(const Vector3 *positions);
  199 +
  200 +protected:
  201 +
  202 + /**
  203 + * Protected constructor see ClusterStyleRandom::New().
  204 + */
  205 + ClusterStyleStandard(StyleType style);
  206 +
  207 +private:
  208 +
  209 + const float *mSizes; ///< List of sizes
  210 + const Vector3 *mPositions; ///< List of positions
  211 +
  212 +};
  213 +
  214 +/**
  215 + * ClusterStyleRandom internal implementation
  216 + */
  217 +class ClusterStyleRandom : public ClusterStyle
  218 +{
  219 +public:
  220 +
  221 + /**
  222 + * Create a new cluster style.
  223 + * @return A smart-pointer to the newly allocated ClusterStyle.
  224 + */
  225 + static ClusterStylePtr New();
  226 +
  227 +public:
  228 +
  229 + /**
  230 + * @copydoc Demo::ClusterStyle::ApplyStyle
  231 + */
  232 + void ApplyStyle(Actor child, unsigned int index, AlphaFunction alpha, const TimePeriod& durationSeconds);
  233 +
  234 +protected:
  235 +
  236 + /**
  237 + * Protected constructor see ClusterStyleRandom::New().
  238 + */
  239 + ClusterStyleRandom();
  240 +
  241 +private:
  242 +
  243 +};
  244 +
  245 +} // namespace Internal
  246 +
  247 +// Helpers for public-api forwarding methods
  248 +
  249 +inline Internal::ClusterStyle& GetImpl(Demo::ClusterStyle& pub)
  250 +{
  251 + DALI_ASSERT_ALWAYS(pub);
  252 +
  253 + Dali::RefObject& handle = pub.GetBaseObject();
  254 +
  255 + return static_cast<Internal::ClusterStyle&>(handle);
  256 +}
  257 +
  258 +inline const Internal::ClusterStyle& GetImpl(const Demo::ClusterStyle& pub)
  259 +{
  260 + DALI_ASSERT_ALWAYS(pub);
  261 +
  262 + const Dali::RefObject& handle = pub.GetBaseObject();
  263 +
  264 + return static_cast<const Internal::ClusterStyle&>(handle);
  265 +}
  266 +
  267 +} // namespace Demo
  268 +
  269 +} // namespace Dali
... ...
examples/cluster/cluster-style.cpp 0 โ†’ 100644
  1 +/*
  2 + * Copyright (c) 2015 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 "cluster-style.h"
  20 +
  21 +// EXTERNAL INCLUDES
  22 +#include <limits>
  23 +
  24 +// INTERNAL INCLUDES
  25 +#include "cluster-style-impl.h"
  26 +
  27 +using namespace Dali;
  28 +using namespace Dali::Demo;
  29 +
  30 +namespace Dali
  31 +{
  32 +
  33 +namespace Demo
  34 +{
  35 +
  36 +// ClusterStyle ///////////////////////////////////////////////////////////////
  37 +
  38 +const unsigned int ClusterStyle::UNLIMITED_CHILDREN = std::numeric_limits<unsigned int>::max();
  39 +
  40 +ClusterStyle::ClusterStyle()
  41 +{
  42 +}
  43 +
  44 +ClusterStyle::~ClusterStyle()
  45 +{
  46 +}
  47 +
  48 +ClusterStyle::ClusterStyle(Internal::ClusterStyle* internal)
  49 +: BaseHandle(internal)
  50 +{
  51 +}
  52 +
  53 +unsigned int ClusterStyle::GetMaximumNumberOfChildren() const
  54 +{
  55 + return GetImpl(*this).GetMaximumNumberOfChildren();
  56 +}
  57 +
  58 +void ClusterStyle::ApplyStyle(Actor child, unsigned int index, AlphaFunction alpha, const TimePeriod& durationSeconds)
  59 +{
  60 + GetImpl(*this).ApplyStyle(child, index, alpha, durationSeconds);
  61 +}
  62 +
  63 +void ClusterStyle::ApplyStyleToBackground(Actor background, AlphaFunction alpha, const TimePeriod& durationSeconds)
  64 +{
  65 + GetImpl(*this).ApplyStyleToBackground(background, alpha, durationSeconds);
  66 +}
  67 +
  68 +void ClusterStyle::ApplyStyleToTitle(Actor title, AlphaFunction alpha, const TimePeriod& durationSeconds)
  69 +{
  70 + GetImpl(*this).ApplyStyleToTitle(title, alpha, durationSeconds);
  71 +}
  72 +
  73 +// ClusterStyleStandard ///////////////////////////////////////////////////////
  74 +
  75 +ClusterStyleStandard ClusterStyleStandard::New(StyleType style)
  76 +{
  77 + Internal::ClusterStylePtr internal = Internal::ClusterStyleStandard::New(style);
  78 +
  79 + return ClusterStyleStandard(internal.Get());
  80 +}
  81 +
  82 +ClusterStyleStandard::ClusterStyleStandard(Internal::ClusterStyle* internal)
  83 +: ClusterStyle(internal)
  84 +{
  85 +}
  86 +
  87 +// ClusterStyleRandom /////////////////////////////////////////////////////////
  88 +
  89 +ClusterStyleRandom ClusterStyleRandom::New()
  90 +{
  91 + Internal::ClusterStylePtr internal = Internal::ClusterStyleRandom::New();
  92 +
  93 + return ClusterStyleRandom(internal.Get());
  94 +}
  95 +
  96 +ClusterStyleRandom::ClusterStyleRandom(Internal::ClusterStyle* internal)
  97 +: ClusterStyle(internal)
  98 +{
  99 +}
  100 +
  101 +} // namespace Demo
  102 +
  103 +} // namespace Dali
... ...
examples/cluster/cluster-style.h 0 โ†’ 100644
  1 +#ifndef __DALI_DEMO_CLUSTER_STYLE_H__
  2 +#define __DALI_DEMO_CLUSTER_STYLE_H__
  3 +
  4 +/*
  5 + * Copyright (c) 2015 Samsung Electronics Co., Ltd.
  6 + *
  7 + * Licensed under the Apache License, Version 2.0 (the "License");
  8 + * you may not use this file except in compliance with the License.
  9 + * You may obtain a copy of the License at
  10 + *
  11 + * http://www.apache.org/licenses/LICENSE-2.0
  12 + *
  13 + * Unless required by applicable law or agreed to in writing, software
  14 + * distributed under the License is distributed on an "AS IS" BASIS,
  15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16 + * See the License for the specific language governing permissions and
  17 + * limitations under the License.
  18 + *
  19 + */
  20 +
  21 +// EXTERNAL INCLUDES
  22 +#include <dali/public-api/actors/actor.h>
  23 +#include <dali/public-api/animation/alpha-functions.h>
  24 +#include <dali/public-api/animation/time-period.h>
  25 +#include <dali/public-api/common/dali-common.h>
  26 +#include <dali/public-api/object/base-handle.h>
  27 +
  28 +// INTERNAL INCLUDES
  29 +#include <dali-toolkit/public-api/enums.h>
  30 +
  31 +namespace Dali
  32 +{
  33 +
  34 +class Actor;
  35 +
  36 +namespace Demo
  37 +{
  38 +
  39 +namespace Internal DALI_INTERNAL
  40 +{
  41 +class ClusterStyle;
  42 +class ClusterStyleRandom;
  43 +}
  44 +
  45 +class ClusterStyle;
  46 +
  47 +typedef IntrusivePtr<ClusterStyle> ClusterStylePtr; ///< Pointer to a Dali::Demo::ClusterStyle object
  48 +
  49 +/**
  50 + * @brief A ClusterStyle describes the constraints which are imposed on the child actors in the cluster.
  51 + */
  52 +class ClusterStyle : public Dali::BaseHandle
  53 +{
  54 +public:
  55 +
  56 + static const unsigned int UNLIMITED_CHILDREN; ///< Constant that represents an unlimited number of children.
  57 +
  58 +public:
  59 +
  60 + /**
  61 + * @brief Destructor
  62 + *
  63 + * This is non-virtual since derived Handle types must not contain data or virtual methods.
  64 + */
  65 + ~ClusterStyle();
  66 +
  67 + /**
  68 + * @brief Query the maximum number of children this Style can handle.
  69 + *
  70 + * If return value is UNLIMITED_CHILDREN, then this style has no
  71 + * limit.
  72 + * @return The maximum number of children.
  73 + */
  74 + unsigned int GetMaximumNumberOfChildren() const;
  75 +
  76 + /**
  77 + * @brief Applies style (position) to child actor over a specified time duration.
  78 + *
  79 + * @param[in] child The child actor to apply
  80 + * @param[in] index The style position index for the actor to transform to.
  81 + * @param[in] alpha The alpha function to use.
  82 + * @param[in] durationSeconds The time period to apply this style.
  83 + */
  84 + void ApplyStyle(Actor child, unsigned int index, AlphaFunction alpha, const TimePeriod& durationSeconds);
  85 +
  86 + /**
  87 + * @brief Applies style to background actor over a specified time duration.
  88 + *
  89 + * @param[in] background The background actor to apply
  90 + * @param[in] alpha The alpha function to use.
  91 + * @param[in] durationSeconds The time period to apply this style.
  92 + */
  93 + void ApplyStyleToBackground(Actor background, AlphaFunction alpha, const TimePeriod& durationSeconds);
  94 +
  95 + /**
  96 + * @brief Applies style to title actor over a specified time duration.
  97 + *
  98 + * @param[in] title The title actor to apply
  99 + * @param[in] alpha The alpha function to use.
  100 + * @param[in] durationSeconds The time period to apply this style.
  101 + */
  102 + void ApplyStyleToTitle(Actor title, AlphaFunction alpha, const TimePeriod& durationSeconds);
  103 +
  104 +protected:
  105 +
  106 + /**
  107 + * @brief Create a new ClusterStyle; Only derived versions are instantiatable.
  108 + */
  109 + ClusterStyle();
  110 +
  111 +public: // Not intended for application developers
  112 +
  113 + /**
  114 + * @brief This constructor is used by Dali New() methods.
  115 + *
  116 + * @param [in] internal A pointer to a newly allocated Dali resource
  117 + */
  118 + explicit DALI_INTERNAL ClusterStyle(Internal::ClusterStyle* internal);
  119 +};
  120 +
  121 +/**
  122 + * @brief A ClusterStyle describes the constraints, which are imposed on the child actors in the cluster.
  123 + */
  124 +class ClusterStyleStandard : public ClusterStyle
  125 +{
  126 +public:
  127 +
  128 + /**
  129 + * @brief Cluster Style type.
  130 + */
  131 + enum StyleType
  132 + {
  133 + ClusterStyle1, ///< Style number 1
  134 + ClusterStyle2, ///< Style number 2
  135 + ClusterStyle3, ///< Style number 3
  136 + ClusterStyle4, ///< Style number 4
  137 + TotalClusterStyles ///< The number of styles
  138 + };
  139 +
  140 +public:
  141 +
  142 + /**
  143 + * @brief Create an initialized style.
  144 + */
  145 + static ClusterStyleStandard New(StyleType style);
  146 +
  147 +public: // Not intended for application developers
  148 +
  149 + /**
  150 + * @brief This constructor is used by Dali New() methods.
  151 + *
  152 + * @param [in] internal A pointer to a newly allocated Dali resource
  153 + */
  154 + explicit DALI_INTERNAL ClusterStyleStandard(Internal::ClusterStyle* internal);
  155 +};
  156 +
  157 +/**
  158 + * @brief A ClusterStyle describes the constraints, which are imposed on the child actors in the cluster.
  159 + */
  160 +class ClusterStyleRandom : public ClusterStyle
  161 +{
  162 +public:
  163 +
  164 + /**
  165 + * @brief Create an initialized style.
  166 + */
  167 + static ClusterStyleRandom New();
  168 +
  169 +public: // Not intended for application developers
  170 +
  171 + /**
  172 + * @brief This constructor is used by Dali New() methods.
  173 + *
  174 + * @param [in] internal A pointer to a newly allocated Dali resource
  175 + */
  176 + explicit DALI_INTERNAL ClusterStyleRandom(Internal::ClusterStyle* internal);
  177 +};
  178 +
  179 +} // namespace Demo
  180 +
  181 +} // namespace Dali
  182 +
  183 +#endif // __DALI_TOOLKIT_CLUSTER_STYLE_H__
... ...
examples/cluster/cluster.cpp 0 โ†’ 100644
  1 +/*
  2 + * Copyright (c) 2015 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 +
  20 +#include "cluster.h"
  21 +
  22 +// INTERNAL INCLUDES
  23 +
  24 +#include "cluster-impl.h"
  25 +
  26 +namespace Dali
  27 +{
  28 +
  29 +namespace Demo
  30 +{
  31 +
  32 +///////////////////////////////////////////////////////////////////////////////////////////////////
  33 +// Cluster
  34 +///////////////////////////////////////////////////////////////////////////////////////////////////
  35 +
  36 +const std::string Cluster::CLUSTER_ACTOR_DEPTH( "cluster-actor-depth" );
  37 +
  38 +Cluster::Cluster()
  39 +{
  40 +}
  41 +
  42 +Cluster::Cluster(const Cluster& cluster)
  43 +: Toolkit::Control(cluster)
  44 +{
  45 +}
  46 +
  47 +Cluster& Cluster::operator =(const Cluster& cluster)
  48 +{
  49 + if( &cluster != this )
  50 + {
  51 + Toolkit::Control::operator=( cluster );
  52 + }
  53 + return *this;
  54 +}
  55 +
  56 +Cluster::~Cluster()
  57 +{
  58 +}
  59 +
  60 +Cluster Cluster::New( ClusterStyle& style )
  61 +{
  62 + return Internal::Cluster::New(style);
  63 +}
  64 +
  65 +Cluster Cluster::DownCast( BaseHandle handle )
  66 +{
  67 + return Toolkit::Control::DownCast<Cluster, Internal::Cluster>(handle);
  68 +}
  69 +
  70 +void Cluster::AddChild( Actor child )
  71 +{
  72 + GetImpl(*this).AddChild( child );
  73 +}
  74 +
  75 +void Cluster::AddChild( Actor child, unsigned int positionIndex )
  76 +{
  77 + GetImpl(*this).AddChild( child, positionIndex);
  78 +}
  79 +
  80 +void Cluster::AddChildAt( Actor child, unsigned int index )
  81 +{
  82 + GetImpl(*this).AddChildAt( child, index );
  83 +}
  84 +
  85 +void Cluster::AddChildAt( Actor child, unsigned int positionIndex, unsigned int index )
  86 +{
  87 + GetImpl(*this).AddChildAt( child, positionIndex, index );
  88 +}
  89 +
  90 +Actor Cluster::GetChildAt( unsigned int index )
  91 +{
  92 + return GetImpl(*this).GetChildAt(index);
  93 +}
  94 +
  95 +Actor Cluster::RemoveChildAt( unsigned int index )
  96 +{
  97 + return GetImpl(*this).RemoveChildAt(index);
  98 +}
  99 +
  100 +void Cluster::ExpandChild( unsigned int index )
  101 +{
  102 + GetImpl(*this).ExpandChild(index);
  103 +}
  104 +
  105 +void Cluster::ExpandAllChildren()
  106 +{
  107 + GetImpl(*this).ExpandAllChildren();
  108 +}
  109 +
  110 +void Cluster::CollapseChild( unsigned int index, bool front )
  111 +{
  112 + GetImpl(*this).CollapseChild(index, front);
  113 +}
  114 +
  115 +void Cluster::CollapseAllChildren( bool front )
  116 +{
  117 + GetImpl(*this).CollapseAllChildren( front );
  118 +}
  119 +
  120 +void Cluster::TransformChild( unsigned int index, const Vector3& position, const Vector3& scale, const Quaternion& rotation, AlphaFunction alpha, const TimePeriod& period )
  121 +{
  122 + GetImpl(*this).TransformChild( index, position, scale, rotation, alpha, period );
  123 +}
  124 +
  125 +void Cluster::RestoreChild( unsigned int index, AlphaFunction alpha, const TimePeriod& period, bool front )
  126 +{
  127 + GetImpl(*this).RestoreChild( index, alpha, period, front );
  128 +}
  129 +
  130 +void Cluster::SetBackgroundImage( Actor image )
  131 +{
  132 + GetImpl(*this).SetBackgroundImage(image);
  133 +}
  134 +
  135 +void Cluster::SetTitle( Actor text )
  136 +{
  137 + GetImpl(*this).SetTitle(text);
  138 +}
  139 +
  140 +void Cluster::SetStyle(ClusterStyle style)
  141 +{
  142 + GetImpl(*this).SetStyle(style);
  143 +}
  144 +
  145 +ClusterStyle Cluster::GetStyle() const
  146 +{
  147 + return GetImpl(*this).GetStyle();
  148 +}
  149 +
  150 +unsigned int Cluster::GetExpandedCount() const
  151 +{
  152 + return GetImpl(*this).GetExpandedCount();
  153 +}
  154 +
  155 +unsigned int Cluster::GetTotalCount() const
  156 +{
  157 + return GetImpl(*this).GetTotalCount();
  158 +}
  159 +
  160 +Cluster::Cluster( Internal::Cluster& impl )
  161 +: Toolkit::Control( impl )
  162 +{
  163 +}
  164 +
  165 +Cluster::Cluster( Dali::Internal::CustomActor* internal )
  166 +: Toolkit::Control( internal )
  167 +{
  168 + VerifyCustomActorPointer<Internal::Cluster>(internal);
  169 +}
  170 +
  171 +} // namespace Demo
  172 +
  173 +} // namespace Dali
... ...
examples/cluster/cluster.h 0 โ†’ 100644
  1 +#ifndef __DALI_DEMO_CLUSTER_H__
  2 +#define __DALI_DEMO_CLUSTER_H__
  3 +
  4 +/*
  5 + * Copyright (c) 2015 Samsung Electronics Co., Ltd.
  6 + *
  7 + * Licensed under the Apache License, Version 2.0 (the "License");
  8 + * you may not use this file except in compliance with the License.
  9 + * You may obtain a copy of the License at
  10 + *
  11 + * http://www.apache.org/licenses/LICENSE-2.0
  12 + *
  13 + * Unless required by applicable law or agreed to in writing, software
  14 + * distributed under the License is distributed on an "AS IS" BASIS,
  15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16 + * See the License for the specific language governing permissions and
  17 + * limitations under the License.
  18 + *
  19 + */
  20 +
  21 +// EXTERNAL INCLUDES
  22 +#include <dali/public-api/animation/alpha-functions.h>
  23 +#include <dali/public-api/animation/time-period.h>
  24 +
  25 +// INTERNAL INCLUDES
  26 +#include <dali-toolkit/public-api/controls/control.h>
  27 +
  28 +namespace Dali
  29 +{
  30 +
  31 +namespace Demo
  32 +{
  33 +
  34 +namespace Internal DALI_INTERNAL
  35 +{
  36 +class Cluster;
  37 +}
  38 +
  39 +class ClusterStyle;
  40 +
  41 +/**
  42 + * @brief Cluster is a container of grouped actors positioned in different cluster styles.
  43 + *
  44 + * Actions
  45 + * | %Action Name | Method |
  46 + * |---------------------------|---------------------------|
  47 + * | expand | DoExpandAction() |
  48 + * | collapse | DoCollapseAction() |
  49 + * | transform | DoTransformAction() |
  50 + */
  51 +class Cluster : public Toolkit::Control
  52 +{
  53 +public:
  54 +
  55 + // Custom properties
  56 +
  57 + static const std::string CLUSTER_ACTOR_DEPTH; ///< Property, name "cluster-actor-depth", type float
  58 +
  59 +public:
  60 +
  61 + /**
  62 + * Create a Cluster handle; this can be initialised with Cluster::New()
  63 + * Calling member functions with an uninitialised handle is not allowed.
  64 + */
  65 + Cluster();
  66 +
  67 + /**
  68 + * Copy Constructor.
  69 + */
  70 + Cluster( const Cluster& cluster );
  71 +
  72 + /**
  73 + * Assignment Operator.
  74 + */
  75 + Cluster& operator=( const Cluster& cluster );
  76 +
  77 + /**
  78 + * @brief Destructor
  79 + *
  80 + * This is non-virtual since derived Handle types must not contain data or virtual methods.
  81 + */
  82 + ~Cluster();
  83 +
  84 + /**
  85 + * Create the Cluster control with the given style.
  86 + * @param[in] style The style of the cluster
  87 + * @return A handle to the Cluster control.
  88 + */
  89 + static Cluster New( ClusterStyle& style );
  90 +
  91 + /**
  92 + * Downcast an Object handle to Cluster. If handle points to a Cluster the
  93 + * downcast produces valid handle. If not the returned handle is left uninitialized.
  94 + * @param[in] handle Handle to an object
  95 + * @return handle to a Cluster or an uninitialized handle
  96 + */
  97 + static Cluster DownCast( BaseHandle handle );
  98 +
  99 + /**
  100 + * Adds a child to the Cluster
  101 + * Will automatically choose a position for the child.
  102 + * @pre The child actor has been initialized.
  103 + * @param[in] child The child to add
  104 + */
  105 + void AddChild( Actor child );
  106 +
  107 + /**
  108 + * Adds a child to the Cluster
  109 + * User specifies the position for the child.
  110 + * @pre The child actor has been initialized.
  111 + * @param[in] child The child to add
  112 + * @param[in] positionIndex The position for this child
  113 + */
  114 + void AddChild( Actor child, unsigned int positionIndex );
  115 +
  116 + /**
  117 + * Adds a child to the Cluster to be inserted at a specified
  118 + * depth index.
  119 + * Will automatically choose a position for the child.
  120 + * @pre The child actor has been initialized.
  121 + * @param[in] child The child to add
  122 + * @param[in] index The depth position for this child
  123 + */
  124 + void AddChildAt( Actor child, unsigned int index );
  125 +
  126 + /**
  127 + * Adds a child to the Cluster to be inserted at a specified
  128 + * depth index.
  129 + * User specifies the position for the child.
  130 + * @pre The child actor has been initialized.
  131 + * @param[in] child The child to add
  132 + * @param[in] positionIndex The position for this child
  133 + * @param[in] index The depth position for this child
  134 + */
  135 + void AddChildAt( Actor child, unsigned int positionIndex, unsigned int index );
  136 +
  137 + /**
  138 + * Returns a child from the given layout position
  139 + * Note! if there is no child in this layout position this method returns an uninitialized
  140 + * Actor handle
  141 + * @param[in] index The child index in the cluster
  142 + * @return The child that was in the layout position or an uninitialized handle
  143 + */
  144 + Actor GetChildAt( unsigned int index );
  145 +
  146 + /**
  147 + * Removes a child from the given layout position
  148 + * Note! if there is no child in this layout position this method does nothing
  149 + * @param[in] index The index of the child to remove
  150 + * @return The child that was removed or an uninitialized handle
  151 + */
  152 + Actor RemoveChildAt( unsigned int index );
  153 +
  154 + /**
  155 + * Expands a child
  156 + * A child will move away from the cluster.
  157 + * @param[in] index The child position index to expand
  158 + */
  159 + void ExpandChild( unsigned int index );
  160 +
  161 + /**
  162 + * Expands all children
  163 + * All children that have been collapsed will
  164 + * move away from the cluster
  165 + */
  166 + void ExpandAllChildren();
  167 +
  168 + /**
  169 + * Collapses a child
  170 + * A child that has been expanded will move
  171 + * back to its original positions.
  172 + * @param[in] index The child index to collapse
  173 + * @param[in] front Whether to move child to the front or
  174 + * back of cluster (depth).
  175 + */
  176 + void CollapseChild( unsigned int index, bool front = false );
  177 +
  178 + /**
  179 + * Collapses all children.
  180 + * All children that have been expanded will move
  181 + * back to their original positions.
  182 + * @param[in] front Whether to move child to the front or
  183 + * back of cluster (depth).
  184 + */
  185 + void CollapseAllChildren( bool front = false );
  186 +
  187 + /**
  188 + * Transforms Actor from default transform to new transform
  189 + * @param[in] index The child index to move
  190 + * @param[in] position The position to move to
  191 + * @param[in] scale The scale to change to
  192 + * @param[in] rotation The rotation to change to
  193 + * @param[in] alpha The alpha function to use to tween to this transform
  194 + * @param[in] period The duration for this transformation to take
  195 + */
  196 + void TransformChild( unsigned int index, const Vector3& position, const Vector3& scale, const Quaternion& rotation, AlphaFunction alpha, const TimePeriod& period );
  197 +
  198 + /**
  199 + * Restores Actor to the default transform (based on current style)
  200 + * @param[in] index The child index to move back
  201 + * @param[in] alpha The alpha function to use to tween to this transform
  202 + * @param[in] period The duration for this transformation to take
  203 + * @param[in] front Whether to move child to the front or
  204 + * back of cluster (depth).
  205 + */
  206 + void RestoreChild( unsigned int index, AlphaFunction alpha, const TimePeriod& period, bool front = false );
  207 +
  208 + /**
  209 + * Sets the background image.
  210 + * @param[in] image The background image.
  211 + */
  212 + void SetBackgroundImage( Actor image );
  213 +
  214 + /**
  215 + * Sets the title.
  216 + *
  217 + * @param[in] text Title text.
  218 + */
  219 + void SetTitle( Actor text );
  220 +
  221 + /**
  222 + * Sets the style of the cluster
  223 + * @param[in] style The style of the cluster
  224 + */
  225 + void SetStyle(ClusterStyle style);
  226 +
  227 + /**
  228 + * Gets the style of the cluster
  229 + * @return style of the cluster
  230 + */
  231 + ClusterStyle GetStyle() const;
  232 +
  233 + /**
  234 + * Gets the number of children that have been expanded in this cluster.
  235 + * @return the number of children expanded.
  236 + */
  237 + unsigned int GetExpandedCount() const;
  238 +
  239 + /**
  240 + * Gets the number of children that have been added to this cluster.
  241 + * @return the total number of children.
  242 + */
  243 + unsigned int GetTotalCount() const;
  244 +
  245 +public: // Not intended for application developers
  246 +
  247 + /**
  248 + * Creates a handle using the Toolkit::Internal implementation.
  249 + * @param[in] implementation The Control implementation.
  250 + */
  251 + DALI_INTERNAL Cluster( Internal::Cluster& implementation );
  252 +
  253 + /**
  254 + * Allows the creation of this Control from an Internal::CustomActor pointer.
  255 + * @param[in] internal A pointer to the internal CustomActor.
  256 + */
  257 + explicit DALI_INTERNAL Cluster( Dali::Internal::CustomActor* internal );
  258 +};
  259 +
  260 +} // namespace Toolkit
  261 +
  262 +} // namespace Dali
  263 +
  264 +#endif // __DALI_DEMO_CLUSTER_H__
... ...
examples/cube-transition-effect/cube-transition-effect-example.cpp
... ... @@ -168,7 +168,7 @@ private:
168 168  
169 169 private:
170 170 Application& mApplication;
171   - Toolkit::View mView;
  171 + Toolkit::Control mView;
172 172 Toolkit::ToolBar mToolBar;
173 173 Layer mContent;
174 174 Toolkit::TextLabel mTitleActor;
... ...
examples/dissolve-effect/dissolve-effect-example.cpp
... ... @@ -152,7 +152,7 @@ private:
152 152  
153 153 private:
154 154 Application& mApplication;
155   - Toolkit::View mView;
  155 + Toolkit::Control mView;
156 156 Toolkit::ToolBar mToolBar;
157 157 Layer mContent;
158 158 Toolkit::TextLabel mTitleActor;
... ...
examples/image-scaling-irregular-grid/image-scaling-irregular-grid-example.cpp
... ... @@ -568,7 +568,7 @@ private:
568 568 Application& mApplication;
569 569  
570 570 Layer mContentLayer; ///< The content layer (contains non gui chrome actors)
571   - Toolkit::View mView; ///< The View instance.
  571 + Toolkit::Control mView; ///< The View instance.
572 572 Toolkit::ToolBar mToolBar; ///< The View's Toolbar.
573 573 TextLabel mTitleActor; ///< The Toolbar's Title.
574 574 Actor mGridActor; ///< The container for the grid of images
... ...
examples/item-view/item-view-example.cpp
... ... @@ -253,7 +253,7 @@ public:
253 253 TOOLBAR_IMAGE,
254 254 "" );
255 255  
256   - mView.OrientationAnimationStartedSignal().Connect( this, &ItemViewExample::OnOrientationChanged );
  256 + app.GetWindow().GetOrientation().ChangedSignal().Connect( this, &ItemViewExample::OnOrientationChanged );
257 257  
258 258 // Create an edit mode button. (left of toolbar)
259 259 Toolkit::PushButton editButton = Toolkit::PushButton::New();
... ... @@ -414,7 +414,7 @@ public:
414 414 * Orientation changed signal callback
415 415 * @param orientation
416 416 */
417   - void OnOrientationChanged( View view, Animation& animation, const Orientation& orientation )
  417 + void OnOrientationChanged( Orientation orientation )
418 418 {
419 419 const unsigned int angle = orientation.GetDegrees();
420 420  
... ... @@ -1105,7 +1105,7 @@ private:
1105 1105 Mode mMode;
1106 1106 bool mMenuShown;
1107 1107  
1108   - Toolkit::View mView;
  1108 + Toolkit::Control mView;
1109 1109 unsigned int mOrientation;
1110 1110  
1111 1111 Toolkit::ToolBar mToolBar;
... ...
examples/logging/logging-example.cpp
... ... @@ -722,7 +722,7 @@ class LoggingController: public ConnectionTracker
722 722 };
723 723  
724 724 Application& mApplication;
725   - Toolkit::View mView; ///< The View instance.
  725 + Toolkit::Control mView; ///< The View instance.
726 726 Toolkit::ToolBar mToolBar; ///< The View's Toolbar.
727 727 Layer mContentLayer; ///< Content layer
728 728  
... ...
examples/magnifier/magnifier-example.cpp
... ... @@ -225,7 +225,7 @@ public:
225 225 Stage::GetCurrent().Add(overlay);
226 226  
227 227 mMagnifier = Toolkit::Magnifier::New();
228   - mMagnifier.SetSourceActor( mView.GetBackgroundLayer() );
  228 + mMagnifier.SetSourceActor( mView.GetChildAt( 0 ) );
229 229 mMagnifier.SetSize( MAGNIFIER_SIZE * mStageSize.width ); // Size of magnifier is in relation to stage width
230 230 mMagnifier.SetMagnificationFactor( MAGNIFICATION_FACTOR );
231 231 mMagnifier.SetScale(Vector3::ZERO);
... ... @@ -242,7 +242,7 @@ public:
242 242  
243 243 // Create bouncing magnifier automatically bounces around screen.
244 244 mBouncingMagnifier = Toolkit::Magnifier::New();
245   - mBouncingMagnifier.SetSourceActor( mView.GetBackgroundLayer() );
  245 + mBouncingMagnifier.SetSourceActor( mView.GetChildAt( 0 ) );
246 246 mBouncingMagnifier.SetSize( MAGNIFIER_SIZE * mStageSize.width ); // Size of magnifier is in relation to stage width
247 247 mBouncingMagnifier.SetMagnificationFactor( MAGNIFICATION_FACTOR );
248 248 overlay.Add( mBouncingMagnifier );
... ... @@ -393,7 +393,7 @@ public:
393 393 private:
394 394  
395 395 Application& mApplication; ///< Application instance
396   - Toolkit::View mView; ///< The view
  396 + Toolkit::Control mView; ///< The view
397 397 Layer mContent; ///< The content layer
398 398 Toolkit::Magnifier mMagnifier; ///< The manually controlled magnifier
399 399 Toolkit::Magnifier mBouncingMagnifier; ///< The animating magnifier (swirly animation)
... ...
examples/motion-blur/motion-blur-example.cpp
... ... @@ -503,7 +503,7 @@ public:
503 503  
504 504 private:
505 505 Application& mApplication; ///< Application instance
506   - Toolkit::View mView;
  506 + Toolkit::Control mView;
507 507 Toolkit::ToolBar mToolBar;
508 508 Image mIconEffectsOff;
509 509 Image mIconEffectsOn;
... ...
examples/motion-stretch/motion-stretch-example.cpp
... ... @@ -400,7 +400,7 @@ public:
400 400  
401 401 private:
402 402 Application& mApplication; ///< Application instance
403   - Toolkit::View mView;
  403 + Toolkit::Control mView;
404 404 Toolkit::ToolBar mToolBar;
405 405 Image mIconEffectsOff;
406 406 Image mIconEffectsOn;
... ...
examples/new-window/new-window-example.cpp
... ... @@ -88,7 +88,7 @@ private:
88 88 MeshActor mMeshActor;
89 89 MeshActor mAnimatedMeshActor;
90 90  
91   - Toolkit::View mView; ///< The View instance.
  91 + Toolkit::Control mView; ///< The View instance.
92 92 Toolkit::ToolBar mToolBar; ///< The View's Toolbar.
93 93 TextLabel mTitleActor; ///< The Toolbar's Title.
94 94 Layer mContentLayer; ///< Content layer (scrolling cluster content)
... ...
examples/page-turn-view/page-turn-view-example.cpp
... ... @@ -152,11 +152,9 @@ private:
152 152  
153 153 /**
154 154 * This method gets called when the screen is rotated, switch between portrait and landscape views
155   - * param [in] view The view receiving the orientation change signal
156   - * param [in] animation The Orientation Rotating animation
157 155 * param [in] orientation The current screen orientation
158 156 */
159   - void OnOrientationAnimationStarted( View view, Animation& animation, const Orientation& orientation );
  157 + void OnOrientationAnimationStarted( Orientation orientation );
160 158  
161 159 /**
162 160 * Main key event handler
... ... @@ -196,7 +194,7 @@ private:
196 194 private:
197 195  
198 196 Application& mApplication;
199   - View mView;
  197 + Actor mView;
200 198  
201 199 PageTurnView mPageTurnPortraitView;
202 200 PageTurnView mPageTurnLandscapeView;
... ... @@ -231,7 +229,10 @@ void PageTurnController::OnInit( Application&amp; app )
231 229 Vector2 stageSize = stage.GetSize();
232 230  
233 231 // Create default View.
234   - mView = View::New();
  232 + mView = Actor::New();
  233 + mView.SetAnchorPoint( Dali::AnchorPoint::CENTER );
  234 + mView.SetParentOrigin( Dali::ParentOrigin::CENTER );
  235 + mView.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
235 236 stage.Add( mView );
236 237  
237 238 Dali::Window winHandle = app.GetWindow();
... ... @@ -239,10 +240,9 @@ void PageTurnController::OnInit( Application&amp; app )
239 240 winHandle.AddAvailableOrientation( Dali::Window::LANDSCAPE );
240 241 winHandle.AddAvailableOrientation( Dali::Window::PORTRAIT_INVERSE );
241 242 winHandle.AddAvailableOrientation( Dali::Window::LANDSCAPE_INVERSE );
242   - // FIXME
243   - //app.GetOrientation().ChangedSignal().Connect( &mView, &View::OrientationChanged );
  243 +
244 244 // view will response to orientation change to display portrait or landscape views
245   - mView.OrientationAnimationStartedSignal().Connect( this, &PageTurnController::OnOrientationAnimationStarted );
  245 + app.GetWindow().GetOrientation().ChangedSignal().Connect( this, &PageTurnController::OnOrientationAnimationStarted );
246 246  
247 247 mPageTurnPortraitView = PageTurnPortraitView::New( mPortraitPageFactory, stageSize );
248 248 mPageTurnPortraitView.SetSpineShadowParameter( Vector2(70.f, 30.f) );
... ... @@ -262,7 +262,7 @@ void PageTurnController::OnInit( Application&amp; app )
262 262 mView.Add(mPageTurnPortraitView);
263 263 }
264 264  
265   -void PageTurnController::OnOrientationAnimationStarted( View view, Animation& animation, const Orientation& orientation )
  265 +void PageTurnController::OnOrientationAnimationStarted( Orientation orientation )
266 266 {
267 267 switch( orientation.GetDegrees() )
268 268 {
... ...
examples/path-animation/path-animation.cpp
... ... @@ -444,7 +444,7 @@ public:
444 444 stage.KeyEventSignal().Connect(this, &PathController::OnKeyEvent);
445 445  
446 446 // Create a default view with a default tool bar:
447   - Toolkit::View view; ///< The View instance.
  447 + Toolkit::Control view; ///< The View instance.
448 448 Toolkit::ToolBar toolBar; ///< The View's Toolbar.
449 449 mContentLayer = DemoHelper::CreateView( mApplication,
450 450 view,
... ...
examples/radial-menu/radial-menu-example.cpp
... ... @@ -91,7 +91,7 @@ private: // Member variables
91 91 };
92 92  
93 93 Application mApplication; ///< The application handle
94   - Toolkit::View mView; ///< The toolbar view
  94 + Toolkit::Control mView; ///< The toolbar view
95 95 Layer mContents; ///< The toolbar contents pane
96 96 ImageActor mImageActor; ///< Image actor shown by stencil mask
97 97 Animation mAnimation;
... ...
examples/refraction-effect/refraction-effect-example.cpp
... ... @@ -325,7 +325,7 @@ private:
325 325 // Creates a default view with a default tool bar.
326 326 // The view is added to the stage.
327 327 Toolkit::ToolBar toolBar;
328   - Toolkit::View view;
  328 + Toolkit::Control view;
329 329 mContent = DemoHelper::CreateView( application,
330 330 view,
331 331 toolBar,
... ...
examples/scroll-view/scroll-view-example.cpp
... ... @@ -659,7 +659,7 @@ private:
659 659 private:
660 660  
661 661 Application& mApplication; ///< Application instance
662   - Toolkit::View mView; ///< The View instance.
  662 + Toolkit::Control mView; ///< The View instance.
663 663 Toolkit::ToolBar mToolBar; ///< The View's Toolbar.
664 664 TextLabel mTitleActor; ///< The Toolbar's Title.
665 665 Layer mContentLayer; ///< The content layer (contains game actors)
... ...
examples/shadow-bone-lighting/shadow-bone-lighting-example.cpp
... ... @@ -444,7 +444,7 @@ public:
444 444  
445 445 private:
446 446 Application& mApp;
447   - Toolkit::View mView;
  447 + Toolkit::Control mView;
448 448 Layer mContents;
449 449 Actor mSceneActor;
450 450 Animation mAnimation;
... ...
examples/size-negotiation/size-negotiation-example.cpp
... ... @@ -1275,7 +1275,7 @@ private:
1275 1275 };
1276 1276  
1277 1277 Application& mApplication;
1278   - Toolkit::View mView; ///< The View instance.
  1278 + Toolkit::Control mView; ///< The View instance.
1279 1279 Toolkit::ToolBar mToolBar; ///< The View's Toolbar.
1280 1280 Layer mContentLayer; ///< Content layer
1281 1281  
... ...
shared/view.h
... ... @@ -120,7 +120,7 @@ Dali::Layer CreateToolbar( Dali::Toolkit::ToolBar&amp; toolBar,
120 120 }
121 121  
122 122 Dali::Layer CreateView( Dali::Application& application,
123   - Dali::Toolkit::View& view,
  123 + Dali::Toolkit::Control& view,
124 124 Dali::Toolkit::ToolBar& toolBar,
125 125 const std::string& backgroundImagePath,
126 126 const std::string& toolbarImagePath,
... ... @@ -130,7 +130,9 @@ Dali::Layer CreateView( Dali::Application&amp; application,
130 130 Dali::Stage stage = Dali::Stage::GetCurrent();
131 131  
132 132 // Create default View.
133   - view = Dali::Toolkit::View::New();
  133 + view = Dali::Toolkit::Control::New();
  134 + view.SetAnchorPoint( Dali::AnchorPoint::CENTER );
  135 + view.SetParentOrigin( Dali::ParentOrigin::CENTER );
134 136 view.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::ALL_DIMENSIONS );
135 137  
136 138 // Add the view to the stage before setting the background.
... ... @@ -140,8 +142,7 @@ Dali::Layer CreateView( Dali::Application&amp; application,
140 142 if ( !backgroundImagePath.empty() )
141 143 {
142 144 Dali::Image backgroundImage = Dali::ResourceImage::New( backgroundImagePath, Dali::ImageDimensions( stage.GetSize().x, stage.GetSize().y ), Dali::FittingMode::SCALE_TO_FILL, Dali::SamplingMode::BOX_THEN_LINEAR );
143   - Dali::ImageActor backgroundImageActor = Dali::ImageActor::New( backgroundImage );
144   - view.SetBackground( backgroundImageActor );
  145 + view.SetBackgroundImage( backgroundImage );
145 146 }
146 147  
147 148 // FIXME
... ... @@ -152,14 +153,14 @@ Dali::Layer CreateView( Dali::Application&amp; application,
152 153 Dali::Layer toolBarLayer = CreateToolbar( toolBar, toolbarImagePath, title, style );
153 154  
154 155 // Add tool bar layer to the view.
155   - view.AddContentLayer( toolBarLayer );
  156 + view.Add( toolBarLayer );
156 157  
157 158 // Create a content layer.
158 159 Dali::Layer contentLayer = Dali::Layer::New();
159 160 contentLayer.SetAnchorPoint( Dali::AnchorPoint::CENTER );
160 161 contentLayer.SetParentOrigin( Dali::ParentOrigin::CENTER );
161 162 contentLayer.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::ALL_DIMENSIONS );
162   - view.AddContentLayer( contentLayer );
  163 + view.Add( contentLayer );
163 164 contentLayer.LowerBelow( toolBarLayer );
164 165  
165 166 return contentLayer;
... ...