X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fbuttons%2Fpush-button-impl.cpp;h=1ee6b92152fde435c873f6383894d3f25044f47f;hp=f07eb329ccf6c6f35ce1eae89db0d41f7d21c7f8;hb=efc136204e9a4460a7a2421e673c873e23974a80;hpb=7dc926f34a990b06a39dec7bc467803fe0773600 diff --git a/dali-toolkit/internal/controls/buttons/push-button-impl.cpp b/dali-toolkit/internal/controls/buttons/push-button-impl.cpp index f07eb32..1ee6b92 100644 --- a/dali-toolkit/internal/controls/buttons/push-button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/push-button-impl.cpp @@ -21,6 +21,7 @@ // EXTERNAL INCLUDES #include #include +#include // INTERNAL INCLUDES #include @@ -47,6 +48,11 @@ BaseHandle Create() TypeRegistration typeRegistration( typeid(Toolkit::PushButton), typeid(Toolkit::Button), Create ); +const char* const UNSELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "button-up.9.png"; +const char* const SELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "button-down.9.png"; +const char* const DISABLED_UNSELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "button-disabled.9.png"; +const char* const DISABLED_SELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "button-down-disabled.9.png"; + } // unnamed namespace namespace @@ -103,6 +109,16 @@ void PushButton::OnButtonInitialize() // Set resize policy to natural size so that buttons will resize to background images self.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); + + Image buttonImage = Dali::ResourceImage::New( UNSELECTED_BUTTON_IMAGE_DIR, ResourceImage::ON_DEMAND, ResourceImage::NEVER ); + Image selectedImage = Dali::ResourceImage::New( SELECTED_BUTTON_IMAGE_DIR, ResourceImage::ON_DEMAND, ResourceImage::NEVER ); + Image disabledImage = Dali::ResourceImage::New( DISABLED_UNSELECTED_BUTTON_IMAGE_DIR, ResourceImage::ON_DEMAND, ResourceImage::NEVER ); + Image disabledSelectedImage = Dali::ResourceImage::New( DISABLED_SELECTED_BUTTON_IMAGE_DIR, ResourceImage::ON_DEMAND, ResourceImage::NEVER ); + + SetButtonImage( ImageActor::New( buttonImage ) ); + SetSelectedImage( ImageActor::New( selectedImage ) ); + SetDisabledImage( ImageActor::New( disabledImage ) ); + SetDisabledSelectedImage( ImageActor::New( disabledSelectedImage ) ); } void PushButton::OnLabelSet() @@ -156,389 +172,19 @@ void PushButton::OnDisabledImageSet() RelayoutRequest(); } -void PushButton::OnDisabledBackgroundImageSet() +void PushButton::OnDisabledSelectedImageSet() { ConfigureSizeNegotiation(); RelayoutRequest(); } -bool PushButton::OnSelected() -{ - Actor& buttonImage = GetButtonImage(); - Actor& selectedImage = GetSelectedImage(); - Actor& selectedBackgroundImage = GetSelectedBackgroundImage(); - - PaintState paintState = GetPaintState(); - - switch( paintState ) - { - case UnselectedState: - { - FadeOutImage( buttonImage ); - FadeInImage( selectedBackgroundImage ); - FadeInImage( selectedImage ); - StartTransitionAnimation(); - break; - } - case SelectedState: - { - FadeOutImage( selectedBackgroundImage ); - FadeOutImage( selectedImage ); - FadeInImage( buttonImage ); - StartTransitionAnimation(); - break; - } - case UnselectedSelectedTransition: - { - float opacity = 1.f; - if( selectedImage ) - { - opacity = selectedImage.GetCurrentOpacity(); - } - - StopTransitionAnimation( false ); - FadeOutImage( selectedBackgroundImage, opacity ); - FadeOutImage( selectedImage, opacity ); - FadeInImage( buttonImage, 1.f - opacity ); - StartTransitionAnimation(); - break; - } - case SelectedUnselectedTransition: - { - float opacity = 0.f; - if( selectedImage ) - { - opacity = selectedImage.GetCurrentOpacity(); - } - - StopTransitionAnimation( false ); - FadeOutImage( buttonImage, 1.f - opacity ); - FadeInImage( selectedBackgroundImage, opacity ); - FadeInImage( selectedImage, opacity ); - StartTransitionAnimation(); - break; - } - case DisabledUnselectedTransition: - { - StopTransitionAnimation(); - FadeOutImage( buttonImage ); - FadeInImage( selectedBackgroundImage ); - FadeInImage( selectedImage ); - StartTransitionAnimation(); - break; - } - case DisabledSelectedTransition: - { - StopTransitionAnimation(); - FadeOutImage( selectedBackgroundImage ); - FadeOutImage( selectedImage ); - FadeInImage( buttonImage ); - StartTransitionAnimation(); - break; - } - default: - { - break; - } - } - - if( mTransitionAnimation ) - { - return true; - } - - return false; -} - -bool PushButton::OnDisabled() -{ - Actor& buttonImage = GetButtonImage(); - Actor& selectedImage = GetSelectedImage(); - Actor& selectedBackgroundImage = GetSelectedBackgroundImage(); - Actor& backgroundImage = GetBackgroundImage(); - Actor& disabledImage = GetDisabledImage(); - Actor& disabledSelectedImage = GetDisabledSelectedImage(); - Actor& disabledBackgroundImage = GetDisabledBackgroundImage(); - - PaintState paintState = GetPaintState(); - - switch( paintState ) - { - case UnselectedState: - { - FadeOutImage( backgroundImage ); - FadeOutImage( buttonImage ); - FadeInImage( disabledBackgroundImage ); - FadeInImage( disabledImage ); - StartTransitionAnimation(); - break; - } - case SelectedState: - { - FadeOutImage( backgroundImage ); - FadeOutImage( selectedBackgroundImage ); - FadeOutImage( selectedImage ); - FadeInImage( disabledBackgroundImage ); - FadeInImage( disabledSelectedImage ); - StartTransitionAnimation(); - break; - } - case DisabledUnselectedState: - { - FadeOutImage( disabledBackgroundImage ); - FadeOutImage( disabledImage ); - FadeInImage( backgroundImage ); - FadeInImage( buttonImage ); - StartTransitionAnimation(); - break; - } - case DisabledSelectedState: - { - FadeOutImage( disabledBackgroundImage ); - FadeOutImage( disabledSelectedImage ); - FadeInImage( backgroundImage ); - FadeInImage( selectedBackgroundImage ); - FadeInImage( selectedImage ); - StartTransitionAnimation(); - break; - } - case UnselectedSelectedTransition: - { - float opacity = 1.f; - if( selectedImage ) - { - opacity = selectedImage.GetCurrentOpacity(); - } - - StopTransitionAnimation(); - FadeOutImage( backgroundImage ); - FadeOutImage( selectedBackgroundImage, opacity ); - FadeOutImage( selectedImage, opacity ); - FadeInImage( disabledBackgroundImage ); - FadeInImage( disabledSelectedImage ); - StartTransitionAnimation(); - break; - } - case SelectedUnselectedTransition: - { - float opacity = 1.f; - if( buttonImage ) - { - opacity = buttonImage.GetCurrentOpacity(); - } - - StopTransitionAnimation(); - FadeOutImage( backgroundImage ); - FadeOutImage( buttonImage, opacity ); - FadeInImage( disabledBackgroundImage ); - FadeInImage( disabledImage ); - StartTransitionAnimation(); - break; - } - case UnselectedDisabledTransition: - { - float opacity = 1.f; - if( disabledImage ) - { - opacity = disabledImage.GetCurrentOpacity(); - } - - StopTransitionAnimation( false ); - FadeOutImage( disabledBackgroundImage, opacity ); - FadeOutImage( disabledImage, opacity ); - FadeInImage( backgroundImage, 1.f - opacity ); - FadeInImage( buttonImage, 1.f - opacity ); - StartTransitionAnimation(); - break; - } - case DisabledUnselectedTransition: - { - float opacity = 1.f; - if( buttonImage ) - { - opacity = buttonImage.GetCurrentOpacity(); - } - - StopTransitionAnimation( false ); - FadeOutImage( backgroundImage, opacity ); - FadeOutImage( buttonImage, opacity ); - FadeInImage( disabledBackgroundImage, 1.f - opacity ); - FadeInImage( disabledImage, 1.f - opacity ); - StartTransitionAnimation(); - break; - } - case SelectedDisabledTransition: - { - float opacity = 1.f; - if( disabledSelectedImage ) - { - opacity = disabledSelectedImage.GetCurrentOpacity(); - } - - StopTransitionAnimation( false ); - FadeOutImage( disabledBackgroundImage, opacity ); - FadeOutImage( disabledSelectedImage, opacity ); - FadeInImage( backgroundImage, 1.f - opacity ); - FadeInImage( selectedBackgroundImage, 1.f - opacity ); - FadeInImage( selectedImage, 1.f - opacity ); - StartTransitionAnimation(); - break; - } - case DisabledSelectedTransition: - { - float opacity = 1.f; - if( selectedImage ) - { - opacity = selectedImage.GetCurrentOpacity(); - } - - StopTransitionAnimation( false ); - FadeOutImage( backgroundImage, opacity ); - FadeOutImage( selectedBackgroundImage, opacity ); - FadeOutImage( selectedImage, opacity ); - FadeInImage( disabledBackgroundImage, 1.f - opacity ); - FadeInImage( disabledSelectedImage, 1.f - opacity ); - StartTransitionAnimation(); - break; - } - } - - if( mTransitionAnimation ) - { - return true; - } - - return false; -} - -bool PushButton::OnPressed() -{ - Actor& buttonImage = GetButtonImage(); - Actor& selectedImage = GetSelectedImage(); - Actor& selectedBackgroundImage = GetSelectedBackgroundImage(); - - PaintState paintState = GetPaintState(); - - switch( paintState ) - { - case UnselectedState: - { - FadeOutImage( buttonImage ); - FadeInImage( selectedBackgroundImage ); - FadeInImage( selectedImage ); - StartTransitionAnimation(); - break; - } - case SelectedUnselectedTransition: - { - float opacity = 1.f; - if( buttonImage ) - { - opacity = buttonImage.GetCurrentOpacity(); - } - - StopTransitionAnimation( false ); - FadeOutImage( buttonImage, opacity ); - FadeInImage( selectedBackgroundImage, 1.f - opacity ); - FadeInImage( selectedImage, 1.f - opacity ); - StartTransitionAnimation(); - break; - } - case DisabledUnselectedTransition: - { - float opacity = 1.f; - if( buttonImage ) - { - opacity = buttonImage.GetCurrentOpacity(); - } - - StopTransitionAnimation(); - FadeOutImage( buttonImage, opacity ); - FadeInImage( selectedBackgroundImage ); - FadeInImage( selectedImage ); - StartTransitionAnimation(); - break; - } - default: - break; - } - - if( mTransitionAnimation ) - { - return true; - } - - return false; -} - -bool PushButton::OnReleased() -{ - Actor& buttonImage = GetButtonImage(); - Actor& selectedImage = GetSelectedImage(); - Actor& selectedBackgroundImage = GetSelectedBackgroundImage(); - - PaintState paintState = GetPaintState(); - - switch( paintState ) - { - case SelectedState: - { - FadeOutImage( selectedBackgroundImage ); - FadeOutImage( selectedImage ); - FadeInImage( buttonImage ); - StartTransitionAnimation(); - break; - } - case UnselectedSelectedTransition: - { - float opacity = 1.f; - if( selectedImage ) - { - opacity = selectedImage.GetCurrentOpacity(); - } - - StopTransitionAnimation( false ); - FadeOutImage( selectedBackgroundImage, opacity ); - FadeOutImage( selectedImage, opacity ); - FadeInImage( buttonImage, 1.f - opacity ); - StartTransitionAnimation(); - break; - } - case DisabledSelectedTransition: - { - float opacity = 1.f; - if( selectedImage ) - { - opacity = selectedImage.GetCurrentOpacity(); - } - - StopTransitionAnimation(); - FadeOutImage( selectedBackgroundImage, opacity ); - FadeOutImage( selectedImage, opacity ); - FadeInImage( buttonImage ); - StartTransitionAnimation(); - break; - } - default: - { - break; - } - } - - if( mTransitionAnimation ) - { - return true; - } - - return false; -} - -void PushButton::StopAllAnimations() +void PushButton::OnDisabledBackgroundImageSet() { - StopTransitionAnimation(); + ConfigureSizeNegotiation(); + RelayoutRequest(); } -void PushButton::OnControlSizeSet( const Vector3& targetSize ) +void PushButton::OnSizeSet( const Vector3& targetSize ) { if( targetSize != mSize ) { @@ -553,66 +199,40 @@ void PushButton::OnControlSizeSet( const Vector3& targetSize ) } } -void PushButton::StartTransitionAnimation() +void PushButton::PrepareForTranstionIn( Actor actor ) { - if( mTransitionAnimation ) - { - mTransitionAnimation.FinishedSignal().Connect( this, &PushButton::TransitionAnimationFinished ); - mTransitionAnimation.Play(); - } + actor.SetOpacity( 0.0f ); } -void PushButton::StopTransitionAnimation( bool remove ) +void PushButton::PrepareForTranstionOut( Actor actor ) { - if( mTransitionAnimation ) - { - mTransitionAnimation.Clear(); - mTransitionAnimation.Reset(); - } - - if( remove ) - { - UpdatePaintTransitionState(); - } + actor.SetOpacity( 1.0f ); } -void PushButton::FadeInImage( Actor& image, float opacity, Vector3 scale ) +void PushButton::OnTransitionIn( Actor actor ) { - if( image ) - { - image.SetOpacity( opacity ); - image.SetScale( scale ); - - if( !mTransitionAnimation ) - { - mTransitionAnimation = Dali::Animation::New( GetAnimationTime() ); - } + FadeImageTo( actor, 1.f ); +} - mTransitionAnimation.AnimateTo( Property( image, Actor::Property::COLOR_ALPHA ), 1.f ); - } +void PushButton::OnTransitionOut( Actor actor ) +{ + FadeImageTo( actor, 0.0f ); } -void PushButton::FadeOutImage( Actor& image, float opacity, Vector3 scale ) +void PushButton::FadeImageTo( Actor actor, float opacity ) { - if( image ) + if( actor ) { - image.SetOpacity( opacity ); - image.SetScale( scale ); + Dali::Animation transitionAnimation = GetTransitionAnimation(); + DALI_ASSERT_DEBUG( transitionAnimation ); - if( !mTransitionAnimation ) + if( transitionAnimation ) { - mTransitionAnimation = Dali::Animation::New( GetAnimationTime() ); + transitionAnimation.AnimateTo( Property( actor, Actor::Property::COLOR_ALPHA ), opacity ); } - - mTransitionAnimation.AnimateTo( Property( image, Actor::Property::COLOR_ALPHA ), 0.f ); } } -void PushButton::TransitionAnimationFinished( Dali::Animation& source ) -{ - StopTransitionAnimation(); -} - Vector3 PushButton::GetNaturalSize() { Vector3 size; @@ -641,7 +261,7 @@ void PushButton::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type d void PushButton::ConfigureSizeNegotiation() { - ActorContainer images; + std::vector< Actor > images; images.reserve( 7 ); images.push_back( GetButtonImage() ); @@ -661,11 +281,25 @@ void PushButton::ConfigureSizeNegotiation() if( label ) { - label.SetPadding( Padding( TEXT_PADDING, TEXT_PADDING, TEXT_PADDING, TEXT_PADDING) ); + Padding padding; + + if( label.GetResizePolicy( Dimension::WIDTH ) == ResizePolicy::USE_NATURAL_SIZE ) + { + padding.left = TEXT_PADDING; + padding.right = TEXT_PADDING; + } + + if( label.GetResizePolicy( Dimension::HEIGHT ) == ResizePolicy::USE_NATURAL_SIZE ) + { + padding.top = TEXT_PADDING; + padding.bottom = TEXT_PADDING; + } + + label.SetPadding( padding ); } } -void PushButton::ConfigureSizeNegotiationDimension( Dimension::Type dimension, const ActorContainer& images, Actor& label ) +void PushButton::ConfigureSizeNegotiationDimension( Dimension::Type dimension, const std::vector< Actor >& images, Actor& label ) { ResizePolicy::Type imageResizePolicy = ResizePolicy::FILL_TO_PARENT; ResizePolicy::Type labelResizePolicy = ResizePolicy::FILL_TO_PARENT; @@ -700,7 +334,7 @@ void PushButton::ConfigureSizeNegotiationDimension( Dimension::Type dimension, c label.SetResizePolicy( labelResizePolicy, dimension ); } - for( ActorConstIter it = images.begin(), itEnd = images.end(); it != itEnd; ++it ) + for( std::vector< Actor >::const_iterator it = images.begin(), itEnd = images.end(); it != itEnd; ++it ) { Actor actor = *it; if( actor )