Remove obsolete and non functional SizeChanged signal from actor
[platform/core/uifw/dali-toolkit.git] / base / 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    * Sets the background image.
73    *
74    * It adds the background image to the root actor and creates the image transition if needed.
75    *
76    * @param[inout] checkBox The button in which all actors that form its appearance are going to be added.
77    * @param[in] image The background image.
78    */
79   void SetBackgroundImage( Toolkit::CheckBoxButton& checkBox, Actor image );
80
81   /**
82    * Sets the checked image.
83    *
84    * It adds the checked image to the root actor and creates the image transition if needed.
85    *
86    * @param[inout] checkBox The button in which all actors that form its appearance are going to be added.
87    * @param[in] image The checked image.
88    */
89   void SetCheckedImage( Toolkit::CheckBoxButton& checkBox, Actor image );
90
91   /**
92    * Sets the disabled backgroundimage.
93    *
94    * It adds the disabled backgroundimage to the root actor and creates the image transition if needed.
95    *
96    * @param[inout] checkBox The button in which all actors that form its appearance are going to be added.
97    * @param[in] image The disabled backgroundimage.
98    */
99   void SetDisabledBackgroundImage( Toolkit::CheckBoxButton& checkBox, Actor image );
100
101   /**
102    * Sets the disabled checked image.
103    *
104    * It adds the disabled checked image to the root actor and creates the image transition if needed.
105    *
106    * @param[inout] checkBox The button in which all actors that form its appearance are going to be added.
107    * @param[in] image The disabled checked image.
108    */
109   void SetDisabledCheckedImage( Toolkit::CheckBoxButton& checkBox, Actor image );
110
111   /////////////////////////////////////////////////////////////////////////////
112   // ButtonPainter interface
113   /////////////////////////////////////////////////////////////////////////////
114
115   /**
116    * Initializes the painter by setting the default images.
117    *
118    * @param[inout] button The button in which all actors that form its appearance are going to be added.
119    */
120   void Initialize( Toolkit::Button& button );
121
122   /**
123    * Sets the new size.
124    *
125    * Resizes images. It applies size constraints.
126    *
127    * @param[inout] button The button which stores button's images.
128    * @param[in] size The new size.
129    */
130   void SetSize( Toolkit::Button& button, const Vector3& size );
131
132   /**
133    * Changes the Vega::Toolkit::CheckBoxButton for the given disabled state.
134    *
135    * It creates the image transition if needed.
136    *
137    * @param[inout] button The button in which all actors that form its appearance are going to be added.
138    * @param[in] disabled The disabled state.
139    */
140   void SetDisabled( Toolkit::Button& button, bool disabled );
141
142   /**
143    * Sets the animation time.
144    * @param[in] animationTime The animation time.
145    */
146   void SetAnimationTime( float animationTime );
147
148   /**
149    * Retrieves the animation time.
150    * @return The animation time.
151    */
152   float GetAnimationTime() const;
153
154   /////////////////////////////////////////////////////////////////////////////
155   // CheckBoxButtonPainter interface
156   /////////////////////////////////////////////////////////////////////////////
157
158   /**
159    * This method is called when the Dali::Toolkit::Internal::CheckBoxButton in which this object is registered
160    * changes its state.
161    *
162    * @param[inout] checkBox The Dali::Toolkit::CheckBoxButton in which this object is registered.
163    */
164   void Checked( Toolkit::CheckBoxButton& checkBox );
165
166 private:
167
168   // Undefined
169   CheckBoxButtonDefaultPainter( const CheckBoxButtonDefaultPainter& );
170
171   // Undefined
172   CheckBoxButtonDefaultPainter& operator=( const CheckBoxButtonDefaultPainter& );
173
174 private:
175
176   /**
177    * Default check box button painter states.
178    */
179   enum PaintState
180   {
181     UncheckedState,              ///< The check box button is unchecked.
182     CheckedState,                ///< The check box button is checked.
183     DisabledUncheckedState,      ///< The check box button is disabled and unchecked.
184     DisabledCheckedState,        ///< The check box button is disabled and checked.
185     UncheckedCheckedTransition,  ///< The check box button is in transition from unchecked to checked.
186     CheckedUncheckedTransition,  ///< The check box button is in transition from checked to unchecked.
187     UncheckedDisabledTransition, ///< The check box button is in transition from unchecked to disabled.
188     DisabledUncheckedTransition, ///< The check box button is in transition from disabled to unchecked.
189     CheckedDisabledTransition,   ///< The check box button is in transition from checked to disabled.
190     DisabledCheckedTransition    ///< The check box button is in transition from disabled to checked.
191   };
192
193   /**
194    * Used in the FadeOut functions.
195    */
196   enum ImageLayer
197   {
198     Background, ///< Fade out the background.
199     Foreground  ///< Fade out the foreground.
200   };
201
202 private:
203   /**
204    * Apply size and position constraints to painter actors.
205    *
206    * @param[inout] actor The actor.
207    * @param[in] depth Depth position.
208    */
209   void ApplyConstraint( Actor& actor, float depth );
210
211   /**
212    * Apply size constraint to check tick
213    *
214    * @param[inout] actor The actor.
215    * @param[in] depth Depth position.
216    */
217   void ApplyCheckedConstraint( Actor& actor, float depth );
218
219   /**
220    * Adds the actor to the fade in animation. It creates a fade in animation if needed.
221    *
222    * @param[in] actor The actor.
223    */
224   void AddToFadeInAnimation( const Actor& actor );
225
226   /**
227    * Starts the check in animation.
228    *
229    * CheckBoxButtonDefaultPainter::CheckInAnimationFinished slot is called when the animation finishes.
230    */
231   void StartCheckInAnimation();
232
233   /**
234    * Stops the check in animation.
235    */
236   void StopCheckInAnimation();
237
238   /**
239    * Adds the actor to the fade out animation. It creates a fade out animation if needed.
240    *
241    * @param[in] actor The actor.
242    */
243   void AddToFadeOutAnimation( const Actor& actor );
244
245   /**
246    * Starts the check out animation.
247    *
248    * CheckBoxButtonDefaultPainter::CheckOutAnimationFinished slot is called when the animation finishes.
249    *
250    * @param[inout] checkBox The button which holds images.
251    */
252   void StartCheckOutAnimation( Toolkit::CheckBoxButton& checkBox );
253
254   /**
255    * Stops the fade out animation.
256    *
257    * It removes the actor stored in CheckBoxButtonDefaultPainter::mFadeOutBackgroundImage and
258    * CheckBoxButtonDefaultPainter::mFadeOutCheckedImage.
259    *
260    * @param[inout] checkBox The button which holds images.
261    * @param[in] remove If true, removes the fadeout actor from root.
262    */
263   void StopCheckOutAnimation( Toolkit::CheckBoxButton& checkBox, bool remove = true );
264
265   /**
266    * It adds the actor to the root actor and to the fade in animation.
267    *
268    * @param[inout] checkBox The button which holds images.
269    * @param[inout] image The actor.
270    * @param[in] opacity The initial opacity.
271    */
272   void FadeInImage( Toolkit::CheckBoxButton& checkBox, Actor& image, float opacity = 0.f );
273
274   /**
275    * It adds the actor fade out animation and stores it to be removed when the animation finishes.
276    *
277    * @param[inout] checkBox The button which holds images.
278    * @param[in] layer Defines if the actor is going to be stored in the mFadeOutBackgroundImage or mFadeOutCheckedImage member.
279    * @param[inout] image The actor.
280    * @param[in] opacity The initial opacity.
281    */
282   void FadeOutImage( Toolkit::CheckBoxButton& checkBox, ImageLayer layer, Actor& image, float opacity = 1.f );
283
284   /**
285    * Adds the actor to the fade in animation. It creates a fade in animation if needed.
286    *
287    * @param[in] actor The actor.
288    */
289   void AddToCheckInAnimation( const Actor& actor );
290
291   /**
292    * It adds the actor to the root actor and to the fade in animation.
293    *
294    * @param[inout] checkBox The button which holds images.
295    * @param[inout] image The actor.
296    */
297   void SetupCheckedAnimation( Toolkit::CheckBoxButton& checkBox, Actor& image );
298
299   /**
300    * Signal end of check out animation
301    */
302   void EndCheckOutAnimation();
303
304   // slots
305
306   /**
307    * Called when the fade out animation finishes.
308    *
309    * It changes the check button painter state and removes actors from the root.
310    */
311   void CheckOutAnimationFinished( Dali::Animation& source );
312
313   /**
314    * Called when the fade in animation finishes.
315    *
316    * It changes the check button painter state.
317    */
318   void CheckInAnimationFinished( Dali::Animation& source );
319
320 private:
321   bool                      mDisabled;           ///< Stores the disabled property.
322
323   PaintState                mPaintState;       ///< The painter state.
324
325   Animation                 mCheckInAnimation;  ///< Animation used in the state transitions.
326   Animation                 mCheckOutAnimation; ///< Animation used in the state transitions.
327   Internal::CheckBoxButton* mButton;           ///< Temporary pointer used to remove fade out images from button.
328   float                     mAnimationTime;    ///< The animation time.
329
330   ImageRegionEffect         mTickUVEffect;     ///< ImageRegionEffect to expand the tick across
331
332   Property::Index           mPercentageParentSizeProperty;  ///< Dynamic property on the image actor
333 };
334
335 } // namespace Internal
336
337 } // namespace Toolkit
338
339 } // namespace Dali
340
341 #endif // __DALI_TOOLKIT_INTERNAL_CHECK_BOX_BUTTON_DEFAULT_PAINTER_H__