diff --git a/com.samsung.dali-demo.xml b/com.samsung.dali-demo.xml index c68fba7..3ced582 100644 --- a/com.samsung.dali-demo.xml +++ b/com.samsung.dali-demo.xml @@ -53,8 +53,8 @@ - - + + @@ -67,8 +67,11 @@ + + + - + diff --git a/demo/dali-demo.cpp b/demo/dali-demo.cpp index 63d8b69..78c2aae 100644 --- a/demo/dali-demo.cpp +++ b/demo/dali-demo.cpp @@ -51,6 +51,7 @@ int main(int argc, char **argv) demo.AddExample(Example("scroll-view.example", DALI_DEMO_STR_TITLE_SCROLL_VIEW)); demo.AddExample(Example("shadow-bone-lighting.example", DALI_DEMO_STR_TITLE_LIGHTS_AND_SHADOWS)); demo.AddExample(Example("builder.example", DALI_DEMO_STR_TITLE_SCRIPT_BASED_UI)); + demo.AddExample(Example("image-scaling-and-filtering.example", DALI_DEMO_STR_TITLE_IMAGE_FITTING_SAMPLING)); demo.AddExample(Example("image-scaling-irregular-grid.example", DALI_DEMO_STR_TITLE_IMAGE_SCALING)); demo.AddExample(Example("text-label.example", DALI_DEMO_STR_TITLE_TEXT_LABEL)); demo.AddExample(Example("text-label-multi-language.example", DALI_DEMO_STR_TITLE_TEXT_LABEL_MULTI_LANGUAGE)); diff --git a/demo/dali-table-view.cpp b/demo/dali-table-view.cpp index c1b7f6b..8175c94 100644 --- a/demo/dali-table-view.cpp +++ b/demo/dali-table-view.cpp @@ -86,8 +86,6 @@ const Vector2 POSITION_SWING_3DEFFECT( 0.55f, 0.4f ); ///< Position const Vector3 ANCHOR_3DEFFECT_STYLE0( -105.0f, 30.0f, -240.0f ); ///< Rotation Anchor position for 3D Effect (Style 0) const Vector3 ANCHOR_3DEFFECT_STYLE1( 65.0f, -70.0f, -500.0f ); ///< Rotation Anchor position for 3D Effect (Style 1) -const Dali::Vector4 TABLE_TEXT_STYLE_COLOR(0.0f, 0.0f, 0.0f, 1.0f); - Vector3 ScalePointSize(const Vector3& vec) { return Vector3( DemoHelper::ScalePointSize( vec.x ), DemoHelper::ScalePointSize( vec.y ), DemoHelper::ScalePointSize( vec.z ) ); @@ -479,8 +477,8 @@ void DaliTableView::Rotate( unsigned int degrees ) } mRotateAnimation = Animation::New( ROTATE_ANIMATION_TIME ); - mRotateAnimation.AnimateTo( Property( mRootActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree( 360 - degrees ) ), Vector3::ZAXIS ), AlphaFunctions::EaseOut ); - mRotateAnimation.AnimateTo( Property( mRootActor, Actor::Property::SIZE ), targetSize, AlphaFunctions::EaseOut ); + mRotateAnimation.AnimateTo( Property( mRootActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree( 360 - degrees ) ), Vector3::ZAXIS ), AlphaFunction::EASE_OUT ); + mRotateAnimation.AnimateTo( Property( mRootActor, Actor::Property::SIZE ), targetSize, AlphaFunction::EASE_OUT ); mRotateAnimation.Play(); } @@ -523,7 +521,6 @@ Actor DaliTableView::CreateTile( const std::string& name, const std::string& tit label.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); label.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); label.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT ); - label.SetColor( TABLE_TEXT_STYLE_COLOR ); content.Add( label ); // Set the tile to be keyboard focusable @@ -592,9 +589,9 @@ bool DaliTableView::OnTilePressed( Actor actor, const TouchEvent& event ) // scale the content actor within the Tile, as to not affect the placement within the Table. Actor content = actor.GetChildAt(0); - mPressedAnimation.AnimateTo( Property( content, Actor::Property::SCALE ), Vector3( 0.9f, 0.9f, 1.0f ), AlphaFunctions::EaseInOut, + mPressedAnimation.AnimateTo( Property( content, Actor::Property::SCALE ), Vector3( 0.9f, 0.9f, 1.0f ), AlphaFunction::EASE_IN_OUT, TimePeriod( 0.0f, BUTTON_PRESS_ANIMATION_TIME * 0.5f ) ); - mPressedAnimation.AnimateTo( Property( content, Actor::Property::SCALE ), Vector3::ONE, AlphaFunctions::EaseInOut, + mPressedAnimation.AnimateTo( Property( content, Actor::Property::SCALE ), Vector3::ONE, AlphaFunction::EASE_IN_OUT, TimePeriod( BUTTON_PRESS_ANIMATION_TIME * 0.5f, BUTTON_PRESS_ANIMATION_TIME * 0.5f ) ); mPressedAnimation.Play(); mPressedAnimation.FinishedSignal().Connect( this, &DaliTableView::OnPressedAnimationFinished ); @@ -759,7 +756,7 @@ void DaliTableView::InitialiseBackgroundActors( Actor actor ) // Kickoff animation Animation animation = Animation::New( Random::Range( 40.0f, 80.0f ) ); - animation.AnimateBy( Property( child, Actor::Property::POSITION ), Vector3( 0.0f, -1.0f, 0.0f ), AlphaFunctions::Linear ); + animation.AnimateBy( Property( child, Actor::Property::POSITION ), Vector3( 0.0f, -1.0f, 0.0f ), AlphaFunction::LINEAR ); animation.SetLooping( true ); animation.Play(); mBackgroundAnimations.push_back( animation ); diff --git a/examples/animated-shapes/animated-shapes-example.cpp b/examples/animated-shapes/animated-shapes-example.cpp index 262f0b5..0c59827 100644 --- a/examples/animated-shapes/animated-shapes-example.cpp +++ b/examples/animated-shapes/animated-shapes-example.cpp @@ -55,16 +55,14 @@ public: Stage stage = Stage::GetCurrent(); //Create a view - mView = Dali::Toolkit::View::New(); + mView = Dali::Toolkit::Control::New(); + mView.SetAnchorPoint( Dali::AnchorPoint::CENTER ); + mView.SetParentOrigin( Dali::ParentOrigin::CENTER ); mView.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); stage.Add( mView ); //Set background image for the view - Image image = ResourceImage::New( BACKGROUND_IMAGE ); - - - Dali::ImageActor backgroundImageActor = Dali::ImageActor::New( image ); - mView.SetBackground( backgroundImageActor ); + mView.SetBackgroundImage( ResourceImage::New( BACKGROUND_IMAGE ) ); CreateTriangleMorph(Vector3( stage.GetSize().x*0.5f,stage.GetSize().y*0.15f,0.0f), 100.0f ); CreateCircleMorph( Vector3( stage.GetSize().x*0.5f,stage.GetSize().y*0.85f,0.0f), 60.0f ); @@ -145,25 +143,25 @@ public: k0.Add( 0.0f, Vector3( 0.0f,-radius, 0.0f) ); k0.Add( 0.5f, Vector3(0.0f, -radius*4.0f, 0.0f)); k0.Add( 1.0f, Vector3( 0.0f,-radius, 0.0f) ); - animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(1)),k0,AlphaFunctions::EaseInOutSine ); + animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(1)),k0,AlphaFunction::EASE_IN_OUT ); k0 = KeyFrames::New(); k0.Add( 0.0f, Vector3( radius, 0.0f, 0.0f) ); k0.Add( 0.5f, Vector3(radius*4.0f,0.0f, 0.0f)); k0.Add( 1.0f, Vector3( radius,0.0f, 0.0f)); - animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(4)),k0,AlphaFunctions::EaseInOutSine ); + animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(4)),k0,AlphaFunction::EASE_IN_OUT ); k0 = KeyFrames::New(); k0.Add( 0.0f, Vector3(0.0f,radius, 0.0f) ); k0.Add( 0.5f, Vector3(0.0f,radius*4.0f, 0.0f)); k0.Add( 1.0f, Vector3(0.0f,radius, 0.0f) ); - animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(7)),k0,AlphaFunctions::EaseInOutSine ); + animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(7)),k0,AlphaFunction::EASE_IN_OUT ); k0 = KeyFrames::New(); k0.Add( 0.0f, Vector3( -radius, 0.0f, 0.0f) ); k0.Add( 0.5f, Vector3(-radius*4.0f,0.0f, 0.0f)); k0.Add( 1.0f, Vector3( -radius, 0.0f, 0.0f) ); - animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(10)),k0,AlphaFunctions::EaseInOutSine ); + animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(10)),k0,AlphaFunction::EASE_IN_OUT ); animation.AnimateBy( Property( meshActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(90.0f) ), Vector3::ZAXIS ) ); animation.SetLooping( true ); @@ -246,19 +244,19 @@ public: k0.Add( 0.0f,v3 ); k0.Add( 0.5f, v3 + Vector3(-200.0f,-200.0f,0.0f)); k0.Add( 1.0f, v3 ); - animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(1)),k0,AlphaFunctions::EaseInOutSine ); + animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(1)),k0,AlphaFunction::EASE_IN_OUT ); k0 = KeyFrames::New(); k0.Add( 0.0f,v4 ); k0.Add( 0.5f, v4 + Vector3(200.0f,-200.0f,0.0f)); k0.Add( 1.0f, v4 ); - animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(4)),k0,AlphaFunctions::EaseInOutSine ); + animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(4)),k0,AlphaFunction::EASE_IN_OUT ); k0 = KeyFrames::New(); k0.Add( 0.0f,v5 ); k0.Add( 0.5f, v5 + Vector3(0.0,200.0f,0.0f)); k0.Add( 1.0f, v5 ); - animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(7)),k0,AlphaFunctions::EaseInOutSine ); + animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(7)),k0,AlphaFunction::EASE_IN_OUT ); animation.SetLooping( true ); animation.Play(); } @@ -326,25 +324,25 @@ public: k0.Add( 0.0f, Vector3( 0.0f,-radius*2.0, 0.0f) ); k0.Add( 0.5f, Vector3(-radius*2.0, -radius*3.0f, 0.0f)); k0.Add( 1.0f, Vector3( 0.0f,-radius*2.0, 0.0f) ); - animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(1)),k0,AlphaFunctions::EaseInOutSine ); + animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(1)),k0,AlphaFunction::EASE_IN_OUT ); k0 = KeyFrames::New(); k0.Add( 0.0f, Vector3( radius*2.0, 0.0f, 0.0f) ); k0.Add( 0.5f, Vector3(radius*3.0f,-radius*2.0, 0.0f)); k0.Add( 1.0f, Vector3( radius*2.0,0.0f, 0.0f)); - animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(4)),k0,AlphaFunctions::EaseInOutSine ); + animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(4)),k0,AlphaFunction::EASE_IN_OUT ); k0 = KeyFrames::New(); k0.Add( 0.0f, Vector3(0.0f,radius*2.0, 0.0f) ); k0.Add( 0.5f, Vector3(radius*2.0,radius*3.0f, 0.0f)); k0.Add( 1.0f, Vector3(0.0f,radius*2.0, 0.0f) ); - animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(7)),k0,AlphaFunctions::EaseInOutSine ); + animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(7)),k0,AlphaFunction::EASE_IN_OUT ); k0 = KeyFrames::New(); k0.Add( 0.0f, Vector3( -radius*2.0, 0.0f, 0.0f) ); k0.Add( 0.5f, Vector3(-radius*3.0f,radius*2.0, 0.0f)); k0.Add( 1.0f, Vector3( -radius*2.0, 0.0f, 0.0f) ); - animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(10)),k0,AlphaFunctions::EaseInOutSine ); + animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(10)),k0,AlphaFunction::EASE_IN_OUT ); animation.AnimateBy( Property( meshActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(-90.0f) ), Vector3::ZAXIS ) ); animation.SetLooping( true ); @@ -364,7 +362,7 @@ public: private: Application& mApplication; - Toolkit::View mView; + Toolkit::Control mView; }; void RunTest( Application& application ) diff --git a/examples/atlas/atlas-example.cpp b/examples/atlas/atlas-example.cpp index c126da9..6d45fd8 100644 --- a/examples/atlas/atlas-example.cpp +++ b/examples/atlas/atlas-example.cpp @@ -207,7 +207,7 @@ private: Application& mApplication; PanGestureDetector mPanGestureDetector; - Toolkit::View mView; ///< The View instance. + Toolkit::Control mView; ///< The View instance. Toolkit::ToolBar mToolBar; ///< The View's Toolbar. Layer mContentLayer; ///< Content layer (scrolling cluster content) Toolkit::PushButton mLoseContextButton; diff --git a/examples/blocks/blocks-example.cpp b/examples/blocks/blocks-example.cpp index 3d96204..23775b2 100644 --- a/examples/blocks/blocks-example.cpp +++ b/examples/blocks/blocks-example.cpp @@ -595,8 +595,8 @@ private: mDragActor = actor; mDragAnimation = Animation::New(0.25f); - mDragAnimation.AnimateTo( Property(mDragActor, Actor::Property::SCALE), Vector3(1.1f, 1.1f, 1.0f), AlphaFunctions::EaseOut); - mDragAnimation.AnimateTo( Property(mPaddleHandle, Actor::Property::COLOR), Vector4(1.0f, 1.0f, 1.0f, 0.0f), AlphaFunctions::EaseOut); + mDragAnimation.AnimateTo( Property(mDragActor, Actor::Property::SCALE), Vector3(1.1f, 1.1f, 1.0f), AlphaFunction::EASE_OUT); + mDragAnimation.AnimateTo( Property(mPaddleHandle, Actor::Property::COLOR), Vector4(1.0f, 1.0f, 1.0f, 0.0f), AlphaFunction::EASE_OUT); mDragAnimation.Play(); } } @@ -621,8 +621,8 @@ private: if(point.state==TouchPoint::Up) // Stop dragging { mDragAnimation = Animation::New(0.25f); - mDragAnimation.AnimateTo( Property(mDragActor, Actor::Property::SCALE), Vector3(1.0f, 1.0f, 1.0f), AlphaFunctions::EaseIn); - mDragAnimation.AnimateTo( Property(mPaddleHandle, Actor::Property::COLOR), Vector4(1.0f, 1.0f, 1.0f, 1.0f), AlphaFunctions::EaseOut); + mDragAnimation.AnimateTo( Property(mDragActor, Actor::Property::SCALE), Vector3(1.0f, 1.0f, 1.0f), AlphaFunction::EASE_IN); + mDragAnimation.AnimateTo( Property(mPaddleHandle, Actor::Property::COLOR), Vector4(1.0f, 1.0f, 1.0f, 1.0f), AlphaFunction::EASE_OUT); mDragAnimation.Play(); mDragActor.Reset(); } @@ -764,7 +764,7 @@ private: // fade brick (destroy) Animation destroyAnimation = Animation::New(0.5f); - destroyAnimation.AnimateTo( Property( brick, Actor::Property::COLOR_ALPHA ), 0.0f, AlphaFunctions::EaseIn ); + destroyAnimation.AnimateTo( Property( brick, Actor::Property::COLOR_ALPHA ), 0.0f, AlphaFunction::EASE_IN ); destroyAnimation.Play(); destroyAnimation.FinishedSignal().Connect( this, &ExampleController::OnBrickDestroyed ); mDestroyAnimationMap[destroyAnimation] = brick; @@ -806,7 +806,7 @@ private: private: Application& mApplication; ///< Application instance - Toolkit::View mView; ///< The View instance. + Toolkit::Control mView; ///< The View instance. Layer mContentLayer; ///< The content layer (contains game actors) ImageActor mBall; ///< The Moving ball image. Vector3 mBallStartPosition; ///< Ball Start position diff --git a/examples/bubble-effect/bubble-effect-example.cpp b/examples/bubble-effect/bubble-effect-example.cpp index 5f06194..4575ee2 100644 --- a/examples/bubble-effect/bubble-effect-example.cpp +++ b/examples/bubble-effect/bubble-effect-example.cpp @@ -101,7 +101,7 @@ private: // Creates a default view with a default tool bar. // The view is added to the stage. Toolkit::ToolBar toolBar; - Toolkit::View view; + Toolkit::Control view; Layer content = DemoHelper::CreateView( app, view, toolBar, @@ -141,8 +141,8 @@ private: content.Add( bubbleRoot ); // Add the background image actor to stage - mBackgroundActor = ImageActor::New( mBackgroundImage ); - view.SetBackground( mBackgroundActor ); + view.SetBackgroundImage( mBackgroundImage ); + mBackgroundActor = ImageActor::DownCast( view.GetBackgroundActor() ); // Set up the timer to emit bubble regularly when the finger is touched down but not moved mTimerForBubbleEmission = Timer::New( mTimerInterval ); diff --git a/examples/builder/examples.cpp b/examples/builder/examples.cpp index f43ba1e..65964dc 100644 --- a/examples/builder/examples.cpp +++ b/examples/builder/examples.cpp @@ -275,6 +275,7 @@ public: void EnterSelection() { Stage stage = Stage::GetCurrent(); + stage.SetBackgroundColor( Color::WHITE ); mTapDetector = TapGestureDetector::New(); mTapDetector.DetectedSignal().Connect( this, &ExampleApp::OnTap ); @@ -587,7 +588,7 @@ private: GridLayoutPtr mGridLayout; ItemView mItemView; - Toolkit::View mView; + Toolkit::Control mView; unsigned int mOrientation; Toolkit::ToolBar mToolBar; diff --git a/examples/buttons/buttons-example.cpp b/examples/buttons/buttons-example.cpp index f5c035a..739d357 100644 --- a/examples/buttons/buttons-example.cpp +++ b/examples/buttons/buttons-example.cpp @@ -484,7 +484,7 @@ class ButtonsController: public ConnectionTracker { if( mAnimation ) { - mAnimation.AnimateBy( Property(actor, Actor::Property::POSITION), Vector3( 0.f, localPoint - mLastPoint, 0.f ), AlphaFunctions::Linear ); + mAnimation.AnimateBy( Property(actor, Actor::Property::POSITION), Vector3( 0.f, localPoint - mLastPoint, 0.f ), AlphaFunction::LINEAR ); mAnimation.Play(); mLastPoint = localPoint; } @@ -497,7 +497,7 @@ class ButtonsController: public ConnectionTracker private: Application& mApplication; - Toolkit::View mView; ///< The View instance. + Toolkit::Control mView; ///< The View instance. Toolkit::ToolBar mToolBar; ///< The View's Toolbar. Layer mContentLayer; ///< Content layer diff --git a/examples/cluster/cluster-example.cpp b/examples/cluster/cluster-example.cpp index c0f92b1..7dd8673 100644 --- a/examples/cluster/cluster-example.cpp +++ b/examples/cluster/cluster-example.cpp @@ -22,7 +22,12 @@ #include #include +#include "cluster.h" +#include "cluster-style.h" + + using namespace Dali; +using namespace Dali::Demo; using namespace Dali::Toolkit; using namespace DemoHelper; @@ -449,8 +454,6 @@ public: Stage::GetCurrent().KeyEventSignal().Connect(this, &ClusterController::OnKeyEvent); - Vector2 stageSize = Stage::GetCurrent().GetSize(); - // The Init signal is received once (only) during the Application lifetime // Hide the indicator bar @@ -477,7 +480,7 @@ public: // create and setup the scroll view... mScrollView = ScrollView::New(); - mScrollView.SetSize(stageSize); + mScrollView.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); // attach Wobble Effect to ScrollView mScrollViewEffect = ScrollViewWobbleEffect::New(); @@ -842,9 +845,9 @@ public: private: Application& mApplication; ///< Application instance - Toolkit::View mView; ///< The View instance. + Toolkit::Control mView; ///< The View instance. Toolkit::ToolBar mToolBar; ///< The View's Toolbar. - TextLabel mTitleActor; ///< The Toolbar's Title. + TextLabel mTitleActor; ///< The Toolbar's Title. Layer mContentLayer; ///< Content layer (scrolling cluster content) diff --git a/examples/cluster/cluster-impl.cpp b/examples/cluster/cluster-impl.cpp new file mode 100644 index 0000000..00b91f9 --- /dev/null +++ b/examples/cluster/cluster-impl.cpp @@ -0,0 +1,583 @@ +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// CLASS HEADER +#include "cluster-impl.h" + +// EXTERNAL INCLUDES +#include +#include // for strcmp +#include +#include +#include +#include + +// INTERNAL INCLUDES +#include "cluster-style.h" +#include "cluster-style-impl.h" + +using namespace Dali; + +namespace Dali +{ + +namespace Demo +{ + +namespace Internal +{ + +namespace +{ + +BaseHandle Create() +{ + Demo::ClusterStyleStandard s = Demo::ClusterStyleStandard::New( Demo::ClusterStyleStandard::ClusterStyle1 ); + return Demo::Cluster::New( s ); +} + +DALI_TYPE_REGISTRATION_BEGIN( Demo::Cluster, Toolkit::Control, Create ) + +DALI_ACTION_REGISTRATION( Demo, Cluster, "expand", ACTION_EXPAND ) +DALI_ACTION_REGISTRATION( Demo, Cluster, "collapse", ACTION_COLLAPSE ) +DALI_ACTION_REGISTRATION( Demo, Cluster, "transform", ACTION_TRANSFORM ) + +DALI_TYPE_REGISTRATION_END() + +const float CLUSTER_STYLE_CONSTRAINT_DURATION = 1.0f; + +} + +/////////////////////////////////////////////////////////////////////////////////////////////////// +// Cluster +/////////////////////////////////////////////////////////////////////////////////////////////////// + +Dali::Demo::Cluster Cluster::New(Demo::ClusterStyle& style) +{ + // Create the implementation + ClusterPtr cluster(new Cluster(style)); + + // Pass ownership to CustomActor via derived handle + Dali::Demo::Cluster handle(*cluster); + + // Second-phase init of the implementation + // This can only be done after the CustomActor connection has been made... + cluster->Initialize(); + + return handle; +} + +Cluster::Cluster(Demo::ClusterStyle& style) +: Toolkit::Internal::Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS | DISABLE_SIZE_NEGOTIATION ) ), + mClusterStyle(style), + mExpandedCount(0) +{ +} + +void Cluster::OnInitialize() +{ +} + +void Cluster::OnControlSizeSet( const Vector3& targetSize ) +{ + mClusterSize = targetSize; + GetImpl(mClusterStyle).SetClusterSize(targetSize); + + for(ChildInfoIter iter = mChildren.begin(); iter != mChildren.end(); ++iter) + { + + if((*iter).mActor) + { + mClusterStyle.ApplyStyle( (*iter).mActor, + (*iter).mPositionIndex, + AlphaFunction::EASE_OUT, + TimePeriod(0.f) ); + } + } + + UpdateBackground(0.f); + UpdateTitle(0.f); +} + +Cluster::~Cluster() +{ +} + +void Cluster::AddChild( Actor child ) +{ + // automatically add child with a position at end. + AddChild( child, mChildren.size() ); +} + +void Cluster::AddChild( Actor child, unsigned int positionIndex ) +{ + AddChildInfo( ChildInfo(child, positionIndex) ); +} + +void Cluster::AddChildAt( Actor child, unsigned int index ) +{ + // automatically add child with a position at end. + AddChild( child, mChildren.size() ); +} + +void Cluster::AddChildAt( Actor child, unsigned int positionIndex, unsigned int index ) +{ + AddChildInfoAt( ChildInfo(child, positionIndex), index ); +} + +void Cluster::AddChildInfo( ChildInfo childInfo ) +{ + AddChildInfoAt(childInfo, mChildren.size()); +} + +void Cluster::AddChildInfoAt( ChildInfo childInfo, unsigned int index ) +{ + // check that the child is valid + DALI_ASSERT_ALWAYS( childInfo.mActor ); + + ChildInfoIter offset = index < mChildren.size() ? (mChildren.begin() + index) : mChildren.end(); + // now perform customization on this child. + + // adopt the child + if(childInfo.mActor.GetParent() != Self()) + { + Actor& child = childInfo.mActor; + const float depth = std::distance(mChildren.begin(), offset); + + Property::Index depthProperty = child.GetPropertyIndex(Demo::Cluster::CLUSTER_ACTOR_DEPTH); + if(depthProperty == Property::INVALID_INDEX) + { + child.RegisterProperty(Demo::Cluster::CLUSTER_ACTOR_DEPTH, depth); + } + + // not added prior + Self().Add( childInfo.mActor ); + mChildren.insert( offset, childInfo ); + + // Use parent position plus relative position. + child.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION_PLUS_LOCAL_POSITION ); + + // remove old constraints + child.RemoveConstraints(); + + // apply new constraints to the child + mClusterStyle.ApplyStyle(child, childInfo.mPositionIndex, AlphaFunction::EASE_OUT, TimePeriod(0.0f)); + } + else + { + // already added. + ChildInfoContainer mNewChildren; + ChildInfoIter iter = mChildren.begin(); + float depth = 0.0f; + + for( ; iter != mChildren.end(); ++iter) + { + if(iter == offset) + { + SetDepth(childInfo, depth); + depth++; + // insert the new childInfo before offset. + mNewChildren.push_back(childInfo); + } + // copy all children except the one that we wish to move. + if((*iter).mActor != childInfo.mActor) + { + SetDepth(*iter, depth); + depth++; + mNewChildren.push_back(*iter); + } + } // end for. + + if(iter == offset) + { + SetDepth(childInfo, depth); + // insert the new childInfo before offset (end). + mNewChildren.push_back(childInfo); + } + + mChildren = mNewChildren; + + // Todo somehow adjust their perceived depth. + } +} + +void Cluster::SetDepth( ChildInfo& childInfo, float depth ) +{ + Property::Index depthProperty = childInfo.mActor.GetPropertyIndex(Demo::Cluster::CLUSTER_ACTOR_DEPTH); + childInfo.mActor.SetProperty( depthProperty, depth ); +} + +ChildInfo Cluster::GetChildInfoAt( unsigned int index ) +{ + // check if we have this position in the cluster + if( index < mChildren.size() ) + { + // return the child handle + return mChildren[ index ]; + } + + // return an empty handle + return ChildInfo(); +} + +Actor Cluster::GetChildAt( unsigned int index ) +{ + // check if we have this position in the cluster + if( index < mChildren.size() ) + { + // return the child handle + return mChildren[ index ].mActor; + } + + // return an empty handle + return Actor(); +} + +Actor Cluster::RemoveChildAt( unsigned int index ) +{ + DALI_ASSERT_ALWAYS( index < mChildren.size() ); + + ChildInfoIter iter = mChildren.begin() + index; + Actor child = (*iter).mActor; + mChildren.erase( iter ); + Self().Remove(child); + // note: constraints will automatically be removed in OnControlChildRemove + + // update depths. + float depth = 0.0f; + + for(ChildInfoIter iter = mChildren.begin(); iter != mChildren.end(); ++iter) + { + SetDepth(*iter, depth); + depth++; + } // end for. + + return child; +} + +void Cluster::ExpandChild( unsigned int index ) +{ + if( index < mChildren.size() ) + { + ChildInfo& childInfo = mChildren[ index ]; + DALI_ASSERT_ALWAYS(childInfo.mActor); + + if(!childInfo.mExpanded) + { + // expand child to a random position/angle. + const Vector3 clusterSize = Self().GetCurrentSize(); + const float length = clusterSize.Length() * 0.1f; + const float zOffset = 50.0f; + const float angle = (rand()%360) * Math::PI / 180.0f; + Vector3 position(sin(angle) * length, -cos(angle) * length, zOffset); + const float scale(1.2f); + const Radian rotate( Degree( (rand()%30) - 15 ) ); + + position += childInfo.mActor.GetCurrentPosition(); + + TransformChild(index, + position, + Vector3::ONE * scale, + Quaternion(rotate, Vector3::ZAXIS), + AlphaFunction::EASE_OUT, + TimePeriod(0.5f)); + } + } +} + +void Cluster::ExpandAllChildren() +{ + for(unsigned int index = 0;index < mChildren.size(); index++) + { + ExpandChild( index ); + } +} + +void Cluster::CollapseChild( unsigned int index, bool front ) +{ + if( index < mChildren.size() ) + { + RestoreChild(index, + AlphaFunction::EASE_OUT, + TimePeriod(0.25f), + front); + } +} + +void Cluster::CollapseAllChildren( bool front ) +{ + for(unsigned int index = 0;index < mChildren.size(); index++) + { + RestoreChild(index, + AlphaFunction::EASE_OUT, + TimePeriod(0.25f), + front); + } +} + +void Cluster::TransformChild( unsigned int index, const Vector3& position, const Vector3& scale, const Quaternion& rotation, AlphaFunction alpha, const TimePeriod& period ) +{ + if( index < mChildren.size() ) + { + ChildInfo& childInfo = mChildren[ index ]; + DALI_ASSERT_ALWAYS(childInfo.mActor); + + if(!childInfo.mExpanded) + { + Actor child = childInfo.mActor; + childInfo.mExpanded = true; + mExpandedCount++; + + child.RemoveConstraints(); + Animation animation = Animation::New(period.delaySeconds + period.durationSeconds); + animation.AnimateTo( Property(child, Actor::Property::POSITION), position, AlphaFunction::EASE_OUT, period); + animation.AnimateTo( Property(child, Actor::Property::SCALE), scale, AlphaFunction::EASE_OUT, period); + animation.AnimateTo( Property(child, Actor::Property::ORIENTATION), rotation, AlphaFunction::EASE_OUT, period); + animation.Play(); + } + } +} + +void Cluster::RestoreChild( unsigned int index, AlphaFunction alpha, const TimePeriod& period, bool front ) +{ + if( index < mChildren.size() ) + { + ChildInfo& childInfo = mChildren[ index ]; + DALI_ASSERT_ALWAYS(childInfo.mActor); + + if(childInfo.mExpanded) + { + Actor child = childInfo.mActor; + childInfo.mExpanded = false; + mExpandedCount--; + mClusterStyle.ApplyStyle( child, childInfo.mPositionIndex, alpha, period ); + + const unsigned int hideIndex = front ? mChildren.size() : 0; + AddChildInfoAt(childInfo, hideIndex); // move child info to the back or front of the pack. + } + } +} + +void Cluster::SetBackgroundImage( Actor image ) +{ + // Replaces the background image. + if(mBackgroundImage && mBackgroundImage.GetParent()) + { + mBackgroundImage.GetParent().Remove(mBackgroundImage); + } + + mBackgroundImage = image; + Self().Add(mBackgroundImage); + + mBackgroundImage.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + mBackgroundImage.SetParentOrigin( ParentOrigin::TOP_LEFT ); + + UpdateBackground(0.0f); +} + +void Cluster::SetTitle( Actor text ) +{ + // Replaces the title actor. + if(mTitle && mTitle.GetParent()) + { + mTitle.GetParent().Remove( mTitle ); + } + + mTitle = text; + Self().Add( mTitle ); + + mTitle.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + mTitle.SetParentOrigin( ParentOrigin::TOP_LEFT ); + + UpdateTitle(0.0f); +} + +void Cluster::SetStyle(Demo::ClusterStyle style) +{ + unsigned int previousChildrenNum = mChildren.size(); + mClusterStyle = style; + GetImpl(mClusterStyle).SetClusterSize(mClusterSize); + unsigned int newChildrenNum = mClusterStyle.GetMaximumNumberOfChildren(); + + // New style supports less children (remove those that no longer belong) + if(newChildrenNum < previousChildrenNum) + { + ChildInfoIter removeStart = mChildren.begin() + newChildrenNum; + + for(ChildInfoIter iter = removeStart; iter != mChildren.end(); ++iter) + { + Actor child = (*iter).mActor; + child.RemoveConstraints(); + Self().Remove(child); + } + + mChildren.erase( removeStart, mChildren.end() ); + } + + for(ChildInfoIter iter = mChildren.begin(); iter != mChildren.end(); ++iter) + { + + if((*iter).mActor) + { + mClusterStyle.ApplyStyle( (*iter).mActor, + (*iter).mPositionIndex, + AlphaFunction::EASE_OUT, + TimePeriod(CLUSTER_STYLE_CONSTRAINT_DURATION) ); + } + } + + UpdateBackground(CLUSTER_STYLE_CONSTRAINT_DURATION); + UpdateTitle(CLUSTER_STYLE_CONSTRAINT_DURATION); +} + +Demo::ClusterStyle Cluster::GetStyle() const +{ + return mClusterStyle; +} + +unsigned int Cluster::GetExpandedCount() const +{ + return mExpandedCount; +} + +unsigned int Cluster::GetTotalCount() const +{ + return mChildren.size(); +} + +void Cluster::UpdateBackground(float duration) +{ + if (mBackgroundImage) + { + mClusterStyle.ApplyStyleToBackground(mBackgroundImage, AlphaFunction::EASE_OUT, TimePeriod(duration)); + } +} + +void Cluster::UpdateTitle(float duration) +{ + if (mTitle) + { + mClusterStyle.ApplyStyleToTitle(mTitle, AlphaFunction::EASE_OUT, TimePeriod(duration)); + } +} + +void Cluster::DoExpandAction(const PropertyValueContainer& attributes) +{ + if(attributes.size() >= 1) + { + for(PropertyValueConstIter iter = attributes.begin(); iter != attributes.end(); ++iter) + { + const Property::Value& value = *iter; + + DALI_ASSERT_ALWAYS(value.GetType() == Property::FLOAT); + unsigned int index = value.Get(); + ExpandChild( index ); + } + } + else + { + ExpandAllChildren(); + } +} + +void Cluster::DoCollapseAction(const PropertyValueContainer& attributes) +{ + if(attributes.size() >= 1) + { + for(PropertyValueConstIter iter = attributes.begin(); iter != attributes.end(); ++iter) + { + const Property::Value& value = *iter; + + DALI_ASSERT_ALWAYS(value.GetType() == Property::FLOAT); + unsigned int index = value.Get(); + CollapseChild( index, false ); + } + } + else + { + CollapseAllChildren( false ); + } +} + +void Cluster::DoTransformAction(const PropertyValueContainer& attributes) +{ + DALI_ASSERT_ALWAYS(attributes.size() >= 2); + + DALI_ASSERT_ALWAYS(attributes[0].GetType() == Property::FLOAT); + unsigned int index = attributes[0].Get(); + Vector3 position; + Vector3 scale(Vector3::ONE); + Quaternion rotation( Dali::ANGLE_0, Vector3::ZAXIS ); + + DALI_ASSERT_ALWAYS(attributes[1].GetType() == Property::VECTOR3); + attributes[1].Get(position); + + if(attributes.size()>2) + { + attributes[2].Get(scale); + } + + if(attributes.size()>3) + { + attributes[3].Get(rotation); + } + + // wrap index around -1 => size - 1 + index%= mChildren.size(); + + TransformChild(index, position, scale, rotation, AlphaFunction::EASE_OUT, TimePeriod(0.5f)); +} + +void Cluster::OnControlChildRemove(Actor& child) +{ + child.RemoveConstraints(); +} + +bool Cluster::DoAction(BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes) +{ + bool ret = false; + + Dali::BaseHandle handle( object ); + + Demo::Cluster cluster = Demo::Cluster::DownCast( handle ); + + DALI_ASSERT_ALWAYS( cluster ); + + if( 0 == strcmp( actionName.c_str(), ACTION_EXPAND ) ) + { + GetImpl( cluster ).DoExpandAction( attributes ); + ret = true; + } + else if( 0 == strcmp( actionName.c_str(), ACTION_COLLAPSE ) ) + { + GetImpl( cluster ).DoCollapseAction( attributes ); + ret = true; + } + else if( 0 == strcmp( actionName.c_str(), ACTION_TRANSFORM ) ) + { + GetImpl( cluster ).DoTransformAction( attributes ); + ret = true; + } + + return ret; +} + +} // namespace Internal + +} // namespace Demo + +} // namespace Dali diff --git a/examples/cluster/cluster-impl.h b/examples/cluster/cluster-impl.h new file mode 100644 index 0000000..f57c221 --- /dev/null +++ b/examples/cluster/cluster-impl.h @@ -0,0 +1,325 @@ +#ifndef __DALI_DEMO_INTERNAL_CLUSTER_H__ +#define __DALI_DEMO_INTERNAL_CLUSTER_H__ + +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// EXTERNAL INCLUDES +#include + +// INTERNAL INCLUDES +#include "cluster.h" +#include "cluster-style.h" +#include + +namespace Dali +{ + +namespace Demo +{ + +namespace Internal +{ + +class Cluster; + +typedef IntrusivePtr ClusterPtr; + +class ChildInfo +{ + +public: + + ChildInfo() + : mExpanded(false) + { + } + + ChildInfo(Actor actor, unsigned int positionIndex) + : mActor(actor), + mExpanded(false), + mPositionIndex(positionIndex) + { + } + + Actor mActor; + bool mExpanded; + unsigned int mPositionIndex; +}; + +typedef std::vector ChildInfoContainer; +typedef ChildInfoContainer::iterator ChildInfoIter; +typedef ChildInfoContainer::const_iterator ChildInfoConstIter; + +/** + * Cluster is a container of grouped actors positioned in different cluster styles. + * Multiple cluster styles may be provided, to determine the position, size, rotation, scale, color and visibility + * of the child actors in the cluster. + */ +class Cluster : public Toolkit::Internal::Control +{ +public: + + /** + * Create a new Cluster. + * @param[in] style of the cluster + * @return A public handle to the newly allocated Cluster. + */ + static Dali::Demo::Cluster New(Demo::ClusterStyle& style); + + /** + * @copydoc Demo::Cluster::AddChild( Actor child ) + */ + void AddChild( Actor child ); + + /** + * @copydoc Demo::Cluster::AddChild( Actor child, unsigned int positionIndex ) + */ + void AddChild( Actor child, unsigned int positionIndex ); + + /** + * @copydoc Demo::Cluster::AddChildAt( Actor child, unsigned int index ); + */ + void AddChildAt( Actor child, unsigned int index ); + + /** + * @copydoc Demo::Cluster::AddChildAt( Actor child, unsigned int positionIndex, unsigned int index ); + */ + void AddChildAt( Actor child, unsigned int positionIndex, unsigned int index ); + + /** + * Adds a ChildInfo struct to the end of the children list. + * @param[in] childInfo the child info to that to children list. + */ + void AddChildInfo( ChildInfo childInfo ); + + /** + * Adds a ChildInfo struct before the specified index. + * @param[in] childInfo the child info to that to children list. + * @param[in] index the index within the children list to insert + * ChildInfo + */ + void AddChildInfoAt( ChildInfo childInfo, unsigned int index ); + + /** + * @copydoc Demo::Cluster::GetChildAt + */ + Actor GetChildAt( unsigned int index ); + + /** + * @copydoc Demo::Cluster::RemoveChildAt + */ + Actor RemoveChildAt( unsigned int index ); + + /** + * @copydoc Demo::Cluster::ExpandChild + */ + void ExpandChild( unsigned int index ); + + /** + * @copydoc Demo::Cluster::ExpandAllChildren + */ + void ExpandAllChildren(); + + /** + * @copydoc Demo::Cluster::CollapseChild + */ + void CollapseChild( unsigned int index, bool front ); + + /** + * @copydoc Demo::Cluster::CollapseAllChildren + */ + void CollapseAllChildren( bool front ); + + /** + * @copydoc Demo::Cluster::TransformChild + */ + void TransformChild( unsigned int index, const Vector3& position, const Vector3& scale, const Quaternion& rotation, AlphaFunction alpha, const TimePeriod& period ); + + /** + * @copydoc Demo::Cluster::RestoreChild + */ + void RestoreChild( unsigned int index, AlphaFunction alpha, const TimePeriod& period, bool front ); + + /** + * @copydoc Demo::Cluster::SetBackgroundImage + */ + void SetBackgroundImage( Actor image ); + + /** + * @copydoc Demo::Cluster::SetTitle + */ + void SetTitle( Actor text ); + + /** + * @copydoc Demo::Cluster::SetStyle + */ + void SetStyle(Demo::ClusterStyle style); + + /** + * @copydoc Demo::Cluster::GetStyle + */ + Demo::ClusterStyle GetStyle() const; + + /** + * @copydoc Demo::Cluster::GetExpandedCount + */ + unsigned int GetExpandedCount() const; + + /** + * @copydoc Demo::Cluster::GetTotalCount + */ + unsigned int GetTotalCount() const; + +private: + + ChildInfo GetChildInfoAt( unsigned int index ); + + void SetDepth( ChildInfo& childInfo, float depth ); + + /** + * Updates the style of the Background + * (occurs when either background changes or style changes) + * @param[in] duration apply duration for style + */ + void UpdateBackground(float duration); + + /** + * Updates the style of the Title + * (occurs when either background changes or style changes) + * @param[in] duration apply duration for style + */ + void UpdateTitle(float duration); + + /** + * Action: Expand + * Expands one or more actors. + * + * @param[in] attributes list of indices of actors to expand. + * (if no attributes specifies, then all actors expand) + */ + void DoExpandAction(const PropertyValueContainer& attributes); + + /** + * Action: Collapse + * Collapses one or more actors. + * + * @param[in] attributes list of indices of actors to collapse. + * (if no attributes specifies, then all actors collapse) + */ + void DoCollapseAction(const PropertyValueContainer& attributes); + + /** + * Action: Transform + * Transforms one actor (index) to a specified position (Vector3), + * scale (Vector3), and rotation (Quaternion). + * + * @param[in] attributes index and transform values. + */ + void DoTransformAction(const PropertyValueContainer& attributes); + +private: // From Control + /** + * From Control; called shortly before a child is removed from the owning actor. + * @param[in] child The child being removed.Ptr + */ + virtual void OnControlChildRemove(Actor& child); + +public: + + /** + * Performs actions as requested using the action name. + * @param[in] object The object on which to perform the action. + * @param[in] actionName The action to perform. + * @param[in] attributes The attributes with which to perfrom this action. + * @return true if action has been accepted by this control + */ + static bool DoAction(BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes); + +private: // From Control + + /** + * @copydoc Demo::Control::OnInitialize() + */ + virtual void OnInitialize(); + + /** + * + * @copydoc Demo::Control::OnControlSizeSet( const Vector3& targetSize ) + */ + virtual void OnControlSizeSet( const Vector3& targetSize ); + +protected: + + /** + * Construct a new Cluster. + * @param[in] style of the cluster + */ + Cluster(Demo::ClusterStyle& style); + + /** + * A reference counted object may only be deleted by calling Unreference() + */ + virtual ~Cluster(); + +private: + + // Undefined + Cluster(const Cluster&); + + // Undefined + Cluster& operator=(const Cluster& rhs); + +private: + + Demo::ClusterStyle mClusterStyle; + ChildInfoContainer mChildren; + Vector3 mClusterSize; + + Actor mBackgroundImage; ///< Stores the background image. + Actor mTitle; ///< Stores the text title. + unsigned int mExpandedCount; ///< A count of how many children have been expanded. + +}; + +} // namespace Internal + +// Helpers for public-api forwarding methods + +inline Demo::Internal::Cluster& GetImpl(Demo::Cluster& cluster) +{ + DALI_ASSERT_ALWAYS(cluster); + + Dali::RefObject& handle = cluster.GetImplementation(); + + return static_cast(handle); +} + +inline const Demo::Internal::Cluster& GetImpl(const Demo::Cluster& cluster) +{ + DALI_ASSERT_ALWAYS(cluster); + + const Dali::RefObject& handle = cluster.GetImplementation(); + + return static_cast(handle); +} + +} // namespace Demo + +} // namespace Dali + +#endif // __DALI_TOOLKIT_INTERNAL_CLUSTER_H__ diff --git a/examples/cluster/cluster-style-impl.cpp b/examples/cluster/cluster-style-impl.cpp new file mode 100644 index 0000000..f73afff --- /dev/null +++ b/examples/cluster/cluster-style-impl.cpp @@ -0,0 +1,486 @@ +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// CLASS HEADER +#include "cluster-style-impl.h" + +// EXTERNAL INCLUDES +#include + +// INTERNAL INCLUDES +#include "cluster.h" + +namespace Dali +{ + +namespace // unnamed namespace +{ +// Cluster style one + +const unsigned int STYLE_1_CHILDREN_NUMBER = 8; + +const float STYLE_1_BACKGROUND_IMAGE_OFFSET_Z = 1.0f; + +const float STYLE_1_CHILD_OFFSET_Z = 2.0f; +const float STYLE_1_CHILD_GAP_FACTOR = 0.03f; +const float STYLE_1_CHILD_SIZE_FACTOR[] = { 0.4f, 0.15f, 0.25f, 0.15f, 0.4f, 0.15f, 0.25f, 0.15f }; +const Vector3 STYLE_1_CHILD_POSITION_FACTOR[] = { Vector3(0.5f - STYLE_1_CHILD_SIZE_FACTOR[0] - STYLE_1_CHILD_GAP_FACTOR * 0.5f, + 0.5f - STYLE_1_CHILD_SIZE_FACTOR[0] - STYLE_1_CHILD_GAP_FACTOR * 0.5f, + STYLE_1_CHILD_OFFSET_Z), + Vector3(0.5f + STYLE_1_CHILD_GAP_FACTOR * 0.5f, + 0.5f - STYLE_1_CHILD_SIZE_FACTOR[1] - STYLE_1_CHILD_SIZE_FACTOR[2] - STYLE_1_CHILD_GAP_FACTOR * 1.5f, + STYLE_1_CHILD_OFFSET_Z + 0.5f), + Vector3(0.5f + STYLE_1_CHILD_GAP_FACTOR * 0.5f, + 0.5f - STYLE_1_CHILD_SIZE_FACTOR[2] - STYLE_1_CHILD_GAP_FACTOR * 0.5f, + STYLE_1_CHILD_OFFSET_Z + 1.0f), + Vector3(0.5f + STYLE_1_CHILD_SIZE_FACTOR[2] + STYLE_1_CHILD_GAP_FACTOR * 1.5f, + 0.5f - STYLE_1_CHILD_SIZE_FACTOR[3] - STYLE_1_CHILD_GAP_FACTOR * 0.5f, + STYLE_1_CHILD_OFFSET_Z + 1.5f), + Vector3(0.5f + STYLE_1_CHILD_GAP_FACTOR * 0.5f, + 0.5f + STYLE_1_CHILD_GAP_FACTOR * 0.5f, + STYLE_1_CHILD_OFFSET_Z + 2.0f), + Vector3(0.5f - STYLE_1_CHILD_SIZE_FACTOR[5] - STYLE_1_CHILD_GAP_FACTOR * 0.5f, + 0.5f + STYLE_1_CHILD_SIZE_FACTOR[6] + STYLE_1_CHILD_GAP_FACTOR * 1.5f, + STYLE_1_CHILD_OFFSET_Z + 2.5f), + Vector3(0.5f - STYLE_1_CHILD_SIZE_FACTOR[6] - STYLE_1_CHILD_GAP_FACTOR * 0.5f, + 0.5f + STYLE_1_CHILD_GAP_FACTOR * 0.5f, + STYLE_1_CHILD_OFFSET_Z + 3.0f), + Vector3(0.5f - STYLE_1_CHILD_SIZE_FACTOR[6] - STYLE_1_CHILD_SIZE_FACTOR[7] - STYLE_1_CHILD_GAP_FACTOR * 1.5f, + 0.5f + STYLE_1_CHILD_GAP_FACTOR * 0.5f, + STYLE_1_CHILD_OFFSET_Z + 3.5f) }; + +const Vector3 STYLE_1_TITLE_SIZE_FACTOR = Vector3(0.3f, 0.11f, 1.0f); +const Vector3 STYLE_1_TITLE_POSITION_FACTOR = Vector3(0.5f - STYLE_1_CHILD_SIZE_FACTOR[0] - STYLE_1_CHILD_GAP_FACTOR * 0.5f, + 0.5f - STYLE_1_CHILD_SIZE_FACTOR[0] - STYLE_1_CHILD_GAP_FACTOR * 0.5f - STYLE_1_TITLE_SIZE_FACTOR.height + 0.02f, + 0.0f); +const Vector3 STYLE_1_TITLE_POSITION_OFFSET = Vector3(0.0f, 0.0f, 8.0f); + +// Cluster style two + +const unsigned int STYLE_2_CHILDREN_NUMBER = 6; + +const float STYLE_2_BACKGROUND_IMAGE_OFFSET_Z = 1.0f; + +const float STYLE_2_CHILD_OFFSET_Z = 2.0f; +const float STYLE_2_CHILD_GAP_FACTOR = 0.03f; +const float STYLE_2_CHILD_SIZE_FACTOR[] = { 0.4f, 0.25f, 0.15f, 0.4f, 0.25f, 0.15f }; +const Vector3 STYLE_2_CHILD_POSITION_FACTOR[] = { Vector3(0.5f - STYLE_2_CHILD_SIZE_FACTOR[0] - STYLE_2_CHILD_GAP_FACTOR * 0.5f, + 0.5f - STYLE_2_CHILD_SIZE_FACTOR[0] * 0.75f, + STYLE_2_CHILD_OFFSET_Z), + Vector3(0.5f + STYLE_2_CHILD_GAP_FACTOR * 0.5f, + 0.5f - STYLE_2_CHILD_SIZE_FACTOR[1] - STYLE_2_CHILD_SIZE_FACTOR[3] * 0.25f - STYLE_2_CHILD_GAP_FACTOR, + STYLE_2_CHILD_OFFSET_Z + 0.5f), + Vector3(0.5f + STYLE_2_CHILD_SIZE_FACTOR[1] + STYLE_2_CHILD_GAP_FACTOR * 1.5f, + 0.5f - STYLE_2_CHILD_SIZE_FACTOR[2] - STYLE_2_CHILD_SIZE_FACTOR[3] * 0.25f - STYLE_2_CHILD_GAP_FACTOR, + STYLE_2_CHILD_OFFSET_Z + 1.0f), + Vector3(0.5f + STYLE_2_CHILD_GAP_FACTOR * 0.5f, + 0.5f - STYLE_2_CHILD_SIZE_FACTOR[3] * 0.25f, + STYLE_2_CHILD_OFFSET_Z + 1.5f), + Vector3(0.5f - STYLE_2_CHILD_SIZE_FACTOR[4] - STYLE_2_CHILD_GAP_FACTOR * 0.5f, + 0.5f + STYLE_2_CHILD_SIZE_FACTOR[0] * 0.25f + STYLE_2_CHILD_GAP_FACTOR, + STYLE_2_CHILD_OFFSET_Z + 2.0f), + Vector3(0.5f - STYLE_2_CHILD_SIZE_FACTOR[4] - STYLE_2_CHILD_SIZE_FACTOR[5] - STYLE_2_CHILD_GAP_FACTOR * 1.5f, + 0.5f + STYLE_2_CHILD_SIZE_FACTOR[0] * 0.25f + STYLE_2_CHILD_GAP_FACTOR, + STYLE_2_CHILD_OFFSET_Z + 2.5f) }; + +const Vector3 STYLE_2_TITLE_SIZE_FACTOR = Vector3(0.3f, 0.11f, 1.0f); +const Vector3 STYLE_2_TITLE_POSITION_FACTOR = Vector3(0.5f - STYLE_2_CHILD_SIZE_FACTOR[0] - STYLE_2_CHILD_GAP_FACTOR * 0.5f, + 0.5f - STYLE_2_CHILD_SIZE_FACTOR[0] * 0.75f - STYLE_2_TITLE_SIZE_FACTOR.height + 0.02f, + 0.0f); +const Vector3 STYLE_2_TITLE_POSITION_OFFSET = Vector3(0.0f, 0.0f, 8.0f); + +// Cluster style three + +const unsigned int STYLE_3_CHILDREN_NUMBER = 6; + +const Vector3 STYLE_3_TITLE_SIZE_FACTOR = Vector3(0.4f, 0.15f, 1.0f); + +const float STYLE_3_BACKGROUND_IMAGE_OFFSET_Z = 1.0f; + +const float STYLE_3_CHILD_OFFSET_Z = 2.0f; +const float STYLE_3_CHILD_GAP_FACTOR = 0.03f; +const float STYLE_3_CHILD_SIZE_FACTOR[] = { 0.4f, 0.4f, 0.15f, 0.25f, 0.25f, 0.15f }; +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; +const Vector3 STYLE_3_CHILD_POSITION_FACTOR[] = { Vector3(0.5f - STYLE_3_CHILD_SIZE_FACTOR[0] - STYLE_3_CHILD_GAP_FACTOR * 0.5f, + 0.5f - STYLE_3_CHILD_SIZE_FACTOR[0] - STYLE_3_CHILD_GAP_FACTOR * 0.5f + STYLE_3_CHILD_POSITION_OFFSET_Y, + STYLE_3_CHILD_OFFSET_Z), + Vector3(0.5f + STYLE_3_CHILD_GAP_FACTOR * 0.5f, + 0.5f - STYLE_3_CHILD_SIZE_FACTOR[1] - STYLE_3_CHILD_GAP_FACTOR * 0.5f + STYLE_3_CHILD_POSITION_OFFSET_Y, + STYLE_3_CHILD_OFFSET_Z + 0.5f), + Vector3(0.5f + STYLE_3_CHILD_SIZE_FACTOR[3] + STYLE_3_CHILD_GAP_FACTOR * 1.5f, + 0.5f + STYLE_3_CHILD_GAP_FACTOR * 0.5f + STYLE_3_CHILD_POSITION_OFFSET_Y, + STYLE_3_CHILD_OFFSET_Z + 1.0f), + Vector3(0.5f + STYLE_3_CHILD_GAP_FACTOR * 0.5f, + 0.5f + STYLE_3_CHILD_GAP_FACTOR * 0.5f + STYLE_3_CHILD_POSITION_OFFSET_Y, + STYLE_3_CHILD_OFFSET_Z + 1.5f), + Vector3(0.5f - STYLE_3_CHILD_SIZE_FACTOR[4] - STYLE_3_CHILD_GAP_FACTOR * 0.5f, + 0.5f + STYLE_3_CHILD_GAP_FACTOR * 0.5f + STYLE_3_CHILD_POSITION_OFFSET_Y, + STYLE_3_CHILD_OFFSET_Z + 2.0f), + Vector3(0.5f - STYLE_3_CHILD_SIZE_FACTOR[4] - STYLE_3_CHILD_SIZE_FACTOR[5] - STYLE_3_CHILD_GAP_FACTOR * 1.5f, + 0.5f + STYLE_3_CHILD_GAP_FACTOR * 0.5f + STYLE_3_CHILD_POSITION_OFFSET_Y, + STYLE_3_CHILD_OFFSET_Z + 2.5f) }; + +const Vector3 STYLE_3_TITLE_POSITION_FACTOR = Vector3(0.5f - STYLE_3_CHILD_SIZE_FACTOR[0] - STYLE_3_CHILD_GAP_FACTOR * 0.5f, + 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, + 0.0f); +const Vector3 STYLE_3_TITLE_POSITION_OFFSET = Vector3(0.0f, 0.0f, 8.0f); + +// Cluster style four + +const unsigned int STYLE_4_CHILDREN_NUMBER = 6; + +const float STYLE_4_BACKGROUND_IMAGE_OFFSET_Z = 1.0f; + +const float STYLE_4_CHILD_OFFSET_Z = 2.0f; +const float STYLE_4_CHILD_GAP_FACTOR = 0.03f; +const float STYLE_4_CHILD_SIZE_FACTOR[] = { 0.4f, 0.22f, 0.13f, 0.4f, 0.22f, 0.13f }; +const Vector3 STYLE_4_CHILD_POSITION_FACTOR[] = { Vector3(0.5f - STYLE_4_CHILD_SIZE_FACTOR[0] * 0.9f, + 0.5f - STYLE_4_CHILD_SIZE_FACTOR[0] - STYLE_4_CHILD_GAP_FACTOR * 0.5f, + STYLE_4_CHILD_OFFSET_Z), + Vector3(0.5f + STYLE_4_CHILD_SIZE_FACTOR[0] * 0.1f + STYLE_4_CHILD_GAP_FACTOR, + 0.5f - STYLE_4_CHILD_SIZE_FACTOR[1] - STYLE_4_CHILD_GAP_FACTOR * 0.5f, + STYLE_4_CHILD_OFFSET_Z + 0.5f), + Vector3(0.5f + STYLE_4_CHILD_SIZE_FACTOR[0] * 0.1f + STYLE_4_CHILD_SIZE_FACTOR[1] + STYLE_4_CHILD_GAP_FACTOR * 2.0f, + 0.5f - STYLE_4_CHILD_SIZE_FACTOR[2] - STYLE_4_CHILD_GAP_FACTOR * 0.5f, + STYLE_4_CHILD_OFFSET_Z + 1.0f), + Vector3(0.5f - STYLE_4_CHILD_SIZE_FACTOR[3] * 0.1f, + 0.5f + STYLE_4_CHILD_GAP_FACTOR * 0.5f, + STYLE_4_CHILD_OFFSET_Z + 1.5f), + Vector3(0.5f - STYLE_4_CHILD_SIZE_FACTOR[3] * 0.1f - STYLE_4_CHILD_SIZE_FACTOR[4] - STYLE_4_CHILD_GAP_FACTOR, + 0.5f + STYLE_4_CHILD_GAP_FACTOR * 0.5f, + STYLE_4_CHILD_OFFSET_Z + 2.0f), + 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, + 0.5f + STYLE_4_CHILD_GAP_FACTOR * 0.5f, + STYLE_4_CHILD_OFFSET_Z + 2.5f) }; + +const Vector3 STYLE_4_TITLE_SIZE_FACTOR = Vector3(0.3f, 0.11f, 1.0f); +const Vector3 STYLE_4_TITLE_POSITION_FACTOR = Vector3(0.5f - STYLE_4_CHILD_SIZE_FACTOR[0] * 0.9f, + 0.5f - STYLE_4_CHILD_SIZE_FACTOR[0] - STYLE_4_CHILD_GAP_FACTOR * 0.5f - STYLE_4_TITLE_SIZE_FACTOR.height + 0.02f, + 0.0f); +const Vector3 STYLE_4_TITLE_POSITION_OFFSET = Vector3(0.0f, 0.0f, 8.0f); +const unsigned int CLUSTER_RANDOM_SEED(0x17eac9f3); ///< Random seed for cluster data. + +const int STYLE_RANDOM_CHILDREN_NUMBER = 16; + +Vector3 FirstOrderEquation( const Vector3& source, const Vector3& relative, const Vector3& offset = Vector3::ZERO ) +{ + return source * relative + offset; +} + +// random data generator ////////////////////////////////////////////////////// + +const unsigned int GEN_RAND_CONST = 0x15d9a373; + +unsigned int genRandom(unsigned int& seed, unsigned int offset) +{ + unsigned int shft = offset&31; + + offset++; + + seed^= (seed << (shft) | seed >> (32 - shft)) * (offset * GEN_RAND_CONST); + + return seed; +} + +float genRandomFloat(unsigned int& seed, unsigned int offset, float min, float max) +{ + const float f = static_cast(genRandom(seed, offset)) / 0xffffffff; + return f * (max - min) + min; +} + +} // unnamed namespace + +namespace Demo +{ + +namespace Internal +{ + +// ClusterStyle /////////////////////////////////////////////////////////////// + +ClusterStyle::ClusterStyle() +: mMaxChildren(0), + mTitlePositionRelative(Vector3::ONE), + mTitlePositionOffset(Vector3::ZERO), + mTitleSize(Vector3::ONE), + mBackgroundPositionRelative(Vector3::ONE), + mBackgroundPositionOffset(Vector3::ZERO), + mBackgroundSize(Vector3::ONE), + mClusterSize( Vector3::ZERO ) +{ +} + +ClusterStyle::~ClusterStyle() +{ + +} + +void ClusterStyle::SetMaximumNumberOfChildren(unsigned int maxChildren) +{ + mMaxChildren = maxChildren; +} + +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) +{ + mTitlePositionRelative = relativePosition; + mTitlePositionOffset = offsetPosition; + mTitleSize = size; +} + +void ClusterStyle::SetBackgroundProperties(const Vector3& relativePosition, + const Vector3& offsetPosition, + const Vector3& size) +{ + mBackgroundPositionRelative = relativePosition; + mBackgroundPositionOffset = offsetPosition; + 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.AnimateTo( Property( actor, Actor::Property::POSITION ), position, alpha, TimePeriod( durationSeconds.delaySeconds, durationSeconds.durationSeconds ) ); + animation.AnimateTo( Property( actor, Actor::Property::SIZE ), size, alpha, TimePeriod( 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.AnimateTo( Property( actor, Actor::Property::POSITION ), position, alpha, TimePeriod( durationSeconds.delaySeconds, durationSeconds.durationSeconds ) ); + animation.AnimateTo( Property( actor, Actor::Property::SIZE ), size, alpha, TimePeriod( durationSeconds.delaySeconds, durationSeconds.durationSeconds ) ); + animation.AnimateTo( Property( actor, Actor::Property::ORIENTATION ), rotation, alpha, TimePeriod( durationSeconds.delaySeconds, durationSeconds.durationSeconds ) ); + animation.AnimateTo( Property( actor, Actor::Property::SCALE ), scale, alpha, TimePeriod( durationSeconds.delaySeconds, durationSeconds.durationSeconds ) ); + animation.Play(); + } + else + { + actor.SetPosition( position ); + actor.SetSize( size ); + actor.SetOrientation( rotation ); + actor.SetScale( scale ); + } +} + +// ClusterStyleStandard /////////////////////////////////////////////////////// + +ClusterStylePtr ClusterStyleStandard::New(StyleType style) +{ + ClusterStylePtr impl( new ClusterStyleStandard(style) ); + + return impl; +} + +ClusterStyleStandard::ClusterStyleStandard(StyleType style) +: ClusterStyle(), + mSizes(NULL), + mPositions(NULL) +{ + switch(style) + { + case Demo::ClusterStyleStandard::ClusterStyle1: + { + SetMaximumNumberOfChildren(STYLE_1_CHILDREN_NUMBER); + SetSizes(STYLE_1_CHILD_SIZE_FACTOR); + SetPositions(STYLE_1_CHILD_POSITION_FACTOR); + SetTitleProperties(STYLE_1_TITLE_POSITION_FACTOR, + STYLE_1_TITLE_POSITION_OFFSET, + STYLE_1_TITLE_SIZE_FACTOR); + SetBackgroundProperties(Vector3::ZERO, + Vector3(0.0f, 0.0f, STYLE_1_BACKGROUND_IMAGE_OFFSET_Z), + Vector3::ONE); + break; + } + case Demo::ClusterStyleStandard::ClusterStyle2: + { + SetMaximumNumberOfChildren(STYLE_2_CHILDREN_NUMBER); + SetSizes(STYLE_2_CHILD_SIZE_FACTOR); + SetPositions(STYLE_2_CHILD_POSITION_FACTOR); + SetTitleProperties(STYLE_2_TITLE_POSITION_FACTOR, + STYLE_2_TITLE_POSITION_OFFSET, + STYLE_2_TITLE_SIZE_FACTOR); + SetBackgroundProperties(Vector3::ZERO, + Vector3(0.0f, 0.0f, STYLE_2_BACKGROUND_IMAGE_OFFSET_Z), + Vector3::ONE); + break; + } + case Demo::ClusterStyleStandard::ClusterStyle3: + { + SetMaximumNumberOfChildren(STYLE_3_CHILDREN_NUMBER); + SetSizes(STYLE_3_CHILD_SIZE_FACTOR); + SetPositions(STYLE_3_CHILD_POSITION_FACTOR); + SetTitleProperties(STYLE_3_TITLE_POSITION_FACTOR, + STYLE_3_TITLE_POSITION_OFFSET, + STYLE_3_TITLE_SIZE_FACTOR); + SetBackgroundProperties(Vector3::ZERO, + Vector3(0.0f, 0.0f, STYLE_3_BACKGROUND_IMAGE_OFFSET_Z), + Vector3::ONE); + break; + } + case Demo::ClusterStyleStandard::ClusterStyle4: + { + SetMaximumNumberOfChildren(STYLE_4_CHILDREN_NUMBER); + SetSizes(STYLE_4_CHILD_SIZE_FACTOR); + SetPositions(STYLE_4_CHILD_POSITION_FACTOR); + SetTitleProperties(STYLE_4_TITLE_POSITION_FACTOR, + STYLE_4_TITLE_POSITION_OFFSET, + STYLE_4_TITLE_SIZE_FACTOR); + SetBackgroundProperties(Vector3::ZERO, + Vector3(0.0f, 0.0f, STYLE_4_BACKGROUND_IMAGE_OFFSET_Z), + Vector3::ONE); + break; + } + default: + { + DALI_ASSERT_ALWAYS(false && "Invalid Style"); + break; + } + } // end switch +} + +void ClusterStyleStandard::SetSizes(const float *sizes) +{ + mSizes = sizes; +} + +void ClusterStyleStandard::SetPositions(const Vector3 *positions) +{ + mPositions = positions; +} + +void ClusterStyleStandard::ApplyStyle(Actor child, unsigned int index, AlphaFunction alpha, const TimePeriod& durationSeconds) +{ + if(mPositions) + { + const float& size = mSizes[index]; + // 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; + + 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); + } +} + +// ClusterStyleRandom ///////////////////////////////////////////////////////// + +ClusterStylePtr ClusterStyleRandom::New() +{ + ClusterStylePtr impl( new ClusterStyleRandom() ); + + return impl; +} + +ClusterStyleRandom::ClusterStyleRandom() +: ClusterStyle() +{ + SetMaximumNumberOfChildren(STYLE_RANDOM_CHILDREN_NUMBER); + SetTitleProperties(Vector3::ZERO, + Vector3::ZERO, + Vector3::ONE); + SetBackgroundProperties(Vector3::ZERO, + Vector3(0.0f, 0.0f, 0.0f), + Vector3::ONE); +} + +void ClusterStyleRandom::ApplyStyle(Actor child, unsigned int index, AlphaFunction alpha, const TimePeriod& durationSeconds) +{ + unsigned int seed = CLUSTER_RANDOM_SEED; + const float size = 0.5f; + const float rotation = genRandomFloat(seed, index, -1.0f, 1.0f) * Math::PI * 0.1; // +/- 18 degrees + const Vector3 position(genRandomFloat(seed, index, -0.1f, 0.1f), + genRandomFloat(seed, index, -0.1f, 0.1f), + 0.0f); + + Property::Index depthProperty = child.GetPropertyIndex(Demo::Cluster::CLUSTER_ACTOR_DEPTH); + float depthPropertyValue = child.GetProperty( depthProperty ); + + Apply( child, + FirstOrderEquation( GetClusterSize(), Vector3(position.x, position.y, 0.0f), Vector3(0.0f, 0.0f, depthPropertyValue) ), + FirstOrderEquation( GetClusterSize(), Vector3::ONE * size), + Quaternion( Radian( rotation ), Vector3::ZAXIS ), + Vector3::ONE, + alpha, + durationSeconds); +} + +} // namespace Internal + +} // namespace Demo + +} // namespace Dali diff --git a/examples/cluster/cluster-style-impl.h b/examples/cluster/cluster-style-impl.h new file mode 100644 index 0000000..8b0e9d0 --- /dev/null +++ b/examples/cluster/cluster-style-impl.h @@ -0,0 +1,269 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// EXTERNAL INCLUDES +#include +#include +#include +#include + +// INTERNAL INCLUDES +#include "cluster-style.h" + +namespace Dali +{ + +namespace Demo +{ + +namespace Internal +{ + +class ClusterStyle; + +typedef IntrusivePtr ClusterStylePtr; + +/** + * ClusterStyle internal implementation + */ +class ClusterStyle : public Dali::BaseObject +{ +public: + + /** + * @copydoc Demo::ClusterStyle::GetMaximumNumberOfChildren + */ + unsigned int GetMaximumNumberOfChildren() const; + + /** + * @copydoc Demo::ClusterStyle::ApplyStyle + */ + virtual void ApplyStyle(Actor child, unsigned int index, AlphaFunction alpha, const TimePeriod& durationSeconds) = 0; + + /** + * @copydoc Demo::ClusterStyle::ApplyStyleToBackground + */ + virtual void ApplyStyleToBackground(Actor background, AlphaFunction alpha, const TimePeriod& durationSeconds); + + /** + * @copydoc Demo::ClusterStyle::ApplyStyleToTitle + */ + virtual void ApplyStyleToTitle(Actor title, AlphaFunction alpha, const TimePeriod& durationSeconds); + + /** + * Set the size of cluster + */ + void SetClusterSize( const Vector3& clusterSize ); + +protected: + + /** + * Set the maximum number of children this Style can handle. + * @param[in] The maximum number of children. + */ + void SetMaximumNumberOfChildren(unsigned int children); + + /** + * Set the title properties + * @param[in] relativePosition Relative position of the title + * @param[in] offsetPosition Offset position of the title + * @param[in] size The size of the title + */ + void SetTitleProperties(const Vector3& relativePosition, + const Vector3& offsetPosition, + const Vector3& size); + + /** + * Set the background properties + * @param[in] relativePosition Relative position of the background + * @param[in] offsetPosition Offset position of the background + * @param[in] size The size of the title + */ + void SetBackgroundProperties(const Vector3& relativePosition, + const Vector3& offsetPosition, + const Vector3& size); + + /** + * Get the size of cluster. + * @return the cluster size + */ + Vector3 GetClusterSize() const; + + /** + * Apply the given position & size to the actor + * @param[in] position The target position + * @param[in] size The target size + * @param[in] size The size to resize to + * @param[in] alpha The alpha function to use. + * @param[in] durationSeconds The time period to apply this style. + */ + void Apply( Actor actor, + const Vector3& position, + const Vector3& size, + AlphaFunction alpha, + const TimePeriod& durationSeconds); + /** + * Apply the given position & size to the actor + * @param[in] actor The actor to apply the changes + * @param[in] position The target position + * @param[in] size The target size + * @param[in] rotation The target Quaternion value + * @param[in] scale The target scale + * @param[in] alpha The alpha function to use. + * @param[in] durationSeconds The time period to apply this style. + */ + void Apply( Actor actor, + const Vector3& position, + const Vector3& size, + const Quaternion& rotation, + const Vector3& scale, + AlphaFunction alpha, + const TimePeriod& durationSeconds); + +protected: + + /** + * Protected constructor see ClusterStyle::New(). + */ + ClusterStyle(); + + /** + * A reference counted object may only be deleted by calling Unreference() + */ + virtual ~ClusterStyle(); + +protected: + + unsigned int mMaxChildren; ///< Maximum number of children that this style supports + Vector3 mTitlePositionRelative; ///< Title's position relative to size of cluster + Vector3 mTitlePositionOffset; ///< Title's position offset + Vector3 mTitleSize; ///< Title's size relative to size of cluster + Vector3 mBackgroundPositionRelative; ///< Background's position relative to size of cluster + Vector3 mBackgroundPositionOffset; ///< Background's position offset + Vector3 mBackgroundSize; ///< Background's size relative to size of cluster + Vector3 mClusterSize; ///< The size of cluster +}; + +/** + * ClusterStyleStandard internal implementation + */ +class ClusterStyleStandard : public ClusterStyle +{ +public: + + typedef Demo::ClusterStyleStandard::StyleType StyleType; + +public: + + /** + * Create a new cluster style. + * @param[in] style The style type to create. + * @return A smart-pointer to the newly allocated ClusterStyle. + */ + static ClusterStylePtr New(StyleType style); + +public: + + /** + * @copydoc Demo::ClusterStyle::ApplyStyle + */ + void ApplyStyle(Actor child, unsigned int index, AlphaFunction alpha, const TimePeriod& durationSeconds); + +private: + + /** + * Set the relative sizes of the children + * @param[in] size The list of sizes for the children + */ + void SetSizes(const float *sizes); + + /** + * Set the relative positions of the children + * @param[in] positions The list of positions for the children + */ + void SetPositions(const Vector3 *positions); + +protected: + + /** + * Protected constructor see ClusterStyleRandom::New(). + */ + ClusterStyleStandard(StyleType style); + +private: + + const float *mSizes; ///< List of sizes + const Vector3 *mPositions; ///< List of positions + +}; + +/** + * ClusterStyleRandom internal implementation + */ +class ClusterStyleRandom : public ClusterStyle +{ +public: + + /** + * Create a new cluster style. + * @return A smart-pointer to the newly allocated ClusterStyle. + */ + static ClusterStylePtr New(); + +public: + + /** + * @copydoc Demo::ClusterStyle::ApplyStyle + */ + void ApplyStyle(Actor child, unsigned int index, AlphaFunction alpha, const TimePeriod& durationSeconds); + +protected: + + /** + * Protected constructor see ClusterStyleRandom::New(). + */ + ClusterStyleRandom(); + +private: + +}; + +} // namespace Internal + +// Helpers for public-api forwarding methods + +inline Internal::ClusterStyle& GetImpl(Demo::ClusterStyle& pub) +{ + DALI_ASSERT_ALWAYS(pub); + + Dali::RefObject& handle = pub.GetBaseObject(); + + return static_cast(handle); +} + +inline const Internal::ClusterStyle& GetImpl(const Demo::ClusterStyle& pub) +{ + DALI_ASSERT_ALWAYS(pub); + + const Dali::RefObject& handle = pub.GetBaseObject(); + + return static_cast(handle); +} + +} // namespace Demo + +} // namespace Dali diff --git a/examples/cluster/cluster-style.cpp b/examples/cluster/cluster-style.cpp new file mode 100644 index 0000000..6117d86 --- /dev/null +++ b/examples/cluster/cluster-style.cpp @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// CLASS HEADER +#include "cluster-style.h" + +// EXTERNAL INCLUDES +#include + +// INTERNAL INCLUDES +#include "cluster-style-impl.h" + +using namespace Dali; +using namespace Dali::Demo; + +namespace Dali +{ + +namespace Demo +{ + +// ClusterStyle /////////////////////////////////////////////////////////////// + +const unsigned int ClusterStyle::UNLIMITED_CHILDREN = std::numeric_limits::max(); + +ClusterStyle::ClusterStyle() +{ +} + +ClusterStyle::~ClusterStyle() +{ +} + +ClusterStyle::ClusterStyle(Internal::ClusterStyle* internal) +: BaseHandle(internal) +{ +} + +unsigned int ClusterStyle::GetMaximumNumberOfChildren() const +{ + return GetImpl(*this).GetMaximumNumberOfChildren(); +} + +void ClusterStyle::ApplyStyle(Actor child, unsigned int index, AlphaFunction alpha, const TimePeriod& durationSeconds) +{ + GetImpl(*this).ApplyStyle(child, index, alpha, TimePeriod(durationSeconds)); +} + +void ClusterStyle::ApplyStyleToBackground(Actor background, AlphaFunction alpha, const TimePeriod& durationSeconds) +{ + GetImpl(*this).ApplyStyleToBackground(background, alpha, TimePeriod(durationSeconds)); +} + +void ClusterStyle::ApplyStyleToTitle(Actor title, AlphaFunction alpha, const TimePeriod& durationSeconds) +{ + GetImpl(*this).ApplyStyleToTitle(title, alpha, TimePeriod(durationSeconds)); +} + +// ClusterStyleStandard /////////////////////////////////////////////////////// + +ClusterStyleStandard ClusterStyleStandard::New(StyleType style) +{ + Internal::ClusterStylePtr internal = Internal::ClusterStyleStandard::New(style); + + return ClusterStyleStandard(internal.Get()); +} + +ClusterStyleStandard::ClusterStyleStandard(Internal::ClusterStyle* internal) +: ClusterStyle(internal) +{ +} + +// ClusterStyleRandom ///////////////////////////////////////////////////////// + +ClusterStyleRandom ClusterStyleRandom::New() +{ + Internal::ClusterStylePtr internal = Internal::ClusterStyleRandom::New(); + + return ClusterStyleRandom(internal.Get()); +} + +ClusterStyleRandom::ClusterStyleRandom(Internal::ClusterStyle* internal) +: ClusterStyle(internal) +{ +} + +} // namespace Demo + +} // namespace Dali diff --git a/examples/cluster/cluster-style.h b/examples/cluster/cluster-style.h new file mode 100644 index 0000000..1e39ff7 --- /dev/null +++ b/examples/cluster/cluster-style.h @@ -0,0 +1,183 @@ +#ifndef __DALI_DEMO_CLUSTER_STYLE_H__ +#define __DALI_DEMO_CLUSTER_STYLE_H__ + +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// EXTERNAL INCLUDES +#include +#include +#include +#include +#include + +// INTERNAL INCLUDES +#include + +namespace Dali +{ + +class Actor; + +namespace Demo +{ + +namespace Internal DALI_INTERNAL +{ +class ClusterStyle; +class ClusterStyleRandom; +} + +class ClusterStyle; + +typedef IntrusivePtr ClusterStylePtr; ///< Pointer to a Dali::Demo::ClusterStyle object + +/** + * @brief A ClusterStyle describes the constraints which are imposed on the child actors in the cluster. + */ +class ClusterStyle : public Dali::BaseHandle +{ +public: + + static const unsigned int UNLIMITED_CHILDREN; ///< Constant that represents an unlimited number of children. + +public: + + /** + * @brief Destructor + * + * This is non-virtual since derived Handle types must not contain data or virtual methods. + */ + ~ClusterStyle(); + + /** + * @brief Query the maximum number of children this Style can handle. + * + * If return value is UNLIMITED_CHILDREN, then this style has no + * limit. + * @return The maximum number of children. + */ + unsigned int GetMaximumNumberOfChildren() const; + + /** + * @brief Applies style (position) to child actor over a specified time duration. + * + * @param[in] child The child actor to apply + * @param[in] index The style position index for the actor to transform to. + * @param[in] alpha The alpha function to use. + * @param[in] durationSeconds The time period to apply this style. + */ + void ApplyStyle(Actor child, unsigned int index, AlphaFunction alpha, const TimePeriod& durationSeconds); + + /** + * @brief Applies style to background actor over a specified time duration. + * + * @param[in] background The background actor to apply + * @param[in] alpha The alpha function to use. + * @param[in] durationSeconds The time period to apply this style. + */ + void ApplyStyleToBackground(Actor background, AlphaFunction alpha, const TimePeriod& durationSeconds); + + /** + * @brief Applies style to title actor over a specified time duration. + * + * @param[in] title The title actor to apply + * @param[in] alpha The alpha function to use. + * @param[in] durationSeconds The time period to apply this style. + */ + void ApplyStyleToTitle(Actor title, AlphaFunction alpha, const TimePeriod& durationSeconds); + +protected: + + /** + * @brief Create a new ClusterStyle; Only derived versions are instantiatable. + */ + ClusterStyle(); + +public: // Not intended for application developers + + /** + * @brief This constructor is used by Dali New() methods. + * + * @param [in] internal A pointer to a newly allocated Dali resource + */ + explicit DALI_INTERNAL ClusterStyle(Internal::ClusterStyle* internal); +}; + +/** + * @brief A ClusterStyle describes the constraints, which are imposed on the child actors in the cluster. + */ +class ClusterStyleStandard : public ClusterStyle +{ +public: + + /** + * @brief Cluster Style type. + */ + enum StyleType + { + ClusterStyle1, ///< Style number 1 + ClusterStyle2, ///< Style number 2 + ClusterStyle3, ///< Style number 3 + ClusterStyle4, ///< Style number 4 + TotalClusterStyles ///< The number of styles + }; + +public: + + /** + * @brief Create an initialized style. + */ + static ClusterStyleStandard New(StyleType style); + +public: // Not intended for application developers + + /** + * @brief This constructor is used by Dali New() methods. + * + * @param [in] internal A pointer to a newly allocated Dali resource + */ + explicit DALI_INTERNAL ClusterStyleStandard(Internal::ClusterStyle* internal); +}; + +/** + * @brief A ClusterStyle describes the constraints, which are imposed on the child actors in the cluster. + */ +class ClusterStyleRandom : public ClusterStyle +{ +public: + + /** + * @brief Create an initialized style. + */ + static ClusterStyleRandom New(); + +public: // Not intended for application developers + + /** + * @brief This constructor is used by Dali New() methods. + * + * @param [in] internal A pointer to a newly allocated Dali resource + */ + explicit DALI_INTERNAL ClusterStyleRandom(Internal::ClusterStyle* internal); +}; + +} // namespace Demo + +} // namespace Dali + +#endif // __DALI_TOOLKIT_CLUSTER_STYLE_H__ diff --git a/examples/cluster/cluster.cpp b/examples/cluster/cluster.cpp new file mode 100644 index 0000000..76b8cf6 --- /dev/null +++ b/examples/cluster/cluster.cpp @@ -0,0 +1,173 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// CLASS HEADER + +#include "cluster.h" + +// INTERNAL INCLUDES + +#include "cluster-impl.h" + +namespace Dali +{ + +namespace Demo +{ + +/////////////////////////////////////////////////////////////////////////////////////////////////// +// Cluster +/////////////////////////////////////////////////////////////////////////////////////////////////// + +const std::string Cluster::CLUSTER_ACTOR_DEPTH( "cluster-actor-depth" ); + +Cluster::Cluster() +{ +} + +Cluster::Cluster(const Cluster& cluster) +: Toolkit::Control(cluster) +{ +} + +Cluster& Cluster::operator =(const Cluster& cluster) +{ + if( &cluster != this ) + { + Toolkit::Control::operator=( cluster ); + } + return *this; +} + +Cluster::~Cluster() +{ +} + +Cluster Cluster::New( ClusterStyle& style ) +{ + return Internal::Cluster::New(style); +} + +Cluster Cluster::DownCast( BaseHandle handle ) +{ + return Toolkit::Control::DownCast(handle); +} + +void Cluster::AddChild( Actor child ) +{ + GetImpl(*this).AddChild( child ); +} + +void Cluster::AddChild( Actor child, unsigned int positionIndex ) +{ + GetImpl(*this).AddChild( child, positionIndex); +} + +void Cluster::AddChildAt( Actor child, unsigned int index ) +{ + GetImpl(*this).AddChildAt( child, index ); +} + +void Cluster::AddChildAt( Actor child, unsigned int positionIndex, unsigned int index ) +{ + GetImpl(*this).AddChildAt( child, positionIndex, index ); +} + +Actor Cluster::GetChildAt( unsigned int index ) +{ + return GetImpl(*this).GetChildAt(index); +} + +Actor Cluster::RemoveChildAt( unsigned int index ) +{ + return GetImpl(*this).RemoveChildAt(index); +} + +void Cluster::ExpandChild( unsigned int index ) +{ + GetImpl(*this).ExpandChild(index); +} + +void Cluster::ExpandAllChildren() +{ + GetImpl(*this).ExpandAllChildren(); +} + +void Cluster::CollapseChild( unsigned int index, bool front ) +{ + GetImpl(*this).CollapseChild(index, front); +} + +void Cluster::CollapseAllChildren( bool front ) +{ + GetImpl(*this).CollapseAllChildren( front ); +} + +void Cluster::TransformChild( unsigned int index, const Vector3& position, const Vector3& scale, const Quaternion& rotation, AlphaFunction alpha, const TimePeriod& period ) +{ + GetImpl(*this).TransformChild( index, position, scale, rotation, alpha, period ); +} + +void Cluster::RestoreChild( unsigned int index, AlphaFunction alpha, const TimePeriod& period, bool front ) +{ + GetImpl(*this).RestoreChild( index, alpha, period, front ); +} + +void Cluster::SetBackgroundImage( Actor image ) +{ + GetImpl(*this).SetBackgroundImage(image); +} + +void Cluster::SetTitle( Actor text ) +{ + GetImpl(*this).SetTitle(text); +} + +void Cluster::SetStyle(ClusterStyle style) +{ + GetImpl(*this).SetStyle(style); +} + +ClusterStyle Cluster::GetStyle() const +{ + return GetImpl(*this).GetStyle(); +} + +unsigned int Cluster::GetExpandedCount() const +{ + return GetImpl(*this).GetExpandedCount(); +} + +unsigned int Cluster::GetTotalCount() const +{ + return GetImpl(*this).GetTotalCount(); +} + +Cluster::Cluster( Internal::Cluster& impl ) +: Toolkit::Control( impl ) +{ +} + +Cluster::Cluster( Dali::Internal::CustomActor* internal ) +: Toolkit::Control( internal ) +{ + VerifyCustomActorPointer(internal); +} + +} // namespace Demo + +} // namespace Dali diff --git a/examples/cluster/cluster.h b/examples/cluster/cluster.h new file mode 100644 index 0000000..07a08dc --- /dev/null +++ b/examples/cluster/cluster.h @@ -0,0 +1,264 @@ +#ifndef __DALI_DEMO_CLUSTER_H__ +#define __DALI_DEMO_CLUSTER_H__ + +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// EXTERNAL INCLUDES +#include +#include + +// INTERNAL INCLUDES +#include + +namespace Dali +{ + +namespace Demo +{ + +namespace Internal DALI_INTERNAL +{ +class Cluster; +} + +class ClusterStyle; + +/** + * @brief Cluster is a container of grouped actors positioned in different cluster styles. + * + * Actions + * | %Action Name | Method | + * |---------------------------|---------------------------| + * | expand | DoExpandAction() | + * | collapse | DoCollapseAction() | + * | transform | DoTransformAction() | + */ +class Cluster : public Toolkit::Control +{ +public: + + // Custom properties + + static const std::string CLUSTER_ACTOR_DEPTH; ///< Property, name "cluster-actor-depth", type float + +public: + + /** + * Create a Cluster handle; this can be initialised with Cluster::New() + * Calling member functions with an uninitialised handle is not allowed. + */ + Cluster(); + + /** + * Copy Constructor. + */ + Cluster( const Cluster& cluster ); + + /** + * Assignment Operator. + */ + Cluster& operator=( const Cluster& cluster ); + + /** + * @brief Destructor + * + * This is non-virtual since derived Handle types must not contain data or virtual methods. + */ + ~Cluster(); + + /** + * Create the Cluster control with the given style. + * @param[in] style The style of the cluster + * @return A handle to the Cluster control. + */ + static Cluster New( ClusterStyle& style ); + + /** + * Downcast an Object handle to Cluster. If handle points to a Cluster the + * downcast produces valid handle. If not the returned handle is left uninitialized. + * @param[in] handle Handle to an object + * @return handle to a Cluster or an uninitialized handle + */ + static Cluster DownCast( BaseHandle handle ); + + /** + * Adds a child to the Cluster + * Will automatically choose a position for the child. + * @pre The child actor has been initialized. + * @param[in] child The child to add + */ + void AddChild( Actor child ); + + /** + * Adds a child to the Cluster + * User specifies the position for the child. + * @pre The child actor has been initialized. + * @param[in] child The child to add + * @param[in] positionIndex The position for this child + */ + void AddChild( Actor child, unsigned int positionIndex ); + + /** + * Adds a child to the Cluster to be inserted at a specified + * depth index. + * Will automatically choose a position for the child. + * @pre The child actor has been initialized. + * @param[in] child The child to add + * @param[in] index The depth position for this child + */ + void AddChildAt( Actor child, unsigned int index ); + + /** + * Adds a child to the Cluster to be inserted at a specified + * depth index. + * User specifies the position for the child. + * @pre The child actor has been initialized. + * @param[in] child The child to add + * @param[in] positionIndex The position for this child + * @param[in] index The depth position for this child + */ + void AddChildAt( Actor child, unsigned int positionIndex, unsigned int index ); + + /** + * Returns a child from the given layout position + * Note! if there is no child in this layout position this method returns an uninitialized + * Actor handle + * @param[in] index The child index in the cluster + * @return The child that was in the layout position or an uninitialized handle + */ + Actor GetChildAt( unsigned int index ); + + /** + * Removes a child from the given layout position + * Note! if there is no child in this layout position this method does nothing + * @param[in] index The index of the child to remove + * @return The child that was removed or an uninitialized handle + */ + Actor RemoveChildAt( unsigned int index ); + + /** + * Expands a child + * A child will move away from the cluster. + * @param[in] index The child position index to expand + */ + void ExpandChild( unsigned int index ); + + /** + * Expands all children + * All children that have been collapsed will + * move away from the cluster + */ + void ExpandAllChildren(); + + /** + * Collapses a child + * A child that has been expanded will move + * back to its original positions. + * @param[in] index The child index to collapse + * @param[in] front Whether to move child to the front or + * back of cluster (depth). + */ + void CollapseChild( unsigned int index, bool front = false ); + + /** + * Collapses all children. + * All children that have been expanded will move + * back to their original positions. + * @param[in] front Whether to move child to the front or + * back of cluster (depth). + */ + void CollapseAllChildren( bool front = false ); + + /** + * Transforms Actor from default transform to new transform + * @param[in] index The child index to move + * @param[in] position The position to move to + * @param[in] scale The scale to change to + * @param[in] rotation The rotation to change to + * @param[in] alpha The alpha function to use to tween to this transform + * @param[in] period The duration for this transformation to take + */ + void TransformChild( unsigned int index, const Vector3& position, const Vector3& scale, const Quaternion& rotation, AlphaFunction alpha, const TimePeriod& period ); + + /** + * Restores Actor to the default transform (based on current style) + * @param[in] index The child index to move back + * @param[in] alpha The alpha function to use to tween to this transform + * @param[in] period The duration for this transformation to take + * @param[in] front Whether to move child to the front or + * back of cluster (depth). + */ + void RestoreChild( unsigned int index, AlphaFunction alpha, const TimePeriod& period, bool front = false ); + + /** + * Sets the background image. + * @param[in] image The background image. + */ + void SetBackgroundImage( Actor image ); + + /** + * Sets the title. + * + * @param[in] text Title text. + */ + void SetTitle( Actor text ); + + /** + * Sets the style of the cluster + * @param[in] style The style of the cluster + */ + void SetStyle(ClusterStyle style); + + /** + * Gets the style of the cluster + * @return style of the cluster + */ + ClusterStyle GetStyle() const; + + /** + * Gets the number of children that have been expanded in this cluster. + * @return the number of children expanded. + */ + unsigned int GetExpandedCount() const; + + /** + * Gets the number of children that have been added to this cluster. + * @return the total number of children. + */ + unsigned int GetTotalCount() const; + +public: // Not intended for application developers + + /** + * Creates a handle using the Toolkit::Internal implementation. + * @param[in] implementation The Control implementation. + */ + DALI_INTERNAL Cluster( Internal::Cluster& implementation ); + + /** + * Allows the creation of this Control from an Internal::CustomActor pointer. + * @param[in] internal A pointer to the internal CustomActor. + */ + explicit DALI_INTERNAL Cluster( Dali::Internal::CustomActor* internal ); +}; + +} // namespace Toolkit + +} // namespace Dali + +#endif // __DALI_DEMO_CLUSTER_H__ diff --git a/examples/cube-transition-effect/cube-transition-effect-example.cpp b/examples/cube-transition-effect/cube-transition-effect-example.cpp index abc16d8..5961390 100644 --- a/examples/cube-transition-effect/cube-transition-effect-example.cpp +++ b/examples/cube-transition-effect/cube-transition-effect-example.cpp @@ -168,7 +168,7 @@ private: private: Application& mApplication; - Toolkit::View mView; + Toolkit::Control mView; Toolkit::ToolBar mToolBar; Layer mContent; Toolkit::TextLabel mTitleActor; diff --git a/examples/dissolve-effect/dissolve-effect-example.cpp b/examples/dissolve-effect/dissolve-effect-example.cpp index fdada71..ebbe4c9 100644 --- a/examples/dissolve-effect/dissolve-effect-example.cpp +++ b/examples/dissolve-effect/dissolve-effect-example.cpp @@ -152,7 +152,7 @@ private: private: Application& mApplication; - Toolkit::View mView; + Toolkit::Control mView; Toolkit::ToolBar mToolBar; Layer mContent; Toolkit::TextLabel mTitleActor; @@ -297,21 +297,21 @@ void DissolveEffectApp::StartTransition(Vector2 position, Vector2 displacement) mCurrentImageEffect.SetCentralLine(position,displacement); mCurrentImageEffect.SetDistortion(0.0f); mCurrentImage.SetShaderEffect(mCurrentImageEffect); - mAnimation.AnimateTo( Property(mCurrentImageEffect, mCurrentImageEffect.GetDistortionPropertyName()), 1.0f, AlphaFunctions::Linear ); + mAnimation.AnimateTo( Property(mCurrentImageEffect, mCurrentImageEffect.GetDistortionPropertyName()), 1.0f, AlphaFunction::LINEAR ); mNextImage.SetOpacity(0.0f); - mAnimation.AnimateTo( Property( mNextImage, Actor::Property::COLOR_ALPHA ), 1.0f, AlphaFunctions::Linear ); + mAnimation.AnimateTo( Property( mNextImage, Actor::Property::COLOR_ALPHA ), 1.0f, AlphaFunction::LINEAR ); if(mUseHighPrecision) { mNextImageEffect.SetCentralLine(position,-displacement); mNextImageEffect.SetDistortion(1.0f); mNextImage.SetShaderEffect(mNextImageEffect); - mAnimation.AnimateTo( Property(mNextImageEffect, mNextImageEffect.GetDistortionPropertyName()), 0.0f, AlphaFunctions::Linear ); + mAnimation.AnimateTo( Property(mNextImageEffect, mNextImageEffect.GetDistortionPropertyName()), 0.0f, AlphaFunction::LINEAR ); } else { - mAnimation.AnimateTo( Property( mNextImage, Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), AlphaFunctions::Linear ); + mAnimation.AnimateTo( Property( mNextImage, Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), AlphaFunction::LINEAR ); } mAnimation.FinishedSignal().Connect( this, &DissolveEffectApp::OnTransitionCompleted ); diff --git a/examples/hello-world/hello-world-example.cpp b/examples/hello-world/hello-world-example.cpp index 9dea8ac..3a944fa 100644 --- a/examples/hello-world/hello-world-example.cpp +++ b/examples/hello-world/hello-world-example.cpp @@ -43,6 +43,7 @@ public: { // Get a handle to the stage Stage stage = Stage::GetCurrent(); + stage.SetBackgroundColor( Color::WHITE ); TextLabel textLabel = TextLabel::New( "Hello World" ); textLabel.SetAnchorPoint( AnchorPoint::TOP_LEFT ); diff --git a/examples/image-scaling-and-filtering/image-scaling-and-filtering-example.cpp b/examples/image-scaling-and-filtering/image-scaling-and-filtering-example.cpp new file mode 100644 index 0000000..882687a --- /dev/null +++ b/examples/image-scaling-and-filtering/image-scaling-and-filtering-example.cpp @@ -0,0 +1,738 @@ +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include "shared/view.h" +#include + +using namespace Dali; +using Toolkit::TextLabel; + +namespace +{ + +const char* BACKGROUND_IMAGE( DALI_IMAGE_DIR "background-gradient.jpg" ); +const Vector4 BACKGROUND_COLOUR( 1.0f, 1.0f, 1.0f, 0.15f ); + +const int MARGIN_SIZE = 10; + +const char* const NEXT_BUTTON_ID = "NEXT_BUTTON"; +const char* const PREVIOUS_BUTTON_ID = "PREVIOUS_BUTTON"; +const char * const DALI_ICON_PLAY = DALI_IMAGE_DIR "icon-play.png"; + +const char* const PUSHBUTTON_PRESS_IMAGE = DALI_IMAGE_DIR "button-down.9.png"; +const char* const PUSHBUTTON_BUTTON_IMAGE = DALI_IMAGE_DIR "button-up.9.png"; +const char* const PUSHBUTTON_DISABLED_IMAGE = DALI_IMAGE_DIR "button-disabled.9.png"; + +const char* const FITTING_BUTTON_ID = "FITTING_BUTTON"; +const char* const SAMPLING_BUTTON_ID = "SAMPLING_BUTTON"; +const char* const FITTING_BUTTON_TEXT = "Fitting"; +const char* const SAMPLING_BUTTON_TEXT = "Sampling"; + +const char* const STYLE_LABEL_TEXT = "grouplabel"; +const char* const STYLE_BUTTON_TEXT = "buttonlabel"; + + + +const char* IMAGE_PATHS[] = +{ + // Worst case for aliasing in downscaling, 2k x 2k 1 bit per pixel dithered + // black and white image: + DALI_IMAGE_DIR "gallery-large-14.wbmp", + // Variety of sizes, shapes and formats: + DALI_IMAGE_DIR "animation-list.png", + DALI_IMAGE_DIR "layer1.png", + DALI_IMAGE_DIR "layer2.png", + DALI_IMAGE_DIR "music-libray-main-screen.png", + DALI_IMAGE_DIR "music-libray-record-cover.png", + DALI_IMAGE_DIR "contacts-background.png", + DALI_IMAGE_DIR "portrait_screen_primitive_shapes.gif", + DALI_IMAGE_DIR "landscape_screen_primitive_shapes.gif", + DALI_IMAGE_DIR "square_primitive_shapes.bmp", + DALI_IMAGE_DIR "dali-logo.png", + DALI_IMAGE_DIR "com.samsung.dali-demo.ico", + DALI_IMAGE_DIR "gallery-large-14.jpg", + DALI_IMAGE_DIR "book-landscape-cover.jpg", + DALI_IMAGE_DIR "book-portrait-p1.jpg", + DALI_IMAGE_DIR "book-landscape-cover-back.jpg", + DALI_IMAGE_DIR "background-1.jpg", + DALI_IMAGE_DIR "background-blocks.jpg", + DALI_IMAGE_DIR "background-magnifier.jpg", + DALI_IMAGE_DIR "gallery-large-14.jpg", + NULL +}; +const int NUM_IMAGE_PATHS = sizeof(IMAGE_PATHS) / sizeof(IMAGE_PATHS[0]) - 1u; + +/** Cycle the scaling mode options. */ +FittingMode::Type NextScalingMode( FittingMode::Type oldMode ) +{ + FittingMode::Type newMode = FittingMode::SHRINK_TO_FIT; + switch ( oldMode ) + { + case FittingMode::SHRINK_TO_FIT: + newMode = FittingMode::SCALE_TO_FILL; + break; + case FittingMode::SCALE_TO_FILL: + newMode = FittingMode::FIT_WIDTH; + break; + case FittingMode::FIT_WIDTH: + newMode = FittingMode::FIT_HEIGHT; + break; + case FittingMode::FIT_HEIGHT: + newMode = FittingMode::SHRINK_TO_FIT; + break; + } + return newMode; +} + +/** Cycle through filter mode options. */ +SamplingMode::Type NextFilterMode( SamplingMode::Type oldMode ) +{ + SamplingMode::Type newMode = SamplingMode::BOX; + + switch ( oldMode ) + { + case SamplingMode::BOX: + newMode = SamplingMode::NEAREST; + break; + case SamplingMode::NEAREST: + newMode = SamplingMode::LINEAR; + break; + case SamplingMode::LINEAR: + newMode = SamplingMode::BOX_THEN_NEAREST; + break; + case SamplingMode::BOX_THEN_NEAREST: + newMode = SamplingMode::BOX_THEN_LINEAR; + break; + case SamplingMode::BOX_THEN_LINEAR: + newMode = SamplingMode::NO_FILTER; + break; + case SamplingMode::NO_FILTER: + newMode = SamplingMode::BOX; + break; + case SamplingMode::DONT_CARE: + newMode = SamplingMode::BOX; + break; + } + return newMode; +} + +const char* StringFromScalingMode( FittingMode::Type scalingMode ) +{ + return scalingMode == FittingMode::SCALE_TO_FILL ? "SCALE_TO_FILL" : scalingMode == FittingMode::SHRINK_TO_FIT ? "SHRINK_TO_FIT" : scalingMode == FittingMode::FIT_WIDTH ? "FIT_WIDTH" : scalingMode == FittingMode::FIT_HEIGHT ? "FIT_HEIGHT" : "UnknownScalingMode"; +} + +const char* StringFromFilterMode( SamplingMode::Type filterMode ) +{ + return filterMode == SamplingMode::BOX ? "BOX" : filterMode == SamplingMode::BOX_THEN_NEAREST ? "BOX_THEN_NEAREST" : filterMode == SamplingMode::BOX_THEN_LINEAR ? "BOX_THEN_LINEAR" : filterMode == SamplingMode::NEAREST ? "NEAREST" : filterMode == SamplingMode::LINEAR ? "LINEAR" : filterMode == SamplingMode::NO_FILTER ? "NO_FILTER" : filterMode == SamplingMode::DONT_CARE ? "DONT_CARE" : "UnknownFilterMode"; +} + +} + +// This example shows the load-time image scaling and filtering features. +// +class ImageScalingAndFilteringController : public ConnectionTracker +{ +public: + + ImageScalingAndFilteringController( Application& application ) + : mApplication( application ), + mImageStageScale( 0.5f, 0.5f ), + mCurrentPath( 0 ), + mFittingMode( FittingMode::SCALE_TO_FILL ), + mSamplingMode( SamplingMode::BOX_THEN_LINEAR) + { + // Connect to the Application's Init signal + mApplication.InitSignal().Connect( this, &ImageScalingAndFilteringController::Create ); + } + + ~ImageScalingAndFilteringController() + { + // Nothing to do here; + } + + // The Init signal is received once (only) during the Application lifetime + void Create( Application& application ) + { + // Apply the default theme: + DemoHelper::RequestThemeChange(); + + // Get a handle to the stage + Stage stage = Stage::GetCurrent(); + + // Background image: + ResourceImage backgroundImage = ResourceImage::New( BACKGROUND_IMAGE, ImageDimensions( stage.GetSize().width, stage.GetSize().height ), FittingMode::SCALE_TO_FILL, SamplingMode::BOX_THEN_LINEAR ); + ImageActor background = ImageActor::New( backgroundImage ); + background.SetZ( -2.0f ); + background.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + background.SetSize( stage.GetSize() ); + stage.Add( background ); + + // Make grey pixels for the desired box, the desired height the desired width: + BufferImage desiredBackground = BufferImage::WHITE(); + + BufferImage heightBackground = BufferImage::WHITE(); + PixelBuffer* const heightPixel = heightBackground.GetBuffer(); + heightPixel[0] = 0x8f; + heightPixel[1] = 0x8f; + heightPixel[2] = 0x8f; + + BufferImage widthBackground = BufferImage::WHITE(); + PixelBuffer* const widthPixel = widthBackground.GetBuffer(); + widthPixel[0] = 0x4f; + widthPixel[1] = 0x4f; + widthPixel[2] = 0x4f; + + mHeightBox = ImageActor::New( heightBackground ); + mHeightBox.SetOpacity( 0.2f ); + stage.Add( mHeightBox ); + + mWidthBox = ImageActor::New( widthBackground ); + mWidthBox.SetOpacity( 0.2f ); + stage.Add( mWidthBox ); + + mDesiredBox = ImageActor::New( desiredBackground ); + stage.Add( mDesiredBox ); + + mDesiredBox.SetSize( stage.GetSize() * mImageStageScale ); + mDesiredBox.SetParentOrigin( ParentOrigin::CENTER ); + mDesiredBox.SetAnchorPoint( AnchorPoint::CENTER ); + mDesiredBox.SetPosition( 0, 0, -1 ); + + mHeightBox.SetSize( stage.GetSize().width, (stage.GetSize() * mImageStageScale).height ); + mHeightBox.SetParentOrigin( ParentOrigin::CENTER ); + mHeightBox.SetAnchorPoint( AnchorPoint::CENTER ); + mHeightBox.SetPosition( 0, 0, -1 ); + + mWidthBox.SetSize( (stage.GetSize() * mImageStageScale).width, stage.GetSize().height ); + mWidthBox.SetParentOrigin( ParentOrigin::CENTER ); + mWidthBox.SetAnchorPoint( AnchorPoint::CENTER ); + mWidthBox.SetPosition( 0, 0, -1 ); + + // Make a grab-handle for resizing the image: + mGrabCorner = Toolkit::PushButton::New(); + mGrabCorner.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::WIDTH ); + mGrabCorner.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); + mGrabCorner.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) ); + mGrabCorner.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) ); + mGrabCorner.SetDisabledImage( Dali::ResourceImage::New( PUSHBUTTON_DISABLED_IMAGE ) ); + mGrabCorner.SetName( "GrabCorner" ); + mGrabCorner.SetAnchorPoint( AnchorPoint::BOTTOM_RIGHT ); + mGrabCorner.SetParentOrigin( ParentOrigin::BOTTOM_RIGHT ); + mGrabCorner.SetSize( Vector2( stage.GetSize().width*0.08f, stage.GetSize().width*0.08f ) ); + mGrabCorner.SetZ( 1.0f ); + mGrabCorner.SetOpacity( 0.6f ); + mDesiredBox.Add( mGrabCorner ); + mPanGestureDetector = PanGestureDetector::New(); + mPanGestureDetector.Attach( mGrabCorner ); + mPanGestureDetector.DetectedSignal().Connect( this, &ImageScalingAndFilteringController::OnPan ); + + // Initialize the actor + mImageActor = ImageActor::New(); + + // Reposition the actor + mImageActor.SetParentOrigin( ParentOrigin::CENTER ); + mImageActor.SetAnchorPoint( AnchorPoint::CENTER ); + + // Display the actor on the stage + stage.Add( mImageActor ); + + mImageActor.SetSize( stage.GetSize() * mImageStageScale ); + + // Setup the pinch detector for scaling the desired image load dimensions: + mPinchDetector = PinchGestureDetector::New(); + mPinchDetector.Attach( mImageActor ); + mPinchDetector.DetectedSignal().Connect( this, &ImageScalingAndFilteringController::OnPinch ); + + // Tie-in input event handlers: + stage.KeyEventSignal().Connect( this, &ImageScalingAndFilteringController::OnKeyEvent ); + + CreateControls(); + + ResizeImage(); + } + + /** + * Create the GUI controls which float above the scene + */ + void CreateControls() + { + Stage stage = Stage::GetCurrent(); + + Dali::Layer controlsLayer = Dali::Layer::New(); + controlsLayer.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); + controlsLayer.SetSizeModeFactor( Vector3( 1.0f, 1.0f, 1.0f ) ); + controlsLayer.SetAnchorPoint( AnchorPoint::TOP_LEFT); + controlsLayer.SetParentOrigin( ParentOrigin::TOP_LEFT); + stage.Add( controlsLayer ); + + // Back and next image buttons in corners of stage: + unsigned int playWidth = std::min( stage.GetSize().x * (1 / 5.0f), 58.0f ); + Image playImage = ResourceImage::New( DALI_ICON_PLAY, ImageDimensions( playWidth, playWidth ), FittingMode::SHRINK_TO_FIT, SamplingMode::BOX_THEN_LINEAR ); + Actor imagePrevious = ImageActor::New( playImage ); + + // Last image button: + imagePrevious.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + imagePrevious.RotateBy( Radian(3.14159265358979323846f), Vector3( 0, 1.0f, 0 ) ); + imagePrevious.SetY( playWidth * 0.5f ); + imagePrevious.SetX( playWidth + playWidth * 0.5f ); + imagePrevious.SetOpacity( 0.6f ); + controlsLayer.Add( imagePrevious ); + imagePrevious.SetName( PREVIOUS_BUTTON_ID ); + imagePrevious.TouchedSignal().Connect( this, &ImageScalingAndFilteringController::OnControlTouched ); + + // Next image button: + Actor imageNext = ImageActor::New( playImage ); + imageNext.SetAnchorPoint( AnchorPoint::TOP_RIGHT ); + imageNext.SetY( playWidth * 0.5f ); + imageNext.SetX( stage.GetSize().x - playWidth * 0.5f ); + imageNext.SetOpacity( 0.6f ); + controlsLayer.Add( imageNext ); + imageNext.SetName( NEXT_BUTTON_ID ); + imageNext.TouchedSignal().Connect( this, &ImageScalingAndFilteringController::OnControlTouched ); + + // Buttons to popup selectors for fitting and sampling modes: + + // Wrapper table to hold two buttons side by side: + Toolkit::TableView modesGroupBackground = Toolkit::TableView::New( 1, 2 ); + modesGroupBackground.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); + modesGroupBackground.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); + modesGroupBackground.SetBackgroundColor( BACKGROUND_COLOUR ); + modesGroupBackground.SetCellPadding( Size( MARGIN_SIZE * 0.5f, MARGIN_SIZE ) ); + modesGroupBackground.SetFitHeight( 0 ); + + modesGroupBackground.SetAnchorPoint( AnchorPoint::BOTTOM_LEFT ); + modesGroupBackground.SetParentOrigin( ParentOrigin::BOTTOM_LEFT ); + modesGroupBackground.SetPosition( 0.0f, 0.0f ); + + controlsLayer.Add( modesGroupBackground ); + + { + // Vertical table to hold label and button: + Toolkit::TableView fittingModeGroup = Toolkit::TableView::New( 2, 1 ); + fittingModeGroup.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); + fittingModeGroup.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); + fittingModeGroup.SetBackgroundColor( BACKGROUND_COLOUR ); + fittingModeGroup.SetCellPadding( Size( MARGIN_SIZE * 0.5f, MARGIN_SIZE * 0.5f ) ); + fittingModeGroup.SetFitHeight( 0 ); + fittingModeGroup.SetFitHeight( 1 ); + + TextLabel label = TextLabel::New( "Image fitting mode:" ); + label.SetProperty( Toolkit::Control::Property::STYLE_NAME, STYLE_LABEL_TEXT ); + fittingModeGroup.Add( label ); + + Toolkit::PushButton button = CreateButton( FITTING_BUTTON_ID, StringFromScalingMode( mFittingMode ) ); + button.GetLabel().SetProperty( Toolkit::Control::Property::STYLE_NAME, STYLE_BUTTON_TEXT ); + fittingModeGroup.Add( button ); + mFittingModeButton = button; + + modesGroupBackground.Add( fittingModeGroup ); + } + + { + // Vertical table to hold label and button: + Toolkit::TableView samplingModeGroup = Toolkit::TableView::New( 2, 1 ); + samplingModeGroup.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); + samplingModeGroup.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); + samplingModeGroup.SetBackgroundColor( BACKGROUND_COLOUR ); + samplingModeGroup.SetCellPadding( Size( MARGIN_SIZE * 0.5f, MARGIN_SIZE * 0.5f ) ); + samplingModeGroup.SetFitHeight( 0 ); + samplingModeGroup.SetFitHeight( 1 ); + + TextLabel label = TextLabel::New( "Image sampling mode:" ); + label.SetProperty( Toolkit::Control::Property::STYLE_NAME, STYLE_LABEL_TEXT ); + samplingModeGroup.Add( label ); + + Toolkit::PushButton button = CreateButton( SAMPLING_BUTTON_ID, StringFromFilterMode( mSamplingMode ) ); + button.GetLabel().SetProperty( Toolkit::Control::Property::STYLE_NAME, STYLE_BUTTON_TEXT ); + samplingModeGroup.Add( button ); + mSamplingModeButton = button; + + modesGroupBackground.Add( samplingModeGroup ); + } + } + + Toolkit::PushButton CreateButton( const char * id, const char * label ) + { + Toolkit::PushButton button = Toolkit::PushButton::New(); + button.SetProperty( Toolkit::Control::Property::STYLE_NAME, STYLE_BUTTON_TEXT ); + button.SetName( id ); + button.SetLabel( label ); + button.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); + button.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); + button.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) ); + button.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) ); + button.SetDisabledImage( Dali::ResourceImage::New( PUSHBUTTON_DISABLED_IMAGE ) ); + button.ClickedSignal().Connect( this, &ImageScalingAndFilteringController::OnButtonClicked ); + return button; + } + + Toolkit::Popup CreatePopup() + { + Stage stage = Stage::GetCurrent(); + const float POPUP_WIDTH_DP = stage.GetSize().width * 0.75f; + + Toolkit::Popup popup = Toolkit::Popup::New(); + popup.SetName( "POPUP" ); + popup.SetParentOrigin( ParentOrigin::CENTER ); + popup.SetAnchorPoint( AnchorPoint::CENTER ); + popup.SetSize( POPUP_WIDTH_DP, 0.0f ); + popup.HideTail(); + + popup.OutsideTouchedSignal().Connect( this, &ImageScalingAndFilteringController::OnPopupOutsideTouched ); + + return popup; + } + + //void CreatePopupButton( Toolkit::Popup popup, const char* id ) + Toolkit::PushButton CreatePopupButton( Actor parent, const char* id ) + { + Toolkit::PushButton button = Toolkit::PushButton::New(); + button.SetName( id ); + button.SetLabel( id ); + button.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) ); + button.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) ); + Toolkit::TextLabel textLabel = Toolkit::TextLabel::DownCast( button.GetLabel() ); + textLabel.SetProperty( TextLabel::Property::POINT_SIZE, 12.0f ); + + button.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + button.SetParentOrigin( ParentOrigin::BOTTOM_LEFT ); + button.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); + button.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); + + button.ClickedSignal().Connect( this, &ImageScalingAndFilteringController::OnButtonClicked ); + + parent.Add( button ); + return button; + } + + bool OnButtonClicked( Toolkit::Button button ) + { + if( button.GetName() == FITTING_BUTTON_ID ) + { + mPopup = CreatePopup(); + + // Four-row table to hold buttons: + Toolkit::TableView fittingModes = Toolkit::TableView::New( 4, 1 ); + fittingModes.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); + fittingModes.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); + fittingModes.SetBackgroundColor( BACKGROUND_COLOUR ); + fittingModes.SetCellPadding( Size( MARGIN_SIZE, MARGIN_SIZE * 0.5 ) ); + fittingModes.SetFitHeight( 0 ); + fittingModes.SetFitHeight( 1 ); + fittingModes.SetFitHeight( 2 ); + fittingModes.SetFitHeight( 3 ); + + CreatePopupButton( fittingModes, StringFromScalingMode( FittingMode::SCALE_TO_FILL ) ); + CreatePopupButton( fittingModes, StringFromScalingMode( FittingMode::SHRINK_TO_FIT ) ); + CreatePopupButton( fittingModes, StringFromScalingMode( FittingMode::FIT_WIDTH ) ); + CreatePopupButton( fittingModes, StringFromScalingMode( FittingMode::FIT_HEIGHT ) ); + + mPopup.Add( fittingModes ); + mPopup.Show(); + } + else if( button.GetName() == SAMPLING_BUTTON_ID ) + { + mPopup = CreatePopup(); + + // Table to hold buttons for each sampling mode: + Toolkit::TableView samplingModes = Toolkit::TableView::New( 6, 1 ); + samplingModes.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); + samplingModes.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); + samplingModes.SetBackgroundColor( BACKGROUND_COLOUR ); + samplingModes.SetCellPadding( Size( MARGIN_SIZE, MARGIN_SIZE * 0.5 ) ); + samplingModes.SetFitHeight( 0 ); + samplingModes.SetFitHeight( 1 ); + samplingModes.SetFitHeight( 2 ); + samplingModes.SetFitHeight( 3 ); + samplingModes.SetFitHeight( 4 ); + samplingModes.SetFitHeight( 5 ); + + CreatePopupButton( samplingModes, StringFromFilterMode( SamplingMode::NEAREST ) ); + CreatePopupButton( samplingModes, StringFromFilterMode( SamplingMode::LINEAR ) ); + CreatePopupButton( samplingModes, StringFromFilterMode( SamplingMode::BOX ) ); + CreatePopupButton( samplingModes, StringFromFilterMode( SamplingMode::BOX_THEN_NEAREST ) ); + CreatePopupButton( samplingModes, StringFromFilterMode( SamplingMode::BOX_THEN_LINEAR ) ); + CreatePopupButton( samplingModes, StringFromFilterMode( SamplingMode::NO_FILTER ) ); + + mPopup.Add( samplingModes ); + mPopup.Show(); + } + else if( CheckFittingModeButton( button, FittingMode::SCALE_TO_FILL) || + CheckFittingModeButton( button, FittingMode::SHRINK_TO_FIT) || + CheckFittingModeButton( button, FittingMode::FIT_WIDTH) || + CheckFittingModeButton( button, FittingMode::FIT_HEIGHT) ) + { + } + else if( CheckSamplingModeButton( button, SamplingMode::NEAREST ) || + CheckSamplingModeButton( button, SamplingMode::LINEAR ) || + CheckSamplingModeButton( button, SamplingMode::BOX ) || + CheckSamplingModeButton( button, SamplingMode::LINEAR ) || + CheckSamplingModeButton( button, SamplingMode::BOX_THEN_NEAREST ) || + CheckSamplingModeButton( button, SamplingMode::BOX_THEN_LINEAR ) || + CheckSamplingModeButton( button, SamplingMode::NO_FILTER ) ) + { + } + return true; + } + + bool CheckFittingModeButton( Actor &button, FittingMode::Type mode ) + { + const char * const modeName = StringFromScalingMode( mode ); + if( button.GetName() == modeName ) + { + mFittingMode = mode; + mFittingModeButton.SetLabel( modeName ); + mFittingModeButton.GetLabel().SetProperty( Toolkit::Control::Property::STYLE_NAME, STYLE_BUTTON_TEXT ); + ResizeImage(); + mPopup.Hide(); + mPopup.Reset(); + return true; + } + return false; + } + + bool CheckSamplingModeButton( Actor &button, SamplingMode::Type mode ) + { + const char * const modeName = StringFromFilterMode( mode ); + if( button.GetName() == modeName ) + { + mSamplingMode = mode; + mSamplingModeButton.SetLabel( modeName ); + mSamplingModeButton.GetLabel().SetProperty( Toolkit::Control::Property::STYLE_NAME, STYLE_BUTTON_TEXT ); + ResizeImage(); + mPopup.Hide(); + mPopup.Reset(); + return true; + } + return false; + } + + void OnPopupOutsideTouched() + { + if( mPopup ) + { + mPopup.Hide(); + mPopup.Reset(); + } + } + + void OnImageLoaded( ResourceImage image ) + { + DALI_ASSERT_DEBUG( image == mNextImage ); + mImageActor.SetImage( image ); + mImageActor.SetSize( Size( image.GetWidth(), image.GetHeight() ) ); + } + + bool OnControlTouched( Actor actor, const TouchEvent& event ) + { + if(event.GetPointCount() > 0) + { + const TouchPoint& point = event.GetPoint(0); + switch(point.state) + { + case TouchPoint::Up: + { + const std::string & name = actor.GetName(); + if( name == NEXT_BUTTON_ID ) + { + mCurrentPath = mCurrentPath + 1; + mCurrentPath = mCurrentPath < NUM_IMAGE_PATHS ? mCurrentPath : 0; + ResizeImage(); + } + else if( name == PREVIOUS_BUTTON_ID ) + { + mCurrentPath = mCurrentPath - 1; + mCurrentPath = mCurrentPath >= 0 ? mCurrentPath : NUM_IMAGE_PATHS - 1; + ResizeImage(); + } + break; + } + default: + { + break; + } + } // end switch + } + + return false; + } + + void OnPinch( Actor actor, const PinchGesture& pinch ) + { + if( pinch.state == Gesture::Started ) + { + mLastPinchScale = pinch.scale; + } + const float scale = pinch.scale; + + if( scale != mLastPinchScale ) + { + if ( scale < mLastPinchScale ) + { + mImageStageScale.x = std::max( 0.05f, mImageStageScale.x * 0.9f ); + mImageStageScale.y = std::max( 0.05f, mImageStageScale.y * 0.9f ); + } + else + { + mImageStageScale.x = std::max( 0.05f, std::min( 1.0f, mImageStageScale.x * 1.1f ) ); + mImageStageScale.y = std::max( 0.05f, std::min( 1.0f, mImageStageScale.y * 1.1f ) ); + } + ResizeImage(); + } + mLastPinchScale = scale; + } + + void OnPan( Actor actor, const PanGesture& gesture ) + { + Stage stage = Stage::GetCurrent(); + mImageStageScale.x = std::max( 0.05f, std::min( 1.0f, mImageStageScale.x + (gesture.displacement.x * 2.0f / stage.GetSize().width ) ) ); + mImageStageScale.y = std::max( 0.05f, std::min( 1.0f, mImageStageScale.y + (gesture.displacement.y * 2.0f / stage.GetSize().height ) ) ); + ResizeImage(); + } + + void OnKeyEvent(const KeyEvent& event) + { + if( event.state == KeyEvent::Down ) + { + if( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + { + if( mPopup && mPopup.IsVisible() ) + { + mPopup.Hide(); + mPopup.Reset(); + } + else + { + mApplication.Quit(); + } + } + else if ( event.keyPressedName == "Right" ) + { + mImageStageScale.x = std::max( 0.05f, std::min( 1.0f, mImageStageScale.x * 1.1f ) ); + } + else if ( event.keyPressedName == "Left" ) + { + mImageStageScale.x = std::max( 0.05f, mImageStageScale.x * 0.9f ); + } + else if ( event.keyPressedName == "Up" ) + { + mImageStageScale.y = std::max( 0.05f, std::min( 1.0f, mImageStageScale.y * 1.1f ) ); + } + else if ( event.keyPressedName == "Down" ) + { + mImageStageScale.y = std::max( 0.05f, mImageStageScale.y * 0.9f ); + } + else if ( event.keyPressedName == "o" ) + { + mImageStageScale.x = std::max( 0.05f, mImageStageScale.x * 0.9f ); + mImageStageScale.y = std::max( 0.05f, mImageStageScale.y * 0.9f ); + } + else if ( event.keyPressedName == "p" ) + { + mImageStageScale.x = std::max( 0.05f, std::min( 1.0f, mImageStageScale.x * 1.1f ) ); + mImageStageScale.y = std::max( 0.05f, std::min( 1.0f, mImageStageScale.y * 1.1f ) ); + } + else if ( event.keyPressedName == "n" ) + { + mCurrentPath = mCurrentPath + 1; + mCurrentPath = mCurrentPath < NUM_IMAGE_PATHS ? mCurrentPath : 0; + } + else if ( event.keyPressedName == "b" ) + { + mCurrentPath = mCurrentPath - 1; + mCurrentPath = mCurrentPath >= 0 ? mCurrentPath : NUM_IMAGE_PATHS - 1; + } + // Cycle filter and scaling modes: + else if ( event.keyPressedName == "f" ) + { + mSamplingMode = NextFilterMode( mSamplingMode ); + mSamplingModeButton.SetLabel( StringFromFilterMode( mSamplingMode ) ); + mSamplingModeButton.GetLabel().SetProperty( Toolkit::Control::Property::STYLE_NAME, STYLE_BUTTON_TEXT ); + } + // Cycle filter and scaling modes: + else if ( event.keyPressedName == "s" ) + { + mFittingMode = NextScalingMode( mFittingMode ); + mFittingModeButton.SetLabel( StringFromScalingMode( mFittingMode ) ); + mFittingModeButton.GetLabel().SetProperty( Toolkit::Control::Property::STYLE_NAME, STYLE_BUTTON_TEXT ); + } + else + { + return; + } + + ResizeImage(); + } + } + +private: + void ResizeImage() + { + const char * const path = IMAGE_PATHS[mCurrentPath]; + + Stage stage = Stage::GetCurrent(); + Size imageSize = stage.GetSize() * mImageStageScale; + const ImageDimensions imageSizeInt = ImageDimensions::FromFloatArray( &imageSize.x ); + + ResourceImage image = ResourceImage::New( path, imageSizeInt, mFittingMode, mSamplingMode ); + image.LoadingFinishedSignal().Connect( this, &ImageScalingAndFilteringController::OnImageLoaded ); + + mNextImage = image; + + mDesiredBox.SetSize( stage.GetSize() * mImageStageScale ); + mHeightBox.SetSize( stage.GetSize().width, (stage.GetSize() * mImageStageScale).height ); + mWidthBox.SetSize( (stage.GetSize() * mImageStageScale).width, stage.GetSize().height ); + } + +private: + Application& mApplication; + Actor mDesiredBox; //< Background rectangle to show requested image size. + Actor mHeightBox; //< Background horizontal stripe to show requested image height. + Actor mWidthBox; //< Background vertical stripe to show requested image width. + Toolkit::PushButton mFittingModeButton; + Toolkit::PushButton mSamplingModeButton; + Toolkit::Popup mPopup; + PinchGestureDetector mPinchDetector; + float mLastPinchScale; + Toolkit::PushButton mGrabCorner; + PanGestureDetector mPanGestureDetector; + ImageActor mImageActor; + ResourceImage mNextImage; //< Currently-loading image + Vector2 mImageStageScale; + int mCurrentPath; + FittingMode::Type mFittingMode; + SamplingMode::Type mSamplingMode; +}; + +void RunTest( Application& application ) +{ + ImageScalingAndFilteringController test( application ); + + application.MainLoop(); +} + +// Entry point for Linux & Tizen applications +int main( int argc, char **argv ) +{ + Application application = Application::New( &argc, &argv ); + + RunTest( application ); + + return 0; +} diff --git a/examples/image-scaling-irregular-grid/image-scaling-irregular-grid-example.cpp b/examples/image-scaling-irregular-grid/image-scaling-irregular-grid-example.cpp index d0772a3..d921645 100644 --- a/examples/image-scaling-irregular-grid/image-scaling-irregular-grid-example.cpp +++ b/examples/image-scaling-irregular-grid/image-scaling-irregular-grid-example.cpp @@ -465,7 +465,7 @@ public: { // Spin the image a few times: Animation animation = Animation::New(SPIN_DURATION); - animation.AnimateBy( Property( actor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(360.0f * SPIN_DURATION) ), Vector3::XAXIS ), AlphaFunctions::EaseOut ); + animation.AnimateBy( Property( actor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(360.0f * SPIN_DURATION) ), Vector3::XAXIS ), AlphaFunction::EASE_OUT ); animation.Play(); // Change the scaling mode: @@ -568,7 +568,7 @@ private: Application& mApplication; Layer mContentLayer; ///< The content layer (contains non gui chrome actors) - Toolkit::View mView; ///< The View instance. + Toolkit::Control mView; ///< The View instance. Toolkit::ToolBar mToolBar; ///< The View's Toolbar. TextLabel mTitleActor; ///< The Toolbar's Title. Actor mGridActor; ///< The container for the grid of images diff --git a/examples/item-view/item-view-example.cpp b/examples/item-view/item-view-example.cpp index 9bfbac8..6a0a6e2 100644 --- a/examples/item-view/item-view-example.cpp +++ b/examples/item-view/item-view-example.cpp @@ -103,9 +103,9 @@ const unsigned int IMAGE_WIDTH = 256; const unsigned int IMAGE_HEIGHT = 256; const unsigned int NUM_IMAGE_PER_ROW_IN_ATLAS = 8; -AlphaFunction ALPHA_FUNCTIONS[] = { AlphaFunctions::Linear, - AlphaFunctions::EaseIn, - AlphaFunctions::EaseOut }; +AlphaFunction ALPHA_FUNCTIONS[] = { AlphaFunction(AlphaFunction::LINEAR), + AlphaFunction(AlphaFunction::EASE_IN), + AlphaFunction(AlphaFunction::EASE_OUT) }; const unsigned int NUM_ALPHA_FUNCTIONS = sizeof(ALPHA_FUNCTIONS) / sizeof(AlphaFunction); @@ -253,7 +253,7 @@ public: TOOLBAR_IMAGE, "" ); - mView.OrientationAnimationStartedSignal().Connect( this, &ItemViewExample::OnOrientationChanged ); + app.GetWindow().GetOrientation().ChangedSignal().Connect( this, &ItemViewExample::OnOrientationChanged ); // Create an edit mode button. (left of toolbar) Toolkit::PushButton editButton = Toolkit::PushButton::New(); @@ -414,7 +414,7 @@ public: * Orientation changed signal callback * @param orientation */ - void OnOrientationChanged( View view, Animation& animation, const Orientation& orientation ) + void OnOrientationChanged( Orientation orientation ) { const unsigned int angle = orientation.GetDegrees(); @@ -1105,7 +1105,7 @@ private: Mode mMode; bool mMenuShown; - Toolkit::View mView; + Toolkit::Control mView; unsigned int mOrientation; Toolkit::ToolBar mToolBar; diff --git a/examples/logging/logging-example.cpp b/examples/logging/logging-example.cpp index 2abc12b..a37fcb4 100644 --- a/examples/logging/logging-example.cpp +++ b/examples/logging/logging-example.cpp @@ -700,7 +700,7 @@ class LoggingController: public ConnectionTracker { if( mAnimation ) { - mAnimation.AnimateBy( Property(actor, Actor::Property::POSITION), Vector3( 0.f, localPoint - mLastPoint, 0.f ), AlphaFunctions::Linear ); + mAnimation.AnimateBy( Property(actor, Actor::Property::POSITION), Vector3( 0.f, localPoint - mLastPoint, 0.f ), AlphaFunction::LINEAR ); mAnimation.Play(); mLastPoint = localPoint; } @@ -722,7 +722,7 @@ class LoggingController: public ConnectionTracker }; Application& mApplication; - Toolkit::View mView; ///< The View instance. + Toolkit::Control mView; ///< The View instance. Toolkit::ToolBar mToolBar; ///< The View's Toolbar. Layer mContentLayer; ///< Content layer diff --git a/examples/magnifier/magnifier-example.cpp b/examples/magnifier/magnifier-example.cpp index 791935d..08c107e 100644 --- a/examples/magnifier/magnifier-example.cpp +++ b/examples/magnifier/magnifier-example.cpp @@ -225,7 +225,7 @@ public: Stage::GetCurrent().Add(overlay); mMagnifier = Toolkit::Magnifier::New(); - mMagnifier.SetSourceActor( mView.GetBackgroundLayer() ); + mMagnifier.SetSourceActor( mView.GetChildAt( 0 ) ); mMagnifier.SetSize( MAGNIFIER_SIZE * mStageSize.width ); // Size of magnifier is in relation to stage width mMagnifier.SetMagnificationFactor( MAGNIFICATION_FACTOR ); mMagnifier.SetScale(Vector3::ZERO); @@ -242,7 +242,7 @@ public: // Create bouncing magnifier automatically bounces around screen. mBouncingMagnifier = Toolkit::Magnifier::New(); - mBouncingMagnifier.SetSourceActor( mView.GetBackgroundLayer() ); + mBouncingMagnifier.SetSourceActor( mView.GetChildAt( 0 ) ); mBouncingMagnifier.SetSize( MAGNIFIER_SIZE * mStageSize.width ); // Size of magnifier is in relation to stage width mBouncingMagnifier.SetMagnificationFactor( MAGNIFICATION_FACTOR ); overlay.Add( mBouncingMagnifier ); @@ -344,7 +344,7 @@ public: if(!mMagnifierShown) { Animation animation = Animation::New(MAGNIFIER_DISPLAY_DURATION); - animation.AnimateTo(Property(mMagnifier, Actor::Property::SCALE), Vector3::ONE, AlphaFunctions::EaseIn); + animation.AnimateTo(Property(mMagnifier, Actor::Property::SCALE), Vector3::ONE, AlphaFunction::EASE_IN); animation.Play(); mMagnifierShown = true; } @@ -358,7 +358,7 @@ public: if(mMagnifierShown) { Animation animation = Animation::New(MAGNIFIER_DISPLAY_DURATION); - animation.AnimateTo(Property(mMagnifier, Actor::Property::SCALE), Vector3::ZERO, AlphaFunctions::EaseOut); + animation.AnimateTo(Property(mMagnifier, Actor::Property::SCALE), Vector3::ZERO, AlphaFunction::EASE_OUT); animation.Play(); mMagnifierShown = false; } @@ -393,7 +393,7 @@ public: private: Application& mApplication; ///< Application instance - Toolkit::View mView; ///< The view + Toolkit::Control mView; ///< The view Layer mContent; ///< The content layer Toolkit::Magnifier mMagnifier; ///< The manually controlled magnifier Toolkit::Magnifier mBouncingMagnifier; ///< The animating magnifier (swirly animation) diff --git a/examples/motion-blur/motion-blur-example.cpp b/examples/motion-blur/motion-blur-example.cpp index c35f474..ccc056c 100644 --- a/examples/motion-blur/motion-blur-example.cpp +++ b/examples/motion-blur/motion-blur-example.cpp @@ -322,7 +322,7 @@ public: { // has parent so we expect it to be on stage, start animation mRotateAnimation = Animation::New( ORIENTATION_DURATION ); - mRotateAnimation.AnimateTo( Property( mView, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree( -orientation ) ), Vector3::ZAXIS ), AlphaFunctions::EaseOut ); + mRotateAnimation.AnimateTo( Property( mView, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree( -orientation ) ), Vector3::ZAXIS ), AlphaFunction::EASE_OUT ); mRotateAnimation.AnimateTo( Property( mView, Actor::Property::SIZE_WIDTH ), targetSize.width ); mRotateAnimation.AnimateTo( Property( mView, Actor::Property::SIZE_HEIGHT ), targetSize.height ); mRotateAnimation.Play(); @@ -367,7 +367,7 @@ public: mActorTapMovementAnimation = Animation::New( animDuration ); if ( mMotionBlurImageActor ) { - mActorTapMovementAnimation.AnimateTo( Property(mMotionBlurImageActor, Actor::Property::POSITION), destPos, AlphaFunctions::EaseInOutSine, TimePeriod(animDuration) ); + mActorTapMovementAnimation.AnimateTo( Property(mMotionBlurImageActor, Actor::Property::POSITION), destPos, AlphaFunction::EASE_IN_OUT_SINE, TimePeriod(animDuration) ); } mActorTapMovementAnimation.SetEndAction( Animation::Bake ); mActorTapMovementAnimation.Play(); @@ -383,7 +383,7 @@ public: { float animDuration = 1.0f; mActorAnimation = Animation::New(animDuration); - mActorAnimation.AnimateBy( Property( mMotionBlurImageActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(360.0f) ), Vector3::YAXIS ), AlphaFunctions::EaseInOut ); + mActorAnimation.AnimateBy( Property( mMotionBlurImageActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(360.0f) ), Vector3::YAXIS ), AlphaFunction::EASE_IN_OUT ); mActorAnimation.SetEndAction( Animation::Bake ); mActorAnimation.Play(); } @@ -394,7 +394,7 @@ public: { float animDuration = 1.0f; mActorAnimation = Animation::New(animDuration); - mActorAnimation.AnimateBy( Property( mMotionBlurImageActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(360.0f) ), Vector3::ZAXIS ), AlphaFunctions::EaseInOut ); + mActorAnimation.AnimateBy( Property( mMotionBlurImageActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(360.0f) ), Vector3::ZAXIS ), AlphaFunction::EASE_IN_OUT ); mActorAnimation.SetEndAction( Animation::Bake ); mActorAnimation.Play(); } @@ -405,8 +405,8 @@ public: { float animDuration = 1.0f; mActorAnimation = Animation::New(animDuration); - mActorAnimation.AnimateBy( Property( mMotionBlurImageActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(360.0f) ), Vector3::YAXIS ), AlphaFunctions::EaseInOut ); - mActorAnimation.AnimateBy( Property( mMotionBlurImageActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(360.0f) ), Vector3::ZAXIS ), AlphaFunctions::EaseInOut ); + mActorAnimation.AnimateBy( Property( mMotionBlurImageActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(360.0f) ), Vector3::YAXIS ), AlphaFunction::EASE_IN_OUT ); + mActorAnimation.AnimateBy( Property( mMotionBlurImageActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(360.0f) ), Vector3::ZAXIS ), AlphaFunction::EASE_IN_OUT ); mActorAnimation.SetEndAction( Animation::Bake ); mActorAnimation.Play(); } @@ -417,7 +417,7 @@ public: { float animDuration = 1.0f; mActorAnimation = Animation::New(animDuration); - mActorAnimation.AnimateBy( Property( mMotionBlurImageActor, Actor::Property::SCALE ), Vector3(2.0f, 2.0f, 2.0f), AlphaFunctions::Bounce, TimePeriod( 0.0f, 1.0f ) ); + mActorAnimation.AnimateBy( Property( mMotionBlurImageActor, Actor::Property::SCALE ), Vector3(2.0f, 2.0f, 2.0f), AlphaFunction::BOUNCE, TimePeriod( 0.0f, 1.0f ) ); mActorAnimation.SetEndAction( Animation::Bake ); mActorAnimation.Play(); } @@ -503,7 +503,7 @@ public: private: Application& mApplication; ///< Application instance - Toolkit::View mView; + Toolkit::Control mView; Toolkit::ToolBar mToolBar; Image mIconEffectsOff; Image mIconEffectsOn; diff --git a/examples/motion-stretch/motion-stretch-example.cpp b/examples/motion-stretch/motion-stretch-example.cpp index ff61118..b9c4a75 100644 --- a/examples/motion-stretch/motion-stretch-example.cpp +++ b/examples/motion-stretch/motion-stretch-example.cpp @@ -220,7 +220,7 @@ public: { // has parent so we expect it to be on stage, start animation mRotateAnimation = Animation::New( ORIENTATION_DURATION ); - mRotateAnimation.AnimateTo( Property( mView, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree( -orientation ) ), Vector3::ZAXIS ), AlphaFunctions::EaseOut ); + mRotateAnimation.AnimateTo( Property( mView, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree( -orientation ) ), Vector3::ZAXIS ), AlphaFunction::EASE_OUT ); mRotateAnimation.AnimateTo( Property( mView, Actor::Property::SIZE_WIDTH ), targetSize.width ); mRotateAnimation.AnimateTo( Property( mView, Actor::Property::SIZE_HEIGHT ), targetSize.height ); mRotateAnimation.Play(); @@ -264,7 +264,7 @@ public: mActorTapMovementAnimation = Animation::New( animDuration ); if ( mMotionStretchImageActor ) { - mActorTapMovementAnimation.AnimateTo( Property(mMotionStretchImageActor, Actor::Property::POSITION), destPos, AlphaFunctions::EaseInOutSine, TimePeriod(animDuration) ); + mActorTapMovementAnimation.AnimateTo( Property(mMotionStretchImageActor, Actor::Property::POSITION), destPos, AlphaFunction::EASE_IN_OUT_SINE, TimePeriod(animDuration) ); } mActorTapMovementAnimation.SetEndAction( Animation::Bake ); mActorTapMovementAnimation.Play(); @@ -280,7 +280,7 @@ public: { float animDuration = 1.0f; mActorAnimation = Animation::New(animDuration); - mActorAnimation.AnimateBy( Property( mMotionStretchImageActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(360.0f) ), Vector3::YAXIS ), AlphaFunctions::EaseInOut ); + mActorAnimation.AnimateBy( Property( mMotionStretchImageActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(360.0f) ), Vector3::YAXIS ), AlphaFunction::EASE_IN_OUT ); mActorAnimation.SetEndAction( Animation::Bake ); mActorAnimation.Play(); } @@ -291,7 +291,7 @@ public: { float animDuration = 1.0f; mActorAnimation = Animation::New(animDuration); - mActorAnimation.AnimateBy( Property( mMotionStretchImageActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(360.0f) ), Vector3::ZAXIS ), AlphaFunctions::EaseInOut ); + mActorAnimation.AnimateBy( Property( mMotionStretchImageActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(360.0f) ), Vector3::ZAXIS ), AlphaFunction::EASE_IN_OUT ); mActorAnimation.SetEndAction( Animation::Bake ); mActorAnimation.Play(); } @@ -302,8 +302,8 @@ public: { float animDuration = 1.0f; mActorAnimation = Animation::New(animDuration); - mActorAnimation.AnimateBy( Property( mMotionStretchImageActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(360.0f) ), Vector3::YAXIS ), AlphaFunctions::EaseInOut ); - mActorAnimation.AnimateBy( Property( mMotionStretchImageActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(360.0f) ), Vector3::ZAXIS ), AlphaFunctions::EaseInOut ); + mActorAnimation.AnimateBy( Property( mMotionStretchImageActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(360.0f) ), Vector3::YAXIS ), AlphaFunction::EASE_IN_OUT ); + mActorAnimation.AnimateBy( Property( mMotionStretchImageActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(360.0f) ), Vector3::ZAXIS ), AlphaFunction::EASE_IN_OUT ); mActorAnimation.SetEndAction( Animation::Bake ); mActorAnimation.Play(); } @@ -314,7 +314,7 @@ public: { float animDuration = 1.0f; mActorAnimation = Animation::New(animDuration); - mActorAnimation.AnimateBy( Property( mMotionStretchImageActor, Actor::Property::SCALE ), Vector3(2.0f, 2.0f, 2.0f), AlphaFunctions::Bounce, TimePeriod( 0.0f, 1.0f ) ); + mActorAnimation.AnimateBy( Property( mMotionStretchImageActor, Actor::Property::SCALE ), Vector3(2.0f, 2.0f, 2.0f), AlphaFunction::BOUNCE, TimePeriod( 0.0f, 1.0f ) ); mActorAnimation.SetEndAction( Animation::Bake ); mActorAnimation.Play(); } @@ -400,7 +400,7 @@ public: private: Application& mApplication; ///< Application instance - Toolkit::View mView; + Toolkit::Control mView; Toolkit::ToolBar mToolBar; Image mIconEffectsOff; Image mIconEffectsOn; diff --git a/examples/new-window/new-window-example.cpp b/examples/new-window/new-window-example.cpp index 1f918f0..3533cd2 100644 --- a/examples/new-window/new-window-example.cpp +++ b/examples/new-window/new-window-example.cpp @@ -88,7 +88,7 @@ private: MeshActor mMeshActor; MeshActor mAnimatedMeshActor; - Toolkit::View mView; ///< The View instance. + Toolkit::Control mView; ///< The View instance. Toolkit::ToolBar mToolBar; ///< The View's Toolbar. TextLabel mTitleActor; ///< The Toolbar's Title. Layer mContentLayer; ///< Content layer (scrolling cluster content) diff --git a/examples/page-turn-view/page-turn-view-example.cpp b/examples/page-turn-view/page-turn-view-example.cpp index a57b9f4..3596034 100644 --- a/examples/page-turn-view/page-turn-view-example.cpp +++ b/examples/page-turn-view/page-turn-view-example.cpp @@ -152,11 +152,9 @@ private: /** * This method gets called when the screen is rotated, switch between portrait and landscape views - * param [in] view The view receiving the orientation change signal - * param [in] animation The Orientation Rotating animation * param [in] orientation The current screen orientation */ - void OnOrientationAnimationStarted( View view, Animation& animation, const Orientation& orientation ); + void OnOrientationAnimationStarted( Orientation orientation ); /** * Main key event handler @@ -196,7 +194,7 @@ private: private: Application& mApplication; - View mView; + Actor mView; PageTurnView mPageTurnPortraitView; PageTurnView mPageTurnLandscapeView; @@ -231,7 +229,10 @@ void PageTurnController::OnInit( Application& app ) Vector2 stageSize = stage.GetSize(); // Create default View. - mView = View::New(); + mView = Actor::New(); + mView.SetAnchorPoint( Dali::AnchorPoint::CENTER ); + mView.SetParentOrigin( Dali::ParentOrigin::CENTER ); + mView.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); stage.Add( mView ); Dali::Window winHandle = app.GetWindow(); @@ -239,10 +240,9 @@ void PageTurnController::OnInit( Application& app ) winHandle.AddAvailableOrientation( Dali::Window::LANDSCAPE ); winHandle.AddAvailableOrientation( Dali::Window::PORTRAIT_INVERSE ); winHandle.AddAvailableOrientation( Dali::Window::LANDSCAPE_INVERSE ); - // FIXME - //app.GetOrientation().ChangedSignal().Connect( &mView, &View::OrientationChanged ); + // view will response to orientation change to display portrait or landscape views - mView.OrientationAnimationStartedSignal().Connect( this, &PageTurnController::OnOrientationAnimationStarted ); + app.GetWindow().GetOrientation().ChangedSignal().Connect( this, &PageTurnController::OnOrientationAnimationStarted ); mPageTurnPortraitView = PageTurnPortraitView::New( mPortraitPageFactory, stageSize ); mPageTurnPortraitView.SetSpineShadowParameter( Vector2(70.f, 30.f) ); @@ -262,7 +262,7 @@ void PageTurnController::OnInit( Application& app ) mView.Add(mPageTurnPortraitView); } -void PageTurnController::OnOrientationAnimationStarted( View view, Animation& animation, const Orientation& orientation ) +void PageTurnController::OnOrientationAnimationStarted( Orientation orientation ) { switch( orientation.GetDegrees() ) { diff --git a/examples/path-animation/path-animation.cpp b/examples/path-animation/path-animation.cpp index 5566cc9..06b3cf0 100644 --- a/examples/path-animation/path-animation.cpp +++ b/examples/path-animation/path-animation.cpp @@ -444,7 +444,7 @@ public: stage.KeyEventSignal().Connect(this, &PathController::OnKeyEvent); // Create a default view with a default tool bar: - Toolkit::View view; ///< The View instance. + Toolkit::Control view; ///< The View instance. Toolkit::ToolBar toolBar; ///< The View's Toolbar. mContentLayer = DemoHelper::CreateView( mApplication, view, diff --git a/examples/radial-menu/radial-menu-example.cpp b/examples/radial-menu/radial-menu-example.cpp index 278dddc..c98a6ef 100644 --- a/examples/radial-menu/radial-menu-example.cpp +++ b/examples/radial-menu/radial-menu-example.cpp @@ -91,7 +91,7 @@ private: // Member variables }; Application mApplication; ///< The application handle - Toolkit::View mView; ///< The toolbar view + Toolkit::Control mView; ///< The toolbar view Layer mContents; ///< The toolbar contents pane ImageActor mImageActor; ///< Image actor shown by stencil mask Animation mAnimation; @@ -194,8 +194,8 @@ void RadialMenuExample::StartAnimation() mRadialSweepView1.Activate(mAnimation, 0.0f, 3.0f); mRadialSweepView2.Activate(mAnimation, 1.5f, 3.0f); mRadialSweepView3.Activate(mAnimation, 3.0f, 3.0f); - mAnimation.AnimateTo( Property( mDialActor, Actor::Property::COLOR_ALPHA ), 1.0f, AlphaFunctions::EaseIn, TimePeriod( 0.0f, 0.8f ) ); - mAnimation.AnimateTo( Property( mRadialSweepView1, Actor::Property::COLOR_ALPHA ), 1.0f, AlphaFunctions::EaseIn, TimePeriod( 0.0f, 0.5f ) ); + mAnimation.AnimateTo( Property( mDialActor, Actor::Property::COLOR_ALPHA ), 1.0f, AlphaFunction::EASE_IN, TimePeriod( 0.0f, 0.8f ) ); + mAnimation.AnimateTo( Property( mRadialSweepView1, Actor::Property::COLOR_ALPHA ), 1.0f, AlphaFunction::EASE_IN, TimePeriod( 0.0f, 0.5f ) ); mAnimation.FinishedSignal().Connect( this, &RadialMenuExample::OnAnimationFinished ); mAnimationState = PLAYING; @@ -259,7 +259,7 @@ RadialSweepView RadialMenuExample::CreateSweepView( std::string imageName, radialSweepView.SetInitialSector( Degree(0.0f) ); radialSweepView.SetFinalSector( Degree(359.999f) ); radialSweepView.SetSize( Stage::GetCurrent().GetSize()); - radialSweepView.SetEasingFunction( Dali::AlphaFunctions::EaseInOut ); + radialSweepView.SetEasingFunction( Dali::AlphaFunction::EASE_IN_OUT ); radialSweepView.SetPositionInheritanceMode(USE_PARENT_POSITION); mContents.Add(radialSweepView); radialSweepView.Add( mImageActor ); diff --git a/examples/radial-menu/radial-sweep-view-impl.cpp b/examples/radial-menu/radial-sweep-view-impl.cpp index 1062406..44ec95d 100644 --- a/examples/radial-menu/radial-sweep-view-impl.cpp +++ b/examples/radial-menu/radial-sweep-view-impl.cpp @@ -67,11 +67,13 @@ float HoldZeroFastEaseInOutHoldOne(float progress) } else if(progress < 0.5f) { - return AlphaFunctions::EaseIn((progress-0.2) / 0.3f) * 0.5f; + progress = (progress-0.2) / 0.3f; + return progress*progress*progress*0.5f; } else if(progress < 0.8f) { - return AlphaFunctions::EaseOut((progress - 0.5f) / 0.3f) * 0.5f + 0.5f; + progress = ((progress - 0.5f) / 0.3f) - 1.0f; + return (progress*progress*progress+1.0f) * 0.5f + 0.5f; } else { diff --git a/examples/refraction-effect/refraction-effect-example.cpp b/examples/refraction-effect/refraction-effect-example.cpp index dfcf9d8..61bae03 100644 --- a/examples/refraction-effect/refraction-effect-example.cpp +++ b/examples/refraction-effect/refraction-effect-example.cpp @@ -325,7 +325,7 @@ private: // Creates a default view with a default tool bar. // The view is added to the stage. Toolkit::ToolBar toolBar; - Toolkit::View view; + Toolkit::Control view; mContent = DemoHelper::CreateView( application, view, toolBar, diff --git a/examples/scroll-view/scroll-view-example.cpp b/examples/scroll-view/scroll-view-example.cpp index e499377..da7a64b 100644 --- a/examples/scroll-view/scroll-view-example.cpp +++ b/examples/scroll-view/scroll-view-example.cpp @@ -353,8 +353,8 @@ private: mScrollViewEffect = ScrollViewDepthEffect::New(); mScrollView.SetScrollSnapDuration(EFFECT_SNAP_DURATION); mScrollView.SetScrollFlickDuration(EFFECT_FLICK_DURATION); - mScrollView.SetScrollSnapAlphaFunction(AlphaFunctions::EaseOut); - mScrollView.SetScrollFlickAlphaFunction(AlphaFunctions::EaseOut); + mScrollView.SetScrollSnapAlphaFunction(AlphaFunction::EASE_OUT); + mScrollView.SetScrollFlickAlphaFunction(AlphaFunction::EASE_OUT); mScrollView.RemoveConstraintsFromChildren(); break; } @@ -364,8 +364,8 @@ private: mScrollViewEffect = ScrollViewCubeEffect::New(); mScrollView.SetScrollSnapDuration(EFFECT_SNAP_DURATION); mScrollView.SetScrollFlickDuration(EFFECT_FLICK_DURATION); - mScrollView.SetScrollSnapAlphaFunction(AlphaFunctions::EaseOutBack); - mScrollView.SetScrollFlickAlphaFunction(AlphaFunctions::EaseOutBack); + mScrollView.SetScrollSnapAlphaFunction(AlphaFunction::EASE_OUT_BACK); + mScrollView.SetScrollFlickAlphaFunction(AlphaFunction::EASE_OUT_BACK); mScrollView.RemoveConstraintsFromChildren(); break; } @@ -375,8 +375,8 @@ private: mScrollViewEffect = ScrollViewPageCarouselEffect::New(); mScrollView.SetScrollSnapDuration(EFFECT_SNAP_DURATION); mScrollView.SetScrollFlickDuration(EFFECT_FLICK_DURATION); - mScrollView.SetScrollSnapAlphaFunction(AlphaFunctions::EaseOut); - mScrollView.SetScrollFlickAlphaFunction(AlphaFunctions::EaseOut); + mScrollView.SetScrollSnapAlphaFunction(AlphaFunction::EASE_OUT); + mScrollView.SetScrollFlickAlphaFunction(AlphaFunction::EASE_OUT); mScrollView.RemoveConstraintsFromChildren(); break; } @@ -386,8 +386,8 @@ private: mScrollViewEffect = ScrollViewPageCubeEffect::New(); mScrollView.SetScrollSnapDuration(EFFECT_SNAP_DURATION); mScrollView.SetScrollFlickDuration(EFFECT_FLICK_DURATION); - mScrollView.SetScrollSnapAlphaFunction(AlphaFunctions::EaseOut); - mScrollView.SetScrollFlickAlphaFunction(AlphaFunctions::EaseOut); + mScrollView.SetScrollSnapAlphaFunction(AlphaFunction::EASE_OUT); + mScrollView.SetScrollFlickAlphaFunction(AlphaFunction::EASE_OUT); mScrollView.RemoveConstraintsFromChildren(); break; } @@ -397,8 +397,8 @@ private: mScrollViewEffect = ScrollViewPageSpiralEffect::New(); mScrollView.SetScrollSnapDuration(EFFECT_SNAP_DURATION); mScrollView.SetScrollFlickDuration(EFFECT_FLICK_DURATION); - mScrollView.SetScrollSnapAlphaFunction(AlphaFunctions::EaseOut); - mScrollView.SetScrollFlickAlphaFunction(AlphaFunctions::EaseOut); + mScrollView.SetScrollSnapAlphaFunction(AlphaFunction::EASE_OUT); + mScrollView.SetScrollFlickAlphaFunction(AlphaFunction::EASE_OUT); mScrollView.RemoveConstraintsFromChildren(); break; } @@ -607,7 +607,7 @@ private: { // Spin the Image a few times. Animation animation = Animation::New(SPIN_DURATION); - animation.AnimateBy( Property( actor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(360.0f * SPIN_DURATION) ), Vector3::XAXIS ), AlphaFunctions::EaseOut ); + animation.AnimateBy( Property( actor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(360.0f * SPIN_DURATION) ), Vector3::XAXIS ), AlphaFunction::EASE_OUT ); animation.Play(); } } @@ -659,7 +659,7 @@ private: private: Application& mApplication; ///< Application instance - Toolkit::View mView; ///< The View instance. + Toolkit::Control mView; ///< The View instance. Toolkit::ToolBar mToolBar; ///< The View's Toolbar. TextLabel mTitleActor; ///< The Toolbar's Title. Layer mContentLayer; ///< The content layer (contains game actors) diff --git a/examples/shadow-bone-lighting/shadow-bone-lighting-example.cpp b/examples/shadow-bone-lighting/shadow-bone-lighting-example.cpp index 4a3ca8a..7e3a22a 100644 --- a/examples/shadow-bone-lighting/shadow-bone-lighting-example.cpp +++ b/examples/shadow-bone-lighting/shadow-bone-lighting-example.cpp @@ -277,7 +277,7 @@ public: // Want to animate angle from 30 => -30 and back again smoothly. - mSceneAnimation.AnimateTo( Property( mImageActor2, angleIndex ), Property::Value(-Dali::ANGLE_30), AlphaFunctions::Sin ); + mSceneAnimation.AnimateTo( Property( mImageActor2, angleIndex ), Property::Value(-Dali::ANGLE_30), AlphaFunction::SIN ); mSceneAnimation.SetLooping(true); mSceneAnimation.Play(); @@ -444,7 +444,7 @@ public: private: Application& mApp; - Toolkit::View mView; + Toolkit::Control mView; Layer mContents; Actor mSceneActor; Animation mAnimation; diff --git a/examples/size-negotiation/size-negotiation-example.cpp b/examples/size-negotiation/size-negotiation-example.cpp index cae5517..60ee45d 100644 --- a/examples/size-negotiation/size-negotiation-example.cpp +++ b/examples/size-negotiation/size-negotiation-example.cpp @@ -1275,7 +1275,7 @@ private: }; Application& mApplication; - Toolkit::View mView; ///< The View instance. + Toolkit::Control mView; ///< The View instance. Toolkit::ToolBar mToolBar; ///< The View's Toolbar. Layer mContentLayer; ///< Content layer diff --git a/examples/text-field/text-field-example.cpp b/examples/text-field/text-field-example.cpp index dfcd06a..d99d0ec 100644 --- a/examples/text-field/text-field-example.cpp +++ b/examples/text-field/text-field-example.cpp @@ -25,17 +25,48 @@ #include // INTERNAL INCLUDES +#include "shared/multi-language-strings.h" #include "shared/view.h" using namespace Dali; using namespace Dali::Toolkit; +using namespace MultiLanguageStrings; namespace { -const char* const BACKGROUND_IMAGE = DALI_IMAGE_DIR "button-up.9.png"; + const char* const BACKGROUND_IMAGE = DALI_IMAGE_DIR "button-up.9.png"; -const float BORDER_WIDTH = 4.0f; + const float BORDER_WIDTH = 4.0f; + + const unsigned int KEY_ZERO = 10; + const unsigned int KEY_ONE = 11; + const unsigned int KEY_F = 41; + const unsigned int KEY_H = 43; + const unsigned int KEY_V = 55; + const unsigned int KEY_M = 58; + const unsigned int KEY_L = 46; + const unsigned int KEY_S = 39; + const unsigned int KEY_PLUS = 21; + const unsigned int KEY_MINUS = 20; + + const char* H_ALIGNMENT_STRING_TABLE[] = + { + "BEGIN", + "CENTER", + "END" + }; + + const unsigned int H_ALIGNMENT_STRING_COUNT = sizeof( H_ALIGNMENT_STRING_TABLE ) / sizeof( H_ALIGNMENT_STRING_TABLE[0u] ); + + const char* V_ALIGNMENT_STRING_TABLE[] = + { + "TOP", + "CENTER", + "BOTTOM" + }; + + const unsigned int V_ALIGNMENT_STRING_COUNT = sizeof( V_ALIGNMENT_STRING_TABLE ) / sizeof( V_ALIGNMENT_STRING_TABLE[0u] ); } // unnamed namespace @@ -47,7 +78,9 @@ class TextFieldExample : public ConnectionTracker public: TextFieldExample( Application& application ) - : mApplication( application ) + : mApplication( application ), + mLanguageId( 0u ), + mAlignment( 0u ) { // Connect to the Application's Init signal mApplication.InitSignal().Connect( this, &TextFieldExample::Create ); @@ -67,33 +100,41 @@ public: Stage stage = Stage::GetCurrent(); + mTapGestureDetector = TapGestureDetector::New(); + mTapGestureDetector.Attach( stage.GetRootLayer() ); + mTapGestureDetector.DetectedSignal().Connect( this, &TextFieldExample::OnTap ); + stage.KeyEventSignal().Connect(this, &TextFieldExample::OnKeyEvent); Vector2 stageSize = stage.GetSize(); - mContainer = Control::New(); - mContainer.SetName( "Container" ); - mContainer.SetParentOrigin( ParentOrigin::CENTER ); - mContainer.SetSize( Vector2(stageSize.width*0.6f, stageSize.width*0.6f) ); - mContainer.SetBackgroundImage( ResourceImage::New( BACKGROUND_IMAGE ) ); - mContainer.GetChildAt(0).SetZ(-1.0f); - stage.Add( mContainer ); + Control container = Control::New(); + container.SetName( "Container" ); + container.SetParentOrigin( ParentOrigin::CENTER ); + container.SetSize( Vector2(stageSize.width*0.6f, stageSize.width*0.6f) ); + container.SetBackgroundColor( Color::WHITE ); + container.GetChildAt(0).SetZ(-1.0f); + stage.Add( container ); - TextField field = TextField::New(); - field.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - field.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - field.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT ); + mField = TextField::New(); + mField.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + mField.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); + mField.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT ); + mField.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "Unnamed folder" ); + mField.SetProperty( TextField::Property::DECORATION_BOUNDING_BOX, Rect( BORDER_WIDTH, BORDER_WIDTH, stageSize.width - BORDER_WIDTH*2, stageSize.height - BORDER_WIDTH*2 ) ); - mContainer.Add( field ); + container.Add( mField ); - field.SetProperty( TextField::Property::TEXT, "Hello" ); - field.SetProperty( TextField::Property::DECORATION_BOUNDING_BOX, Rect( BORDER_WIDTH, BORDER_WIDTH, stageSize.width - BORDER_WIDTH*2, stageSize.height - BORDER_WIDTH*2 ) ); - - Property::Value fieldText = field.GetProperty( TextField::Property::TEXT ); + Property::Value fieldText = mField.GetProperty( TextField::Property::TEXT ); std::cout << "Displaying text: " << fieldText.Get< std::string >() << std::endl; } + void OnTap( Actor actor, const TapGesture& tapGesture ) + { + mField.ClearKeyInputFocus(); + } + /** * Main key event handler */ @@ -105,6 +146,73 @@ public: { mApplication.Quit(); } + else if( event.IsCtrlModifier() ) + { + switch( event.keyCode ) + { + // Select rendering back-end + case KEY_ZERO: // fall through + case KEY_ONE: + { + mField.SetProperty( TextField::Property::RENDERING_BACKEND, event.keyCode - 10 ); + break; + } + case KEY_H: // Horizontal alignment + { + if( ++mAlignment >= H_ALIGNMENT_STRING_COUNT ) + { + mAlignment = 0u; + } + + mField.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, H_ALIGNMENT_STRING_TABLE[ mAlignment ] ); + break; + } + case KEY_V: // Vertical alignment + { + if( ++mAlignment >= V_ALIGNMENT_STRING_COUNT ) + { + mAlignment = 0u; + } + + mField.SetProperty( TextField::Property::VERTICAL_ALIGNMENT, V_ALIGNMENT_STRING_TABLE[ mAlignment ] ); + break; + } + case KEY_L: // Language + { + const Language& language = LANGUAGES[ mLanguageId ]; + + mField.SetProperty( TextField::Property::TEXT, language.text ); + + if( ++mLanguageId >= NUMBER_OF_LANGUAGES ) + { + mLanguageId = 0u; + } + break; + } + case KEY_S: // Shadow color + { + if( Color::BLACK == mField.GetProperty( TextField::Property::SHADOW_COLOR ) ) + { + mField.SetProperty( TextField::Property::SHADOW_COLOR, Color::RED ); + } + else + { + mField.SetProperty( TextField::Property::SHADOW_COLOR, Color::BLACK ); + } + break; + } + case KEY_PLUS: // Increase shadow offset + { + mField.SetProperty( TextField::Property::SHADOW_OFFSET, mField.GetProperty( TextField::Property::SHADOW_OFFSET ) + Vector2( 1.0f, 1.0f ) ); + break; + } + case KEY_MINUS: // Decrease shadow offset + { + mField.SetProperty( TextField::Property::SHADOW_OFFSET, mField.GetProperty( TextField::Property::SHADOW_OFFSET ) - Vector2( 1.0f, 1.0f ) ); + break; + } + } + } } } @@ -112,7 +220,12 @@ private: Application& mApplication; - Control mContainer; + TextField mField; + + TapGestureDetector mTapGestureDetector; + + unsigned int mLanguageId; + unsigned int mAlignment; }; void RunTest( Application& application ) diff --git a/examples/text-label-emojis/text-label-emojis.cpp b/examples/text-label-emojis/text-label-emojis.cpp index 8529904..751cb26 100644 --- a/examples/text-label-emojis/text-label-emojis.cpp +++ b/examples/text-label-emojis/text-label-emojis.cpp @@ -56,6 +56,7 @@ public: void Create( Application& application ) { Stage stage = Stage::GetCurrent(); + stage.SetBackgroundColor( Color::WHITE ); stage.KeyEventSignal().Connect(this, &EmojiExample::OnKeyEvent); mTableView = Toolkit::TableView::New( NUMBER_OF_EMOJIS, 1 ); @@ -99,7 +100,7 @@ public: { if( mAnimation ) { - mAnimation.AnimateBy( Property(mTableView, Actor::Property::POSITION), Vector3( 0.f, localPoint - mLastPoint, 0.f ), AlphaFunctions::Linear ); + mAnimation.AnimateBy( Property(mTableView, Actor::Property::POSITION), Vector3( 0.f, localPoint - mLastPoint, 0.f ), AlphaFunction::LINEAR ); mAnimation.Play(); mLastPoint = localPoint; } diff --git a/examples/text-label-multi-language/text-label-multi-language-example.cpp b/examples/text-label-multi-language/text-label-multi-language-example.cpp index 436b213..3706b81 100644 --- a/examples/text-label-multi-language/text-label-multi-language-example.cpp +++ b/examples/text-label-multi-language/text-label-multi-language-example.cpp @@ -62,6 +62,7 @@ public: Stage stage = Stage::GetCurrent(); stage.KeyEventSignal().Connect(this, &TextLabelMultiLanguageExample::OnKeyEvent); + stage.SetBackgroundColor( Color::WHITE ); mTableView = Toolkit::TableView::New( NUMBER_OF_LANGUAGES, 1 ); mTableView.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); @@ -104,7 +105,7 @@ public: { if( mAnimation ) { - mAnimation.AnimateBy( Property(mTableView, Actor::Property::POSITION), Vector3( 0.f, localPoint - mLastPoint, 0.f ), AlphaFunctions::Linear ); + mAnimation.AnimateBy( Property(mTableView, Actor::Property::POSITION), Vector3( 0.f, localPoint - mLastPoint, 0.f ), AlphaFunction::LINEAR ); mAnimation.Play(); mLastPoint = localPoint; } diff --git a/examples/text-label/text-label-example.cpp b/examples/text-label/text-label-example.cpp index 4816737..a24e3aa 100644 --- a/examples/text-label/text-label-example.cpp +++ b/examples/text-label/text-label-example.cpp @@ -131,9 +131,10 @@ public: mLabel.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); mLabel.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT ); mLabel.SetProperty( TextLabel::Property::MULTI_LINE, true ); + mLabel.SetProperty( TextLabel::Property::TEXT_COLOR, Color::BLUE ); mLabel.SetProperty( TextLabel::Property::SHADOW_OFFSET, Vector2( 1.0f, 1.0f ) ); mLabel.SetProperty( TextLabel::Property::SHADOW_COLOR, Color::BLACK ); - mLabel.SetBackgroundColor( Vector4(0.3f,0.3f,0.6f,1.0f) ); + mLabel.SetBackgroundColor( Color::WHITE ); mContainer.Add( mLabel ); Property::Value labelText = mLabel.GetProperty( TextLabel::Property::TEXT ); diff --git a/packaging/com.samsung.dali-demo.spec b/packaging/com.samsung.dali-demo.spec index 40d65dc..cd7aec2 100755 --- a/packaging/com.samsung.dali-demo.spec +++ b/packaging/com.samsung.dali-demo.spec @@ -2,7 +2,7 @@ Name: com.samsung.dali-demo Summary: The OpenGLES Canvas Core Demo -Version: 1.0.39 +Version: 1.0.40 Release: 1 Group: System/Libraries License: Apache-2.0 diff --git a/resources/style/demo-theme.json b/resources/style/demo-theme.json index 89650ce..79acc25 100644 --- a/resources/style/demo-theme.json +++ b/resources/style/demo-theme.json @@ -54,6 +54,16 @@ distributing this software or its derivatives. "scrollview": { "overshoot-effect-color":"B018" + }, + + "grouplabel": + { + "point-size":9 + }, + + "buttonlabel": + { + "point-size":11 } } } diff --git a/resources/style/mobile/demo-theme.json b/resources/style/mobile/demo-theme.json index 682db8e..4328b32 100644 --- a/resources/style/mobile/demo-theme.json +++ b/resources/style/mobile/demo-theme.json @@ -94,6 +94,16 @@ distributing this software or its derivatives. "scrollview": { "overshoot-effect-color":"B018" + }, + + "grouplabel": + { + "point-size":6 + }, + + "buttonlabel": + { + "point-size":8 } } } diff --git a/shared/dali-demo-strings.h b/shared/dali-demo-strings.h index 56adecf..6f408d5 100644 --- a/shared/dali-demo-strings.h +++ b/shared/dali-demo-strings.h @@ -47,6 +47,7 @@ extern "C" #define DALI_DEMO_STR_TITLE_SCROLL_VIEW dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_SCROLL_VIEW") #define DALI_DEMO_STR_TITLE_LIGHTS_AND_SHADOWS dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_LIGHTS_AND_SHADOWS") #define DALI_DEMO_STR_TITLE_SCRIPT_BASED_UI dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_SCRIPT_BASED_UI") +#define DALI_DEMO_STR_TITLE_IMAGE_FITTING_SAMPLING dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_IMAGE_FITTING_SAMPLING") #define DALI_DEMO_STR_TITLE_IMAGE_SCALING dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_IMAGE_SCALING") #define DALI_DEMO_STR_TITLE_TEXT_LABEL dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_LABEL") #define DALI_DEMO_STR_TITLE_TEXT_LABEL_MULTI_LANGUAGE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_LABEL_MULTI_LANGUAGE") @@ -74,7 +75,8 @@ extern "C" #define DALI_DEMO_STR_TITLE_SCROLL_VIEW "Scroll View" #define DALI_DEMO_STR_TITLE_LIGHTS_AND_SHADOWS "Lights and shadows" #define DALI_DEMO_STR_TITLE_SCRIPT_BASED_UI "Script Based UI" -#define DALI_DEMO_STR_TITLE_IMAGE_SCALING "Image Scaling Modes" +#define DALI_DEMO_STR_TITLE_IMAGE_FITTING_SAMPLING "Image Fitting and Sampling" +#define DALI_DEMO_STR_TITLE_IMAGE_SCALING "Image Scaling Grid" #define DALI_DEMO_STR_TITLE_TEXT_LABEL "Text Label" #define DALI_DEMO_STR_TITLE_TEXT_LABEL_MULTI_LANGUAGE "Text Scripts" #define DALI_DEMO_STR_TITLE_EMOJI_TEXT "Emoji Text" diff --git a/shared/view.h b/shared/view.h index d1cca77..44b6663 100644 --- a/shared/view.h +++ b/shared/view.h @@ -46,7 +46,6 @@ const ViewStyle DEFAULT_VIEW_STYLE( 0.1f, 0.7f, 80.f, 4.f ); const char* DEFAULT_TEXT_STYLE_FONT_FAMILY("HelveticaNue"); const char* DEFAULT_TEXT_STYLE_FONT_STYLE("Regular"); const float DEFAULT_TEXT_STYLE_POINT_SIZE( 8.0f ); -const Dali::Vector4 DEFAULT_TEXT_STYLE_COLOR(0.0f, 0.0f, 0.0f, 1.0f); const Dali::Toolkit::Alignment::Padding DEFAULT_PLAY_PADDING(12.0f, 12.0f, 12.0f, 12.0f); const Dali::Toolkit::Alignment::Padding DEFAULT_MODE_SWITCH_PADDING(8.0f, 8.0f, 8.0f, 8.0f); @@ -109,7 +108,6 @@ Dali::Layer CreateToolbar( Dali::Toolkit::ToolBar& toolBar, label.SetProperty( Dali::Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); label.SetProperty( Dali::Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); label.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::HEIGHT ); - label.SetColor( DEFAULT_TEXT_STYLE_COLOR ); // Add title to the tool bar. const float padding( style.mToolBarPadding ); @@ -120,7 +118,7 @@ Dali::Layer CreateToolbar( Dali::Toolkit::ToolBar& toolBar, } Dali::Layer CreateView( Dali::Application& application, - Dali::Toolkit::View& view, + Dali::Toolkit::Control& view, Dali::Toolkit::ToolBar& toolBar, const std::string& backgroundImagePath, const std::string& toolbarImagePath, @@ -130,7 +128,9 @@ Dali::Layer CreateView( Dali::Application& application, Dali::Stage stage = Dali::Stage::GetCurrent(); // Create default View. - view = Dali::Toolkit::View::New(); + view = Dali::Toolkit::Control::New(); + view.SetAnchorPoint( Dali::AnchorPoint::CENTER ); + view.SetParentOrigin( Dali::ParentOrigin::CENTER ); view.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::ALL_DIMENSIONS ); // Add the view to the stage before setting the background. @@ -140,8 +140,7 @@ Dali::Layer CreateView( Dali::Application& application, if ( !backgroundImagePath.empty() ) { 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 ); - Dali::ImageActor backgroundImageActor = Dali::ImageActor::New( backgroundImage ); - view.SetBackground( backgroundImageActor ); + view.SetBackgroundImage( backgroundImage ); } // FIXME @@ -152,14 +151,14 @@ Dali::Layer CreateView( Dali::Application& application, Dali::Layer toolBarLayer = CreateToolbar( toolBar, toolbarImagePath, title, style ); // Add tool bar layer to the view. - view.AddContentLayer( toolBarLayer ); + view.Add( toolBarLayer ); // Create a content layer. Dali::Layer contentLayer = Dali::Layer::New(); contentLayer.SetAnchorPoint( Dali::AnchorPoint::CENTER ); contentLayer.SetParentOrigin( Dali::ParentOrigin::CENTER ); contentLayer.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::ALL_DIMENSIONS ); - view.AddContentLayer( contentLayer ); + view.Add( contentLayer ); contentLayer.LowerBelow( toolBarLayer ); return contentLayer; @@ -173,7 +172,6 @@ Dali::Toolkit::TextLabel CreateToolBarLabel( const std::string& text ) label.SetProperty( Dali::Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); label.SetProperty( Dali::Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); label.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::HEIGHT ); - label.SetColor( DEFAULT_TEXT_STYLE_COLOR ); return label; }