+Button::PaintState Button::GetPaintState()
+{
+ return mPaintState;
+}
+
+bool Button::InsertButtonImage( unsigned int index, Actor& actor )
+{
+ if( actor )
+ {
+ Self().Insert( index, actor );
+ PrepareForTranstionOut( actor );
+ return true;
+ }
+
+ return false;
+}
+
+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::TransitionInBetween( Actor childLower, Actor childUpper, Actor actor )
+{
+ unsigned int index = childLower ? FindChildIndex( childLower ) + 1 : FindChildIndex( childUpper );
+ TransitionInAtIndex( index, actor );
+}
+
+void Button::TransitionInAbove( Actor child, Actor actor )
+{
+ unsigned int index = child ? FindChildIndex( child ) + 1 : 0;
+ TransitionInAtIndex( index, actor );
+}
+
+void Button::TransitionInAtIndex( unsigned int index, Actor actor )
+{
+ if( actor )
+ {
+ if( !actor.GetParent() )
+ {
+ Self().Insert( index, actor );
+ }
+
+ OnTransitionIn( actor );
+ }
+}
+
+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
+
+ int index = 0;
+ switch( mPaintState )
+ {
+ case UnselectedState:
+ {
+ //Layer Order
+ //(2) mUnselectedContent
+ //(1) mBackgroundContent
+
+ RemoveButtonImage( mSelectedContent );
+ RemoveButtonImage( mSelectedBackgroundContent );
+ RemoveButtonImage( mDisabledContent );
+ RemoveButtonImage( mDisabledSelectedContent );
+ RemoveButtonImage( mDisabledBackgroundContent );
+
+ if( InsertButtonImage( index, mBackgroundContent ) )
+ {
+ ++index;
+ }
+ if( InsertButtonImage( index, mUnselectedContent ) )
+ {
+ ++index;
+ }
+ break;
+ }
+ case SelectedState:
+ {
+ //Layer Order
+ //(3) mSelectedContent
+ //(2) mSelectedBackgroundContent
+ //(1) mBackgroundContent
+
+ RemoveButtonImage( mUnselectedContent );
+ RemoveButtonImage( mDisabledContent );
+ RemoveButtonImage( mDisabledSelectedContent );
+ RemoveButtonImage( mDisabledBackgroundContent );
+
+ if( InsertButtonImage( index, mBackgroundContent ) )
+ {
+ ++index;
+ }
+ if( InsertButtonImage( index, mSelectedBackgroundContent ) )
+ {
+ ++index;
+ }
+ if( InsertButtonImage( index, mSelectedContent ) )
+ {
+ ++index;
+ }
+ break;
+ }
+ case DisabledUnselectedState:
+ {
+ //Layer Order
+ //(2) mDisabledContent
+ //(1) mDisabledBackgroundContent
+
+ RemoveButtonImage( mUnselectedContent );
+ RemoveButtonImage( mBackgroundContent );
+ RemoveButtonImage( mSelectedContent );
+ RemoveButtonImage( mDisabledSelectedContent );
+ RemoveButtonImage( mSelectedBackgroundContent );
+
+ if( InsertButtonImage( index, mDisabledBackgroundContent ? mDisabledBackgroundContent : mBackgroundContent ) )
+ {
+ ++index;
+ }
+ if( InsertButtonImage( index, mDisabledContent ? mDisabledContent : mUnselectedContent ) )
+ {
+ ++index;
+ }
+ break;
+ }
+ case DisabledSelectedState:
+ {
+ //Layer Order
+ // (2) mDisabledSelectedContent
+ // (1) mDisabledBackgroundContent
+
+ RemoveButtonImage( mUnselectedContent );
+ RemoveButtonImage( mSelectedContent );
+ RemoveButtonImage( mBackgroundContent );
+ RemoveButtonImage( mSelectedBackgroundContent );
+ RemoveButtonImage( mDisabledContent );
+
+ if( mDisabledBackgroundContent )
+ {
+ if( InsertButtonImage( index, mDisabledBackgroundContent) )
+ {
+ ++index;
+ }
+ }
+ else
+ {
+ if( InsertButtonImage( index, mBackgroundContent ) )
+ {
+ ++index;
+ }
+ if( InsertButtonImage( index, mSelectedBackgroundContent ) )
+ {
+ ++index;
+ }
+ }
+
+ if( InsertButtonImage( index, mDisabledSelectedContent ? mDisabledSelectedContent : mSelectedContent) )
+ {
+ ++index;
+ }
+ 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();
+}
+