312a43c3d36b59c12bb3bb3408eab40891c15bb3
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / buttons / push-button-default-painter-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_PUSH_BUTTON_DEFAULT_PAINTER_H__
2 #define __DALI_TOOLKIT_INTERNAL_PUSH_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 "push-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 PushButton;
42 class PushButtonDefaultPainter;
43
44 // Type definitions
45
46 typedef IntrusivePtr<PushButtonDefaultPainter> PushButtonDefaultPainterPtr;
47
48 /**
49  * PushButtonDefaultPainter controls the Dali::Toolkit::PushButton appearance.
50  *
51  * This class inherits from Dali::Toolkit::Internal::PushButtonPainter and is registered in a
52  * Dali::Toolkit::Internal::PushButton object in order to receive the state changes.
53  */
54 class PushButtonDefaultPainter : public PushButtonPainter
55 {
56 public:
57
58   /**
59    * Constructor.
60    *
61    * Set actors and animations to NULL.
62    */
63   PushButtonDefaultPainter();
64
65   /**
66    * Destructor.
67    *
68    * It clears all fade in or fade out animations.
69    */
70   ~PushButtonDefaultPainter();
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::SetLabel( Toolkit::Button& button, Actor label )
103    */
104   virtual void SetLabel( Toolkit::Button& button, Actor label );
105
106   /**
107    * @copydoc ButtonPainter::SetAutoRepeating( bool autorepeating )
108    */
109   virtual void SetAutoRepeating( bool autorepeating );
110
111   /**
112    * @copydoc ButtonPainter::SetButtonImage( Toolkit::Button& button, Actor image )
113    */
114   virtual void SetButtonImage( Toolkit::Button& button, Actor image );
115
116   /**
117    * @copydoc ButtonPainter::SetSelectedImage( Toolkit::Button& button, Actor image )
118    */
119   virtual void SetSelectedImage( Toolkit::Button& button, Actor image );
120
121   /**
122    * @copydoc ButtonPainter::SetBackgroundImage( Toolkit::Button& button, Actor image )
123    */
124   virtual void SetBackgroundImage( Toolkit::Button& button, Actor image );
125
126   /**
127    * @copydoc ButtonPainter::SetDisabledImage( Toolkit::Button& button, Actor image )
128    */
129   virtual void SetDisabledImage( Toolkit::Button& button, Actor image );
130
131   /**
132    * @copydoc ButtonPainter::SetDisabledBackgroundImage( Toolkit::Button& button, Actor image )
133    */
134   virtual void SetDisabledBackgroundImage( Toolkit::Button& button, Actor image );
135
136   /**
137    * @copydoc ButtonPainter::Pressed( Toolkit::Button& button )
138    */
139   void Pressed( Toolkit::Button& button );
140
141   /**
142    * @copydoc ButtonPainter::Released( Toolkit::Button& button )
143    */
144   void Released( Toolkit::Button& button );
145
146   /**
147    * @copydoc ButtonPainter::Clicked( Toolkit::Button& button )
148    */
149   void Clicked( Toolkit::Button& button );
150
151   /**
152    * @copydoc ButtonPainter::Selected( Toolkit::Button& button )
153    */
154   void Selected( Toolkit::Button& button );
155
156 private:
157
158   // Undefined
159   PushButtonDefaultPainter( const PushButtonDefaultPainter& );
160
161   // Undefined
162   PushButtonDefaultPainter& operator=( const PushButtonDefaultPainter& );
163
164 private:
165
166   /**
167    * Default push button painter states.
168    */
169   enum PaintState
170   {
171     ReleasedState,              ///< The push button is released.
172     PressedState,               ///< The push button is pressed.
173     DisabledReleasedState,      ///< The push button is disabled and released.
174     DisabledPressedState,       ///< The push button is Disabled and pressed.
175     ReleasedPressedTransition,  ///< The push button is in transition from released to pressed.
176     PressedReleasedTransition,  ///< The push button is in transition from pressed to released.
177     ReleasedDisabledTransition, ///< The push button is in transition from released to disabled.
178     DisabledReleasedTransition, ///< The push button is in transition from disabled to released.
179     PressedDisabledTransition,  ///< The push button is in transition from pressed to disabled.
180     DisabledPressedTransition   ///< The push button is in transition from disabled to pressed.
181   };
182
183   /**
184    * Used in the FadeOut functions.
185    */
186   enum ImageLayer
187   {
188     Background, ///< Fade out the background.
189     Foreground  ///< Fade out the foreground.
190   };
191
192 private:
193   /**
194    * Apply size and position constraints to painter actors.
195    *
196    * @param[inout] actor The actor.
197    * @param[in] depth Depth position.
198    */
199   void ApplyConstraint( Actor& actor, float depth );
200
201   /**
202    * Adds the actor to the fade in animation. It creates a fade in animation if needed.
203    *
204    * @param[in] actor The actor.
205    */
206   void AddToFadeInAnimation( const Actor& actor );
207
208   /**
209    * Starts the fade in animation.
210    *
211    * PushButtonDefaultPainter::PressedReleasedFadeInAnimationFinished slot is called when the animation finishes.
212    */
213   void StartFadeInAnimation();
214
215   /**
216    * Stops the fade in animation.
217    */
218   void StopFadeInAnimation();
219
220   /**
221    * Adds the actor to the fade out animation. It creates a fade out animation if needed.
222    */
223   void AddToFadeOutAnimation( const Actor& actor );
224
225   /**
226    * Starts the fade out animation.
227    *
228    * PushButtonDefaultPainter::PressedReleasedFadeOutAnimationFinished slot is called when the animation finishes.
229    * @param[inout] pushButton The button which holds images.
230    */
231   void StartFadeOutAnimation( Toolkit::PushButton& pushButton );
232
233   /**
234    * Stops the fade out animation.
235    *
236    * It removes the actor stored in PushButtonDefaultPainter::mFadeOutBackgroundImage and
237    * PushButtonDefaultPainter::mFadeOutCheckedImage.
238    *
239    * @param[inout] pushButton The button which holds images.
240    * @param[in] remove If true, removes the fadeout actor from root.
241    */
242   void StopFadeOutAnimation( Toolkit::PushButton& pushButton, bool remove = true );
243
244   /**
245    * It adds the actor to the root actor and to the fade in animation.
246    *
247    * @param[inout] pushButton The button which holds images.
248    * @param[inout] image The actor.
249    * @param[in] opacity The initial opacity.
250    */
251   void FadeInImage( Toolkit::PushButton& pushButton, Actor& image, float opacity = 0.f );
252
253   /**
254    * It adds the actor fade out animation and stores it to be removed when the animation finishes.
255    * @param[inout] pushButton The button which holds images.
256    * @param[in] layer Defines if the actor is going to be stored in the mFadeOutBackgroundImage or mFadeOutCheckedImage member.
257    * @param[inout] image The actor.
258    * @param[in] opacity The initial opacity.
259    */
260   void FadeOutImage( Toolkit::PushButton& pushButton, ImageLayer layer, Actor& image, float opacity = 1.f );
261
262   // slots
263
264   /**
265    * Called when the fade out animation finishes.
266    *
267    * It changes the check button painter state and removes actors from the root.
268    */
269   void PressedReleasedFadeOutAnimationFinished( Dali::Animation& source );
270
271   /**
272    * Called when the fade in animation finishes.
273    *
274    * It changes the check button painter state.
275    */
276   void PressedReleasedFadeInAnimationFinished( Dali::Animation& source );
277
278 private:
279   bool                  mAutoRepeating;    ///< Stores the autorepeating property.
280   bool                  mDisabled;         ///< Stores the disabled property.
281
282   PaintState            mPaintState;       ///< The painter state.
283   Animation             mFadeInAnimation;  ///< Animation used in the state transitions.
284   Animation             mFadeOutAnimation; ///< Animation used in the state transitions.
285   Internal::PushButton* mButton;           ///< Temporary pointer used to remove fade out images from button.
286   float                 mAnimationTime;    ///< The animation time.
287   Vector3               mSize;             ///< The button's size.
288 };
289
290 } // namespace Internal
291
292 } // namespace Toolkit
293
294 } // namespace Dali
295
296 #endif // __DALI_TOOLKIT_INTERNAL_PUSH_BUTTON_DEFAULT_PAINTER_H__