[dali_2.3.26] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / internal / event / events / pinch-gesture / pinch-gesture-processor.h
1 #ifndef DALI_INTERNAL_PINCH_GESTURE_EVENT_PROCESSOR_H
2 #define DALI_INTERNAL_PINCH_GESTURE_EVENT_PROCESSOR_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 // INTERNAL INCLUDES
22 #include <dali/internal/event/events/gesture-processor.h>
23 #include <dali/internal/event/events/pinch-gesture/pinch-gesture-detector-impl.h>
24 #include <dali/internal/event/render-tasks/render-task-impl.h>
25
26 namespace Dali
27 {
28 namespace Internal
29 {
30 class Scene;
31 class Stage;
32
33 struct PinchGestureEvent;
34
35 /**
36  * Pinch Gesture Event Processing:
37  *
38  * When we receive a pinch gesture event, we do the following:
39  * - Find the hit actor that requires a pinch underneath the center-point of the pinch.
40  * - Emit the gesture if the event satisfies the detector conditions.
41  *
42  * The above is only checked when our gesture starts. We continue sending the pinch gesture to this
43  * detector until the pinch ends or is cancelled.
44  */
45 class PinchGestureProcessor : public GestureProcessor, public RecognizerObserver<PinchGestureEvent>
46 {
47 public:
48   /**
49    * Create a pinch gesture processor.
50    */
51   PinchGestureProcessor();
52
53   /**
54    * Non-virtual destructor; PinchGestureProcessor is not a base class
55    */
56   ~PinchGestureProcessor() override;
57
58 public: // To be called by GestureEventProcessor
59   /**
60    * This method sets the minimum distance to start a pinch
61    * @param[in] value The distance in pixels
62    */
63   void SetMinimumPinchDistance(float value);
64
65   /**
66    * Sets the minimum touch events required before a pinch can be started
67    * @param[in] value The number of touch events
68    */
69   void SetMinimumTouchEvents(uint32_t value);
70
71   /**
72    * Sets the minimum touch events required after a pinch started
73    * @param[in] value The number of touch events
74    */
75   void SetMinimumTouchEventsAfterStart(uint32_t value);
76
77   /**
78    * This method is called whenever a pinch gesture event occurs.
79    * @param[in] scene The scene the pinch gesture event occurs in.
80    * @param[in] pinchEvent The event that has occurred.
81    */
82   void Process(Scene& scene, const PinchGestureEvent& pinchEvent) override;
83
84   /**
85    * Adds a gesture detector to this gesture processor.
86    * If this is the first gesture detector being added, then this method registers the required
87    * gesture with the adaptor.
88    * @param[in]  gestureDetector  The gesture detector being added.
89    */
90   void AddGestureDetector(PinchGestureDetector* gestureDetector, Scene& scene);
91
92   /**
93    * Removes the specified gesture detector from this gesture processor.  If, after removing this
94    * gesture detector, there are no more gesture detectors registered, then this method unregisters
95    * the gesture from the adaptor.
96    * @param[in]  gestureDetector  The gesture detector being removed.
97    */
98   void RemoveGestureDetector(PinchGestureDetector* gestureDetector);
99
100   /**
101    * This method updates the gesture detection parameters.
102    * @param[in]  gestureDetector  The gesture detector that has been updated.
103    */
104   void GestureDetectorUpdated(PinchGestureDetector* gestureDetector);
105
106 private:
107   // Undefined
108   PinchGestureProcessor(const PinchGestureProcessor&);
109   PinchGestureProcessor& operator=(const PinchGestureProcessor& rhs);
110
111 private:
112   // GestureProcessor overrides
113
114   /**
115    * @copydoc GestureProcessor::OnGesturedActorStageDisconnection()
116    */
117   void OnGesturedActorStageDisconnection() override;
118
119   /**
120    * @copydoc GestureProcessor::CheckGestureDetector()
121    */
122   bool CheckGestureDetector(GestureDetector* detector, Actor* actor) override;
123
124   /**
125    * @copydoc GestureProcessor::EmitGestureSignal()
126    */
127   void EmitGestureSignal(Actor* actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates) override;
128
129 private:
130   PinchGestureDetectorContainer mPinchGestureDetectors;
131   GestureDetectorContainer      mCurrentPinchEmitters;
132   RenderTaskPtr                 mCurrentRenderTask;
133
134   const PinchGestureEvent* mCurrentPinchEvent; ///< Pointer to current PinchEvent, used when calling ProcessAndEmit()
135
136   float    mMinimumPinchDistance;
137   uint32_t mMinimumTouchEvents;
138   uint32_t mMinimumTouchEventsAfterStart;
139 };
140
141 } // namespace Internal
142
143 } // namespace Dali
144
145 #endif // DALI_INTERNAL_PINCH_GESTURE_EVENT_PROCESSOR_H