Merge "[3.0] Removed 3D layer dependency of Model3dView and Mesh Visual." into tizen
[platform/core/uifw/dali-demo.git] / examples / radial-menu / radial-menu-example.cpp
index ac735bf..13be24a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * 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.
@@ -26,14 +26,16 @@ using namespace Dali::Toolkit;
 
 namespace
 {
-const char* TEST_OUTER_RING_FILENAME = DALI_IMAGE_DIR "layer2.png"; // Image to be masked
-const char* TEST_INNER_RING_FILENAME = DALI_IMAGE_DIR "layer1.png"; // Image to be masked
-const char* TEST_MENU_FILENAME = DALI_IMAGE_DIR "layer3.png"; // Image to be masked
-const char* TEST_DIAL_FILENAME = DALI_IMAGE_DIR "layer4.png"; // Image to be masked
-const char* TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" ); // Background for toolbar
+const char* TEST_OUTER_RING_FILENAME = DEMO_IMAGE_DIR "layer2.png"; // Image to be masked
+const char* TEST_INNER_RING_FILENAME = DEMO_IMAGE_DIR "layer1.png"; // Image to be masked
+const char* TEST_MENU_FILENAME = DEMO_IMAGE_DIR "layer3.png"; // Image to be masked
+const char* TEST_DIAL_FILENAME = DEMO_IMAGE_DIR "layer4.png"; // Image to be masked
+const char* TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" ); // Background for toolbar
 const char* APPLICATION_TITLE( "Radial Menu" );
-const char * const PLAY_ICON( DALI_IMAGE_DIR "icon-play.png" );
-const char * const STOP_ICON( DALI_IMAGE_DIR "icon-stop.png" );
+const char * const PLAY_ICON( DEMO_IMAGE_DIR "icon-play.png" );
+const char * const PLAY_ICON_SELECTED( DEMO_IMAGE_DIR "icon-play-selected.png" );
+const char * const STOP_ICON( DEMO_IMAGE_DIR "icon-stop.png" );
+const char * const STOP_ICON_SELECTED( DEMO_IMAGE_DIR "icon-stop-selected.png" );
 }
 
 
@@ -69,10 +71,19 @@ private:
    */
   RadialSweepView CreateSweepView( std::string imageName, Degree initial, Degree final );
 
+  /**
+   * Start the sweep animation on the menu
+   */
   void StartAnimation();
 
+  /**
+   * Play or pause the animation when the button is clicked
+   */
   bool OnButtonClicked( Toolkit::Button button );
 
+  /**
+   * Update the state flag and change the button icon when the animation is finished
+   */
   void OnAnimationFinished( Animation& source );
 
   /**
@@ -91,16 +102,14 @@ 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
+  ImageView       mImageView;  ///< Image view shown by stencil mask
   Animation       mAnimation;
   AnimState       mAnimationState;
 
-  Image               mIconPlay;
-  Image               mIconStop;
   Toolkit::PushButton mPlayStopButton;
-  ImageActor      mDialActor;
+  ImageView       mDialView;
   RadialSweepView mRadialSweepView1;
   RadialSweepView mRadialSweepView2;
   RadialSweepView mRadialSweepView3;
@@ -121,8 +130,6 @@ RadialMenuExample::~RadialMenuExample()
 
 void RadialMenuExample::OnInit(Application& app)
 {
-  DemoHelper::RequestThemeChange();
-
   Stage stage = Dali::Stage::GetCurrent();
 
   // The Init signal is received once (only) during the Application lifetime
@@ -137,10 +144,9 @@ void RadialMenuExample::OnInit(Application& app)
                                       TOOLBAR_IMAGE,
                                       APPLICATION_TITLE );
 
-  mIconPlay = ResourceImage::New( PLAY_ICON );
-  mIconStop = ResourceImage::New( STOP_ICON );
   mPlayStopButton = Toolkit::PushButton::New();
-  mPlayStopButton.SetBackgroundImage( mIconStop );
+  mPlayStopButton.SetUnselectedImage( STOP_ICON );
+  mPlayStopButton.SetSelectedImage( STOP_ICON_SELECTED );
 
   mPlayStopButton.ClickedSignal().Connect( this, &RadialMenuExample::OnButtonClicked );
 
@@ -149,15 +155,16 @@ void RadialMenuExample::OnInit(Application& app)
                       Toolkit::Alignment::HorizontalRight,
                       DemoHelper::DEFAULT_PLAY_PADDING );
 
-  Vector2 imgSize = ResourceImage::GetImageSize(TEST_OUTER_RING_FILENAME);
-  Vector2 stageSize = stage.GetSize();
-  float minStageDimension = std::min(stageSize.width, stageSize.height);
 
-  if(stageSize.height <= stageSize.width)
+  const ImageDimensions intImgSize = ResourceImage::GetImageSize(TEST_OUTER_RING_FILENAME);
+  Vector2 imgSize = Vector2( intImgSize.GetWidth(), intImgSize.GetHeight() );
+  Vector2 stageSize = stage.GetSize();
+  float scale = stageSize.width / imgSize.width;
+  float availableHeight = stageSize.height - DemoHelper::DEFAULT_VIEW_STYLE.mToolBarHeight * 2.0f;
+  if(availableHeight <= stageSize.width)
   {
-    minStageDimension -= DemoHelper::DEFAULT_VIEW_STYLE.mToolBarHeight * 2.0f;
+    scale = availableHeight / imgSize.width;
   }
-  float scale = minStageDimension / imgSize.width;
 
   mRadialSweepView1 = CreateSweepView( TEST_OUTER_RING_FILENAME, Degree(-90.0f), Degree(-90.0f));
   mRadialSweepView2 = CreateSweepView( TEST_INNER_RING_FILENAME, Degree(90.0f),  Degree(0.0f));
@@ -165,15 +172,14 @@ void RadialMenuExample::OnInit(Application& app)
   mRadialSweepView3.SetInitialActorAngle(Degree(-110));
   mRadialSweepView3.SetFinalActorAngle(Degree(0));
 
-  Image dial = ResourceImage::New( TEST_DIAL_FILENAME );
-  mDialActor = ImageActor::New( dial );
-  mDialActor.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
-  mDialActor.SetPositionInheritanceMode(USE_PARENT_POSITION);
-  mDialActor.SetScale(scale);
+  mDialView = ImageView::New( TEST_DIAL_FILENAME );
+  mDialView.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
+  mDialView.SetParentOrigin( ParentOrigin::CENTER );
+  mDialView.SetScale(scale);
   Layer dialLayer = Layer::New();
 
-  dialLayer.Add(mDialActor);
-  dialLayer.SetPositionInheritanceMode(USE_PARENT_POSITION);
+  dialLayer.Add( mDialView );
+  dialLayer.SetParentOrigin( ParentOrigin::CENTER );
   dialLayer.SetSize(stage.GetSize());
   mContents.Add(dialLayer);
 
@@ -186,14 +192,14 @@ void RadialMenuExample::OnInit(Application& app)
 
 void RadialMenuExample::StartAnimation()
 {
-  mDialActor.SetOpacity(0.0f);
+  mDialView.SetOpacity(0.0f);
   mRadialSweepView1.SetOpacity(0.0f);
   mAnimation = Animation::New(6.0f);
   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( mDialView, 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;
@@ -207,20 +213,25 @@ bool RadialMenuExample::OnButtonClicked( Toolkit::Button button )
     case PLAYING:
     {
       mAnimation.Pause();
-      mPlayStopButton.SetBackgroundImage( mIconPlay );
+      mAnimationState = PAUSED;
+      mPlayStopButton.SetUnselectedImage( PLAY_ICON );
+      mPlayStopButton.SetSelectedImage( PLAY_ICON_SELECTED );
     }
     break;
 
     case PAUSED:
     {
       mAnimation.Play();
-      mPlayStopButton.SetBackgroundImage( mIconStop );
+      mAnimationState = PLAYING;
+      mPlayStopButton.SetUnselectedImage( STOP_ICON );
+      mPlayStopButton.SetSelectedImage( STOP_ICON_SELECTED );
     }
     break;
 
     case STOPPED:
     {
-      mPlayStopButton.SetBackgroundImage( mIconStop );
+      mPlayStopButton.SetUnselectedImage( STOP_ICON );
+      mPlayStopButton.SetSelectedImage( STOP_ICON_SELECTED );
       mRadialSweepView1.Deactivate();
       mRadialSweepView2.Deactivate();
       mRadialSweepView3.Deactivate();
@@ -233,7 +244,8 @@ bool RadialMenuExample::OnButtonClicked( Toolkit::Button button )
 void RadialMenuExample::OnAnimationFinished( Animation& source )
 {
   mAnimationState = STOPPED;
-  mPlayStopButton.SetBackgroundImage( mIconPlay );
+  mPlayStopButton.SetUnselectedImage( PLAY_ICON );
+  mPlayStopButton.SetSelectedImage( PLAY_ICON_SELECTED );
 }
 
 RadialSweepView RadialMenuExample::CreateSweepView( std::string imageName,
@@ -241,15 +253,14 @@ RadialSweepView RadialMenuExample::CreateSweepView( std::string imageName,
                                                     Degree finalAngle)
 {
   // Create the image
-  Image image = ResourceImage::New(imageName);
-  mImageActor = ImageActor::New(image);
-  mImageActor.SetParentOrigin(ParentOrigin::CENTER);
-  mImageActor.SetAnchorPoint(AnchorPoint::CENTER);
-  mImageActor.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
+  mImageView = ImageView::New(imageName);
+  mImageView.SetParentOrigin(ParentOrigin::CENTER);
+  mImageView.SetAnchorPoint(AnchorPoint::CENTER);
+  mImageView.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
 
   // Create the stencil
-  Vector2 imageSize = ResourceImage::GetImageSize(imageName);
-  float diameter = std::max(imageSize.width, imageSize.height);
+  const ImageDimensions imageSize = ResourceImage::GetImageSize(imageName);
+  float diameter = std::max(imageSize.GetWidth(), imageSize.GetHeight());
   RadialSweepView radialSweepView = RadialSweepView::New();
   radialSweepView.SetDiameter( diameter );
   radialSweepView.SetInitialAngle( initialAngle );
@@ -257,11 +268,11 @@ 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.SetPositionInheritanceMode(USE_PARENT_POSITION);
+  radialSweepView.SetEasingFunction( Dali::AlphaFunction::EASE_IN_OUT );
+  radialSweepView.SetParentOrigin( ParentOrigin::CENTER );
   mContents.Add(radialSweepView);
-  radialSweepView.Add( mImageActor );
-  mImageActor.SetPositionInheritanceMode(USE_PARENT_POSITION);
+  radialSweepView.Add( mImageView );
+  mImageView.SetParentOrigin( ParentOrigin::CENTER );
 
   return radialSweepView;
 }
@@ -286,9 +297,9 @@ void RunTest(Application app)
 }
 
 // Entry point for Linux & Tizen applications
-int main(int argc, char **argv)
+int DALI_EXPORT_API main(int argc, char **argv)
 {
-  Application app = Application::New(&argc, &argv);
+  Application app = Application::New(&argc, &argv, DEMO_THEME_PATH);
 
   RunTest(app);