Merge remote-tracking branch 'origin/tizen' into new_text
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / buttons / push-button-impl.cpp
index bd26b23..08948de 100644 (file)
@@ -23,7 +23,6 @@
 #include <dali/public-api/object/type-registry.h>
 
 // INTERNAL INCLUDES
-#include <dali-toolkit/internal/controls/relayout-helper.h>
 
 namespace Dali
 {
@@ -123,7 +122,7 @@ void PushButton::SetButtonImage( Actor image )
 
         buttonImage = image;
 
-        FadeInImage( buttonImage );
+        FadeInImage( buttonImage, 0.0f, 0 );
 
         StartFadeOutAnimation();
         StartFadeInAnimation();
@@ -131,7 +130,7 @@ void PushButton::SetButtonImage( Actor image )
       else
       {
         buttonImage = image;
-        Self().Add( buttonImage );
+        Self().Insert( 0, buttonImage );
       }
       break;
     }
@@ -148,7 +147,7 @@ void PushButton::SetButtonImage( Actor image )
       // Replaces the button image.
       buttonImage = image;
 
-      Self().Add( buttonImage );
+      Self().Insert( 0, buttonImage );
       FadeOutImage( Foreground, buttonImage, opacity );
 
       StartFadeOutAnimation();
@@ -162,7 +161,7 @@ void PushButton::SetButtonImage( Actor image )
 
       buttonImage = image;
 
-      FadeInImage( buttonImage );
+      FadeInImage( buttonImage, 0.0f, 0 );
       StartFadeInAnimation();
       break;
     }
@@ -174,7 +173,8 @@ void PushButton::SetButtonImage( Actor image )
   buttonImage.SetAnchorPoint( AnchorPoint::TOP_LEFT );
   buttonImage.SetParentOrigin( ParentOrigin::TOP_LEFT );
   buttonImage.SetPosition( 0.f, 0.f, FOREGROUND_DEPTH );
-  buttonImage.SetSizeMode( SIZE_EQUAL_TO_PARENT );
+  buttonImage.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
+  buttonImage.SetName( "BUTTON_IMAGE" );
 }
 
 void PushButton::SetSelectedImage( Actor image )
@@ -193,7 +193,7 @@ void PushButton::SetSelectedImage( Actor image )
 
         selectedImage = image;
 
-        FadeInImage( selectedImage );
+        FadeInImage( selectedImage, 0.0f, 0 );
 
         StartFadeOutAnimation();
         StartFadeInAnimation();
@@ -201,7 +201,7 @@ void PushButton::SetSelectedImage( Actor image )
       else
       {
         selectedImage = image;
-        Self().Add( selectedImage );
+        Self().Insert( 0, selectedImage );
       }
       break;
     }
@@ -218,7 +218,7 @@ void PushButton::SetSelectedImage( Actor image )
       // Replaces the button image.
       selectedImage = image;
 
-      Self().Add( selectedImage );
+      Self().Insert( 0, selectedImage );
       FadeOutImage( Foreground, selectedImage, opacity );
 
       StartFadeOutAnimation();
@@ -232,7 +232,7 @@ void PushButton::SetSelectedImage( Actor image )
 
       selectedImage = image;
 
-      FadeInImage( selectedImage );
+      FadeInImage( selectedImage, 0.0f, 0 );
       StartFadeInAnimation();
       break;
     }
@@ -244,7 +244,7 @@ void PushButton::SetSelectedImage( Actor image )
   selectedImage.SetAnchorPoint( AnchorPoint::TOP_LEFT );
   selectedImage.SetParentOrigin( ParentOrigin::TOP_LEFT );
   selectedImage.SetPosition( 0.f, 0.f, FOREGROUND_DEPTH );
-  selectedImage.SetSizeMode( SIZE_EQUAL_TO_PARENT );
+  selectedImage.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
 }
 
 void PushButton::SetBackgroundImage( Actor image )
@@ -266,7 +266,7 @@ void PushButton::SetBackgroundImage( Actor image )
 
         backgroundImage = image;
 
-        FadeInImage( backgroundImage );
+        FadeInImage( backgroundImage, 0.0f, 0 );
 
         StartFadeOutAnimation();
         StartFadeInAnimation();
@@ -274,7 +274,7 @@ void PushButton::SetBackgroundImage( Actor image )
       else
       {
         backgroundImage = image;
-        Self().Add( backgroundImage );
+        Self().Insert( 0, backgroundImage );
       }
       break;
     }
@@ -291,7 +291,7 @@ void PushButton::SetBackgroundImage( Actor image )
       // Replaces the button image.
       backgroundImage = image;
 
-      Self().Add( backgroundImage );
+      Self().Insert( 0, backgroundImage );
       FadeOutImage( Background, backgroundImage, opacity );
 
       StartFadeOutAnimation();
@@ -305,7 +305,7 @@ void PushButton::SetBackgroundImage( Actor image )
 
       backgroundImage = image;
 
-      FadeInImage( backgroundImage );
+      FadeInImage( backgroundImage, 0.0f, 0 );
       StartFadeInAnimation();
       break;
     }
@@ -317,7 +317,7 @@ void PushButton::SetBackgroundImage( Actor image )
   backgroundImage.SetAnchorPoint( AnchorPoint::TOP_LEFT );
   backgroundImage.SetParentOrigin( ParentOrigin::TOP_LEFT );
   backgroundImage.SetPosition( 0.f, 0.f, BACKGROUND_DEPTH );
-  backgroundImage.SetSizeMode( SIZE_EQUAL_TO_PARENT );
+  backgroundImage.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
 }
 
 void PushButton::SetDisabledImage( Actor image )
@@ -337,7 +337,7 @@ void PushButton::SetDisabledImage( Actor image )
 
         disabledImage = image;
 
-        FadeInImage( disabledImage );
+        FadeInImage( disabledImage, 0.0f, 0 );
 
         StartFadeOutAnimation();
         StartFadeInAnimation();
@@ -357,7 +357,7 @@ void PushButton::SetDisabledImage( Actor image )
 
       disabledImage = image;
 
-      FadeInImage( disabledImage );
+      FadeInImage( disabledImage, 0.0f, 0 );
       StartFadeInAnimation();
       break;
     }
@@ -388,7 +388,7 @@ void PushButton::SetDisabledImage( Actor image )
   disabledImage.SetAnchorPoint( AnchorPoint::TOP_LEFT );
   disabledImage.SetParentOrigin( ParentOrigin::TOP_LEFT );
   disabledImage.SetPosition( 0.f, 0.f, FOREGROUND_DEPTH );
-  disabledImage.SetSizeMode( SIZE_EQUAL_TO_PARENT );
+  disabledImage.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
 }
 
 void PushButton::SetDisabledBackgroundImage( Actor image )
@@ -408,7 +408,7 @@ void PushButton::SetDisabledBackgroundImage( Actor image )
 
         disabledBackgroundImage = image;
 
-        FadeInImage( disabledBackgroundImage );
+        FadeInImage( disabledBackgroundImage, 0.0f, 0 );
 
         StartFadeOutAnimation();
         StartFadeInAnimation();
@@ -428,7 +428,7 @@ void PushButton::SetDisabledBackgroundImage( Actor image )
 
       disabledBackgroundImage = image;
 
-      FadeInImage( disabledBackgroundImage );
+      FadeInImage( disabledBackgroundImage, 0.0f, 0 );
       StartFadeInAnimation();
       break;
     }
@@ -459,7 +459,7 @@ void PushButton::SetDisabledBackgroundImage( Actor image )
   disabledBackgroundImage.SetAnchorPoint( AnchorPoint::TOP_LEFT );
   disabledBackgroundImage.SetParentOrigin( ParentOrigin::TOP_LEFT );
   disabledBackgroundImage.SetPosition( 0.f, 0.f, BACKGROUND_DEPTH );
-  disabledBackgroundImage.SetSizeMode( SIZE_EQUAL_TO_PARENT );
+  disabledBackgroundImage.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
 }
 
 void PushButton::OnButtonInitialize()
@@ -467,6 +467,9 @@ void PushButton::OnButtonInitialize()
   // Push button requires the Leave event.
   Actor root = Self();
   root.SetLeaveRequired( true );
+
+  // Set resize policy to natural size so that buttons will resize to background images
+  root.SetResizePolicy( USE_NATURAL_SIZE, ALL_DIMENSIONS );
 }
 
 void PushButton::OnLabelSet()
@@ -496,7 +499,7 @@ void PushButton::OnSelected( bool selected )
     {
       StopFadeOutAnimation();
       FadeOutImage( Foreground, buttonImage );
-      FadeInImage( selectedImage );
+      FadeInImage( selectedImage, 0.0f, 0 );
       StartFadeOutAnimation();
       StartFadeInAnimation();
 
@@ -514,7 +517,7 @@ void PushButton::OnSelected( bool selected )
     {
       StopFadeOutAnimation();
       FadeOutImage( Foreground, selectedImage );
-      FadeInImage( buttonImage );
+      FadeInImage( buttonImage, 0.0f, 0 );
       StartFadeOutAnimation();
       StartFadeInAnimation();
 
@@ -539,7 +542,7 @@ void PushButton::OnSelected( bool selected )
       StopFadeInAnimation();
 
       FadeOutImage( Foreground, selectedImage, 1.f - opacity );
-      FadeInImage( buttonImage, opacity );
+      FadeInImage( buttonImage, opacity, 0 );
 
       StartFadeOutAnimation();
       StartFadeInAnimation();
@@ -565,7 +568,7 @@ void PushButton::OnSelected( bool selected )
       StopFadeInAnimation();
 
       FadeOutImage( Foreground, buttonImage, 1.f - opacity );
-      FadeInImage( selectedImage, opacity );
+      FadeInImage( selectedImage, opacity, 0 );
 
       StartFadeOutAnimation();
       StartFadeInAnimation();
@@ -605,8 +608,8 @@ void PushButton::OnDisabled( bool disabled )
       StopFadeOutAnimation();
       FadeOutImage( Background, backgroundImage );
       FadeOutImage( Foreground, buttonImage );
-      FadeInImage( disabledBackgroundImage );
-      FadeInImage( disabledImage );
+      FadeInImage( disabledBackgroundImage, 0.0f, 0 );
+      FadeInImage( disabledImage, 0.0f, 0 );
       StartFadeOutAnimation();
       StartFadeInAnimation();
 
@@ -628,8 +631,8 @@ void PushButton::OnDisabled( bool disabled )
       StopFadeOutAnimation();
       FadeOutImage( Background, backgroundImage );
       FadeOutImage( Foreground, selectedImage );
-      FadeInImage( disabledBackgroundImage );
-      FadeInImage( disabledImage );
+      FadeInImage( disabledBackgroundImage, 0.0f, 0 );
+      FadeInImage( disabledImage, 0.0f, 0 );
       StartFadeOutAnimation();
       StartFadeInAnimation();
 
@@ -651,8 +654,8 @@ void PushButton::OnDisabled( bool disabled )
       StopFadeOutAnimation();
       FadeOutImage( Background, disabledBackgroundImage );
       FadeOutImage( Foreground, disabledImage );
-      FadeInImage( backgroundImage );
-      FadeInImage( buttonImage );
+      FadeInImage( backgroundImage, 0.0f, 0 );
+      FadeInImage( buttonImage, 0.0f, 0 );
       StartFadeOutAnimation();
       StartFadeInAnimation();
 
@@ -674,8 +677,8 @@ void PushButton::OnDisabled( bool disabled )
       StopFadeOutAnimation();
       FadeOutImage( Background, disabledBackgroundImage );
       FadeOutImage( Foreground, disabledImage );
-      FadeInImage( backgroundImage );
-      FadeInImage( selectedImage );
+      FadeInImage( backgroundImage, 0.0f, 0 );
+      FadeInImage( selectedImage, 0.0f, 0 );
       StartFadeOutAnimation();
       StartFadeInAnimation();
 
@@ -705,8 +708,8 @@ void PushButton::OnDisabled( bool disabled )
       FadeOutImage( Foreground, selectedImage, 1.f - opacity );
       FadeOutImage( Background, backgroundImage );
 
-      FadeInImage( disabledImage );
-      FadeInImage( disabledBackgroundImage );
+      FadeInImage( disabledImage, 0.0f, 0 );
+      FadeInImage( disabledBackgroundImage, 0.0f, 0 );
 
       StartFadeOutAnimation();
       StartFadeInAnimation();
@@ -737,8 +740,8 @@ void PushButton::OnDisabled( bool disabled )
       FadeOutImage( Foreground, buttonImage, 1.f - opacity );
       FadeOutImage( Background, backgroundImage );
 
-      FadeInImage( disabledImage );
-      FadeInImage( disabledBackgroundImage );
+      FadeInImage( disabledImage, 0.0f, 0);
+      FadeInImage( disabledBackgroundImage, 0.0f, 0 );
 
       StartFadeOutAnimation();
       StartFadeInAnimation();
@@ -768,8 +771,8 @@ void PushButton::OnDisabled( bool disabled )
 
       FadeOutImage( Foreground, disabledImage, 1.f - opacity );
       FadeOutImage( Background, disabledBackgroundImage, 1.f - opacity );
-      FadeInImage( buttonImage, opacity );
-      FadeInImage( backgroundImage, opacity );
+      FadeInImage( buttonImage, opacity, 0 );
+      FadeInImage( backgroundImage, opacity, 0 );
 
       StartFadeOutAnimation();
       StartFadeInAnimation();
@@ -799,8 +802,8 @@ void PushButton::OnDisabled( bool disabled )
 
       FadeOutImage( Foreground, buttonImage, 1.f - opacity );
       FadeOutImage( Background, backgroundImage, 1.f - opacity );
-      FadeInImage( disabledImage, opacity );
-      FadeInImage( disabledBackgroundImage, opacity );
+      FadeInImage( disabledImage, opacity, 0 );
+      FadeInImage( disabledBackgroundImage, opacity, 0 );
 
       StartFadeOutAnimation();
       StartFadeInAnimation();
@@ -830,8 +833,8 @@ void PushButton::OnDisabled( bool disabled )
 
       FadeOutImage( Foreground, disabledImage, 1.f - opacity );
       FadeOutImage( Background, disabledBackgroundImage, 1.f - opacity );
-      FadeInImage( selectedImage, opacity );
-      FadeInImage( backgroundImage, opacity );
+      FadeInImage( selectedImage, opacity, 0 );
+      FadeInImage( backgroundImage, opacity, 0 );
 
       StartFadeOutAnimation();
       StartFadeInAnimation();
@@ -861,8 +864,8 @@ void PushButton::OnDisabled( bool disabled )
 
       FadeOutImage( Foreground, selectedImage, 1.f - opacity );
       FadeOutImage( Background, backgroundImage, 1.f - opacity );
-      FadeInImage( disabledImage, opacity );
-      FadeInImage( disabledBackgroundImage, opacity );
+      FadeInImage( disabledImage, opacity, 0 );
+      FadeInImage( disabledBackgroundImage, opacity, 0 );
 
       StartFadeOutAnimation();
       StartFadeInAnimation();
@@ -895,7 +898,7 @@ void PushButton::OnPressed()
     {
       StopFadeOutAnimation();
       FadeOutImage( Foreground, buttonImage );
-      FadeInImage( selectedImage );
+      FadeInImage( selectedImage, 0.0f, 0 );
       StartFadeOutAnimation();
       StartFadeInAnimation();
 
@@ -928,7 +931,7 @@ void PushButton::OnPressed()
       StopFadeInAnimation();
 
       FadeOutImage( Foreground, buttonImage, 1.f - opacity );
-      FadeInImage( selectedImage, opacity );
+      FadeInImage( selectedImage, opacity, 0 );
 
       StartFadeOutAnimation();
       StartFadeInAnimation();
@@ -960,7 +963,7 @@ void PushButton::OnReleased()
     {
       StopFadeOutAnimation();
       FadeOutImage( Foreground, selectedImage );
-      FadeInImage( buttonImage );
+      FadeInImage( buttonImage, 0.0f, 0 );
       StartFadeOutAnimation();
       StartFadeInAnimation();
 
@@ -985,7 +988,7 @@ void PushButton::OnReleased()
       StopFadeInAnimation();
 
       FadeOutImage( Foreground, selectedImage, 1.f - opacity );
-      FadeInImage( buttonImage, opacity );
+      FadeInImage( buttonImage, opacity, 0 );
 
       StartFadeOutAnimation();
       StartFadeInAnimation();
@@ -1040,7 +1043,7 @@ Vector3 PushButton::GetNaturalSize()
     ImageActor imageActor = FindImageActor( GetButtonImage() );
     if( imageActor && imageActor.GetStyle() != ImageActor::STYLE_NINE_PATCH )
     {
-      Vector3 imageSize = RelayoutHelper::GetNaturalSize( imageActor );
+      Vector3 imageSize = imageActor.GetNaturalSize();
 
       if( widthIsZero )
       {
@@ -1056,7 +1059,7 @@ Vector3 PushButton::GetNaturalSize()
     ImageActor backgroundImageActor = FindImageActor( GetBackgroundImage() );
     if( backgroundImageActor && backgroundImageActor.GetStyle() != ImageActor::STYLE_NINE_PATCH )
     {
-      Vector3 imageSize = RelayoutHelper::GetNaturalSize( backgroundImageActor );
+      Vector3 imageSize = backgroundImageActor.GetNaturalSize();
 
       if( widthIsZero )
       {
@@ -1158,14 +1161,21 @@ void PushButton::StopFadeOutAnimation( bool remove )
   }
 }
 
-void PushButton::FadeInImage( Actor& image, float opacity )
+void PushButton::FadeInImage( Actor& image, float opacity, int priority )
 {
   if( image )
   {
     image.SetOpacity( opacity );
     if( !image.GetParent() )
     {
-      Self().Add( image );
+      if( priority > -1 )
+      {
+        Self().Insert( priority, image );
+      }
+      else
+      {
+        Self().Add( image );
+      }
     }
 
     AddToFadeInAnimation( image );