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
47 BUTTON_PROPERTY_START_INDEX = ControlImpl::CONTROL_PROPERTY_END_INDEX + 1,
48 BUTTON_PROPERTY_END_INDEX = BUTTON_PROPERTY_START_INDEX + 1000 ///< Reserving 1000 property indices
54 * Construct a new Button.
59 * A reference counted object may only be deleted by calling Unreference()
66 * @copydoc Dali::Toolkit::Button::SetDimmed( bool dimmed )
68 void SetDimmed( bool dimmed );
71 * @copydoc Dali::Toolkit::Button::IsDimmed() const
73 bool IsDimmed() const;
76 * @copydoc Dali::Toolkit::Button::SetAnimationTime()
78 void SetAnimationTime( float animationTime );
81 * @copydoc Dali::Toolkit::Button::GetAnimationTime()
83 float GetAnimationTime() const;
88 * This method is called after the button initialization.
89 * Could be reimplemented in subclasses to provide specific behaviour.
91 virtual void OnButtonInitialize() { }
94 * This method is called from the OnTouchEvent method when the button is down.
95 * Could be reimplemented in subclasses to provide specific behaviour.
97 virtual void OnButtonDown() { }
100 * This method is called from the OnTouchEvent method when the button is up.
101 * Could be reimplemented in subclasses to provide specific behaviour.
103 virtual void OnButtonUp() { }
106 * This method is called from the OnTouchEvent method when the touch point leaves the boundary of the button or
107 * more than one touch points are received.
108 * Could be reimplemented in subclasses to provide specific behaviour.
110 virtual void OnTouchPointLeave() { }
113 * This method is called from the OnTouchEvent method when the touch point is interrupted.
114 * Could be reimplemented in subclasses to provide specific behaviour.
116 virtual void OnTouchPointInterrupted() { }
119 * This method is called when the animation time is set.
120 * Needs to be reimplemented in subclasses to set the animation time in different buttons.
121 * @param animationTime The animation time in seconds.
123 virtual void OnAnimationTimeSet( float animationTime );
126 * This method is called when the animation time is requested.
127 * Needs to be reimplemented in subclases to return the animation time.
128 * @return The animation time in seconds.
130 virtual float OnAnimationTimeRequested() const;
135 * @copydoc Dali::Toolkit::Button::ClickedSignal()
137 Toolkit::Button::ClickedSignalV2& ClickedSignal();
140 * Connects a callback function with the object's signals.
141 * @param[in] object The object providing the signal.
142 * @param[in] tracker Used to disconnect the signal.
143 * @param[in] signalName The signal to connect to.
144 * @param[in] functor A newly allocated FunctorDelegate.
145 * @return True if the signal was connected.
146 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
148 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
153 * Called when a property of an object of this type is set.
154 * @param[in] object The object whose property is set.
155 * @param[in] index The property index.
156 * @param[in] value The new property value.
158 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
161 * Called to retrieve a property of an object of this type.
162 * @param[in] object The object whose property is to be retrieved.
163 * @param[in] index The property index.
164 * @return The current value of the property.
166 static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
168 protected: // From CustomActorImpl
171 * @copydoc Dali::CustomActorImpl::OnTouchEvent( const TouchEvent& event )
173 virtual bool OnTouchEvent( const TouchEvent& event );
175 private: // From ControlImpl
178 * @copydoc Toolkit::Control::OnInitialize()
180 virtual void OnInitialize();
183 * @copydoc Toolkit::Control::OnControlSizeSet( const Vector3& targetSize )
185 virtual void OnControlSizeSet( const Vector3& targetSize );
190 * Handler for tap events.
191 * We do not actually do anything when we receive a tap as the button handles tap event through
192 * the touch event system itself as it requires more than just tap handling (e.g. leave events).
193 * This stops any of our parents receiving a tap gesture when it occurs within our area.
194 * @param[in] actor The tapped actor.
195 * @param[in] tap The tap gesture.
197 void OnTap(Actor actor, TapGesture tap);
202 * Callback received when the button is disconected from the stage.
203 * It resets the button status.
205 void OnStageDisconnection();
210 Button( const Button& );
213 Button& operator = ( const Button& );
215 protected: // Signals
219 ButtonUp, ///< The button is up.
220 ButtonDown, ///< The button is down.
223 ButtonState mState; ///< Stores the button state.
225 bool mDimmed; ///< Stores the dimmed property.
227 ButtonPainterPtr mPainter; ///< Pointer to a ButtonPainter base class.
229 Toolkit::Button::ClickedSignalV2 mClickedSignalV2; ///< Signal emitted when the button is clicked.
231 TapGestureDetector mTapDetector;
234 } // namespace Internal
237 // Helpers for public-api forwarding methods
239 inline Toolkit::Internal::Button& GetImplementation( Toolkit::Button& button )
241 DALI_ASSERT_ALWAYS( button );
243 Dali::RefObject& handle = button.GetImplementation();
245 return static_cast<Toolkit::Internal::Button&>( handle );
248 inline const Toolkit::Internal::Button& GetImplementation( const Toolkit::Button& button )
250 DALI_ASSERT_ALWAYS( button );
252 const Dali::RefObject& handle = button.GetImplementation();
254 return static_cast<const Toolkit::Internal::Button&>( handle );
257 } // namespace Toolkit
261 #endif // __DALI_TOOLKIT_INTERNAL_BUTTON_H__