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