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