Revert "[Tizen] Not execute the remove callback"
[platform/core/uifw/dali-core.git] / dali / internal / event / events / pinch-gesture / pinch-gesture-recognizer.h
1 #ifndef DALI_INTERNAL_EVENT_PINCH_GESTURE_RECOGNIZER_H
2 #define DALI_INTERNAL_EVENT_PINCH_GESTURE_RECOGNIZER_H
3
4 /*
5  * Copyright (c) 2021 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 <dali/public-api/common/vector-wrapper.h>
23
24 // INTERNAL INCLUDES
25 #include <dali/internal/event/events/gesture-recognizer.h>
26 #include <dali/internal/event/events/pinch-gesture/pinch-gesture-event.h>
27
28 namespace Dali
29 {
30 namespace Integration
31 {
32 struct TouchEvent;
33 }
34
35 namespace Internal
36 {
37 /**
38  * When given a set of touch events, this detector attempts to determine if a pinch gesture has taken place.
39  */
40 class PinchGestureRecognizer : public GestureRecognizer
41 {
42 public:
43   using Observer = RecognizerObserver<PinchGestureEvent>;
44
45   /**
46    * Constructor
47    * @param[in] screenSize The size of the screen.
48    * @param[in] screenDpi The dpi value of the screen
49    * @param[in] minimumPinchDistance in pixels
50    * @param[in] minimumTouchEvents The number of touch events required
51    * @param[in] minimumTouchEventsAfterStart The number of touch events required after a gesture started
52    */
53   PinchGestureRecognizer(Observer& observer, Vector2 screenSize, Vector2 screenDpi, float minimumPinchDistance, uint32_t minimumTouchEvents, uint32_t minimumTouchEventsAfterStart);
54
55   /**
56    * Virtual destructor.
57    */
58   ~PinchGestureRecognizer() override;
59
60 public:
61   void SetMinimumPinchDistance(float value);
62
63   /**
64    * Sets the minimum touch events required before a pinch can be started
65    * @param[in] value The number of touch events
66    */
67   void SetMinimumTouchEvents(uint32_t value);
68
69   /**
70    * Sets the minimum touch events required after a pinch started
71    * @param[in] value The number of touch events
72    */
73   void SetMinimumTouchEventsAfterStart(uint32_t value);
74
75   /**
76    * @copydoc Dali::Internal::GestureDetector::SendEvent(const Integration::TouchEvent&)
77    */
78   void SendEvent(const Integration::TouchEvent& event) override;
79
80   /**
81    * @copydoc Dali::Internal::GestureDetector::Update(const Integration::GestureRequest&)
82    */
83   void Update(const GestureRequest& request) override;
84
85 private:
86   /**
87    * Emits the pinch gesture event to the core.
88    * @param[in]  state         The state of the pinch (whether it's starting, continuing or finished).
89    * @param[in]  currentEvent  The latest touch event.
90    */
91   void SendPinch(GestureState state, const Integration::TouchEvent& currentEvent);
92
93 private:
94   // Reference to the gesture processor for this recognizer
95   Observer& mObserver;
96
97   /**
98    * Internal state machine.
99    */
100   enum State
101   {
102     CLEAR,    ///< No gesture detected.
103     POSSIBLE, ///< The current touch event data suggests that a gesture is possible.
104     STARTED,  ///< A gesture has been detected.
105   };
106
107   State                                mState;       ///< The current state of the detector.
108   std::vector<Integration::TouchEvent> mTouchEvents; ///< The touch events since initial touch down.
109
110   float mDefaultMinimumDistanceDelta; ///< The default value of the mMinimumDistanceDelta.
111
112   float mMinimumDistanceDelta; ///< The minimum distance before a pinch is applicable.
113
114   float mStartingDistance; ///< The distance between the two touch points when the pinch is first detected.
115
116   uint32_t mMinimumTouchEvents; ///< The minimum touch events required before a pinch can be started.
117
118   uint32_t mMinimumTouchEventsAfterStart; ///< The minimum touch events required after a pinch started.
119 };
120
121 } // namespace Internal
122
123 } // namespace Dali
124
125 #endif // DALI_INTERNAL_EVENT_PINCH_GESTURE_RECOGNIZER_H