Merge "Typo fixed in Control implementation doc." into tizen
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / buttons / check-box-button-default-painter-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_CHECK_BOX_BUTTON_DEFAULT_PAINTER_H__
2 #define __DALI_TOOLKIT_INTERNAL_CHECK_BOX_BUTTON_DEFAULT_PAINTER_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/images/image.h>
23 #include <dali/public-api/actors/actor.h>
24 #include <dali/public-api/math/vector2.h>
25 #include <dali/public-api/animation/animation.h>
26 #include <dali-toolkit/public-api/shader-effects/image-region-effect.h>
27
28 #include "check-box-button-painter-impl.h"
29
30 namespace Dali
31 {
32
33 namespace Toolkit
34 {
35
36 namespace Internal
37 {
38
39 // Forward declarations
40
41 class CheckBoxButton;
42 class CheckBoxButtonDefaultPainter;
43
44 // Type definitions
45
46 typedef IntrusivePtr<CheckBoxButtonDefaultPainter> CheckBoxButtonDefaultPainterPtr;
47
48 /**
49  * CheckBoxButtonDefaultPainter controls the Dali::Toolkit::CheckBoxButton appearance.
50  *
51  * This class inherits from Dali::Toolkit::Internal::CheckBoxButtonPainter and is registered in a
52  * Dali::Toolkit::Internal::CheckBoxButton object in order to receive the state changes.
53  */
54 class CheckBoxButtonDefaultPainter : public CheckBoxButtonPainter
55 {
56 public:
57   /**
58    * Constructor.
59    *
60    * Set actors and animations to NULL.
61    */
62   CheckBoxButtonDefaultPainter();
63
64   /**
65    * Destructor.
66    *
67    * It clears all fade in or fade out animations.
68    */
69   ~CheckBoxButtonDefaultPainter();
70
71   /////////////////////////////////////////////////////////////////////////////
72   // ButtonPainter interface
73   /////////////////////////////////////////////////////////////////////////////
74
75   /**
76    * @copydoc ButtonPainter::Initialize( Toolkit::Button& button )
77    */
78   virtual void Initialize( Toolkit::Button& button );
79
80   /**
81    * @copydoc ButtonPainter::SetSize( Toolkit::Button& button, const Vector3& size )
82    */
83   virtual void SetSize( Toolkit::Button& button, const Vector3& size );
84
85   /**
86    * @copydoc ButtonPainter::SetDisabled( Toolkit::Button& button, bool disabled )
87    */
88   virtual void SetDisabled( Toolkit::Button& button, bool disabled );
89
90   /**
91    * @copydoc ButtonPainter::SetAnimationTime( float animationTime )
92    */
93   virtual void SetAnimationTime( float animationTime );
94
95   /**
96    * @copydoc ButtonPainter::GetAnimationTime()
97    */
98   virtual float GetAnimationTime() const;
99
100   /**
101    * @copydoc ButtonPainter::SetSelectedImage( Toolkit::Button& button, Actor image )
102    */
103   virtual void SetSelectedImage( Toolkit::Button& button, Actor image );
104
105   /**
106    * @copydoc ButtonPainter::SetBackgroundImage( Toolkit::Button& button, Actor image )
107    */
108   virtual void SetBackgroundImage( Toolkit::Button& button, Actor image );
109
110   /**
111    * @copydoc ButtonPainter::SetDisabledSelectedImage( Toolkit::Button& button, Actor image )
112    */
113   virtual void SetDisabledSelectedImage( Toolkit::Button& button, Actor image );
114
115   /**
116    * @copydoc ButtonPainter::SetDisabledBackgroundImage( Toolkit::Button& button, Actor image )
117    */
118   virtual void SetDisabledBackgroundImage( Toolkit::Button& button, Actor image );
119
120   /////////////////////////////////////////////////////////////////////////////
121   // CheckBoxButtonPainter interface
122   /////////////////////////////////////////////////////////////////////////////
123
124   /**
125    * This method is called when the Dali::Toolkit::Internal::CheckBoxButton in which this object is registered
126    * changes its state.
127    *
128    * @param[inout] checkBox The Dali::Toolkit::CheckBoxButton in which this object is registered.
129    */
130   void Selected( Toolkit::Button& checkBox );
131
132 private:
133
134   // Undefined
135   CheckBoxButtonDefaultPainter( const CheckBoxButtonDefaultPainter& );
136
137   // Undefined
138   CheckBoxButtonDefaultPainter& operator=( const CheckBoxButtonDefaultPainter& );
139
140 private:
141
142   /**
143    * Default check box button painter states.
144    */
145   enum PaintState
146   {
147     UnselectedState,              ///< The check box button is unselected.
148     SelectedState,                ///< The check box button is selected.
149     DisabledUnselectedState,      ///< The check box button is disabled and unselected.
150     DisabledSelectedState,        ///< The check box button is disabled and selected.
151     UnselectedSelectedTransition, ///< The check box button is in transition from unselected to selected.
152     SelectedUnselectedTransition, ///< The check box button is in transition from selected to unselected.
153     UnselectedDisabledTransition, ///< The check box button is in transition from unselected to disabled.
154     DisabledUnselectedTransition, ///< The check box button is in transition from disabled to unselected.
155     SelectedDisabledTransition,   ///< The check box button is in transition from selected to disabled.
156     DisabledSelectedTransition    ///< The check box button is in transition from disabled to selected.
157   };
158
159   /**
160    * Used in the FadeOut functions.
161    */
162   enum ImageLayer
163   {
164     Background, ///< Fade out the background.
165     Foreground  ///< Fade out the foreground.
166   };
167
168 private:
169   /**
170    * Apply size and position constraints to painter actors.
171    *
172    * @param[inout] actor The actor.
173    * @param[in] depth Depth position.
174    */
175   void ApplyConstraint( Actor& actor, float depth );
176
177   /**
178    * Apply size constraint to check tick
179    *
180    * @param[inout] actor The actor.
181    * @param[in] depth Depth position.
182    */
183   void ApplySelectedConstraint( Actor& actor, float depth );
184
185   /**
186    * Adds the actor to the fade in animation. It creates a fade in animation if needed.
187    *
188    * @param[in] actor The actor.
189    */
190   void AddToFadeInAnimation( const Actor& actor );
191
192   /**
193    * Starts the check in animation.
194    *
195    * CheckBoxButtonDefaultPainter::CheckInAnimationFinished slot is called when the animation finishes.
196    */
197   void StartCheckInAnimation();
198
199   /**
200    * Stops the check in animation.
201    */
202   void StopCheckInAnimation();
203
204   /**
205    * Adds the actor to the fade out animation. It creates a fade out animation if needed.
206    *
207    * @param[in] actor The actor.
208    */
209   void AddToFadeOutAnimation( const Actor& actor );
210
211   /**
212    * Starts the check out animation.
213    *
214    * CheckBoxButtonDefaultPainter::CheckOutAnimationFinished slot is called when the animation finishes.
215    *
216    * @param[inout] checkBox The button which holds images.
217    */
218   void StartCheckOutAnimation( Toolkit::CheckBoxButton& checkBox );
219
220   /**
221    * Stops the fade out animation.
222    *
223    * It removes the actor stored in CheckBoxButtonDefaultPainter::mFadeOutBackgroundImage and
224    * CheckBoxButtonDefaultPainter::mFadeOutSelectedImage.
225    *
226    * @param[inout] checkBox The button which holds images.
227    * @param[in] remove If true, removes the fadeout actor from root.
228    */
229   void StopCheckOutAnimation( Toolkit::CheckBoxButton& checkBox, bool remove = true );
230
231   /**
232    * It adds the actor to the root actor and to the fade in animation.
233    *
234    * @param[inout] checkBox The button which holds images.
235    * @param[inout] image The actor.
236    * @param[in] opacity The initial opacity.
237    */
238   void FadeInImage( Toolkit::CheckBoxButton& checkBox, Actor& image, float opacity = 0.f );
239
240   /**
241    * It adds the actor fade out animation and stores it to be removed when the animation finishes.
242    *
243    * @param[inout] checkBox The button which holds images.
244    * @param[in] layer Defines if the actor is going to be stored in the mFadeOutBackgroundImage or mFadeOutSelectedImage member.
245    * @param[inout] image The actor.
246    * @param[in] opacity The initial opacity.
247    */
248   void FadeOutImage( Toolkit::CheckBoxButton& checkBox, ImageLayer layer, Actor& image, float opacity = 1.f );
249
250   /**
251    * Adds the actor to the fade in animation. It creates a fade in animation if needed.
252    *
253    * @param[in] actor The actor.
254    */
255   void AddToCheckInAnimation( const Actor& actor );
256
257   /**
258    * It adds the actor to the root actor and to the fade in animation.
259    *
260    * @param[inout] checkBox The button which holds images.
261    * @param[inout] image The actor.
262    */
263   void SetupSelectedAnimation( Toolkit::CheckBoxButton& checkBox, Actor& image );
264
265   /**
266    * Signal end of check out animation
267    */
268   void EndCheckOutAnimation();
269
270   // slots
271
272   /**
273    * Called when the fade out animation finishes.
274    *
275    * It changes the check button painter state and removes actors from the root.
276    */
277   void CheckOutAnimationFinished( Dali::Animation& source );
278
279   /**
280    * Called when the fade in animation finishes.
281    *
282    * It changes the check button painter state.
283    */
284   void CheckInAnimationFinished( Dali::Animation& source );
285
286 private:
287   bool                      mDisabled;           ///< Stores the disabled property.
288
289   PaintState                mPaintState;       ///< The painter state.
290
291   Animation                 mCheckInAnimation;  ///< Animation used in the state transitions.
292   Animation                 mCheckOutAnimation; ///< Animation used in the state transitions.
293   Internal::CheckBoxButton* mButton;           ///< Temporary pointer used to remove fade out images from button.
294   float                     mAnimationTime;    ///< The animation time.
295
296   ImageRegionEffect         mTickUVEffect;     ///< ImageRegionEffect to expand the tick across
297
298   Property::Index           mPercentageParentSizeProperty;  ///< Dynamic property on the image actor
299 };
300
301 } // namespace Internal
302
303 } // namespace Toolkit
304
305 } // namespace Dali
306
307 #endif // __DALI_TOOLKIT_INTERNAL_CHECK_BOX_BUTTON_DEFAULT_PAINTER_H__