1 #ifndef __DALI_TOOLKIT_INTERNAL_PUSH_BUTTON_H__
2 #define __DALI_TOOLKIT_INTERNAL_PUSH_BUTTON_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/common/dali-vector.h>
23 #include <dali/public-api/animation/animation.h>
26 #include <dali-toolkit/public-api/controls/buttons/push-button.h>
27 #include "button-impl.h"
39 * PushButton implementation class.
41 * \sa Dali::Toolkit::PushButton
43 class PushButton : public Button
48 * Create a new PushButton.
49 * @return A smart-pointer to the newly allocated PushButton.
51 static Dali::Toolkit::PushButton New();
56 * Construct a new PushButton.
61 * A reference counted object may only be deleted by calling Unreference()
63 virtual ~PushButton();
65 public: // From Button
68 * @copydoc Toolkit::Internal::Button::SetButtonImage( Actor image )
70 virtual void SetButtonImage( Actor image );
73 * @copydoc Toolkit::Internal::Button::SetSelectedImage( Actor image )
75 virtual void SetSelectedImage( Actor image );
78 * @copydoc Toolkit::Internal::Button::SetBackgroundImage( Actor image )
80 virtual void SetBackgroundImage( Actor image );
83 * @copydoc Toolkit::Internal::Button::SetDisabledImage( Actor image )
85 virtual void SetDisabledImage( Actor image );
88 * @copydoc Toolkit::Internal::Button::SetDisabledBackgroundImage( Actor image )
90 virtual void SetDisabledBackgroundImage( Actor image );
92 private: // From Button
95 * @copydoc Toolkit::Internal::Button::OnButtonInitialize()
97 virtual void OnButtonInitialize();
100 * @copydoc Toolkit::Internal::Button::OnLabelSet()
102 virtual void OnLabelSet();
105 * @copydoc Toolkit::Internal::Button::OnSelected()
107 virtual void OnSelected( bool selected );
110 * @copydoc Toolkit::Internal::Button::OnDisabled( bool disabled )
112 virtual void OnDisabled( bool disabled );
115 * @copydoc Toolkit::Internal::Button::OnPressed()
117 virtual void OnPressed();
120 * @copydoc Toolkit::Internal::Button::OnReleased()
122 virtual void OnReleased();
125 * @copydoc Toolkit::Internal::Button::OnClicked()
127 virtual void OnClicked();
129 private: // From Control
132 * @copydoc Toolkit::Control::OnControlSizeSet( const Vector3& targetSize )
134 virtual void OnControlSizeSet( const Vector3& targetSize );
137 * @copydoc Toolkit::Control::GetNaturalSize()
139 virtual Vector3 GetNaturalSize();
144 * Used in the FadeOut functions.
148 Background, ///< Fade out the background.
149 Foreground ///< Fade out the foreground.
153 * Gets the button image that is fading out.
154 * @return A reference to the button image that is fading out.
156 Actor& GetFadeOutButtonImage();
159 * Gets the background image that is fading out.
160 * @return A reference to the background image that is fading out.
162 Actor& GetFadeOutBackgroundImage();
165 * Adds the actor to the fade in animation. It creates a fade in animation if needed.
166 * @param[in] actor The actor.
168 void AddToFadeInAnimation( const Actor& actor );
171 * Starts the fade in animation.
172 * PushButton::FadeInAnimationFinished slot is called when the animation finishes.
174 void StartFadeInAnimation();
177 * Stops the fade in animation.
179 void StopFadeInAnimation();
182 * Adds the actor to the fade out animation. It creates a fade out animation if needed.
184 void AddToFadeOutAnimation( const Actor& actor );
187 * Starts the fade out animation.
188 * PushButton::FadeOutAnimationFinished slot is called when the animation finishes.
190 void StartFadeOutAnimation();
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.
197 void StopFadeOutAnimation( bool remove = true );
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.
204 void FadeInImage( Actor& image, float opacity = 0.f );
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.
212 void FadeOutImage( ImageLayer layer, Actor& image, float opacity = 1.f );
217 * Called when the fade out animation finishes.
218 * It changes the check button paint state and removes actors from the root.
220 void FadeOutAnimationFinished( Dali::Animation& source );
223 * Called when the fade in animation finishes.
224 * It changes the check button paint state.
226 void FadeInAnimationFinished( Dali::Animation& source );
231 PushButton( const PushButton& );
234 PushButton& operator=( const PushButton& );
238 Animation mFadeInAnimation; ///< Animation used in the state transitions.
239 Animation mFadeOutAnimation; ///< Animation used in the state transitions.
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.
244 Vector3 mSize; ///< The button's size.
246 PaintState mPaintState; ///< The paint state.
249 } // namespace Internal
251 // Helpers for public-api forwarding methods
253 inline Toolkit::Internal::PushButton& GetImplementation( Toolkit::PushButton& button )
255 DALI_ASSERT_ALWAYS( button );
257 Dali::RefObject& handle = button.GetImplementation();
259 return static_cast<Toolkit::Internal::PushButton&>( handle );
262 inline const Toolkit::Internal::PushButton& GetImplementation( const Toolkit::PushButton& button )
264 DALI_ASSERT_ALWAYS( button );
266 const Dali::RefObject& handle = button.GetImplementation();
268 return static_cast<const Toolkit::Internal::PushButton&>( handle );
271 } // namespace Toolkit
275 #endif // __DALI_TOOLKIT_INTERNAL_PUSH_BUTTON_H__