X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fbuttons%2Fcheck-box-button-impl.cpp;h=30aba5ecc03b111504d7ea31342ea69340925b7c;hp=f5c908d78527e9bf13d012d5ee83e0238e712dd4;hb=4517298d9e2e87d3814ddd311233568ef10f7018;hpb=d3a00dc1c24ece2488696c0b518013ad6d97969b diff --git a/dali-toolkit/internal/controls/buttons/check-box-button-impl.cpp b/dali-toolkit/internal/controls/buttons/check-box-button-impl.cpp index f5c908d..30aba5e 100644 --- a/dali-toolkit/internal/controls/buttons/check-box-button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/check-box-button-impl.cpp @@ -21,6 +21,7 @@ // EXTERNAL INCLUDES #include #include +#include //INTERNAL INCLUDES #include @@ -47,6 +48,10 @@ BaseHandle Create() TypeRegistration mType( typeid(Toolkit::CheckBoxButton), typeid(Toolkit::Button), Create ); +const char* const UNSELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "checkbox-unselected.png"; +const char* const SELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "checkbox-selected.png"; +const char* const DISABLED_UNSELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "checkbox-unselected-disabled.png"; +const char* const DISABLED_SELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "checkbox-selected-diabled.png"; } Dali::Toolkit::CheckBoxButton CheckBoxButton::New() @@ -74,21 +79,22 @@ CheckBoxButton::CheckBoxButton() CheckBoxButton::~CheckBoxButton() { - if( mTransitionAnimation ) - { - mTransitionAnimation.Clear(); - } } void CheckBoxButton::OnButtonInitialize() { // Wrap around all children Self().SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS ); + + SetUnselectedImage( UNSELECTED_BUTTON_IMAGE_DIR ); + SetSelectedImage( SELECTED_BUTTON_IMAGE_DIR ); + SetDisabledImage( DISABLED_UNSELECTED_BUTTON_IMAGE_DIR ); + SetDisabledSelectedImage( DISABLED_SELECTED_BUTTON_IMAGE_DIR ); } -void CheckBoxButton::OnLabelSet() +void CheckBoxButton::OnLabelSet( bool noPadding ) { - Actor& label = GetLabel(); + Actor& label = GetLabelActor(); if( label ) { @@ -103,103 +109,30 @@ void CheckBoxButton::OnLabelSet() { label.SetX( GetBackgroundImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); } - else + else if( IsSelected() && GetSelectedImage()) { - label.SetX( DISTANCE_BETWEEN_IMAGE_AND_LABEL ); + label.SetX( GetSelectedImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); } - } -} - -bool CheckBoxButton::OnSelected() -{ - Actor& selectedImage = GetSelectedImage(); - - PaintState paintState = GetPaintState(); - - switch( paintState ) - { - case UnselectedState: - { - StartTransitionAnimation( selectedImage ); - break; - } - case SelectedState: - { - RemoveChild( selectedImage ); - break; - } - case UnselectedSelectedTransition: + else if( GetUnselectedImage() ) { - StopTransitionAnimation( false ); - RemoveChild( selectedImage ); - break; + label.SetX( GetUnselectedImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); } - default: + else { - break; + label.SetX( DISTANCE_BETWEEN_IMAGE_AND_LABEL ); } } - - if( mTransitionAnimation ) - { - return true; - } - - return false; } -bool CheckBoxButton::OnDisabled() +void CheckBoxButton::OnDisabled() { Actor& backgroundImage = GetBackgroundImage(); - Actor& selectedImage = GetSelectedImage(); Actor& disabledBackgroundImage = GetDisabledBackgroundImage(); - Actor& disabledSelectedImage = GetDisabledSelectedImage(); - - PaintState paintState = GetPaintState(); - - switch( paintState ) - { - case UnselectedState: - { - RemoveChild( backgroundImage ); - break; - } - case SelectedState: - { - RemoveChild( backgroundImage ); - RemoveChild( selectedImage ); - break; - } - case DisabledUnselectedState: - { - RemoveChild( disabledBackgroundImage ); - break; - } - case DisabledSelectedState: - { - RemoveChild( disabledBackgroundImage ); - RemoveChild( disabledSelectedImage ); - break; - } - case UnselectedSelectedTransition: - { - StopTransitionAnimation(); - - RemoveChild( backgroundImage ); - RemoveChild( selectedImage ); - break; - } - default: - { - break; - } - } - - Actor& label = GetLabel(); + Actor& label = GetLabelActor(); if( label ) { - if( IsDisabled() && disabledBackgroundImage) + if( IsDisabled() && disabledBackgroundImage ) { label.SetX( disabledBackgroundImage.GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); } @@ -207,73 +140,93 @@ bool CheckBoxButton::OnDisabled() { label.SetX( backgroundImage.GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); } + else if( IsSelected() && GetSelectedImage()) + { + label.SetX( GetSelectedImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); + } + else if( GetUnselectedImage() ) + { + label.SetX( GetUnselectedImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); + } else { label.SetX( DISTANCE_BETWEEN_IMAGE_AND_LABEL ); } } - - if( mTransitionAnimation ) - { - return true; - } - - return false; -} - -void CheckBoxButton::StopAllAnimations() -{ - StopTransitionAnimation(); } -void CheckBoxButton::StartTransitionAnimation( Actor& actor ) +void CheckBoxButton::PrepareForTranstionIn( Actor actor ) { - if( actor ) + Actor& selectedImage = GetSelectedImage(); + if( actor == selectedImage ) { + actor.SetScale( Vector3( 0.0f, 1.0f, 1.0f ) ); + if( !mTickUVEffect ) { - ImageActor imageActor = ImageActor::DownCast( actor ); mTickUVEffect = CreateImageRegionEffect(); - imageActor.SetShaderEffect( mTickUVEffect ); } - - actor.SetScale( Vector3( 0.0f, 1.0f, 1.0f ) ); - mTickUVEffect.SetUniform("uBottomRight", Vector2( 0.0f, 1.0f ) ); - if( !mTransitionAnimation ) + ImageActor imageActor = ImageActor::DownCast( actor ); + if( imageActor ) { - mTransitionAnimation = Dali::Animation::New( GetAnimationTime() ); + imageActor.SetShaderEffect( mTickUVEffect ); } - - // UV anim - mTransitionAnimation.AnimateTo( Property( mTickUVEffect, "uBottomRight" ), Vector2( 1.0f, 1.0f ) ); - - // Actor size anim - mTransitionAnimation.AnimateTo( Property( actor, Actor::Property::SCALE_X ), 1.0f ); - - mTransitionAnimation.FinishedSignal().Connect( this, &CheckBoxButton::TransitionAnimationFinished ); - mTransitionAnimation.Play(); } } -void CheckBoxButton::StopTransitionAnimation( bool remove ) +void CheckBoxButton::PrepareForTranstionOut( Actor actor ) { - if( mTransitionAnimation ) + Actor& selectedImage = GetSelectedImage(); + if( actor == selectedImage ) { - mTransitionAnimation.Clear(); - mTransitionAnimation.Reset(); - } + actor.SetScale( Vector3::ONE ); - if( remove ) - { - UpdatePaintTransitionState(); + if( !mTickUVEffect ) + { + mTickUVEffect = CreateImageRegionEffect(); + } + mTickUVEffect.SetUniform("uBottomRight", Vector2::ONE ); + + ImageActor imageActor = ImageActor::DownCast( actor ); + if( imageActor ) + { + imageActor.SetShaderEffect( mTickUVEffect ); + } } } -void CheckBoxButton::TransitionAnimationFinished( Dali::Animation& source ) +void CheckBoxButton::OnTransitionIn( Actor actor ) { - StopTransitionAnimation(); + Actor& selectedImage = GetSelectedImage(); + if( actor && actor == selectedImage ) + { + if( GetPaintState() == UnselectedState ) + { + Dali::Animation transitionAnimation = GetTransitionAnimation(); + if( transitionAnimation ) + { + DALI_ASSERT_DEBUG( mTickUVEffect ); + if( mTickUVEffect ) + { + // UV anim + transitionAnimation.AnimateTo( Property( mTickUVEffect, "uBottomRight" ), Vector2::ONE ); + } + // Actor size anim + transitionAnimation.AnimateTo( Property( actor, Actor::Property::SCALE_X ), 1.0f ); + } + } + else + { + //explicitly end the swipe animation + actor.SetScale( Vector3::ONE ); + if( mTickUVEffect ) + { + mTickUVEffect.SetUniform("uBottomRight", Vector2::ONE ); + } + } + } } } // namespace Internal