/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include "check-box-button-impl.h"
// EXTERNAL INCLUDES
-#include <dali/public-api/actors/image-actor.h>
#include <dali/public-api/object/type-registry.h>
+#include <dali/public-api/images/resource-image.h>
+
+//INTERNAL INCLUDES
+#include <dali-toolkit/internal/controls/image-view/image-view-impl.h>
+#include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
+#include <dali-toolkit/devel-api/shader-effects/image-region-effect.h>
+#include <dali-toolkit/devel-api/shader-effects/image-region-effect.h>
namespace Dali
{
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()
CheckBoxButton::~CheckBoxButton()
{
- if( mTransitionAnimation )
+}
+
+void CheckBoxButton::SetTickUVEffect()
+{
+ Toolkit::ImageView imageView = Toolkit::ImageView::DownCast( mSelectedImage );
+ if( imageView )
{
- mTransitionAnimation.Clear();
+ imageView.RegisterProperty( "uTextureRect", Vector4(0.f, 0.f, 1.f, 1.f ) );
+ imageView.RegisterProperty( "uTopLeft", Vector2::ZERO );
+
+ Property::Map shaderMap = CreateImageRegionEffect();
+ imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, shaderMap );
+
+ GetImpl( imageView ).SetDepthIndex( DepthIndex::DECORATION );
}
}
-void CheckBoxButton::OnButtonInitialize()
+void CheckBoxButton::OnInitialize()
{
+ Button::OnInitialize();
+
// Wrap around all children
- Self().SetResizePolicy( FIT_TO_CHILDREN, ALL_DIMENSIONS );
+ Self().SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
+
+ SetUnselectedImage( UNSELECTED_BUTTON_IMAGE_DIR );
+ SetSelectedImage( SELECTED_BUTTON_IMAGE_DIR );
+ SetDisabledImage( DISABLED_UNSELECTED_BUTTON_IMAGE_DIR );
+ SetDisabledSelectedImage( DISABLED_SELECTED_BUTTON_IMAGE_DIR );
+
+ mSelectedImage = GetSelectedImage();
+ SetTickUVEffect();
}
-void CheckBoxButton::OnLabelSet()
+void CheckBoxButton::OnLabelSet( bool noPadding )
{
- Actor& label = GetLabel();
+ Actor& label = GetLabelActor();
if( label )
{
{
label.SetX( GetBackgroundImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL );
}
- else
- {
- label.SetX( DISTANCE_BETWEEN_IMAGE_AND_LABEL );
- }
- }
-}
-
-bool CheckBoxButton::OnSelected()
-{
- Actor& selectedImage = GetSelectedImage();
-
- PaintState paintState = GetPaintState();
-
- switch( paintState )
- {
- case UnselectedState:
+ else if( IsSelected() && GetSelectedImage())
{
- StartTransitionAnimation( selectedImage );
- break;
+ label.SetX( GetSelectedImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL );
}
- case SelectedState:
+ else if( GetUnselectedImage() )
{
- RemoveChild( selectedImage );
- break;
+ label.SetX( GetUnselectedImage().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();
+ Actor& label = GetLabelActor();
if( label )
{
- if( IsDisabled() && disabledBackgroundImage)
+ if( IsDisabled() && disabledBackgroundImage )
{
label.SetX( disabledBackgroundImage.GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL );
}
{
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( GetUnselectedImage() )
+ {
+ label.SetX( GetUnselectedImage().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 )
{
- if( !mTickUVEffect )
- {
- ImageActor imageActor = ImageActor::DownCast( actor );
- mTickUVEffect = ImageRegionEffect::New();
- imageActor.SetShaderEffect( mTickUVEffect );
- }
-
actor.SetScale( Vector3( 0.0f, 1.0f, 1.0f ) );
+ actor.RegisterProperty( "uBottomRight", Vector2( 0.0f, 1.0f ) );
- mTickUVEffect.SetBottomRight( Vector2( 0.0f, 1.0f ) );
-
- if( !mTransitionAnimation )
+ if( mSelectedImage != selectedImage )
{
- mTransitionAnimation = Dali::Animation::New( GetAnimationTime() );
+ mSelectedImage = selectedImage;
+ SetTickUVEffect();
}
-
- // UV anim
- mTransitionAnimation.AnimateTo( Property( mTickUVEffect, mTickUVEffect.GetBottomRightPropertyName() ), 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 );
+ actor.RegisterProperty( "uBottomRight", Vector2::ONE );
- if( remove )
- {
- UpdatePaintTransitionState();
+ if( mSelectedImage != selectedImage )
+ {
+ mSelectedImage = selectedImage;
+ SetTickUVEffect();
+ }
}
}
-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 )
+ {
+ // UV anim
+ transitionAnimation.AnimateTo( Property( actor, "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( mSelectedImage == selectedImage )
+ {
+ actor.RegisterProperty( "uBottomRight", Vector2::ONE );
+ }
+ }
+ }
}
} // namespace Internal