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/common/dali-vector.h>
24 #include <dali-toolkit/public-api/controls/buttons/push-button.h>
26 #include "button-impl.h"
38 * PushButton implementation class.
40 * \sa Dali::Toolkit::PushButton
42 class PushButton : public Button
47 * Create a new PushButton.
48 * @return A smart-pointer to the newly allocated PushButton.
50 static Dali::Toolkit::PushButton New();
53 * @copydoc Dali::Toolkit::PushButton::SetAutoRepeating( bool autoRepeating )
55 void SetAutoRepeating( bool autoRepeating );
58 * @copydoc Dali::Toolkit::PushButton::IsAutoRepeating() const
60 bool IsAutoRepeating() const;
63 * @copydoc Dali::Toolkit::PushButton::SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay )
65 void SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay );
68 * @copydoc Dali::Toolkit::PushButton::GetInitialAutoRepeatingDelay() const
70 float GetInitialAutoRepeatingDelay() const;
73 * @copydoc Dali::Toolkit::PushButton::SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay )
75 void SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay );
78 * @copydoc Dali::Toolkit::PushButton::GetNextAutoRepeatingDelay() const
80 float GetNextAutoRepeatingDelay() const;
83 * @copydoc Dali::Toolkit::PushButton::SetToggleButton( bool toggle )
85 void SetToggleButton( bool toggle );
88 * @copydoc Dali::Toolkit::PushButton::IsToggleButton() const
90 bool IsToggleButton() const;
93 * @copydoc Dali::Toolkit::PushButton::SetToggled( bool toggle )
95 void SetToggled( bool toggle );
98 * @copydoc Dali::Toolkit::PushButton::IsToggled() const
100 bool IsToggled() const;
103 * @copydoc Dali::Toolkit::PushButton::SetButtonImage( const Image image )
105 void SetButtonImage( Image image );
108 * @copydoc Dali::Toolkit::PushButton::SetButtonImage( Actor image )
110 void SetButtonImage( Actor image );
113 * Used by the painter only.
114 * @return A reference to the button image.
116 Actor& GetButtonImage();
119 * @copydoc Dali::Toolkit::PushButton::
121 Actor GetButtonImage() const;
124 * @copydoc Dali::Toolkit::PushButton::SetBackgroundImage( const Image image )
126 void SetBackgroundImage( Image image );
129 * @copydoc Dali::Toolkit::PushButton::SetBackgroundImage( Actor image )
131 void SetBackgroundImage( Actor image );
134 * Used by the painter only.
135 * @return A reference to the background image.
137 Actor& GetBackgroundImage();
140 * @copydoc Dali::Toolkit::PushButton::GetBackgroundImage()
142 Actor GetBackgroundImage() const;
145 * @copydoc Dali::Toolkit::PushButton::SetPressedImage( const Image image )
147 void SetPressedImage( Image image );
150 * @copydoc Dali::Toolkit::PushButton::SetPressedImage( Actor image )
152 void SetPressedImage( Actor image );
155 * Used by the painter only.
156 * @return A reference to the pressed image.
158 Actor& GetPressedImage();
161 * @copydoc Dali::Toolkit::PushButton::GetPressedImage()
163 Actor GetPressedImage() const;
166 * @copydoc Dali::Toolkit::PushButton::SetDimmedBackgroundImage( Image image )
168 void SetDimmedBackgroundImage( Image image );
171 * @copydoc Dali::Toolkit::PushButton::SetDimmedBackgroundImage( Actor image )
173 void SetDimmedBackgroundImage( Actor image );
176 * Used by the painter only.
177 * @return A reference to the dimmed background image.
179 Actor& GetDimmedBackgroundImage();
182 * @copydoc Dali::Toolkit::PushButton::GetDimmedBackgroundImage()
184 Actor GetDimmedBackgroundImage() const;
187 * @copydoc Dali::Toolkit::PushButton::SetDimmedImage( Image image )
189 void SetDimmedImage( Image image );
192 * @copydoc Dali::Toolkit::PushButton::SetDimmedImage( Actor image )
194 void SetDimmedImage( Actor image );
197 * Used by the painter only.
198 * @return A reference to the dimmed button image.
200 Actor& GetDimmedImage();
203 * @copydoc Dali::Toolkit::PushButton::GetDimmedImage()
205 Actor GetDimmedImage() const;
208 * @copydoc Dali::Toolkit::PushButton::SetLabelText( const std::string& text )
210 void SetLabelText( const std::string& text );
213 * @copydoc Dali::Toolkit::PushButton::SetLabelText( Actor text )
215 void SetLabelText( Actor text );
218 * Used by the painter only.
219 * @return A reference to the label actor.
224 * @copydoc Dali::Toolkit::PushButton::GetLabelText()
226 Actor GetLabelText() const;
229 * Used by the painter only.
230 * @return A reference to the background image that is fading out.
232 Actor& GetFadeOutBackgroundImage();
235 * Used by the painter only.
236 * @return A reference to the button image that is fading out.
238 Actor& GetFadeOutButtonImage();
245 * @copydoc Dali::Toolkit::PushButton::PressedSignal()
247 Toolkit::PushButton::PressedSignalV2& PressedSignal();
250 * @copydoc Dali::Toolkit::PushButton::ReleasedSignal()
252 Toolkit::PushButton::ReleasedSignalV2& ReleasedSignal();
255 * Connects a callback function with the object's signals.
256 * @param[in] object The object providing the signal.
257 * @param[in] tracker Used to disconnect the signal.
258 * @param[in] signalName The signal to connect to.
259 * @param[in] functor A newly allocated FunctorDelegate.
260 * @return True if the signal was connected.
261 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
263 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
268 * @copydoc Button::SetProperty
270 static void SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value );
273 * @copydoc Button::GetProperty
275 static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
277 protected: // From Button
280 * Sets the Leave signal.
282 virtual void OnButtonInitialize();
285 * Emits signals and notifies the painter accordingly with the set button
286 * properties when the button is pressed.
288 virtual void OnButtonDown();
291 * Emits signals and notifies the painter accordingly with the set button
292 * properties when the button is released.
294 virtual void OnButtonUp();
297 * Emits signals and notifies the painter accordingly with the set button
298 * properties when the touch point leaves the boundary of the button.
300 virtual void OnTouchPointLeave();
303 * Currently it doesn't need different behaviour than @see OnTouchPointLeave()
305 virtual void OnTouchPointInterrupted();
308 * Sets the push button animation time.
309 * @param animationTime The animation time in seconds.
311 virtual void OnAnimationTimeSet( float animationTime );
314 * Retrieves the animation time.
315 * @return The animation time in seconds.
317 virtual float OnAnimationTimeRequested() const;
319 protected: // From Control
322 * Respond the activate notification.
324 virtual void OnActivated();
327 * @copydoc Control::GetNaturalSize()
329 virtual Vector3 GetNaturalSize();
334 * Perform the click action to click the button.
335 * @param[in] attributes The attributes to perfrom this action.
337 void DoClickAction(const PropertyValueContainer& attributes);
342 * Performs actions as requested using the action name.
343 * @param[in] object The object on which to perform the action.
344 * @param[in] actionName The action to perform.
345 * @param[in] attributes The attributes with which to perfrom this action.
346 * @return true if action has been accepted by this control
348 static bool DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes);
351 * Construct a new PushButton.
356 * A reference counted object may only be deleted by calling Unreference()
358 virtual ~PushButton();
363 PushButton( const PushButton& );
366 PushButton& operator=( const PushButton& );
369 * Sets up the autorepeating timer.
370 * @param[in] delay The delay time in seconds.
372 void SetUpTimer( float delay );
375 * Slot called when Dali::Timer::SignalTick signal. Resets the autorepeating timer.
377 bool AutoRepeatingSlot();
380 bool mAutoRepeating; ///< Stores the autorepeating property.
381 float mInitialAutoRepeatingDelay; ///< Stores the initial autorepeating delay in seconds.
382 float mNextAutoRepeatingDelay; ///< Stores the next autorepeating delay in seconds.
383 bool mToggleButton; ///< Stores the toggle property.
386 Timer mAutoRepeatingTimer; ///< Timer used to implement the autorepeating property.
389 bool mToggled; ///< Stores the toggle state.
392 Toolkit::PushButton::PressedSignalV2 mPressedSignalV2; ///< Signal emitted when the button is pressed.
393 Toolkit::PushButton::ReleasedSignalV2 mReleasedSignalV2; ///< Signal emitted when the button is released.
395 Actor mButtonImage; ///< Stores the released image.
396 Actor mBackgroundImage; ///< Stores the background image.
397 Actor mPressedImage; ///< Stores the pressed image.
398 Actor mDimmedImage; ///< Stores the dimmed image.
399 Actor mDimmedBackgroundImage; ///< Stores the dimmed background image.
401 Actor mLabel; ///< Stores the text label.
403 Actor mFadeOutBackgroundImage; ///< Stores a background image, which is in a fade out animation, to be removed when the animation finishes.
404 Actor mFadeOutButtonImage; ///< Stores a foreground image, which is in a fade out animation, to be removed when the animation finishes.
407 bool mClickActionPerforming;
410 } // namespace Internal
412 // Helpers for public-api forwarding methods
414 inline Toolkit::Internal::PushButton& GetImplementation( Toolkit::PushButton& button )
416 DALI_ASSERT_ALWAYS( button );
418 Dali::RefObject& handle = button.GetImplementation();
420 return static_cast<Toolkit::Internal::PushButton&>( handle );
423 inline const Toolkit::Internal::PushButton& GetImplementation( const Toolkit::PushButton& button )
425 DALI_ASSERT_ALWAYS( button );
427 const Dali::RefObject& handle = button.GetImplementation();
429 return static_cast<const Toolkit::Internal::PushButton&>( handle );
432 } // namespace Toolkit
436 #endif // __DALI_TOOLKIT_INTERNAL_PUSH_BUTTON_H__