Merge "Added TextLabel and TextField tests" into tizen
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / buttons / button-impl.cpp
index eef0cd8..d1f30bc 100644 (file)
 #include "button-impl.h"
 
 // EXTERNAL INCLUDES
+#include <cstring> // for strcmp
 #include <dali/public-api/events/touch-event.h>
 #include <dali/public-api/object/type-registry.h>
+#include <dali/public-api/object/type-registry-helper.h>
 #include <dali/public-api/actors/image-actor.h>
 #include <dali/public-api/scripting/scripting.h>
-#include <dali-toolkit/public-api/controls/text-view/text-view.h>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/public-api/controls/text-controls/text-label.h>
+
+/**
+ * Button states and contents
+ *                                         (3) mSelectedContent
+ *  (2) mButtonContent                     (2) mSelectedBackgroundContent
+ *  (1) mBackgroundContent                 (1) mBackgroundContent
+ * < unselected > ----------------------- < selected >
+ *       |                OnSelect()            |
+ *       | OnDisabled()                         | OnDisabled()
+ *       |                                      |
+ * < disabled >                           < disabled-selected >
+ *  (2) mDisabledContent                   (2) mDisabledSelectedContent
+ *  (1) mDisabledBackgroundContent         (1) mDisabledBackgroundContent
+ *
+ * The drawing order of child actors is as follows.
+ *
+ *  Top      mLabel
+ *   |       mButtonContent / mSelectedContent / mDisabledContent / mDisabledSelectedContent
+ *   |       mSelectedBackgroundContent
+ * Bottom    mBackgroundContent / mDisabledBackgroundContent
+ *
+ * Some of contents may be missed.
+ * And 2 images - fade-in image and fade-out image - in the same layer can be shown during the transition animation. Fade-in image should be above fade-out image.
+ */
 
 namespace Dali
 {
@@ -31,68 +59,59 @@ namespace Dali
 namespace Toolkit
 {
 
-const Property::Index Button::PROPERTY_DISABLED                     = Internal::Button::BUTTON_PROPERTY_START_INDEX;
-const Property::Index Button::PROPERTY_AUTO_REPEATING               = Internal::Button::BUTTON_PROPERTY_START_INDEX + 1;
-const Property::Index Button::PROPERTY_INITIAL_AUTO_REPEATING_DELAY = Internal::Button::BUTTON_PROPERTY_START_INDEX + 2;
-const Property::Index Button::PROPERTY_NEXT_AUTO_REPEATING_DELAY    = Internal::Button::BUTTON_PROPERTY_START_INDEX + 3;
-const Property::Index Button::PROPERTY_TOGGLABLE                    = Internal::Button::BUTTON_PROPERTY_START_INDEX + 4;
-const Property::Index Button::PROPERTY_SELECTED                     = Internal::Button::BUTTON_PROPERTY_START_INDEX + 5;
-const Property::Index Button::PROPERTY_NORMAL_STATE_ACTOR           = Internal::Button::BUTTON_PROPERTY_START_INDEX + 6;
-const Property::Index Button::PROPERTY_SELECTED_STATE_ACTOR         = Internal::Button::BUTTON_PROPERTY_START_INDEX + 7;
-const Property::Index Button::PROPERTY_DISABLED_STATE_ACTOR         = Internal::Button::BUTTON_PROPERTY_START_INDEX + 8;
-const Property::Index Button::PROPERTY_LABEL_ACTOR                  = Internal::Button::BUTTON_PROPERTY_START_INDEX + 9;
-
 namespace Internal
 {
 
 namespace
 {
 
-const unsigned int INITIAL_AUTOREPEATING_DELAY( 0.15f );
-const unsigned int NEXT_AUTOREPEATING_DELAY( 0.05f );
-
 BaseHandle Create()
 {
   // empty handle as we cannot create button (but type registered for clicked signal)
   return BaseHandle();
 }
 
-TypeRegistration typeRegistration( typeid(Toolkit::Button), typeid(Toolkit::Control), Create );
+// Setup properties, signals and actions using the type-registry.
+DALI_TYPE_REGISTRATION_BEGIN( Toolkit::Button, Toolkit::Control, Create );
 
-SignalConnectorType signalConnector1( typeRegistration, Toolkit::Button::SIGNAL_PRESSED , &Button::DoConnectSignal );
-SignalConnectorType signalConnector2( typeRegistration, Toolkit::Button::SIGNAL_RELEASED, &Button::DoConnectSignal );
-SignalConnectorType signalConnector3( typeRegistration, Toolkit::Button::SIGNAL_CLICKED, &Button::DoConnectSignal );
-SignalConnectorType signalConnector4( typeRegistration, Toolkit::Button::SIGNAL_STATE_CHANGED, &Button::DoConnectSignal );
+DALI_PROPERTY_REGISTRATION( Button, "disabled",                     BOOLEAN, DISABLED                     )
+DALI_PROPERTY_REGISTRATION( Button, "auto-repeating",               BOOLEAN, AUTO_REPEATING               )
+DALI_PROPERTY_REGISTRATION( Button, "initial-auto-repeating-delay", FLOAT,   INITIAL_AUTO_REPEATING_DELAY )
+DALI_PROPERTY_REGISTRATION( Button, "next-auto-repeating-delay",    FLOAT,   NEXT_AUTO_REPEATING_DELAY    )
+DALI_PROPERTY_REGISTRATION( Button, "togglable",                    BOOLEAN, TOGGLABLE                    )
+DALI_PROPERTY_REGISTRATION( Button, "selected",                     BOOLEAN, SELECTED                     )
+DALI_PROPERTY_REGISTRATION( Button, "normal-state-actor",           MAP,     NORMAL_STATE_ACTOR           )
+DALI_PROPERTY_REGISTRATION( Button, "selected-state-actor",         MAP,     SELECTED_STATE_ACTOR         )
+DALI_PROPERTY_REGISTRATION( Button, "disabled-state-actor",         MAP,     DISABLED_STATE_ACTOR         )
+DALI_PROPERTY_REGISTRATION( Button, "label-actor",                  MAP,     LABEL_ACTOR                  )
 
-TypeAction action1( typeRegistration, Toolkit::Button::ACTION_BUTTON_CLICK, &Button::DoAction );
+DALI_SIGNAL_REGISTRATION(   Button, "pressed",                               SIGNAL_PRESSED               )
+DALI_SIGNAL_REGISTRATION(   Button, "released",                              SIGNAL_RELEASED              )
+DALI_SIGNAL_REGISTRATION(   Button, "clicked",                               SIGNAL_CLICKED               )
+DALI_SIGNAL_REGISTRATION(   Button, "state-changed",                         SIGNAL_STATE_CHANGED         )
 
-PropertyRegistration property1( typeRegistration, "disabled",                     Toolkit::Button::PROPERTY_DISABLED,                     Property::BOOLEAN, &Button::SetProperty, &Button::GetProperty );
-PropertyRegistration property2( typeRegistration, "auto-repeating",               Toolkit::Button::PROPERTY_AUTO_REPEATING,               Property::BOOLEAN, &Button::SetProperty, &Button::GetProperty );
-PropertyRegistration property3( typeRegistration, "initial-auto-repeating-delay", Toolkit::Button::PROPERTY_INITIAL_AUTO_REPEATING_DELAY, Property::FLOAT,   &Button::SetProperty, &Button::GetProperty );
-PropertyRegistration property4( typeRegistration, "next-auto-repeating-delay",    Toolkit::Button::PROPERTY_NEXT_AUTO_REPEATING_DELAY,    Property::FLOAT,   &Button::SetProperty, &Button::GetProperty );
-PropertyRegistration property5( typeRegistration, "togglable",                    Toolkit::Button::PROPERTY_TOGGLABLE,                    Property::BOOLEAN, &Button::SetProperty, &Button::GetProperty );
-PropertyRegistration property6( typeRegistration, "selected",                     Toolkit::Button::PROPERTY_SELECTED,                     Property::BOOLEAN, &Button::SetProperty, &Button::GetProperty );
-PropertyRegistration property7( typeRegistration, "normal-state-actor",           Toolkit::Button::PROPERTY_NORMAL_STATE_ACTOR,           Property::MAP,     &Button::SetProperty, &Button::GetProperty );
-PropertyRegistration property8( typeRegistration, "selected-state-actor",         Toolkit::Button::PROPERTY_SELECTED_STATE_ACTOR,         Property::MAP,     &Button::SetProperty, &Button::GetProperty );
-PropertyRegistration property9( typeRegistration, "disabled-state-actor",         Toolkit::Button::PROPERTY_DISABLED_STATE_ACTOR,         Property::MAP,     &Button::SetProperty, &Button::GetProperty );
-PropertyRegistration property10( typeRegistration, "label-actor",                 Toolkit::Button::PROPERTY_LABEL_ACTOR,                  Property::MAP,     &Button::SetProperty, &Button::GetProperty );
+DALI_ACTION_REGISTRATION(   Button, "button-click",                          ACTION_BUTTON_CLICK          )
+
+DALI_TYPE_REGISTRATION_END()
+
+const unsigned int INITIAL_AUTOREPEATING_DELAY( 0.15f );
+const unsigned int NEXT_AUTOREPEATING_DELAY( 0.05f );
 
 } // unnamed namespace
 
 Button::Button()
 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ),
-  mTogglableButton( false ),
-  mSelected( false ),
-  mPainter( NULL ),
   mAutoRepeatingTimer(),
   mDisabled( false ),
   mAutoRepeating( false ),
-//  mTogglableButton( false ),
-//  mSelected( false ),
+  mTogglableButton( false ),
+  mSelected( false ),
   mInitialAutoRepeatingDelay( INITIAL_AUTOREPEATING_DELAY ),
   mNextAutoRepeatingDelay( NEXT_AUTOREPEATING_DELAY ),
+  mAnimationTime( 0.0f ),
   mClickActionPerforming( false ),
-  mState( ButtonUp )
+  mState( ButtonUp ),
+  mPaintState( UnselectedState )
 {
 }
 
@@ -106,13 +125,243 @@ Button::~Button()
 
 void Button::SetDisabled( bool disabled )
 {
-  mDisabled = disabled;
-
-  // Notifies the painter.
-  Toolkit::Button handle( GetOwner() );
-  if( mPainter )
+  if( disabled != mDisabled )
   {
-    mPainter->SetDisabled( handle, mDisabled );
+    unsigned int backgroundIndex;
+    unsigned int buttonIndex;
+
+    bool animationStarted = false;
+
+    mDisabled = disabled;
+
+    switch( mPaintState )
+    {
+      case UnselectedState:
+      {
+        buttonIndex = FindChildIndex( mLabel );
+        InsertChild( buttonIndex, mDisabledContent );
+
+        if( mBackgroundContent )
+        {
+          backgroundIndex = 1;
+        }
+        else
+        {
+          backgroundIndex = 0;
+        }
+
+        InsertChild( backgroundIndex, mDisabledBackgroundContent );
+
+        animationStarted = OnDisabled();
+
+        if( animationStarted )
+        {
+          mPaintState = UnselectedDisabledTransition;
+        }
+        else
+        {
+          mPaintState = DisabledUnselectedState;
+        }
+        break;
+      }
+      case SelectedState:
+      {
+        buttonIndex = FindChildIndex( mLabel );
+        InsertChild( buttonIndex, mDisabledSelectedContent );
+
+        if( mBackgroundContent )
+        {
+          backgroundIndex = 1;
+        }
+        else
+        {
+          backgroundIndex = 0;
+        }
+
+        InsertChild( backgroundIndex, mDisabledBackgroundContent );
+
+        animationStarted = OnDisabled();
+
+        if( animationStarted )
+        {
+          mPaintState = SelectedDisabledTransition;
+        }
+        else
+        {
+          mPaintState = DisabledSelectedState;
+        }
+        break;
+      }
+      case DisabledUnselectedState:
+      {
+        buttonIndex = FindChildIndex( mLabel );
+        InsertChild( buttonIndex, mButtonContent );
+
+        if( mDisabledBackgroundContent )
+        {
+          backgroundIndex = 1;
+        }
+        else
+        {
+          backgroundIndex = 0;
+        }
+
+        InsertChild( backgroundIndex, mBackgroundContent );
+
+        animationStarted = OnDisabled();
+
+        if( animationStarted )
+        {
+          mPaintState = DisabledUnselectedTransition;
+        }
+        else
+        {
+          mPaintState = UnselectedState;
+        }
+        break;
+      }
+      case DisabledSelectedState:
+      {
+        buttonIndex = FindChildIndex( mLabel );
+        InsertChild( buttonIndex, mSelectedContent );
+
+        if( mDisabledBackgroundContent )
+        {
+          backgroundIndex = 1;
+        }
+        else
+        {
+          backgroundIndex = 0;
+        }
+
+        InsertChild( backgroundIndex, mSelectedBackgroundContent );
+        InsertChild( backgroundIndex, mBackgroundContent );
+
+        animationStarted = OnDisabled();
+
+        if( animationStarted )
+        {
+          mPaintState = DisabledSelectedTransition;
+        }
+        else
+        {
+          mPaintState = SelectedState;
+        }
+        break;
+      }
+      case UnselectedSelectedTransition:
+      {
+        buttonIndex = FindChildIndex( mLabel );
+        InsertChild( buttonIndex, mDisabledSelectedContent );
+
+        if( mBackgroundContent )
+        {
+          backgroundIndex = 1;
+        }
+        else
+        {
+          backgroundIndex = 0;
+        }
+
+        InsertChild( backgroundIndex, mDisabledBackgroundContent );
+
+        animationStarted = OnDisabled();
+
+        if( animationStarted )
+        {
+          mPaintState = SelectedDisabledTransition;
+        }
+        else
+        {
+          mPaintState = DisabledSelectedState;
+        }
+        break;
+      }
+      case SelectedUnselectedTransition:
+      {
+        buttonIndex = FindChildIndex( mLabel );
+        InsertChild( buttonIndex, mDisabledContent );
+
+        if( mBackgroundContent )
+        {
+          backgroundIndex = 1;
+        }
+        else
+        {
+          backgroundIndex = 0;
+        }
+
+        InsertChild( backgroundIndex, mDisabledBackgroundContent );
+
+        animationStarted = OnDisabled();
+
+        if( animationStarted )
+        {
+          mPaintState = UnselectedDisabledTransition;
+        }
+        else
+        {
+          mPaintState = DisabledUnselectedState;
+        }
+        break;
+      }
+      case UnselectedDisabledTransition:
+      {
+        animationStarted = OnDisabled();
+
+        if( animationStarted )
+        {
+          mPaintState = DisabledUnselectedTransition;
+        }
+        else
+        {
+          mPaintState = UnselectedState;
+        }
+        break;
+      }
+      case DisabledUnselectedTransition:
+      {
+        animationStarted = OnDisabled();
+
+        if( animationStarted )
+        {
+          mPaintState = UnselectedDisabledTransition;
+        }
+        else
+        {
+          mPaintState = DisabledUnselectedState;
+        }
+        break;
+      }
+      case SelectedDisabledTransition:
+      {
+        animationStarted = OnDisabled();
+
+        if( animationStarted )
+        {
+          mPaintState = DisabledSelectedTransition;
+        }
+        else
+        {
+          mPaintState = SelectedState;
+        }
+        break;
+      }
+      case DisabledSelectedTransition:
+      {
+        animationStarted = OnDisabled();
+
+        if( animationStarted )
+        {
+          mPaintState = SelectedDisabledTransition;
+        }
+        else
+        {
+          mPaintState = DisabledSelectedState;
+        }
+        break;
+      }
+    }
   }
 }
 
@@ -129,17 +378,13 @@ void Button::SetAutoRepeating( bool autoRepeating )
   if( autoRepeating )
   {
     mTogglableButton = false;
+
     if( mSelected )
     {
       // Emit a signal is not wanted, only change the appearance.
-      Toolkit::Button handle( GetOwner() );
-      mPainter->Selected( handle );
-      mSelected = false;
+      SetSelected( false, false );
     }
   }
-
-  // Notifies the painter.
-  mPainter->SetAutoRepeating( mAutoRepeating );
 }
 
 bool Button::IsAutoRepeating() const
@@ -177,9 +422,6 @@ void Button::SetTogglableButton( bool togglable )
   if( togglable )
   {
     mAutoRepeating = false;
-
-    // Notifies the painter.
-    mPainter->SetAutoRepeating( mAutoRepeating );
   }
 }
 
@@ -192,16 +434,169 @@ void Button::SetSelected( bool selected )
 {
   if( !mDisabled && mTogglableButton && ( selected != mSelected ) )
   {
-    mSelected = selected;
+    SetSelected( selected, true );
+  }
+}
 
-    Toolkit::Button handle( GetOwner() );
+void Button::SetSelected( bool selected, bool emitSignal )
+{
+  unsigned int buttonIndex, backgroundIndex;
+  bool animationStarted = false;
+
+  mSelected = selected;
+
+  switch( mPaintState )
+  {
+    case UnselectedState:
+    {
+      buttonIndex = FindChildIndex( mLabel );
+      InsertChild( buttonIndex, mSelectedContent );
+
+      if( mBackgroundContent )
+      {
+        backgroundIndex = 1;
+      }
+      else
+      {
+        backgroundIndex = 0;
+      }
 
-    // Notifies the painter the button has been selected.
-    mPainter->Selected( handle );
+      InsertChild( backgroundIndex, mSelectedBackgroundContent );
+
+      // Notifies the derived class the button has been selected.
+      animationStarted = OnSelected();
+
+      if( animationStarted )
+      {
+        mPaintState = UnselectedSelectedTransition;
+      }
+      else
+      {
+        mPaintState = SelectedState;
+      }
+      break;
+    }
+    case SelectedState:
+    {
+      buttonIndex = FindChildIndex( mLabel );
+      InsertChild( buttonIndex, mButtonContent );
+
+      // Notifies the derived class the button has been selected.
+      animationStarted = OnSelected();
+
+      if( animationStarted )
+      {
+        mPaintState = SelectedUnselectedTransition;
+      }
+      else
+      {
+        mPaintState = UnselectedState;
+      }
+      break;
+    }
+    case UnselectedSelectedTransition:
+    {
+      // Notifies the derived class the button has been selected.
+      animationStarted = OnSelected();
+
+      if( animationStarted )
+      {
+        mPaintState = SelectedUnselectedTransition;
+      }
+      else
+      {
+        mPaintState = UnselectedState;
+      }
+      break;
+    }
+    case SelectedUnselectedTransition:
+    {
+      // Notifies the derived class the button has been selected.
+      animationStarted = OnSelected();
+
+      if( animationStarted )
+      {
+        mPaintState = UnselectedSelectedTransition;
+      }
+      else
+      {
+        mPaintState = SelectedState;
+      }
+      break;
+    }
+    case DisabledUnselectedTransition:
+    {
+      buttonIndex = FindChildIndex( mLabel );
+      InsertChild( buttonIndex, mSelectedContent );
+
+      if( mDisabledBackgroundContent )
+      {
+        if(  mBackgroundContent )
+        {
+          backgroundIndex = 2;
+        }
+        else
+        {
+          backgroundIndex = 1;
+        }
+      }
+      else if( mBackgroundContent )
+      {
+        backgroundIndex = 1;
+      }
+      else
+      {
+        backgroundIndex = 0;
+      }
+
+      InsertChild( backgroundIndex, mSelectedBackgroundContent );
+
+      // Notifies the derived class the button has been selected.
+      animationStarted = OnSelected();
+
+      if( animationStarted )
+      {
+        mPaintState = UnselectedSelectedTransition;
+      }
+      else
+      {
+        mPaintState = SelectedState;
+      }
+      break;
+    }
+    case DisabledSelectedTransition:
+    {
+      buttonIndex = FindChildIndex( mLabel );
+      InsertChild( buttonIndex, mButtonContent );
+
+      // Notifies the derived class the button has been selected.
+      animationStarted = OnSelected();
+
+      if( animationStarted )
+      {
+        mPaintState = SelectedUnselectedTransition;
+      }
+      else
+      {
+        mPaintState = UnselectedState;
+      }
+      break;
+    }
+    default:
+    {
+      break;
+    }
+  }
+
+  if( emitSignal )
+  {
+    Toolkit::Button handle( GetOwner() );
 
     // Emit signal.
     mStateChangedSignal.Emit( handle );
   }
+
+  RelayoutRequest();
 }
 
 bool Button::IsSelected() const
@@ -211,28 +606,39 @@ bool Button::IsSelected() const
 
 void Button::SetAnimationTime( float animationTime )
 {
-  OnAnimationTimeSet( animationTime );
+  mAnimationTime = animationTime;
 }
 
 float Button::GetAnimationTime() const
 {
-  return OnAnimationTimeRequested();
+  return mAnimationTime;
 }
 
 void Button::SetLabel( const std::string& label )
 {
-  Toolkit::TextView textView = Toolkit::TextView::New( label );
-  textView.SetWidthExceedPolicy( Toolkit::TextView::ShrinkToFit ); // Make sure our text always fits inside the button
-  SetLabel( textView );
-
-  RelayoutRequest();
+  Toolkit::TextLabel textLabel = Toolkit::TextLabel::New( label );
+  SetLabel( textLabel );
 }
 
 void Button::SetLabel( Actor label )
 {
-  Toolkit::Button handle( GetOwner() );
+  if( mLabel != label )
+  {
+    if( mLabel && mLabel.GetParent() )
+    {
+      mLabel.GetParent().Remove( mLabel );
+    }
+
+    mLabel = label;
+    mLabel.SetPosition( 0.f, 0.f );
+
+    // label should be the top of the button
+    Self().Add( mLabel );
+
+    OnLabelSet();
 
-  mPainter->SetLabel( handle, label );
+    RelayoutRequest();
+  }
 }
 
 Actor Button::GetLabel() const
@@ -245,145 +651,250 @@ Actor& Button::GetLabel()
   return mLabel;
 }
 
-void Button::SetButtonImage( Image image )
-{
-  SetButtonImage( ImageActor::New( image ) );
-}
-
 void Button::SetButtonImage( Actor image )
 {
-  Toolkit::Button handle( GetOwner() );
-  mPainter->SetButtonImage( handle, image );
+  StopAllAnimations();
+
+  if( mButtonContent && mButtonContent.GetParent() )
+  {
+    Self().Remove( mButtonContent );
+  }
+
+  mButtonContent = image;
+
+  mButtonContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+  mButtonContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
+  mButtonContent.SetPosition( 0.f, 0.f );
+
+  if( mPaintState == UnselectedState )
+  {
+    unsigned int index = FindChildIndex( mLabel );
+
+    Self().Insert( index, mButtonContent );
+  }
+
+  OnButtonImageSet();
 }
 
 Actor Button::GetButtonImage() const
 {
-  return mButtonImage;
+  return mButtonContent;
 }
 
 Actor& Button::GetButtonImage()
 {
-  return mButtonImage;
-}
-
-void Button::SetSelectedImage( Image image )
-{
-  SetSelectedImage( ImageActor::New( image ) );
+  return mButtonContent;
 }
 
 void Button::SetSelectedImage( Actor image )
 {
-  Toolkit::Button handle( GetOwner() );
-  mPainter->SetSelectedImage( handle, image );
+  StopAllAnimations();
+
+  if( mSelectedContent && mSelectedContent.GetParent() )
+  {
+    Self().Remove( mSelectedContent );
+  }
+
+  mSelectedContent = image;
+
+  mSelectedContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+  mSelectedContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
+  mSelectedContent.SetPosition( 0.f, 0.f );
+
+  if( mPaintState == SelectedState )
+  {
+    unsigned int index = FindChildIndex( mLabel );
+
+    Self().Insert( index, mSelectedContent );
+  }
+
+  OnSelectedImageSet();
 }
 
 Actor Button::GetSelectedImage() const
 {
-  return mSelectedImage;
+  return mSelectedContent;
 }
 
 Actor& Button::GetSelectedImage()
 {
-  return mSelectedImage;
-}
-
-void Button::SetBackgroundImage( Image image )
-{
-  SetBackgroundImage( ImageActor::New( image ) );
+  return mSelectedContent;
 }
 
 void Button::SetBackgroundImage( Actor image )
 {
-  Toolkit::Button handle( GetOwner() );
-  mPainter->SetBackgroundImage( handle, image );
+  StopAllAnimations();
+
+  if( mBackgroundContent && mBackgroundContent.GetParent() )
+  {
+    Self().Remove( mBackgroundContent );
+  }
+
+  mBackgroundContent = image;
+
+  mBackgroundContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+  mBackgroundContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
+  mBackgroundContent.SetPosition( 0.f, 0.f );
+
+  if( mPaintState == UnselectedState || mPaintState == SelectedState )
+  {
+    Self().Insert( 0, mBackgroundContent );
+  }
+
+  OnBackgroundImageSet();
 }
 
 Actor Button::GetBackgroundImage() const
 {
-  return mBackgroundImage;
+  return mBackgroundContent;
 }
 
 Actor& Button::GetBackgroundImage()
 {
-  return mBackgroundImage;
+  return mBackgroundContent;
+}
+
+void Button::SetSelectedBackgroundImage( Actor image )
+{
+  StopAllAnimations();
+
+  if( mSelectedBackgroundContent && mSelectedBackgroundContent.GetParent() )
+  {
+    Self().Remove( mSelectedBackgroundContent );
+  }
+
+  mSelectedBackgroundContent = image;
+
+  mSelectedBackgroundContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+  mSelectedBackgroundContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
+  mSelectedBackgroundContent.SetPosition( 0.f, 0.f );
+
+  if( mPaintState == SelectedState )
+  {
+    if( mBackgroundContent )
+    {
+      Self().Insert( 1, mSelectedBackgroundContent );
+    }
+    else
+    {
+      Self().Insert( 0, mSelectedBackgroundContent );
+    }
+  }
+
+  OnSelectedBackgroundImageSet();
+}
+
+Actor Button::GetSelectedBackgroundImage() const
+{
+  return mSelectedBackgroundContent;
 }
 
-void Button::SetDisabledImage( Image image )
+Actor& Button::GetSelectedBackgroundImage()
 {
-  SetDisabledImage( ImageActor::New( image ) );
+  return mSelectedBackgroundContent;
 }
 
 void Button::SetDisabledImage( Actor image )
 {
-  Toolkit::Button handle( GetOwner() );
-  mPainter->SetDisabledImage( handle, image );
+  StopAllAnimations();
+
+  if( mDisabledContent && mDisabledContent.GetParent() )
+  {
+    Self().Remove( mDisabledContent );
+  }
+
+  mDisabledContent = image;
+
+  mDisabledContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+  mDisabledContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
+  mDisabledContent.SetPosition( 0.f, 0.f );
+
+  if( mPaintState == DisabledUnselectedState || mPaintState == DisabledSelectedState )
+  {
+    unsigned int index = FindChildIndex( mLabel );
+
+    Self().Insert( index, mDisabledContent );
+  }
+
+  OnDisabledImageSet();
 }
 
 Actor Button::GetDisabledImage() const
 {
-  return mDisabledImage;
+  return mDisabledContent;
 }
 
 Actor& Button::GetDisabledImage()
 {
-  return mDisabledImage;
-}
-
-void Button::SetDisabledSelectedImage( Image image )
-{
-  SetDisabledSelectedImage( ImageActor::New( image ) );
+  return mDisabledContent;
 }
 
 void Button::SetDisabledSelectedImage( Actor image )
 {
-  Toolkit::Button handle( GetOwner() );
-  mPainter->SetDisabledSelectedImage( handle, image );
+  StopAllAnimations();
+
+  if( mDisabledSelectedContent && mDisabledSelectedContent.GetParent() )
+  {
+    Self().Remove( mDisabledSelectedContent );
+  }
+
+  mDisabledSelectedContent = image;
+
+  mDisabledSelectedContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+  mDisabledSelectedContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
+  mDisabledSelectedContent.SetPosition( 0.f, 0.f );
+
+  if( mPaintState == DisabledSelectedState )
+  {
+    unsigned int index = FindChildIndex( mLabel );
+
+    Self().Insert( index, mDisabledSelectedContent );
+  }
+
+  OnDisabledSelectedImageSet();
 }
 
 Actor Button::GetDisabledSelectedImage() const
 {
-  return mDisabledSelectedImage;
+  return mDisabledSelectedContent;
 }
 
 Actor& Button::GetDisabledSelectedImage()
 {
-  return mDisabledSelectedImage;
-}
-
-void Button::SetDisabledBackgroundImage( Image image )
-{
-  SetDisabledBackgroundImage( ImageActor::New( image ) );
+  return mDisabledSelectedContent;
 }
 
 void Button::SetDisabledBackgroundImage( Actor image )
 {
-  Toolkit::Button handle( GetOwner() );
-  mPainter->SetDisabledBackgroundImage( handle, image );
-}
+  StopAllAnimations();
 
-Actor Button::GetDisabledBackgroundImage() const
-{
-  return mDisabledBackgroundImage;
-}
+  if( mDisabledBackgroundContent && mDisabledBackgroundContent.GetParent() )
+  {
+    Self().Remove( mDisabledBackgroundContent );
+  }
 
-Actor& Button::GetDisabledBackgroundImage()
-{
-  return mDisabledBackgroundImage;
-}
+  mDisabledBackgroundContent = image;
 
-Actor& Button::GetFadeOutButtonImage()
-{
-  return mFadeOutButtonImage;
+  mDisabledBackgroundContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+  mDisabledBackgroundContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
+  mDisabledBackgroundContent.SetPosition( 0.f, 0.f );
+
+  if( mPaintState == DisabledUnselectedState || mPaintState == DisabledSelectedState )
+  {
+    Self().Insert( 0, mDisabledBackgroundContent );
+  }
+
+  OnDisabledBackgroundImageSet();
 }
 
-Actor& Button::GetFadeOutSelectedImage()
+Actor Button::GetDisabledBackgroundImage() const
 {
-  return mFadeOutSelectedImage;
+  return mDisabledBackgroundContent;
 }
 
-Actor& Button::GetFadeOutBackgroundImage()
+Actor& Button::GetDisabledBackgroundImage()
 {
-  return mFadeOutBackgroundImage;
+  return mDisabledBackgroundContent;
 }
 
 bool Button::DoAction( BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes )
@@ -396,7 +907,7 @@ bool Button::DoAction( BaseObject* object, const std::string& actionName, const
 
   DALI_ASSERT_ALWAYS( button );
 
-  if( Toolkit::Button::ACTION_BUTTON_CLICK == actionName )
+  if( 0 == strcmp( actionName.c_str(), ACTION_BUTTON_CLICK ) )
   {
     GetImplementation( button ).DoClickAction( attributes );
     ret = true;
@@ -419,14 +930,57 @@ void Button::DoClickAction( const PropertyValueContainer& attributes )
   }
 }
 
-void Button::OnAnimationTimeSet( float animationTime )
-{
-  mPainter->SetAnimationTime( animationTime );
-}
-
-float Button::OnAnimationTimeRequested() const
+void Button::UpdatePaintTransitionState()
 {
-  return mPainter->GetAnimationTime();
+  switch( mPaintState )
+  {
+    case UnselectedSelectedTransition:
+    {
+      RemoveChild( mButtonContent );
+      mPaintState = SelectedState;
+      break;
+    }
+    case SelectedUnselectedTransition:
+    {
+      RemoveChild( mSelectedBackgroundContent );
+      RemoveChild( mSelectedContent );
+      mPaintState = UnselectedState;
+      break;
+    }
+    case UnselectedDisabledTransition:
+    {
+      RemoveChild( mBackgroundContent );
+      RemoveChild( mButtonContent );
+      mPaintState = DisabledUnselectedState;
+      break;
+    }
+    case DisabledUnselectedTransition:
+    {
+      RemoveChild( mDisabledBackgroundContent );
+      RemoveChild( mDisabledContent );
+      mPaintState = UnselectedState;
+      break;
+    }
+    case SelectedDisabledTransition:
+    {
+      RemoveChild( mBackgroundContent );
+      RemoveChild( mSelectedBackgroundContent );
+      RemoveChild( mSelectedContent );
+      mPaintState = DisabledSelectedState;
+      break;
+    }
+    case DisabledSelectedTransition:
+    {
+      RemoveChild( mDisabledBackgroundContent );
+      RemoveChild( mDisabledSelectedContent );
+      mPaintState = SelectedState;
+      break;
+    }
+    default:
+    {
+      break;
+    }
+  }
 }
 
 void Button::OnButtonStageDisconnection()
@@ -435,10 +989,7 @@ void Button::OnButtonStageDisconnection()
   {
     if( !mTogglableButton )
     {
-      Toolkit::Button handle( GetOwner() );
-
-      // Notifies the painter the button has been released.
-      mPainter->Released( handle );
+      Released();
 
       if( mAutoRepeating )
       {
@@ -454,8 +1005,7 @@ void Button::OnButtonDown()
   {
     Toolkit::Button handle( GetOwner() );
 
-    // Notifies the painter the button has been pressed.
-    mPainter->Pressed( handle );
+    Pressed();
 
     if( mAutoRepeating )
     {
@@ -477,17 +1027,15 @@ void Button::OnButtonUp()
     }
     else
     {
-      Toolkit::Button handle( GetOwner() );
-
-      // Notifies the painter the button has been clicked.
-      mPainter->Released( handle );
-      mPainter->Clicked( handle );
+      Released();
 
       if( mAutoRepeating )
       {
         mAutoRepeatingTimer.Reset();
       }
 
+      Toolkit::Button handle( GetOwner() );
+
       //Emit signal.
       mReleasedSignal.Emit( handle );
       mClickedSignal.Emit( handle );
@@ -503,8 +1051,7 @@ void Button::OnTouchPointLeave()
     {
       Toolkit::Button handle( GetOwner() );
 
-      // Notifies the painter the button has been released.
-      mPainter->Released( handle );
+      Released();
 
       if( mAutoRepeating )
       {
@@ -547,21 +1094,21 @@ bool Button::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tr
   Dali::BaseHandle handle( object );
 
   bool connected( true );
-  Toolkit::Button button = Toolkit::Button::DownCast(handle);
+  Toolkit::Button button = Toolkit::Button::DownCast( handle );
 
-  if( Toolkit::Button::SIGNAL_PRESSED == signalName )
+  if( 0 == strcmp( signalName.c_str(), SIGNAL_PRESSED ) )
   {
     button.PressedSignal().Connect( tracker, functor );
   }
-  else if( Toolkit::Button::SIGNAL_RELEASED == signalName )
+  else if( 0 == strcmp( signalName.c_str(), SIGNAL_RELEASED ) )
   {
     button.ReleasedSignal().Connect( tracker, functor );
   }
-  else if( Dali::Toolkit::Button::SIGNAL_CLICKED == signalName )
+  else if( 0 == strcmp( signalName.c_str(), SIGNAL_CLICKED ) )
   {
     button.ClickedSignal().Connect( tracker, functor );
   }
-  else if( Dali::Toolkit::Button::SIGNAL_STATE_CHANGED == signalName )
+  else if( 0 == strcmp( signalName.c_str(), SIGNAL_STATE_CHANGED ) )
   {
     button.StateChangedSignal().Connect( tracker, functor );
   }
@@ -640,13 +1187,6 @@ bool Button::OnTouchEvent(const TouchEvent& event)
 
 void Button::OnInitialize()
 {
-  // Initialize the painter and notifies subclasses.
-  Toolkit::Button handle( GetOwner() );
-  if( mPainter )
-  {
-    mPainter->Initialize( handle );
-  }
-
   Actor self = Self();
 
   mTapDetector = TapGestureDetector::New();
@@ -655,6 +1195,7 @@ void Button::OnInitialize()
 
   OnButtonInitialize();
 
+  self.SetDrawMode( DrawMode::OVERLAY );
   self.SetKeyboardFocusable( true );
 }
 
@@ -665,13 +1206,10 @@ void Button::OnActivated()
   DoClickAction( attributes );
 }
 
-void Button::OnControlSizeSet(const Vector3& targetSize)
+void Button::OnControlStageDisconnection()
 {
-  Toolkit::Button handle( GetOwner() );
-  if( mPainter )
-  {
-    mPainter->SetSize( handle, targetSize );
-  }
+  OnButtonStageDisconnection(); // Notification for derived classes.
+  mState = ButtonUp;
 }
 
 void Button::OnTap(Actor actor, const TapGesture& tap)
@@ -694,10 +1232,9 @@ bool Button::AutoRepeatingSlot()
     // Restart the autorepeat timer.
     SetUpTimer( mNextAutoRepeatingDelay );
 
-    Toolkit::Button handle( GetOwner() );
+    Pressed();
 
-    // Notifies the painter the button has been pressed.
-    mPainter->Pressed( handle );
+    Toolkit::Button handle( GetOwner() );
 
     //Emit signal.
     consumed = mReleasedSignal.Emit( handle );
@@ -708,15 +1245,165 @@ bool Button::AutoRepeatingSlot()
   return consumed;
 }
 
-void Button::OnControlStageDisconnection()
+void Button::Pressed()
 {
-  OnButtonStageDisconnection(); // Notification for derived classes.
-  mState = ButtonUp;
+  unsigned int buttonIndex, backgroundIndex;
+  bool animationStarted = false;
+
+  switch( mPaintState )
+  {
+    case UnselectedState:
+    {
+      buttonIndex = FindChildIndex( mLabel );
+      InsertChild( buttonIndex, mSelectedContent );
+
+      if( mBackgroundContent )
+      {
+        backgroundIndex = 1;
+      }
+      else
+      {
+        backgroundIndex = 0;
+      }
+
+      InsertChild( backgroundIndex, mSelectedBackgroundContent );
+
+      // Notifies the derived class the button has been pressed.
+      animationStarted = OnPressed();
+
+      if( animationStarted )
+      {
+        mPaintState = UnselectedSelectedTransition;
+      }
+      else
+      {
+        mPaintState = SelectedState;
+      }
+      break;
+    }
+    case SelectedUnselectedTransition:
+    {
+      // Notifies the derived class the button has been pressed.
+      animationStarted = OnPressed();
+
+      if( animationStarted )
+      {
+        mPaintState = UnselectedSelectedTransition;
+      }
+      else
+      {
+        mPaintState = SelectedState;
+      }
+      break;
+    }
+    case DisabledUnselectedTransition:
+    {
+      buttonIndex = FindChildIndex( mLabel );
+      InsertChild( buttonIndex, mSelectedContent );
+
+      if( mDisabledBackgroundContent )
+      {
+        if(  mBackgroundContent )
+        {
+          backgroundIndex = 2;
+        }
+        else
+        {
+          backgroundIndex = 1;
+        }
+      }
+      else if( mBackgroundContent )
+      {
+        backgroundIndex = 1;
+      }
+      else
+      {
+        backgroundIndex = 0;
+      }
+
+      InsertChild( backgroundIndex, mSelectedBackgroundContent );
+
+      // Notifies the derived class the button has been pressed.
+      animationStarted = OnPressed();
+
+      if( animationStarted )
+      {
+        mPaintState = UnselectedSelectedTransition;
+      }
+      else
+      {
+        mPaintState = SelectedState;
+      }
+      break;
+    }
+    default:
+      break;
+  }
 }
 
-void Button::SetPainter(ButtonPainterPtr painter)
+void Button::Released()
 {
-  mPainter = painter;
+  unsigned int buttonIndex;
+  bool animationStarted = false;
+
+  switch( mPaintState )
+  {
+    case SelectedState:
+    {
+      buttonIndex = FindChildIndex( mLabel );
+      InsertChild( buttonIndex, mButtonContent );
+
+      // Notifies the derived class the button has been released.
+      animationStarted = OnReleased();
+
+      if( animationStarted )
+      {
+        mPaintState = SelectedUnselectedTransition;
+      }
+      else
+      {
+        mPaintState = UnselectedState;
+      }
+      break;
+    }
+    case UnselectedSelectedTransition:
+    {
+      // Notifies the derived class the button has been released.
+      animationStarted = OnReleased();
+
+      if( animationStarted )
+      {
+        mPaintState = SelectedUnselectedTransition;
+      }
+      else
+      {
+        mPaintState = UnselectedState;
+      }
+      break;
+    }
+    case DisabledSelectedTransition:
+    {
+      buttonIndex = FindChildIndex( mLabel );
+      InsertChild( buttonIndex, mButtonContent );
+
+      // Notifies the derived class the button has been released.
+      animationStarted = OnReleased();
+
+      if( animationStarted )
+      {
+        mPaintState = SelectedUnselectedTransition;
+      }
+      else
+      {
+        mPaintState = UnselectedState;
+      }
+      break;
+    }
+    default:
+    {
+      break;
+    }
+  }
 }
 
 Button::ButtonState Button::GetState()
@@ -724,6 +1411,44 @@ Button::ButtonState Button::GetState()
   return mState;
 }
 
+Button::PaintState Button::GetPaintState()
+{
+  return mPaintState;
+}
+
+void Button::InsertChild( unsigned int index, Actor& actor )
+{
+  if( actor )
+  {
+    Self().Insert( index, actor);
+  }
+}
+
+void Button::RemoveChild( Actor& actor )
+{
+  if( actor && actor.GetParent() )
+  {
+    Self().Remove( actor );
+  }
+}
+
+unsigned int Button::FindChildIndex( Actor& actor )
+{
+  Actor self = Self();
+  unsigned int childrenNum = self.GetChildCount();
+
+  for( unsigned int i = 0; i < childrenNum; i++ )
+  {
+    Actor child = self.GetChildAt( i );
+    if( child == actor )
+    {
+      return i;
+    }
+  }
+
+  return childrenNum;
+}
+
 void Button::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
 {
   Toolkit::Button button = Toolkit::Button::DownCast( Dali::BaseHandle( object ) );
@@ -732,61 +1457,61 @@ void Button::SetProperty( BaseObject* object, Property::Index index, const Prope
   {
     switch ( index )
     {
-      case Toolkit::Button::PROPERTY_DISABLED:
+      case Toolkit::Button::Property::DISABLED:
       {
         GetImplementation( button ).SetDisabled( value.Get<bool>() );
         break;
       }
 
-      case Toolkit::Button::PROPERTY_AUTO_REPEATING:
+      case Toolkit::Button::Property::AUTO_REPEATING:
       {
         GetImplementation( button ).SetAutoRepeating( value.Get< bool >() );
         break;
       }
 
-      case Toolkit::Button::PROPERTY_INITIAL_AUTO_REPEATING_DELAY:
+      case Toolkit::Button::Property::INITIAL_AUTO_REPEATING_DELAY:
       {
         GetImplementation( button ).SetInitialAutoRepeatingDelay( value.Get< float >() );
         break;
       }
 
-      case Toolkit::Button::PROPERTY_NEXT_AUTO_REPEATING_DELAY:
+      case Toolkit::Button::Property::NEXT_AUTO_REPEATING_DELAY:
       {
         GetImplementation( button ).SetNextAutoRepeatingDelay( value.Get< float >() );
         break;
       }
 
-      case Toolkit::Button::PROPERTY_TOGGLABLE:
+      case Toolkit::Button::Property::TOGGLABLE:
       {
         GetImplementation( button ).SetTogglableButton( value.Get< bool >() );
         break;
       }
 
-      case Toolkit::Button::PROPERTY_SELECTED:
+      case Toolkit::Button::Property::SELECTED:
       {
         GetImplementation( button ).SetSelected( value.Get< bool >() );
         break;
       }
 
-      case Toolkit::Button::PROPERTY_NORMAL_STATE_ACTOR:
+      case Toolkit::Button::Property::NORMAL_STATE_ACTOR:
       {
         GetImplementation( button ).SetButtonImage( Scripting::NewActor( value.Get< Property::Map >() ) );
         break;
       }
 
-      case Toolkit::Button::PROPERTY_SELECTED_STATE_ACTOR:
+      case Toolkit::Button::Property::SELECTED_STATE_ACTOR:
       {
         GetImplementation( button ).SetSelectedImage( Scripting::NewActor( value.Get< Property::Map >() ) );
         break;
       }
 
-      case Toolkit::Button::PROPERTY_DISABLED_STATE_ACTOR:
+      case Toolkit::Button::Property::DISABLED_STATE_ACTOR:
       {
         GetImplementation( button ).SetDisabledImage( Scripting::NewActor( value.Get< Property::Map >() ) );
         break;
       }
 
-      case Toolkit::Button::PROPERTY_LABEL_ACTOR:
+      case Toolkit::Button::Property::LABEL_ACTOR:
       {
         GetImplementation( button ).SetLabel( Scripting::NewActor( value.Get< Property::Map >() ) );
         break;
@@ -805,67 +1530,67 @@ Property::Value Button::GetProperty( BaseObject* object, Property::Index propert
   {
     switch ( propertyIndex )
     {
-      case Toolkit::Button::PROPERTY_DISABLED:
+      case Toolkit::Button::Property::DISABLED:
       {
         value = GetImplementation( button ).mDisabled;
         break;
       }
 
-      case Toolkit::Button::PROPERTY_AUTO_REPEATING:
+      case Toolkit::Button::Property::AUTO_REPEATING:
       {
         value = GetImplementation( button ).mAutoRepeating;
         break;
       }
 
-      case Toolkit::Button::PROPERTY_INITIAL_AUTO_REPEATING_DELAY:
+      case Toolkit::Button::Property::INITIAL_AUTO_REPEATING_DELAY:
       {
         value = GetImplementation( button ).mInitialAutoRepeatingDelay;
         break;
       }
 
-      case Toolkit::Button::PROPERTY_NEXT_AUTO_REPEATING_DELAY:
+      case Toolkit::Button::Property::NEXT_AUTO_REPEATING_DELAY:
       {
         value = GetImplementation( button ).mNextAutoRepeatingDelay;
         break;
       }
 
-      case Toolkit::Button::PROPERTY_TOGGLABLE:
+      case Toolkit::Button::Property::TOGGLABLE:
       {
         value = GetImplementation( button ).mTogglableButton;
         break;
       }
 
-      case Toolkit::Button::PROPERTY_SELECTED:
+      case Toolkit::Button::Property::SELECTED:
       {
         value = GetImplementation( button ).mSelected;
         break;
       }
 
-      case Toolkit::Button::PROPERTY_NORMAL_STATE_ACTOR:
+      case Toolkit::Button::Property::NORMAL_STATE_ACTOR:
       {
         Property::Map map;
-        Scripting::CreatePropertyMap( GetImplementation( button ).mButtonImage, map );
+        Scripting::CreatePropertyMap( GetImplementation( button ).mButtonContent, map );
         value = map;
         break;
       }
 
-      case Toolkit::Button::PROPERTY_SELECTED_STATE_ACTOR:
+      case Toolkit::Button::Property::SELECTED_STATE_ACTOR:
       {
         Property::Map map;
-        Scripting::CreatePropertyMap( GetImplementation( button ).mSelectedImage, map );
+        Scripting::CreatePropertyMap( GetImplementation( button ).mSelectedContent, map );
         value = map;
         break;
       }
 
-      case Toolkit::Button::PROPERTY_DISABLED_STATE_ACTOR:
+      case Toolkit::Button::Property::DISABLED_STATE_ACTOR:
       {
         Property::Map map;
-        Scripting::CreatePropertyMap( GetImplementation( button ).mDisabledImage, map );
+        Scripting::CreatePropertyMap( GetImplementation( button ).mDisabledContent, map );
         value = map;
         break;
       }
 
-      case Toolkit::Button::PROPERTY_LABEL_ACTOR:
+      case Toolkit::Button::Property::LABEL_ACTOR:
       {
         Property::Map map;
         Scripting::CreatePropertyMap( GetImplementation( button ).mLabel, map );