1 #ifndef __DALI_TOOLKIT_INTERNAL_BUTTON_H__
2 #define __DALI_TOOLKIT_INTERNAL_BUTTON_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/dali.h>
22 #include <dali-toolkit/public-api/controls/buttons/button.h>
23 #include <dali-toolkit/public-api/controls/control-impl.h>
24 #include "button-painter-impl.h"
38 * Button is the base class implementation for all buttons.
40 class Button : public ControlImpl
46 * Construct a new Button.
51 * A reference counted object may only be deleted by calling Unreference()
58 * @copydoc Dali::Toolkit::Button::SetDimmed( bool dimmed )
60 void SetDimmed( bool dimmed );
63 * @copydoc Dali::Toolkit::Button::IsDimmed() const
65 bool IsDimmed() const;
68 * @copydoc Dali::Toolkit::Button::SetAnimationTime()
70 void SetAnimationTime( float animationTime );
73 * @copydoc Dali::Toolkit::Button::GetAnimationTime()
75 float GetAnimationTime() const;
80 * This method is called after the button initialization.
81 * Could be reimplemented in subclasses to provide specific behaviour.
83 virtual void OnButtonInitialize() { }
86 * This method is called from the OnTouchEvent method when the button is down.
87 * Could be reimplemented in subclasses to provide specific behaviour.
89 virtual void OnButtonDown() { }
92 * This method is called from the OnTouchEvent method when the button is up.
93 * Could be reimplemented in subclasses to provide specific behaviour.
95 virtual void OnButtonUp() { }
98 * This method is called from the OnTouchEvent method when the touch point leaves the boundary of the button or
99 * more than one touch points are received.
100 * Could be reimplemented in subclasses to provide specific behaviour.
102 virtual void OnTouchPointLeave() { }
105 * This method is called from the OnTouchEvent method when the touch point is interrupted.
106 * Could be reimplemented in subclasses to provide specific behaviour.
108 virtual void OnTouchPointInterrupted() { }
111 * This method is called when the animation time is set.
112 * Needs to be reimplemented in subclasses to set the animation time in different buttons.
113 * @param animationTime The animation time in seconds.
115 virtual void OnAnimationTimeSet( float animationTime );
118 * This method is called when the animation time is requested.
119 * Needs to be reimplemented in subclases to return the animation time.
120 * @return The animation time in seconds.
122 virtual float OnAnimationTimeRequested() const;
127 * @copydoc Dali::Toolkit::Button::ClickedSignal()
129 Toolkit::Button::ClickedSignalV2& ClickedSignal();
132 * Connects a callback function with the object's signals.
133 * @param[in] object The object providing the signal.
134 * @param[in] tracker Used to disconnect the signal.
135 * @param[in] signalName The signal to connect to.
136 * @param[in] functor A newly allocated FunctorDelegate.
137 * @return True if the signal was connected.
138 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
140 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
142 protected: // From CustomActorImpl
145 * @copydoc Dali::CustomActorImpl::OnTouchEvent( const TouchEvent& event )
147 virtual bool OnTouchEvent( const TouchEvent& event );
149 private: // From ControlImpl
152 * @copydoc Toolkit::Control::OnInitialize()
154 virtual void OnInitialize();
157 * @copydoc Toolkit::Control::OnControlSizeSet( const Vector3& targetSize )
159 virtual void OnControlSizeSet( const Vector3& targetSize );
162 * @copydoc Dali::CustomActorImpl::OnPropertySet()
164 virtual void OnPropertySet( Property::Index index, Property::Value propertyValue );
169 * Handler for tap events.
170 * We do not actually do anything when we receive a tap as the button handles tap event through
171 * the touch event system itself as it requires more than just tap handling (e.g. leave events).
172 * This stops any of our parents receiving a tap gesture when it occurs within our area.
173 * @param[in] actor The tapped actor.
174 * @param[in] tap The tap gesture.
176 void OnTap(Actor actor, TapGesture tap);
181 * Callback received when the button is disconected from the stage.
182 * It resets the button status.
184 void OnStageDisconnection();
189 Button( const Button& );
192 Button& operator = ( const Button& );
194 protected: // Signals
198 ButtonUp, ///< The button is up.
199 ButtonDown, ///< The button is down.
202 ButtonState mState; ///< Stores the button state.
204 bool mDimmed; ///< Stores the dimmed property.
206 ButtonPainterPtr mPainter; ///< Pointer to a ButtonPainter base class.
208 Toolkit::Button::ClickedSignalV2 mClickedSignalV2; ///< Signal emitted when the button is clicked.
210 TapGestureDetector mTapDetector;
212 Property::Index mPropertyDimmed; ///< Property index for dimmed.
215 } // namespace Internal
218 // Helpers for public-api forwarding methods
220 inline Toolkit::Internal::Button& GetImplementation( Toolkit::Button& button )
222 DALI_ASSERT_ALWAYS( button );
224 Dali::RefObject& handle = button.GetImplementation();
226 return static_cast<Toolkit::Internal::Button&>( handle );
229 inline const Toolkit::Internal::Button& GetImplementation( const Toolkit::Button& button )
231 DALI_ASSERT_ALWAYS( button );
233 const Dali::RefObject& handle = button.GetImplementation();
235 return static_cast<const Toolkit::Internal::Button&>( handle );
238 } // namespace Toolkit
242 #endif // __DALI_TOOLKIT_INTERNAL_BUTTON_H__