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 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/dali.h>
23 #include <dali-toolkit/public-api/controls/buttons/button.h>
24 #include <dali-toolkit/public-api/controls/control-impl.h>
25 #include "button-painter-impl.h"
39 * Button is the base class implementation for all buttons.
41 class Button : public Control
48 BUTTON_PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
49 BUTTON_PROPERTY_END_INDEX = BUTTON_PROPERTY_START_INDEX + 1000 ///< Reserving 1000 property indices
55 * Construct a new Button.
60 * A reference counted object may only be deleted by calling Unreference()
67 * @copydoc Dali::Toolkit::Button::SetDimmed( bool dimmed )
69 void SetDimmed( bool dimmed );
72 * @copydoc Dali::Toolkit::Button::IsDimmed() const
74 bool IsDimmed() const;
77 * @copydoc Dali::Toolkit::Button::SetAnimationTime()
79 void SetAnimationTime( float animationTime );
82 * @copydoc Dali::Toolkit::Button::GetAnimationTime()
84 float GetAnimationTime() const;
89 * This method is called after the button initialization.
90 * Could be reimplemented in subclasses to provide specific behaviour.
92 virtual void OnButtonInitialize() { }
95 * This method is called from the OnTouchEvent method when the button is down.
96 * Could be reimplemented in subclasses to provide specific behaviour.
98 virtual void OnButtonDown() { }
101 * This method is called from the OnTouchEvent method when the button is up.
102 * Could be reimplemented in subclasses to provide specific behaviour.
104 virtual void OnButtonUp() { }
107 * This method is called from the OnTouchEvent method when the touch point leaves the boundary of the button or
108 * more than one touch points are received.
109 * Could be reimplemented in subclasses to provide specific behaviour.
111 virtual void OnTouchPointLeave() { }
114 * This method is called from the OnTouchEvent method when the touch point is interrupted.
115 * Could be reimplemented in subclasses to provide specific behaviour.
117 virtual void OnTouchPointInterrupted() { }
120 * This method is called when the animation time is set.
121 * Needs to be reimplemented in subclasses to set the animation time in different buttons.
122 * @param animationTime The animation time in seconds.
124 virtual void OnAnimationTimeSet( float animationTime );
127 * This method is called when the animation time is requested.
128 * Needs to be reimplemented in subclases to return the animation time.
129 * @return The animation time in seconds.
131 virtual float OnAnimationTimeRequested() const;
134 * This method is called when the button is removed from the stage.
135 * Could be reimplemented in subclasses to provide specific behaviour.
137 virtual void OnButtonStageDisconnection() { }
142 * @copydoc Dali::Toolkit::Button::ClickedSignal()
144 Toolkit::Button::ClickedSignalV2& ClickedSignal();
147 * Connects a callback function with the object's signals.
148 * @param[in] object The object providing the signal.
149 * @param[in] tracker Used to disconnect the signal.
150 * @param[in] signalName The signal to connect to.
151 * @param[in] functor A newly allocated FunctorDelegate.
152 * @return True if the signal was connected.
153 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
155 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
160 * Called when a property of an object of this type is set.
161 * @param[in] object The object whose property is set.
162 * @param[in] index The property index.
163 * @param[in] value The new property value.
165 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
168 * Called to retrieve a property of an object of this type.
169 * @param[in] object The object whose property is to be retrieved.
170 * @param[in] index The property index.
171 * @return The current value of the property.
173 static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
175 protected: // From CustomActorImpl
178 * @copydoc Dali::CustomActorImpl::OnTouchEvent( const TouchEvent& event )
180 virtual bool OnTouchEvent( const TouchEvent& event );
182 private: // From Control
185 * @copydoc Toolkit::Control::OnInitialize()
187 virtual void OnInitialize();
190 * @copydoc Toolkit::Control::OnControlSizeSet( const Vector3& targetSize )
192 virtual void OnControlSizeSet( const Vector3& targetSize );
195 * Callback received when the button is disconnected from the stage.
196 * It resets the button status.
198 void OnControlStageDisconnection();
203 * Handler for tap events.
204 * We do not actually do anything when we receive a tap as the button handles tap event through
205 * the touch event system itself as it requires more than just tap handling (e.g. leave events).
206 * This stops any of our parents receiving a tap gesture when it occurs within our area.
207 * @param[in] actor The tapped actor.
208 * @param[in] tap The tap gesture.
210 void OnTap(Actor actor, TapGesture tap);
215 Button( const Button& );
218 Button& operator = ( const Button& );
220 protected: // Signals
224 ButtonUp, ///< The button is up.
225 ButtonDown, ///< The button is down.
228 ButtonState mState; ///< Stores the button state.
230 bool mDimmed; ///< Stores the dimmed property.
232 ButtonPainterPtr mPainter; ///< Pointer to a ButtonPainter base class.
234 Toolkit::Button::ClickedSignalV2 mClickedSignalV2; ///< Signal emitted when the button is clicked.
236 TapGestureDetector mTapDetector;
239 } // namespace Internal
242 // Helpers for public-api forwarding methods
244 inline Toolkit::Internal::Button& GetImplementation( Toolkit::Button& button )
246 DALI_ASSERT_ALWAYS( button );
248 Dali::RefObject& handle = button.GetImplementation();
250 return static_cast<Toolkit::Internal::Button&>( handle );
253 inline const Toolkit::Internal::Button& GetImplementation( const Toolkit::Button& button )
255 DALI_ASSERT_ALWAYS( button );
257 const Dali::RefObject& handle = button.GetImplementation();
259 return static_cast<const Toolkit::Internal::Button&>( handle );
262 } // namespace Toolkit
266 #endif // __DALI_TOOLKIT_INTERNAL_BUTTON_H__