df64cb7d45ac01242c52103870469f2a0d9610c2
[platform/core/uifw/dali-core.git] / dali / internal / event / events / tap-gesture-processor.h
1 #ifndef DALI_INTERNAL_TAP_GESTURE_EVENT_PROCESSOR_H
2 #define DALI_INTERNAL_TAP_GESTURE_EVENT_PROCESSOR_H
3
4 /*
5  * Copyright (c) 2019 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/tap-gesture-detector-impl.h>
23 #include <dali/internal/event/events/gesture-processor.h>
24 #include "actor-observer.h"
25
26 namespace Dali
27 {
28
29 namespace Internal
30 {
31
32 class Scene;
33 class Stage;
34 class Actor;
35
36 struct GestureEvent;
37 struct TapGestureEvent;
38
39 /**
40  * Tap Gesture Event Processing:
41  *
42  * When we receive a tap gesture event, we do the following:
43  * - Find the actor that requires a tap where the tap occurred.
44  * - Emit the gesture if the tap gesture event satisfies the detector conditions.
45  */
46 class TapGestureProcessor : public GestureProcessor, public RecognizerObserver<TapGestureEvent>
47 {
48 public:
49
50   /**
51    * Create a tap gesture processor.
52    * @param[in] gestureManager The gesture manager.
53    */
54   TapGestureProcessor();
55
56   /**
57    * Non-virtual destructor; TapGestureProcessor is not a base class
58    */
59   ~TapGestureProcessor();
60
61 public: // To be called by GestureEventProcessor
62
63   /**
64    * This method is called whenever a tap gesture event occurs.
65    * @param[in] scene The scene the tap gesture event occurs in.
66    * @param[in] tapEvent The event that has occurred.
67    */
68   void Process( Scene& scene, const TapGestureEvent& event);
69
70   /**
71    * Adds a gesture detector to this gesture processor.
72    * If this is the first gesture detector being added, then this method registers the required
73    * gesture with the adaptor.
74    * @param[in]  gestureDetector  The gesture detector being added.
75    */
76   void AddGestureDetector(TapGestureDetector* gestureDetector, Scene& scene);
77
78   /**
79    * Removes the specified gesture detector from this gesture processor.  If, after removing this
80    * gesture detector, there are no more gesture detectors registered, then this method unregisters
81    * the gesture from the adaptor.
82    * @param[in]  gestureDetector  The gesture detector being removed.
83    */
84   void RemoveGestureDetector(TapGestureDetector* gestureDetector);
85
86   /**
87    * This method updates the gesture detection parameters.
88    * @param[in]  gestureDetector  The gesture detector that has been updated.
89    */
90   void GestureDetectorUpdated(TapGestureDetector* gestureDetector);
91
92 private:
93
94   // Undefined
95   TapGestureProcessor(const TapGestureProcessor&);
96   TapGestureProcessor& operator=(const TapGestureProcessor& rhs);
97
98 private:
99
100   /**
101    * Iterates through our GestureDetectors and determines if we need to ask the adaptor to update
102    * its detection policy.  If it does, it sends the appropriate gesture update request to adaptor.
103    */
104   void UpdateDetection();
105
106   // GestureProcessor overrides
107
108   /**
109    * @copydoc GestureProcessor::OnGesturedActorStageDisconnection()
110    */
111   void OnGesturedActorStageDisconnection() { /* Nothing to do */ }
112
113   /**
114    * @copydoc GestureProcessor::CheckGestureDetector()
115    */
116   bool CheckGestureDetector( GestureDetector* detector, Actor* actor );
117
118   /**
119    * @copydoc GestureProcessor::EmitGestureSignal()
120    */
121   void EmitGestureSignal( Actor* actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates );
122
123 private:
124
125   TapGestureDetectorContainer mTapGestureDetectors;
126
127   unsigned int mMinTapsRequired;
128   unsigned int mMaxTapsRequired;
129   unsigned int mMinTouchesRequired;
130   unsigned int mMaxTouchesRequired;
131
132   ActorObserver mCurrentTapActor; ///< Observer for the current gesture actor
133   const TapGestureEvent* mCurrentTapEvent; ///< Pointer to current TapEvent, used when calling ProcessAndEmit()
134   bool mPossibleProcessed; ///< Indication of whether we've processed a touch down for this gestuee
135 };
136
137 } // namespace Internal
138
139 } // namespace Dali
140
141 #endif // DALI_INTERNAL_TAP_GESTURE_EVENT_PROCESSOR_H