Moved Gesture::State and -::Type to gesture-enumerations.h.
[platform/core/uifw/dali-core.git] / dali / internal / event / events / tap-gesture / tap-gesture-recognizer.h
1 #ifndef DALI_INTERNAL_EVENT_EVENTS_TAP_GESTURE_RECOGNIZER_H
2 #define DALI_INTERNAL_EVENT_EVENTS_TAP_GESTURE_RECOGNIZER_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>
23 #include <dali/public-api/common/vector-wrapper.h>
24 #include <dali/integration-api/events/point.h>
25
26
27 // INTERNAL INCLUDES
28 #include <dali/internal/event/events/gesture-recognizer.h>
29 #include <dali/internal/event/events/tap-gesture/tap-gesture-event.h>
30
31 namespace Dali
32 {
33
34 namespace Integration
35 {
36 struct TouchEvent;
37 }
38
39 namespace Internal
40 {
41 struct TapGestureRequest;
42
43 /**
44  * When given a set of touch events, this detector attempts to determine if a tap gesture has taken place.
45  */
46 class TapGestureRecognizer : public GestureRecognizer
47 {
48 public:
49
50   using Observer = RecognizerObserver<TapGestureEvent>;
51
52   /**
53    * Constructor
54    * @param[in] coreEventInterface Used to send events to Core.
55    * @param[in]  screenSize  The size of the screen.
56    * @param[in]  request     The tap gesture request.
57    */
58   TapGestureRecognizer(Observer& observer, Vector2 screenSize, const TapGestureRequest& request);
59
60   /**
61    * Virtual destructor.
62    */
63   virtual ~TapGestureRecognizer();
64
65 public:
66
67   /**
68    * @copydoc Dali::Internal::GestureDetector::SendEvent(const Integration::TouchEvent&)
69    */
70   virtual void SendEvent(const Integration::TouchEvent& event);
71
72   /**
73    * @copydoc Dali::Internal::GestureDetector::Update(const Integration::GestureRequest&)
74    */
75   virtual void Update(const GestureRequest& request);
76
77 private:
78
79   /**
80    * Checks if registered taps are within required bounds and emits tap gesture if they are.
81    *
82    * @param[in] state current state of incomplete gesture
83    * @param[in] time time of this latest touch event
84    */
85   void EmitGesture( GestureState state, uint32_t time );
86
87   /**
88    * Initialises tap gesture detector for next tap sequence
89    *
90    * @param[in] event registered touch event
91    * @param[in] point position touch event occurred
92    */
93   void SetupForTouchDown( const Integration::TouchEvent& event, const Integration::Point& point );
94
95   /**
96    * Emit a touch down event for hit testing
97    *
98    * @param[in] event registered touch event
99    */
100   void EmitPossibleState( const Integration::TouchEvent& event );
101
102   /**
103    * Force a touch event sequence to be treated as a single tap
104    *
105    * @param[in] time time of this latest touch event
106    * @param[in] point position touch event occurred
107     */
108   void EmitSingleTap( uint32_t time, const Integration::Point& point );
109
110   /**
111    * Emit a tap event
112    *
113    * @param[in] time time of this latest touch event
114    * @param[in] event registered touch event
115    */
116   void EmitTap( uint32_t time, TapGestureEvent& event );
117
118   /**
119    * Send the event for processing
120    *
121    * @param[in] tap event for processing
122    */
123   void ProcessEvent( TapGestureEvent& event );
124
125 private:
126
127   // Reference to the gesture processor for this recognizer
128   Observer& mObserver;
129
130   /**
131    * Internal state machine.
132    */
133   enum State
134   {
135     CLEAR,      ///< No gesture detected.
136     TOUCHED,    ///< User is touching the screen.
137     REGISTERED, ///< At least one tap has been registered.
138     FAILED,     ///< Gesture has failed.
139   };
140
141   State mState; ///< Current state of the detector.
142
143   int mMinimumTapsRequired; ///< Minimum number of taps required.
144   int mMaximumTapsRequired; ///< Maximum number of taps required.
145   int mTapsRegistered;      ///< In current detection, the number of taps registered.
146
147   Vector2 mTouchPosition;   ///< The initial touch down position.
148   uint32_t mTouchTime; ///< The initial touch down time.
149   uint32_t mLastTapTime; ///< Time last tap gesture was registered
150
151 };
152
153 } // namespace Internal
154
155 } // namespace Dali
156
157
158 #endif // DALI_INTERNAL_EVENT_EVENTS_TAP_GESTURE_RECOGNIZER_H