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 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>
25 #include <dali-toolkit/public-api/shader-effects/image-region-effect.h>
27 #include "check-box-button-painter-impl.h"
38 // Forward declarations
41 class CheckBoxButtonDefaultPainter;
45 typedef IntrusivePtr<CheckBoxButtonDefaultPainter> CheckBoxButtonDefaultPainterPtr;
48 * CheckBoxButtonDefaultPainter controls the Dali::Toolkit::CheckBoxButton appearance.
50 * This class inherits from Dali::Toolkit::Internal::CheckBoxButtonPainter and is registered in a
51 * Dali::Toolkit::Internal::CheckBoxButton object in order to receive the state changes.
53 class CheckBoxButtonDefaultPainter : public CheckBoxButtonPainter
59 * Set actors and animations to NULL.
61 CheckBoxButtonDefaultPainter();
66 * It clears all fade in or fade out animations.
68 ~CheckBoxButtonDefaultPainter();
71 * Sets the background image.
73 * It adds the background image to the root actor and creates the image transition if needed.
75 * @param[inout] checkBox The button in which all actors that form its appearance are going to be added.
76 * @param[in] image The background image.
78 void SetBackgroundImage( Toolkit::CheckBoxButton& checkBox, Actor image );
81 * Sets the checked image.
83 * It adds the checked image to the root actor and creates the image transition if needed.
85 * @param[inout] checkBox The button in which all actors that form its appearance are going to be added.
86 * @param[in] image The checked image.
88 void SetCheckedImage( Toolkit::CheckBoxButton& checkBox, Actor image );
91 * Sets the dimmed backgroundimage.
93 * It adds the dimmed backgroundimage to the root actor and creates the image transition if needed.
95 * @param[inout] checkBox The button in which all actors that form its appearance are going to be added.
96 * @param[in] image The dimmed backgroundimage.
98 void SetDimmedBackgroundImage( Toolkit::CheckBoxButton& checkBox, Actor image );
101 * Sets the dimmed checked image.
103 * It adds the dimmed checked image to the root actor and creates the image transition if needed.
105 * @param[inout] checkBox The button in which all actors that form its appearance are going to be added.
106 * @param[in] image The dimmed checked image.
108 void SetDimmedCheckedImage( Toolkit::CheckBoxButton& checkBox, Actor image );
110 /////////////////////////////////////////////////////////////////////////////
111 // ButtonPainter interface
112 /////////////////////////////////////////////////////////////////////////////
115 * Initializes the painter by setting the default images.
117 * @param[inout] button The button in which all actors that form its appearance are going to be added.
119 void Initialize( Toolkit::Button& button );
124 * Resizes images. It applies size constraints.
126 * @param[inout] button The button which stores button's images.
127 * @param[in] size The new size.
129 void SetSize( Toolkit::Button& button, const Vector3& size );
132 * Changes the Vega::Toolkit::CheckBoxButton for the given dimmed state.
134 * It creates the image transition if needed.
136 * @param[inout] button The button in which all actors that form its appearance are going to be added.
137 * @param[in] dimmed The dimmed state.
139 void SetDimmed( Toolkit::Button& button, bool dimmed );
142 * Sets the animation time.
143 * @param[in] animationTime The animation time.
145 void SetAnimationTime( float animationTime );
148 * Retrieves the animation time.
149 * @return The animation time.
151 float GetAnimationTime() const;
153 /////////////////////////////////////////////////////////////////////////////
154 // CheckBoxButtonPainter interface
155 /////////////////////////////////////////////////////////////////////////////
158 * This method is called when the Dali::Toolkit::Internal::CheckBoxButton in which this object is registered
161 * @param[inout] checkBox The Dali::Toolkit::CheckBoxButton in which this object is registered.
163 void Checked( Toolkit::CheckBoxButton& checkBox );
168 CheckBoxButtonDefaultPainter( const CheckBoxButtonDefaultPainter& );
171 CheckBoxButtonDefaultPainter& operator=( const CheckBoxButtonDefaultPainter& );
176 * Default check box button painter states.
180 UncheckedState, ///< The check box button is unchecked.
181 CheckedState, ///< The check box button is checked.
182 DimmedUncheckedState, ///< The check box button is dimmed and unchecked.
183 DimmedCheckedState, ///< The check box button is dimmed and checked.
184 UncheckedCheckedTransition, ///< The check box button is in transition from unchecked to checked.
185 CheckedUncheckedTransition, ///< The check box button is in transition from checked to unchecked.
186 UncheckedDimmedTransition, ///< The check box button is in transition from unchecked to dimmed.
187 DimmedUncheckedTransition, ///< The check box button is in transition from dimmed to unchecked.
188 CheckedDimmedTransition, ///< The check box button is in transition from checked to dimmed.
189 DimmedCheckedTransition ///< The check box button is in transition from dimmed to checked.
193 * Used in the FadeOut functions.
197 Background, ///< Fade out the background.
198 Foreground ///< Fade out the foreground.
203 * Apply size and position constraints to painter actors.
205 * @param[inout] actor The actor.
206 * @param[in] depth Depth position.
208 void ApplyConstraint( Actor& actor, float depth );
211 * Apply size constraint to check tick
213 * @param[inout] actor The actor.
214 * @param[in] depth Depth position.
216 void ApplyCheckedConstraint( Actor& actor, float depth );
219 * Adds the actor to the fade in animation. It creates a fade in animation if needed.
221 * @param[in] actor The actor.
223 void AddToFadeInAnimation( const Actor& actor );
226 * Starts the check in animation.
228 * CheckBoxButtonDefaultPainter::CheckInAnimationFinished slot is called when the animation finishes.
230 void StartCheckInAnimation();
233 * Stops the check in animation.
235 void StopCheckInAnimation();
238 * Adds the actor to the fade out animation. It creates a fade out animation if needed.
240 * @param[in] actor The actor.
242 void AddToFadeOutAnimation( const Actor& actor );
245 * Starts the check out animation.
247 * CheckBoxButtonDefaultPainter::CheckOutAnimationFinished slot is called when the animation finishes.
249 * @param[inout] checkBox The button which holds images.
251 void StartCheckOutAnimation( Toolkit::CheckBoxButton& checkBox );
254 * Stops the fade out animation.
256 * It removes the actor stored in CheckBoxButtonDefaultPainter::mFadeOutBackgroundImage and
257 * CheckBoxButtonDefaultPainter::mFadeOutCheckedImage.
259 * @param[inout] checkBox The button which holds images.
260 * @param[in] remove If true, removes the fadeout actor from root.
262 void StopCheckOutAnimation( Toolkit::CheckBoxButton& checkBox, bool remove = true );
265 * It adds the actor to the root actor and to the fade in animation.
267 * @param[inout] checkBox The button which holds images.
268 * @param[inout] image The actor.
269 * @param[in] opacity The initial opacity.
271 void FadeInImage( Toolkit::CheckBoxButton& checkBox, Actor& image, float opacity = 0.f );
274 * It adds the actor fade out animation and stores it to be removed when the animation finishes.
276 * @param[inout] checkBox The button which holds images.
277 * @param[in] layer Defines if the actor is going to be stored in the mFadeOutBackgroundImage or mFadeOutCheckedImage member.
278 * @param[inout] image The actor.
279 * @param[in] opacity The initial opacity.
281 void FadeOutImage( Toolkit::CheckBoxButton& checkBox, ImageLayer layer, Actor& image, float opacity = 1.f );
284 * Adds the actor to the fade in animation. It creates a fade in animation if needed.
286 * @param[in] actor The actor.
288 void AddToCheckInAnimation( const Actor& actor );
291 * It adds the actor to the root actor and to the fade in animation.
293 * @param[inout] checkBox The button which holds images.
294 * @param[inout] image The actor.
296 void SetupCheckedAnimation( Toolkit::CheckBoxButton& checkBox, Actor& image );
299 * Signal end of check out animation
301 void EndCheckOutAnimation();
306 * Called when the fade out animation finishes.
308 * It changes the check button painter state and removes actors from the root.
310 void CheckOutAnimationFinished( Dali::Animation& source );
313 * Called when the fade in animation finishes.
315 * It changes the check button painter state.
317 void CheckInAnimationFinished( Dali::Animation& source );
320 bool mDimmed; ///< Stores the dimmed property.
322 PaintState mPaintState; ///< The painter state.
324 Animation mCheckInAnimation; ///< Animation used in the state transitions.
325 Animation mCheckOutAnimation; ///< Animation used in the state transitions.
326 Internal::CheckBoxButton* mButton; ///< Temporary pointer used to remove fade out images from button.
327 float mAnimationTime; ///< The animation time.
329 ImageRegionEffect mTickUVEffect; ///< ImageRegionEffect to expand the tick across
331 Property::Index mPercentageParentSizeProperty; ///< Dynamic property on the image actor
334 } // namespace Internal
336 } // namespace Toolkit
340 #endif // __DALI_TOOLKIT_INTERNAL_CHECK_BOX_BUTTON_DEFAULT_PAINTER_H__