From: Chu Hoang Date: Thu, 25 Jun 2015 15:41:58 +0000 (+0100) Subject: Refactored Button and derived classes, moving state change and transition logic to... X-Git-Tag: dali_1.0.48~23^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=efc136204e9a4460a7a2421e673c873e23974a80;ds=sidebyside Refactored Button and derived classes, moving state change and transition logic to base class. Added default images for PushButton, CheckBoxButton and RadioButton. Change-Id: I0acd58074bf72eb7d9bc1f809ecc4de6bcc9aeb8 --- diff --git a/dali-toolkit/images/button-disabled.9.png b/dali-toolkit/images/button-disabled.9.png new file mode 100644 index 0000000..d9286e2 Binary files /dev/null and b/dali-toolkit/images/button-disabled.9.png differ diff --git a/dali-toolkit/images/button-down-disabled.9.png b/dali-toolkit/images/button-down-disabled.9.png new file mode 100644 index 0000000..a57bd78 Binary files /dev/null and b/dali-toolkit/images/button-down-disabled.9.png differ diff --git a/dali-toolkit/images/button-down.9.png b/dali-toolkit/images/button-down.9.png new file mode 100644 index 0000000..afff203 Binary files /dev/null and b/dali-toolkit/images/button-down.9.png differ diff --git a/dali-toolkit/images/button-up.9.png b/dali-toolkit/images/button-up.9.png new file mode 100644 index 0000000..7a20d38 Binary files /dev/null and b/dali-toolkit/images/button-up.9.png differ diff --git a/dali-toolkit/images/checkbox-selected-diabled.png b/dali-toolkit/images/checkbox-selected-diabled.png new file mode 100644 index 0000000..a6517b8 Binary files /dev/null and b/dali-toolkit/images/checkbox-selected-diabled.png differ diff --git a/dali-toolkit/images/checkbox-selected.png b/dali-toolkit/images/checkbox-selected.png new file mode 100644 index 0000000..e3a8c43 Binary files /dev/null and b/dali-toolkit/images/checkbox-selected.png differ diff --git a/dali-toolkit/images/checkbox-unselected-disabled.png b/dali-toolkit/images/checkbox-unselected-disabled.png new file mode 100644 index 0000000..022c1cf Binary files /dev/null and b/dali-toolkit/images/checkbox-unselected-disabled.png differ diff --git a/dali-toolkit/images/checkbox-unselected.png b/dali-toolkit/images/checkbox-unselected.png new file mode 100644 index 0000000..58e9390 Binary files /dev/null and b/dali-toolkit/images/checkbox-unselected.png differ diff --git a/dali-toolkit/images/radio-button-selected-disabled.png b/dali-toolkit/images/radio-button-selected-disabled.png new file mode 100644 index 0000000..5c40e4b Binary files /dev/null and b/dali-toolkit/images/radio-button-selected-disabled.png differ diff --git a/dali-toolkit/images/radio-button-unselected-disabled.png b/dali-toolkit/images/radio-button-unselected-disabled.png new file mode 100644 index 0000000..0c5fa5f Binary files /dev/null and b/dali-toolkit/images/radio-button-unselected-disabled.png differ diff --git a/dali-toolkit/internal/controls/buttons/button-impl.cpp b/dali-toolkit/internal/controls/buttons/button-impl.cpp index a1eb3cf..4072f43 100644 --- a/dali-toolkit/internal/controls/buttons/button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/button-impl.cpp @@ -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 * @@ -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; - } - - InsertChild( backgroundIndex, mSelectedBackgroundContent ); - InsertChild( backgroundIndex, mBackgroundContent ); + return; + } - animationStarted = OnDisabled(); + StopTransitionAnimation(); - if( animationStarted ) - { - mPaintState = DisabledSelectedTransition; - } - else - { - mPaintState = SelectedState; - } - break; - } - case UnselectedSelectedTransition: - { - buttonIndex = FindChildIndex( mLabel ); - InsertChild( buttonIndex, mDisabledSelectedContent ); + mDisabled = disabled; - if( mBackgroundContent ) - { - backgroundIndex = 1; - } - else - { - backgroundIndex = 0; - } + // Notifies the derived class the button has been disabled. + OnDisabled(); - InsertChild( backgroundIndex, mDisabledBackgroundContent ); + switch( mPaintState ) + { + case UnselectedState: + { + //Layer Order + //(3) mDisabledContent (Inserted) + //(4) mUnselectedContent + //(2) mDisabledBackgroundContent (Inserted) + //(1) mBackgroundContent - animationStarted = OnDisabled(); + TransitionInBetween( mUnselectedContent, mLabel, mDisabledContent ); + TransitionInAbove( mBackgroundContent, mDisabledBackgroundContent ); - if( animationStarted ) - { - mPaintState = SelectedDisabledTransition; - } - else - { - mPaintState = DisabledSelectedState; - } - break; - } - case SelectedUnselectedTransition: - { - buttonIndex = FindChildIndex( mLabel ); - InsertChild( buttonIndex, mDisabledContent ); + TransitionOut( mUnselectedContent ); + TransitionOut( mSelectedContent ); + TransitionOut( mBackgroundContent ); + TransitionOut( mSelectedBackgroundContent ); + TransitionOut( mDisabledSelectedContent ); - if( mBackgroundContent ) - { - backgroundIndex = 1; - } - else - { - backgroundIndex = 0; - } + 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 ); - InsertChild( backgroundIndex, mDisabledBackgroundContent ); + mPaintState = DisabledSelectedState; + break; + } + case DisabledUnselectedState: + { + //Layer Order + //(3) mUnselectedContent (Inserted) + //(4) mDisabledContent + //(2) mBackgroundContent (Inserted) + //(1) mDisabledBackgroundContent - animationStarted = OnDisabled(); + TransitionInBetween( mDisabledContent, mLabel, mUnselectedContent ); + TransitionInAbove( mDisabledBackgroundContent, mBackgroundContent ); - if( animationStarted ) - { - mPaintState = UnselectedDisabledTransition; - } - else - { - mPaintState = DisabledUnselectedState; - } - break; - } - case UnselectedDisabledTransition: - { - animationStarted = OnDisabled(); + TransitionOut( mSelectedContent ); + TransitionOut( mSelectedBackgroundContent ); + TransitionOut( mDisabledContent ); + TransitionOut( mDisabledSelectedContent ); + TransitionOut( mDisabledBackgroundContent ); - if( animationStarted ) - { - mPaintState = DisabledUnselectedTransition; - } - else - { - mPaintState = UnselectedState; - } - break; - } - case DisabledUnselectedTransition: - { - animationStarted = OnDisabled(); - - if( animationStarted ) - { - mPaintState = UnselectedDisabledTransition; - } - else - { - mPaintState = DisabledUnselectedState; - } - break; - } - case SelectedDisabledTransition: - { - animationStarted = OnDisabled(); - - 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; - } - - InsertChild( backgroundIndex, mSelectedBackgroundContent ); + TransitionInBetween( mUnselectedContent, mLabel, mSelectedContent ); + TransitionInAbove( mBackgroundContent, mSelectedBackgroundContent ); + TransitionInAtIndex( 0, mBackgroundContent ); - // Notifies the derived class the button has been selected. - animationStarted = OnSelected(); + TransitionOut( mUnselectedContent ); + TransitionOut( mDisabledContent ); + TransitionOut( mDisabledSelectedContent ); + TransitionOut( mDisabledBackgroundContent ); - if( animationStarted ) - { - mPaintState = UnselectedSelectedTransition; - } - else - { - mPaintState = SelectedState; - } + mPaintState = SelectedState; break; } case SelectedState: { - buttonIndex = FindChildIndex( mLabel ); - InsertChild( buttonIndex, mButtonContent ); + //Layer Order + //(3) mUnselectedContent (Inserted) + //(2) mSelectedContent + //(1) mBackgroundContent - // Notifies the derived class the button has been selected. - animationStarted = OnSelected(); + TransitionInBetween( mSelectedContent, mLabel, mUnselectedContent ); + TransitionInAtIndex( 0, mBackgroundContent ); - if( animationStarted ) - { - mPaintState = SelectedUnselectedTransition; - } - else - { - mPaintState = UnselectedState; - } - break; - } - case UnselectedSelectedTransition: - { - // Notifies the derived class the button has been selected. - animationStarted = OnSelected(); + TransitionOut( mSelectedContent ); + TransitionOut( mSelectedBackgroundContent ); + TransitionOut( mDisabledContent ); + TransitionOut( mDisabledSelectedContent ); + TransitionOut( mDisabledBackgroundContent ); - 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 ); - - if( mDisabledBackgroundContent ) - { - if( mBackgroundContent ) - { - backgroundIndex = 2; - } - else - { - backgroundIndex = 1; - } - } - else if( mBackgroundContent ) - { - backgroundIndex = 1; - } - else - { - backgroundIndex = 0; - } - - 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 ); - - // 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(); } @@ -941,59 +674,6 @@ bool Button::DoClickAction( const Property::Map& attributes ) return 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; - } - } -} - void Button::OnButtonStageDisconnection() { if( ButtonDown == mState ) @@ -1264,206 +944,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 ) +{ + OnTransitionOut( actor ); +} + +void Button::ResetImageLayers() { - unsigned int buttonIndex; - bool animationStarted = false; + //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 - if( animationStarted ) + RemoveButtonImage( mUnselectedContent ); + RemoveButtonImage( mDisabledContent ); + RemoveButtonImage( mDisabledSelectedContent ); + RemoveButtonImage( mDisabledBackgroundContent ); + + 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 ) { - Self().Insert( index, actor); + mTransitionAnimation.Play(); + } + else + { + 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 ) @@ -1476,7 +1247,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; } @@ -1586,7 +1357,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; } diff --git a/dali-toolkit/internal/controls/buttons/button-impl.h b/dali-toolkit/internal/controls/buttons/button-impl.h index e4d49d7..89f0591 100644 --- a/dali-toolkit/internal/controls/buttons/button-impl.h +++ b/dali-toolkit/internal/controls/buttons/button-impl.h @@ -20,6 +20,7 @@ // EXTERNAL INCLUDES #include +#include // INTERNAL INCLUDES #include @@ -269,11 +270,6 @@ protected: */ Actor& GetLabel(); - /** - * It changes the transition state of the push button. - */ - void UpdatePaintTransitionState(); - private: /** @@ -362,32 +358,23 @@ private: /** * This method is called when the \e selected property is changed. - * @return true if the transition animation is started. */ - virtual bool OnSelected() { return false; } + virtual void OnSelected() {} /** * This method is called when the \e disabled property is changed. - * @return true if the transition animation is started. */ - virtual bool OnDisabled() { return false; } + virtual void OnDisabled() {} /** * This method is called when the button is pressed. - * @return true if the transition animation is started. */ - virtual bool OnPressed() { return false; } + virtual void OnPressed() {} /** * This method is called when the button is released. - * @return true if the transition animation is started. */ - virtual bool OnReleased() { return false; } - - /** - * This method stops all animations - */ - virtual void StopAllAnimations() {} + virtual void OnReleased() {} public: @@ -527,26 +514,102 @@ protected: SelectedState, ///< The button is selected. DisabledUnselectedState, ///< The button is disabled and unselected. DisabledSelectedState, ///< The button is disabled and selected. - UnselectedSelectedTransition, ///< The button is in transition from unselected to selected. - SelectedUnselectedTransition, ///< The button is in transition from selected to unselected. - UnselectedDisabledTransition, ///< The button is in transition from unselected to disabled. - DisabledUnselectedTransition, ///< The button is in transition from disabled to unselected. - SelectedDisabledTransition, ///< The button is in transition from selected to disabled. - DisabledSelectedTransition ///< The button is in transition from disabled to selected. }; ButtonState GetState(); PaintState GetPaintState(); /** - * Inserts the actor to the button. + * Returns the animation to be used for transitioning creating the animation if needed. + * @return The initialised transition animation. + */ + Dali::Animation GetTransitionAnimation(); + + /** + * Prepares the actor to be transitioned in. + * @param[in] actor The actor that will be transitioned in. + */ + virtual void PrepareForTranstionIn( Actor actor ) {} + + /** + * Prepares the actor to be transitioned in. + * @param[in] actor The actor that will be transitioned out. + */ + virtual void PrepareForTranstionOut( Actor actor ) {} + + /** + * Transitions the actor in, allowing derived classes to configure + * the GetTransitionAnimation() animation ready. + * Button is in charge of calling Dali::Animation::Play and so derived classes + * only need to add the animation. + */ + virtual void OnTransitionIn( Actor actor ) {} + + /** + * Transitions the actor out, allowing derived classes to configure + * the GetTransitionAnimation() animation ready. + * Button is in charge of calling Dali::Animation::Play and so derived classes + * only need to add the animation. + */ + virtual void OnTransitionOut( Actor actor ) {} + +private: + /** + * Starts the transition animation. + * Button::TransitionFinished is called when the animation finishes. + */ + void StartTransitionAnimation(); + + /** + * This method stops all transition animations */ - void InsertChild( unsigned int index, Actor& actor ); + void StopTransitionAnimation(); /** - * Removes the actor from the button. + * Called when the transition animation finishes. */ - void RemoveChild( Actor& actor ); + void TransitionAnimationFinished( Dali::Animation& source ); + + /** + * Resets the Button to the base state for the current paint state. + * Any additionally inserted images needed for transitions that are + * no longer needed and the removed. + */ + void ResetImageLayers(); + + /** + * Transitions in the actor, inserting the actor above childLower below the childUpper. + * Will not insert the actor if it is already attached to a parent (and so will not reorder the actor) + */ + void TransitionInBetween( Actor childLower, Actor childUpper, Actor actor ); + + /** + * Transitions in the actor, inserting the actor above the child if the child exists or at the bottom otherwise + * Will not insert the actor if it is already attached to a parent (and so will not reorder the actor) + */ + void TransitionInAbove( Actor child, Actor actor ); + + /** + * Transitions in the actor, inserting the actor at the index + * Will not insert the actor if it is already attached to a parent (and so will not reorder the actor) + */ + void TransitionInAtIndex( unsigned int index, Actor actor ); + + /** + * Transitions out the actor + */ + void TransitionOut( Actor actor ); + + /** + * Inserts the actor to the button and prepares it to be transitioned out + * @return true if the child was inserted, false otherwise + */ + bool InsertButtonImage( unsigned int index, Actor& actor ); + + /** + * Removes the actor from the button and prepares it to be transitioned out + */ + void RemoveButtonImage( Actor& actor ); /** * Finds the index of the actor. @@ -554,7 +617,6 @@ protected: */ unsigned int FindChildIndex( Actor& actor ); -private: // Undefined Button( const Button& ); @@ -574,7 +636,7 @@ private: Actor mLabel; ///< Stores the button label. - Actor mButtonContent; ///< Stores the unselected content. + Actor mUnselectedContent; ///< Stores the unselected content. Actor mSelectedContent; ///< Stores the selected content. Actor mBackgroundContent; ///< Stores the background content. Actor mSelectedBackgroundContent; ///< Stores the selected background content. @@ -582,6 +644,8 @@ private: Actor mDisabledSelectedContent; ///< Stores the disabled selected content. Actor mDisabledBackgroundContent; ///< Stores the disabled background content. + Animation mTransitionAnimation; ///< Animation used in the state transitions. + TapGestureDetector mTapDetector; bool mDisabled; ///< Stores the disabled property. @@ -590,6 +654,7 @@ private: bool mSelected; ///< Stores the selected state. float mInitialAutoRepeatingDelay; ///< Stores the initial autorepeating delay in seconds. float mNextAutoRepeatingDelay; ///< Stores the next autorepeating delay in seconds. + float mAnimationTime; ///< The animation time. // Actions diff --git a/dali-toolkit/internal/controls/buttons/check-box-button-impl.cpp b/dali-toolkit/internal/controls/buttons/check-box-button-impl.cpp index f5c908d..b1f7474 100644 --- a/dali-toolkit/internal/controls/buttons/check-box-button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/check-box-button-impl.cpp @@ -21,6 +21,7 @@ // EXTERNAL INCLUDES #include #include +#include //INTERNAL INCLUDES #include @@ -47,6 +48,10 @@ BaseHandle Create() TypeRegistration mType( typeid(Toolkit::CheckBoxButton), typeid(Toolkit::Button), Create ); +const char* const UNSELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "checkbox-unselected.png"; +const char* const SELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "checkbox-selected.png"; +const char* const DISABLED_UNSELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "checkbox-unselected-disabled.png"; +const char* const DISABLED_SELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "checkbox-selected-diabled.png"; } Dali::Toolkit::CheckBoxButton CheckBoxButton::New() @@ -74,16 +79,22 @@ CheckBoxButton::CheckBoxButton() CheckBoxButton::~CheckBoxButton() { - if( mTransitionAnimation ) - { - mTransitionAnimation.Clear(); - } } void CheckBoxButton::OnButtonInitialize() { // Wrap around all children Self().SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS ); + + Image buttonImage = Dali::ResourceImage::New( UNSELECTED_BUTTON_IMAGE_DIR, ResourceImage::ON_DEMAND, ResourceImage::NEVER ); + Image selectedImage = Dali::ResourceImage::New( SELECTED_BUTTON_IMAGE_DIR, ResourceImage::ON_DEMAND, ResourceImage::NEVER ); + Image disabledImage = Dali::ResourceImage::New( DISABLED_UNSELECTED_BUTTON_IMAGE_DIR, ResourceImage::ON_DEMAND, ResourceImage::NEVER ); + Image disabledSelectedImage = Dali::ResourceImage::New( DISABLED_SELECTED_BUTTON_IMAGE_DIR, ResourceImage::ON_DEMAND, ResourceImage::NEVER ); + + SetButtonImage( ImageActor::New( buttonImage ) ); + SetSelectedImage( ImageActor::New( selectedImage ) ); + SetDisabledImage( ImageActor::New( disabledImage ) ); + SetDisabledSelectedImage( ImageActor::New( disabledSelectedImage ) ); } void CheckBoxButton::OnLabelSet() @@ -103,103 +114,30 @@ void CheckBoxButton::OnLabelSet() { label.SetX( GetBackgroundImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); } - else + else if( IsSelected() && GetSelectedImage()) { - label.SetX( DISTANCE_BETWEEN_IMAGE_AND_LABEL ); + label.SetX( GetSelectedImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); } - } -} - -bool CheckBoxButton::OnSelected() -{ - Actor& selectedImage = GetSelectedImage(); - - PaintState paintState = GetPaintState(); - - switch( paintState ) - { - case UnselectedState: - { - StartTransitionAnimation( selectedImage ); - break; - } - case SelectedState: + else if( GetButtonImage() ) { - RemoveChild( selectedImage ); - break; + label.SetX( GetButtonImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); } - case UnselectedSelectedTransition: - { - StopTransitionAnimation( false ); - RemoveChild( selectedImage ); - break; - } - default: + else { - break; + label.SetX( DISTANCE_BETWEEN_IMAGE_AND_LABEL ); } } - - if( mTransitionAnimation ) - { - return true; - } - - return false; } -bool CheckBoxButton::OnDisabled() +void CheckBoxButton::OnDisabled() { Actor& backgroundImage = GetBackgroundImage(); - Actor& selectedImage = GetSelectedImage(); Actor& disabledBackgroundImage = GetDisabledBackgroundImage(); - Actor& disabledSelectedImage = GetDisabledSelectedImage(); - - PaintState paintState = GetPaintState(); - - switch( paintState ) - { - case UnselectedState: - { - RemoveChild( backgroundImage ); - break; - } - case SelectedState: - { - RemoveChild( backgroundImage ); - RemoveChild( selectedImage ); - break; - } - case DisabledUnselectedState: - { - RemoveChild( disabledBackgroundImage ); - break; - } - case DisabledSelectedState: - { - RemoveChild( disabledBackgroundImage ); - RemoveChild( disabledSelectedImage ); - break; - } - case UnselectedSelectedTransition: - { - StopTransitionAnimation(); - - RemoveChild( backgroundImage ); - RemoveChild( selectedImage ); - break; - } - default: - { - break; - } - } Actor& label = GetLabel(); - if( label ) { - if( IsDisabled() && disabledBackgroundImage) + if( IsDisabled() && disabledBackgroundImage ) { label.SetX( disabledBackgroundImage.GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); } @@ -207,73 +145,93 @@ bool CheckBoxButton::OnDisabled() { label.SetX( backgroundImage.GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); } + else if( IsSelected() && GetSelectedImage()) + { + label.SetX( GetSelectedImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); + } + else if( GetButtonImage() ) + { + label.SetX( GetButtonImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); + } else { label.SetX( DISTANCE_BETWEEN_IMAGE_AND_LABEL ); } } - - if( mTransitionAnimation ) - { - return true; - } - - return false; } -void CheckBoxButton::StopAllAnimations() +void CheckBoxButton::PrepareForTranstionIn( Actor actor ) { - StopTransitionAnimation(); -} - -void CheckBoxButton::StartTransitionAnimation( Actor& actor ) -{ - if( actor ) + Actor& selectedImage = GetSelectedImage(); + if( actor == selectedImage ) { + actor.SetScale( Vector3( 0.0f, 1.0f, 1.0f ) ); + if( !mTickUVEffect ) { - ImageActor imageActor = ImageActor::DownCast( actor ); mTickUVEffect = CreateImageRegionEffect(); - imageActor.SetShaderEffect( mTickUVEffect ); } - - actor.SetScale( Vector3( 0.0f, 1.0f, 1.0f ) ); - mTickUVEffect.SetUniform("uBottomRight", Vector2( 0.0f, 1.0f ) ); - if( !mTransitionAnimation ) + ImageActor imageActor = ImageActor::DownCast( actor ); + if( imageActor ) { - mTransitionAnimation = Dali::Animation::New( GetAnimationTime() ); + imageActor.SetShaderEffect( mTickUVEffect ); } - - // UV anim - mTransitionAnimation.AnimateTo( Property( mTickUVEffect, "uBottomRight" ), Vector2( 1.0f, 1.0f ) ); - - // Actor size anim - mTransitionAnimation.AnimateTo( Property( actor, Actor::Property::SCALE_X ), 1.0f ); - - mTransitionAnimation.FinishedSignal().Connect( this, &CheckBoxButton::TransitionAnimationFinished ); - mTransitionAnimation.Play(); } } -void CheckBoxButton::StopTransitionAnimation( bool remove ) +void CheckBoxButton::PrepareForTranstionOut( Actor actor ) { - if( mTransitionAnimation ) + Actor& selectedImage = GetSelectedImage(); + if( actor == selectedImage ) { - mTransitionAnimation.Clear(); - mTransitionAnimation.Reset(); - } + actor.SetScale( Vector3::ONE ); - if( remove ) - { - UpdatePaintTransitionState(); + if( !mTickUVEffect ) + { + mTickUVEffect = CreateImageRegionEffect(); + } + mTickUVEffect.SetUniform("uBottomRight", Vector2::ONE ); + + ImageActor imageActor = ImageActor::DownCast( actor ); + if( imageActor ) + { + imageActor.SetShaderEffect( mTickUVEffect ); + } } } -void CheckBoxButton::TransitionAnimationFinished( Dali::Animation& source ) +void CheckBoxButton::OnTransitionIn( Actor actor ) { - StopTransitionAnimation(); + Actor& selectedImage = GetSelectedImage(); + if( actor && actor == selectedImage ) + { + if( GetPaintState() == UnselectedState ) + { + Dali::Animation transitionAnimation = GetTransitionAnimation(); + if( transitionAnimation ) + { + DALI_ASSERT_DEBUG( mTickUVEffect ); + if( mTickUVEffect ) + { + // UV anim + transitionAnimation.AnimateTo( Property( mTickUVEffect, "uBottomRight" ), Vector2::ONE ); + } + // Actor size anim + transitionAnimation.AnimateTo( Property( actor, Actor::Property::SCALE_X ), 1.0f ); + } + } + else + { + //explicitly end the swipe animation + actor.SetScale( Vector3::ONE ); + if( mTickUVEffect ) + { + mTickUVEffect.SetUniform("uBottomRight", Vector2::ONE ); + } + } + } } } // namespace Internal diff --git a/dali-toolkit/internal/controls/buttons/check-box-button-impl.h b/dali-toolkit/internal/controls/buttons/check-box-button-impl.h index 0135e6b..25945d2 100644 --- a/dali-toolkit/internal/controls/buttons/check-box-button-impl.h +++ b/dali-toolkit/internal/controls/buttons/check-box-button-impl.h @@ -20,10 +20,8 @@ // EXTERNAL INCLUDES #include -#include #include - // INTERNAL INCLUDES #include #include @@ -80,41 +78,24 @@ private: // From Button virtual void OnLabelSet(); /** - * @copydoc Toolkit::Internal::Button::OnSelected() - */ - virtual bool OnSelected(); - - /** * @copydoc Toolkit::Internal::Button::OnDisabled() */ - virtual bool OnDisabled(); - - /** - * @copydoc Toolkit::Internal::Button::StopAllAnimations() - */ - virtual void StopAllAnimations(); - -private: + virtual void OnDisabled(); /** - * Adds the actor to the transition animation. - * It creates a transition animation if needed and starts the animation. - * @param[in] actor The actor. + * @copydoc Toolkit::Internal::Button::PrepareForTranstionIn( Actor actor ) */ - void StartTransitionAnimation( Actor& actor ); + virtual void PrepareForTranstionIn( Actor actor ); /** - * Stops the transition animation. - * @param[in] remove If true, removes the fadeout actor from root. + * @copydoc Toolkit::Internal::Button::PrepareForTranstionOut( Actor actor ) */ - void StopTransitionAnimation( bool remove = true ); - - // slots + virtual void PrepareForTranstionOut( Actor actor ); /** - * Called when the transition animation finishes. + * @copydoc Toolkit::Internal::Button::OnTransitionInImage( Actor actor ) */ - void TransitionAnimationFinished( Dali::Animation& source ); + virtual void OnTransitionIn( Actor actor ); private: @@ -125,7 +106,6 @@ private: CheckBoxButton& operator=( const CheckBoxButton& ); private: - Animation mTransitionAnimation; ///< Animation used in the state transitions. ShaderEffect mTickUVEffect; ///< ImageRegionEffect to expand the tick across }; diff --git a/dali-toolkit/internal/controls/buttons/push-button-impl.cpp b/dali-toolkit/internal/controls/buttons/push-button-impl.cpp index a63b861..1ee6b92 100644 --- a/dali-toolkit/internal/controls/buttons/push-button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/push-button-impl.cpp @@ -21,6 +21,7 @@ // EXTERNAL INCLUDES #include #include +#include // INTERNAL INCLUDES #include @@ -47,6 +48,11 @@ BaseHandle Create() TypeRegistration typeRegistration( typeid(Toolkit::PushButton), typeid(Toolkit::Button), Create ); +const char* const UNSELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "button-up.9.png"; +const char* const SELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "button-down.9.png"; +const char* const DISABLED_UNSELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "button-disabled.9.png"; +const char* const DISABLED_SELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "button-down-disabled.9.png"; + } // unnamed namespace namespace @@ -103,6 +109,16 @@ void PushButton::OnButtonInitialize() // Set resize policy to natural size so that buttons will resize to background images self.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); + + Image buttonImage = Dali::ResourceImage::New( UNSELECTED_BUTTON_IMAGE_DIR, ResourceImage::ON_DEMAND, ResourceImage::NEVER ); + Image selectedImage = Dali::ResourceImage::New( SELECTED_BUTTON_IMAGE_DIR, ResourceImage::ON_DEMAND, ResourceImage::NEVER ); + Image disabledImage = Dali::ResourceImage::New( DISABLED_UNSELECTED_BUTTON_IMAGE_DIR, ResourceImage::ON_DEMAND, ResourceImage::NEVER ); + Image disabledSelectedImage = Dali::ResourceImage::New( DISABLED_SELECTED_BUTTON_IMAGE_DIR, ResourceImage::ON_DEMAND, ResourceImage::NEVER ); + + SetButtonImage( ImageActor::New( buttonImage ) ); + SetSelectedImage( ImageActor::New( selectedImage ) ); + SetDisabledImage( ImageActor::New( disabledImage ) ); + SetDisabledSelectedImage( ImageActor::New( disabledSelectedImage ) ); } void PushButton::OnLabelSet() @@ -156,386 +172,16 @@ void PushButton::OnDisabledImageSet() RelayoutRequest(); } -void PushButton::OnDisabledBackgroundImageSet() +void PushButton::OnDisabledSelectedImageSet() { ConfigureSizeNegotiation(); RelayoutRequest(); } -bool PushButton::OnSelected() -{ - Actor& buttonImage = GetButtonImage(); - Actor& selectedImage = GetSelectedImage(); - Actor& selectedBackgroundImage = GetSelectedBackgroundImage(); - - PaintState paintState = GetPaintState(); - - switch( paintState ) - { - case UnselectedState: - { - FadeOutImage( buttonImage ); - FadeInImage( selectedBackgroundImage ); - FadeInImage( selectedImage ); - StartTransitionAnimation(); - break; - } - case SelectedState: - { - FadeOutImage( selectedBackgroundImage ); - FadeOutImage( selectedImage ); - FadeInImage( buttonImage ); - StartTransitionAnimation(); - break; - } - case UnselectedSelectedTransition: - { - float opacity = 1.f; - if( selectedImage ) - { - opacity = selectedImage.GetCurrentOpacity(); - } - - StopTransitionAnimation( false ); - FadeOutImage( selectedBackgroundImage, opacity ); - FadeOutImage( selectedImage, opacity ); - FadeInImage( buttonImage, 1.f - opacity ); - StartTransitionAnimation(); - break; - } - case SelectedUnselectedTransition: - { - float opacity = 0.f; - if( selectedImage ) - { - opacity = selectedImage.GetCurrentOpacity(); - } - - StopTransitionAnimation( false ); - FadeOutImage( buttonImage, 1.f - opacity ); - FadeInImage( selectedBackgroundImage, opacity ); - FadeInImage( selectedImage, opacity ); - StartTransitionAnimation(); - break; - } - case DisabledUnselectedTransition: - { - StopTransitionAnimation(); - FadeOutImage( buttonImage ); - FadeInImage( selectedBackgroundImage ); - FadeInImage( selectedImage ); - StartTransitionAnimation(); - break; - } - case DisabledSelectedTransition: - { - StopTransitionAnimation(); - FadeOutImage( selectedBackgroundImage ); - FadeOutImage( selectedImage ); - FadeInImage( buttonImage ); - StartTransitionAnimation(); - break; - } - default: - { - break; - } - } - - if( mTransitionAnimation ) - { - return true; - } - - return false; -} - -bool PushButton::OnDisabled() -{ - Actor& buttonImage = GetButtonImage(); - Actor& selectedImage = GetSelectedImage(); - Actor& selectedBackgroundImage = GetSelectedBackgroundImage(); - Actor& backgroundImage = GetBackgroundImage(); - Actor& disabledImage = GetDisabledImage(); - Actor& disabledSelectedImage = GetDisabledSelectedImage(); - Actor& disabledBackgroundImage = GetDisabledBackgroundImage(); - - PaintState paintState = GetPaintState(); - - switch( paintState ) - { - case UnselectedState: - { - FadeOutImage( backgroundImage ); - FadeOutImage( buttonImage ); - FadeInImage( disabledBackgroundImage ); - FadeInImage( disabledImage ); - StartTransitionAnimation(); - break; - } - case SelectedState: - { - FadeOutImage( backgroundImage ); - FadeOutImage( selectedBackgroundImage ); - FadeOutImage( selectedImage ); - FadeInImage( disabledBackgroundImage ); - FadeInImage( disabledSelectedImage ); - StartTransitionAnimation(); - break; - } - case DisabledUnselectedState: - { - FadeOutImage( disabledBackgroundImage ); - FadeOutImage( disabledImage ); - FadeInImage( backgroundImage ); - FadeInImage( buttonImage ); - StartTransitionAnimation(); - break; - } - case DisabledSelectedState: - { - FadeOutImage( disabledBackgroundImage ); - FadeOutImage( disabledSelectedImage ); - FadeInImage( backgroundImage ); - FadeInImage( selectedBackgroundImage ); - FadeInImage( selectedImage ); - StartTransitionAnimation(); - break; - } - case UnselectedSelectedTransition: - { - float opacity = 1.f; - if( selectedImage ) - { - opacity = selectedImage.GetCurrentOpacity(); - } - - StopTransitionAnimation(); - FadeOutImage( backgroundImage ); - FadeOutImage( selectedBackgroundImage, opacity ); - FadeOutImage( selectedImage, opacity ); - FadeInImage( disabledBackgroundImage ); - FadeInImage( disabledSelectedImage ); - StartTransitionAnimation(); - break; - } - case SelectedUnselectedTransition: - { - float opacity = 1.f; - if( buttonImage ) - { - opacity = buttonImage.GetCurrentOpacity(); - } - - StopTransitionAnimation(); - FadeOutImage( backgroundImage ); - FadeOutImage( buttonImage, opacity ); - FadeInImage( disabledBackgroundImage ); - FadeInImage( disabledImage ); - StartTransitionAnimation(); - break; - } - case UnselectedDisabledTransition: - { - float opacity = 1.f; - if( disabledImage ) - { - opacity = disabledImage.GetCurrentOpacity(); - } - - StopTransitionAnimation( false ); - FadeOutImage( disabledBackgroundImage, opacity ); - FadeOutImage( disabledImage, opacity ); - FadeInImage( backgroundImage, 1.f - opacity ); - FadeInImage( buttonImage, 1.f - opacity ); - StartTransitionAnimation(); - break; - } - case DisabledUnselectedTransition: - { - float opacity = 1.f; - if( buttonImage ) - { - opacity = buttonImage.GetCurrentOpacity(); - } - - StopTransitionAnimation( false ); - FadeOutImage( backgroundImage, opacity ); - FadeOutImage( buttonImage, opacity ); - FadeInImage( disabledBackgroundImage, 1.f - opacity ); - FadeInImage( disabledImage, 1.f - opacity ); - StartTransitionAnimation(); - break; - } - case SelectedDisabledTransition: - { - float opacity = 1.f; - if( disabledSelectedImage ) - { - opacity = disabledSelectedImage.GetCurrentOpacity(); - } - - StopTransitionAnimation( false ); - FadeOutImage( disabledBackgroundImage, opacity ); - FadeOutImage( disabledSelectedImage, opacity ); - FadeInImage( backgroundImage, 1.f - opacity ); - FadeInImage( selectedBackgroundImage, 1.f - opacity ); - FadeInImage( selectedImage, 1.f - opacity ); - StartTransitionAnimation(); - break; - } - case DisabledSelectedTransition: - { - float opacity = 1.f; - if( selectedImage ) - { - opacity = selectedImage.GetCurrentOpacity(); - } - - StopTransitionAnimation( false ); - FadeOutImage( backgroundImage, opacity ); - FadeOutImage( selectedBackgroundImage, opacity ); - FadeOutImage( selectedImage, opacity ); - FadeInImage( disabledBackgroundImage, 1.f - opacity ); - FadeInImage( disabledSelectedImage, 1.f - opacity ); - StartTransitionAnimation(); - break; - } - } - - if( mTransitionAnimation ) - { - return true; - } - - return false; -} - -bool PushButton::OnPressed() -{ - Actor& buttonImage = GetButtonImage(); - Actor& selectedImage = GetSelectedImage(); - Actor& selectedBackgroundImage = GetSelectedBackgroundImage(); - - PaintState paintState = GetPaintState(); - - switch( paintState ) - { - case UnselectedState: - { - FadeOutImage( buttonImage ); - FadeInImage( selectedBackgroundImage ); - FadeInImage( selectedImage ); - StartTransitionAnimation(); - break; - } - case SelectedUnselectedTransition: - { - float opacity = 1.f; - if( buttonImage ) - { - opacity = buttonImage.GetCurrentOpacity(); - } - - StopTransitionAnimation( false ); - FadeOutImage( buttonImage, opacity ); - FadeInImage( selectedBackgroundImage, 1.f - opacity ); - FadeInImage( selectedImage, 1.f - opacity ); - StartTransitionAnimation(); - break; - } - case DisabledUnselectedTransition: - { - float opacity = 1.f; - if( buttonImage ) - { - opacity = buttonImage.GetCurrentOpacity(); - } - - StopTransitionAnimation(); - FadeOutImage( buttonImage, opacity ); - FadeInImage( selectedBackgroundImage ); - FadeInImage( selectedImage ); - StartTransitionAnimation(); - break; - } - default: - break; - } - - if( mTransitionAnimation ) - { - return true; - } - - return false; -} - -bool PushButton::OnReleased() -{ - Actor& buttonImage = GetButtonImage(); - Actor& selectedImage = GetSelectedImage(); - Actor& selectedBackgroundImage = GetSelectedBackgroundImage(); - - PaintState paintState = GetPaintState(); - - switch( paintState ) - { - case SelectedState: - { - FadeOutImage( selectedBackgroundImage ); - FadeOutImage( selectedImage ); - FadeInImage( buttonImage ); - StartTransitionAnimation(); - break; - } - case UnselectedSelectedTransition: - { - float opacity = 1.f; - if( selectedImage ) - { - opacity = selectedImage.GetCurrentOpacity(); - } - - StopTransitionAnimation( false ); - FadeOutImage( selectedBackgroundImage, opacity ); - FadeOutImage( selectedImage, opacity ); - FadeInImage( buttonImage, 1.f - opacity ); - StartTransitionAnimation(); - break; - } - case DisabledSelectedTransition: - { - float opacity = 1.f; - if( selectedImage ) - { - opacity = selectedImage.GetCurrentOpacity(); - } - - StopTransitionAnimation(); - FadeOutImage( selectedBackgroundImage, opacity ); - FadeOutImage( selectedImage, opacity ); - FadeInImage( buttonImage ); - StartTransitionAnimation(); - break; - } - default: - { - break; - } - } - - if( mTransitionAnimation ) - { - return true; - } - - return false; -} - -void PushButton::StopAllAnimations() +void PushButton::OnDisabledBackgroundImageSet() { - StopTransitionAnimation(); + ConfigureSizeNegotiation(); + RelayoutRequest(); } void PushButton::OnSizeSet( const Vector3& targetSize ) @@ -553,66 +199,40 @@ void PushButton::OnSizeSet( const Vector3& targetSize ) } } -void PushButton::StartTransitionAnimation() +void PushButton::PrepareForTranstionIn( Actor actor ) { - if( mTransitionAnimation ) - { - mTransitionAnimation.FinishedSignal().Connect( this, &PushButton::TransitionAnimationFinished ); - mTransitionAnimation.Play(); - } + actor.SetOpacity( 0.0f ); } -void PushButton::StopTransitionAnimation( bool remove ) +void PushButton::PrepareForTranstionOut( Actor actor ) { - if( mTransitionAnimation ) - { - mTransitionAnimation.Clear(); - mTransitionAnimation.Reset(); - } - - if( remove ) - { - UpdatePaintTransitionState(); - } + actor.SetOpacity( 1.0f ); } -void PushButton::FadeInImage( Actor& image, float opacity, Vector3 scale ) +void PushButton::OnTransitionIn( Actor actor ) { - if( image ) - { - image.SetOpacity( opacity ); - image.SetScale( scale ); - - if( !mTransitionAnimation ) - { - mTransitionAnimation = Dali::Animation::New( GetAnimationTime() ); - } + FadeImageTo( actor, 1.f ); +} - mTransitionAnimation.AnimateTo( Property( image, Actor::Property::COLOR_ALPHA ), 1.f ); - } +void PushButton::OnTransitionOut( Actor actor ) +{ + FadeImageTo( actor, 0.0f ); } -void PushButton::FadeOutImage( Actor& image, float opacity, Vector3 scale ) +void PushButton::FadeImageTo( Actor actor, float opacity ) { - if( image ) + if( actor ) { - image.SetOpacity( opacity ); - image.SetScale( scale ); + Dali::Animation transitionAnimation = GetTransitionAnimation(); + DALI_ASSERT_DEBUG( transitionAnimation ); - if( !mTransitionAnimation ) + if( transitionAnimation ) { - mTransitionAnimation = Dali::Animation::New( GetAnimationTime() ); + transitionAnimation.AnimateTo( Property( actor, Actor::Property::COLOR_ALPHA ), opacity ); } - - mTransitionAnimation.AnimateTo( Property( image, Actor::Property::COLOR_ALPHA ), 0.f ); } } -void PushButton::TransitionAnimationFinished( Dali::Animation& source ) -{ - StopTransitionAnimation(); -} - Vector3 PushButton::GetNaturalSize() { Vector3 size; diff --git a/dali-toolkit/internal/controls/buttons/push-button-impl.h b/dali-toolkit/internal/controls/buttons/push-button-impl.h index da49f13..51164b5 100644 --- a/dali-toolkit/internal/controls/buttons/push-button-impl.h +++ b/dali-toolkit/internal/controls/buttons/push-button-impl.h @@ -20,7 +20,6 @@ // EXTERNAL INCLUDES #include -#include // INTERNAL INCLUDES #include @@ -100,34 +99,34 @@ private: // From Button virtual void OnDisabledImageSet(); /** - * @copydoc Toolkit::Internal::Button::OnDisabledBackgroundImageSet() + * @copydoc Toolkit::Internal::Button::OnDisabledSelectedImageSet() */ - virtual void OnDisabledBackgroundImageSet(); + virtual void OnDisabledSelectedImageSet(); /** - * @copydoc Toolkit::Internal::Button::OnSelected() + * @copydoc Toolkit::Internal::Button::OnDisabledBackgroundImageSet() */ - virtual bool OnSelected(); + virtual void OnDisabledBackgroundImageSet(); /** - * @copydoc Toolkit::Internal::Button::OnDisabled() + * @copydoc Toolkit::Internal::Button::PrepareForTranstionIn( Actor actor ) */ - virtual bool OnDisabled(); + virtual void PrepareForTranstionIn( Actor actor ); /** - * @copydoc Toolkit::Internal::Button::OnPressed() + * @copydoc Toolkit::Internal::Button::PrepareForTranstionOut( Actor actor ) */ - virtual bool OnPressed(); + virtual void PrepareForTranstionOut( Actor actor ); /** - * @copydoc Toolkit::Internal::Button::OnReleased() + * @copydoc Toolkit::Internal::Button::OnTransitionIn( Actor actor ) */ - virtual bool OnReleased(); + virtual void OnTransitionIn( Actor actor ); /** - * @copydoc Toolkit::Internal::Button::StopAllAnimations() + * @copydoc Toolkit::Internal::Button::OnTransitionOut( Actor actor ) */ - virtual void StopAllAnimations(); + virtual void OnTransitionOut( Actor actor ); private: // From Control @@ -149,33 +148,11 @@ private: // From Control private: /** - * Starts the transition animation. - * PushButton::TransitionAnimationFinished slot is called when the animation finishes. - */ - void StartTransitionAnimation(); - - /** - * Stops the transition animation. - * @param[in] remove If true, removes the fadeout actor from root. - */ - void StopTransitionAnimation( bool remove = true ); - - /** * It adds the actor to the root actor and to the fade in animation. - * @param[inout] image The actor. - * @param[in] opacity The initial opacity. - * @param[in] scale The initial scale. - */ - void FadeInImage( Actor& image, float opacity = 0.f, Vector3 scale = Vector3( 1.f, 1.f, 1.f ) ); - - /** - * It adds the actor fade out animation and stores it to be removed when the animation finishes. - * @param[in] layer Defines if the actor is going to be stored in the mFadeOutBackgroundImage or mFadeOutCheckedImage member. - * @param[inout] image The actor. - * @param[in] opacity The initial opacity. - * @param[in] scale The initial scale. + * @param[inout] actor The actor. + * @param[in] opacity The opacity to fade to */ - void FadeOutImage( Actor& image, float opacity = 1.f, Vector3 scale = Vector3( 1.f, 1.f, 1.f ) ); + void FadeImageTo( Actor actor, float opacity ); /** * @brief Custom configuration for size negotiation @@ -191,13 +168,6 @@ private: */ void ConfigureSizeNegotiationDimension( Dimension::Type dimension, const std::vector< Actor >& images, Actor& label ); - // slots - - /** - * Called when the transition animation finishes. - */ - void TransitionAnimationFinished( Dali::Animation& source ); - private: // Undefined @@ -208,7 +178,6 @@ private: private: - Animation mTransitionAnimation; ///< Animation used in the state transitions. Vector3 mSize; ///< The button's size. }; diff --git a/dali-toolkit/internal/controls/buttons/radio-button-impl.cpp b/dali-toolkit/internal/controls/buttons/radio-button-impl.cpp index 81b6a5d..1e51ce3 100644 --- a/dali-toolkit/internal/controls/buttons/radio-button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/radio-button-impl.cpp @@ -44,6 +44,8 @@ TypeRegistration typeRegistration( typeid( Toolkit::RadioButton ), typeid( Toolk const char* const UNSELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "radio-button-unselected.png"; const char* const SELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "radio-button-selected.png"; +const char* const DISABLED_UNSELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "radio-button-unselected-disabled.png"; +const char* const DISABLED_SELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "radio-button-selected-disabled.png"; const float DISTANCE_BETWEEN_IMAGE_AND_LABEL( 5.0f ); } @@ -79,11 +81,15 @@ void RadioButton::OnButtonInitialize() // Wrap size of radio button around all its children self.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS ); - Image buttonImage = Dali::ResourceImage::New( UNSELECTED_BUTTON_IMAGE_DIR ); - Image selectedImage = Dali::ResourceImage::New( SELECTED_BUTTON_IMAGE_DIR ); + Image buttonImage = Dali::ResourceImage::New( UNSELECTED_BUTTON_IMAGE_DIR, ResourceImage::ON_DEMAND, ResourceImage::NEVER ); + Image selectedImage = Dali::ResourceImage::New( SELECTED_BUTTON_IMAGE_DIR, ResourceImage::ON_DEMAND, ResourceImage::NEVER ); + Image disabledImage = Dali::ResourceImage::New( DISABLED_UNSELECTED_BUTTON_IMAGE_DIR, ResourceImage::ON_DEMAND, ResourceImage::NEVER ); + Image disabledSelectedImage = Dali::ResourceImage::New( DISABLED_SELECTED_BUTTON_IMAGE_DIR, ResourceImage::ON_DEMAND, ResourceImage::NEVER ); SetButtonImage( ImageActor::New( buttonImage ) ); SetSelectedImage( ImageActor::New( selectedImage ) ); + SetDisabledImage( ImageActor::New( disabledImage ) ); + SetDisabledSelectedImage( ImageActor::New( disabledSelectedImage ) ); RelayoutRequest(); } @@ -115,25 +121,26 @@ void RadioButton::OnLabelSet() label.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::WIDTH ); } - if( IsSelected() ) + if( IsSelected() && GetSelectedImage() ) { label.SetX( GetSelectedImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); } - else + else if( GetButtonImage() ) { label.SetX( GetButtonImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); } + else + { + label.SetX( DISTANCE_BETWEEN_IMAGE_AND_LABEL ); + } } } -bool RadioButton::OnSelected() +void RadioButton::OnSelected() { - Actor& buttonImage = GetButtonImage(); - Actor& selectedImage = GetSelectedImage(); Actor& label = GetLabel(); PaintState paintState = GetPaintState(); - switch( paintState ) { case UnselectedState: @@ -151,9 +158,8 @@ bool RadioButton::OnSelected() } } - RemoveChild( buttonImage ); - - if( label ) + Actor& selectedImage = GetSelectedImage(); + if( label && selectedImage ) { label.SetX( selectedImage.GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); } @@ -161,9 +167,8 @@ bool RadioButton::OnSelected() } case SelectedState: { - RemoveChild( selectedImage ); - - if( label ) + Actor& buttonImage = GetButtonImage(); + if( label && buttonImage ) { label.SetX( buttonImage.GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); } @@ -174,9 +179,6 @@ bool RadioButton::OnSelected() break; } } - - // there is no animation - return false; } } // namespace Internal diff --git a/dali-toolkit/internal/controls/buttons/radio-button-impl.h b/dali-toolkit/internal/controls/buttons/radio-button-impl.h index d525a43..e7703a0 100644 --- a/dali-toolkit/internal/controls/buttons/radio-button-impl.h +++ b/dali-toolkit/internal/controls/buttons/radio-button-impl.h @@ -77,7 +77,7 @@ private: // From Button /** * @copydoc Toolkit::Internal::Button::OnSelected() */ - virtual bool OnSelected(); + virtual void OnSelected(); /** * @copydoc Toolkit::Internal::Button::OnLabelSet()