Merge "Add BuildPickingRay to devel api" into devel/master
[platform/core/uifw/dali-core.git] / dali / public-api / events / tap-gesture-detector.h
1 #ifndef DALI_TAP_GESTURE_DETECTOR_H
2 #define DALI_TAP_GESTURE_DETECTOR_H
3
4 /*
5  * Copyright (c) 2022 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 TapGestureDetector;
38 }
39
40 class TapGesture;
41
42 /**
43  * @brief This class emits a signal when a tap gesture occurs that meets the requirements set by the
44  * application.
45  *
46  * See @ref TapGestureDetector::SetMinimumTapsRequired
47  * See @ref TapGestureDetector::SetMaximumTapsRequired
48  *
49  * A TapGesture is a discrete gesture, which means it does not have any state information attached
50  * to it.  Please see TapGesture for more information.
51  *
52  * The application programmer can use this gesture detector as follows:
53  * @code
54  * TapGestureDetector detector = TapGestureDetector::New();
55  * detector.Attach(myActor);
56  * detector.DetectedSignal().Connect(this, &MyApplication::OnTap);
57  * @endcode
58  *
59  * @SINCE_1_0.0
60  * @note Multi-touch taps (two or more points of contact with the surface) are not currently
61  * supported. However, multiple taps (double & triple tap etc.) are supported.
62  *
63  * Signals
64  * | %Signal Name | Method                |
65  * |--------------|-----------------------|
66  * | tapDetected  | @ref DetectedSignal() |
67  * @see TapGesture
68  *
69  */
70 class DALI_CORE_API TapGestureDetector : public GestureDetector
71 {
72 public: // Typedefs
73   /**
74    * @brief Signal type for detected signal.
75    * @SINCE_1_0.0
76    */
77   using DetectedSignalType = Signal<void(Actor, const TapGesture&)>;
78
79 public: // Creation & Destruction
80   /**
81    * @brief Creates an uninitialized TapGestureDetector; this can be initialized with TapGestureDetector::New().
82    *
83    * Calling member functions with an uninitialized TapGestureDetector handle is not allowed.
84    * @SINCE_1_0.0
85    */
86   TapGestureDetector();
87
88   /**
89    * @brief Creates an initialized TapGestureDetector.
90    *
91    * By default, this would create a gesture detector which requires one tap with one touch.
92    * @SINCE_1_0.0
93    * @return A handle to a newly allocated Dali resource
94    */
95   static TapGestureDetector New();
96
97   /**
98    * @brief Creates an initialized TapGestureDetector with the specified parameters.
99    *
100    * @SINCE_1_0.0
101    * @param[in] tapsRequired The minimum & maximum number of taps required
102    * @return A handle to a newly allocated Dali resource
103    */
104   static TapGestureDetector New(uint32_t tapsRequired);
105
106   /**
107    * @brief Downcasts a handle to TapGestureDetector handle.
108    *
109    * If handle points to a TapGestureDetector object, the
110    * downcast produces valid handle. If not, the returned handle is left uninitialized.
111    * @SINCE_1_0.0
112    * @param[in] handle Handle to an object
113    * @return Handle to a TapGestureDetector object or an uninitialized handle
114    */
115   static TapGestureDetector DownCast(BaseHandle handle);
116
117   /**
118    * @brief Destructor.
119    *
120    * This is non-virtual since derived Handle types must not contain data or virtual methods.
121    * @SINCE_1_0.0
122    */
123   ~TapGestureDetector();
124
125   /**
126    * @brief This copy constructor is required for (smart) pointer semantics.
127    *
128    * @SINCE_1_0.0
129    * @param[in] handle A reference to the copied handle
130    */
131   TapGestureDetector(const TapGestureDetector& handle);
132
133   /**
134    * @brief This assignment operator is required for (smart) pointer semantics.
135    *
136    * @SINCE_1_0.0
137    * @param[in] rhs A reference to the copied handle
138    * @return A reference to this
139    */
140   TapGestureDetector& operator=(const TapGestureDetector& rhs);
141
142   /**
143    * @brief This move constructor is required for (smart) pointer semantics.
144    *
145    * @SINCE_2_2.4
146    * @param[in] handle A reference to the moved handle
147    */
148   TapGestureDetector(TapGestureDetector&& handle) noexcept;
149
150   /**
151    * @brief This move assignment operator is required for (smart) pointer semantics.
152    *
153    * @SINCE_2_2.4
154    * @param[in] rhs A reference to the moved handle
155    * @return A reference to this
156    */
157   TapGestureDetector& operator=(TapGestureDetector&& rhs) noexcept;
158
159 public: // Setters
160   /**
161    * @brief Sets the minimum number of taps required.
162    *
163    * The tap count is the number of times a user should "tap" the screen.
164    * @SINCE_1_0.0
165    * @param[in] minimumTaps The minimum taps required
166    * @pre The gesture detector has been initialized.
167    * @note The default is '1', the maximum is 2.
168    * @see ReceiveAllTapEvents
169    */
170   void SetMinimumTapsRequired(uint32_t minimumTaps);
171
172   /**
173    * @brief Sets the maximum number of taps required.
174    *
175    * The tap count is the number of times a user should "tap" the screen.
176    * @SINCE_1_0.0
177    * @param[in] maximumTaps The maximum taps required
178    * @pre The gesture detector has been initialized.
179    * @note The default is '1', the maximum is 2.
180    * @see ReceiveAllTapEvents
181    */
182   void SetMaximumTapsRequired(uint32_t maximumTaps);
183
184   /**
185    * @brief When set to true, all tap gestures will be received when multiple taps are supported by the gesture detector.
186    *
187    * @param[in] receive The receiving all tap events flag
188    * @pre The gesture detector has been initialized.
189    * @note The default is false.
190    */
191   void ReceiveAllTapEvents(bool receive);
192
193 public: // Getters
194   /**
195    * @brief Retrieves the minimum number of taps required.
196    *
197    * @SINCE_1_0.0
198    * @return The minimum taps required
199    * @pre The gesture detector has been initialized.
200    */
201   uint32_t GetMinimumTapsRequired() const;
202
203   /**
204    * @brief Retrieves the maximum number of taps required.
205    *
206    * @SINCE_1_0.0
207    * @return The maximum taps required
208    * @pre The gesture detector has been initialized.
209    */
210   uint32_t GetMaximumTapsRequired() const;
211
212 public: // Signals
213   /**
214    * @brief This signal is emitted when the specified tap is detected on the attached actor.
215    *
216    * A callback of the following type may be connected:
217    * @code
218    *   void YourCallbackName( Actor actor, const TapGesture& gesture );
219    * @endcode
220    * @SINCE_1_0.0
221    * @return The signal to connect to
222    * @pre The gesture detector has been initialized.
223    */
224   DetectedSignalType& DetectedSignal();
225
226 public: // Not intended for Application developers
227   /// @cond internal
228   /**
229    * @brief This constructor is used by TapGestureDetector::New() methods.
230    *
231    * @SINCE_1_0.0
232    * @param[in] internal A pointer to a newly allocated Dali resource
233    */
234   explicit DALI_INTERNAL TapGestureDetector(Internal::TapGestureDetector* internal);
235   /// @endcond
236 };
237
238 /**
239  * @}
240  */
241
242 } // namespace Dali
243
244 #endif // DALI_TAP_GESTURE_DETECTOR_H