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 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/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>
27 #include "push-button-painter-impl.h"
38 // Forward declarations
41 class PushButtonDefaultPainter;
45 typedef IntrusivePtr<PushButtonDefaultPainter> PushButtonDefaultPainterPtr;
48 * PushButtonDefaultPainter controls the Dali::Toolkit::PushButton appearance.
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.
53 class PushButtonDefaultPainter : public PushButtonPainter
60 * Set actors and animations to NULL.
62 PushButtonDefaultPainter();
67 * It clears all fade in or fade out animations.
69 ~PushButtonDefaultPainter();
72 * Sets the button image.
74 * It adds the button image to the root actor and creates the image transition if needed.
76 * @param[inout] pushButton The button in which all actors that form its appearance are going to be added.
77 * @param[in] image The button image.
79 void SetButtonImage( Toolkit::PushButton& pushButton, Actor image );
82 * Sets the background image.
84 * It adds the background image to the root actor and creates the image transition if needed.
86 * @param[inout] pushButton The button in which all actors that form its appearance are going to be added.
87 * @param[in] image The background image.
89 void SetBackgroundImage( Toolkit::PushButton& pushButton, Actor image );
92 * Sets the selected image.
94 * It adds the selected image to the root actor and creates the image transition if needed.
96 * @param[inout] pushButton The button in which all actors that form its appearance are going to be added.
97 * @param[in] image The selected image.
99 void SetSelectedImage( Toolkit::PushButton& pushButton, Actor image );
102 * Sets the disabled background image.
104 * It adds the disabled background image to the root actor and creates the image transition if needed.
106 * @param[inout] pushButton The button in which all actors that form its appearance are going to be added.
107 * @param[in] image The disabled background image.
109 void SetDisabledBackgroundImage( Toolkit::PushButton& pushButton, Actor image );
112 * Sets the disabled image.
114 * It adds the disabled image to the root actor and creates the image transition if needed.
116 * @param[inout] pushButton The button in which all actors that form its appearance are going to be added.
117 * @param[in] image The image.
119 void SetDisabledImage( Toolkit::PushButton& pushButton, Actor image );
124 * It adds the label to the root actor.
126 * @param[inout] pushButton The button in which all actors that form its appearance are going to be added.
127 * @param[in] label Button label.
129 void SetLabel( Toolkit::PushButton& pushButton, Actor label );
131 /////////////////////////////////////////////////////////////////////////////
132 // ButtonPainter interface
133 /////////////////////////////////////////////////////////////////////////////
136 * Initializes the painter by setting the default images.
138 * @param[inout] button The button in which all actors that form its appearance are going to be added.
140 void Initialize( Toolkit::Button& button );
145 * Resizes actors. It applies size constraints.
147 * @param[inout] button The button which stores button's images.
148 * @param[in] size The new size.
150 void SetSize( Toolkit::Button& button, const Vector3& size );
153 * This method is called when the \e disabled property in the Dali::Toolkit::PushButton changes.
155 * Creates image transitions if needed.
157 * @param[inout] button The button in which all actors that form its appearance are going to be added.
158 * @param[in] disabled property.
160 void SetDisabled( Toolkit::Button& button, bool disabled );
163 * Sets the animation time.
164 * @param[in] animationTime The animation time.
166 void SetAnimationTime( float animationTime );
169 * Retrieves the animation time.
170 * @return The animation time.
172 float GetAnimationTime() const;
174 /////////////////////////////////////////////////////////////////////////////
175 // PushButtonPainter interface
176 /////////////////////////////////////////////////////////////////////////////
179 * This method is called when the \e autorepeating property in the Dali::Toolkit::PushButton changes.
180 * @param[in] autorepeating property.
182 void SetAutoRepeating( bool autorepeating );
185 * This method is called when the Dali::Toolkit::Internal::PushButton in which this object is registered
186 * is pressed. It changes to the selected image with a transition.
188 * @param[inout] button The Dali::Toolkit::PushButton in which this object is registered.
190 void Pressed( Toolkit::PushButton& button );
193 * This method is called when the Dali::Toolkit::Internal::PushButton in which this object is registered
194 * is released. It changes to the button image with a transition.
196 * @param[inout] button The Dali::Toolkit::PushButton in which this object is registered.
198 void Released( Toolkit::PushButton& button );
201 * This method is called when the Dali::Toolkit::Internal::PushButton in which this object is registered
204 * @param[inout] button The Dali::Toolkit::PushButton in which this object is registered.
206 void Clicked( Toolkit::PushButton& button );
209 * This method is called when the Dali::Toolkit::Internal::PushButton in which this object is registered
212 * @param[inout] button The Dali::Toolkit::PushButton in which this object is registered.
214 void Toggled( Toolkit::PushButton& button );
219 PushButtonDefaultPainter( const PushButtonDefaultPainter& );
222 PushButtonDefaultPainter& operator=( const PushButtonDefaultPainter& );
227 * Default push button painter states.
231 ReleasedState, ///< The push button is released.
232 PressedState, ///< The push button is pressed.
233 DisabledReleasedState, ///< The push button is disabled and released.
234 DisabledPressedState, ///< The push button is Disabled and pressed.
235 ReleasedPressedTransition, ///< The push button is in transition from released to pressed.
236 PressedReleasedTransition, ///< The push button is in transition from pressed to released.
237 ReleasedDisabledTransition, ///< The push button is in transition from released to disabled.
238 DisabledReleasedTransition, ///< The push button is in transition from disabled to released.
239 PressedDisabledTransition, ///< The push button is in transition from pressed to disabled.
240 DisabledPressedTransition ///< The push button is in transition from disabled to pressed.
244 * Used in the FadeOut functions.
248 Background, ///< Fade out the background.
249 Foreground ///< Fade out the foreground.
254 * Apply size and position constraints to painter actors.
256 * @param[inout] actor The actor.
257 * @param[in] depth Depth position.
259 void ApplyConstraint( Actor& actor, float depth );
262 * Adds the actor to the fade in animation. It creates a fade in animation if needed.
264 * @param[in] actor The actor.
266 void AddToFadeInAnimation( const Actor& actor );
269 * Starts the fade in animation.
271 * PushButtonDefaultPainter::PressedReleasedFadeInAnimationFinished slot is called when the animation finishes.
273 void StartFadeInAnimation();
276 * Stops the fade in animation.
278 void StopFadeInAnimation();
281 * Adds the actor to the fade out animation. It creates a fade out animation if needed.
283 void AddToFadeOutAnimation( const Actor& actor );
286 * Starts the fade out animation.
288 * PushButtonDefaultPainter::PressedReleasedFadeOutAnimationFinished slot is called when the animation finishes.
289 * @param[inout] pushButton The button which holds images.
291 void StartFadeOutAnimation( Toolkit::PushButton& pushButton );
294 * Stops the fade out animation.
296 * It removes the actor stored in PushButtonDefaultPainter::mFadeOutBackgroundImage and
297 * PushButtonDefaultPainter::mFadeOutCheckedImage.
299 * @param[inout] pushButton The button which holds images.
300 * @param[in] remove If true, removes the fadeout actor from root.
302 void StopFadeOutAnimation( Toolkit::PushButton& pushButton, bool remove = true );
305 * It adds the actor to the root actor and to the fade in animation.
307 * @param[inout] pushButton The button which holds images.
308 * @param[inout] image The actor.
309 * @param[in] opacity The initial opacity.
311 void FadeInImage( Toolkit::PushButton& pushButton, Actor& image, float opacity = 0.f );
314 * It adds the actor fade out animation and stores it to be removed when the animation finishes.
315 * @param[inout] pushButton The button which holds images.
316 * @param[in] layer Defines if the actor is going to be stored in the mFadeOutBackgroundImage or mFadeOutCheckedImage member.
317 * @param[inout] image The actor.
318 * @param[in] opacity The initial opacity.
320 void FadeOutImage( Toolkit::PushButton& pushButton, ImageLayer layer, Actor& image, float opacity = 1.f );
325 * Called when the fade out animation finishes.
327 * It changes the check button painter state and removes actors from the root.
329 void PressedReleasedFadeOutAnimationFinished( Dali::Animation& source );
332 * Called when the fade in animation finishes.
334 * It changes the check button painter state.
336 void PressedReleasedFadeInAnimationFinished( Dali::Animation& source );
339 bool mAutoRepeating; ///< Stores the autorepeating property.
340 bool mDisabled; ///< Stores the disabled property.
342 PaintState mPaintState; ///< The painter state.
343 Animation mFadeInAnimation; ///< Animation used in the state transitions.
344 Animation mFadeOutAnimation; ///< Animation used in the state transitions.
345 Internal::PushButton* mButton; ///< Temporary pointer used to remove fade out images from button.
346 float mAnimationTime; ///< The animation time.
347 Vector3 mSize; ///< The button's size.
350 } // namespace Internal
352 } // namespace Toolkit
356 #endif // __DALI_TOOLKIT_INTERNAL_PUSH_BUTTON_DEFAULT_PAINTER_H__