Formatted API
[platform/core/uifw/dali-core.git] / dali / public-api / events / long-press-gesture-detector.h
1 #ifndef DALI_LONG_PRESS_GESTURE_DETECTOR_H
2 #define DALI_LONG_PRESS_GESTURE_DETECTOR_H
3
4 /*
5  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <cstdint> // uint32_t
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/events/gesture-detector.h>
26 #include <dali/public-api/signals/dali-signal.h>
27
28 namespace Dali
29 {
30 /**
31  * @addtogroup dali_core_events
32  * @{
33  */
34
35 namespace Internal DALI_INTERNAL
36 {
37 class LongPressGestureDetector;
38 }
39
40 class LongPressGesture;
41
42 /**
43  * @brief This class emits a signals when a long press gesture occurs that meets the requirements set by the application.
44  * @SINCE_1_0.0
45  *
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.
49  *
50  * The application programmer can use this gesture detector as follows:
51  * @code
52  * LongPressGestureDetector detector = LongPressGestureDetector::New();
53  * detector.Attach(myActor);
54  * detector.DetectedSignal().Connect(this, &MyApplication::OnLongPress);
55  * @endcode
56  *
57  * @see LongPressGesture
58  *
59  * Signals
60  * | %Signal Name      | Method                |
61  * |-------------------|-----------------------|
62  * | longPressDetected | @ref DetectedSignal() |
63  */
64 class DALI_CORE_API LongPressGestureDetector : public GestureDetector
65 {
66 public:                                                                    // Typedefs
67   using DetectedSignalType = Signal<void(Actor, const LongPressGesture&)>; ///< Gesture detected signal type @SINCE_1_0.0
68
69 public: // Creation & Destruction
70   /**
71    * @brief Creates an uninitialized LongPressGestureDetector; this can be initialized with LongPressGestureDetector::New().
72    *
73    * Calling member functions with an uninitialized LongPressGestureDetector handle is not allowed.
74    * @SINCE_1_0.0
75    */
76   LongPressGestureDetector();
77
78   /**
79    * @brief Creates an initialized LongPressGestureDetector.
80    *
81    * By default, this would create a gesture detector that requires only one touch.
82    * @SINCE_1_0.0
83    * @return A handle to a newly allocated Dali resource
84    */
85   static LongPressGestureDetector New();
86
87   /**
88    * @brief Creates an initialized LongPressGestureDetector with the number of touches required.
89    *
90    * A long press gesture will be emitted from this detector if the number of fingers touching the
91    * screen is equal to the touches required.
92    * @SINCE_1_0.0
93    * @param[in] touchesRequired The number of touches required
94    * @return A handle to a newly allocated Dali resource
95    */
96   static LongPressGestureDetector New(uint32_t touchesRequired);
97
98   /**
99    * @brief Creates an initialized LongPressGestureDetector with the minimum and maximum number of touches required.
100    *
101    * A long press gesture will be emitted from this detector if the number of fingers touching the screen
102    * falls between the minimum and maximum touches set.
103    * @SINCE_1_0.0
104    * @param[in] minTouches The minimum number of touches required
105    * @param[in] maxTouches The maximum number of touches required
106    * @return A handle to a newly allocated Dali resource
107    */
108   static LongPressGestureDetector New(uint32_t minTouches, uint32_t maxTouches);
109
110   /**
111    * @brief Downcasts a handle to LongPressGestureDetector handle.
112    *
113    * If handle points to a LongPressGestureDetector object, the
114    * downcast produces valid handle. If not, the returned handle is left uninitialized.
115    * @SINCE_1_0.0
116    * @param[in] handle Handle to an object
117    * @return Handle to a LongPressGestureDetector object or an uninitialized handle
118    */
119   static LongPressGestureDetector DownCast(BaseHandle handle);
120
121   /**
122    * @brief Destructor.
123    *
124    * This is non-virtual since derived Handle types must not contain data or virtual methods.
125    * @SINCE_1_0.0
126    */
127   ~LongPressGestureDetector();
128
129   /**
130    * @brief This copy constructor is required for (smart) pointer semantics.
131    *
132    * @SINCE_1_0.0
133    * @param[in] handle A reference to the copied handle
134    */
135   LongPressGestureDetector(const LongPressGestureDetector& handle);
136
137   /**
138    * @brief This assignment operator is required for (smart) pointer semantics.
139    *
140    * @SINCE_1_0.0
141    * @param[in] rhs A reference to the copied handle
142    * @return A reference to this
143    */
144   LongPressGestureDetector& operator=(const LongPressGestureDetector& rhs);
145
146 public: // Setters
147   /**
148    * @brief Sets the number of touches required.
149    *
150    * The number of touches corresponds to the number of fingers a user
151    * has on the screen.  This sets the minimum and maximum touches to
152    * the input parameter.
153    *
154    * @SINCE_1_0.0
155    * @param[in] touches Touches required
156    * @pre The gesture detector has been initialized.
157    * @note The default is '1'.
158    */
159   void SetTouchesRequired(uint32_t touches);
160
161   /**
162    * @brief Sets the minimum and maximum touches required.
163    *
164    * The number of touches corresponds to the number of fingers a user
165    * has on the screen.
166    *
167    * @SINCE_1_0.0
168    * @param[in] minTouches Minimum Touches required
169    * @param[in] maxTouches Maximum Touches required
170    * @pre The gesture detector has been initialized.
171    * @note The default is '1'.
172    */
173   void SetTouchesRequired(uint32_t minTouches, uint32_t maxTouches);
174
175 public: // Getters
176   /**
177    * @brief Retrieves the minimum number of touches required.
178    *
179    * @SINCE_1_0.0
180    * @return The minimum number of touches required
181    * @pre The gesture detector has been initialized.
182    */
183   uint32_t GetMinimumTouchesRequired() const;
184
185   /**
186    * @brief Retrieves the maximum number of touches required.
187    *
188    * @SINCE_1_0.0
189    * @return The maximum number of touches required
190    * @pre The gesture detector has been initialized.
191    */
192   uint32_t GetMaximumTouchesRequired() const;
193
194 public: // Signals
195   /**
196    * @brief This signal is emitted when the specified long press is detected on the attached actor.
197    *
198    * A callback of the following type may be connected:
199    * @code
200    *   void YourCallbackName( Actor actor, const LongPressGesture& gesture );
201    * @endcode
202    * @SINCE_1_0.0
203    * @return The signal to connect to
204    * @pre The gesture detector has been initialized.
205    */
206   DetectedSignalType& DetectedSignal();
207
208 public: // Not intended for Application developers
209   /// @cond internal
210   /**
211    * @brief This constructor is used by LongPressGestureDetector::New() methods.
212    *
213    * @SINCE_1_0.0
214    * @param[in] internal A pointer to a newly allocated Dali resource
215    */
216   explicit DALI_INTERNAL LongPressGestureDetector(Internal::LongPressGestureDetector* internal);
217   /// @endcond
218 };
219
220 /**
221  * @}
222  */
223 } // namespace Dali
224
225 #endif // DALI_LONG_PRESS_GESTURE_DETECTOR_H