X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fbuttons%2Fcheck-box-button-impl.cpp;h=5bf5344fae42fd085f991a60ddacbef15b0c1310;hb=refs%2Fchanges%2F49%2F88249%2F1;hp=4eb7831028edede2cc5e189d9625b335843ee652;hpb=e2eda444afbe82e9591fe198eef339227f90a616;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git 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 4eb7831..5bf5344 100644 --- a/dali-toolkit/internal/controls/buttons/check-box-button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/check-box-button-impl.cpp @@ -1,30 +1,32 @@ -// -// Copyright (c) 2014 Samsung Electronics Co., Ltd. -// -// Licensed under the Flora License, Version 1.0 (the License); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://floralicense.org/license/ -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an AS IS BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ // CLASS HEADER - #include "check-box-button-impl.h" // EXTERNAL INCLUDES +#include +#include -#include - -// INTERNAL INCLUDES - -#include "check-box-button-default-painter-impl.h" +//INTERNAL INCLUDES +#include +#include +#include +#include namespace Dali { @@ -38,6 +40,9 @@ namespace Internal namespace { +const float DISTANCE_BETWEEN_IMAGE_AND_LABEL( 5.0f ); +const float ANIMATION_TIME( 0.26f ); // EFL checkbox tick time + BaseHandle Create() { return Toolkit::CheckBoxButton::New(); @@ -45,19 +50,12 @@ BaseHandle Create() TypeRegistration mType( typeid(Toolkit::CheckBoxButton), typeid(Toolkit::Button), Create ); -TypeAction a1(mType, Toolkit::CheckBoxButton::ACTION_CHECK_BOX_BUTTON_CLICK, &CheckBoxButton::DoAction); - +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"; } -namespace -{ - // Helper function used to cast a ButtonPainterPtr to CheckBoxButtonDefaultPainterPtr - CheckBoxButtonDefaultPainterPtr GetCheckBoxButtonPainter( ButtonPainterPtr painter ) - { - return static_cast( painter.Get() ); - } -} // namespace - Dali::Toolkit::CheckBoxButton CheckBoxButton::New() { // Create the implementation, temporarily owned on stack @@ -73,195 +71,171 @@ Dali::Toolkit::CheckBoxButton CheckBoxButton::New() return checkBoxButton; } -void CheckBoxButton::SetChecked( bool checked ) -{ - if( !mDimmed && ( checked != mChecked ) ) - { - // Stores the state. - mChecked = checked; - - Toolkit::CheckBoxButton handle( GetOwner() ); - - // Notifies the painter the checkbox has been checked. - GetCheckBoxButtonPainter( mPainter )->Checked( handle ); - - // Emit signal. - mClickedSignalV2.Emit( handle ); - } -} - -bool CheckBoxButton::IsChecked() const -{ - return mChecked; -} - -void CheckBoxButton::SetBackgroundImage( Image image ) -{ - SetBackgroundImage( ImageActor::New( image ) ); -} - -void CheckBoxButton::SetBackgroundImage( Actor image ) -{ - Toolkit::CheckBoxButton handle( GetOwner() ); - GetCheckBoxButtonPainter( mPainter )->SetBackgroundImage( handle, image ); -} - -Actor& CheckBoxButton::GetBackgroundImage() -{ - return mBackgroundImage; -} - -Actor CheckBoxButton::GetBackgroundImage() const -{ - return mBackgroundImage; -} - -void CheckBoxButton::SetCheckedImage( Image image ) -{ - SetCheckedImage( ImageActor::New( image ) ); -} - -void CheckBoxButton::SetCheckedImage( Actor image ) -{ - Toolkit::CheckBoxButton handle( GetOwner() ); - GetCheckBoxButtonPainter( mPainter )->SetCheckedImage( handle, image ); -} - -Actor& CheckBoxButton::GetCheckedImage() -{ - return mCheckedImage; -} - -Actor CheckBoxButton::GetCheckedImage() const -{ - return mCheckedImage; -} - -void CheckBoxButton::SetDimmedBackgroundImage( Image image ) +CheckBoxButton::CheckBoxButton() +: Button() { - SetDimmedBackgroundImage( ImageActor::New( image ) ); -} + SetTogglableButton( true ); -void CheckBoxButton::SetDimmedBackgroundImage( Actor image ) -{ - Toolkit::CheckBoxButton handle( GetOwner() ); - GetCheckBoxButtonPainter( mPainter )->SetDimmedBackgroundImage( handle, image ); + SetAnimationTime( ANIMATION_TIME ); } -Actor& CheckBoxButton::GetDimmedBackgroundImage() +CheckBoxButton::~CheckBoxButton() { - return mDimmedBackgroundImage; } -Actor CheckBoxButton::GetDimmedBackgroundImage() const +void CheckBoxButton::SetTickUVEffect() { - return mDimmedBackgroundImage; -} + Toolkit::ImageView imageView = Toolkit::ImageView::DownCast( mSelectedImage ); + if( imageView ) + { + imageView.RegisterProperty( "uTextureRect", Vector4(0.f, 0.f, 1.f, 1.f ) ); + imageView.RegisterProperty( "uTopLeft", Vector2::ZERO ); -void CheckBoxButton::SetDimmedCheckedImage( Image image ) -{ - SetDimmedCheckedImage( ImageActor::New( image ) ); -} + Property::Map shaderMap = CreateImageRegionEffect(); + imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, shaderMap ); -void CheckBoxButton::SetDimmedCheckedImage( Actor image ) -{ - Toolkit::CheckBoxButton handle( GetOwner() ); - GetCheckBoxButtonPainter( mPainter )->SetDimmedCheckedImage( handle, image ); + GetImpl( imageView ).SetDepthIndex( DepthIndex::DECORATION ); + } } -Actor& CheckBoxButton::GetDimmedCheckedImage() +void CheckBoxButton::OnInitialize() { - return mDimmedCheckedImage; -} + Button::OnInitialize(); -Actor CheckBoxButton::GetDimmedCheckedImage() const -{ - return mDimmedCheckedImage; -} + // Wrap around all children + Self().SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS ); -Actor& CheckBoxButton::GetFadeOutBackgroundImage() -{ - return mFadeOutBackgroundImage; -} + SetUnselectedImage( UNSELECTED_BUTTON_IMAGE_DIR ); + SetSelectedImage( SELECTED_BUTTON_IMAGE_DIR ); + SetDisabledImage( DISABLED_UNSELECTED_BUTTON_IMAGE_DIR ); + SetDisabledSelectedImage( DISABLED_SELECTED_BUTTON_IMAGE_DIR ); -Actor& CheckBoxButton::GetFadeOutCheckedImage() -{ - return mFadeOutCheckedImage; + mSelectedImage = GetSelectedImage(); + SetTickUVEffect(); } -void CheckBoxButton::OnButtonInitialize() +void CheckBoxButton::OnLabelSet( bool noPadding ) { - mUseFadeAnimationProperty = Self().RegisterProperty( Toolkit::CheckBoxButton::USE_FADE_ANIMATION_PROPERTY_NAME, false ); - mUseCheckAnimationProperty = Self().RegisterProperty( Toolkit::CheckBoxButton::USE_CHECK_ANIMATION_PROPERTY_NAME, true ); -} + Actor& label = GetLabelActor(); -void CheckBoxButton::OnButtonUp() -{ - if( ButtonDown == mState ) + if( label ) { - // Stores the state, notifies the painter and emits a signal. - SetChecked( !mChecked ); + label.SetParentOrigin( ParentOrigin::CENTER_LEFT ); + label.SetAnchorPoint( AnchorPoint::CENTER_LEFT ); + + if( IsDisabled() && GetDisabledBackgroundImage() ) + { + label.SetX( GetDisabledBackgroundImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); + } + else if ( GetBackgroundImage() ) + { + label.SetX( GetBackgroundImage().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 ); + } } } -void CheckBoxButton::OnAnimationTimeSet( float animationTime ) -{ - GetCheckBoxButtonPainter( mPainter )->SetAnimationTime( animationTime ); -} - -float CheckBoxButton::OnAnimationTimeRequested() const +void CheckBoxButton::OnDisabled() { - return GetCheckBoxButtonPainter( mPainter )->GetAnimationTime(); -} + Actor& backgroundImage = GetBackgroundImage(); + Actor& disabledBackgroundImage = GetDisabledBackgroundImage(); -void CheckBoxButton::OnActivated() -{ - // When the button is activated, it performs the click action - std::vector attributes; - DoClickAction(attributes); -} - -void CheckBoxButton::DoClickAction(const PropertyValueContainer& attributes) -{ - // Prevents the button signals from doing a recursive loop by sending an action - // and re-emitting the signals. - if(!mClickActionPerforming) + Actor& label = GetLabelActor(); + if( label ) { - mClickActionPerforming = true; - SetChecked( !mChecked ); - mClickActionPerforming = false; + if( IsDisabled() && disabledBackgroundImage ) + { + label.SetX( disabledBackgroundImage.GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); + } + else if( backgroundImage ) + { + 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 ); + } } } -bool CheckBoxButton::DoAction(BaseObject* object, const std::string& actionName, const std::vector& attributes) +void CheckBoxButton::PrepareForTranstionIn( Actor actor ) { - bool ret = false; - - Dali::BaseHandle handle(object); - - Toolkit::CheckBoxButton button = Toolkit::CheckBoxButton::DownCast(handle); - - if(Toolkit::CheckBoxButton::ACTION_CHECK_BOX_BUTTON_CLICK == actionName) + Actor& selectedImage = GetSelectedImage(); + if( actor == selectedImage ) { - GetImplementation(button).DoClickAction(attributes); - ret = true; + actor.SetScale( Vector3( 0.0f, 1.0f, 1.0f ) ); + actor.RegisterProperty( "uBottomRight", Vector2( 0.0f, 1.0f ) ); + + if( mSelectedImage != selectedImage ) + { + mSelectedImage = selectedImage; + SetTickUVEffect(); + } } - - return ret; } -CheckBoxButton::CheckBoxButton() -: Button(), - mChecked( false ), - mClickActionPerforming(false) +void CheckBoxButton::PrepareForTranstionOut( Actor actor ) { - // Creates specific painter. - mPainter = new CheckBoxButtonDefaultPainter(); + Actor& selectedImage = GetSelectedImage(); + if( actor == selectedImage ) + { + actor.SetScale( Vector3::ONE ); + actor.RegisterProperty( "uBottomRight", Vector2::ONE ); + + if( mSelectedImage != selectedImage ) + { + mSelectedImage = selectedImage; + SetTickUVEffect(); + } + } } -CheckBoxButton::~CheckBoxButton() +void CheckBoxButton::OnTransitionIn( Actor actor ) { - mPainter = NULL; + 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