1 #ifndef __DALI_TOOLKIT_INTERNAL_CHECK_BOX_BUTTON_DEFAULT_PAINTER_H__
2 #define __DALI_TOOLKIT_INTERNAL_CHECK_BOX_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>
26 #include <dali-toolkit/public-api/shader-effects/image-region-effect.h>
28 #include "check-box-button-painter-impl.h"
39 // Forward declarations
42 class CheckBoxButtonDefaultPainter;
46 typedef IntrusivePtr<CheckBoxButtonDefaultPainter> CheckBoxButtonDefaultPainterPtr;
49 * CheckBoxButtonDefaultPainter controls the Dali::Toolkit::CheckBoxButton appearance.
51 * This class inherits from Dali::Toolkit::Internal::CheckBoxButtonPainter and is registered in a
52 * Dali::Toolkit::Internal::CheckBoxButton object in order to receive the state changes.
54 class CheckBoxButtonDefaultPainter : public CheckBoxButtonPainter
60 * Set actors and animations to NULL.
62 CheckBoxButtonDefaultPainter();
67 * It clears all fade in or fade out animations.
69 ~CheckBoxButtonDefaultPainter();
72 * Sets the background image.
74 * It adds the background image to the root actor and creates the image transition if needed.
76 * @param[inout] checkBox The button in which all actors that form its appearance are going to be added.
77 * @param[in] image The background image.
79 void SetBackgroundImage( Toolkit::CheckBoxButton& checkBox, Actor image );
82 * Sets the checked image.
84 * It adds the checked image to the root actor and creates the image transition if needed.
86 * @param[inout] checkBox The button in which all actors that form its appearance are going to be added.
87 * @param[in] image The checked image.
89 void SetCheckedImage( Toolkit::CheckBoxButton& checkBox, Actor image );
92 * Sets the dimmed backgroundimage.
94 * It adds the dimmed backgroundimage to the root actor and creates the image transition if needed.
96 * @param[inout] checkBox The button in which all actors that form its appearance are going to be added.
97 * @param[in] image The dimmed backgroundimage.
99 void SetDimmedBackgroundImage( Toolkit::CheckBoxButton& checkBox, Actor image );
102 * Sets the dimmed checked image.
104 * It adds the dimmed checked image to the root actor and creates the image transition if needed.
106 * @param[inout] checkBox The button in which all actors that form its appearance are going to be added.
107 * @param[in] image The dimmed checked image.
109 void SetDimmedCheckedImage( Toolkit::CheckBoxButton& checkBox, Actor image );
111 /////////////////////////////////////////////////////////////////////////////
112 // ButtonPainter interface
113 /////////////////////////////////////////////////////////////////////////////
116 * Initializes the painter by setting the default images.
118 * @param[inout] button The button in which all actors that form its appearance are going to be added.
120 void Initialize( Toolkit::Button& button );
125 * Resizes images. It applies size constraints.
127 * @param[inout] button The button which stores button's images.
128 * @param[in] size The new size.
130 void SetSize( Toolkit::Button& button, const Vector3& size );
133 * Changes the Vega::Toolkit::CheckBoxButton for the given dimmed state.
135 * It creates the image transition if needed.
137 * @param[inout] button The button in which all actors that form its appearance are going to be added.
138 * @param[in] dimmed The dimmed state.
140 void SetDimmed( Toolkit::Button& button, bool dimmed );
143 * Sets the animation time.
144 * @param[in] animationTime The animation time.
146 void SetAnimationTime( float animationTime );
149 * Retrieves the animation time.
150 * @return The animation time.
152 float GetAnimationTime() const;
154 /////////////////////////////////////////////////////////////////////////////
155 // CheckBoxButtonPainter interface
156 /////////////////////////////////////////////////////////////////////////////
159 * This method is called when the Dali::Toolkit::Internal::CheckBoxButton in which this object is registered
162 * @param[inout] checkBox The Dali::Toolkit::CheckBoxButton in which this object is registered.
164 void Checked( Toolkit::CheckBoxButton& checkBox );
169 CheckBoxButtonDefaultPainter( const CheckBoxButtonDefaultPainter& );
172 CheckBoxButtonDefaultPainter& operator=( const CheckBoxButtonDefaultPainter& );
177 * Default check box button painter states.
181 UncheckedState, ///< The check box button is unchecked.
182 CheckedState, ///< The check box button is checked.
183 DimmedUncheckedState, ///< The check box button is dimmed and unchecked.
184 DimmedCheckedState, ///< The check box button is dimmed and checked.
185 UncheckedCheckedTransition, ///< The check box button is in transition from unchecked to checked.
186 CheckedUncheckedTransition, ///< The check box button is in transition from checked to unchecked.
187 UncheckedDimmedTransition, ///< The check box button is in transition from unchecked to dimmed.
188 DimmedUncheckedTransition, ///< The check box button is in transition from dimmed to unchecked.
189 CheckedDimmedTransition, ///< The check box button is in transition from checked to dimmed.
190 DimmedCheckedTransition ///< The check box button is in transition from dimmed to checked.
194 * Used in the FadeOut functions.
198 Background, ///< Fade out the background.
199 Foreground ///< Fade out the foreground.
204 * Apply size and position constraints to painter actors.
206 * @param[inout] actor The actor.
207 * @param[in] depth Depth position.
209 void ApplyConstraint( Actor& actor, float depth );
212 * Apply size constraint to check tick
214 * @param[inout] actor The actor.
215 * @param[in] depth Depth position.
217 void ApplyCheckedConstraint( Actor& actor, float depth );
220 * Adds the actor to the fade in animation. It creates a fade in animation if needed.
222 * @param[in] actor The actor.
224 void AddToFadeInAnimation( const Actor& actor );
227 * Starts the check in animation.
229 * CheckBoxButtonDefaultPainter::CheckInAnimationFinished slot is called when the animation finishes.
231 void StartCheckInAnimation();
234 * Stops the check in animation.
236 void StopCheckInAnimation();
239 * Adds the actor to the fade out animation. It creates a fade out animation if needed.
241 * @param[in] actor The actor.
243 void AddToFadeOutAnimation( const Actor& actor );
246 * Starts the check out animation.
248 * CheckBoxButtonDefaultPainter::CheckOutAnimationFinished slot is called when the animation finishes.
250 * @param[inout] checkBox The button which holds images.
252 void StartCheckOutAnimation( Toolkit::CheckBoxButton& checkBox );
255 * Stops the fade out animation.
257 * It removes the actor stored in CheckBoxButtonDefaultPainter::mFadeOutBackgroundImage and
258 * CheckBoxButtonDefaultPainter::mFadeOutCheckedImage.
260 * @param[inout] checkBox The button which holds images.
261 * @param[in] remove If true, removes the fadeout actor from root.
263 void StopCheckOutAnimation( Toolkit::CheckBoxButton& checkBox, bool remove = true );
266 * It adds the actor to the root actor and to the fade in animation.
268 * @param[inout] checkBox The button which holds images.
269 * @param[inout] image The actor.
270 * @param[in] opacity The initial opacity.
272 void FadeInImage( Toolkit::CheckBoxButton& checkBox, Actor& image, float opacity = 0.f );
275 * It adds the actor fade out animation and stores it to be removed when the animation finishes.
277 * @param[inout] checkBox The button which holds images.
278 * @param[in] layer Defines if the actor is going to be stored in the mFadeOutBackgroundImage or mFadeOutCheckedImage member.
279 * @param[inout] image The actor.
280 * @param[in] opacity The initial opacity.
282 void FadeOutImage( Toolkit::CheckBoxButton& checkBox, ImageLayer layer, Actor& image, float opacity = 1.f );
285 * Adds the actor to the fade in animation. It creates a fade in animation if needed.
287 * @param[in] actor The actor.
289 void AddToCheckInAnimation( const Actor& actor );
292 * It adds the actor to the root actor and to the fade in animation.
294 * @param[inout] checkBox The button which holds images.
295 * @param[inout] image The actor.
297 void SetupCheckedAnimation( Toolkit::CheckBoxButton& checkBox, Actor& image );
300 * Signal end of check out animation
302 void EndCheckOutAnimation();
307 * Called when the fade out animation finishes.
309 * It changes the check button painter state and removes actors from the root.
311 void CheckOutAnimationFinished( Dali::Animation& source );
314 * Called when the fade in animation finishes.
316 * It changes the check button painter state.
318 void CheckInAnimationFinished( Dali::Animation& source );
321 bool mDimmed; ///< Stores the dimmed property.
323 PaintState mPaintState; ///< The painter state.
325 Animation mCheckInAnimation; ///< Animation used in the state transitions.
326 Animation mCheckOutAnimation; ///< Animation used in the state transitions.
327 Internal::CheckBoxButton* mButton; ///< Temporary pointer used to remove fade out images from button.
328 float mAnimationTime; ///< The animation time.
330 ImageRegionEffect mTickUVEffect; ///< ImageRegionEffect to expand the tick across
332 Property::Index mPercentageParentSizeProperty; ///< Dynamic property on the image actor
335 } // namespace Internal
337 } // namespace Toolkit
341 #endif // __DALI_TOOLKIT_INTERNAL_CHECK_BOX_BUTTON_DEFAULT_PAINTER_H__