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/adaptor-framework/timer.h>
23 #include <dali/public-api/common/dali-vector.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();
54 * @copydoc Dali::Toolkit::PushButton::SetAutoRepeating( bool autoRepeating )
56 void SetAutoRepeating( bool autoRepeating );
59 * @copydoc Dali::Toolkit::PushButton::IsAutoRepeating() const
61 bool IsAutoRepeating() const;
64 * @copydoc Dali::Toolkit::PushButton::SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay )
66 void SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay );
69 * @copydoc Dali::Toolkit::PushButton::GetInitialAutoRepeatingDelay() const
71 float GetInitialAutoRepeatingDelay() const;
74 * @copydoc Dali::Toolkit::PushButton::SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay )
76 void SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay );
79 * @copydoc Dali::Toolkit::PushButton::GetNextAutoRepeatingDelay() const
81 float GetNextAutoRepeatingDelay() const;
84 * @copydoc Dali::Toolkit::PushButton::SetToggleButton( bool toggle )
86 void SetToggleButton( bool toggle );
89 * @copydoc Dali::Toolkit::PushButton::IsToggleButton() const
91 bool IsToggleButton() const;
94 * @copydoc Dali::Toolkit::PushButton::SetToggled( bool toggle )
96 void SetToggled( bool toggle );
99 * @copydoc Dali::Toolkit::PushButton::IsToggled() const
101 bool IsToggled() const;
104 * @copydoc Dali::Toolkit::PushButton::SetButtonImage( const Image image )
106 void SetButtonImage( Image image );
109 * @copydoc Dali::Toolkit::PushButton::SetButtonImage( Actor image )
111 void SetButtonImage( Actor image );
114 * Used by the painter only.
115 * @return A reference to the button image.
117 Actor& GetButtonImage();
120 * @copydoc Dali::Toolkit::PushButton::
122 Actor GetButtonImage() const;
125 * @copydoc Dali::Toolkit::PushButton::SetBackgroundImage( const Image image )
127 void SetBackgroundImage( Image image );
130 * @copydoc Dali::Toolkit::PushButton::SetBackgroundImage( Actor image )
132 void SetBackgroundImage( Actor image );
135 * Used by the painter only.
136 * @return A reference to the background image.
138 Actor& GetBackgroundImage();
141 * @copydoc Dali::Toolkit::PushButton::GetBackgroundImage()
143 Actor GetBackgroundImage() const;
146 * @copydoc Dali::Toolkit::PushButton::SetPressedImage( const Image image )
148 void SetPressedImage( Image image );
151 * @copydoc Dali::Toolkit::PushButton::SetPressedImage( Actor image )
153 void SetPressedImage( Actor image );
156 * Used by the painter only.
157 * @return A reference to the pressed image.
159 Actor& GetPressedImage();
162 * @copydoc Dali::Toolkit::PushButton::GetPressedImage()
164 Actor GetPressedImage() const;
167 * @copydoc Dali::Toolkit::PushButton::SetDimmedBackgroundImage( Image image )
169 void SetDimmedBackgroundImage( Image image );
172 * @copydoc Dali::Toolkit::PushButton::SetDimmedBackgroundImage( Actor image )
174 void SetDimmedBackgroundImage( Actor image );
177 * Used by the painter only.
178 * @return A reference to the dimmed background image.
180 Actor& GetDimmedBackgroundImage();
183 * @copydoc Dali::Toolkit::PushButton::GetDimmedBackgroundImage()
185 Actor GetDimmedBackgroundImage() const;
188 * @copydoc Dali::Toolkit::PushButton::SetDimmedImage( Image image )
190 void SetDimmedImage( Image image );
193 * @copydoc Dali::Toolkit::PushButton::SetDimmedImage( Actor image )
195 void SetDimmedImage( Actor image );
198 * Used by the painter only.
199 * @return A reference to the dimmed button image.
201 Actor& GetDimmedImage();
204 * @copydoc Dali::Toolkit::PushButton::GetDimmedImage()
206 Actor GetDimmedImage() const;
209 * @copydoc Dali::Toolkit::PushButton::SetLabelText( const std::string& text )
211 void SetLabelText( const std::string& text );
214 * @copydoc Dali::Toolkit::PushButton::SetLabelText( Actor text )
216 void SetLabelText( Actor text );
219 * Used by the painter only.
220 * @return A reference to the label actor.
225 * @copydoc Dali::Toolkit::PushButton::GetLabelText()
227 Actor GetLabelText() const;
230 * Used by the painter only.
231 * @return A reference to the background image that is fading out.
233 Actor& GetFadeOutBackgroundImage();
236 * Used by the painter only.
237 * @return A reference to the button image that is fading out.
239 Actor& GetFadeOutButtonImage();
246 * @copydoc Dali::Toolkit::PushButton::PressedSignal()
248 Toolkit::PushButton::PressedSignalV2& PressedSignal();
251 * @copydoc Dali::Toolkit::PushButton::ReleasedSignal()
253 Toolkit::PushButton::ReleasedSignalV2& ReleasedSignal();
256 * Connects a callback function with the object's signals.
257 * @param[in] object The object providing the signal.
258 * @param[in] tracker Used to disconnect the signal.
259 * @param[in] signalName The signal to connect to.
260 * @param[in] functor A newly allocated FunctorDelegate.
261 * @return True if the signal was connected.
262 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
264 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
269 * @copydoc Button::SetProperty
271 static void SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value );
274 * @copydoc Button::GetProperty
276 static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
278 protected: // From Button
281 * Sets the Leave signal.
283 virtual void OnButtonInitialize();
286 * Emits signals and notifies the painter accordingly with the set button
287 * properties when the button is pressed.
289 virtual void OnButtonDown();
292 * Emits signals and notifies the painter accordingly with the set button
293 * properties when the button is released.
295 virtual void OnButtonUp();
298 * Emits signals and notifies the painter accordingly with the set button
299 * properties when the touch point leaves the boundary of the button.
301 virtual void OnTouchPointLeave();
304 * Currently it doesn't need different behaviour than @see OnTouchPointLeave()
306 virtual void OnTouchPointInterrupted();
309 * Sets the push button animation time.
310 * @param animationTime The animation time in seconds.
312 virtual void OnAnimationTimeSet( float animationTime );
315 * Retrieves the animation time.
316 * @return The animation time in seconds.
318 virtual float OnAnimationTimeRequested() const;
321 * This method is called when the button is removed from the stage.
323 virtual void OnButtonStageDisconnection();
325 protected: // From Control
328 * Respond the activate notification.
330 virtual void OnActivated();
333 * @copydoc Control::GetNaturalSize()
335 virtual Vector3 GetNaturalSize();
340 * Perform the click action to click the button.
341 * @param[in] attributes The attributes to perfrom this action.
343 void DoClickAction(const PropertyValueContainer& attributes);
348 * Performs actions as requested using the action name.
349 * @param[in] object The object on which to perform the action.
350 * @param[in] actionName The action to perform.
351 * @param[in] attributes The attributes with which to perfrom this action.
352 * @return true if action has been accepted by this control
354 static bool DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes);
357 * Construct a new PushButton.
362 * A reference counted object may only be deleted by calling Unreference()
364 virtual ~PushButton();
369 PushButton( const PushButton& );
372 PushButton& operator=( const PushButton& );
375 * Sets up the autorepeating timer.
376 * @param[in] delay The delay time in seconds.
378 void SetUpTimer( float delay );
381 * Slot called when Dali::Timer::SignalTick signal. Resets the autorepeating timer.
383 bool AutoRepeatingSlot();
386 bool mAutoRepeating; ///< Stores the autorepeating property.
387 float mInitialAutoRepeatingDelay; ///< Stores the initial autorepeating delay in seconds.
388 float mNextAutoRepeatingDelay; ///< Stores the next autorepeating delay in seconds.
389 bool mToggleButton; ///< Stores the toggle property.
392 Timer mAutoRepeatingTimer; ///< Timer used to implement the autorepeating property.
395 bool mToggled; ///< Stores the toggle state.
398 Toolkit::PushButton::PressedSignalV2 mPressedSignalV2; ///< Signal emitted when the button is pressed.
399 Toolkit::PushButton::ReleasedSignalV2 mReleasedSignalV2; ///< Signal emitted when the button is released.
401 Actor mButtonImage; ///< Stores the released image.
402 Actor mBackgroundImage; ///< Stores the background image.
403 Actor mPressedImage; ///< Stores the pressed image.
404 Actor mDimmedImage; ///< Stores the dimmed image.
405 Actor mDimmedBackgroundImage; ///< Stores the dimmed background image.
407 Actor mLabel; ///< Stores the text label.
409 Actor mFadeOutBackgroundImage; ///< Stores a background image, which is in a fade out animation, to be removed when the animation finishes.
410 Actor mFadeOutButtonImage; ///< Stores a foreground image, which is in a fade out animation, to be removed when the animation finishes.
413 bool mClickActionPerforming;
416 } // namespace Internal
418 // Helpers for public-api forwarding methods
420 inline Toolkit::Internal::PushButton& GetImplementation( Toolkit::PushButton& button )
422 DALI_ASSERT_ALWAYS( button );
424 Dali::RefObject& handle = button.GetImplementation();
426 return static_cast<Toolkit::Internal::PushButton&>( handle );
429 inline const Toolkit::Internal::PushButton& GetImplementation( const Toolkit::PushButton& button )
431 DALI_ASSERT_ALWAYS( button );
433 const Dali::RefObject& handle = button.GetImplementation();
435 return static_cast<const Toolkit::Internal::PushButton&>( handle );
438 } // namespace Toolkit
442 #endif // __DALI_TOOLKIT_INTERNAL_PUSH_BUTTON_H__