2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include "check-box-button-default-painter-impl.h"
24 #include <dali/public-api/actors/image-actor.h>
25 #include <dali/public-api/object/ref-object.h>
26 #include "check-box-button-impl.h"
41 const float FOREGROUND_DEPTH( 0.5f );
42 const float BACKGROUND_DEPTH( 0.25f );
44 const float ANIMATION_TIME( 0.26f ); // EFL checkbox tick time
46 const std::string PERCENTAGE_PARENT_SIZE_PROPERTY_NAME( "percentage-parent-size" );
50 * Constraint to wrap an actor in y that is moving vertically
52 Vector3 EqualToPercentageWidthConstraint( const Vector3& current,
53 const PropertyInput& percentageProperty,
54 const PropertyInput& parentSizeProperty )
56 float percentage = percentageProperty.GetFloat();
57 const Vector3& parentSize = parentSizeProperty.GetVector3();
59 Vector3 size( parentSize );
66 inline Toolkit::Internal::CheckBoxButton& GetCheckBoxButtonImpl( Toolkit::Button& button )
68 DALI_ASSERT_ALWAYS( button );
70 Dali::RefObject& handle = button.GetImplementation();
72 return static_cast<Toolkit::Internal::CheckBoxButton&>( handle );
75 inline const Toolkit::Internal::CheckBoxButton& GetCheckBoxButtonImpl( const Toolkit::Button& button )
77 DALI_ASSERT_ALWAYS( button );
79 const Dali::RefObject& handle = button.GetImplementation();
81 return static_cast<const Toolkit::Internal::CheckBoxButton&>( handle );
86 CheckBoxButtonDefaultPainter::CheckBoxButtonDefaultPainter()
87 : CheckBoxButtonPainter(),
89 mPaintState( UncheckedState ),
91 mAnimationTime( ANIMATION_TIME ),
92 mPercentageParentSizeProperty( Property::INVALID_INDEX )
96 CheckBoxButtonDefaultPainter::~CheckBoxButtonDefaultPainter()
98 if( mCheckInAnimation )
100 mCheckInAnimation.Clear();
102 if( mCheckOutAnimation )
104 mCheckOutAnimation.Clear();
108 void CheckBoxButtonDefaultPainter::SetBackgroundImage( Toolkit::CheckBoxButton& checkBox, Actor image )
110 Toolkit::Internal::CheckBoxButton& checkBoxImpl = GetImplementation( checkBox );
111 Actor& backgroundImage = checkBoxImpl.GetBackgroundImage();
112 Actor& fadeOutBackgroundImage = checkBoxImpl.GetFadeOutBackgroundImage();
114 switch( mPaintState )
116 case UncheckedState: // FALLTHROUGH
118 case UncheckedCheckedTransition:
119 case CheckedUncheckedTransition:
121 if( backgroundImage && backgroundImage.GetParent() )
123 StopCheckOutAnimation( checkBox );
124 FadeOutImage( checkBox, Background, backgroundImage );
126 backgroundImage = image;
128 FadeInImage( checkBox, backgroundImage );
130 StartCheckOutAnimation( checkBox );
131 StartCheckInAnimation();
135 backgroundImage = image;
136 checkBox.Add( backgroundImage );
140 case DimmedUncheckedTransition: // FALLTHROUGH
141 case DimmedCheckedTransition:
143 StopCheckInAnimation();
144 checkBox.Remove( backgroundImage );
146 backgroundImage = image;
148 FadeInImage( checkBox, backgroundImage );
149 StartCheckInAnimation();
152 case CheckedDimmedTransition: // FALLTHROUGH
153 case UncheckedDimmedTransition:
156 if( fadeOutBackgroundImage )
158 opacity = fadeOutBackgroundImage.GetCurrentOpacity();
160 StopCheckOutAnimation( checkBox );
162 // Replaces the button image.
163 backgroundImage = image;
165 checkBox.Add( backgroundImage );
166 FadeOutImage( checkBox, Background, backgroundImage, opacity );
168 StartCheckOutAnimation( checkBox );
173 backgroundImage = image;
178 backgroundImage.SetAnchorPoint( AnchorPoint::TOP_LEFT );
179 backgroundImage.SetParentOrigin( ParentOrigin::TOP_LEFT );
180 ApplyConstraint( backgroundImage, BACKGROUND_DEPTH );
183 void CheckBoxButtonDefaultPainter::SetCheckedImage( Toolkit::CheckBoxButton& checkBox, Actor image )
185 Toolkit::Internal::CheckBoxButton& checkBoxImpl = GetImplementation( checkBox );
186 Actor& checkedImage = checkBoxImpl.GetCheckedImage();
187 Actor& fadeOutCheckedImage = checkBoxImpl.GetFadeOutCheckedImage();
189 switch( mPaintState )
193 if( checkedImage && checkedImage.GetParent() )
195 StopCheckOutAnimation( checkBox );
196 FadeOutImage( checkBox, Foreground, checkedImage );
198 checkedImage = image;
200 FadeInImage( checkBox, checkedImage );
202 StartCheckOutAnimation( checkBox );
203 StartCheckInAnimation();
207 checkedImage = image;
208 checkBox.Add( checkedImage );
212 case UncheckedCheckedTransition: // FALLTHROUGH
213 case DimmedCheckedTransition:
215 StopCheckInAnimation();
216 checkBox.Remove( checkedImage );
218 checkedImage = image;
220 FadeInImage( checkBox, checkedImage );
221 StartCheckInAnimation();
224 case CheckedUncheckedTransition: // FALLTHROUGH
225 case CheckedDimmedTransition:
228 if( fadeOutCheckedImage )
230 opacity = fadeOutCheckedImage.GetCurrentOpacity();
232 StopCheckOutAnimation( checkBox );
234 // Replaces the button image.
235 checkedImage = image;
237 checkBox.Add( checkedImage );
238 FadeOutImage( checkBox, Foreground, checkedImage, opacity );
240 StartCheckOutAnimation( checkBox );
245 checkedImage = image;
250 checkedImage.SetAnchorPoint( AnchorPoint::TOP_LEFT );
251 checkedImage.SetParentOrigin( ParentOrigin::TOP_LEFT );
252 ApplyCheckedConstraint( checkedImage, FOREGROUND_DEPTH );
255 void CheckBoxButtonDefaultPainter::SetDimmedCheckedImage( Toolkit::CheckBoxButton& checkBox, Actor image )
257 Toolkit::Internal::CheckBoxButton& checkBoxImpl = GetImplementation( checkBox );
258 Actor& dimmedCheckedImage = checkBoxImpl.GetDimmedCheckedImage();
259 Actor& fadeOutCheckedImage = checkBoxImpl.GetFadeOutCheckedImage();
261 switch( mPaintState )
263 case DimmedCheckedState:
265 if( dimmedCheckedImage && dimmedCheckedImage.GetParent() )
267 StopCheckOutAnimation( checkBox );
268 FadeOutImage( checkBox, Foreground, dimmedCheckedImage );
270 dimmedCheckedImage = image;
272 FadeInImage( checkBox, dimmedCheckedImage );
274 StartCheckOutAnimation( checkBox );
275 StartCheckInAnimation();
279 dimmedCheckedImage = image;
280 checkBox.Add( dimmedCheckedImage );
284 case CheckedDimmedTransition:
286 StopCheckInAnimation();
287 checkBox.Remove( dimmedCheckedImage );
289 dimmedCheckedImage = image;
291 FadeInImage( checkBox, dimmedCheckedImage );
292 StartCheckInAnimation();
295 case DimmedCheckedTransition:
298 if( fadeOutCheckedImage )
300 opacity = fadeOutCheckedImage.GetCurrentOpacity();
302 StopCheckOutAnimation( checkBox );
304 // Replaces the button image.
305 dimmedCheckedImage = image;
307 checkBox.Add( dimmedCheckedImage );
308 FadeOutImage( checkBox, Foreground, dimmedCheckedImage, opacity );
310 StartCheckOutAnimation( checkBox );
315 dimmedCheckedImage = image;
320 dimmedCheckedImage.SetAnchorPoint( AnchorPoint::TOP_LEFT );
321 dimmedCheckedImage.SetParentOrigin( ParentOrigin::TOP_LEFT );
322 ApplyConstraint( dimmedCheckedImage, FOREGROUND_DEPTH );
325 void CheckBoxButtonDefaultPainter::SetDimmedBackgroundImage( Toolkit::CheckBoxButton& checkBox, Actor image )
327 Toolkit::Internal::CheckBoxButton& checkBoxImpl = GetImplementation( checkBox );
328 Actor& dimmedBackgroundImage = checkBoxImpl.GetDimmedBackgroundImage();
329 Actor& fadeOutBackgroundImage = checkBoxImpl.GetFadeOutBackgroundImage();
331 switch( mPaintState )
333 case DimmedCheckedState: // FALLTHROUGH
334 case DimmedUncheckedState:
336 if( dimmedBackgroundImage && dimmedBackgroundImage.GetParent() )
338 StopCheckOutAnimation( checkBox );
339 FadeOutImage( checkBox, Background, dimmedBackgroundImage );
341 dimmedBackgroundImage = image;
343 FadeInImage( checkBox, dimmedBackgroundImage );
345 StartCheckOutAnimation( checkBox );
346 StartCheckInAnimation();
350 dimmedBackgroundImage = image;
351 checkBox.Add( dimmedBackgroundImage );
355 case UncheckedDimmedTransition: // FALLTHROUGH
356 case CheckedDimmedTransition:
358 StopCheckInAnimation();
359 checkBox.Remove( dimmedBackgroundImage );
361 dimmedBackgroundImage = image;
363 FadeInImage( checkBox, dimmedBackgroundImage );
364 StartCheckInAnimation();
367 case DimmedUncheckedTransition: // FALLTHROUGH
368 case DimmedCheckedTransition:
371 if( fadeOutBackgroundImage )
373 opacity = fadeOutBackgroundImage.GetCurrentOpacity();
375 StopCheckOutAnimation( checkBox );
377 // Replaces the button image.
378 dimmedBackgroundImage = image;
380 checkBox.Add( dimmedBackgroundImage );
381 FadeOutImage( checkBox, Background, dimmedBackgroundImage, opacity );
383 StartCheckOutAnimation( checkBox );
388 dimmedBackgroundImage = image;
393 dimmedBackgroundImage.SetAnchorPoint( AnchorPoint::TOP_LEFT );
394 dimmedBackgroundImage.SetParentOrigin( ParentOrigin::TOP_LEFT );
395 ApplyConstraint( dimmedBackgroundImage, BACKGROUND_DEPTH );
398 void CheckBoxButtonDefaultPainter::Initialize( Toolkit::Button& button )
400 Toolkit::Internal::CheckBoxButton& buttonImpl = GetCheckBoxButtonImpl( button );
401 Actor& backgroundImage = buttonImpl.GetBackgroundImage();
402 Actor& checkedImage = buttonImpl.GetCheckedImage();
403 Actor& dimmedBackgroundImage = buttonImpl.GetDimmedBackgroundImage();
404 Actor& dimmedCheckedImage = buttonImpl.GetDimmedCheckedImage();
406 Toolkit::CheckBoxButton& checkBox = static_cast<Toolkit::CheckBoxButton&>( button );
408 if( backgroundImage )
410 SetBackgroundImage( checkBox, backgroundImage );
415 SetCheckedImage( checkBox, checkedImage );
418 if( dimmedBackgroundImage )
420 SetDimmedBackgroundImage( checkBox, dimmedBackgroundImage );
423 if( dimmedCheckedImage )
425 SetDimmedCheckedImage( checkBox, dimmedCheckedImage );
428 SetDimmed( button, mDimmed );
431 void CheckBoxButtonDefaultPainter::SetSize( Toolkit::Button& button, const Vector3& size )
433 Toolkit::Internal::CheckBoxButton& buttonImpl = GetCheckBoxButtonImpl( button );
434 Actor& backgroundImage = buttonImpl.GetBackgroundImage();
435 Actor& checkedImage = buttonImpl.GetCheckedImage();
436 Actor& dimmedBackgroundImage = buttonImpl.GetDimmedBackgroundImage();
437 Actor& dimmedCheckedImage = buttonImpl.GetDimmedCheckedImage();
439 ApplyCheckedConstraint( checkedImage, FOREGROUND_DEPTH );
440 ApplyConstraint( backgroundImage, BACKGROUND_DEPTH );
441 ApplyConstraint( dimmedCheckedImage, FOREGROUND_DEPTH );
442 ApplyConstraint( dimmedBackgroundImage, BACKGROUND_DEPTH );
445 void CheckBoxButtonDefaultPainter::SetDimmed( Toolkit::Button& button, bool dimmed )
449 Toolkit::Internal::CheckBoxButton& buttonImpl = GetCheckBoxButtonImpl( button );
450 Actor& backgroundImage = buttonImpl.GetBackgroundImage();
451 Actor& checkedImage = buttonImpl.GetCheckedImage();
452 Actor& dimmedBackgroundImage = buttonImpl.GetDimmedBackgroundImage();
453 Actor& dimmedCheckedImage = buttonImpl.GetDimmedCheckedImage();
454 Actor& fadeOutCheckedImage = buttonImpl.GetFadeOutCheckedImage();
455 Actor& fadeOutBackgroundImage = buttonImpl.GetFadeOutBackgroundImage();
457 Toolkit::CheckBoxButton& checkBox = static_cast<Toolkit::CheckBoxButton&>( button );
459 switch( mPaintState )
465 StopCheckOutAnimation( checkBox );
466 FadeOutImage( checkBox, Background, backgroundImage );
467 FadeInImage( checkBox, dimmedBackgroundImage );
468 StartCheckOutAnimation( checkBox );
469 StartCheckInAnimation();
471 mPaintState = UncheckedDimmedTransition;
479 StopCheckOutAnimation( checkBox );
480 FadeOutImage( checkBox, Background, backgroundImage );
481 FadeOutImage( checkBox, Foreground, checkedImage );
482 FadeInImage( checkBox, dimmedCheckedImage );
483 FadeInImage( checkBox, dimmedBackgroundImage );
484 StartCheckOutAnimation( checkBox );
485 StartCheckInAnimation();
487 mPaintState = CheckedDimmedTransition;
491 case DimmedUncheckedState:
495 StopCheckOutAnimation( checkBox );
496 FadeOutImage( checkBox, Background, dimmedBackgroundImage );
497 FadeInImage( checkBox, backgroundImage );
498 StartCheckOutAnimation( checkBox );
499 StartCheckInAnimation();
501 mPaintState = DimmedUncheckedTransition;
505 case DimmedCheckedState:
509 StopCheckOutAnimation( checkBox );
510 FadeOutImage( checkBox, Background, dimmedBackgroundImage );
511 FadeOutImage( checkBox, Foreground, dimmedCheckedImage );
512 FadeInImage( checkBox, backgroundImage );
513 FadeInImage( checkBox, checkedImage );
514 StartCheckOutAnimation( checkBox );
515 StartCheckInAnimation();
517 mPaintState = DimmedCheckedTransition;
521 case UncheckedCheckedTransition:
528 opacity = checkedImage.GetCurrentOpacity();
530 StopCheckOutAnimation( checkBox );
531 StopCheckInAnimation();
533 FadeOutImage( checkBox, Foreground, checkedImage, opacity );
534 FadeOutImage( checkBox, Background, backgroundImage );
536 FadeInImage( checkBox, dimmedCheckedImage );
537 FadeInImage( checkBox, dimmedBackgroundImage );
539 StartCheckOutAnimation( checkBox );
540 StartCheckInAnimation();
542 mPaintState = CheckedDimmedTransition;
546 case CheckedUncheckedTransition:
551 if( fadeOutCheckedImage )
553 opacity = fadeOutCheckedImage.GetCurrentOpacity();
555 StopCheckOutAnimation( checkBox );
556 StopCheckInAnimation();
558 button.Add( dimmedCheckedImage );
559 FadeOutImage( checkBox, Foreground, dimmedCheckedImage, opacity );
560 FadeOutImage( checkBox, Background, backgroundImage );
562 FadeInImage( checkBox, dimmedBackgroundImage );
564 StartCheckOutAnimation( checkBox );
565 StartCheckInAnimation();
567 mPaintState = UncheckedDimmedTransition;
571 case UncheckedDimmedTransition:
576 if( fadeOutBackgroundImage )
578 opacity = fadeOutBackgroundImage.GetCurrentOpacity();
580 StopCheckOutAnimation( checkBox, false );
581 StopCheckInAnimation();
583 FadeOutImage( checkBox, Background, dimmedBackgroundImage, 1.f - opacity );
584 FadeInImage( checkBox, backgroundImage, opacity );
586 StartCheckOutAnimation( checkBox );
587 StartCheckInAnimation();
589 mPaintState = DimmedUncheckedTransition;
593 case DimmedUncheckedTransition:
598 if( fadeOutBackgroundImage )
600 opacity = fadeOutBackgroundImage.GetCurrentOpacity();
602 StopCheckOutAnimation( checkBox, false );
603 StopCheckInAnimation();
605 FadeOutImage( checkBox, Background, backgroundImage, 1.f - opacity );
606 FadeInImage( checkBox, dimmedBackgroundImage, opacity );
608 StartCheckOutAnimation( checkBox );
609 StartCheckInAnimation();
611 mPaintState = UncheckedDimmedTransition;
615 case CheckedDimmedTransition:
620 if( fadeOutBackgroundImage )
622 opacity = fadeOutBackgroundImage.GetCurrentOpacity();
624 StopCheckOutAnimation( checkBox, false );
625 StopCheckInAnimation();
627 FadeOutImage( checkBox, Foreground, dimmedCheckedImage, 1.f - opacity );
628 FadeOutImage( checkBox, Background, dimmedBackgroundImage, 1.f - opacity );
629 FadeInImage( checkBox, checkedImage, opacity );
630 FadeInImage( checkBox, backgroundImage, opacity );
632 StartCheckOutAnimation( checkBox );
633 StartCheckInAnimation();
635 mPaintState = DimmedCheckedTransition;
639 case DimmedCheckedTransition:
644 if( fadeOutBackgroundImage )
646 opacity = fadeOutBackgroundImage.GetCurrentOpacity();
648 StopCheckOutAnimation( checkBox, false );
649 StopCheckInAnimation();
651 FadeOutImage( checkBox, Foreground, checkedImage, 1.f - opacity );
652 FadeOutImage( checkBox, Background, backgroundImage, 1.f - opacity );
653 FadeInImage( checkBox, dimmedCheckedImage, opacity );
654 FadeInImage( checkBox, dimmedBackgroundImage, opacity );
656 StartCheckOutAnimation( checkBox );
657 StartCheckInAnimation();
659 mPaintState = CheckedDimmedTransition;
668 void CheckBoxButtonDefaultPainter::SetAnimationTime( float animationTime )
670 mAnimationTime = animationTime;
673 float CheckBoxButtonDefaultPainter::GetAnimationTime() const
675 return mAnimationTime;
678 void CheckBoxButtonDefaultPainter::Checked( Toolkit::CheckBoxButton& button )
680 Toolkit::Internal::CheckBoxButton& checkBoxImpl = GetCheckBoxButtonImpl( button );
681 Actor& checkedImage = checkBoxImpl.GetCheckedImage();
682 Actor& fadeOutCheckedImage = checkBoxImpl.GetFadeOutCheckedImage();
684 switch( mPaintState )
688 // Fade in the 'check' actor.
689 FadeInImage( button, checkedImage );
690 SetupCheckedAnimation( button, checkedImage ); // Animate in the check actor
691 StartCheckInAnimation();
693 mPaintState = UncheckedCheckedTransition;
698 // Fade out the 'check' actor.
699 StopCheckOutAnimation( button );
700 FadeOutImage( button, Foreground, checkedImage );
701 StartCheckOutAnimation( button );
703 if( button.GetProperty<bool>( button.GetPropertyIndex( Toolkit::CheckBoxButton::USE_FADE_ANIMATION_PROPERTY_NAME ) ) )
705 mPaintState = CheckedUncheckedTransition;
709 mPaintState = UncheckedState;
713 case UncheckedCheckedTransition:
715 // Stop fade in and start fade out.
716 StopCheckOutAnimation( button );
717 StopCheckInAnimation();
722 opacity = checkedImage.GetCurrentOpacity();
724 FadeOutImage( button, Foreground, checkedImage, opacity );
725 StartCheckOutAnimation( button );
727 if( button.GetProperty<bool>( button.GetPropertyIndex( Toolkit::CheckBoxButton::USE_FADE_ANIMATION_PROPERTY_NAME ) ) )
729 mPaintState = CheckedUncheckedTransition;
733 mPaintState = UncheckedState;
737 case CheckedUncheckedTransition:
739 // Stop fade out and start fade in.
741 if( fadeOutCheckedImage )
743 opacity = fadeOutCheckedImage.GetCurrentOpacity();
745 StopCheckOutAnimation( button );
747 FadeInImage( button, checkedImage, opacity );
748 StartCheckInAnimation();
750 mPaintState = UncheckedCheckedTransition;
758 void CheckBoxButtonDefaultPainter::ApplyConstraint( Actor& actor, float depth )
762 actor.RemoveConstraints();
763 actor.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
768 void CheckBoxButtonDefaultPainter::ApplyCheckedConstraint( Actor& actor, float depth )
772 if( mPercentageParentSizeProperty == Property::INVALID_INDEX )
774 mPercentageParentSizeProperty = actor.RegisterProperty( PERCENTAGE_PARENT_SIZE_PROPERTY_NAME, 1.0f );
777 actor.RemoveConstraints();
778 actor.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE,
779 LocalSource( mPercentageParentSizeProperty ),
780 ParentSource( Actor::SIZE ),
781 EqualToPercentageWidthConstraint ) );
786 void CheckBoxButtonDefaultPainter::AddToFadeInAnimation( const Actor& actor )
788 if( !mCheckInAnimation )
790 mCheckInAnimation = Dali::Animation::New( mAnimationTime );
793 mCheckInAnimation.OpacityTo( actor, 1.f );
797 void CheckBoxButtonDefaultPainter::StartCheckInAnimation()
799 if( mCheckInAnimation )
801 mCheckInAnimation.FinishedSignal().Connect( this, &CheckBoxButtonDefaultPainter::CheckInAnimationFinished );
802 mCheckInAnimation.Play();
806 void CheckBoxButtonDefaultPainter::StopCheckInAnimation()
808 if( mCheckInAnimation )
810 mCheckInAnimation.Clear();
811 mCheckInAnimation.Reset();
815 void CheckBoxButtonDefaultPainter::AddToFadeOutAnimation( const Actor& actor )
817 if( !mCheckOutAnimation )
819 mCheckOutAnimation = Dali::Animation::New( mAnimationTime );
822 mCheckOutAnimation.OpacityTo( actor, 0.f );
825 void CheckBoxButtonDefaultPainter::StartCheckOutAnimation( Toolkit::CheckBoxButton& checkBox )
827 if( mCheckOutAnimation )
829 Toolkit::Internal::CheckBoxButton& checkBoxImpl = GetCheckBoxButtonImpl( checkBox );
830 mButton = &checkBoxImpl;
832 mCheckOutAnimation.FinishedSignal().Connect( this, &CheckBoxButtonDefaultPainter::CheckOutAnimationFinished );
833 mCheckOutAnimation.Play();
837 void CheckBoxButtonDefaultPainter::StopCheckOutAnimation( Toolkit::CheckBoxButton& checkBox, bool remove )
839 if( mCheckOutAnimation )
841 mCheckOutAnimation.Clear();
842 mCheckOutAnimation.Reset();
845 Toolkit::Internal::CheckBoxButton& checkBoxImpl = GetCheckBoxButtonImpl( checkBox );
846 Actor& fadeOutCheckedImage = checkBoxImpl.GetFadeOutCheckedImage();
847 Actor& fadeOutBackgroundImage = checkBoxImpl.GetFadeOutBackgroundImage();
851 if( fadeOutCheckedImage && fadeOutCheckedImage.GetParent() )
853 fadeOutCheckedImage.GetParent().Remove( fadeOutCheckedImage );
856 if( fadeOutBackgroundImage && fadeOutBackgroundImage.GetParent() )
858 fadeOutBackgroundImage.GetParent().Remove( fadeOutBackgroundImage );
861 fadeOutCheckedImage.Reset();
862 fadeOutBackgroundImage.Reset();
866 void CheckBoxButtonDefaultPainter::FadeInImage( Toolkit::CheckBoxButton& checkBox, Actor& image, float opacity )
870 if( !image.GetParent() )
872 checkBox.Add( image );
875 if( checkBox.GetProperty<bool>( checkBox.GetPropertyIndex( Toolkit::CheckBoxButton::USE_FADE_ANIMATION_PROPERTY_NAME ) ) )
877 image.SetOpacity( opacity );
878 AddToFadeInAnimation( image );
882 image.SetOpacity( 1.0f );
887 void CheckBoxButtonDefaultPainter::FadeOutImage( Toolkit::CheckBoxButton& checkBox, ImageLayer layer, Actor& image, float opacity )
891 Toolkit::Internal::CheckBoxButton& checkBoxImpl = GetCheckBoxButtonImpl( checkBox );
892 Actor& fadeOutCheckedImage = checkBoxImpl.GetFadeOutCheckedImage();
893 Actor& fadeOutBackgroundImage = checkBoxImpl.GetFadeOutBackgroundImage();
895 Actor& actorLayer = ( ( Background == layer ) ? fadeOutBackgroundImage : fadeOutCheckedImage );
899 if( checkBox.GetProperty<bool>( checkBox.GetPropertyIndex( Toolkit::CheckBoxButton::USE_FADE_ANIMATION_PROPERTY_NAME ) ) )
901 actorLayer.SetOpacity( opacity );
902 AddToFadeOutAnimation( actorLayer );
906 actorLayer.SetOpacity( 0.0f );
911 void CheckBoxButtonDefaultPainter::AddToCheckInAnimation( const Actor& actor )
913 if( !mCheckInAnimation )
915 mCheckInAnimation = Dali::Animation::New( mAnimationTime );
919 mCheckInAnimation.AnimateTo( Property( mTickUVEffect, mTickUVEffect.GetBottomRightPropertyName() ), Vector2( 1.0f, 1.0f ) );
922 Handle handle = actor; // Get rid of const
923 mCheckInAnimation.AnimateTo( Property( handle, mPercentageParentSizeProperty ), 1.0f );
926 void CheckBoxButtonDefaultPainter::SetupCheckedAnimation( Toolkit::CheckBoxButton& checkBox, Actor& image )
928 if( checkBox.GetProperty<bool>( checkBox.GetPropertyIndex( Toolkit::CheckBoxButton::USE_CHECK_ANIMATION_PROPERTY_NAME ) ) && image )
932 ImageActor imageActor = ImageActor::DownCast( image );
933 mTickUVEffect = ImageRegionEffect::New();
934 imageActor.SetShaderEffect( mTickUVEffect );
937 // Register a custom property to animate size of tick over
938 if( mPercentageParentSizeProperty != Property::INVALID_INDEX )
940 image.SetProperty( mPercentageParentSizeProperty, 0.0f );
943 mTickUVEffect.SetBottomRight( Vector2( 0.0f, 1.0f ) );
946 if( !image.GetParent() )
948 checkBox.Add( image );
951 AddToCheckInAnimation( image );
955 void CheckBoxButtonDefaultPainter::EndCheckOutAnimation()
957 switch( mPaintState )
959 case UncheckedCheckedTransition:
961 mPaintState = CheckedState;
964 case CheckedUncheckedTransition:
966 mPaintState = UncheckedState;
969 case UncheckedDimmedTransition:
971 mPaintState = DimmedUncheckedState;
974 case DimmedUncheckedTransition:
976 mPaintState = UncheckedState;
979 case CheckedDimmedTransition:
981 mPaintState = DimmedCheckedState;
984 case DimmedCheckedTransition:
986 mPaintState = CheckedState;
996 void CheckBoxButtonDefaultPainter::CheckOutAnimationFinished( Dali::Animation& source )
998 EndCheckOutAnimation();
1000 Toolkit::CheckBoxButton handle( mButton->GetOwner() );
1001 StopCheckOutAnimation( handle );
1005 void CheckBoxButtonDefaultPainter::CheckInAnimationFinished( Dali::Animation& source )
1007 switch( mPaintState )
1009 case UncheckedCheckedTransition:
1011 mPaintState = CheckedState;
1014 case CheckedUncheckedTransition:
1016 mPaintState = UncheckedState;
1019 case UncheckedDimmedTransition:
1021 mPaintState = DimmedUncheckedState;
1024 case DimmedUncheckedTransition:
1026 mPaintState = UncheckedState;
1029 case CheckedDimmedTransition:
1031 mPaintState = DimmedCheckedState;
1034 case DimmedCheckedTransition:
1036 mPaintState = CheckedState;
1045 StopCheckInAnimation();
1048 } // namespace Internal
1050 } // namespace Toolkit