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