[dali_2.3.25] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / public-api / events / gesture-detector.h
1 #ifndef DALI_GESTURE_DETECTOR_H
2 #define DALI_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 // INTERNAL INCLUDES
22 #include <dali/public-api/object/handle.h>
23 #include <dali/public-api/events/touch-event.h>
24
25 namespace Dali
26 {
27 /**
28  * @addtogroup dali_core_events
29  * @{
30  */
31
32 namespace Internal DALI_INTERNAL
33 {
34 class GestureDetector;
35 }
36
37 class Actor;
38
39 /**
40  * @brief GestureDetectors analyse a stream of touch events and attempt to determine the intention of the user.
41  *
42  * An actor is attached to a gesture detector and if the detector recognises a pattern in its analysis, it will
43  * emit a detected signal to the application.
44  *
45  * This is the base class for different gesture detectors available and provides functionality that is common
46  * to all the gesture detectors.
47  *
48  * @SINCE_1_0.0
49  * @see Gesture
50  */
51 class DALI_CORE_API GestureDetector : public Handle
52 {
53 public: // Creation & Destruction
54   /**
55    * @brief Creates an uninitialized GestureDetector.
56    *
57    * This can be initialized with one of the derived gesture detectors' New() methods. For example, PanGestureDetector::New().
58    *
59    * Calling member functions with an uninitialized Dali::GestureDetector handle is not allowed.
60    * @SINCE_1_0.0
61    */
62   GestureDetector();
63
64   /**
65    * @brief Downcasts a handle to GestureDetector handle.
66    *
67    * If handle points to a GestureDetector object, the downcast produces valid handle.
68    * If not, the returned handle is left uninitialized.
69    * @SINCE_1_0.0
70    * @param[in] handle Handle to an object
71    * @return Handle to a GestureDetector object or an uninitialized handle
72    */
73   static GestureDetector DownCast(BaseHandle handle);
74
75   /**
76    * @brief Dali::GestureDetector is intended as a base class.
77    *
78    * This is non-virtual since derived Handle types must not contain data or virtual methods.
79    * @SINCE_1_0.0
80    */
81   ~GestureDetector();
82
83   /**
84    * @brief This copy constructor is required for (smart) pointer semantics.
85    *
86    * @SINCE_1_0.0
87    * @param[in] handle A reference to the copied handle
88    */
89   GestureDetector(const GestureDetector& handle);
90
91   /**
92    * @brief This assignment operator is required for (smart) pointer semantics.
93    *
94    * @SINCE_1_0.0
95    * @param[in] rhs A reference to the copied handle
96    * @return A reference to this
97    */
98   GestureDetector& operator=(const GestureDetector& rhs);
99
100   /**
101    * @brief This move constructor is required for (smart) pointer semantics.
102    *
103    * @SINCE_2_2.4
104    * @param[in] handle A reference to the moved handle
105    */
106   GestureDetector(GestureDetector&& handle) noexcept;
107
108   /**
109    * @brief This move assignment operator is required for (smart) pointer semantics.
110    *
111    * @SINCE_2_2.4
112    * @param[in] rhs A reference to the moved handle
113    * @return A reference to this
114    */
115   GestureDetector& operator=(GestureDetector&& rhs) noexcept;
116
117 public: // Actor related
118   /**
119    * @brief Attaches an actor to the gesture.
120    *
121    * The detected signal will be dispatched when the gesture occurs on
122    * the attached actor.
123    * @SINCE_1_0.0
124    * @param[in] actor The actor to attach to the gesture detector
125    * @pre The gesture detector has been initialized.
126    * @note You can attach several actors to a gesture detector.
127    */
128   void Attach(Actor actor);
129
130   /**
131    * @brief Detaches the attached actor from the gesture detector.
132    *
133    * @SINCE_1_0.0
134    * @param[in] actor The actor to detach from the gesture detector
135    * @pre The gesture detector has been initialized.
136    * @pre The specified actor has been attached to the gesture detector.
137    */
138   void Detach(Actor actor);
139
140   /**
141    * @brief Detaches all the actors that have been attached to the gesture detector.
142    *
143    * @SINCE_1_0.0
144    * @pre The gesture detector has been initialized.
145    * @pre At least one actor has been attached to the gesture detector.
146    */
147   void DetachAll();
148
149   /**
150    * @brief Returns the number of actors attached to the gesture detector.
151    *
152    * @SINCE_1_0.0
153    * @return The count
154    * @pre The gesture detector has been initialized.
155    */
156   size_t GetAttachedActorCount() const;
157
158   /**
159    * @brief Returns an actor by index. An empty handle if the index is not valid.
160    *
161    * @SINCE_1_0.0
162    * @param[in] index The attached actor's index
163    * @return The attached actor or an empty handle
164    * @pre The gesture detector has been initialized.
165    */
166   Actor GetAttachedActor(size_t index) const;
167
168   /**
169    * @brief The gesture is recognized by sending a Touch event to the actor.
170    *
171    * @param actor The actor receiving touch events
172    * @param touch The thouch event
173    * @return If true , the gesture is being recognized.
174    */
175   bool FeedTouch(Dali::Actor& actor, Dali::TouchEvent& touch);
176
177 protected:
178   /// @cond internal
179   /**
180    * @brief This constructor is used by New() methods of derived classes (For example, PanGestureDetector::New()).
181    *
182    * @SINCE_1_0.0
183    * @param[in] internal A pointer to a newly allocated Dali resource
184    */
185   explicit DALI_INTERNAL GestureDetector(Internal::GestureDetector* internal);
186   /// @endcond
187 };
188
189 /**
190  * @}
191  */
192 } // namespace Dali
193
194 #endif // DALI_GESTURE_DETECTOR_H