X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=optional%2Fdali-toolkit%2Finternal%2Fcontrols%2Fcluster%2Fcluster-style-impl.cpp;h=e53b378526f2dbea2872cd3c2c9d3768b8efa2f7;hp=3440be7d5770921802202411b8aebb6f859fb144;hb=4c9e3c8180e813f24d7514b275abd0d79c155405;hpb=2359f074da61124b708a31212133c8e06fe2689b diff --git a/optional/dali-toolkit/internal/controls/cluster/cluster-style-impl.cpp b/optional/dali-toolkit/internal/controls/cluster/cluster-style-impl.cpp index 3440be7..e53b378 100644 --- a/optional/dali-toolkit/internal/controls/cluster/cluster-style-impl.cpp +++ b/optional/dali-toolkit/internal/controls/cluster/cluster-style-impl.cpp @@ -19,7 +19,7 @@ #include // EXTERNAL INCLUDES - +#include // INTERNAL INCLUDES #include @@ -175,110 +175,10 @@ const unsigned int CLUSTER_RANDOM_SEED(0x17eac9f3); ///< Random seed for const int STYLE_RANDOM_CHILDREN_NUMBER = 16; -// Constraints - -/** - * First order equation of the form y = Mx + C - * current' = current * relative + offset - */ -struct FirstOrderEquationConstraint -{ - /** - * @param relative The relative multiplier of the source property - * @param offset The offset to add onto the result. - */ - FirstOrderEquationConstraint(Vector3 relative, Vector3 offset = Vector3::ZERO) - : mRelative(relative), - mOffset(offset) - { - } - - Vector3 operator()(const Vector3& current, - const PropertyInput& sourceProperty) - { - const Vector3 source = sourceProperty.GetVector3(); - - return source * mRelative + mOffset; - } - -public: - - Vector3 mRelative; - Vector3 mOffset; -}; - -/** - * Depth Constraint. - * current' = current.xy | + Vector3::ONE.z - */ -struct DepthConstraint +Vector3 FirstOrderEquation( const Vector3& source, const Vector3& relative, const Vector3& offset = Vector3::ZERO ) { - /** - * constructor - */ - DepthConstraint() - { - } - - Vector3 operator()(const Vector3& current, - const PropertyInput& depthProperty) - { - Vector3 position(current); - position.z = depthProperty.GetFloat(); - return position; - } -}; - - -/** - * Position Constraint. - * current' = current * relative + offset - */ -struct PositionConstraint -{ - /** - * @param relative The relative multiplier of the source property - * @param offset The offset to add onto the result. - */ - PositionConstraint(Vector3 relative, Vector3 offset = Vector3::ZERO) - : mRelative(relative), - mOffset(offset) - { - } - - Vector3 operator()(const Vector3& current, - const PropertyInput& sourceProperty, - const PropertyInput& depthProperty) - { - const Vector3 source = sourceProperty.GetVector3(); - - Vector3 position(source * mRelative + mOffset); - position.z += depthProperty.GetFloat(); - return position; - } - -public: - - Vector3 mRelative; - Vector3 mOffset; -}; - -template -struct SetConstraint -{ - SetConstraint(T value) - : mValue(value) - { - - } - - T operator()(const T& current) - { - return mValue; - } - - T mValue; -}; + return source * relative + offset; +} // random data generator ////////////////////////////////////////////////////// @@ -318,7 +218,8 @@ ClusterStyle::ClusterStyle() mTitleSize(Vector3::ONE), mBackgroundPositionRelative(Vector3::ONE), mBackgroundPositionOffset(Vector3::ZERO), - mBackgroundSize(Vector3::ONE) + mBackgroundSize(Vector3::ONE), + mClusterSize( Vector3::ZERO ) { } @@ -337,6 +238,24 @@ unsigned int ClusterStyle::GetMaximumNumberOfChildren() const return mMaxChildren; } +void ClusterStyle::ApplyStyleToBackground(Actor background, AlphaFunction alpha, const TimePeriod& durationSeconds) +{ + Apply( background, + FirstOrderEquation( GetClusterSize(), mBackgroundPositionRelative, mBackgroundPositionOffset ), + FirstOrderEquation( GetClusterSize(), mBackgroundSize ), + alpha, + durationSeconds); +} + +void ClusterStyle::ApplyStyleToTitle(Actor title, AlphaFunction alpha, const TimePeriod& durationSeconds) +{ + Apply( title, + FirstOrderEquation( GetClusterSize(), mTitlePositionRelative, mTitlePositionOffset ), + FirstOrderEquation( GetClusterSize(), mTitleSize ), + alpha, + durationSeconds); +} + void ClusterStyle::SetTitleProperties(const Vector3& relativePosition, const Vector3& offsetPosition, const Vector3& size) @@ -355,6 +274,64 @@ void ClusterStyle::SetBackgroundProperties(const Vector3& relativePosition, mBackgroundSize = size; } +void ClusterStyle::SetClusterSize( const Vector3& clusterSize ) +{ + mClusterSize = clusterSize; +} + +Vector3 ClusterStyle::GetClusterSize() const +{ + return mClusterSize; +} + +void ClusterStyle::Apply( Actor actor, + const Vector3& position, + const Vector3& size, + AlphaFunction alpha, + const TimePeriod& durationSeconds) +{ + float animationDuration = durationSeconds.delaySeconds + durationSeconds.durationSeconds; + if( animationDuration > 0.f ) + { + Animation animation = Animation::New(animationDuration); + animation.MoveTo( actor, position, alpha, durationSeconds.delaySeconds, durationSeconds.durationSeconds ); + animation.Resize( actor, size, alpha, durationSeconds.delaySeconds, durationSeconds.durationSeconds ); + animation.Play(); + } + else + { + actor.SetPosition( position ); + actor.SetSize( size ); + } +} + +void ClusterStyle::Apply( Actor actor, + const Vector3& position, + const Vector3& size, + const Quaternion& rotation, + const Vector3& scale, + AlphaFunction alpha, + const TimePeriod& durationSeconds) +{ + float animationDuration = durationSeconds.delaySeconds + durationSeconds.durationSeconds; + if( animationDuration > 0.f ) + { + Animation animation = Animation::New(animationDuration); + animation.MoveTo( actor, position, alpha, durationSeconds.delaySeconds, durationSeconds.durationSeconds ); + animation.Resize( actor, size, alpha, durationSeconds.delaySeconds, durationSeconds.durationSeconds ); + animation.RotateTo( actor, rotation, alpha, durationSeconds.delaySeconds, durationSeconds.durationSeconds ); + animation.ScaleTo( actor, scale, alpha, durationSeconds.delaySeconds, durationSeconds.durationSeconds ); + animation.Play(); + } + else + { + actor.SetPosition( position ); + actor.SetSize( size ); + actor.SetRotation( rotation ); + actor.SetScale( scale ); + } +} + // ClusterStyleStandard /////////////////////////////////////////////////////// ClusterStylePtr ClusterStyleStandard::New(StyleType style) @@ -449,78 +426,16 @@ void ClusterStyleStandard::ApplyStyle(Actor child, unsigned int index, AlphaFunc // counter top-left parent origin and top-left anchor point. const Vector3 position = mPositions[index] - Vector3(0.5f, 0.5f, 0.0f) + Vector3(size, size, 0.0f) * 0.5f; - Constraint constraint = Constraint::New( Actor::POSITION, - ParentSource( Actor::SIZE ), - FirstOrderEquationConstraint(Vector3(position.x, position.y, 0.0f), - Vector3(0.0f, 0.0f, position.z)) ); - - constraint.SetApplyTime(durationSeconds); - constraint.SetAlphaFunction(alpha); - constraint.SetRemoveAction(Constraint::Bake); - child.ApplyConstraint(constraint); - - constraint = Constraint::New( Actor::SIZE, - ParentSource( Actor::SIZE ), - FirstOrderEquationConstraint(Vector3::ONE * size) ); - constraint.SetApplyTime(durationSeconds); - constraint.SetAlphaFunction(alpha); - constraint.SetRemoveAction(Constraint::Bake); - child.ApplyConstraint(constraint); - - constraint = Constraint::New( Actor::ROTATION, - SetConstraint(Quaternion()) ); - constraint.SetApplyTime(durationSeconds); - constraint.SetAlphaFunction(alpha); - constraint.SetRemoveAction(Constraint::Bake); - child.ApplyConstraint(constraint); - - constraint = Constraint::New( Actor::SCALE, - SetConstraint(Vector3::ONE) ); - constraint.SetApplyTime(durationSeconds); - constraint.SetAlphaFunction(alpha); - constraint.SetRemoveAction(Constraint::Bake); - child.ApplyConstraint(constraint); + Apply( child, + FirstOrderEquation( GetClusterSize(), Vector3(position.x, position.y, 0.0f), Vector3(0.0f, 0.0f, position.z) ), + FirstOrderEquation( GetClusterSize(), Vector3::ONE * size ), + Quaternion(), + Vector3::ONE, + alpha, + durationSeconds); } } -void ClusterStyleStandard::ApplyStyleToBackground(Actor background, AlphaFunction alpha, const TimePeriod& durationSeconds) -{ - Constraint constraint = Constraint::New( Actor::POSITION, - ParentSource( Actor::SIZE ), - FirstOrderEquationConstraint(mBackgroundPositionRelative, mBackgroundPositionOffset) ); - constraint.SetApplyTime(durationSeconds); - constraint.SetAlphaFunction(alpha); - constraint.SetRemoveAction(Constraint::Bake); - background.ApplyConstraint(constraint); - - constraint = Constraint::New( Actor::SIZE, - ParentSource( Actor::SIZE ), - FirstOrderEquationConstraint(mBackgroundSize) ); - constraint.SetApplyTime(durationSeconds); - constraint.SetAlphaFunction(alpha); - constraint.SetRemoveAction(Constraint::Bake); - background.ApplyConstraint(constraint); -} - -void ClusterStyleStandard::ApplyStyleToTitle(Actor title, AlphaFunction alpha, const TimePeriod& durationSeconds) -{ - Constraint constraint = Constraint::New( Actor::POSITION, - ParentSource( Actor::SIZE ), - FirstOrderEquationConstraint(mTitlePositionRelative, mTitlePositionOffset) ); - constraint.SetApplyTime(durationSeconds); - constraint.SetAlphaFunction(alpha); - constraint.SetRemoveAction(Constraint::Bake); - title.ApplyConstraint(constraint); - - constraint = Constraint::New( Actor::SIZE, - ParentSource( Actor::SIZE ), - FirstOrderEquationConstraint(mTitleSize) ); - constraint.SetApplyTime(durationSeconds); - constraint.SetAlphaFunction(alpha); - constraint.SetRemoveAction(Constraint::Bake); - title.ApplyConstraint(constraint); -} - // ClusterStyleRandom ///////////////////////////////////////////////////////// ClusterStylePtr ClusterStyleRandom::New() @@ -552,85 +467,16 @@ void ClusterStyleRandom::ApplyStyle(Actor child, unsigned int index, AlphaFuncti 0.0f); Property::Index depthProperty = child.GetPropertyIndex(Toolkit::Cluster::CLUSTER_ACTOR_DEPTH); + float depthPropertyValue = child.GetProperty( depthProperty ); - Constraint constraint = Constraint::New( Actor::POSITION, - ParentSource( Actor::SIZE ), - FirstOrderEquationConstraint( Vector3(position.x, position.y, 0.0f), - Vector3(0.0f, 0.0f, position.z) ) ); - - constraint.SetApplyTime(durationSeconds); - constraint.SetAlphaFunction(alpha); - constraint.SetRemoveAction(Constraint::Bake); - child.ApplyConstraint(constraint); - - // this constraint overrides the Z position. setting it to cluster-actor-depth - constraint = Constraint::New( Actor::POSITION, - LocalSource( depthProperty ), - DepthConstraint() ); - - constraint.SetAlphaFunction(alpha); - constraint.SetRemoveAction(Constraint::Bake); - child.ApplyConstraint(constraint); - - constraint = Constraint::New( Actor::SIZE, - ParentSource( Actor::SIZE ), - FirstOrderEquationConstraint(Vector3::ONE * size) ); - constraint.SetApplyTime(durationSeconds); - constraint.SetAlphaFunction(alpha); - constraint.SetRemoveAction(Constraint::Bake); - child.ApplyConstraint(constraint); - - constraint = Constraint::New( Actor::ROTATION, - SetConstraint(Quaternion(rotation, Vector3::ZAXIS)) ); - constraint.SetApplyTime(durationSeconds); - constraint.SetAlphaFunction(alpha); - constraint.SetRemoveAction(Constraint::Bake); - child.ApplyConstraint(constraint); - - constraint = Constraint::New( Actor::SCALE, - SetConstraint(Vector3::ONE) ); - constraint.SetApplyTime(durationSeconds); - constraint.SetAlphaFunction(alpha); - constraint.SetRemoveAction(Constraint::Bake); - child.ApplyConstraint(constraint); -} -void ClusterStyleRandom::ApplyStyleToBackground(Actor background, AlphaFunction alpha, const TimePeriod& durationSeconds) -{ - Constraint constraint = Constraint::New( Actor::POSITION, - ParentSource( Actor::SIZE ), - FirstOrderEquationConstraint(mBackgroundPositionRelative, mBackgroundPositionOffset) ); - constraint.SetApplyTime(durationSeconds); - constraint.SetAlphaFunction(alpha); - constraint.SetRemoveAction(Constraint::Bake); - background.ApplyConstraint(constraint); - - constraint = Constraint::New( Actor::SIZE, - ParentSource( Actor::SIZE ), - FirstOrderEquationConstraint(mBackgroundSize) ); - constraint.SetApplyTime(durationSeconds); - constraint.SetAlphaFunction(alpha); - constraint.SetRemoveAction(Constraint::Bake); - background.ApplyConstraint(constraint); -} - -void ClusterStyleRandom::ApplyStyleToTitle(Actor title, AlphaFunction alpha, const TimePeriod& durationSeconds) -{ - Constraint constraint = Constraint::New( Actor::POSITION, - ParentSource( Actor::SIZE ), - FirstOrderEquationConstraint(mTitlePositionRelative, mTitlePositionOffset) ); - constraint.SetApplyTime(durationSeconds); - constraint.SetAlphaFunction(alpha); - constraint.SetRemoveAction(Constraint::Bake); - title.ApplyConstraint(constraint); - - constraint = Constraint::New( Actor::SIZE, - ParentSource( Actor::SIZE ), - FirstOrderEquationConstraint(mTitleSize) ); - constraint.SetApplyTime(durationSeconds); - constraint.SetAlphaFunction(alpha); - constraint.SetRemoveAction(Constraint::Bake); - title.ApplyConstraint(constraint); + Apply( child, + FirstOrderEquation( GetClusterSize(), Vector3(position.x, position.y, 0.0f), Vector3(0.0f, 0.0f, depthPropertyValue) ), + FirstOrderEquation( GetClusterSize(), Vector3::ONE * size), + Quaternion(rotation, Vector3::ZAXIS), + Vector3::ONE, + alpha, + durationSeconds); } } // namespace Internal