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=3031d4fd800bed4a4887d94fbcdc29f50666434d;hp=7115cecfdf64a37fe35ccc8dee329041bbd883db;hb=db486aa2b45e86d175dce690989b604799ccc8a1;hpb=70ee2ab38bb1aa71222e65863ebb98d395c449a2 diff --git a/dali-toolkit/internal/controls/buttons/button-impl.cpp b/dali-toolkit/internal/controls/buttons/button-impl.cpp index 7115cec..3031d4f 100644 --- a/dali-toolkit/internal/controls/buttons/button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/button-impl.cpp @@ -22,9 +22,9 @@ #include // for strcmp #include #include -#include +#include #include -#include +#include // INTERNAL INCLUDES #include @@ -32,7 +32,7 @@ /** * Button states and contents * (3) mSelectedContent - * (2) mButtonContent (2) mSelectedBackgroundContent + * (2) mUnselectedContent (2) mSelectedBackgroundContent * (1) mBackgroundContent (1) mBackgroundContent * < unselected > ----------------------- < selected > * | OnSelect() | @@ -45,7 +45,7 @@ * The drawing order of child actors is as follows. * * Top mLabel - * | mButtonContent / mSelectedContent / mDisabledContent / mDisabledSelectedContent + * | mUnselectedContent / mSelectedContent / mDisabledContent / mDisabledSelectedContent * | mSelectedBackgroundContent * Bottom mBackgroundContent / mDisabledBackgroundContent * @@ -74,23 +74,23 @@ BaseHandle Create() // Setup properties, signals and actions using the type-registry. DALI_TYPE_REGISTRATION_BEGIN( Toolkit::Button, Toolkit::Control, Create ); -DALI_PROPERTY_REGISTRATION( Button, "disabled", BOOLEAN, DISABLED ) -DALI_PROPERTY_REGISTRATION( Button, "auto-repeating", BOOLEAN, AUTO_REPEATING ) -DALI_PROPERTY_REGISTRATION( Button, "initial-auto-repeating-delay", FLOAT, INITIAL_AUTO_REPEATING_DELAY ) -DALI_PROPERTY_REGISTRATION( Button, "next-auto-repeating-delay", FLOAT, NEXT_AUTO_REPEATING_DELAY ) -DALI_PROPERTY_REGISTRATION( Button, "togglable", BOOLEAN, TOGGLABLE ) -DALI_PROPERTY_REGISTRATION( Button, "selected", BOOLEAN, SELECTED ) -DALI_PROPERTY_REGISTRATION( Button, "normal-state-actor", MAP, NORMAL_STATE_ACTOR ) -DALI_PROPERTY_REGISTRATION( Button, "selected-state-actor", MAP, SELECTED_STATE_ACTOR ) -DALI_PROPERTY_REGISTRATION( Button, "disabled-state-actor", MAP, DISABLED_STATE_ACTOR ) -DALI_PROPERTY_REGISTRATION( Button, "label-actor", MAP, LABEL_ACTOR ) +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabled", BOOLEAN, DISABLED ) +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "auto-repeating", BOOLEAN, AUTO_REPEATING ) +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "initial-auto-repeating-delay", FLOAT, INITIAL_AUTO_REPEATING_DELAY ) +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_SIGNAL_REGISTRATION( Button, "pressed", SIGNAL_PRESSED ) -DALI_SIGNAL_REGISTRATION( Button, "released", SIGNAL_RELEASED ) -DALI_SIGNAL_REGISTRATION( Button, "clicked", SIGNAL_CLICKED ) -DALI_SIGNAL_REGISTRATION( Button, "state-changed", SIGNAL_STATE_CHANGED ) +DALI_SIGNAL_REGISTRATION( Toolkit, Button, "pressed", SIGNAL_PRESSED ) +DALI_SIGNAL_REGISTRATION( Toolkit, Button, "released", SIGNAL_RELEASED ) +DALI_SIGNAL_REGISTRATION( Toolkit, Button, "clicked", SIGNAL_CLICKED ) +DALI_SIGNAL_REGISTRATION( Toolkit, Button, "state-changed", SIGNAL_STATE_CHANGED ) -DALI_ACTION_REGISTRATION( Button, "button-click", ACTION_BUTTON_CLICK ) +DALI_ACTION_REGISTRATION( Toolkit, Button, "button-click", ACTION_BUTTON_CLICK ) DALI_TYPE_REGISTRATION_END() @@ -117,252 +117,109 @@ Button::Button() Button::~Button() { - if( mAutoRepeatingTimer ) - { - mAutoRepeatingTimer.Reset(); - } } void Button::SetDisabled( bool disabled ) { - if( disabled != mDisabled ) + if( disabled == mDisabled ) { - unsigned int backgroundIndex; - unsigned int buttonIndex; - - bool animationStarted = false; - - mDisabled = disabled; - - switch( mPaintState ) - { - case UnselectedState: - { - buttonIndex = FindChildIndex( mLabel ); - InsertChild( buttonIndex, mDisabledContent ); - - if( mBackgroundContent ) - { - backgroundIndex = 1; - } - else - { - backgroundIndex = 0; - } - - InsertChild( backgroundIndex, mDisabledBackgroundContent ); - - animationStarted = OnDisabled(); - - if( animationStarted ) - { - mPaintState = UnselectedDisabledTransition; - } - else - { - mPaintState = DisabledUnselectedState; - } - break; - } - case SelectedState: - { - buttonIndex = FindChildIndex( mLabel ); - InsertChild( buttonIndex, mDisabledSelectedContent ); - - if( mBackgroundContent ) - { - backgroundIndex = 1; - } - else - { - backgroundIndex = 0; - } - - InsertChild( backgroundIndex, mDisabledBackgroundContent ); - - animationStarted = OnDisabled(); - - if( animationStarted ) - { - mPaintState = SelectedDisabledTransition; - } - else - { - mPaintState = DisabledSelectedState; - } - break; - } - case DisabledUnselectedState: - { - buttonIndex = FindChildIndex( mLabel ); - InsertChild( buttonIndex, mButtonContent ); - - if( mDisabledBackgroundContent ) - { - backgroundIndex = 1; - } - else - { - backgroundIndex = 0; - } - - InsertChild( backgroundIndex, mBackgroundContent ); - - animationStarted = OnDisabled(); - - if( animationStarted ) - { - mPaintState = DisabledUnselectedTransition; - } - else - { - mPaintState = UnselectedState; - } - break; - } - case DisabledSelectedState: - { - buttonIndex = FindChildIndex( mLabel ); - InsertChild( buttonIndex, mSelectedContent ); - - if( mDisabledBackgroundContent ) - { - backgroundIndex = 1; - } - else - { - backgroundIndex = 0; - } + return; + } - InsertChild( backgroundIndex, mSelectedBackgroundContent ); - InsertChild( backgroundIndex, mBackgroundContent ); + StopTransitionAnimation(); - animationStarted = OnDisabled(); + mDisabled = disabled; - if( animationStarted ) - { - mPaintState = DisabledSelectedTransition; - } - else - { - mPaintState = SelectedState; - } - break; - } - case UnselectedSelectedTransition: - { - buttonIndex = FindChildIndex( mLabel ); - InsertChild( buttonIndex, mDisabledSelectedContent ); + // Notifies the derived class the button has been disabled. + OnDisabled(); - if( mBackgroundContent ) - { - backgroundIndex = 1; - } - else - { - backgroundIndex = 0; - } - - InsertChild( backgroundIndex, mDisabledBackgroundContent ); - - animationStarted = OnDisabled(); + switch( mPaintState ) + { + case UnselectedState: + { + //Layer Order + //(3) mDisabledContent (Inserted) + //(4) mUnselectedContent + //(2) mDisabledBackgroundContent (Inserted) + //(1) mBackgroundContent - if( animationStarted ) - { - mPaintState = SelectedDisabledTransition; - } - else - { - mPaintState = DisabledSelectedState; - } - break; - } - case SelectedUnselectedTransition: - { - buttonIndex = FindChildIndex( mLabel ); - InsertChild( buttonIndex, mDisabledContent ); + TransitionInBetween( mUnselectedContent, mLabel, mDisabledContent ); + TransitionInAbove( mBackgroundContent, mDisabledBackgroundContent ); - if( mBackgroundContent ) - { - backgroundIndex = 1; - } - else - { - backgroundIndex = 0; - } + TransitionOut( mUnselectedContent ); + TransitionOut( mSelectedContent ); + TransitionOut( mBackgroundContent ); + TransitionOut( mSelectedBackgroundContent ); + TransitionOut( mDisabledSelectedContent ); - InsertChild( backgroundIndex, mDisabledBackgroundContent ); - - animationStarted = OnDisabled(); + mPaintState = DisabledUnselectedState; + break; + } + case SelectedState: + { + //Layer Order + //(5) mDisabledSelectedContent (Inserted) + //(4) mSelectedContent + //(3) mDisabledBackgroundContent (Inserted) + //(2) mSelectedBackgroundContent + //(1) mBackgroundContent + + TransitionInBetween( mSelectedContent, mLabel, mDisabledSelectedContent ); + TransitionInAbove( mSelectedBackgroundContent, mDisabledBackgroundContent ); + + TransitionOut( mUnselectedContent ); + TransitionOut( mSelectedContent ); + TransitionOut( mBackgroundContent ); + TransitionOut( mSelectedBackgroundContent ); + TransitionOut( mDisabledContent ); - if( animationStarted ) - { - mPaintState = UnselectedDisabledTransition; - } - else - { - mPaintState = DisabledUnselectedState; - } - break; - } - case UnselectedDisabledTransition: - { - animationStarted = OnDisabled(); + mPaintState = DisabledSelectedState; + break; + } + case DisabledUnselectedState: + { + //Layer Order + //(3) mUnselectedContent (Inserted) + //(4) mDisabledContent + //(2) mBackgroundContent (Inserted) + //(1) mDisabledBackgroundContent - if( animationStarted ) - { - mPaintState = DisabledUnselectedTransition; - } - else - { - mPaintState = UnselectedState; - } - break; - } - case DisabledUnselectedTransition: - { - animationStarted = OnDisabled(); + TransitionInBetween( mDisabledContent, mLabel, mUnselectedContent ); + TransitionInAbove( mDisabledBackgroundContent, mBackgroundContent ); - if( animationStarted ) - { - mPaintState = UnselectedDisabledTransition; - } - else - { - mPaintState = DisabledUnselectedState; - } - break; - } - case SelectedDisabledTransition: - { - animationStarted = OnDisabled(); + TransitionOut( mSelectedContent ); + TransitionOut( mSelectedBackgroundContent ); + TransitionOut( mDisabledContent ); + TransitionOut( mDisabledSelectedContent ); + TransitionOut( mDisabledBackgroundContent ); - if( animationStarted ) - { - mPaintState = DisabledSelectedTransition; - } - else - { - mPaintState = SelectedState; - } - break; - } - case DisabledSelectedTransition: - { - animationStarted = OnDisabled(); + mPaintState = UnselectedState; + break; + } + case DisabledSelectedState: + { + //Layer Order + //(4) mSelectedContent (Inserted) + //(5) mDisabledSelectedContent + //(3) mSelectedBackgroundContent (Inserted) + //(2) mBackgroundContent (Inserted) + //(1) mDisabledBackgroundContent + + TransitionInBetween( mDisabledSelectedContent, mLabel, mSelectedContent ); + TransitionInAbove( mDisabledBackgroundContent, mSelectedBackgroundContent ); + TransitionInAbove( mDisabledBackgroundContent, mBackgroundContent ); + + TransitionOut( mUnselectedContent ); + TransitionOut( mDisabledContent ); + TransitionOut( mDisabledSelectedContent ); + TransitionOut( mDisabledBackgroundContent ); - if( animationStarted ) - { - mPaintState = SelectedDisabledTransition; - } - else - { - mPaintState = DisabledSelectedState; - } - break; - } + mPaintState = SelectedState; + break; } } + + StartTransitionAnimation(); } bool Button::IsDisabled() const @@ -440,154 +297,64 @@ void Button::SetSelected( bool selected ) void Button::SetSelected( bool selected, bool emitSignal ) { - unsigned int buttonIndex, backgroundIndex; - bool animationStarted = false; + StopTransitionAnimation(); mSelected = selected; + // Notifies the derived class the button has been selected. + OnSelected(); + switch( mPaintState ) { case UnselectedState: { - buttonIndex = FindChildIndex( mLabel ); - InsertChild( buttonIndex, mSelectedContent ); + //Layer Order + //(3) mSelectedContent (Inserted) + //(4) mUnselectedContent + //(2) mSelectedBackgroundContent (Inserted) + //(1) mBackgroundContent - if( mBackgroundContent ) - { - backgroundIndex = 1; - } - else - { - backgroundIndex = 0; - } + TransitionInBetween( mUnselectedContent, mLabel, mSelectedContent ); + TransitionInAbove( mBackgroundContent, mSelectedBackgroundContent ); + TransitionInAtIndex( 0, mBackgroundContent ); - InsertChild( backgroundIndex, mSelectedBackgroundContent ); + TransitionOut( mUnselectedContent ); + TransitionOut( mDisabledContent ); + TransitionOut( mDisabledSelectedContent ); + TransitionOut( mDisabledBackgroundContent ); - // Notifies the derived class the button has been selected. - animationStarted = OnSelected(); - - if( animationStarted ) - { - mPaintState = UnselectedSelectedTransition; - } - else - { - mPaintState = SelectedState; - } + mPaintState = SelectedState; break; } case SelectedState: { - buttonIndex = FindChildIndex( mLabel ); - InsertChild( buttonIndex, mButtonContent ); - - // Notifies the derived class the button has been selected. - animationStarted = OnSelected(); - - if( animationStarted ) - { - mPaintState = SelectedUnselectedTransition; - } - else - { - mPaintState = UnselectedState; - } - break; - } - case UnselectedSelectedTransition: - { - // Notifies the derived class the button has been selected. - animationStarted = OnSelected(); - - if( animationStarted ) - { - mPaintState = SelectedUnselectedTransition; - } - else - { - mPaintState = UnselectedState; - } - break; - } - case SelectedUnselectedTransition: - { - // Notifies the derived class the button has been selected. - animationStarted = OnSelected(); - - if( animationStarted ) - { - mPaintState = UnselectedSelectedTransition; - } - else - { - mPaintState = SelectedState; - } - break; - } - case DisabledUnselectedTransition: - { - buttonIndex = FindChildIndex( mLabel ); - InsertChild( buttonIndex, mSelectedContent ); + //Layer Order + //(3) mUnselectedContent (Inserted) + //(2) mSelectedContent + //(1) mBackgroundContent - if( mDisabledBackgroundContent ) - { - if( mBackgroundContent ) - { - backgroundIndex = 2; - } - else - { - backgroundIndex = 1; - } - } - else if( mBackgroundContent ) - { - backgroundIndex = 1; - } - else - { - backgroundIndex = 0; - } + TransitionInBetween( mSelectedContent, mLabel, mUnselectedContent ); + TransitionInAtIndex( 0, mBackgroundContent ); - InsertChild( backgroundIndex, mSelectedBackgroundContent ); - - // Notifies the derived class the button has been selected. - animationStarted = OnSelected(); - - if( animationStarted ) - { - mPaintState = UnselectedSelectedTransition; - } - else - { - mPaintState = SelectedState; - } - break; - } - case DisabledSelectedTransition: - { - buttonIndex = FindChildIndex( mLabel ); - InsertChild( buttonIndex, mButtonContent ); + TransitionOut( mSelectedContent ); + TransitionOut( mSelectedBackgroundContent ); + TransitionOut( mDisabledContent ); + TransitionOut( mDisabledSelectedContent ); + TransitionOut( mDisabledBackgroundContent ); - // Notifies the derived class the button has been selected. - animationStarted = OnSelected(); - - if( animationStarted ) - { - mPaintState = SelectedUnselectedTransition; - } - else - { - mPaintState = UnselectedState; - } + mPaintState = UnselectedState; break; } - default: + case DisabledUnselectedState: + case DisabledSelectedState: { + DALI_ASSERT_DEBUG( 0 && "Shouldn't be able to change paint state if the button is disabled." ); break; } } + StartTransitionAnimation(); + if( emitSignal ) { Toolkit::Button handle( GetOwner() ); @@ -653,26 +420,21 @@ Actor& Button::GetLabel() void Button::SetButtonImage( Actor image ) { - StopAllAnimations(); + StopTransitionAnimation(); - if( mButtonContent && mButtonContent.GetParent() ) + if( mUnselectedContent && mUnselectedContent.GetParent() ) { - Self().Remove( mButtonContent ); + Self().Remove( mUnselectedContent ); } - mButtonContent = image; - - mButtonContent.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - mButtonContent.SetParentOrigin( ParentOrigin::TOP_LEFT ); - mButtonContent.SetPosition( 0.f, 0.f ); - - if( mPaintState == UnselectedState ) + mUnselectedContent = image; + if( mUnselectedContent ) { - unsigned int index = FindChildIndex( mLabel ); - - Self().Insert( index, mButtonContent ); + mUnselectedContent.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + mUnselectedContent.SetParentOrigin( ParentOrigin::TOP_LEFT ); + mUnselectedContent.SetPosition( 0.f, 0.f ); } - + ResetImageLayers(); OnButtonImageSet(); RelayoutRequest(); @@ -680,17 +442,17 @@ void Button::SetButtonImage( Actor image ) Actor Button::GetButtonImage() const { - return mButtonContent; + return mUnselectedContent; } Actor& Button::GetButtonImage() { - return mButtonContent; + return mUnselectedContent; } void Button::SetSelectedImage( Actor image ) { - StopAllAnimations(); + StopTransitionAnimation(); if( mSelectedContent && mSelectedContent.GetParent() ) { @@ -698,18 +460,13 @@ void Button::SetSelectedImage( Actor image ) } mSelectedContent = image; - - mSelectedContent.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - mSelectedContent.SetParentOrigin( ParentOrigin::TOP_LEFT ); - mSelectedContent.SetPosition( 0.f, 0.f ); - - if( mPaintState == SelectedState ) + if( mSelectedContent ) { - unsigned int index = FindChildIndex( mLabel ); - - Self().Insert( index, mSelectedContent ); + mSelectedContent.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + mSelectedContent.SetParentOrigin( ParentOrigin::TOP_LEFT ); + mSelectedContent.SetPosition( 0.f, 0.f ); } - + ResetImageLayers(); OnSelectedImageSet(); RelayoutRequest(); @@ -727,7 +484,7 @@ Actor& Button::GetSelectedImage() void Button::SetBackgroundImage( Actor image ) { - StopAllAnimations(); + StopTransitionAnimation(); if( mBackgroundContent && mBackgroundContent.GetParent() ) { @@ -735,16 +492,13 @@ void Button::SetBackgroundImage( Actor image ) } mBackgroundContent = image; - - mBackgroundContent.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - mBackgroundContent.SetParentOrigin( ParentOrigin::TOP_LEFT ); - mBackgroundContent.SetPosition( 0.f, 0.f ); - - if( mPaintState == UnselectedState || mPaintState == SelectedState ) + if( mBackgroundContent ) { - Self().Insert( 0, mBackgroundContent ); + mBackgroundContent.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + mBackgroundContent.SetParentOrigin( ParentOrigin::TOP_LEFT ); + mBackgroundContent.SetPosition( 0.f, 0.f ); } - + ResetImageLayers(); OnBackgroundImageSet(); RelayoutRequest(); @@ -762,7 +516,7 @@ Actor& Button::GetBackgroundImage() void Button::SetSelectedBackgroundImage( Actor image ) { - StopAllAnimations(); + StopTransitionAnimation(); if( mSelectedBackgroundContent && mSelectedBackgroundContent.GetParent() ) { @@ -770,23 +524,13 @@ void Button::SetSelectedBackgroundImage( Actor image ) } mSelectedBackgroundContent = image; - - mSelectedBackgroundContent.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - mSelectedBackgroundContent.SetParentOrigin( ParentOrigin::TOP_LEFT ); - mSelectedBackgroundContent.SetPosition( 0.f, 0.f ); - - if( mPaintState == SelectedState ) + if( mSelectedBackgroundContent ) { - if( mBackgroundContent ) - { - Self().Insert( 1, mSelectedBackgroundContent ); - } - else - { - Self().Insert( 0, mSelectedBackgroundContent ); - } + mSelectedBackgroundContent.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + mSelectedBackgroundContent.SetParentOrigin( ParentOrigin::TOP_LEFT ); + mSelectedBackgroundContent.SetPosition( 0.f, 0.f ); } - + ResetImageLayers(); OnSelectedBackgroundImageSet(); RelayoutRequest(); @@ -804,7 +548,7 @@ Actor& Button::GetSelectedBackgroundImage() void Button::SetDisabledImage( Actor image ) { - StopAllAnimations(); + StopTransitionAnimation(); if( mDisabledContent && mDisabledContent.GetParent() ) { @@ -812,18 +556,14 @@ void Button::SetDisabledImage( Actor image ) } mDisabledContent = image; - - mDisabledContent.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - mDisabledContent.SetParentOrigin( ParentOrigin::TOP_LEFT ); - mDisabledContent.SetPosition( 0.f, 0.f ); - - if( mPaintState == DisabledUnselectedState || mPaintState == DisabledSelectedState ) + if( mDisabledContent ) { - unsigned int index = FindChildIndex( mLabel ); - - Self().Insert( index, mDisabledContent ); + mDisabledContent.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + mDisabledContent.SetParentOrigin( ParentOrigin::TOP_LEFT ); + mDisabledContent.SetPosition( 0.f, 0.f ); } + ResetImageLayers(); OnDisabledImageSet(); } @@ -839,7 +579,7 @@ Actor& Button::GetDisabledImage() void Button::SetDisabledSelectedImage( Actor image ) { - StopAllAnimations(); + StopTransitionAnimation(); if( mDisabledSelectedContent && mDisabledSelectedContent.GetParent() ) { @@ -847,18 +587,14 @@ void Button::SetDisabledSelectedImage( Actor image ) } mDisabledSelectedContent = image; - - mDisabledSelectedContent.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - mDisabledSelectedContent.SetParentOrigin( ParentOrigin::TOP_LEFT ); - mDisabledSelectedContent.SetPosition( 0.f, 0.f ); - - if( mPaintState == DisabledSelectedState ) + if( mDisabledSelectedContent ) { - unsigned int index = FindChildIndex( mLabel ); - - Self().Insert( index, mDisabledSelectedContent ); + mDisabledSelectedContent.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + mDisabledSelectedContent.SetParentOrigin( ParentOrigin::TOP_LEFT ); + mDisabledSelectedContent.SetPosition( 0.f, 0.f ); } + ResetImageLayers(); OnDisabledSelectedImageSet(); } @@ -874,7 +610,7 @@ Actor& Button::GetDisabledSelectedImage() void Button::SetDisabledBackgroundImage( Actor image ) { - StopAllAnimations(); + StopTransitionAnimation(); if( mDisabledBackgroundContent && mDisabledBackgroundContent.GetParent() ) { @@ -882,16 +618,13 @@ void Button::SetDisabledBackgroundImage( Actor image ) } mDisabledBackgroundContent = image; - - mDisabledBackgroundContent.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - mDisabledBackgroundContent.SetParentOrigin( ParentOrigin::TOP_LEFT ); - mDisabledBackgroundContent.SetPosition( 0.f, 0.f ); - - if( mPaintState == DisabledUnselectedState || mPaintState == DisabledSelectedState ) + if( mDisabledBackgroundContent ) { - Self().Insert( 0, mDisabledBackgroundContent ); + mDisabledBackgroundContent.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + mDisabledBackgroundContent.SetParentOrigin( ParentOrigin::TOP_LEFT ); + mDisabledBackgroundContent.SetPosition( 0.f, 0.f ); } - + ResetImageLayers(); OnDisabledBackgroundImageSet(); } @@ -905,7 +638,7 @@ Actor& Button::GetDisabledBackgroundImage() return mDisabledBackgroundContent; } -bool Button::DoAction( BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes ) +bool Button::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes ) { bool ret = false; @@ -917,14 +650,13 @@ bool Button::DoAction( BaseObject* object, const std::string& actionName, const if( 0 == strcmp( actionName.c_str(), ACTION_BUTTON_CLICK ) ) { - GetImplementation( button ).DoClickAction( attributes ); - ret = true; + ret = GetImplementation( button ).DoClickAction( attributes ); } return ret; } -void Button::DoClickAction( const PropertyValueContainer& attributes ) +bool Button::DoClickAction( const Property::Map& attributes ) { // Prevents the button signals from doing a recursive loop by sending an action // and re-emitting the signals. @@ -935,60 +667,11 @@ void Button::DoClickAction( const PropertyValueContainer& attributes ) mState = ButtonDown; OnButtonUp(); mClickActionPerforming = false; - } -} -void Button::UpdatePaintTransitionState() -{ - switch( mPaintState ) - { - case UnselectedSelectedTransition: - { - RemoveChild( mButtonContent ); - mPaintState = SelectedState; - break; - } - case SelectedUnselectedTransition: - { - RemoveChild( mSelectedBackgroundContent ); - RemoveChild( mSelectedContent ); - mPaintState = UnselectedState; - break; - } - case UnselectedDisabledTransition: - { - RemoveChild( mBackgroundContent ); - RemoveChild( mButtonContent ); - mPaintState = DisabledUnselectedState; - break; - } - case DisabledUnselectedTransition: - { - RemoveChild( mDisabledBackgroundContent ); - RemoveChild( mDisabledContent ); - mPaintState = UnselectedState; - break; - } - case SelectedDisabledTransition: - { - RemoveChild( mBackgroundContent ); - RemoveChild( mSelectedBackgroundContent ); - RemoveChild( mSelectedContent ); - mPaintState = DisabledSelectedState; - break; - } - case DisabledSelectedTransition: - { - RemoveChild( mDisabledBackgroundContent ); - RemoveChild( mDisabledSelectedContent ); - mPaintState = SelectedState; - break; - } - default: - { - break; - } + return true; } + + return false; } void Button::OnButtonStageDisconnection() @@ -1011,18 +694,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() @@ -1041,13 +723,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 ); } } @@ -1057,18 +738,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 ); } } @@ -1203,15 +883,21 @@ void Button::OnInitialize() OnButtonInitialize(); - self.SetDrawMode( DrawMode::OVERLAY ); self.SetKeyboardFocusable( true ); } -void Button::OnActivated() +bool Button::OnAccessibilityActivated() +{ + return OnKeyboardEnter(); +} + +bool Button::OnKeyboardEnter() { - // When the button is activated, it performs the click action - PropertyValueContainer attributes; - DoClickAction( attributes ); + // When the enter key is pressed, or button is activated, the click action is performed. + Property::Map attributes; + bool ret = DoClickAction( attributes ); + + return ret; } void Button::OnControlStageDisconnection() @@ -1255,206 +941,297 @@ bool Button::AutoRepeatingSlot() void Button::Pressed() { - unsigned int buttonIndex, backgroundIndex; - bool animationStarted = false; + if( mPaintState == UnselectedState ) + { + StopTransitionAnimation(); - switch( mPaintState ) + // Notifies the derived class the button has been pressed. + OnPressed(); + + //Layer Order + //(4) mSelectedContent (Inserted) + //(3) mUnselectedContent + //(2) mSelectedBackgroundContent (Inserted) + //(1) mBackgroundContent + + TransitionInBetween( mUnselectedContent, mLabel, mSelectedContent ); + TransitionInAbove( mBackgroundContent, mSelectedBackgroundContent ); + TransitionInAtIndex( 0, mBackgroundContent ); + + TransitionOut( mUnselectedContent ); + TransitionOut( mDisabledContent ); + TransitionOut( mDisabledSelectedContent ); + TransitionOut( mDisabledBackgroundContent ); + + mPaintState = SelectedState; + + StartTransitionAnimation(); + } +} + +void Button::Released() +{ + if( mPaintState == SelectedState ) { - case UnselectedState: - { - buttonIndex = FindChildIndex( mLabel ); - InsertChild( buttonIndex, mSelectedContent ); + StopTransitionAnimation(); - if( mBackgroundContent ) - { - backgroundIndex = 1; - } - else - { - backgroundIndex = 0; - } + // Notifies the derived class the button has been released. + OnReleased(); - InsertChild( backgroundIndex, mSelectedBackgroundContent ); + //Layer Order + //(3) mUnselectedContent (Inserted) + //(2) mSelectedContent + //(1) mBackgroundContent - // Notifies the derived class the button has been pressed. - animationStarted = OnPressed(); + TransitionInBetween( mSelectedContent, mLabel, mUnselectedContent ); + TransitionInAtIndex( 0, mBackgroundContent ); - if( animationStarted ) - { - mPaintState = UnselectedSelectedTransition; - } - else - { - mPaintState = SelectedState; - } - break; - } - case SelectedUnselectedTransition: - { - // Notifies the derived class the button has been pressed. - animationStarted = OnPressed(); + TransitionOut( mSelectedContent ); + TransitionOut( mSelectedBackgroundContent ); + TransitionOut( mDisabledContent ); + TransitionOut( mDisabledSelectedContent ); + TransitionOut( mDisabledBackgroundContent ); - if( animationStarted ) - { - mPaintState = UnselectedSelectedTransition; - } - else - { - mPaintState = SelectedState; - } - break; + mPaintState = UnselectedState; + + StartTransitionAnimation(); + } +} + +Button::ButtonState Button::GetState() +{ + return mState; +} + +Button::PaintState Button::GetPaintState() +{ + return mPaintState; +} + +bool Button::InsertButtonImage( unsigned int index, Actor& actor ) +{ + if( actor ) + { + Self().Insert( index, actor ); + PrepareForTranstionOut( actor ); + return true; + } + + return false; +} + +void Button::RemoveButtonImage( Actor& actor ) +{ + if( actor ) + { + if( actor.GetParent() ) + { + Self().Remove( actor ); } - case DisabledUnselectedTransition: + PrepareForTranstionIn( actor ); + } +} + +unsigned int Button::FindChildIndex( Actor& actor ) +{ + Actor self = Self(); + unsigned int childrenNum = self.GetChildCount(); + + for( unsigned int i = 0; i < childrenNum; i++ ) + { + Actor child = self.GetChildAt( i ); + if( child == actor ) { - buttonIndex = FindChildIndex( mLabel ); - InsertChild( buttonIndex, mSelectedContent ); + return i; + } + } - if( mDisabledBackgroundContent ) - { - if( mBackgroundContent ) - { - backgroundIndex = 2; - } - else - { - backgroundIndex = 1; - } - } - else if( mBackgroundContent ) - { - backgroundIndex = 1; - } - else - { - backgroundIndex = 0; - } + return childrenNum; +} - InsertChild( backgroundIndex, mSelectedBackgroundContent ); +void Button::TransitionInBetween( Actor childLower, Actor childUpper, Actor actor ) +{ + unsigned int index = childLower ? FindChildIndex( childLower ) + 1 : FindChildIndex( childUpper ); + TransitionInAtIndex( index, actor ); +} - // Notifies the derived class the button has been pressed. - animationStarted = OnPressed(); +void Button::TransitionInAbove( Actor child, Actor actor ) +{ + unsigned int index = child ? FindChildIndex( child ) + 1 : 0; + TransitionInAtIndex( index, actor ); +} - if( animationStarted ) - { - mPaintState = UnselectedSelectedTransition; - } - else - { - mPaintState = SelectedState; - } - break; +void Button::TransitionInAtIndex( unsigned int index, Actor actor ) +{ + if( actor ) + { + if( !actor.GetParent() ) + { + Self().Insert( index, actor ); } - default: - break; + + OnTransitionIn( actor ); } } -void Button::Released() +void Button::TransitionOut( Actor actor ) { - unsigned int buttonIndex; - bool animationStarted = false; + OnTransitionOut( actor ); +} +void Button::ResetImageLayers() +{ + //ensure that all layers are in the correct order and state according to the paint state + + int index = 0; switch( mPaintState ) { - case SelectedState: + case UnselectedState: { - buttonIndex = FindChildIndex( mLabel ); - InsertChild( buttonIndex, mButtonContent ); + //Layer Order + //(2) mUnselectedContent + //(1) mBackgroundContent - // Notifies the derived class the button has been released. - animationStarted = OnReleased(); + RemoveButtonImage( mSelectedContent ); + RemoveButtonImage( mSelectedBackgroundContent ); + RemoveButtonImage( mDisabledContent ); + RemoveButtonImage( mDisabledSelectedContent ); + RemoveButtonImage( mDisabledBackgroundContent ); - if( animationStarted ) + if( InsertButtonImage( index, mBackgroundContent ) ) { - mPaintState = SelectedUnselectedTransition; + ++index; } - else + if( InsertButtonImage( index, mUnselectedContent ) ) { - mPaintState = UnselectedState; + ++index; } break; } - case UnselectedSelectedTransition: + case SelectedState: { - // Notifies the derived class the button has been released. - animationStarted = OnReleased(); + //Layer Order + //(3) mSelectedContent + //(2) mSelectedBackgroundContent + //(1) mBackgroundContent + + RemoveButtonImage( mUnselectedContent ); + RemoveButtonImage( mDisabledContent ); + RemoveButtonImage( mDisabledSelectedContent ); + RemoveButtonImage( mDisabledBackgroundContent ); - if( animationStarted ) + if( InsertButtonImage( index, mBackgroundContent ) ) { - mPaintState = SelectedUnselectedTransition; + ++index; } - else + if( InsertButtonImage( index, mSelectedBackgroundContent ) ) + { + ++index; + } + if( InsertButtonImage( index, mSelectedContent ) ) { - mPaintState = UnselectedState; + ++index; } break; } - case DisabledSelectedTransition: + case DisabledUnselectedState: { - buttonIndex = FindChildIndex( mLabel ); - InsertChild( buttonIndex, mButtonContent ); + //Layer Order + //(2) mDisabledContent + //(1) mDisabledBackgroundContent - // Notifies the derived class the button has been released. - animationStarted = OnReleased(); + RemoveButtonImage( mUnselectedContent ); + RemoveButtonImage( mBackgroundContent ); + RemoveButtonImage( mSelectedContent ); + RemoveButtonImage( mDisabledSelectedContent ); + RemoveButtonImage( mSelectedBackgroundContent ); - if( animationStarted ) + if( InsertButtonImage( index, mDisabledBackgroundContent ? mDisabledBackgroundContent : mBackgroundContent ) ) { - mPaintState = SelectedUnselectedTransition; + ++index; } - else + if( InsertButtonImage( index, mDisabledContent ? mDisabledContent : mUnselectedContent ) ) { - mPaintState = UnselectedState; + ++index; } break; } - default: + case DisabledSelectedState: { + //Layer Order + // (2) mDisabledSelectedContent + // (1) mDisabledBackgroundContent + + RemoveButtonImage( mUnselectedContent ); + RemoveButtonImage( mSelectedContent ); + RemoveButtonImage( mBackgroundContent ); + RemoveButtonImage( mSelectedBackgroundContent ); + RemoveButtonImage( mDisabledContent ); + + if( mDisabledBackgroundContent ) + { + if( InsertButtonImage( index, mDisabledBackgroundContent) ) + { + ++index; + } + } + else + { + if( InsertButtonImage( index, mBackgroundContent ) ) + { + ++index; + } + if( InsertButtonImage( index, mSelectedBackgroundContent ) ) + { + ++index; + } + } + + if( InsertButtonImage( index, mDisabledSelectedContent ? mDisabledSelectedContent : mSelectedContent) ) + { + ++index; + } break; } } } -Button::ButtonState Button::GetState() -{ - return mState; -} - -Button::PaintState Button::GetPaintState() -{ - return mPaintState; -} - -void Button::InsertChild( unsigned int index, Actor& actor ) +void Button::StartTransitionAnimation() { - if( actor ) + if( mTransitionAnimation ) + { + mTransitionAnimation.Play(); + } + else { - Self().Insert( index, actor); + ResetImageLayers(); } } -void Button::RemoveChild( Actor& actor ) +void Button::StopTransitionAnimation() { - if( actor && actor.GetParent() ) + if( mTransitionAnimation ) { - Self().Remove( actor ); + mTransitionAnimation.Clear(); + mTransitionAnimation.Reset(); } } -unsigned int Button::FindChildIndex( Actor& actor ) +Dali::Animation Button::GetTransitionAnimation() { - Actor self = Self(); - unsigned int childrenNum = self.GetChildCount(); - - for( unsigned int i = 0; i < childrenNum; i++ ) + if( !mTransitionAnimation ) { - Actor child = self.GetChildAt( i ); - if( child == actor ) - { - return i; - } + mTransitionAnimation = Dali::Animation::New( GetAnimationTime() ); + mTransitionAnimation.FinishedSignal().Connect( this, &Button::TransitionAnimationFinished ); } - return childrenNum; + return mTransitionAnimation; +} + +void Button::TransitionAnimationFinished( Dali::Animation& source ) +{ + StopTransitionAnimation(); + ResetImageLayers(); } void Button::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value ) @@ -1467,7 +1244,7 @@ void Button::SetProperty( BaseObject* object, Property::Index index, const Prope { case Toolkit::Button::Property::DISABLED: { - GetImplementation( button ).SetDisabled( value.Get() ); + GetImplementation( button ).SetDisabled( value.Get< bool >() ); break; } @@ -1577,7 +1354,7 @@ Property::Value Button::GetProperty( BaseObject* object, Property::Index propert case Toolkit::Button::Property::NORMAL_STATE_ACTOR: { Property::Map map; - Scripting::CreatePropertyMap( GetImplementation( button ).mButtonContent, map ); + Scripting::CreatePropertyMap( GetImplementation( button ).mUnselectedContent, map ); value = map; break; }