#include "check-box-button-impl.h"
// EXTERNAL INCLUDES
-#include <algorithm>
#include <dali/public-api/actors/image-actor.h>
#include <dali/public-api/object/type-registry.h>
-// INTERNAL INCLUDES
-#include "check-box-button-default-painter-impl.h"
-
namespace Dali
{
namespace
{
+const float FOREGROUND_DEPTH( 0.5f );
+const float BACKGROUND_DEPTH( 0.25f );
+
+const float ANIMATION_TIME( 0.26f ); // EFL checkbox tick time
+
+const Vector3 DISTANCE_BETWEEN_IMAGE_AND_LABEL(5.0f, 0.0f, 0.0f);
+
BaseHandle Create()
{
return Toolkit::CheckBoxButton::New();
TypeRegistration mType( typeid(Toolkit::CheckBoxButton), typeid(Toolkit::Button), Create );
-TypeAction a1(mType, Toolkit::CheckBoxButton::ACTION_CHECK_BOX_BUTTON_CLICK, &CheckBoxButton::DoAction);
-
}
-namespace
-{
- // Helper function used to cast a ButtonPainterPtr to CheckBoxButtonDefaultPainterPtr
- CheckBoxButtonDefaultPainterPtr GetCheckBoxButtonPainter( ButtonPainterPtr painter )
- {
- return static_cast<CheckBoxButtonDefaultPainter*>( painter.Get() );
- }
-} // namespace
-
Dali::Toolkit::CheckBoxButton CheckBoxButton::New()
{
// Create the implementation, temporarily owned on stack
return checkBoxButton;
}
-void CheckBoxButton::SetChecked( bool checked )
+CheckBoxButton::CheckBoxButton()
+: Button(),
+ mPaintState( UnselectedState )
{
- if( !mDisabled && ( checked != mChecked ) )
- {
- // Stores the state.
- mChecked = checked;
-
- Toolkit::CheckBoxButton handle( GetOwner() );
-
- // Notifies the painter the checkbox has been checked.
- GetCheckBoxButtonPainter( mPainter )->Checked( handle );
+ SetTogglableButton( true );
- // Raise state changed signal
- mStateChangedSignal.Emit( handle, mChecked );
- }
+ SetAnimationTime( ANIMATION_TIME );
}
-bool CheckBoxButton::IsChecked() const
+CheckBoxButton::~CheckBoxButton()
{
- return mChecked;
+ if( mCheckInAnimation )
+ {
+ mCheckInAnimation.Clear();
+ }
}
-void CheckBoxButton::SetBackgroundImage( Image image )
+void CheckBoxButton::SetSelectedImage( Actor image )
{
- SetBackgroundImage( ImageActor::New( image ) );
-}
+ Actor& selectedImage = GetSelectedImage();
-void CheckBoxButton::SetBackgroundImage( Actor image )
-{
- Toolkit::CheckBoxButton handle( GetOwner() );
- GetCheckBoxButtonPainter( mPainter )->SetBackgroundImage( handle, image );
-}
+ switch( mPaintState )
+ {
+ case SelectedState:
+ {
+ if( selectedImage && selectedImage.GetParent() )
+ {
+ Self().Remove( selectedImage );
+ }
+
+ selectedImage = image;
+ Self().Add( selectedImage );
+ break;
+ }
+ case UnselectedSelectedTransition:
+ {
+ StopCheckInAnimation();
+ Self().Remove( selectedImage );
+
+ selectedImage = image;
+ Self().Add( selectedImage );
+
+ mPaintState = SelectedState;
+ break;
+ }
+ default:
+ {
+ selectedImage = image;
+ break;
+ }
+ }
-Actor& CheckBoxButton::GetBackgroundImage()
-{
- return mBackgroundImage;
+ selectedImage.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+ selectedImage.SetParentOrigin( ParentOrigin::TOP_LEFT );
+ selectedImage.SetZ( FOREGROUND_DEPTH );
}
-Actor CheckBoxButton::GetBackgroundImage() const
+void CheckBoxButton::SetBackgroundImage( Actor image )
{
- return mBackgroundImage;
-}
+ Actor& backgroundImage = GetBackgroundImage();
-void CheckBoxButton::SetCheckedImage( Image image )
-{
- SetCheckedImage( ImageActor::New( image ) );
-}
+ switch( mPaintState )
+ {
+ case UnselectedState: // FALLTHROUGH
+ case SelectedState:
+ case UnselectedSelectedTransition:
+ {
+ if( backgroundImage && backgroundImage.GetParent() )
+ {
+ Self().Remove( backgroundImage );
+
+ Actor& label = GetLabel();
+
+ if( label )
+ {
+ backgroundImage.Remove( label );
+ image.Add( label );
+ }
+ }
+
+ backgroundImage = image;
+ Self().Add( backgroundImage );
+ break;
+ }
+ default:
+ {
+ backgroundImage = image;
+ break;
+ }
+ }
-void CheckBoxButton::SetCheckedImage( Actor image )
-{
- Toolkit::CheckBoxButton handle( GetOwner() );
- GetCheckBoxButtonPainter( mPainter )->SetCheckedImage( handle, image );
+ backgroundImage.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+ backgroundImage.SetParentOrigin( ParentOrigin::TOP_LEFT );
+ backgroundImage.SetZ( BACKGROUND_DEPTH );
}
-Actor& CheckBoxButton::GetCheckedImage()
+void CheckBoxButton::SetDisabledSelectedImage( Actor image )
{
- return mCheckedImage;
-}
+ Actor& disabledSelectedImage = GetDisabledSelectedImage();
-Actor CheckBoxButton::GetCheckedImage() const
-{
- return mCheckedImage;
-}
+ switch( mPaintState )
+ {
+ case DisabledSelectedState:
+ {
+ if( disabledSelectedImage && disabledSelectedImage.GetParent() )
+ {
+ Self().Remove( disabledSelectedImage );
+ }
+
+ disabledSelectedImage = image;
+ Self().Add( disabledSelectedImage );
+ break;
+ }
+ default:
+ {
+ disabledSelectedImage = image;
+ break;
+ }
+ }
-void CheckBoxButton::SetDisabledBackgroundImage( Image image )
-{
- SetDisabledBackgroundImage( ImageActor::New( image ) );
+ disabledSelectedImage.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+ disabledSelectedImage.SetParentOrigin( ParentOrigin::TOP_LEFT );
+ disabledSelectedImage.SetZ( FOREGROUND_DEPTH );
}
void CheckBoxButton::SetDisabledBackgroundImage( Actor image )
{
- Toolkit::CheckBoxButton handle( GetOwner() );
- GetCheckBoxButtonPainter( mPainter )->SetDisabledBackgroundImage( handle, image );
-}
+ Actor& disabledBackgroundImage = GetDisabledBackgroundImage();
-Actor& CheckBoxButton::GetDisabledBackgroundImage()
-{
- return mDisabledBackgroundImage;
-}
+ switch( mPaintState )
+ {
+ case DisabledSelectedState:
+ case DisabledUnselectedState:
+ {
+ if( disabledBackgroundImage && disabledBackgroundImage.GetParent() )
+ {
+ Self().Remove( disabledBackgroundImage );
+
+ Actor& label = GetLabel();
+
+ if( label )
+ {
+ disabledBackgroundImage.Remove( label );
+ image.Add( label );
+ }
+ }
+
+ disabledBackgroundImage = image;
+ Self().Add( disabledBackgroundImage );
+ break;
+ }
+ default:
+ {
+ disabledBackgroundImage = image;
+ break;
+ }
+ }
-Actor CheckBoxButton::GetDisabledBackgroundImage() const
-{
- return mDisabledBackgroundImage;
+ disabledBackgroundImage.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+ disabledBackgroundImage.SetParentOrigin( ParentOrigin::TOP_LEFT );
+ disabledBackgroundImage.SetZ( BACKGROUND_DEPTH );
}
-void CheckBoxButton::SetDisabledCheckedImage( Image image )
+void CheckBoxButton::OnLabelSet()
{
- SetDisabledCheckedImage( ImageActor::New( image ) );
-}
+ Actor& label = GetLabel();
-void CheckBoxButton::SetDisabledCheckedImage( Actor image )
-{
- Toolkit::CheckBoxButton handle( GetOwner() );
- GetCheckBoxButtonPainter( mPainter )->SetDisabledCheckedImage( handle, image );
+ if( label )
+ {
+ label.SetParentOrigin( ParentOrigin::CENTER_RIGHT );
+ label.SetAnchorPoint( AnchorPoint::CENTER_LEFT );
+ label.MoveBy( DISTANCE_BETWEEN_IMAGE_AND_LABEL );
+
+ if( IsDisabled() && GetDisabledBackgroundImage() )
+ {
+ GetDisabledBackgroundImage().Add( label );
+ }
+ else if ( GetBackgroundImage() )
+ {
+ GetBackgroundImage().Add( label );
+ }
+ else
+ {
+ Self().Add( label );
+ }
+ }
}
-Actor& CheckBoxButton::GetDisabledCheckedImage()
+void CheckBoxButton::OnSelected( bool selected )
{
- return mDisabledCheckedImage;
-}
+ Actor& selectedImage = GetSelectedImage();
-Actor CheckBoxButton::GetDisabledCheckedImage() const
-{
- return mDisabledCheckedImage;
+ switch( mPaintState )
+ {
+ case UnselectedState:
+ {
+ AddChild( selectedImage );
+ StartCheckInAnimation( selectedImage ); // Animate in the check actor
+
+ mPaintState = UnselectedSelectedTransition;
+ break;
+ }
+ case SelectedState:
+ {
+ RemoveChild( selectedImage );
+
+ mPaintState = UnselectedState;
+ break;
+ }
+ case UnselectedSelectedTransition:
+ {
+ StopCheckInAnimation();
+ RemoveChild( selectedImage );
+
+ mPaintState = UnselectedState;
+ break;
+ }
+ default:
+ break;
+ }
}
-Actor& CheckBoxButton::GetFadeOutBackgroundImage()
+void CheckBoxButton::OnDisabled( bool disabled )
{
- return mFadeOutBackgroundImage;
-}
+ Actor& backgroundImage = GetBackgroundImage();
+ Actor& selectedImage = GetSelectedImage();
+ Actor& disabledBackgroundImage = GetDisabledBackgroundImage();
+ Actor& disabledSelectedImage = GetDisabledSelectedImage();
-Actor& CheckBoxButton::GetFadeOutCheckedImage()
-{
- return mFadeOutCheckedImage;
-}
+ switch( mPaintState )
+ {
+ case UnselectedState:
+ {
+ if( disabled )
+ {
+ RemoveChild( backgroundImage );
+ AddChild( disabledBackgroundImage );
+ mPaintState = DisabledUnselectedState;
+ }
+ break;
+ }
+ case SelectedState:
+ {
+ if( disabled )
+ {
+ RemoveChild( backgroundImage );
+ RemoveChild( selectedImage );
+ AddChild( disabledBackgroundImage );
+ AddChild( disabledSelectedImage );
+
+ mPaintState = DisabledSelectedState;
+ }
+ break;
+ }
+ case DisabledUnselectedState:
+ {
+ if( !disabled )
+ {
+ RemoveChild( disabledBackgroundImage );
+ AddChild( backgroundImage );
+
+ mPaintState = UnselectedState;
+ }
+ break;
+ }
+ case DisabledSelectedState:
+ {
+ if( !disabled )
+ {
+ RemoveChild( disabledBackgroundImage );
+ RemoveChild( disabledSelectedImage );
+ AddChild( backgroundImage );
+ AddChild( selectedImage );
+
+ mPaintState = SelectedState;
+ }
+ break;
+ }
+ case UnselectedSelectedTransition:
+ {
+ if( disabled )
+ {
+ StopCheckInAnimation();
+
+ RemoveChild( backgroundImage );
+ RemoveChild( selectedImage );
+ AddChild( disabledBackgroundImage );
+ AddChild( disabledSelectedImage );
+
+ mPaintState = DisabledSelectedState;
+ }
+ break;
+ }
+ default:
+ break;
+ }
-void CheckBoxButton::OnButtonInitialize()
-{
-}
+ Actor& label = GetLabel();
-void CheckBoxButton::OnButtonUp()
-{
- if( ButtonDown == mState )
+ if( label )
{
- // Stores the state, notifies the painter and emits a signal.
- SetChecked( !mChecked );
+ if( label.GetParent() )
+ {
+ label.GetParent().Remove( label );
+ }
+
+ if( disabled && disabledBackgroundImage)
+ {
+ disabledBackgroundImage.Add( label );
+ }
+ else if( backgroundImage )
+ {
+ backgroundImage.Add( label );
+ }
}
}
-void CheckBoxButton::OnAnimationTimeSet( float animationTime )
+void CheckBoxButton::OnRelayout( const Vector2& size, ActorSizeContainer& container )
{
- GetCheckBoxButtonPainter( mPainter )->SetAnimationTime( animationTime );
-}
+ Vector3 newSize;
-float CheckBoxButton::OnAnimationTimeRequested() const
-{
- return GetCheckBoxButtonPainter( mPainter )->GetAnimationTime();
+ if( IsDisabled() && GetDisabledBackgroundImage() )
+ {
+ newSize = GetDisabledBackgroundImage().GetNaturalSize();
+ }
+ else if( GetBackgroundImage() )
+ {
+ newSize = GetBackgroundImage().GetNaturalSize();
+ }
+
+ Actor& label = GetLabel();
+
+ if( label )
+ {
+ // Offset the label from the radio button image
+ newSize.width += DISTANCE_BETWEEN_IMAGE_AND_LABEL.width;
+
+ // Find the size of the control using size negotiation
+ Vector3 actorNaturalSize( label.GetNaturalSize() );
+ Control::Relayout( label, Vector2( actorNaturalSize.width, actorNaturalSize.height ), container );
+
+ Vector3 actorSize( label.GetSize() );
+ newSize.width += actorSize.width;
+ newSize.height = std::max( newSize.height, actorSize.height );
+ }
+
+ Self().SetSize( newSize );
}
-void CheckBoxButton::OnActivated()
+void CheckBoxButton::AddChild( Actor& actor )
{
- // When the button is activated, it performs the click action
- PropertyValueContainer attributes;
- DoClickAction(attributes);
+ if( actor )
+ {
+ Self().Add( actor);
+ }
}
-void CheckBoxButton::DoClickAction(const PropertyValueContainer& attributes)
+void CheckBoxButton::RemoveChild( Actor& actor )
{
- // Prevents the button signals from doing a recursive loop by sending an action
- // and re-emitting the signals.
- if(!mClickActionPerforming)
+ if( actor )
{
- mClickActionPerforming = true;
- SetChecked( !mChecked );
- mClickActionPerforming = false;
+ Self().Remove( actor );
}
}
-bool CheckBoxButton::DoAction(BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes)
+void CheckBoxButton::StartCheckInAnimation( Actor& actor )
{
- bool ret = false;
+ if( actor )
+ {
+ if( !mTickUVEffect )
+ {
+ ImageActor imageActor = ImageActor::DownCast( actor );
+ mTickUVEffect = ImageRegionEffect::New();
+ imageActor.SetShaderEffect( mTickUVEffect );
+ }
- Dali::BaseHandle handle(object);
+ actor.SetScale( Vector3( 0.0f, 1.0f, 1.0f ) );
- Toolkit::CheckBoxButton button = Toolkit::CheckBoxButton::DownCast(handle);
+ mTickUVEffect.SetBottomRight( Vector2( 0.0f, 1.0f ) );
- if(Toolkit::CheckBoxButton::ACTION_CHECK_BOX_BUTTON_CLICK == actionName)
- {
- GetImplementation(button).DoClickAction(attributes);
- ret = true;
- }
+ if( !mCheckInAnimation )
+ {
+ mCheckInAnimation = Dali::Animation::New( GetAnimationTime() );
+ }
- return ret;
+ // UV anim
+ mCheckInAnimation.AnimateTo( Property( mTickUVEffect, mTickUVEffect.GetBottomRightPropertyName() ), Vector2( 1.0f, 1.0f ) );
+
+ // Actor size anim
+ mCheckInAnimation.AnimateTo( Property( actor, Actor::SCALE_X ), 1.0f);
+
+ mCheckInAnimation.FinishedSignal().Connect( this, &CheckBoxButton::CheckInAnimationFinished );
+ mCheckInAnimation.Play();
+ }
}
-CheckBoxButton::CheckBoxButton()
-: Button(),
- mChecked( false ),
- mClickActionPerforming(false)
+void CheckBoxButton::StopCheckInAnimation()
{
- // Creates specific painter.
- mPainter = new CheckBoxButtonDefaultPainter();
+ if( mCheckInAnimation )
+ {
+ mCheckInAnimation.Clear();
+ mCheckInAnimation.Reset();
+ }
}
-CheckBoxButton::~CheckBoxButton()
+void CheckBoxButton::CheckInAnimationFinished( Dali::Animation& source )
{
- mPainter = NULL;
+ switch( mPaintState )
+ {
+ case UnselectedSelectedTransition:
+ {
+ mPaintState = SelectedState;
+ break;
+ }
+ default:
+ {
+ break;
+ }
+ }
+
+ StopCheckInAnimation();
}
} // namespace Internal