+Button::PaintState Button::GetPaintState()
+{
+ return mPaintState;
+}
+
+void Button::PrepareAddButtonImage( Actor& actor )
+{
+ if( actor )
+ {
+ Self().Add( actor );
+ PrepareForTranstionOut( actor );
+ }
+}
+
+void Button::TransitionButtonImage( Actor& actor )
+{
+ if( actor )
+ {
+ if( !actor.GetParent() )
+ {
+ Self().Add( actor );
+ }
+
+ OnTransitionIn( actor );
+ }
+}
+
+void Button::AddButtonImage( Actor& actor )
+{
+ if( actor )
+ {
+ Self().Add( actor );
+ }
+}
+
+void Button::ReAddLabel()
+{
+ if( mLabel )
+ {
+ mLabel.Unparent();
+ Self().Add( mLabel );
+ }
+}
+
+void Button::RemoveButtonImage( Actor& actor )
+{
+ if( actor )
+ {
+ if( actor.GetParent() )
+ {
+ Self().Remove( actor );
+ }
+ PrepareForTranstionIn( 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::TransitionOut( Actor actor )
+{
+ OnTransitionOut( actor );
+}
+
+void Button::ResetImageLayers()
+{
+ // Ensure that all layers are in the correct order and state according to the paint state
+
+ switch( mPaintState )
+ {
+ case UnselectedState:
+ {
+ //Layer Order
+ //(2) mUnselectedContent
+ //(1) mBackgroundContent
+
+ RemoveButtonImage( mDecoration[ SELECTED_DECORATION ] );
+ RemoveButtonImage( mSelectedContent );
+ RemoveButtonImage( mSelectedBackgroundContent );
+ RemoveButtonImage( mDisabledContent );
+ RemoveButtonImage( mDisabledSelectedContent );
+ RemoveButtonImage( mDisabledBackgroundContent );
+
+ PrepareAddButtonImage( mBackgroundContent );
+ PrepareAddButtonImage( mUnselectedContent );
+
+ PrepareAddButtonImage( mDecoration[ UNSELECTED_DECORATION ] );
+ ReAddLabel();
+ break;
+ }
+ case SelectedState:
+ {
+ //Layer Order
+ //(3) mSelectedContent
+ //(2) mSelectedBackgroundContent
+ //(1) mBackgroundContent
+
+ RemoveButtonImage( mDecoration[ UNSELECTED_DECORATION ] );
+ RemoveButtonImage( mUnselectedContent );
+ RemoveButtonImage( mDisabledContent );
+ RemoveButtonImage( mDisabledSelectedContent );
+ RemoveButtonImage( mDisabledBackgroundContent );
+
+ PrepareAddButtonImage( mBackgroundContent );
+ PrepareAddButtonImage( mSelectedBackgroundContent );
+ PrepareAddButtonImage( mSelectedContent );
+
+ PrepareAddButtonImage( mDecoration[ SELECTED_DECORATION ] );
+ ReAddLabel();
+ break;
+ }
+ case DisabledUnselectedState:
+ {
+ //Layer Order
+ //(2) mDisabledContent
+ //(1) mDisabledBackgroundContent
+
+ RemoveButtonImage( mDecoration[ UNSELECTED_DECORATION ] );
+ RemoveButtonImage( mUnselectedContent );
+ RemoveButtonImage( mBackgroundContent );
+ RemoveButtonImage( mDecoration[ SELECTED_DECORATION ] );
+ RemoveButtonImage( mSelectedContent );
+ RemoveButtonImage( mDisabledSelectedContent );
+ RemoveButtonImage( mSelectedBackgroundContent );
+
+ PrepareAddButtonImage( mDisabledBackgroundContent ? mDisabledBackgroundContent : mBackgroundContent );
+ PrepareAddButtonImage( mDisabledContent ? mDisabledContent : mUnselectedContent );
+
+ PrepareAddButtonImage( mDecoration[ UNSELECTED_DECORATION ] );
+ ReAddLabel();
+ break;
+ }
+ case DisabledSelectedState:
+ {
+ //Layer Order
+ // (2) mDisabledSelectedContent
+ // (1) mDisabledBackgroundContent
+
+ RemoveButtonImage( mDecoration[ UNSELECTED_DECORATION ] );
+ RemoveButtonImage( mUnselectedContent );
+ RemoveButtonImage( mDecoration[ SELECTED_DECORATION ] );
+ RemoveButtonImage( mSelectedContent );
+ RemoveButtonImage( mBackgroundContent );
+ RemoveButtonImage( mSelectedBackgroundContent );
+ RemoveButtonImage( mDisabledContent );
+
+ if( mDisabledBackgroundContent )
+ {
+ PrepareAddButtonImage( mDisabledBackgroundContent );
+ }
+ else
+ {
+ PrepareAddButtonImage( mBackgroundContent );
+ PrepareAddButtonImage( mSelectedBackgroundContent );
+ }
+
+ PrepareAddButtonImage( mDisabledSelectedContent ? mDisabledSelectedContent : mSelectedContent );
+
+ PrepareAddButtonImage( mDecoration[ SELECTED_DECORATION ] );
+ ReAddLabel();
+ break;
+ }
+ }
+}
+
+void Button::StartTransitionAnimation()
+{
+ if( mTransitionAnimation )
+ {
+ mTransitionAnimation.Play();
+ }
+ else
+ {
+ ResetImageLayers();
+ }
+}
+
+void Button::StopTransitionAnimation()
+{
+ if( mTransitionAnimation )
+ {
+ mTransitionAnimation.Clear();
+ mTransitionAnimation.Reset();
+ }
+}
+
+Dali::Animation Button::GetTransitionAnimation()
+{
+ if( !mTransitionAnimation )
+ {
+ mTransitionAnimation = Dali::Animation::New( GetAnimationTime() );
+ mTransitionAnimation.FinishedSignal().Connect( this, &Button::TransitionAnimationFinished );
+ }
+
+ return mTransitionAnimation;
+}
+
+void Button::TransitionAnimationFinished( Dali::Animation& source )
+{
+ StopTransitionAnimation();
+ ResetImageLayers();
+}
+