-void Button::SetSelected( bool selected )
-{
- if( !mDisabled && mTogglableButton && ( selected != mSelected ) )
- {
- SetSelected( selected, true );
- }
-}
-
-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;
- }
-
- 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
-{
- return mTogglableButton && mSelected;
-}
-
-void Button::SetAnimationTime( float animationTime )
-{
- mAnimationTime = animationTime;
-}
-
-float Button::GetAnimationTime() const
-{
- return mAnimationTime;
-}
-
-void Button::SetLabel( const std::string& label )
-{
- Toolkit::TextLabel textLabel = Toolkit::TextLabel::New( label );
- SetLabel( textLabel );
-}
-
-void Button::SetLabel( Actor label )
-{
- 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();
-
- RelayoutRequest();
- }
-}
-
-Actor Button::GetLabel() const
-{
- return mLabel;
-}
-
-Actor& Button::GetLabel()
-{
- return mLabel;
-}
-
-void Button::SetButtonImage( Actor 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();
-
- RelayoutRequest();
-}
-
-Actor Button::GetButtonImage() const
-{
- return mButtonContent;
-}
-
-Actor& Button::GetButtonImage()
-{
- return mButtonContent;
-}
-
-void Button::SetSelectedImage( Actor 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();
-
- RelayoutRequest();
-}
-
-Actor Button::GetSelectedImage() const
-{
- return mSelectedContent;
-}
-
-Actor& Button::GetSelectedImage()
-{
- return mSelectedContent;
-}
-
-void Button::SetBackgroundImage( Actor 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();
-
- RelayoutRequest();
-}
-
-Actor Button::GetBackgroundImage() const
-{
- return mBackgroundContent;
-}
-
-Actor& Button::GetBackgroundImage()