Merge "Refactoring Button: remove painter" into tizen
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / buttons / push-button-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_PUSH_BUTTON_H__
2 #define __DALI_TOOLKIT_INTERNAL_PUSH_BUTTON_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/common/dali-vector.h>
23 #include <dali/public-api/animation/animation.h>
24
25 // INTERNAL INCLUDES
26 #include <dali-toolkit/public-api/controls/buttons/push-button.h>
27 #include "button-impl.h"
28
29 namespace Dali
30 {
31
32 namespace Toolkit
33 {
34
35 namespace Internal
36 {
37
38 /**
39  * PushButton implementation class.
40  *
41  * \sa Dali::Toolkit::PushButton
42  */
43 class PushButton : public Button
44 {
45 public:
46
47   /**
48    * Create a new PushButton.
49    * @return A smart-pointer to the newly allocated PushButton.
50    */
51   static Dali::Toolkit::PushButton New();
52
53 protected:
54
55   /**
56    * Construct a new PushButton.
57    */
58   PushButton();
59
60   /**
61    * A reference counted object may only be deleted by calling Unreference()
62    */
63   virtual ~PushButton();
64
65 public: // From Button
66
67   /**
68    * @copydoc Toolkit::Internal::Button::SetButtonImage( Actor image )
69    */
70   virtual void SetButtonImage( Actor image );
71
72   /**
73    * @copydoc Toolkit::Internal::Button::SetSelectedImage( Actor image )
74    */
75   virtual void SetSelectedImage( Actor image );
76
77   /**
78    * @copydoc Toolkit::Internal::Button::SetBackgroundImage( Actor image )
79    */
80   virtual void SetBackgroundImage( Actor image );
81
82   /**
83    * @copydoc Toolkit::Internal::Button::SetDisabledImage( Actor image )
84    */
85   virtual void SetDisabledImage( Actor image );
86
87   /**
88    * @copydoc Toolkit::Internal::Button::SetDisabledBackgroundImage( Actor image )
89    */
90   virtual void SetDisabledBackgroundImage( Actor image );
91
92 private: // From Button
93
94   /**
95    * @copydoc Toolkit::Internal::Button::OnButtonInitialize()
96    */
97   virtual void OnButtonInitialize();
98
99   /**
100    * @copydoc Toolkit::Internal::Button::OnLabelSet()
101    */
102   virtual void OnLabelSet();
103
104   /**
105    * @copydoc Toolkit::Internal::Button::OnSelected()
106    */
107   virtual void OnSelected( bool selected );
108
109   /**
110    * @copydoc Toolkit::Internal::Button::OnDisabled( bool disabled )
111    */
112   virtual void OnDisabled( bool disabled );
113
114   /**
115    * @copydoc Toolkit::Internal::Button::OnPressed()
116    */
117   virtual void OnPressed();
118
119   /**
120    * @copydoc Toolkit::Internal::Button::OnReleased()
121    */
122   virtual void OnReleased();
123
124   /**
125    * @copydoc Toolkit::Internal::Button::OnClicked()
126    */
127   virtual void OnClicked();
128
129 private: // From Control
130
131   /**
132    * @copydoc Toolkit::Control::OnControlSizeSet( const Vector3& targetSize )
133    */
134   virtual void OnControlSizeSet( const Vector3& targetSize );
135
136   /**
137    * @copydoc Toolkit::Control::GetNaturalSize()
138    */
139   virtual Vector3 GetNaturalSize();
140
141 private:
142
143   /**
144    * Used in the FadeOut functions.
145    */
146   enum ImageLayer
147   {
148     Background, ///< Fade out the background.
149     Foreground  ///< Fade out the foreground.
150   };
151
152   /**
153    * Gets the button image that is fading out.
154    * @return A reference to the button image that is fading out.
155    */
156   Actor& GetFadeOutButtonImage();
157
158   /**
159    * Gets the background image that is fading out.
160    * @return A reference to the background image that is fading out.
161    */
162   Actor& GetFadeOutBackgroundImage();
163
164   /**
165    * Adds the actor to the fade in animation. It creates a fade in animation if needed.
166    * @param[in] actor The actor.
167    */
168   void AddToFadeInAnimation( const Actor& actor );
169
170   /**
171    * Starts the fade in animation.
172    * PushButton::FadeInAnimationFinished slot is called when the animation finishes.
173    */
174   void StartFadeInAnimation();
175
176   /**
177    * Stops the fade in animation.
178    */
179   void StopFadeInAnimation();
180
181   /**
182    * Adds the actor to the fade out animation. It creates a fade out animation if needed.
183    */
184   void AddToFadeOutAnimation( const Actor& actor );
185
186   /**
187    * Starts the fade out animation.
188    * PushButton::FadeOutAnimationFinished slot is called when the animation finishes.
189    */
190   void StartFadeOutAnimation();
191
192   /**
193    * Stops the fade out animation.
194    * It removes the actor stored in PushButton::mFadeOutBackgroundImage and PushButton::mFadeOutCheckedImage.
195    * @param[in] remove If true, removes the fadeout actor from root.
196    */
197   void StopFadeOutAnimation( bool remove = true );
198
199   /**
200    * It adds the actor to the root actor and to the fade in animation.
201    * @param[inout] image The actor.
202    * @param[in] opacity The initial opacity.
203    */
204   void FadeInImage( Actor& image, float opacity = 0.f );
205
206   /**
207    * It adds the actor fade out animation and stores it to be removed when the animation finishes.
208    * @param[in] layer Defines if the actor is going to be stored in the mFadeOutBackgroundImage or mFadeOutCheckedImage member.
209    * @param[inout] image The actor.
210    * @param[in] opacity The initial opacity.
211    */
212   void FadeOutImage( ImageLayer layer, Actor& image, float opacity = 1.f );
213
214   // slots
215
216   /**
217    * Called when the fade out animation finishes.
218    * It changes the check button paint state and removes actors from the root.
219    */
220   void FadeOutAnimationFinished( Dali::Animation& source );
221
222   /**
223    * Called when the fade in animation finishes.
224    * It changes the check button paint state.
225    */
226   void FadeInAnimationFinished( Dali::Animation& source );
227
228 private:
229
230   // Undefined
231   PushButton( const PushButton& );
232
233   // Undefined
234   PushButton& operator=( const PushButton& );
235
236 private:
237
238   Animation             mFadeInAnimation;           ///< Animation used in the state transitions.
239   Animation             mFadeOutAnimation;          ///< Animation used in the state transitions.
240
241   Actor                 mFadeOutButtonContent;      ///< Stores a foreground content, which is in a fade out animation, to be removed when the animation finishes.
242   Actor                 mFadeOutBackgroundContent;  ///< Stores a background content, which is in a fade out animation, to be removed when the animation finishes.
243
244   Vector3               mSize;                      ///< The button's size.
245
246   PaintState            mPaintState;                ///< The paint state.
247 };
248
249 } // namespace Internal
250
251 // Helpers for public-api forwarding methods
252
253 inline Toolkit::Internal::PushButton& GetImplementation( Toolkit::PushButton& button )
254 {
255   DALI_ASSERT_ALWAYS( button );
256
257   Dali::RefObject& handle = button.GetImplementation();
258
259   return static_cast<Toolkit::Internal::PushButton&>( handle );
260 }
261
262 inline const Toolkit::Internal::PushButton& GetImplementation( const Toolkit::PushButton& button )
263 {
264   DALI_ASSERT_ALWAYS( button );
265
266   const Dali::RefObject& handle = button.GetImplementation();
267
268   return static_cast<const Toolkit::Internal::PushButton&>( handle );
269 }
270
271 } // namespace Toolkit
272
273 } // namespace Dali
274
275 #endif // __DALI_TOOLKIT_INTERNAL_PUSH_BUTTON_H__