Changed demos to use unselected button images.
[platform/core/uifw/dali-demo.git] / examples / image-scaling-irregular-grid / image-scaling-irregular-grid-example.cpp
index d921645..ffa597b 100644 (file)
@@ -65,6 +65,7 @@ const char* BACKGROUND_IMAGE( DALI_IMAGE_DIR "background-gradient.jpg" );
 const char* TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" );
 const char* APPLICATION_TITLE( "Image Scaling Modes" );
 const char* TOGGLE_SCALING_IMAGE( DALI_IMAGE_DIR "icon-change.png" );
+const char* TOGGLE_SCALING_IMAGE_SELECTED( DALI_IMAGE_DIR "icon-change-selected.png" );
 
 /** The width of the grid in whole grid cells. */
 const unsigned GRID_WIDTH = 9;
@@ -287,8 +288,6 @@ public:
   {
     std::cout << "ImageScalingIrregularGridController::Create" << std::endl;
 
-    DemoHelper::RequestThemeChange();
-
     // Get a handle to the stage:
     Stage stage = Stage::GetCurrent();
 
@@ -308,8 +307,10 @@ public:
 
     // Create an image scaling toggle button. (right of toolbar)
     Image toggleScalingImage = ResourceImage::New( TOGGLE_SCALING_IMAGE );
+    Image toggleScalingImageSelected = ResourceImage::New( TOGGLE_SCALING_IMAGE_SELECTED );
     Toolkit::PushButton toggleScalingButton = Toolkit::PushButton::New();
-    toggleScalingButton.SetBackgroundImage( toggleScalingImage );
+    toggleScalingButton.SetButtonImage( toggleScalingImage );
+    toggleScalingButton.SetSelectedImage( toggleScalingImageSelected );
     toggleScalingButton.ClickedSignal().Connect( this, &ImageScalingIrregularGridController::OnToggleScalingTouched );
     mToolBar.AddControl( toggleScalingButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING  );
 
@@ -335,13 +336,11 @@ public:
     mScrollView.ScrollStartedSignal().Connect( this, &ImageScalingIrregularGridController::OnScrollStarted );
     mScrollView.ScrollCompletedSignal().Connect( this, &ImageScalingIrregularGridController::OnScrollCompleted );
 
-    mScrollView.EnableScrollComponent( Scrollable::VerticalScrollBar );
-    mScrollView.EnableScrollComponent( Scrollable::HorizontalScrollBar );
-
     mScrollView.SetAnchorPoint(AnchorPoint::CENTER);
     mScrollView.SetParentOrigin(ParentOrigin::CENTER);
 
-    mScrollView.SetSize( stageSize );//Vector2( stageSize.width, fieldHeight ) );//stageSize );
+    mScrollView.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+
     mScrollView.SetAxisAutoLock( true );
     mScrollView.SetAxisAutoLockGradient( 1.0f );
 
@@ -351,7 +350,7 @@ public:
     rulerX->SetDomain( RulerDomain( stageSize.width * -0.125f, stageSize.width * 1.125f ) ); //< Scroll slightly left/right of image field.
     mScrollView.SetRulerX ( rulerX );
 
-    RulerPtr rulerY = new DefaultRuler(); //stageSize.height ); //< Snap in multiples of a screen / stage height
+    RulerPtr rulerY = new DefaultRuler(); //< Snap in multiples of a screen / stage height
     rulerY->SetDomain( RulerDomain( - fieldHeight * 0.5f + stageSize.height * 0.5f - GRID_CELL_PADDING, fieldHeight * 0.5f + stageSize.height * 0.5f + GRID_CELL_PADDING ) );
     mScrollView.SetRulerY ( rulerY );
 
@@ -359,8 +358,31 @@ public:
     mScrollView.Add( imageField );
     mGridActor = imageField;
 
+    // Create the scroll bar
+    mScrollBarVertical = ScrollBar::New(Toolkit::ScrollBar::Vertical);
+    mScrollBarVertical.SetParentOrigin(ParentOrigin::TOP_RIGHT);
+    mScrollBarVertical.SetAnchorPoint(AnchorPoint::TOP_RIGHT);
+    mScrollBarVertical.SetResizePolicy(Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::HEIGHT);
+    mScrollBarVertical.SetResizePolicy(Dali::ResizePolicy::FIT_TO_CHILDREN, Dali::Dimension::WIDTH);
+    mScrollView.Add(mScrollBarVertical);
+
+    mScrollBarHorizontal = ScrollBar::New(Toolkit::ScrollBar::Horizontal);
+    mScrollBarHorizontal.SetParentOrigin(ParentOrigin::BOTTOM_LEFT);
+    mScrollBarHorizontal.SetAnchorPoint(AnchorPoint::TOP_LEFT);
+    mScrollBarHorizontal.SetResizePolicy(Dali::ResizePolicy::FIT_TO_CHILDREN, Dali::Dimension::WIDTH);
+    mScrollBarHorizontal.SetOrientation(Quaternion(Radian( 1.5f * Math::PI ), Vector3::ZAXIS));
+    mScrollView.Add(mScrollBarHorizontal);
+
+    mScrollView.OnRelayoutSignal().Connect( this, &ImageScalingIrregularGridController::OnScrollViewRelayout );
+
     // Scroll to top of grid so first images loaded are on-screen:
-    mScrollView.ScrollTo( Vector3( 0, -1000000, 0 ) );
+    mScrollView.ScrollTo( Vector2( 0, -1000000 ) );
+  }
+
+  void OnScrollViewRelayout(Actor actor)
+  {
+    // Make the height of the horizontal scroll bar to be the same as the width of scroll view.
+    mScrollBarHorizontal.SetSize(Vector2(0.0f, mScrollView.GetRelayoutSize( Dimension::WIDTH) ));
   }
 
   /**
@@ -549,7 +571,7 @@ public:
    * note this state (mScrolling = true)
    * @param[in] position Current Scroll Position
    */
-  void OnScrollStarted( const Vector3& position )
+  void OnScrollStarted( const Vector2& position )
   {
     mScrolling = true;
   }
@@ -559,7 +581,7 @@ public:
    * note this state (mScrolling = false).
    * @param[in] position Current Scroll Position
    */
-  void OnScrollCompleted( const Vector3& position )
+  void OnScrollCompleted( const Vector2& position )
   {
     mScrolling = false;
   }
@@ -573,6 +595,8 @@ private:
   TextLabel mTitleActor;               ///< The Toolbar's Title.
   Actor mGridActor;                   ///< The container for the grid of images
   ScrollView mScrollView;             ///< ScrollView UI Component
+  ScrollBar mScrollBarVertical;
+  ScrollBar mScrollBarHorizontal;
   bool mScrolling;                    ///< ScrollView scrolling state (true = scrolling, false = stationary)
   std::map<unsigned, Dali::FittingMode::Type> mFittingModes; ///< Stores the current scaling mode of each image, keyed by image actor id.
   std::map<unsigned, Vector2> mSizes; ///< Stores the current size of each image, keyed by image actor id.
@@ -588,7 +612,7 @@ void RunTest( Application& application )
 /** Entry point for Linux & Tizen applications */
 int main( int argc, char **argv )
 {
-  Application application = Application::New( &argc, &argv );
+  Application application = Application::New( &argc, &argv, DALI_DEMO_THEME_PATH );
 
   RunTest( application );