1 #ifndef DALI_LONG_PRESS_GESTURE_DETECTOR_H
2 #define DALI_LONG_PRESS_GESTURE_DETECTOR_H
5 * Copyright (c) 2020 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 <cstdint> // uint32_t
25 #include <dali/public-api/events/gesture-detector.h>
26 #include <dali/public-api/signals/dali-signal.h>
31 * @addtogroup dali_core_events
35 namespace Internal DALI_INTERNAL
37 class LongPressGestureDetector;
40 class LongPressGesture;
43 * @brief This class emits a signals when a long press gesture occurs that meets the requirements set by the application.
46 * For any valid long press, two signals will be emitted:
47 * - First identifying the beginning (state = GestureState::STARTED) i.e. when fingers held down for the required time.
48 * - Second identifying the ending (state = GestureState::FINISHED) i.e. when fingers are released.
50 * The application programmer can use this gesture detector as follows:
52 * LongPressGestureDetector detector = LongPressGestureDetector::New();
53 * detector.Attach(myActor);
54 * detector.DetectedSignal().Connect(this, &MyApplication::OnLongPress);
57 * @see LongPressGesture
60 * | %Signal Name | Method |
61 * |-------------------|-----------------------|
62 * | longPressDetected | @ref DetectedSignal() |
64 class DALI_CORE_API LongPressGestureDetector : public GestureDetector
67 using DetectedSignalType = Signal<void( Actor, const LongPressGesture& )>; ///< Gesture detected signal type @SINCE_1_0.0
69 public: // Creation & Destruction
72 * @brief Creates an uninitialized LongPressGestureDetector; this can be initialized with LongPressGestureDetector::New().
74 * Calling member functions with an uninitialized LongPressGestureDetector handle is not allowed.
77 LongPressGestureDetector();
80 * @brief Creates an initialized LongPressGestureDetector.
82 * By default, this would create a gesture detector that requires only one touch.
84 * @return A handle to a newly allocated Dali resource
86 static LongPressGestureDetector New();
89 * @brief Creates an initialized LongPressGestureDetector with the number of touches required.
91 * A long press gesture will be emitted from this detector if the number of fingers touching the
92 * screen is equal to the touches required.
94 * @param[in] touchesRequired The number of touches required
95 * @return A handle to a newly allocated Dali resource
97 static LongPressGestureDetector New(uint32_t touchesRequired);
100 * @brief Creates an initialized LongPressGestureDetector with the minimum and maximum number of touches required.
102 * A long press gesture will be emitted from this detector if the number of fingers touching the screen
103 * falls between the minimum and maximum touches set.
105 * @param[in] minTouches The minimum number of touches required
106 * @param[in] maxTouches The maximum number of touches required
107 * @return A handle to a newly allocated Dali resource
109 static LongPressGestureDetector New(uint32_t minTouches, uint32_t maxTouches);
112 * @brief Downcasts a handle to LongPressGestureDetector handle.
114 * If handle points to a LongPressGestureDetector object, the
115 * downcast produces valid handle. If not, the returned handle is left uninitialized.
117 * @param[in] handle Handle to an object
118 * @return Handle to a LongPressGestureDetector object or an uninitialized handle
120 static LongPressGestureDetector DownCast( BaseHandle handle );
125 * This is non-virtual since derived Handle types must not contain data or virtual methods.
128 ~LongPressGestureDetector();
131 * @brief This copy constructor is required for (smart) pointer semantics.
134 * @param[in] handle A reference to the copied handle
136 LongPressGestureDetector(const LongPressGestureDetector& handle);
139 * @brief This assignment operator is required for (smart) pointer semantics.
142 * @param[in] rhs A reference to the copied handle
143 * @return A reference to this
145 LongPressGestureDetector& operator=(const LongPressGestureDetector& rhs);
150 * @brief Sets the number of touches required.
152 * The number of touches corresponds to the number of fingers a user
153 * has on the screen. This sets the minimum and maximum touches to
154 * the input parameter.
157 * @param[in] touches Touches required
158 * @pre The gesture detector has been initialized.
159 * @note The default is '1'.
161 void SetTouchesRequired(uint32_t touches);
164 * @brief Sets the minimum and maximum touches required.
166 * The number of touches corresponds to the number of fingers a user
170 * @param[in] minTouches Minimum Touches required
171 * @param[in] maxTouches Maximum Touches required
172 * @pre The gesture detector has been initialized.
173 * @note The default is '1'.
175 void SetTouchesRequired(uint32_t minTouches, uint32_t maxTouches);
180 * @brief Retrieves the minimum number of touches required.
183 * @return The minimum number of touches required
184 * @pre The gesture detector has been initialized.
186 uint32_t GetMinimumTouchesRequired() const;
189 * @brief Retrieves the maximum number of touches required.
192 * @return The maximum number of touches required
193 * @pre The gesture detector has been initialized.
195 uint32_t GetMaximumTouchesRequired() const;
200 * @brief This signal is emitted when the specified long press is detected on the attached actor.
202 * A callback of the following type may be connected:
204 * void YourCallbackName( Actor actor, const LongPressGesture& gesture );
207 * @return The signal to connect to
208 * @pre The gesture detector has been initialized.
210 DetectedSignalType& DetectedSignal();
212 public: // Not intended for Application developers
216 * @brief This constructor is used by LongPressGestureDetector::New() methods.
219 * @param[in] internal A pointer to a newly allocated Dali resource
221 explicit DALI_INTERNAL LongPressGestureDetector(Internal::LongPressGestureDetector* internal);
231 #endif // DALI_LONG_PRESS_GESTURE_DETECTOR_H