X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fbuttons%2Fbutton-impl.cpp;h=28b9d4a65a00189a7827d43d8cdbac71c6bad975;hp=4072f4320dd1473eacc5d66ba7ba060d3b1be196;hb=06e563f8a982e25a0efe2d91c794657dc8e4bc4a;hpb=0d7ddec50cf09372fb2a830c6e8cdc7af70d362f diff --git a/dali-toolkit/internal/controls/buttons/button-impl.cpp b/dali-toolkit/internal/controls/buttons/button-impl.cpp index 4072f43..28b9d4a 100644 --- a/dali-toolkit/internal/controls/buttons/button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/button-impl.cpp @@ -21,12 +21,14 @@ // EXTERNAL INCLUDES #include // for strcmp #include +#include #include #include #include #include // INTERNAL INCLUDES +#include #include /** @@ -80,10 +82,12 @@ DALI_PROPERTY_REGISTRATION( Toolkit, Button, "initial-auto-repeating-delay", FLO DALI_PROPERTY_REGISTRATION( Toolkit, Button, "next-auto-repeating-delay", FLOAT, NEXT_AUTO_REPEATING_DELAY ) DALI_PROPERTY_REGISTRATION( Toolkit, Button, "togglable", BOOLEAN, TOGGLABLE ) DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selected", BOOLEAN, SELECTED ) -DALI_PROPERTY_REGISTRATION( Toolkit, Button, "normal-state-actor", MAP, NORMAL_STATE_ACTOR ) -DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selected-state-actor", MAP, SELECTED_STATE_ACTOR ) -DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabled-state-actor", MAP, DISABLED_STATE_ACTOR ) -DALI_PROPERTY_REGISTRATION( Toolkit, Button, "label-actor", MAP, LABEL_ACTOR ) +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "unselected-state-image", STRING, UNSELECTED_STATE_IMAGE ) +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selected-state-image", STRING, SELECTED_STATE_IMAGE ) +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabled-state-image", STRING, DISABLED_STATE_IMAGE ) +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "unselected-color", VECTOR4, UNSELECTED_COLOR ) +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selected-color", VECTOR4, SELECTED_COLOR ) +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "label-text", STRING, LABEL_TEXT ) DALI_SIGNAL_REGISTRATION( Toolkit, Button, "pressed", SIGNAL_PRESSED ) DALI_SIGNAL_REGISTRATION( Toolkit, Button, "released", SIGNAL_RELEASED ) @@ -97,11 +101,15 @@ DALI_TYPE_REGISTRATION_END() const unsigned int INITIAL_AUTOREPEATING_DELAY( 0.15f ); const unsigned int NEXT_AUTOREPEATING_DELAY( 0.05f ); +const char* const STYLE_BUTTON_LABEL = "button.label"; + } // unnamed namespace Button::Button() : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ), mAutoRepeatingTimer(), + mUnselectedColor( Color::WHITE ), // The natural colors of the specified images will be used by default. + mSelectedColor( Color::WHITE ), mDisabled( false ), mAutoRepeating( false ), mTogglableButton( false ), @@ -143,9 +151,15 @@ void Button::SetDisabled( bool disabled ) //(2) mDisabledBackgroundContent (Inserted) //(1) mBackgroundContent - TransitionInBetween( mUnselectedContent, mLabel, mDisabledContent ); - TransitionInAbove( mBackgroundContent, mDisabledBackgroundContent ); + AddButtonImage( mBackgroundContent ); + TransitionButtonImage( mDisabledBackgroundContent ); + AddButtonImage( mUnselectedContent ); + TransitionButtonImage( mDisabledContent ); + + AddButtonImage( mDecoration[ UNSELECTED_DECORATION ] ); + ReAddLabel(); + TransitionOut( mDecoration[ SELECTED_DECORATION ] ); TransitionOut( mUnselectedContent ); TransitionOut( mSelectedContent ); TransitionOut( mBackgroundContent ); @@ -164,9 +178,16 @@ void Button::SetDisabled( bool disabled ) //(2) mSelectedBackgroundContent //(1) mBackgroundContent - TransitionInBetween( mSelectedContent, mLabel, mDisabledSelectedContent ); - TransitionInAbove( mSelectedBackgroundContent, mDisabledBackgroundContent ); + AddButtonImage( mBackgroundContent ); + AddButtonImage( mSelectedBackgroundContent ); + TransitionButtonImage( mDisabledBackgroundContent ); + AddButtonImage( mSelectedContent ); + TransitionButtonImage( mDisabledSelectedContent ); + AddButtonImage( mDecoration[ SELECTED_DECORATION ] ); + ReAddLabel(); + + TransitionOut( mDecoration[ UNSELECTED_DECORATION ] ); TransitionOut( mUnselectedContent ); TransitionOut( mSelectedContent ); TransitionOut( mBackgroundContent ); @@ -184,9 +205,15 @@ void Button::SetDisabled( bool disabled ) //(2) mBackgroundContent (Inserted) //(1) mDisabledBackgroundContent - TransitionInBetween( mDisabledContent, mLabel, mUnselectedContent ); - TransitionInAbove( mDisabledBackgroundContent, mBackgroundContent ); + AddButtonImage( mDisabledBackgroundContent ); + TransitionButtonImage( mBackgroundContent ); + AddButtonImage( mDisabledContent ); + TransitionButtonImage( mUnselectedContent ); + + AddButtonImage( mDecoration[ UNSELECTED_DECORATION ] ); + ReAddLabel(); + TransitionOut( mDecoration[ SELECTED_DECORATION ] ); TransitionOut( mSelectedContent ); TransitionOut( mSelectedBackgroundContent ); TransitionOut( mDisabledContent ); @@ -205,10 +232,16 @@ void Button::SetDisabled( bool disabled ) //(2) mBackgroundContent (Inserted) //(1) mDisabledBackgroundContent - TransitionInBetween( mDisabledSelectedContent, mLabel, mSelectedContent ); - TransitionInAbove( mDisabledBackgroundContent, mSelectedBackgroundContent ); - TransitionInAbove( mDisabledBackgroundContent, mBackgroundContent ); + AddButtonImage( mDisabledBackgroundContent ); + TransitionButtonImage( mBackgroundContent ); + TransitionButtonImage( mSelectedBackgroundContent ); + AddButtonImage( mDisabledSelectedContent ); + TransitionButtonImage( mSelectedContent ); + AddButtonImage( mDecoration[ SELECTED_DECORATION ] ); + ReAddLabel(); + + TransitionOut( mDecoration[ UNSELECTED_DECORATION ] ); TransitionOut( mUnselectedContent ); TransitionOut( mDisabledContent ); TransitionOut( mDisabledSelectedContent ); @@ -314,10 +347,16 @@ void Button::SetSelected( bool selected, bool emitSignal ) //(2) mSelectedBackgroundContent (Inserted) //(1) mBackgroundContent - TransitionInBetween( mUnselectedContent, mLabel, mSelectedContent ); - TransitionInAbove( mBackgroundContent, mSelectedBackgroundContent ); - TransitionInAtIndex( 0, mBackgroundContent ); + AddButtonImage( mBackgroundContent ); + TransitionButtonImage( mSelectedBackgroundContent ); + AddButtonImage( mUnselectedContent ); + TransitionButtonImage( mSelectedContent ); + + AddButtonImage( mDecoration[ UNSELECTED_DECORATION ] ); + TransitionButtonImage( mDecoration[ SELECTED_DECORATION ] ); + ReAddLabel(); + TransitionOut( mDecoration[ UNSELECTED_DECORATION ] ); TransitionOut( mUnselectedContent ); TransitionOut( mDisabledContent ); TransitionOut( mDisabledSelectedContent ); @@ -333,9 +372,15 @@ void Button::SetSelected( bool selected, bool emitSignal ) //(2) mSelectedContent //(1) mBackgroundContent - TransitionInBetween( mSelectedContent, mLabel, mUnselectedContent ); - TransitionInAtIndex( 0, mBackgroundContent ); + AddButtonImage( mBackgroundContent ); + AddButtonImage( mSelectedContent ); + TransitionButtonImage( mUnselectedContent ); + + AddButtonImage( mDecoration[ SELECTED_DECORATION ] ); + TransitionButtonImage( mDecoration[ UNSELECTED_DECORATION ] ); + ReAddLabel(); + TransitionOut( mDecoration[ SELECTED_DECORATION ] ); TransitionOut( mSelectedContent ); TransitionOut( mSelectedBackgroundContent ); TransitionOut( mDisabledContent ); @@ -381,26 +426,24 @@ float Button::GetAnimationTime() const return mAnimationTime; } -void Button::SetLabel( const std::string& label ) +void Button::SetLabelText( const std::string& label ) { - Toolkit::TextLabel textLabel = Toolkit::TextLabel::New( label ); - SetLabel( textLabel ); -} - -void Button::SetLabel( Actor label ) -{ - if( mLabel != label ) + if( !mLabel || ( label != GetLabelText() ) ) { - if( mLabel && mLabel.GetParent() ) + // If we have a label, unparent and update it. + if( mLabel ) { - mLabel.GetParent().Remove( mLabel ); + mLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, label ); + } + else + { + // If we don't have a label, create one and set it up. + mLabel = Toolkit::TextLabel::New( label ); + mLabel.SetProperty( Toolkit::Control::Property::STYLE_NAME, STYLE_BUTTON_LABEL ); + mLabel.SetPosition( 0.f, 0.f ); + // label should be the top of the button + Self().Add( mLabel ); } - - mLabel = label; - mLabel.SetPosition( 0.f, 0.f ); - - // label should be the top of the button - Self().Add( mLabel ); OnLabelSet(); @@ -408,168 +451,216 @@ void Button::SetLabel( Actor label ) } } -Actor Button::GetLabel() const +std::string Button::GetLabelText() const { - return mLabel; + Toolkit::TextLabel label = Dali::Toolkit::TextLabel::DownCast( mLabel ); + if( label ) + { + return label.GetProperty( Dali::Toolkit::TextLabel::Property::TEXT ); + } + return std::string(); } -Actor& Button::GetLabel() +Actor& Button::GetLabelActor() { return mLabel; } -void Button::SetButtonImage( Actor image ) +void Button::SetDecoration( DecorationState state, Actor actor ) { - StopTransitionAnimation(); - - if( mUnselectedContent && mUnselectedContent.GetParent() ) + if( mDecoration[ state ] && mDecoration[ state ].GetParent() ) { - Self().Remove( mUnselectedContent ); + mDecoration[ state ].Unparent(); } - mUnselectedContent = image; - if( mUnselectedContent ) - { - mUnselectedContent.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - mUnselectedContent.SetParentOrigin( ParentOrigin::TOP_LEFT ); - mUnselectedContent.SetPosition( 0.f, 0.f ); - } - ResetImageLayers(); - OnButtonImageSet(); + mDecoration[ state ] = actor; + mDecoration[ state ].SetColorMode( USE_OWN_COLOR ); + ResetImageLayers(); RelayoutRequest(); } -Actor Button::GetButtonImage() const +Actor& Button::GetDecoration( DecorationState state ) { - return mUnselectedContent; + return mDecoration[ state ]; } -Actor& Button::GetButtonImage() +void Button::SetupContent( Actor& actorToModify, Actor newActor ) { - return mUnselectedContent; + if( newActor ) + { + StopTransitionAnimation(); + + if( actorToModify && actorToModify.GetParent() ) + { + actorToModify.Unparent(); + } + + actorToModify = newActor; + + if( actorToModify ) + { + actorToModify.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + actorToModify.SetParentOrigin( ParentOrigin::TOP_LEFT ); + actorToModify.SetPosition( 0.f, 0.f ); + } + + ResetImageLayers(); + } } -void Button::SetSelectedImage( Actor image ) +void Button::SetUnselectedColor( const Vector4& color ) { - StopTransitionAnimation(); + mUnselectedColor = color; - if( mSelectedContent && mSelectedContent.GetParent() ) + if( mUnselectedContent && !GetUnselectedImageFilename().empty() ) { - Self().Remove( mSelectedContent ); + // If there is existing unselected content, change the color on it directly. + mUnselectedContent.SetColor( mUnselectedColor ); } - - mSelectedContent = image; - if( mSelectedContent ) + else { - mSelectedContent.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - mSelectedContent.SetParentOrigin( ParentOrigin::TOP_LEFT ); - mSelectedContent.SetPosition( 0.f, 0.f ); + // If there is no existing content, create a new actor to use for flat color. + SetupContent( mUnselectedContent, CreateSolidColorActor( mUnselectedColor ) ); + mUnselectedContent.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); } - ResetImageLayers(); - OnSelectedImageSet(); - - RelayoutRequest(); } -Actor Button::GetSelectedImage() const +const Vector4 Button::GetUnselectedColor() const { - return mSelectedContent; + return mUnselectedColor; } -Actor& Button::GetSelectedImage() +void Button::SetSelectedColor( const Vector4& color ) { - return mSelectedContent; + mSelectedColor = color; + + if( mSelectedContent && !GetSelectedImageFilename().empty() ) + { + // If there is existing unselected content, change the color on it directly. + mSelectedContent.SetColor( mSelectedColor ); + } + else + { + // If there is no existing content, create a new actor to use for flat color. + SetupContent( mSelectedContent, CreateSolidColorActor( mSelectedColor ) ); + mSelectedContent.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + } } -void Button::SetBackgroundImage( Actor image ) +const Vector4 Button::GetSelectedColor() const { - StopTransitionAnimation(); + return mSelectedColor; +} - if( mBackgroundContent && mBackgroundContent.GetParent() ) +void Button::SetUnselectedImage( const std::string& filename ) +{ + ImageActor newContent; + if( !filename.empty() ) { - Self().Remove( mBackgroundContent ); + Image resourceimage = Dali::ResourceImage::New( filename ); + if( resourceimage ) + { + newContent = ImageActor::New( resourceimage ); + } } - - mBackgroundContent = image; - if( mBackgroundContent ) + else { - mBackgroundContent.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - mBackgroundContent.SetParentOrigin( ParentOrigin::TOP_LEFT ); - mBackgroundContent.SetPosition( 0.f, 0.f ); + newContent = ImageActor::New(); } - ResetImageLayers(); - OnBackgroundImageSet(); - RelayoutRequest(); -} + if( newContent ) + { + SetupContent( mUnselectedContent, newContent ); -Actor Button::GetBackgroundImage() const -{ - return mBackgroundContent; + mUnselectedContent.SetColor( mUnselectedColor ); + + OnUnselectedImageSet(); + RelayoutRequest(); + } } -Actor& Button::GetBackgroundImage() +Actor& Button::GetUnselectedImage() { - return mBackgroundContent; + return mUnselectedContent; } -void Button::SetSelectedBackgroundImage( Actor image ) +void Button::SetSelectedImage( const std::string& filename ) { - StopTransitionAnimation(); - - if( mSelectedBackgroundContent && mSelectedBackgroundContent.GetParent() ) + ImageActor newContent; + if( !filename.empty() ) { - Self().Remove( mSelectedBackgroundContent ); + Image resourceimage = Dali::ResourceImage::New( filename ); + if( resourceimage ) + { + newContent = ImageActor::New( resourceimage ); + } } - - mSelectedBackgroundContent = image; - if( mSelectedBackgroundContent ) + else { - mSelectedBackgroundContent.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - mSelectedBackgroundContent.SetParentOrigin( ParentOrigin::TOP_LEFT ); - mSelectedBackgroundContent.SetPosition( 0.f, 0.f ); + newContent = ImageActor::New(); } - ResetImageLayers(); - OnSelectedBackgroundImageSet(); - RelayoutRequest(); + if( newContent ) + { + SetupContent( mSelectedContent, newContent ); + + mSelectedContent.SetColor( mSelectedColor ); + + OnSelectedImageSet(); + RelayoutRequest(); + } } -Actor Button::GetSelectedBackgroundImage() const +Actor& Button::GetSelectedImage() { - return mSelectedBackgroundContent; + return mSelectedContent; } -Actor& Button::GetSelectedBackgroundImage() +void Button::SetBackgroundImage( const std::string& filename ) { - return mSelectedBackgroundContent; + Image resourceimage = Dali::ResourceImage::New( filename ); + if( resourceimage ) + { + SetupContent( mBackgroundContent, ImageActor::New( resourceimage ) ); + + OnBackgroundImageSet(); + RelayoutRequest(); + } } -void Button::SetDisabledImage( Actor image ) +Actor& Button::GetBackgroundImage() { - StopTransitionAnimation(); + return mBackgroundContent; +} - if( mDisabledContent && mDisabledContent.GetParent() ) +void Button::SetSelectedBackgroundImage( const std::string& filename ) +{ + Image resourceimage = Dali::ResourceImage::New( filename ); + if( resourceimage ) { - Self().Remove( mDisabledContent ); - } + SetupContent( mSelectedBackgroundContent, ImageActor::New( resourceimage ) ); - mDisabledContent = image; - if( mDisabledContent ) - { - mDisabledContent.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - mDisabledContent.SetParentOrigin( ParentOrigin::TOP_LEFT ); - mDisabledContent.SetPosition( 0.f, 0.f ); + OnSelectedBackgroundImageSet(); + RelayoutRequest(); } +} - ResetImageLayers(); - OnDisabledImageSet(); +Actor& Button::GetSelectedBackgroundImage() +{ + return mSelectedBackgroundContent; } -Actor Button::GetDisabledImage() const +void Button::SetDisabledImage( const std::string& filename ) { - return mDisabledContent; + Image resourceimage = Dali::ResourceImage::New( filename ); + if( resourceimage ) + { + SetupContent( mDisabledContent, ImageActor::New( resourceimage ) ); + + OnDisabledImageSet(); + RelayoutRequest(); + } } Actor& Button::GetDisabledImage() @@ -577,65 +668,129 @@ Actor& Button::GetDisabledImage() return mDisabledContent; } -void Button::SetDisabledSelectedImage( Actor image ) +void Button::SetDisabledSelectedImage( const std::string& filename ) { - StopTransitionAnimation(); - - if( mDisabledSelectedContent && mDisabledSelectedContent.GetParent() ) + Image resourceimage = Dali::ResourceImage::New( filename ); + if( resourceimage ) { - Self().Remove( mDisabledSelectedContent ); + SetupContent( mDisabledSelectedContent, ImageActor::New( resourceimage ) ); + + OnDisabledSelectedImageSet(); + RelayoutRequest(); } +} - mDisabledSelectedContent = image; - if( mDisabledSelectedContent ) +Actor& Button::GetDisabledSelectedImage() +{ + return mDisabledSelectedContent; +} + +void Button::SetDisabledBackgroundImage( const std::string& filename ) +{ + Image resourceimage = Dali::ResourceImage::New( filename ); + if( resourceimage ) { - mDisabledSelectedContent.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - mDisabledSelectedContent.SetParentOrigin( ParentOrigin::TOP_LEFT ); - mDisabledSelectedContent.SetPosition( 0.f, 0.f ); + SetupContent( mDisabledBackgroundContent, ImageActor::New( resourceimage ) ); + + OnDisabledBackgroundImageSet(); + RelayoutRequest(); } +} - ResetImageLayers(); - OnDisabledSelectedImageSet(); +Actor& Button::GetDisabledBackgroundImage() +{ + return mDisabledBackgroundContent; } -Actor Button::GetDisabledSelectedImage() const +std::string Button::GetUnselectedImageFilename() const { - return mDisabledSelectedContent; + if( mUnselectedContent ) + { + ResourceImage image = ResourceImage::DownCast( mUnselectedContent ); + if( image ) + { + return image.GetUrl(); + } + } + return std::string(); } -Actor& Button::GetDisabledSelectedImage() +std::string Button::GetSelectedImageFilename() const { - return mDisabledSelectedContent; + if( mSelectedContent ) + { + ResourceImage image = ResourceImage::DownCast( mSelectedContent ); + if( image ) + { + return image.GetUrl(); + } + } + return std::string(); } -void Button::SetDisabledBackgroundImage( Actor image ) +std::string Button::GetBackgroundImageFilename() const { - StopTransitionAnimation(); + if( mBackgroundContent ) + { + ResourceImage image = ResourceImage::DownCast( mBackgroundContent ); + if( image ) + { + return image.GetUrl(); + } + } + return std::string(); +} - if( mDisabledBackgroundContent && mDisabledBackgroundContent.GetParent() ) +std::string Button::GetSelectedBackgroundImageFilename() const +{ + if( mSelectedBackgroundContent ) { - Self().Remove( mDisabledBackgroundContent ); + ResourceImage image = ResourceImage::DownCast( mSelectedBackgroundContent ); + if( image ) + { + return image.GetUrl(); + } } + return std::string(); +} - mDisabledBackgroundContent = image; - if( mDisabledBackgroundContent ) +std::string Button::GetDisabledImageFilename() const +{ + if( mDisabledContent ) { - mDisabledBackgroundContent.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - mDisabledBackgroundContent.SetParentOrigin( ParentOrigin::TOP_LEFT ); - mDisabledBackgroundContent.SetPosition( 0.f, 0.f ); + ResourceImage image = ResourceImage::DownCast( mDisabledContent ); + if( image ) + { + return image.GetUrl(); + } } - ResetImageLayers(); - OnDisabledBackgroundImageSet(); + return std::string(); } -Actor Button::GetDisabledBackgroundImage() const +std::string Button::GetDisabledSelectedImageFilename() const { - return mDisabledBackgroundContent; + if( mDisabledSelectedContent ) + { + ResourceImage image = ResourceImage::DownCast( mDisabledSelectedContent ); + if( image ) + { + return image.GetUrl(); + } + } + return std::string(); } -Actor& Button::GetDisabledBackgroundImage() +std::string Button::GetDisabledBackgroundImageFilename() const { - return mDisabledBackgroundContent; + if( mDisabledBackgroundContent ) + { + ResourceImage image = ResourceImage::DownCast( mDisabledBackgroundContent ); + if( image ) + { + return image.GetUrl(); + } + } + return std::string(); } bool Button::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes ) @@ -694,18 +849,17 @@ void Button::OnButtonDown() { if( !mTogglableButton ) { - Toolkit::Button handle( GetOwner() ); - Pressed(); if( mAutoRepeating ) { SetUpTimer( mInitialAutoRepeatingDelay ); } - - //Emit signal. - mPressedSignal.Emit( handle ); } + + // The pressed signal should be emitted regardless of toggle mode. + Toolkit::Button handle( GetOwner() ); + mPressedSignal.Emit( handle ); } void Button::OnButtonUp() @@ -724,13 +878,12 @@ void Button::OnButtonUp() { mAutoRepeatingTimer.Reset(); } - - Toolkit::Button handle( GetOwner() ); - - //Emit signal. - mReleasedSignal.Emit( handle ); - mClickedSignal.Emit( handle ); } + + // The clicked and released signals should be emitted regardless of toggle mode. + Toolkit::Button handle( GetOwner() ); + mReleasedSignal.Emit( handle ); + mClickedSignal.Emit( handle ); } } @@ -740,18 +893,17 @@ void Button::OnTouchPointLeave() { if( !mTogglableButton ) { - Toolkit::Button handle( GetOwner() ); - Released(); if( mAutoRepeating ) { mAutoRepeatingTimer.Reset(); } - - //Emit signal. - mReleasedSignal.Emit( handle ); } + + // The released signal should be emitted regardless of toggle mode. + Toolkit::Button handle( GetOwner() ); + mReleasedSignal.Emit( handle ); } } @@ -949,18 +1101,24 @@ void Button::Pressed() StopTransitionAnimation(); // Notifies the derived class the button has been pressed. - OnPressed(); + OnPressed(); - //Layer Order + //Layer Order //(4) mSelectedContent (Inserted) //(3) mUnselectedContent //(2) mSelectedBackgroundContent (Inserted) //(1) mBackgroundContent - TransitionInBetween( mUnselectedContent, mLabel, mSelectedContent ); - TransitionInAbove( mBackgroundContent, mSelectedBackgroundContent ); - TransitionInAtIndex( 0, mBackgroundContent ); + AddButtonImage( mBackgroundContent ); + TransitionButtonImage( mSelectedBackgroundContent ); + AddButtonImage( mUnselectedContent ); + TransitionButtonImage( mSelectedContent ); + + AddButtonImage( mDecoration[ UNSELECTED_DECORATION ] ); + TransitionButtonImage( mDecoration[ SELECTED_DECORATION ] ); + ReAddLabel(); + TransitionOut( mDecoration[ UNSELECTED_DECORATION ] ); TransitionOut( mUnselectedContent ); TransitionOut( mDisabledContent ); TransitionOut( mDisabledSelectedContent ); @@ -986,9 +1144,15 @@ void Button::Released() //(2) mSelectedContent //(1) mBackgroundContent - TransitionInBetween( mSelectedContent, mLabel, mUnselectedContent ); - TransitionInAtIndex( 0, mBackgroundContent ); + AddButtonImage( mBackgroundContent ); + AddButtonImage( mSelectedContent ); + TransitionButtonImage( mUnselectedContent ); + + AddButtonImage( mDecoration[ SELECTED_DECORATION ] ); + TransitionButtonImage( mDecoration[ UNSELECTED_DECORATION ] ); + ReAddLabel(); + TransitionOut( mDecoration[ SELECTED_DECORATION ] ); TransitionOut( mSelectedContent ); TransitionOut( mSelectedBackgroundContent ); TransitionOut( mDisabledContent ); @@ -1011,16 +1175,45 @@ Button::PaintState Button::GetPaintState() return mPaintState; } -bool Button::InsertButtonImage( unsigned int index, Actor& actor ) +void Button::PrepareAddButtonImage( Actor& actor ) { if( actor ) { - Self().Insert( index, actor ); + actor.Unparent(); + Self().Add( actor ); PrepareForTranstionOut( actor ); - return true; } +} - return false; +void Button::TransitionButtonImage( Actor& actor ) +{ + if( actor ) + { + if( !actor.GetParent() ) + { + Self().Add( actor ); + } + + OnTransitionIn( actor ); + } +} + +void Button::AddButtonImage( Actor& actor ) +{ + if( actor ) + { + actor.Unparent(); + Self().Add( actor ); + } +} + +void Button::ReAddLabel() +{ + if( mLabel ) + { + mLabel.Unparent(); + Self().Add( mLabel ); + } } void Button::RemoveButtonImage( Actor& actor ) @@ -1052,31 +1245,6 @@ unsigned int Button::FindChildIndex( Actor& actor ) return childrenNum; } -void Button::TransitionInBetween( Actor childLower, Actor childUpper, Actor actor ) -{ - unsigned int index = childLower ? FindChildIndex( childLower ) + 1 : FindChildIndex( childUpper ); - TransitionInAtIndex( index, actor ); -} - -void Button::TransitionInAbove( Actor child, Actor actor ) -{ - unsigned int index = child ? FindChildIndex( child ) + 1 : 0; - TransitionInAtIndex( index, actor ); -} - -void Button::TransitionInAtIndex( unsigned int index, Actor actor ) -{ - if( actor ) - { - if( !actor.GetParent() ) - { - Self().Insert( index, actor ); - } - - OnTransitionIn( actor ); - } -} - void Button::TransitionOut( Actor actor ) { OnTransitionOut( actor ); @@ -1084,9 +1252,8 @@ void Button::TransitionOut( Actor actor ) void Button::ResetImageLayers() { - //ensure that all layers are in the correct order and state according to the paint state + // Ensure that all layers are in the correct order and state according to the paint state - int index = 0; switch( mPaintState ) { case UnselectedState: @@ -1095,20 +1262,18 @@ void Button::ResetImageLayers() //(2) mUnselectedContent //(1) mBackgroundContent + RemoveButtonImage( mDecoration[ SELECTED_DECORATION ] ); RemoveButtonImage( mSelectedContent ); RemoveButtonImage( mSelectedBackgroundContent ); RemoveButtonImage( mDisabledContent ); RemoveButtonImage( mDisabledSelectedContent ); RemoveButtonImage( mDisabledBackgroundContent ); - if( InsertButtonImage( index, mBackgroundContent ) ) - { - ++index; - } - if( InsertButtonImage( index, mUnselectedContent ) ) - { - ++index; - } + PrepareAddButtonImage( mBackgroundContent ); + PrepareAddButtonImage( mUnselectedContent ); + + PrepareAddButtonImage( mDecoration[ UNSELECTED_DECORATION ] ); + ReAddLabel(); break; } case SelectedState: @@ -1118,23 +1283,18 @@ void Button::ResetImageLayers() //(2) mSelectedBackgroundContent //(1) mBackgroundContent + RemoveButtonImage( mDecoration[ UNSELECTED_DECORATION ] ); RemoveButtonImage( mUnselectedContent ); RemoveButtonImage( mDisabledContent ); RemoveButtonImage( mDisabledSelectedContent ); RemoveButtonImage( mDisabledBackgroundContent ); - if( InsertButtonImage( index, mBackgroundContent ) ) - { - ++index; - } - if( InsertButtonImage( index, mSelectedBackgroundContent ) ) - { - ++index; - } - if( InsertButtonImage( index, mSelectedContent ) ) - { - ++index; - } + PrepareAddButtonImage( mBackgroundContent ); + PrepareAddButtonImage( mSelectedBackgroundContent ); + PrepareAddButtonImage( mSelectedContent ); + + PrepareAddButtonImage( mDecoration[ SELECTED_DECORATION ] ); + ReAddLabel(); break; } case DisabledUnselectedState: @@ -1143,20 +1303,19 @@ void Button::ResetImageLayers() //(2) mDisabledContent //(1) mDisabledBackgroundContent + RemoveButtonImage( mDecoration[ UNSELECTED_DECORATION ] ); RemoveButtonImage( mUnselectedContent ); RemoveButtonImage( mBackgroundContent ); + RemoveButtonImage( mDecoration[ SELECTED_DECORATION ] ); RemoveButtonImage( mSelectedContent ); RemoveButtonImage( mDisabledSelectedContent ); RemoveButtonImage( mSelectedBackgroundContent ); - if( InsertButtonImage( index, mDisabledBackgroundContent ? mDisabledBackgroundContent : mBackgroundContent ) ) - { - ++index; - } - if( InsertButtonImage( index, mDisabledContent ? mDisabledContent : mUnselectedContent ) ) - { - ++index; - } + PrepareAddButtonImage( mDisabledBackgroundContent ? mDisabledBackgroundContent : mBackgroundContent ); + PrepareAddButtonImage( mDisabledContent ? mDisabledContent : mUnselectedContent ); + + PrepareAddButtonImage( mDecoration[ UNSELECTED_DECORATION ] ); + ReAddLabel(); break; } case DisabledSelectedState: @@ -1165,7 +1324,9 @@ void Button::ResetImageLayers() // (2) mDisabledSelectedContent // (1) mDisabledBackgroundContent + RemoveButtonImage( mDecoration[ UNSELECTED_DECORATION ] ); RemoveButtonImage( mUnselectedContent ); + RemoveButtonImage( mDecoration[ SELECTED_DECORATION ] ); RemoveButtonImage( mSelectedContent ); RemoveButtonImage( mBackgroundContent ); RemoveButtonImage( mSelectedBackgroundContent ); @@ -1173,27 +1334,18 @@ void Button::ResetImageLayers() if( mDisabledBackgroundContent ) { - if( InsertButtonImage( index, mDisabledBackgroundContent) ) - { - ++index; - } + PrepareAddButtonImage( mDisabledBackgroundContent ); } else { - if( InsertButtonImage( index, mBackgroundContent ) ) - { - ++index; - } - if( InsertButtonImage( index, mSelectedBackgroundContent ) ) - { - ++index; - } + PrepareAddButtonImage( mBackgroundContent ); + PrepareAddButtonImage( mSelectedBackgroundContent ); } - if( InsertButtonImage( index, mDisabledSelectedContent ? mDisabledSelectedContent : mSelectedContent) ) - { - ++index; - } + PrepareAddButtonImage( mDisabledSelectedContent ? mDisabledSelectedContent : mSelectedContent ); + + PrepareAddButtonImage( mDecoration[ SELECTED_DECORATION ] ); + ReAddLabel(); break; } } @@ -1281,27 +1433,39 @@ void Button::SetProperty( BaseObject* object, Property::Index index, const Prope break; } - case Toolkit::Button::Property::NORMAL_STATE_ACTOR: + case Toolkit::Button::Property::UNSELECTED_STATE_IMAGE: + { + GetImplementation( button ).SetUnselectedImage( value.Get< std::string >() ); + break; + } + + case Toolkit::Button::Property::SELECTED_STATE_IMAGE: + { + GetImplementation( button ).SetSelectedImage( value.Get< std::string >() ); + break; + } + + case Toolkit::Button::Property::DISABLED_STATE_IMAGE: { - GetImplementation( button ).SetButtonImage( Scripting::NewActor( value.Get< Property::Map >() ) ); + GetImplementation( button ).SetDisabledImage( value.Get< std::string >() ); break; } - case Toolkit::Button::Property::SELECTED_STATE_ACTOR: + case Toolkit::Button::Property::UNSELECTED_COLOR: { - GetImplementation( button ).SetSelectedImage( Scripting::NewActor( value.Get< Property::Map >() ) ); + GetImplementation( button ).SetUnselectedColor( value.Get< Vector4 >() ); break; } - case Toolkit::Button::Property::DISABLED_STATE_ACTOR: + case Toolkit::Button::Property::SELECTED_COLOR: { - GetImplementation( button ).SetDisabledImage( Scripting::NewActor( value.Get< Property::Map >() ) ); + GetImplementation( button ).SetSelectedColor( value.Get< Vector4 >() ); break; } - case Toolkit::Button::Property::LABEL_ACTOR: + case Toolkit::Button::Property::LABEL_TEXT: { - GetImplementation( button ).SetLabel( Scripting::NewActor( value.Get< Property::Map >() ) ); + GetImplementation( button ).SetLabelText( value.Get< std::string >() ); break; } } @@ -1354,35 +1518,39 @@ Property::Value Button::GetProperty( BaseObject* object, Property::Index propert break; } - case Toolkit::Button::Property::NORMAL_STATE_ACTOR: + case Toolkit::Button::Property::UNSELECTED_STATE_IMAGE: + { + value = GetImplementation( button ).GetUnselectedImageFilename(); + break; + } + + case Toolkit::Button::Property::SELECTED_STATE_IMAGE: + { + value = GetImplementation( button ).GetSelectedImageFilename(); + break; + } + + case Toolkit::Button::Property::DISABLED_STATE_IMAGE: { - Property::Map map; - Scripting::CreatePropertyMap( GetImplementation( button ).mUnselectedContent, map ); - value = map; + value = GetImplementation( button ).GetDisabledImageFilename(); break; } - case Toolkit::Button::Property::SELECTED_STATE_ACTOR: + case Toolkit::Button::Property::UNSELECTED_COLOR: { - Property::Map map; - Scripting::CreatePropertyMap( GetImplementation( button ).mSelectedContent, map ); - value = map; + value = GetImplementation( button ).GetUnselectedColor(); break; } - case Toolkit::Button::Property::DISABLED_STATE_ACTOR: + case Toolkit::Button::Property::SELECTED_COLOR: { - Property::Map map; - Scripting::CreatePropertyMap( GetImplementation( button ).mDisabledContent, map ); - value = map; + value = GetImplementation( button ).GetSelectedColor(); break; } - case Toolkit::Button::Property::LABEL_ACTOR: + case Toolkit::Button::Property::LABEL_TEXT: { - Property::Map map; - Scripting::CreatePropertyMap( GetImplementation( button ).mLabel, map ); - value = map; + value = GetImplementation( button ).GetLabelText(); break; } } @@ -1391,6 +1559,132 @@ Property::Value Button::GetProperty( BaseObject* object, Property::Index propert return value; } +// Deprecated API + +void Button::SetLabel( Actor label ) +{ + if( mLabel != label ) + { + if( mLabel && mLabel.GetParent() ) + { + mLabel.GetParent().Remove( mLabel ); + } + + mLabel = label; + mLabel.SetProperty( Toolkit::Control::Property::STYLE_NAME, STYLE_BUTTON_LABEL ); + mLabel.SetPosition( 0.f, 0.f ); + + // label should be the top of the button + Self().Add( mLabel ); + + OnLabelSet(); + + RelayoutRequest(); + } +} + +void Button::SetButtonImage( Actor image ) +{ + if( image ) + { + StopTransitionAnimation(); + + SetupContent( mUnselectedContent, image ); + + OnUnselectedImageSet(); + RelayoutRequest(); + } +} + +void Button::SetSelectedImage( Actor image ) +{ + if( image ) + { + StopTransitionAnimation(); + + SetupContent( mSelectedContent, image ); + + OnSelectedImageSet(); + RelayoutRequest(); + } +} + +void Button::SetBackgroundImage( Actor image ) +{ + if( image ) + { + StopTransitionAnimation(); + + SetupContent( mBackgroundContent, image ); + + OnBackgroundImageSet(); + RelayoutRequest(); + } +} + +void Button::SetSelectedBackgroundImage( Actor image ) +{ + if( image ) + { + StopTransitionAnimation(); + + SetupContent( mSelectedBackgroundContent, image ); + + OnSelectedBackgroundImageSet(); + RelayoutRequest(); + } +} + +void Button::SetDisabledImage( Actor image ) +{ + if( image ) + { + StopTransitionAnimation(); + + SetupContent( mDisabledContent, image ); + + OnDisabledImageSet(); + RelayoutRequest(); + } +} + +void Button::SetDisabledSelectedImage( Actor image ) +{ + if( image ) + { + StopTransitionAnimation(); + + SetupContent( mDisabledSelectedContent, image ); + + OnDisabledSelectedImageSet(); + RelayoutRequest(); + } +} + +void Button::SetDisabledBackgroundImage( Actor image ) +{ + if( image ) + { + StopTransitionAnimation(); + + SetupContent( mDisabledBackgroundContent, image ); + + OnDisabledBackgroundImageSet(); + RelayoutRequest(); + } +} + +Actor Button::GetButtonImage() const +{ + return mUnselectedContent; +} + +Actor Button::GetSelectedImage() const +{ + return mSelectedContent; +} + + } // namespace Internal } // namespace Toolkit