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=4331c873165112723bcef3c4566601606d6ccc81;hp=cf34f85cc409078894308024b9f326d9e9ca20cf;hb=f3da11c2818c6d17706fbb2417f21b602b3190f5;hpb=ded71874c72f72de672b8df770b4983a5d846944 diff --git a/dali-toolkit/internal/controls/buttons/push-button-impl.cpp b/dali-toolkit/internal/controls/buttons/push-button-impl.cpp index cf34f85..4331c87 100644 --- a/dali-toolkit/internal/controls/buttons/push-button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/push-button-impl.cpp @@ -21,6 +21,9 @@ // EXTERNAL INCLUDES #include #include +#include +#include +#include // INTERNAL INCLUDES #include @@ -37,15 +40,41 @@ namespace Internal namespace { -const float TEXT_PADDING = 12.0f; -const float ANIMATION_TIME( 0.2f ); +const float ANIMATION_TIME( 0.2f ); +const Padding DEFAULT_LABEL_PADDING( 12.0f, 12.0f, 12.0f, 12.0f ); +const Padding DEFAULT_ICON_PADDING( 12.0f, 12.0f, 12.0f, 12.0f ); BaseHandle Create() { return Toolkit::PushButton::New(); } -TypeRegistration typeRegistration( typeid(Toolkit::PushButton), typeid(Toolkit::Button), Create ); +// Properties + +DALI_TYPE_REGISTRATION_BEGIN( Toolkit::PushButton, Toolkit::Button, Create ) + +DALI_PROPERTY_REGISTRATION( Toolkit, PushButton, "unselectedIcon", STRING, UNSELECTED_ICON ) +DALI_PROPERTY_REGISTRATION( Toolkit, PushButton, "selectedIcon", STRING, SELECTED_ICON ) +DALI_PROPERTY_REGISTRATION( Toolkit, PushButton, "iconAlignment", STRING, ICON_ALIGNMENT ) +DALI_PROPERTY_REGISTRATION( Toolkit, PushButton, "labelPadding", STRING, LABEL_PADDING ) +DALI_PROPERTY_REGISTRATION( Toolkit, PushButton, "iconPadding", STRING, ICON_PADDING ) + +DALI_TYPE_REGISTRATION_END() + +/* + * Table to define Text-to-enum conversions for IconAlignment. + */ +const Dali::Scripting::StringEnum IconAlignmentTable[] = { + { "LEFT", Toolkit::Internal::PushButton::LEFT }, + { "RIGHT", Toolkit::Internal::PushButton::RIGHT }, + { "TOP", Toolkit::Internal::PushButton::TOP }, + { "BOTTOM", Toolkit::Internal::PushButton::BOTTOM }, +}; const unsigned int IconAlignmentTableCount = sizeof( IconAlignmentTable ) / sizeof( IconAlignmentTable[0] ); + +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 @@ -86,6 +115,9 @@ Dali::Toolkit::PushButton PushButton::New() PushButton::PushButton() : Button(), + mLabelPadding( DEFAULT_LABEL_PADDING ), + mIconPadding( DEFAULT_ICON_PADDING ), + mIconAlignment( RIGHT ), mSize() { SetAnimationTime( ANIMATION_TIME ); @@ -103,477 +135,244 @@ 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 ); + + SetUnselectedImage( UNSELECTED_BUTTON_IMAGE_DIR ); + SetSelectedImage( SELECTED_BUTTON_IMAGE_DIR ); + SetDisabledImage( DISABLED_UNSELECTED_BUTTON_IMAGE_DIR ); + SetDisabledSelectedImage( DISABLED_SELECTED_BUTTON_IMAGE_DIR ); } -void PushButton::OnLabelSet() +void PushButton::SetIcon( DecorationState state, const std::string iconFilename ) { - Actor& label = GetLabel(); - - if( label ) - { - label.SetAnchorPoint( AnchorPoint::CENTER ); - label.SetParentOrigin( ParentOrigin::CENTER ); - label.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - - Toolkit::TextLabel textLabel = Toolkit::TextLabel::DownCast( label ); - if( textLabel ) - { - textLabel.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - textLabel.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); - textLabel.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true ); - } - } + mIconName[ state ] = iconFilename; + SetDecoration( state, ImageActor::New( Dali::ResourceImage::New( iconFilename ) ) ); + ConfigureSizeNegotiation(); } -void PushButton::OnButtonImageSet() +std::string& PushButton::GetIcon( DecorationState state ) { - Actor& buttonImage = GetButtonImage(); - - buttonImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - - buttonImage.RelayoutRequestTree(); - - RelayoutRequest(); + return mIconName[ state ]; } -void PushButton::OnSelectedImageSet() +void PushButton::SetIconAlignment( const PushButton::IconAlignment iconAlignment ) { - Actor& selectedImage = GetSelectedImage(); - - selectedImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - - selectedImage.RelayoutRequestTree(); - - RelayoutRequest(); + mIconAlignment = iconAlignment; + ConfigureSizeNegotiation(); } -void PushButton::OnBackgroundImageSet() +const PushButton::IconAlignment PushButton::GetIconAlignment() const { - Actor& backgroundImage = GetBackgroundImage(); - - backgroundImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - - backgroundImage.RelayoutRequestTree(); - - RelayoutRequest(); + return mIconAlignment; } -void PushButton::OnSelectedBackgroundImageSet() +void PushButton::SetLabelPadding( const Vector4& padding ) { - Actor& selectedBackgroundImage = GetSelectedBackgroundImage(); - - selectedBackgroundImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + mLabelPadding = Padding( padding.x, padding.y, padding.z, padding.w ); + ConfigureSizeNegotiation(); } -void PushButton::OnDisabledImageSet() +Vector4 PushButton::GetLabelPadding() { - Actor& disabledImage = GetDisabledImage(); - - disabledImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - - disabledImage.RelayoutRequestTree(); - - RelayoutRequest(); + return Vector4( mLabelPadding.left, mLabelPadding.right, mLabelPadding.top, mLabelPadding.bottom ); } -void PushButton::OnDisabledBackgroundImageSet() +void PushButton::SetIconPadding( const Vector4& padding ) { - Actor& disabledBackgroundImage = GetDisabledBackgroundImage(); - - disabledBackgroundImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - - disabledBackgroundImage.RelayoutRequestTree(); - - RelayoutRequest(); + mIconPadding = Padding( padding.x, padding.y, padding.z, padding.w ); + ConfigureSizeNegotiation(); } -bool PushButton::OnSelected() +Vector4 PushButton::GetIconPadding() { - Actor& buttonImage = GetButtonImage(); - Actor& selectedImage = GetSelectedImage(); - Actor& selectedBackgroundImage = GetSelectedBackgroundImage(); + return Vector4( mIconPadding.left, mIconPadding.right, mIconPadding.top, mIconPadding.bottom ); +} - PaintState paintState = GetPaintState(); +void PushButton::SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value ) +{ + Toolkit::PushButton pushButton = Toolkit::PushButton::DownCast( Dali::BaseHandle( object ) ); - switch( paintState ) + if ( pushButton ) { - case UnselectedState: - { - FadeOutImage( buttonImage ); - FadeInImage( selectedBackgroundImage ); - FadeInImage( selectedImage ); - StartTransitionAnimation(); - break; - } - case SelectedState: - { - FadeOutImage( selectedBackgroundImage ); - FadeOutImage( selectedImage ); - FadeInImage( buttonImage ); - StartTransitionAnimation(); - break; - } - case UnselectedSelectedTransition: + PushButton& pushButtonImpl( GetImplementation( pushButton ) ); + + switch ( propertyIndex ) { - float opacity = 1.f; - if( selectedImage ) + case Toolkit::PushButton::Property::UNSELECTED_ICON: { - opacity = selectedImage.GetCurrentOpacity(); + pushButtonImpl.SetIcon( UNSELECTED_DECORATION, value.Get< std::string >() ); + break; } - - StopTransitionAnimation( false ); - FadeOutImage( selectedBackgroundImage, opacity ); - FadeOutImage( selectedImage, opacity ); - FadeInImage( buttonImage, 1.f - opacity ); - StartTransitionAnimation(); - break; - } - case SelectedUnselectedTransition: - { - float opacity = 0.f; - if( selectedImage ) + case Toolkit::PushButton::Property::SELECTED_ICON: { - opacity = selectedImage.GetCurrentOpacity(); + pushButtonImpl.SetIcon( SELECTED_DECORATION, value.Get< std::string >() ); + break; + } + case Toolkit::PushButton::Property::ICON_ALIGNMENT: + { + IconAlignment iconAlignment; + if( Scripting::GetEnumeration< IconAlignment >( value.Get< std::string >().c_str(), IconAlignmentTable, IconAlignmentTableCount, iconAlignment ) ) + { + pushButtonImpl.SetIconAlignment( iconAlignment ); + } + break; + } + case Toolkit::PushButton::Property::LABEL_PADDING: + { + pushButtonImpl.SetLabelPadding( value.Get< Vector4 >() ); + break; + } + case Toolkit::PushButton::Property::ICON_PADDING: + { + pushButtonImpl.SetIconPadding( value.Get< Vector4 >() ); + break; } - - 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() +Property::Value PushButton::GetProperty( BaseObject* object, Property::Index propertyIndex ) { - Actor& buttonImage = GetButtonImage(); - Actor& selectedImage = GetSelectedImage(); - Actor& selectedBackgroundImage = GetSelectedBackgroundImage(); - Actor& backgroundImage = GetBackgroundImage(); - Actor& disabledImage = GetDisabledImage(); - Actor& disabledSelectedImage = GetDisabledSelectedImage(); - Actor& disabledBackgroundImage = GetDisabledBackgroundImage(); + Property::Value value; - PaintState paintState = GetPaintState(); + Toolkit::PushButton pushButton = Toolkit::PushButton::DownCast( Dali::BaseHandle( object ) ); - switch( paintState ) + if ( pushButton ) { - 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(); - } + PushButton& pushButtonImpl( GetImplementation( pushButton ) ); - StopTransitionAnimation(); - FadeOutImage( backgroundImage ); - FadeOutImage( selectedBackgroundImage, opacity ); - FadeOutImage( selectedImage, opacity ); - FadeInImage( disabledBackgroundImage ); - FadeInImage( disabledSelectedImage ); - StartTransitionAnimation(); - break; - } - case SelectedUnselectedTransition: + switch ( propertyIndex ) { - float opacity = 1.f; - if( buttonImage ) + case Toolkit::PushButton::Property::UNSELECTED_ICON: { - opacity = buttonImage.GetCurrentOpacity(); + value = pushButtonImpl.GetIcon( UNSELECTED_DECORATION ); + break; } - - StopTransitionAnimation(); - FadeOutImage( backgroundImage ); - FadeOutImage( buttonImage, opacity ); - FadeInImage( disabledBackgroundImage ); - FadeInImage( disabledImage ); - StartTransitionAnimation(); - break; - } - case UnselectedDisabledTransition: - { - float opacity = 1.f; - if( disabledImage ) + case Toolkit::PushButton::Property::SELECTED_ICON: { - opacity = disabledImage.GetCurrentOpacity(); + value = pushButtonImpl.GetIcon( UNSELECTED_DECORATION ); + break; } - - 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 ) + case Toolkit::PushButton::Property::ICON_ALIGNMENT: { - opacity = buttonImage.GetCurrentOpacity(); + value = Scripting::GetLinearEnumerationName< IconAlignment >( pushButtonImpl.GetIconAlignment(), IconAlignmentTable, IconAlignmentTableCount ); + break; } - - 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 ) + case Toolkit::PushButton::Property::LABEL_PADDING: { - opacity = disabledSelectedImage.GetCurrentOpacity(); + value = pushButtonImpl.GetLabelPadding(); + break; } - - 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 ) + case Toolkit::PushButton::Property::ICON_PADDING: { - opacity = selectedImage.GetCurrentOpacity(); + value = pushButtonImpl.GetIconPadding(); + break; } - - 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; + return value; } -bool PushButton::OnPressed() +void PushButton::OnLabelSet( bool noPadding ) { - Actor& buttonImage = GetButtonImage(); - Actor& selectedImage = GetSelectedImage(); - Actor& selectedBackgroundImage = GetSelectedBackgroundImage(); - - PaintState paintState = GetPaintState(); + Actor& label = GetLabelActor(); - switch( paintState ) + if( label ) { - case UnselectedState: + if( noPadding ) { - FadeOutImage( buttonImage ); - FadeInImage( selectedBackgroundImage ); - FadeInImage( selectedImage ); - StartTransitionAnimation(); - break; + mLabelPadding = Padding( 0.0f, 0.0f, 0.0f, 0.0f ); } - 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: + Toolkit::TextLabel textLabel = Toolkit::TextLabel::DownCast( label ); + if( textLabel ) { - float opacity = 1.f; - if( buttonImage ) - { - opacity = buttonImage.GetCurrentOpacity(); - } - - StopTransitionAnimation(); - FadeOutImage( buttonImage, opacity ); - FadeInImage( selectedBackgroundImage ); - FadeInImage( selectedImage ); - StartTransitionAnimation(); - break; + textLabel.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, false ); } - default: - break; } + ConfigureSizeNegotiation(); +} - if( mTransitionAnimation ) - { - return true; - } +void PushButton::OnButtonImageSet() +{ + ConfigureSizeNegotiation(); +} - return false; +void PushButton::OnSelectedImageSet() +{ + ConfigureSizeNegotiation(); } -bool PushButton::OnReleased() +void PushButton::OnBackgroundImageSet() { - Actor& buttonImage = GetButtonImage(); - Actor& selectedImage = GetSelectedImage(); - Actor& selectedBackgroundImage = GetSelectedBackgroundImage(); + ConfigureSizeNegotiation(); +} - PaintState paintState = GetPaintState(); +void PushButton::OnSelectedBackgroundImageSet() +{ + ConfigureSizeNegotiation(); +} + +void PushButton::OnDisabledImageSet() +{ + ConfigureSizeNegotiation(); +} + +void PushButton::OnDisabledSelectedImageSet() +{ + ConfigureSizeNegotiation(); +} - switch( paintState ) +void PushButton::OnDisabledBackgroundImageSet() +{ + ConfigureSizeNegotiation(); +} + +void PushButton::OnSizeSet( const Vector3& targetSize ) +{ + if( targetSize != mSize ) { - case SelectedState: - { - FadeOutImage( selectedBackgroundImage ); - FadeOutImage( selectedImage ); - FadeInImage( buttonImage ); - StartTransitionAnimation(); - break; - } - case UnselectedSelectedTransition: - { - float opacity = 1.f; - if( selectedImage ) - { - opacity = selectedImage.GetCurrentOpacity(); - } + mSize = targetSize; - 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(); - } + Actor& label = GetLabelActor(); - StopTransitionAnimation(); - FadeOutImage( selectedBackgroundImage, opacity ); - FadeOutImage( selectedImage, opacity ); - FadeInImage( buttonImage ); - StartTransitionAnimation(); - break; - } - default: + if( label ) { - break; + label.SetSize( mSize ); } } +} - if( mTransitionAnimation ) - { - return true; - } +void PushButton::PrepareForTranstionIn( Actor actor ) +{ + actor.SetOpacity( 0.0f ); +} - return false; +void PushButton::PrepareForTranstionOut( Actor actor ) +{ + actor.SetOpacity( 1.0f ); } -void PushButton::StopAllAnimations() +void PushButton::OnTransitionIn( Actor actor ) { - StopTransitionAnimation(); + FadeImageTo( actor, 1.f ); } -void PushButton::OnControlSizeSet( const Vector3& targetSize ) +void PushButton::OnTransitionOut( Actor actor ) { - if( targetSize != mSize ) - { - mSize = targetSize; + FadeImageTo( actor, 0.0f ); +} - Actor& label = GetLabel(); +void PushButton::FadeImageTo( Actor actor, float opacity ) +{ + if( actor ) + { + Dali::Animation transitionAnimation = GetTransitionAnimation(); + DALI_ASSERT_DEBUG( transitionAnimation ); - if( label ) + if( transitionAnimation ) { - label.SetSize( mSize ); + transitionAnimation.AnimateTo( Property( actor, Actor::Property::COLOR_ALPHA ), opacity ); } } } @@ -582,82 +381,222 @@ Vector3 PushButton::GetNaturalSize() { Vector3 size; - // Check Image and Background image and use the largest size as the control's Natural size. - SizeOfActorIfLarger( GetButtonImage(), size ); - SizeOfActorIfLarger( GetBackgroundImage(), size ); - // If label, test against it's size - Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( GetLabel() ); - if( label ) + Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( GetLabelActor() ); + + Actor icon = GetDecoration( UNSELECTED_DECORATION ); + if( label || icon ) { - Vector3 labelSize = label.GetNaturalSize(); + Vector3 labelSize( Vector3::ZERO ); + Vector3 iconSize( Vector3::ZERO ); + + if( label ) + { + Vector3 labelNaturalSize = label.GetNaturalSize(); + labelSize.width = labelNaturalSize.width + mLabelPadding.left + mLabelPadding.right; + labelSize.height = labelNaturalSize.height + mLabelPadding.top + mLabelPadding.bottom; + } + + if( icon ) + { + Vector3 iconNaturalSize = icon.GetNaturalSize(); + iconSize.width = iconNaturalSize.width + mIconPadding.left + mIconPadding.right; + iconSize.height = iconNaturalSize.height + mIconPadding.top + mIconPadding.bottom; - size.width = std::max( size.width, labelSize.width + TEXT_PADDING * 2.0f ); - size.height = std::max( size.height, labelSize.height + TEXT_PADDING * 2.0f ); + switch( mIconAlignment ) + { + case LEFT: + case RIGHT: + { + size.width = labelSize.width + iconSize.width; + size.height = std::max( labelSize.height, iconSize.height ); + break; + } + case TOP: + case BOTTOM: + { + size.width = std::max( labelSize.width, iconSize.width ); + size.height = labelSize.height + iconSize.height; + break; + } + } + } + else + { + // No icon, so size is the same as label size. + // (If there is no label this is zero). + size = labelSize; + } + } + else + { + // Check Image and Background image and use the largest size as the control's Natural size. + SizeOfActorIfLarger( GetUnselectedImage(), size ); + SizeOfActorIfLarger( GetBackgroundImage(), size ); } return size; } -void PushButton::StartTransitionAnimation() +void PushButton::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension ) { - if( mTransitionAnimation ) - { - mTransitionAnimation.FinishedSignal().Connect( this, &PushButton::TransitionAnimationFinished ); - mTransitionAnimation.Play(); - } + ConfigureSizeNegotiation(); } -void PushButton::StopTransitionAnimation( bool remove ) +void PushButton::ConfigureSizeNegotiation() { - if( mTransitionAnimation ) + std::vector< Actor > images; + images.reserve( 7 ); + + images.push_back( GetUnselectedImage() ); + images.push_back( GetSelectedImage() ); + images.push_back( GetSelectedBackgroundImage() ); + images.push_back( GetBackgroundImage() ); + images.push_back( GetDisabledImage() ); + images.push_back( GetDisabledSelectedImage() ); + images.push_back( GetDisabledBackgroundImage() ); + + Actor label = GetLabelActor(); + + for( unsigned int i = 0; i < Dimension::DIMENSION_COUNT; ++i ) { - mTransitionAnimation.Clear(); - mTransitionAnimation.Reset(); + ConfigureSizeNegotiationDimension( static_cast< Dimension::Type >( 1 << i ), images, label ); } - if( remove ) + // Add any vertical padding directly to the actors. + Actor icon = GetDecoration( UNSELECTED_DECORATION ); + Actor selectedIcon = GetDecoration( SELECTED_DECORATION ); + bool iconExists = icon || selectedIcon; + + if( label ) { - UpdatePaintTransitionState(); + label.SetPadding( mLabelPadding ); } -} - -void PushButton::FadeInImage( Actor& image, float opacity, Vector3 scale ) -{ - if( image ) + if( icon ) + { + icon.SetPadding( mIconPadding ); + } + if( selectedIcon ) { - image.SetOpacity( opacity ); - image.SetScale( scale ); + selectedIcon.SetPadding( mIconPadding ); + } + + // Calculate and apply horizontal alignments and offsets + // to text and icon (depending on existence). + Vector3 iconPosition( Vector3::ZERO ); + Vector3 labelPosition( Vector3::ZERO ); + Vector3 iconAnchoring( AnchorPoint::CENTER ); + Vector3 labelAnchoring( AnchorPoint::CENTER ); + std::string horizontalLabelAlignment = "CENTER"; + std::string verticalLabelAlignment = "CENTER"; - if( !mTransitionAnimation ) + if( iconExists && label ) + { + // There is an icon and a label to lay out. + switch( mIconAlignment ) { - mTransitionAnimation = Dali::Animation::New( GetAnimationTime() ); + case LEFT: + { + iconPosition.x = mIconPadding.left; + labelPosition.x = -mLabelPadding.right; + iconAnchoring = AnchorPoint::CENTER_LEFT; + labelAnchoring = AnchorPoint::CENTER_RIGHT; + horizontalLabelAlignment = "END"; + break; + } + case RIGHT: + { + iconPosition.x = -mIconPadding.right; + labelPosition.x = mLabelPadding.left; + iconAnchoring = AnchorPoint::CENTER_RIGHT; + labelAnchoring = AnchorPoint::CENTER_LEFT; + horizontalLabelAlignment = "BEGIN"; + break; + } + case TOP: + { + iconPosition.y = mIconPadding.top; + labelPosition.y = -mLabelPadding.bottom; + iconAnchoring = AnchorPoint::TOP_CENTER; + labelAnchoring = AnchorPoint::BOTTOM_CENTER; + verticalLabelAlignment = "BOTTOM"; + break; + } + case BOTTOM: + { + iconPosition.y = -mIconPadding.bottom; + labelPosition.y = mLabelPadding.top; + iconAnchoring = AnchorPoint::BOTTOM_CENTER; + labelAnchoring = AnchorPoint::TOP_CENTER; + verticalLabelAlignment = "TOP"; + break; + } } + } + + // Note: If there is only an icon, or only a label, the default values are now correct. + // Setup the icon(s) with the precalculated values. + if( icon ) + { + icon.SetPosition( iconPosition ); + icon.SetParentOrigin( iconAnchoring ); + icon.SetAnchorPoint( iconAnchoring ); + } + if( selectedIcon ) + { + selectedIcon.SetPosition( iconPosition ); + selectedIcon.SetParentOrigin( iconAnchoring ); + selectedIcon.SetAnchorPoint( iconAnchoring ); + } - mTransitionAnimation.AnimateTo( Property( image, Actor::Property::COLOR_ALPHA ), 1.f ); + // Setup the label. + if( label ) + { + label.SetPosition( labelPosition ); + label.SetParentOrigin( labelAnchoring ); + label.SetAnchorPoint( labelAnchoring ); + label.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, horizontalLabelAlignment ); + label.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, verticalLabelAlignment ); } + + RelayoutRequest(); } -void PushButton::FadeOutImage( Actor& image, float opacity, Vector3 scale ) + +void PushButton::ConfigureSizeNegotiationDimension( Dimension::Type dimension, const std::vector< Actor >& images, Actor& label ) { - if( image ) - { - image.SetOpacity( opacity ); - image.SetScale( scale ); + ResizePolicy::Type imageResizePolicy = ResizePolicy::FILL_TO_PARENT; + ResizePolicy::Type labelResizePolicy = ResizePolicy::FILL_TO_PARENT; + + ResizePolicy::Type resizePolicy = Self().GetResizePolicy( dimension ); - if( !mTransitionAnimation ) + if( resizePolicy == ResizePolicy::FIT_TO_CHILDREN || resizePolicy == ResizePolicy::USE_NATURAL_SIZE ) + { + if( label ) + { + labelResizePolicy = ResizePolicy::USE_NATURAL_SIZE; + } + else { - mTransitionAnimation = Dali::Animation::New( GetAnimationTime() ); + imageResizePolicy = ResizePolicy::USE_NATURAL_SIZE; } + } + + if( label ) + { + label.SetResizePolicy( labelResizePolicy, dimension ); + } - mTransitionAnimation.AnimateTo( Property( image, Actor::Property::COLOR_ALPHA ), 0.f ); + for( std::vector< Actor >::const_iterator it = images.begin(), itEnd = images.end(); it != itEnd; ++it ) + { + Actor actor = *it; + if( actor ) + { + actor.SetResizePolicy( imageResizePolicy, dimension ); + } } } -void PushButton::TransitionAnimationFinished( Dali::Animation& source ) -{ - StopTransitionAnimation(); -} } // namespace Internal