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