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.
19 #include "check-box-button-default-painter-impl.h"
22 #include <dali/public-api/animation/constraints.h>
25 #include <dali/public-api/actors/image-actor.h>
26 #include <dali/public-api/object/ref-object.h>
27 #include "check-box-button-impl.h"
40 const float FOREGROUND_DEPTH( 0.5f );
41 const float BACKGROUND_DEPTH( 0.25f );
43 const float ANIMATION_TIME( 0.26f ); // EFL checkbox tick time
45 const std::string PERCENTAGE_PARENT_SIZE_PROPERTY_NAME( "percentage-parent-size" );
49 * Constraint to wrap an actor in y that is moving vertically
51 Vector3 EqualToPercentageWidthConstraint( const Vector3& current,
52 const PropertyInput& percentageProperty,
53 const PropertyInput& parentSizeProperty )
55 float percentage = percentageProperty.GetFloat();
56 const Vector3& parentSize = parentSizeProperty.GetVector3();
58 Vector3 size( parentSize );
65 inline Toolkit::Internal::CheckBoxButton& GetCheckBoxButtonImpl( Toolkit::Button& button )
67 DALI_ASSERT_ALWAYS( button );
69 Dali::RefObject& handle = button.GetImplementation();
71 return static_cast<Toolkit::Internal::CheckBoxButton&>( handle );
74 inline const Toolkit::Internal::CheckBoxButton& GetCheckBoxButtonImpl( const Toolkit::Button& button )
76 DALI_ASSERT_ALWAYS( button );
78 const Dali::RefObject& handle = button.GetImplementation();
80 return static_cast<const Toolkit::Internal::CheckBoxButton&>( handle );
85 CheckBoxButtonDefaultPainter::CheckBoxButtonDefaultPainter()
86 : CheckBoxButtonPainter(),
88 mPaintState( UncheckedState ),
90 mAnimationTime( ANIMATION_TIME ),
91 mPercentageParentSizeProperty( Property::INVALID_INDEX )
95 CheckBoxButtonDefaultPainter::~CheckBoxButtonDefaultPainter()
97 if( mCheckInAnimation )
99 mCheckInAnimation.Clear();
101 if( mCheckOutAnimation )
103 mCheckOutAnimation.Clear();
107 void CheckBoxButtonDefaultPainter::SetBackgroundImage( Toolkit::CheckBoxButton& checkBox, Actor image )
109 Toolkit::Internal::CheckBoxButton& checkBoxImpl = GetImplementation( checkBox );
110 Actor& backgroundImage = checkBoxImpl.GetBackgroundImage();
111 Actor& fadeOutBackgroundImage = checkBoxImpl.GetFadeOutBackgroundImage();
113 switch( mPaintState )
115 case UncheckedState: // FALLTHROUGH
117 case UncheckedCheckedTransition:
118 case CheckedUncheckedTransition:
120 if( backgroundImage && backgroundImage.GetParent() )
122 StopCheckOutAnimation( checkBox );
123 FadeOutImage( checkBox, Background, backgroundImage );
125 backgroundImage = image;
127 FadeInImage( checkBox, backgroundImage );
129 StartCheckOutAnimation( checkBox );
130 StartCheckInAnimation();
134 backgroundImage = image;
135 checkBox.Add( backgroundImage );
139 case DimmedUncheckedTransition: // FALLTHROUGH
140 case DimmedCheckedTransition:
142 StopCheckInAnimation();
143 checkBox.Remove( backgroundImage );
145 backgroundImage = image;
147 FadeInImage( checkBox, backgroundImage );
148 StartCheckInAnimation();
151 case CheckedDimmedTransition: // FALLTHROUGH
152 case UncheckedDimmedTransition:
155 if( fadeOutBackgroundImage )
157 opacity = fadeOutBackgroundImage.GetCurrentOpacity();
159 StopCheckOutAnimation( checkBox );
161 // Replaces the button image.
162 backgroundImage = image;
164 checkBox.Add( backgroundImage );
165 FadeOutImage( checkBox, Background, backgroundImage, opacity );
167 StartCheckOutAnimation( checkBox );
172 backgroundImage = image;
177 backgroundImage.SetAnchorPoint( AnchorPoint::TOP_LEFT );
178 backgroundImage.SetParentOrigin( ParentOrigin::TOP_LEFT );
179 ApplyConstraint( backgroundImage, BACKGROUND_DEPTH );
182 void CheckBoxButtonDefaultPainter::SetCheckedImage( Toolkit::CheckBoxButton& checkBox, Actor image )
184 Toolkit::Internal::CheckBoxButton& checkBoxImpl = GetImplementation( checkBox );
185 Actor& checkedImage = checkBoxImpl.GetCheckedImage();
186 Actor& fadeOutCheckedImage = checkBoxImpl.GetFadeOutCheckedImage();
188 switch( mPaintState )
192 if( checkedImage && checkedImage.GetParent() )
194 StopCheckOutAnimation( checkBox );
195 FadeOutImage( checkBox, Foreground, checkedImage );
197 checkedImage = image;
199 FadeInImage( checkBox, checkedImage );
201 StartCheckOutAnimation( checkBox );
202 StartCheckInAnimation();
206 checkedImage = image;
207 checkBox.Add( checkedImage );
211 case UncheckedCheckedTransition: // FALLTHROUGH
212 case DimmedCheckedTransition:
214 StopCheckInAnimation();
215 checkBox.Remove( checkedImage );
217 checkedImage = image;
219 FadeInImage( checkBox, checkedImage );
220 StartCheckInAnimation();
223 case CheckedUncheckedTransition: // FALLTHROUGH
224 case CheckedDimmedTransition:
227 if( fadeOutCheckedImage )
229 opacity = fadeOutCheckedImage.GetCurrentOpacity();
231 StopCheckOutAnimation( checkBox );
233 // Replaces the button image.
234 checkedImage = image;
236 checkBox.Add( checkedImage );
237 FadeOutImage( checkBox, Foreground, checkedImage, opacity );
239 StartCheckOutAnimation( checkBox );
244 checkedImage = image;
249 checkedImage.SetAnchorPoint( AnchorPoint::TOP_LEFT );
250 checkedImage.SetParentOrigin( ParentOrigin::TOP_LEFT );
251 ApplyCheckedConstraint( checkedImage, FOREGROUND_DEPTH );
254 void CheckBoxButtonDefaultPainter::SetDimmedCheckedImage( Toolkit::CheckBoxButton& checkBox, Actor image )
256 Toolkit::Internal::CheckBoxButton& checkBoxImpl = GetImplementation( checkBox );
257 Actor& dimmedCheckedImage = checkBoxImpl.GetDimmedCheckedImage();
258 Actor& fadeOutCheckedImage = checkBoxImpl.GetFadeOutCheckedImage();
260 switch( mPaintState )
262 case DimmedCheckedState:
264 if( dimmedCheckedImage && dimmedCheckedImage.GetParent() )
266 StopCheckOutAnimation( checkBox );
267 FadeOutImage( checkBox, Foreground, dimmedCheckedImage );
269 dimmedCheckedImage = image;
271 FadeInImage( checkBox, dimmedCheckedImage );
273 StartCheckOutAnimation( checkBox );
274 StartCheckInAnimation();
278 dimmedCheckedImage = image;
279 checkBox.Add( dimmedCheckedImage );
283 case CheckedDimmedTransition:
285 StopCheckInAnimation();
286 checkBox.Remove( dimmedCheckedImage );
288 dimmedCheckedImage = image;
290 FadeInImage( checkBox, dimmedCheckedImage );
291 StartCheckInAnimation();
294 case DimmedCheckedTransition:
297 if( fadeOutCheckedImage )
299 opacity = fadeOutCheckedImage.GetCurrentOpacity();
301 StopCheckOutAnimation( checkBox );
303 // Replaces the button image.
304 dimmedCheckedImage = image;
306 checkBox.Add( dimmedCheckedImage );
307 FadeOutImage( checkBox, Foreground, dimmedCheckedImage, opacity );
309 StartCheckOutAnimation( checkBox );
314 dimmedCheckedImage = image;
319 dimmedCheckedImage.SetAnchorPoint( AnchorPoint::TOP_LEFT );
320 dimmedCheckedImage.SetParentOrigin( ParentOrigin::TOP_LEFT );
321 ApplyConstraint( dimmedCheckedImage, FOREGROUND_DEPTH );
324 void CheckBoxButtonDefaultPainter::SetDimmedBackgroundImage( Toolkit::CheckBoxButton& checkBox, Actor image )
326 Toolkit::Internal::CheckBoxButton& checkBoxImpl = GetImplementation( checkBox );
327 Actor& dimmedBackgroundImage = checkBoxImpl.GetDimmedBackgroundImage();
328 Actor& fadeOutBackgroundImage = checkBoxImpl.GetFadeOutBackgroundImage();
330 switch( mPaintState )
332 case DimmedCheckedState: // FALLTHROUGH
333 case DimmedUncheckedState:
335 if( dimmedBackgroundImage && dimmedBackgroundImage.GetParent() )
337 StopCheckOutAnimation( checkBox );
338 FadeOutImage( checkBox, Background, dimmedBackgroundImage );
340 dimmedBackgroundImage = image;
342 FadeInImage( checkBox, dimmedBackgroundImage );
344 StartCheckOutAnimation( checkBox );
345 StartCheckInAnimation();
349 dimmedBackgroundImage = image;
350 checkBox.Add( dimmedBackgroundImage );
354 case UncheckedDimmedTransition: // FALLTHROUGH
355 case CheckedDimmedTransition:
357 StopCheckInAnimation();
358 checkBox.Remove( dimmedBackgroundImage );
360 dimmedBackgroundImage = image;
362 FadeInImage( checkBox, dimmedBackgroundImage );
363 StartCheckInAnimation();
366 case DimmedUncheckedTransition: // FALLTHROUGH
367 case DimmedCheckedTransition:
370 if( fadeOutBackgroundImage )
372 opacity = fadeOutBackgroundImage.GetCurrentOpacity();
374 StopCheckOutAnimation( checkBox );
376 // Replaces the button image.
377 dimmedBackgroundImage = image;
379 checkBox.Add( dimmedBackgroundImage );
380 FadeOutImage( checkBox, Background, dimmedBackgroundImage, opacity );
382 StartCheckOutAnimation( checkBox );
387 dimmedBackgroundImage = image;
392 dimmedBackgroundImage.SetAnchorPoint( AnchorPoint::TOP_LEFT );
393 dimmedBackgroundImage.SetParentOrigin( ParentOrigin::TOP_LEFT );
394 ApplyConstraint( dimmedBackgroundImage, BACKGROUND_DEPTH );
397 void CheckBoxButtonDefaultPainter::Initialize( Toolkit::Button& button )
399 Toolkit::Internal::CheckBoxButton& buttonImpl = GetCheckBoxButtonImpl( button );
400 Actor& backgroundImage = buttonImpl.GetBackgroundImage();
401 Actor& checkedImage = buttonImpl.GetCheckedImage();
402 Actor& dimmedBackgroundImage = buttonImpl.GetDimmedBackgroundImage();
403 Actor& dimmedCheckedImage = buttonImpl.GetDimmedCheckedImage();
405 Toolkit::CheckBoxButton& checkBox = static_cast<Toolkit::CheckBoxButton&>( button );
407 if( backgroundImage )
409 SetBackgroundImage( checkBox, backgroundImage );
414 SetCheckedImage( checkBox, checkedImage );
417 if( dimmedBackgroundImage )
419 SetDimmedBackgroundImage( checkBox, dimmedBackgroundImage );
422 if( dimmedCheckedImage )
424 SetDimmedCheckedImage( checkBox, dimmedCheckedImage );
427 SetDimmed( button, mDimmed );
430 void CheckBoxButtonDefaultPainter::SetSize( Toolkit::Button& button, const Vector3& size )
432 Toolkit::Internal::CheckBoxButton& buttonImpl = GetCheckBoxButtonImpl( button );
433 Actor& backgroundImage = buttonImpl.GetBackgroundImage();
434 Actor& checkedImage = buttonImpl.GetCheckedImage();
435 Actor& dimmedBackgroundImage = buttonImpl.GetDimmedBackgroundImage();
436 Actor& dimmedCheckedImage = buttonImpl.GetDimmedCheckedImage();
438 ApplyCheckedConstraint( checkedImage, FOREGROUND_DEPTH );
439 ApplyConstraint( backgroundImage, BACKGROUND_DEPTH );
440 ApplyConstraint( dimmedCheckedImage, FOREGROUND_DEPTH );
441 ApplyConstraint( dimmedBackgroundImage, BACKGROUND_DEPTH );
444 void CheckBoxButtonDefaultPainter::SetDimmed( Toolkit::Button& button, bool dimmed )
448 Toolkit::Internal::CheckBoxButton& buttonImpl = GetCheckBoxButtonImpl( button );
449 Actor& backgroundImage = buttonImpl.GetBackgroundImage();
450 Actor& checkedImage = buttonImpl.GetCheckedImage();
451 Actor& dimmedBackgroundImage = buttonImpl.GetDimmedBackgroundImage();
452 Actor& dimmedCheckedImage = buttonImpl.GetDimmedCheckedImage();
453 Actor& fadeOutCheckedImage = buttonImpl.GetFadeOutCheckedImage();
454 Actor& fadeOutBackgroundImage = buttonImpl.GetFadeOutBackgroundImage();
456 Toolkit::CheckBoxButton& checkBox = static_cast<Toolkit::CheckBoxButton&>( button );
458 switch( mPaintState )
464 StopCheckOutAnimation( checkBox );
465 FadeOutImage( checkBox, Background, backgroundImage );
466 FadeInImage( checkBox, dimmedBackgroundImage );
467 StartCheckOutAnimation( checkBox );
468 StartCheckInAnimation();
470 mPaintState = UncheckedDimmedTransition;
478 StopCheckOutAnimation( checkBox );
479 FadeOutImage( checkBox, Background, backgroundImage );
480 FadeOutImage( checkBox, Foreground, checkedImage );
481 FadeInImage( checkBox, dimmedCheckedImage );
482 FadeInImage( checkBox, dimmedBackgroundImage );
483 StartCheckOutAnimation( checkBox );
484 StartCheckInAnimation();
486 mPaintState = CheckedDimmedTransition;
490 case DimmedUncheckedState:
494 StopCheckOutAnimation( checkBox );
495 FadeOutImage( checkBox, Background, dimmedBackgroundImage );
496 FadeInImage( checkBox, backgroundImage );
497 StartCheckOutAnimation( checkBox );
498 StartCheckInAnimation();
500 mPaintState = DimmedUncheckedTransition;
504 case DimmedCheckedState:
508 StopCheckOutAnimation( checkBox );
509 FadeOutImage( checkBox, Background, dimmedBackgroundImage );
510 FadeOutImage( checkBox, Foreground, dimmedCheckedImage );
511 FadeInImage( checkBox, backgroundImage );
512 FadeInImage( checkBox, checkedImage );
513 StartCheckOutAnimation( checkBox );
514 StartCheckInAnimation();
516 mPaintState = DimmedCheckedTransition;
520 case UncheckedCheckedTransition:
527 opacity = checkedImage.GetCurrentOpacity();
529 StopCheckOutAnimation( checkBox );
530 StopCheckInAnimation();
532 FadeOutImage( checkBox, Foreground, checkedImage, opacity );
533 FadeOutImage( checkBox, Background, backgroundImage );
535 FadeInImage( checkBox, dimmedCheckedImage );
536 FadeInImage( checkBox, dimmedBackgroundImage );
538 StartCheckOutAnimation( checkBox );
539 StartCheckInAnimation();
541 mPaintState = CheckedDimmedTransition;
545 case CheckedUncheckedTransition:
550 if( fadeOutCheckedImage )
552 opacity = fadeOutCheckedImage.GetCurrentOpacity();
554 StopCheckOutAnimation( checkBox );
555 StopCheckInAnimation();
557 button.Add( dimmedCheckedImage );
558 FadeOutImage( checkBox, Foreground, dimmedCheckedImage, opacity );
559 FadeOutImage( checkBox, Background, backgroundImage );
561 FadeInImage( checkBox, dimmedBackgroundImage );
563 StartCheckOutAnimation( checkBox );
564 StartCheckInAnimation();
566 mPaintState = UncheckedDimmedTransition;
570 case UncheckedDimmedTransition:
575 if( fadeOutBackgroundImage )
577 opacity = fadeOutBackgroundImage.GetCurrentOpacity();
579 StopCheckOutAnimation( checkBox, false );
580 StopCheckInAnimation();
582 FadeOutImage( checkBox, Background, dimmedBackgroundImage, 1.f - opacity );
583 FadeInImage( checkBox, backgroundImage, opacity );
585 StartCheckOutAnimation( checkBox );
586 StartCheckInAnimation();
588 mPaintState = DimmedUncheckedTransition;
592 case DimmedUncheckedTransition:
597 if( fadeOutBackgroundImage )
599 opacity = fadeOutBackgroundImage.GetCurrentOpacity();
601 StopCheckOutAnimation( checkBox, false );
602 StopCheckInAnimation();
604 FadeOutImage( checkBox, Background, backgroundImage, 1.f - opacity );
605 FadeInImage( checkBox, dimmedBackgroundImage, opacity );
607 StartCheckOutAnimation( checkBox );
608 StartCheckInAnimation();
610 mPaintState = UncheckedDimmedTransition;
614 case CheckedDimmedTransition:
619 if( fadeOutBackgroundImage )
621 opacity = fadeOutBackgroundImage.GetCurrentOpacity();
623 StopCheckOutAnimation( checkBox, false );
624 StopCheckInAnimation();
626 FadeOutImage( checkBox, Foreground, dimmedCheckedImage, 1.f - opacity );
627 FadeOutImage( checkBox, Background, dimmedBackgroundImage, 1.f - opacity );
628 FadeInImage( checkBox, checkedImage, opacity );
629 FadeInImage( checkBox, backgroundImage, opacity );
631 StartCheckOutAnimation( checkBox );
632 StartCheckInAnimation();
634 mPaintState = DimmedCheckedTransition;
638 case DimmedCheckedTransition:
643 if( fadeOutBackgroundImage )
645 opacity = fadeOutBackgroundImage.GetCurrentOpacity();
647 StopCheckOutAnimation( checkBox, false );
648 StopCheckInAnimation();
650 FadeOutImage( checkBox, Foreground, checkedImage, 1.f - opacity );
651 FadeOutImage( checkBox, Background, backgroundImage, 1.f - opacity );
652 FadeInImage( checkBox, dimmedCheckedImage, opacity );
653 FadeInImage( checkBox, dimmedBackgroundImage, opacity );
655 StartCheckOutAnimation( checkBox );
656 StartCheckInAnimation();
658 mPaintState = CheckedDimmedTransition;
667 void CheckBoxButtonDefaultPainter::SetAnimationTime( float animationTime )
669 mAnimationTime = animationTime;
672 float CheckBoxButtonDefaultPainter::GetAnimationTime() const
674 return mAnimationTime;
677 void CheckBoxButtonDefaultPainter::Checked( Toolkit::CheckBoxButton& button )
679 Toolkit::Internal::CheckBoxButton& checkBoxImpl = GetCheckBoxButtonImpl( button );
680 Actor& checkedImage = checkBoxImpl.GetCheckedImage();
681 Actor& fadeOutCheckedImage = checkBoxImpl.GetFadeOutCheckedImage();
683 switch( mPaintState )
687 // Fade in the 'check' actor.
688 FadeInImage( button, checkedImage );
689 SetupCheckedAnimation( button, checkedImage ); // Animate in the check actor
690 StartCheckInAnimation();
692 mPaintState = UncheckedCheckedTransition;
697 // Fade out the 'check' actor.
698 StopCheckOutAnimation( button );
699 FadeOutImage( button, Foreground, checkedImage );
700 StartCheckOutAnimation( button );
702 if( button.GetProperty<bool>( button.GetPropertyIndex( Toolkit::CheckBoxButton::USE_FADE_ANIMATION_PROPERTY_NAME ) ) )
704 mPaintState = CheckedUncheckedTransition;
708 mPaintState = UncheckedState;
712 case UncheckedCheckedTransition:
714 // Stop fade in and start fade out.
715 StopCheckOutAnimation( button );
716 StopCheckInAnimation();
721 opacity = checkedImage.GetCurrentOpacity();
723 FadeOutImage( button, Foreground, checkedImage, opacity );
724 StartCheckOutAnimation( button );
726 if( button.GetProperty<bool>( button.GetPropertyIndex( Toolkit::CheckBoxButton::USE_FADE_ANIMATION_PROPERTY_NAME ) ) )
728 mPaintState = CheckedUncheckedTransition;
732 mPaintState = UncheckedState;
736 case CheckedUncheckedTransition:
738 // Stop fade out and start fade in.
740 if( fadeOutCheckedImage )
742 opacity = fadeOutCheckedImage.GetCurrentOpacity();
744 StopCheckOutAnimation( button );
746 FadeInImage( button, checkedImage, opacity );
747 StartCheckInAnimation();
749 mPaintState = UncheckedCheckedTransition;
757 void CheckBoxButtonDefaultPainter::ApplyConstraint( Actor& actor, float depth )
761 actor.RemoveConstraints();
762 actor.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
767 void CheckBoxButtonDefaultPainter::ApplyCheckedConstraint( Actor& actor, float depth )
771 if( mPercentageParentSizeProperty == Property::INVALID_INDEX )
773 mPercentageParentSizeProperty = actor.RegisterProperty( PERCENTAGE_PARENT_SIZE_PROPERTY_NAME, 1.0f );
776 actor.RemoveConstraints();
777 actor.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE,
778 LocalSource( mPercentageParentSizeProperty ),
779 ParentSource( Actor::SIZE ),
780 EqualToPercentageWidthConstraint ) );
785 void CheckBoxButtonDefaultPainter::AddToFadeInAnimation( const Actor& actor )
787 if( !mCheckInAnimation )
789 mCheckInAnimation = Dali::Animation::New( mAnimationTime );
792 mCheckInAnimation.OpacityTo( actor, 1.f );
796 void CheckBoxButtonDefaultPainter::StartCheckInAnimation()
798 if( mCheckInAnimation )
800 mCheckInAnimation.FinishedSignal().Connect( this, &CheckBoxButtonDefaultPainter::CheckInAnimationFinished );
801 mCheckInAnimation.Play();
805 void CheckBoxButtonDefaultPainter::StopCheckInAnimation()
807 if( mCheckInAnimation )
809 mCheckInAnimation.Clear();
810 mCheckInAnimation.Reset();
814 void CheckBoxButtonDefaultPainter::AddToFadeOutAnimation( const Actor& actor )
816 if( !mCheckOutAnimation )
818 mCheckOutAnimation = Dali::Animation::New( mAnimationTime );
821 mCheckOutAnimation.OpacityTo( actor, 0.f );
824 void CheckBoxButtonDefaultPainter::StartCheckOutAnimation( Toolkit::CheckBoxButton& checkBox )
826 if( mCheckOutAnimation )
828 Toolkit::Internal::CheckBoxButton& checkBoxImpl = GetCheckBoxButtonImpl( checkBox );
829 mButton = &checkBoxImpl;
831 mCheckOutAnimation.FinishedSignal().Connect( this, &CheckBoxButtonDefaultPainter::CheckOutAnimationFinished );
832 mCheckOutAnimation.Play();
836 void CheckBoxButtonDefaultPainter::StopCheckOutAnimation( Toolkit::CheckBoxButton& checkBox, bool remove )
838 if( mCheckOutAnimation )
840 mCheckOutAnimation.Clear();
841 mCheckOutAnimation.Reset();
844 Toolkit::Internal::CheckBoxButton& checkBoxImpl = GetCheckBoxButtonImpl( checkBox );
845 Actor& fadeOutCheckedImage = checkBoxImpl.GetFadeOutCheckedImage();
846 Actor& fadeOutBackgroundImage = checkBoxImpl.GetFadeOutBackgroundImage();
850 if( fadeOutCheckedImage && fadeOutCheckedImage.GetParent() )
852 fadeOutCheckedImage.GetParent().Remove( fadeOutCheckedImage );
855 if( fadeOutBackgroundImage && fadeOutBackgroundImage.GetParent() )
857 fadeOutBackgroundImage.GetParent().Remove( fadeOutBackgroundImage );
860 fadeOutCheckedImage.Reset();
861 fadeOutBackgroundImage.Reset();
865 void CheckBoxButtonDefaultPainter::FadeInImage( Toolkit::CheckBoxButton& checkBox, Actor& image, float opacity )
869 if( !image.GetParent() )
871 checkBox.Add( image );
874 if( checkBox.GetProperty<bool>( checkBox.GetPropertyIndex( Toolkit::CheckBoxButton::USE_FADE_ANIMATION_PROPERTY_NAME ) ) )
876 image.SetOpacity( opacity );
877 AddToFadeInAnimation( image );
881 image.SetOpacity( 1.0f );
886 void CheckBoxButtonDefaultPainter::FadeOutImage( Toolkit::CheckBoxButton& checkBox, ImageLayer layer, Actor& image, float opacity )
890 Toolkit::Internal::CheckBoxButton& checkBoxImpl = GetCheckBoxButtonImpl( checkBox );
891 Actor& fadeOutCheckedImage = checkBoxImpl.GetFadeOutCheckedImage();
892 Actor& fadeOutBackgroundImage = checkBoxImpl.GetFadeOutBackgroundImage();
894 Actor& actorLayer = ( ( Background == layer ) ? fadeOutBackgroundImage : fadeOutCheckedImage );
898 if( checkBox.GetProperty<bool>( checkBox.GetPropertyIndex( Toolkit::CheckBoxButton::USE_FADE_ANIMATION_PROPERTY_NAME ) ) )
900 actorLayer.SetOpacity( opacity );
901 AddToFadeOutAnimation( actorLayer );
905 actorLayer.SetOpacity( 0.0f );
910 void CheckBoxButtonDefaultPainter::AddToCheckInAnimation( const Actor& actor )
912 if( !mCheckInAnimation )
914 mCheckInAnimation = Dali::Animation::New( mAnimationTime );
918 mCheckInAnimation.AnimateTo( Property( mTickUVEffect, mTickUVEffect.GetBottomRightPropertyName() ), Vector2( 1.0f, 1.0f ) );
921 Handle handle = actor; // Get rid of const
922 mCheckInAnimation.AnimateTo( Property( handle, mPercentageParentSizeProperty ), 1.0f );
925 void CheckBoxButtonDefaultPainter::SetupCheckedAnimation( Toolkit::CheckBoxButton& checkBox, Actor& image )
927 if( checkBox.GetProperty<bool>( checkBox.GetPropertyIndex( Toolkit::CheckBoxButton::USE_CHECK_ANIMATION_PROPERTY_NAME ) ) && image )
931 ImageActor imageActor = ImageActor::DownCast( image );
932 mTickUVEffect = ImageRegionEffect::New();
933 imageActor.SetShaderEffect( mTickUVEffect );
936 // Register a custom property to animate size of tick over
937 if( mPercentageParentSizeProperty != Property::INVALID_INDEX )
939 image.SetProperty( mPercentageParentSizeProperty, 0.0f );
942 mTickUVEffect.SetBottomRight( Vector2( 0.0f, 1.0f ) );
945 if( !image.GetParent() )
947 checkBox.Add( image );
950 AddToCheckInAnimation( image );
954 void CheckBoxButtonDefaultPainter::EndCheckOutAnimation()
956 switch( mPaintState )
958 case UncheckedCheckedTransition:
960 mPaintState = CheckedState;
963 case CheckedUncheckedTransition:
965 mPaintState = UncheckedState;
968 case UncheckedDimmedTransition:
970 mPaintState = DimmedUncheckedState;
973 case DimmedUncheckedTransition:
975 mPaintState = UncheckedState;
978 case CheckedDimmedTransition:
980 mPaintState = DimmedCheckedState;
983 case DimmedCheckedTransition:
985 mPaintState = CheckedState;
995 void CheckBoxButtonDefaultPainter::CheckOutAnimationFinished( Dali::Animation& source )
997 EndCheckOutAnimation();
999 Toolkit::CheckBoxButton handle( mButton->GetOwner() );
1000 StopCheckOutAnimation( handle );
1004 void CheckBoxButtonDefaultPainter::CheckInAnimationFinished( Dali::Animation& source )
1006 switch( mPaintState )
1008 case UncheckedCheckedTransition:
1010 mPaintState = CheckedState;
1013 case CheckedUncheckedTransition:
1015 mPaintState = UncheckedState;
1018 case UncheckedDimmedTransition:
1020 mPaintState = DimmedUncheckedState;
1023 case DimmedUncheckedTransition:
1025 mPaintState = UncheckedState;
1028 case CheckedDimmedTransition:
1030 mPaintState = DimmedCheckedState;
1033 case DimmedCheckedTransition:
1035 mPaintState = CheckedState;
1044 StopCheckInAnimation();
1047 } // namespace Internal
1049 } // namespace Toolkit