1 #ifndef __DALI_TOOLKIT_INTERNAL_PUSH_BUTTON_DEFAULT_PAINTER_H__
2 #define __DALI_TOOLKIT_INTERNAL_PUSH_BUTTON_DEFAULT_PAINTER_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
21 #include <dali/public-api/images/image.h>
22 #include <dali/public-api/actors/actor.h>
23 #include <dali/public-api/math/vector2.h>
24 #include <dali/public-api/animation/animation.h>
26 #include "push-button-painter-impl.h"
37 // Forward declarations
40 class PushButtonDefaultPainter;
44 typedef IntrusivePtr<PushButtonDefaultPainter> PushButtonDefaultPainterPtr;
47 * PushButtonDefaultPainter controls the Dali::Toolkit::PushButton appearance.
49 * This class inherits from Dali::Toolkit::Internal::PushButtonPainter and is registered in a
50 * Dali::Toolkit::Internal::PushButton object in order to receive the state changes.
52 class PushButtonDefaultPainter : public PushButtonPainter
59 * Set actors and animations to NULL.
61 PushButtonDefaultPainter();
66 * It clears all fade in or fade out animations.
68 ~PushButtonDefaultPainter();
71 * Sets the button image.
73 * It adds the button image to the root actor and creates the image transition if needed.
75 * @param[inout] pushButton The button in which all actors that form its appearance are going to be added.
76 * @param[in] image The button image.
78 void SetButtonImage( Toolkit::PushButton& pushButton, Actor image );
81 * Sets the background image.
83 * It adds the background image to the root actor and creates the image transition if needed.
85 * @param[inout] pushButton The button in which all actors that form its appearance are going to be added.
86 * @param[in] image The background image.
88 void SetBackgroundImage( Toolkit::PushButton& pushButton, Actor image );
91 * Sets the pressed image.
93 * It adds the pressed image to the root actor and creates the image transition if needed.
95 * @param[inout] pushButton The button in which all actors that form its appearance are going to be added.
96 * @param[in] image The pressed image.
98 void SetPressedImage( Toolkit::PushButton& pushButton, Actor image );
101 * Sets the dimmed background image.
103 * It adds the dimmed background image to the root actor and creates the image transition if needed.
105 * @param[inout] pushButton The button in which all actors that form its appearance are going to be added.
106 * @param[in] image The dimmed background image.
108 void SetDimmedBackgroundImage( Toolkit::PushButton& pushButton, Actor image );
111 * Sets the dimmed image.
113 * It adds the dimmed image to the root actor and creates the image transition if needed.
115 * @param[inout] pushButton The button in which all actors that form its appearance are going to be added.
116 * @param[in] image The image.
118 void SetDimmedImage( Toolkit::PushButton& pushButton, Actor image );
121 * Sets the text label.
123 * It adds the text to the root actor.
125 * @param[inout] pushButton The button in which all actors that form its appearance are going to be added.
126 * @param[in] text Label text.
128 void SetLabelText( Toolkit::PushButton& pushButton, Actor text );
130 /////////////////////////////////////////////////////////////////////////////
131 // ButtonPainter interface
132 /////////////////////////////////////////////////////////////////////////////
135 * Initializes the painter by setting the default images.
137 * @param[inout] button The button in which all actors that form its appearance are going to be added.
139 void Initialize( Toolkit::Button& button );
144 * Resizes actors. It applies size constraints.
146 * @param[inout] button The button which stores button's images.
147 * @param[in] size The new size.
149 void SetSize( Toolkit::Button& button, const Vector3& size );
152 * This method is called when the \e dimmed property in the Dali::Toolkit::PushButton changes.
154 * Creates image transitions if needed.
156 * @param[inout] button The button in which all actors that form its appearance are going to be added.
157 * @param[in] dimmed property.
159 void SetDimmed( Toolkit::Button& button, bool dimmed );
162 * Sets the animation time.
163 * @param[in] animationTime The animation time.
165 void SetAnimationTime( float animationTime );
168 * Retrieves the animation time.
169 * @return The animation time.
171 float GetAnimationTime() const;
173 /////////////////////////////////////////////////////////////////////////////
174 // PushButtonPainter interface
175 /////////////////////////////////////////////////////////////////////////////
178 * This method is called when the \e autorepeating property in the Dali::Toolkit::PushButton changes.
179 * @param[in] autorepeating property.
181 void SetAutoRepeating( bool autorepeating );
184 * This method is called when the Dali::Toolkit::Internal::PushButton in which this object is registered
185 * is pressed. It changes to the pressed image with a transition.
187 * @param[inout] button The Dali::Toolkit::PushButton in which this object is registered.
189 void Pressed( Toolkit::PushButton& button );
192 * This method is called when the Dali::Toolkit::Internal::PushButton in which this object is registered
193 * is released. It changes to the button image with a transition.
195 * @param[inout] button The Dali::Toolkit::PushButton in which this object is registered.
197 void Released( Toolkit::PushButton& button );
200 * This method is called when the Dali::Toolkit::Internal::PushButton in which this object is registered
203 * @param[inout] button The Dali::Toolkit::PushButton in which this object is registered.
205 void Clicked( Toolkit::PushButton& button );
208 * This method is called when the Dali::Toolkit::Internal::PushButton in which this object is registered
211 * @param[inout] button The Dali::Toolkit::PushButton in which this object is registered.
213 void Toggled( Toolkit::PushButton& button );
218 PushButtonDefaultPainter( const PushButtonDefaultPainter& );
221 PushButtonDefaultPainter& operator=( const PushButtonDefaultPainter& );
226 * Default push button painter states.
230 ReleasedState, ///< The push button is released.
231 PressedState, ///< The push button is pressed.
232 DimmedReleasedState, ///< The push button is dimmed and released.
233 DimmedPressedState, ///< The push button is dimemd and pressed.
234 ReleasedPressedTransition, ///< The push button is in transition from released to pressed.
235 PressedReleasedTransition, ///< The push button is in transition from pressed to released.
236 ReleasedDimmedTransition, ///< The push button is in transition from released to dimmed.
237 DimmedReleasedTransition, ///< The push button is in transition from dimmed to released.
238 PressedDimmedTransition, ///< The push button is in transition from pressed to dimmed.
239 DimmedPressedTransition ///< The push button is in transition from dimmed to pressed.
243 * Used in the FadeOut functions.
247 Background, ///< Fade out the background.
248 Foreground ///< Fade out the foreground.
253 * Apply size and position constraints to painter actors.
255 * @param[inout] actor The actor.
256 * @param[in] depth Depth position.
258 void ApplyConstraint( Actor& actor, float depth );
261 * Adds the actor to the fade in animation. It creates a fade in animation if needed.
263 * @param[in] actor The actor.
265 void AddToFadeInAnimation( const Actor& actor );
268 * Starts the fade in animation.
270 * PushButtonDefaultPainter::PressedReleasedFadeInAnimationFinished slot is called when the animation finishes.
272 void StartFadeInAnimation();
275 * Stops the fade in animation.
277 void StopFadeInAnimation();
280 * Adds the actor to the fade out animation. It creates a fade out animation if needed.
282 void AddToFadeOutAnimation( const Actor& actor );
285 * Starts the fade out animation.
287 * PushButtonDefaultPainter::PressedReleasedFadeOutAnimationFinished slot is called when the animation finishes.
288 * @param[inout] pushButton The button which holds images.
290 void StartFadeOutAnimation( Toolkit::PushButton& pushButton );
293 * Stops the fade out animation.
295 * It removes the actor stored in PushButtonDefaultPainter::mFadeOutBackgroundImage and
296 * PushButtonDefaultPainter::mFadeOutCheckedImage.
298 * @param[inout] pushButton The button which holds images.
299 * @param[in] remove If true, removes the fadeout actor from root.
301 void StopFadeOutAnimation( Toolkit::PushButton& pushButton, bool remove = true );
304 * It adds the actor to the root actor and to the fade in animation.
306 * @param[inout] pushButton The button which holds images.
307 * @param[inout] image The actor.
308 * @param[in] opacity The initial opacity.
310 void FadeInImage( Toolkit::PushButton& pushButton, Actor& image, float opacity = 0.f );
313 * It adds the actor fade out animation and stores it to be removed when the animation finishes.
314 * @param[inout] pushButton The button which holds images.
315 * @param[in] layer Defines if the actor is going to be stored in the mFadeOutBackgroundImage or mFadeOutCheckedImage member.
316 * @param[inout] image The actor.
317 * @param[in] opacity The initial opacity.
319 void FadeOutImage( Toolkit::PushButton& pushButton, ImageLayer layer, Actor& image, float opacity = 1.f );
324 * Called when the fade out animation finishes.
326 * It changes the check button painter state and removes actors from the root.
328 void PressedReleasedFadeOutAnimationFinished( Dali::Animation& source );
331 * Called when the fade in animation finishes.
333 * It changes the check button painter state.
335 void PressedReleasedFadeInAnimationFinished( Dali::Animation& source );
338 bool mAutoRepeating; ///< Stores the autorepeating property.
339 bool mDimmed; ///< Stores the dimmed property.
341 PaintState mPaintState; ///< The painter state.
342 Animation mFadeInAnimation; ///< Animation used in the state transitions.
343 Animation mFadeOutAnimation; ///< Animation used in the state transitions.
344 Internal::PushButton* mButton; ///< Temporary pointer used to remove fade out images from button.
345 float mAnimationTime; ///< The animation time.
346 Vector3 mSize; ///< The button's size.
349 } // namespace Internal
351 } // namespace Toolkit
355 #endif // __DALI_TOOLKIT_INTERNAL_PUSH_BUTTON_DEFAULT_PAINTER_H__