Button refactoring: rename properties
[platform/core/uifw/dali-toolkit.git] / base / dali-toolkit / internal / controls / buttons / check-box-button-default-painter-impl.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include "check-box-button-default-painter-impl.h"
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/animation/constraints.h>
23
24 // INTERNAL INCLUDES
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"
28
29 namespace Dali
30 {
31
32 namespace Toolkit
33 {
34
35 namespace Internal
36 {
37
38 namespace
39 {
40 const float FOREGROUND_DEPTH( 0.5f );
41 const float BACKGROUND_DEPTH( 0.25f );
42
43 const float ANIMATION_TIME( 0.26f );  // EFL checkbox tick time
44
45 /**
46  * Constraint to wrap an actor in y that is moving vertically
47  */
48 Vector3 EqualToPercentageWidthConstraint( const Vector3& current,
49                                           const PropertyInput& percentageProperty,
50                                           const PropertyInput& parentSizeProperty )
51 {
52   float percentage = percentageProperty.GetFloat();
53   const Vector3& parentSize = parentSizeProperty.GetVector3();
54
55   Vector3 size( parentSize );
56   size.x *= percentage;
57
58   return size;
59 }
60
61
62 inline Toolkit::Internal::CheckBoxButton& GetCheckBoxButtonImpl( Toolkit::Button& button )
63 {
64   DALI_ASSERT_ALWAYS( button );
65
66   Dali::RefObject& handle = button.GetImplementation();
67
68   return static_cast<Toolkit::Internal::CheckBoxButton&>( handle );
69 }
70
71 inline const Toolkit::Internal::CheckBoxButton& GetCheckBoxButtonImpl( const Toolkit::Button& button )
72 {
73   DALI_ASSERT_ALWAYS( button );
74
75   const Dali::RefObject& handle = button.GetImplementation();
76
77   return static_cast<const Toolkit::Internal::CheckBoxButton&>( handle );
78 }
79
80 }
81
82 CheckBoxButtonDefaultPainter::CheckBoxButtonDefaultPainter()
83 : CheckBoxButtonPainter(),
84   mDisabled( false ),
85   mPaintState( UncheckedState ),
86   mButton(NULL),
87   mAnimationTime( ANIMATION_TIME )
88 {
89 }
90
91 CheckBoxButtonDefaultPainter::~CheckBoxButtonDefaultPainter()
92 {
93   if( mCheckInAnimation )
94   {
95     mCheckInAnimation.Clear();
96   }
97   if( mCheckOutAnimation )
98   {
99     mCheckOutAnimation.Clear();
100   }
101 }
102
103 void CheckBoxButtonDefaultPainter::SetBackgroundImage( Toolkit::CheckBoxButton& checkBox, Actor image )
104 {
105   Toolkit::Internal::CheckBoxButton& checkBoxImpl = GetImplementation( checkBox );
106   Actor& backgroundImage = checkBoxImpl.GetBackgroundImage();
107   Actor& fadeOutBackgroundImage = checkBoxImpl.GetFadeOutBackgroundImage();
108
109   switch( mPaintState )
110   {
111     case UncheckedState:             // FALLTHROUGH
112     case CheckedState:
113     case UncheckedCheckedTransition:
114     case CheckedUncheckedTransition:
115     {
116       if( backgroundImage && backgroundImage.GetParent() )
117       {
118         StopCheckOutAnimation( checkBox );
119         FadeOutImage( checkBox, Background, backgroundImage  );
120
121         backgroundImage = image;
122
123         FadeInImage( checkBox, backgroundImage );
124
125         StartCheckOutAnimation( checkBox );
126         StartCheckInAnimation();
127       }
128       else
129       {
130         backgroundImage = image;
131         checkBox.Add( backgroundImage );
132       }
133       break;
134     }
135     case DisabledUncheckedTransition: // FALLTHROUGH
136     case DisabledCheckedTransition:
137     {
138       StopCheckInAnimation();
139       checkBox.Remove( backgroundImage );
140
141       backgroundImage = image;
142
143       FadeInImage( checkBox, backgroundImage );
144       StartCheckInAnimation();
145       break;
146     }
147     case CheckedDisabledTransition:   // FALLTHROUGH
148     case UncheckedDisabledTransition:
149     {
150       float opacity = 1.f;
151       if( fadeOutBackgroundImage )
152       {
153         opacity = fadeOutBackgroundImage.GetCurrentOpacity();
154       }
155       StopCheckOutAnimation( checkBox );
156
157       // Replaces the button image.
158       backgroundImage = image;
159
160       checkBox.Add( backgroundImage );
161       FadeOutImage( checkBox, Background, backgroundImage, opacity );
162
163       StartCheckOutAnimation( checkBox );
164       break;
165     }
166     default:
167     {
168       backgroundImage = image;
169       break;
170     }
171   }
172
173   backgroundImage.SetAnchorPoint( AnchorPoint::TOP_LEFT );
174   backgroundImage.SetParentOrigin( ParentOrigin::TOP_LEFT );
175   ApplyConstraint( backgroundImage, BACKGROUND_DEPTH );
176 }
177
178 void CheckBoxButtonDefaultPainter::SetCheckedImage( Toolkit::CheckBoxButton& checkBox, Actor image )
179 {
180   Toolkit::Internal::CheckBoxButton& checkBoxImpl = GetImplementation( checkBox );
181   Actor& checkedImage = checkBoxImpl.GetCheckedImage();
182   Actor& fadeOutCheckedImage = checkBoxImpl.GetFadeOutCheckedImage();
183
184   switch( mPaintState )
185   {
186     case CheckedState:
187     {
188       if( checkedImage && checkedImage.GetParent() )
189       {
190         StopCheckOutAnimation( checkBox );
191         FadeOutImage( checkBox, Foreground, checkedImage );
192
193         checkedImage = image;
194
195         FadeInImage( checkBox, checkedImage );
196
197         StartCheckOutAnimation( checkBox );
198         StartCheckInAnimation();
199       }
200       else
201       {
202         checkedImage = image;
203         checkBox.Add( checkedImage );
204       }
205       break;
206     }
207     case UncheckedCheckedTransition: // FALLTHROUGH
208     case DisabledCheckedTransition:
209     {
210       StopCheckInAnimation();
211       checkBox.Remove( checkedImage );
212
213       checkedImage = image;
214
215       FadeInImage( checkBox, checkedImage );
216       StartCheckInAnimation();
217       break;
218     }
219     case CheckedUncheckedTransition: // FALLTHROUGH
220     case CheckedDisabledTransition:
221     {
222       float opacity = 1.f;
223       if( fadeOutCheckedImage )
224       {
225         opacity = fadeOutCheckedImage.GetCurrentOpacity();
226       }
227       StopCheckOutAnimation( checkBox );
228
229       // Replaces the button image.
230       checkedImage = image;
231
232       checkBox.Add( checkedImage );
233       FadeOutImage( checkBox, Foreground, checkedImage, opacity );
234
235       StartCheckOutAnimation( checkBox );
236       break;
237     }
238     default:
239     {
240       checkedImage = image;
241       break;
242     }
243     }
244
245   checkedImage.SetAnchorPoint( AnchorPoint::TOP_LEFT );
246   checkedImage.SetParentOrigin( ParentOrigin::TOP_LEFT );
247   ApplyCheckedConstraint( checkedImage, FOREGROUND_DEPTH );
248 }
249
250 void CheckBoxButtonDefaultPainter::SetDisabledCheckedImage( Toolkit::CheckBoxButton& checkBox, Actor image )
251 {
252   Toolkit::Internal::CheckBoxButton& checkBoxImpl = GetImplementation( checkBox );
253   Actor& disabledCheckedImage = checkBoxImpl.GetDisabledCheckedImage();
254   Actor& fadeOutCheckedImage = checkBoxImpl.GetFadeOutCheckedImage();
255
256   switch( mPaintState )
257   {
258     case DisabledCheckedState:
259     {
260       if( disabledCheckedImage && disabledCheckedImage.GetParent() )
261       {
262         StopCheckOutAnimation( checkBox );
263         FadeOutImage( checkBox, Foreground, disabledCheckedImage );
264
265         disabledCheckedImage = image;
266
267         FadeInImage( checkBox, disabledCheckedImage );
268
269         StartCheckOutAnimation( checkBox );
270         StartCheckInAnimation();
271       }
272       else
273       {
274         disabledCheckedImage = image;
275         checkBox.Add( disabledCheckedImage );
276       }
277       break;
278     }
279     case CheckedDisabledTransition:
280     {
281       StopCheckInAnimation();
282       checkBox.Remove( disabledCheckedImage );
283
284       disabledCheckedImage = image;
285
286       FadeInImage( checkBox, disabledCheckedImage );
287       StartCheckInAnimation();
288       break;
289     }
290     case DisabledCheckedTransition:
291     {
292       float opacity = 1.f;
293       if( fadeOutCheckedImage )
294       {
295         opacity = fadeOutCheckedImage.GetCurrentOpacity();
296       }
297       StopCheckOutAnimation( checkBox );
298
299       // Replaces the button image.
300       disabledCheckedImage = image;
301
302       checkBox.Add( disabledCheckedImage );
303       FadeOutImage( checkBox, Foreground, disabledCheckedImage, opacity );
304
305       StartCheckOutAnimation( checkBox );
306       break;
307     }
308     default:
309     {
310       disabledCheckedImage = image;
311       break;
312     }
313   }
314
315   disabledCheckedImage.SetAnchorPoint( AnchorPoint::TOP_LEFT );
316   disabledCheckedImage.SetParentOrigin( ParentOrigin::TOP_LEFT );
317   ApplyConstraint( disabledCheckedImage, FOREGROUND_DEPTH );
318 }
319
320 void CheckBoxButtonDefaultPainter::SetDisabledBackgroundImage( Toolkit::CheckBoxButton& checkBox, Actor image )
321 {
322   Toolkit::Internal::CheckBoxButton& checkBoxImpl = GetImplementation( checkBox );
323   Actor& disabledBackgroundImage = checkBoxImpl.GetDisabledBackgroundImage();
324   Actor& fadeOutBackgroundImage = checkBoxImpl.GetFadeOutBackgroundImage();
325
326   switch( mPaintState )
327   {
328     case DisabledCheckedState:   // FALLTHROUGH
329     case DisabledUncheckedState:
330     {
331       if( disabledBackgroundImage && disabledBackgroundImage.GetParent() )
332       {
333         StopCheckOutAnimation( checkBox );
334         FadeOutImage( checkBox, Background, disabledBackgroundImage  );
335
336         disabledBackgroundImage = image;
337
338         FadeInImage( checkBox, disabledBackgroundImage );
339
340         StartCheckOutAnimation( checkBox );
341         StartCheckInAnimation();
342       }
343       else
344       {
345         disabledBackgroundImage = image;
346         checkBox.Add( disabledBackgroundImage );
347       }
348       break;
349     }
350     case UncheckedDisabledTransition: // FALLTHROUGH
351     case CheckedDisabledTransition:
352     {
353       StopCheckInAnimation();
354       checkBox.Remove( disabledBackgroundImage );
355
356       disabledBackgroundImage = image;
357
358       FadeInImage( checkBox, disabledBackgroundImage );
359       StartCheckInAnimation();
360       break;
361     }
362     case DisabledUncheckedTransition: // FALLTHROUGH
363     case DisabledCheckedTransition:
364     {
365       float opacity = 1.f;
366       if( fadeOutBackgroundImage )
367       {
368         opacity = fadeOutBackgroundImage.GetCurrentOpacity();
369       }
370       StopCheckOutAnimation( checkBox );
371
372       // Replaces the button image.
373       disabledBackgroundImage = image;
374
375       checkBox.Add( disabledBackgroundImage );
376       FadeOutImage( checkBox, Background, disabledBackgroundImage, opacity );
377
378       StartCheckOutAnimation( checkBox );
379       break;
380     }
381     default:
382     {
383       disabledBackgroundImage = image;
384       break;
385     }
386   }
387
388   disabledBackgroundImage.SetAnchorPoint( AnchorPoint::TOP_LEFT );
389   disabledBackgroundImage.SetParentOrigin( ParentOrigin::TOP_LEFT );
390   ApplyConstraint( disabledBackgroundImage, BACKGROUND_DEPTH );
391 }
392
393 void CheckBoxButtonDefaultPainter::Initialize( Toolkit::Button& button )
394 {
395   Toolkit::Internal::CheckBoxButton& buttonImpl = GetCheckBoxButtonImpl( button );
396   Actor& backgroundImage = buttonImpl.GetBackgroundImage();
397   Actor& checkedImage = buttonImpl.GetCheckedImage();
398   Actor& disabledBackgroundImage = buttonImpl.GetDisabledBackgroundImage();
399   Actor& disabledCheckedImage = buttonImpl.GetDisabledCheckedImage();
400
401   Toolkit::CheckBoxButton& checkBox = static_cast<Toolkit::CheckBoxButton&>( button );
402
403   if( backgroundImage )
404   {
405     SetBackgroundImage( checkBox, backgroundImage );
406   }
407
408   if( checkedImage )
409   {
410     SetCheckedImage( checkBox, checkedImage );
411   }
412
413   if( disabledBackgroundImage )
414   {
415     SetDisabledBackgroundImage( checkBox, disabledBackgroundImage );
416   }
417
418   if( disabledCheckedImage )
419   {
420     SetDisabledCheckedImage( checkBox, disabledCheckedImage );
421   }
422
423   SetDisabled( button, mDisabled );
424 }
425
426 void CheckBoxButtonDefaultPainter::SetSize( Toolkit::Button& button, const Vector3& size )
427 {
428   Toolkit::Internal::CheckBoxButton& buttonImpl = GetCheckBoxButtonImpl( button );
429   Actor& backgroundImage = buttonImpl.GetBackgroundImage();
430   Actor& checkedImage = buttonImpl.GetCheckedImage();
431   Actor& disabledBackgroundImage = buttonImpl.GetDisabledBackgroundImage();
432   Actor& disabledCheckedImage = buttonImpl.GetDisabledCheckedImage();
433
434   ApplyCheckedConstraint( checkedImage, FOREGROUND_DEPTH );
435   ApplyConstraint( backgroundImage, BACKGROUND_DEPTH );
436   ApplyConstraint( disabledCheckedImage, FOREGROUND_DEPTH );
437   ApplyConstraint( disabledBackgroundImage, BACKGROUND_DEPTH );
438 }
439
440 void CheckBoxButtonDefaultPainter::SetDisabled( Toolkit::Button& button, bool disabled )
441 {
442   mDisabled = disabled;
443
444   Toolkit::Internal::CheckBoxButton& buttonImpl = GetCheckBoxButtonImpl( button );
445   Actor& backgroundImage = buttonImpl.GetBackgroundImage();
446   Actor& checkedImage = buttonImpl.GetCheckedImage();
447   Actor& disabledBackgroundImage = buttonImpl.GetDisabledBackgroundImage();
448   Actor& disabledCheckedImage = buttonImpl.GetDisabledCheckedImage();
449   Actor& fadeOutCheckedImage = buttonImpl.GetFadeOutCheckedImage();
450   Actor& fadeOutBackgroundImage = buttonImpl.GetFadeOutBackgroundImage();
451
452   Toolkit::CheckBoxButton& checkBox = static_cast<Toolkit::CheckBoxButton&>( button );
453
454   switch( mPaintState )
455   {
456     case UncheckedState:
457     {
458       if( disabled )
459       {
460         StopCheckOutAnimation( checkBox );
461         FadeOutImage( checkBox, Background, backgroundImage );
462         FadeInImage( checkBox, disabledBackgroundImage );
463         StartCheckOutAnimation( checkBox );
464         StartCheckInAnimation();
465
466         mPaintState = UncheckedDisabledTransition;
467       }
468       break;
469     }
470     case CheckedState:
471     {
472       if( disabled )
473       {
474         StopCheckOutAnimation( checkBox );
475         FadeOutImage( checkBox, Background, backgroundImage );
476         FadeOutImage( checkBox, Foreground, checkedImage );
477         FadeInImage( checkBox, disabledCheckedImage );
478         FadeInImage( checkBox, disabledBackgroundImage );
479         StartCheckOutAnimation( checkBox );
480         StartCheckInAnimation();
481
482         mPaintState = CheckedDisabledTransition;
483       }
484       break;
485     }
486     case DisabledUncheckedState:
487     {
488       if( !disabled )
489       {
490         StopCheckOutAnimation( checkBox );
491         FadeOutImage( checkBox, Background, disabledBackgroundImage );
492         FadeInImage( checkBox, backgroundImage );
493         StartCheckOutAnimation( checkBox );
494         StartCheckInAnimation();
495
496         mPaintState = DisabledUncheckedTransition;
497       }
498       break;
499     }
500     case DisabledCheckedState:
501     {
502       if( !disabled )
503       {
504         StopCheckOutAnimation( checkBox );
505         FadeOutImage( checkBox, Background, disabledBackgroundImage );
506         FadeOutImage( checkBox, Foreground, disabledCheckedImage );
507         FadeInImage( checkBox, backgroundImage );
508         FadeInImage( checkBox, checkedImage );
509         StartCheckOutAnimation( checkBox );
510         StartCheckInAnimation();
511
512         mPaintState = DisabledCheckedTransition;
513       }
514       break;
515     }
516     case UncheckedCheckedTransition:
517     {
518       if( disabled )
519       {
520         float opacity = 1.f;
521         if( checkedImage )
522         {
523           opacity = checkedImage.GetCurrentOpacity();
524         }
525         StopCheckOutAnimation( checkBox );
526         StopCheckInAnimation();
527
528         FadeOutImage( checkBox, Foreground, checkedImage, opacity );
529         FadeOutImage( checkBox, Background, backgroundImage );
530
531         FadeInImage( checkBox, disabledCheckedImage );
532         FadeInImage( checkBox, disabledBackgroundImage );
533
534         StartCheckOutAnimation( checkBox );
535         StartCheckInAnimation();
536
537         mPaintState = CheckedDisabledTransition;
538       }
539       break;
540     }
541     case CheckedUncheckedTransition:
542     {
543       if( disabled )
544       {
545         float opacity = 1.f;
546         if( fadeOutCheckedImage )
547         {
548           opacity = fadeOutCheckedImage.GetCurrentOpacity();
549         }
550         StopCheckOutAnimation( checkBox );
551         StopCheckInAnimation();
552
553         button.Add( disabledCheckedImage );
554         FadeOutImage( checkBox, Foreground, disabledCheckedImage, opacity );
555         FadeOutImage( checkBox, Background, backgroundImage );
556
557         FadeInImage( checkBox, disabledBackgroundImage );
558
559         StartCheckOutAnimation( checkBox );
560         StartCheckInAnimation();
561
562         mPaintState = UncheckedDisabledTransition;
563       }
564       break;
565     }
566     case UncheckedDisabledTransition:
567     {
568       if( !disabled )
569       {
570         float opacity = 1.f;
571         if( fadeOutBackgroundImage )
572         {
573           opacity = fadeOutBackgroundImage.GetCurrentOpacity();
574         }
575         StopCheckOutAnimation( checkBox, false );
576         StopCheckInAnimation();
577
578         FadeOutImage( checkBox, Background, disabledBackgroundImage, 1.f - opacity );
579         FadeInImage( checkBox, backgroundImage, opacity );
580
581         StartCheckOutAnimation( checkBox );
582         StartCheckInAnimation();
583
584         mPaintState = DisabledUncheckedTransition;
585       }
586       break;
587     }
588     case DisabledUncheckedTransition:
589     {
590       if( disabled )
591       {
592         float opacity = 1.f;
593         if( fadeOutBackgroundImage )
594         {
595           opacity = fadeOutBackgroundImage.GetCurrentOpacity();
596         }
597         StopCheckOutAnimation( checkBox, false );
598         StopCheckInAnimation();
599
600         FadeOutImage( checkBox, Background, backgroundImage, 1.f - opacity );
601         FadeInImage( checkBox, disabledBackgroundImage, opacity );
602
603         StartCheckOutAnimation( checkBox );
604         StartCheckInAnimation();
605
606         mPaintState = UncheckedDisabledTransition;
607       }
608       break;
609     }
610     case CheckedDisabledTransition:
611     {
612       if( !disabled )
613       {
614         float opacity = 1.f;
615         if( fadeOutBackgroundImage )
616         {
617           opacity = fadeOutBackgroundImage.GetCurrentOpacity();
618         }
619         StopCheckOutAnimation( checkBox, false );
620         StopCheckInAnimation();
621
622         FadeOutImage( checkBox, Foreground, disabledCheckedImage, 1.f - opacity );
623         FadeOutImage( checkBox, Background, disabledBackgroundImage, 1.f - opacity );
624         FadeInImage( checkBox, checkedImage, opacity );
625         FadeInImage( checkBox, backgroundImage, opacity );
626
627         StartCheckOutAnimation( checkBox );
628         StartCheckInAnimation();
629
630         mPaintState = DisabledCheckedTransition;
631       }
632       break;
633     }
634     case DisabledCheckedTransition:
635     {
636       if( disabled )
637       {
638         float opacity = 1.f;
639         if( fadeOutBackgroundImage )
640         {
641           opacity = fadeOutBackgroundImage.GetCurrentOpacity();
642         }
643         StopCheckOutAnimation( checkBox, false );
644         StopCheckInAnimation();
645
646         FadeOutImage( checkBox, Foreground, checkedImage, 1.f - opacity );
647         FadeOutImage( checkBox, Background, backgroundImage, 1.f - opacity );
648         FadeInImage( checkBox, disabledCheckedImage, opacity );
649         FadeInImage( checkBox, disabledBackgroundImage, opacity );
650
651         StartCheckOutAnimation( checkBox );
652         StartCheckInAnimation();
653
654         mPaintState = CheckedDisabledTransition;
655       }
656       break;
657     }
658     default:
659       break;
660   }
661 }
662
663 void CheckBoxButtonDefaultPainter::SetAnimationTime( float animationTime )
664 {
665   mAnimationTime = animationTime;
666 }
667
668 float CheckBoxButtonDefaultPainter::GetAnimationTime() const
669 {
670   return mAnimationTime;
671 }
672
673 void CheckBoxButtonDefaultPainter::Checked( Toolkit::CheckBoxButton& button )
674 {
675   Toolkit::Internal::CheckBoxButton& checkBoxImpl = GetCheckBoxButtonImpl( button );
676   Actor& checkedImage = checkBoxImpl.GetCheckedImage();
677   Actor& fadeOutCheckedImage = checkBoxImpl.GetFadeOutCheckedImage();
678
679   switch( mPaintState )
680   {
681     case UncheckedState:
682     {
683       // Fade in the 'check' actor.
684       FadeInImage( button, checkedImage );
685       SetupCheckedAnimation( button, checkedImage );    // Animate in the check actor
686       StartCheckInAnimation();
687
688       mPaintState = UncheckedCheckedTransition;
689       break;
690     }
691     case CheckedState:
692     {
693       // Fade out the 'check' actor.
694       StopCheckOutAnimation( button );
695       FadeOutImage( button, Foreground, checkedImage );
696       StartCheckOutAnimation( button );
697
698       mPaintState = UncheckedState;
699       break;
700     }
701     case UncheckedCheckedTransition:
702     {
703       // Stop fade in and start fade out.
704       StopCheckOutAnimation( button );
705       StopCheckInAnimation();
706
707       float opacity = 0.f;
708       if( checkedImage )
709       {
710         opacity = checkedImage.GetCurrentOpacity();
711       }
712       FadeOutImage( button, Foreground, checkedImage, opacity );
713       StartCheckOutAnimation( button );
714
715       mPaintState = UncheckedState;
716       break;
717     }
718     case CheckedUncheckedTransition:
719     {
720       // Stop fade out and start fade in.
721       float opacity = 1.f;
722       if( fadeOutCheckedImage )
723       {
724         opacity = fadeOutCheckedImage.GetCurrentOpacity();
725       }
726       StopCheckOutAnimation( button );
727
728       FadeInImage( button, checkedImage, opacity );
729       StartCheckInAnimation();
730
731       mPaintState = UncheckedCheckedTransition;
732       break;
733     }
734     default:
735       break;
736   }
737 }
738
739 void CheckBoxButtonDefaultPainter::ApplyConstraint( Actor& actor, float depth )
740 {
741   if( actor )
742   {
743     actor.RemoveConstraints();
744     actor.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
745     actor.SetZ( depth );
746   }
747 }
748
749 void CheckBoxButtonDefaultPainter::ApplyCheckedConstraint( Actor& actor, float depth )
750 {
751   if( actor )
752   {
753     actor.RemoveConstraints();
754     actor.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
755     actor.SetZ( depth );
756   }
757 }
758
759 void CheckBoxButtonDefaultPainter::AddToFadeInAnimation( const Actor& actor )
760 {
761   if( !mCheckInAnimation )
762   {
763     mCheckInAnimation = Dali::Animation::New( mAnimationTime  );
764   }
765
766   mCheckInAnimation.OpacityTo( actor, 1.f );
767
768 }
769
770 void CheckBoxButtonDefaultPainter::StartCheckInAnimation()
771 {
772   if( mCheckInAnimation )
773   {
774     mCheckInAnimation.FinishedSignal().Connect( this, &CheckBoxButtonDefaultPainter::CheckInAnimationFinished );
775     mCheckInAnimation.Play();
776   }
777 }
778
779 void CheckBoxButtonDefaultPainter::StopCheckInAnimation()
780 {
781   if( mCheckInAnimation )
782   {
783     mCheckInAnimation.Clear();
784     mCheckInAnimation.Reset();
785   }
786 }
787
788 void CheckBoxButtonDefaultPainter::AddToFadeOutAnimation( const Actor& actor )
789 {
790   if( !mCheckOutAnimation )
791   {
792     mCheckOutAnimation = Dali::Animation::New( mAnimationTime );
793   }
794
795   mCheckOutAnimation.OpacityTo( actor, 0.f );
796 }
797
798 void CheckBoxButtonDefaultPainter::StartCheckOutAnimation( Toolkit::CheckBoxButton& checkBox )
799 {
800   if( mCheckOutAnimation )
801   {
802     Toolkit::Internal::CheckBoxButton& checkBoxImpl = GetCheckBoxButtonImpl( checkBox );
803     mButton = &checkBoxImpl;
804
805     mCheckOutAnimation.FinishedSignal().Connect( this, &CheckBoxButtonDefaultPainter::CheckOutAnimationFinished );
806     mCheckOutAnimation.Play();
807   }
808 }
809
810 void CheckBoxButtonDefaultPainter::StopCheckOutAnimation( Toolkit::CheckBoxButton& checkBox, bool remove )
811 {
812   if( mCheckOutAnimation )
813   {
814     mCheckOutAnimation.Clear();
815     mCheckOutAnimation.Reset();
816   }
817
818   Toolkit::Internal::CheckBoxButton& checkBoxImpl = GetCheckBoxButtonImpl( checkBox );
819   Actor& fadeOutCheckedImage = checkBoxImpl.GetFadeOutCheckedImage();
820   Actor& fadeOutBackgroundImage = checkBoxImpl.GetFadeOutBackgroundImage();
821
822   if( remove )
823   {
824     if( fadeOutCheckedImage && fadeOutCheckedImage.GetParent() )
825     {
826       fadeOutCheckedImage.GetParent().Remove( fadeOutCheckedImage );
827     }
828
829     if( fadeOutBackgroundImage && fadeOutBackgroundImage.GetParent() )
830     {
831       fadeOutBackgroundImage.GetParent().Remove( fadeOutBackgroundImage );
832     }
833
834     fadeOutCheckedImage.Reset();
835     fadeOutBackgroundImage.Reset();
836   }
837 }
838
839 void CheckBoxButtonDefaultPainter::FadeInImage( Toolkit::CheckBoxButton& checkBox, Actor& image, float opacity )
840 {
841   if( image )
842   {
843     if( !image.GetParent() )
844     {
845       checkBox.Add( image );
846     }
847
848     image.SetOpacity( 1.0f );
849   }
850 }
851
852 void CheckBoxButtonDefaultPainter::FadeOutImage( Toolkit::CheckBoxButton& checkBox, ImageLayer layer, Actor& image, float opacity )
853 {
854   if( image )
855   {
856     Toolkit::Internal::CheckBoxButton& checkBoxImpl = GetCheckBoxButtonImpl( checkBox );
857     Actor& fadeOutCheckedImage = checkBoxImpl.GetFadeOutCheckedImage();
858     Actor& fadeOutBackgroundImage = checkBoxImpl.GetFadeOutBackgroundImage();
859
860     Actor& actorLayer = ( ( Background == layer ) ? fadeOutBackgroundImage : fadeOutCheckedImage );
861
862     actorLayer = image;
863
864     actorLayer.SetOpacity( 0.0f );
865   }
866 }
867
868 void CheckBoxButtonDefaultPainter::AddToCheckInAnimation( const Actor& actor )
869 {
870   if( !mCheckInAnimation )
871   {
872     mCheckInAnimation = Dali::Animation::New( mAnimationTime  );
873   }
874
875   // UV anim
876   mCheckInAnimation.AnimateTo( Property( mTickUVEffect, mTickUVEffect.GetBottomRightPropertyName() ), Vector2( 1.0f, 1.0f ) );
877
878   // Actor size anim
879   Handle handle = actor; // Get rid of const
880   mCheckInAnimation.AnimateTo( Property( handle, Actor::SCALE_X ), 1.0f);
881 }
882
883 void CheckBoxButtonDefaultPainter::SetupCheckedAnimation( Toolkit::CheckBoxButton& checkBox, Actor& image )
884 {
885   if( image )
886   {
887     if( !mTickUVEffect )
888     {
889       ImageActor imageActor = ImageActor::DownCast( image );
890       mTickUVEffect = ImageRegionEffect::New();
891       imageActor.SetShaderEffect( mTickUVEffect );
892     }
893
894     image.SetScale( Vector3( 0.0f, 1.0f, 1.0f ) );
895
896     mTickUVEffect.SetBottomRight( Vector2( 0.0f, 1.0f ) );
897
898     // Parent
899     if( !image.GetParent() )
900     {
901       checkBox.Add( image );
902     }
903
904     AddToCheckInAnimation( image );
905   }
906 }
907
908 void CheckBoxButtonDefaultPainter::EndCheckOutAnimation()
909 {
910   switch( mPaintState )
911   {
912     case UncheckedCheckedTransition:
913     {
914       mPaintState = CheckedState;
915       break;
916     }
917     case CheckedUncheckedTransition:
918     {
919       mPaintState = UncheckedState;
920       break;
921     }
922     case UncheckedDisabledTransition:
923     {
924       mPaintState = DisabledUncheckedState;
925       break;
926     }
927     case DisabledUncheckedTransition:
928     {
929       mPaintState = UncheckedState;
930       break;
931     }
932     case CheckedDisabledTransition:
933     {
934       mPaintState = DisabledCheckedState;
935       break;
936     }
937     case DisabledCheckedTransition:
938     {
939       mPaintState = CheckedState;
940       break;
941     }
942     default:
943     {
944       break;
945     }
946   }
947 }
948
949 void CheckBoxButtonDefaultPainter::CheckOutAnimationFinished( Dali::Animation& source )
950 {
951   EndCheckOutAnimation();
952
953   Toolkit::CheckBoxButton handle( mButton->GetOwner() );
954   StopCheckOutAnimation( handle );
955   mButton = NULL;
956 }
957
958 void CheckBoxButtonDefaultPainter::CheckInAnimationFinished( Dali::Animation& source )
959 {
960   switch( mPaintState )
961   {
962     case UncheckedCheckedTransition:
963     {
964       mPaintState = CheckedState;
965       break;
966     }
967     case CheckedUncheckedTransition:
968     {
969       mPaintState = UncheckedState;
970       break;
971     }
972     case UncheckedDisabledTransition:
973     {
974       mPaintState = DisabledUncheckedState;
975       break;
976     }
977     case DisabledUncheckedTransition:
978     {
979       mPaintState = UncheckedState;
980       break;
981     }
982     case CheckedDisabledTransition:
983     {
984       mPaintState = DisabledCheckedState;
985       break;
986     }
987     case DisabledCheckedTransition:
988     {
989       mPaintState = CheckedState;
990       break;
991     }
992     default:
993     {
994       break;
995     }
996   }
997
998   StopCheckInAnimation();
999 }
1000
1001 } // namespace Internal
1002
1003 } // namespace Toolkit
1004
1005 } // namespace Dali