-void CheckBoxButton::OnDisabled( bool disabled )
-{
- Actor& backgroundImage = GetBackgroundImage();
- Actor& selectedImage = GetSelectedImage();
- Actor& disabledBackgroundImage = GetDisabledBackgroundImage();
- Actor& disabledSelectedImage = GetDisabledSelectedImage();
-
- switch( mPaintState )
- {
- case UnselectedState:
- {
- if( disabled )
- {
- RemoveChild( backgroundImage );
- AddChild( disabledBackgroundImage );
- mPaintState = DisabledUnselectedState;
- }
- break;
- }
- case SelectedState:
- {
- if( disabled )
- {
- RemoveChild( backgroundImage );
- RemoveChild( selectedImage );
- AddChild( disabledBackgroundImage );
- AddChild( disabledSelectedImage );
-
- mPaintState = DisabledSelectedState;
- }
- break;
- }
- case DisabledUnselectedState:
- {
- if( !disabled )
- {
- RemoveChild( disabledBackgroundImage );
- AddChild( backgroundImage );
-
- mPaintState = UnselectedState;
- }
- break;
- }
- case DisabledSelectedState:
- {
- if( !disabled )
- {
- RemoveChild( disabledBackgroundImage );
- RemoveChild( disabledSelectedImage );
- AddChild( backgroundImage );
- AddChild( selectedImage );
-
- mPaintState = SelectedState;
- }
- break;
- }
- case UnselectedSelectedTransition:
- {
- if( disabled )
- {
- StopCheckInAnimation();
-
- RemoveChild( backgroundImage );
- RemoveChild( selectedImage );
- AddChild( disabledBackgroundImage );
- AddChild( disabledSelectedImage );
-
- mPaintState = DisabledSelectedState;
- }
- break;
- }
- default:
- break;
- }
-
- Actor& label = GetLabel();
-
- if( label )
- {
- if( label.GetParent() )
- {
- label.GetParent().Remove( label );
- }
-
- if( disabled && disabledBackgroundImage)
- {
- disabledBackgroundImage.Add( label );
- }
- else if( backgroundImage )
- {
- backgroundImage.Add( label );
- }
- }
-}
-
-void CheckBoxButton::OnRelayout( const Vector2& size, ActorSizeContainer& container )
-{
- Vector3 newSize;
-
- if( IsDisabled() && GetDisabledBackgroundImage() )
- {
- newSize = GetDisabledBackgroundImage().GetNaturalSize();
- }
- else if( GetBackgroundImage() )
- {
- newSize = GetBackgroundImage().GetNaturalSize();
- }
-
- Actor& label = GetLabel();
-
- if( label )
- {
- // Offset the label from the radio button image
- newSize.width += DISTANCE_BETWEEN_IMAGE_AND_LABEL.width;
-
- // Find the size of the control using size negotiation
- Vector3 actorNaturalSize( label.GetNaturalSize() );
- Control::Relayout( label, Vector2( actorNaturalSize.width, actorNaturalSize.height ), container );
-
- Vector3 actorSize( label.GetSize() );
- newSize.width += actorSize.width;
- newSize.height = std::max( newSize.height, actorSize.height );
- }
-
- Self().SetSize( newSize );
-}
-
-void CheckBoxButton::AddChild( Actor& actor )
-{
- if( actor )
- {
- Self().Add( actor);
- }
-}
-
-void CheckBoxButton::RemoveChild( Actor& actor )
-{
- if( actor )
- {
- Self().Remove( actor );
- }
-}
-
-void CheckBoxButton::StartCheckInAnimation( Actor& actor )
-{
- if( actor )
- {
- if( !mTickUVEffect )
- {
- ImageActor imageActor = ImageActor::DownCast( actor );
- mTickUVEffect = ImageRegionEffect::New();
- imageActor.SetShaderEffect( mTickUVEffect );
- }
-
- actor.SetScale( Vector3( 0.0f, 1.0f, 1.0f ) );
-
- mTickUVEffect.SetBottomRight( Vector2( 0.0f, 1.0f ) );
-
- if( !mCheckInAnimation )
- {
- mCheckInAnimation = Dali::Animation::New( GetAnimationTime() );
- }
-
- // UV anim
- mCheckInAnimation.AnimateTo( Property( mTickUVEffect, mTickUVEffect.GetBottomRightPropertyName() ), Vector2( 1.0f, 1.0f ) );
-
- // Actor size anim
- mCheckInAnimation.AnimateTo( Property( actor, Actor::Property::SCALE_X ), 1.0f );
-
- mCheckInAnimation.FinishedSignal().Connect( this, &CheckBoxButton::CheckInAnimationFinished );
- mCheckInAnimation.Play();
- }
-}
-
-void CheckBoxButton::StopCheckInAnimation()
-{
- if( mCheckInAnimation )
- {
- mCheckInAnimation.Clear();
- mCheckInAnimation.Reset();
- }
-}
-
-void CheckBoxButton::CheckInAnimationFinished( Dali::Animation& source )
-{
- switch( mPaintState )
- {
- case UnselectedSelectedTransition:
- {
- mPaintState = SelectedState;
- break;
- }
- default:
- {
- break;
- }
- }
-
- StopCheckInAnimation();
-}
-