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=88e53648d884dcdc45a5732b74f7f33c21516327;hp=9c898c777a3ecf8ab57b4bfde24e14b2819a491a;hb=ded71874c72f72de672b8df770b4983a5d846944;hpb=87f440c3d0367ca5a7027eef8d01d79b8703cf05 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 9c898c7..88e5364 100644 --- a/dali-toolkit/internal/controls/buttons/check-box-button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/check-box-button-impl.cpp @@ -19,11 +19,9 @@ #include "check-box-button-impl.h" // EXTERNAL INCLUDES +#include #include -// INTERNAL INCLUDES -#include "check-box-button-default-painter-impl.h" - namespace Dali { @@ -36,6 +34,9 @@ namespace Internal namespace { +const float DISTANCE_BETWEEN_IMAGE_AND_LABEL( 5.0f ); +const float ANIMATION_TIME( 0.26f ); // EFL checkbox tick time + BaseHandle Create() { return Toolkit::CheckBoxButton::New(); @@ -63,16 +64,213 @@ Dali::Toolkit::CheckBoxButton CheckBoxButton::New() CheckBoxButton::CheckBoxButton() : Button() { - // Creates specific painter. - ButtonPainterPtr painter = new CheckBoxButtonDefaultPainter(); - SetPainter( painter ); - SetTogglableButton( true ); + + SetAnimationTime( ANIMATION_TIME ); } CheckBoxButton::~CheckBoxButton() { - SetPainter( NULL ); + if( mTransitionAnimation ) + { + mTransitionAnimation.Clear(); + } +} + +void CheckBoxButton::OnButtonInitialize() +{ + // Wrap around all children + Self().SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS ); +} + +void CheckBoxButton::OnLabelSet() +{ + Actor& label = GetLabel(); + + if( label ) + { + label.SetParentOrigin( ParentOrigin::CENTER_LEFT ); + label.SetAnchorPoint( AnchorPoint::CENTER_LEFT ); + + if( IsDisabled() && GetDisabledBackgroundImage() ) + { + label.SetX( GetDisabledBackgroundImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); + } + else if ( GetBackgroundImage() ) + { + label.SetX( GetBackgroundImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); + } + else + { + label.SetX( 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: + { + StopTransitionAnimation( false ); + RemoveChild( selectedImage ); + break; + } + default: + { + break; + } + } + + if( mTransitionAnimation ) + { + return true; + } + + return false; +} + +bool 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(); + + if( label ) + { + if( IsDisabled() && disabledBackgroundImage) + { + label.SetX( disabledBackgroundImage.GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); + } + else if( backgroundImage ) + { + label.SetX( backgroundImage.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 ) +{ + 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( !mTransitionAnimation ) + { + mTransitionAnimation = Dali::Animation::New( GetAnimationTime() ); + } + + // UV anim + mTransitionAnimation.AnimateTo( Property( mTickUVEffect, mTickUVEffect.GetBottomRightPropertyName() ), 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 ) +{ + if( mTransitionAnimation ) + { + mTransitionAnimation.Clear(); + mTransitionAnimation.Reset(); + } + + if( remove ) + { + UpdatePaintTransitionState(); + } +} + +void CheckBoxButton::TransitionAnimationFinished( Dali::Animation& source ) +{ + StopTransitionAnimation(); } } // namespace Internal