5c8fe850bd75a39a3f1722ec3c3f2e947b92b0d6
[platform/core/uifw/dali-core.git] / dali / internal / event / events / tap-gesture / tap-gesture-detector-impl.h
1 #ifndef DALI_INTERNAL_TAP_GESTURE_DETECTOR_H
2 #define DALI_INTERNAL_TAP_GESTURE_DETECTOR_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 // INTERNAL INCLUDES
22 #include <dali/public-api/events/tap-gesture-detector.h>
23 #include <dali/public-api/events/tap-gesture.h>
24 #include <dali/internal/event/events/gesture-detector-impl.h>
25
26 namespace Dali
27 {
28
29 namespace Internal
30 {
31
32 class TapGestureDetector;
33
34 using TapGestureDetectorPtr       = IntrusivePtr<TapGestureDetector>;
35 using TapGestureDetectorContainer = DerivedGestureDetectorContainer<TapGestureDetector>::type;
36
37 /**
38  * @copydoc Dali::TapGestureDetector
39  */
40 class TapGestureDetector : public GestureDetector
41 {
42 public: // Creation
43
44   /**
45    * Create a new gesture detector.
46    * @return A smart-pointer to the newly allocated detector.
47    */
48   static TapGestureDetectorPtr New();
49
50   /**
51    * Create a new gesture detector with the specified parameters.
52    * @param[in]  tapsRequired     The number of taps required.
53    * @return A smart-pointer to the newly allocated detector.
54    */
55   static TapGestureDetectorPtr New( unsigned int tapsRequired );
56
57   /**
58    * Construct a new GestureDetector.
59    */
60   TapGestureDetector();
61
62   /**
63    * Construct a new GestureDetector with the specified parameters.
64    * @param[in]  tapsRequired     The number of taps required.
65    */
66   TapGestureDetector( unsigned int tapsRequired );
67
68 public:
69
70   /**
71    * @copydoc Dali::TapGestureDetector::SetTouchesRequired(unsigned int)
72    */
73   void SetTouchesRequired(unsigned int touches);
74
75   /**
76    * @copydoc Dali::TapGestureDetector::SetMinimumTapsRequired()
77    */
78   void SetMinimumTapsRequired( unsigned int minTaps );
79
80   /**
81    * @copydoc Dali::TapGestureDetector::SetMaximumTapsRequired()
82    */
83   void SetMaximumTapsRequired( unsigned int maxTaps );
84
85   /**
86    * @copydoc Dali::TapGestureDetector::GetMinimumTapsRequired()
87    */
88   unsigned int GetMinimumTapsRequired() const;
89
90   /**
91    * @copydoc Dali::TapGestureDetector::SetMaximumTapsRequired()
92    */
93   unsigned int GetMaximumTapsRequired() const;
94
95   /**
96    * @copydoc Dali::TapGestureDetector::GetTouchesRequired()
97    */
98   unsigned int GetTouchesRequired() const;
99
100 public:
101
102   /**
103    * Called by the TapGestureProcessor when a tap gesture event occurs within the bounds of our
104    * attached actor.
105    * @param[in]  tappedActor  The tapped actor.
106    * @param[in]  tap          The tap gesture.
107    */
108   void EmitTapGestureSignal(Dali::Actor tappedActor, const Dali::TapGesture& tap);
109
110 public: // Signals
111
112   /**
113    * @copydoc Dali::TapGestureDetector::DetectedSignal()
114    */
115   Dali::TapGestureDetector::DetectedSignalType& DetectedSignal()
116   {
117     return mDetectedSignal;
118   }
119
120   /**
121    * Connects a callback function with the object's signals.
122    * @param[in] object The object providing the signal.
123    * @param[in] tracker Used to disconnect the signal.
124    * @param[in] signalName The signal to connect to.
125    * @param[in] functor A newly allocated FunctorDelegate.
126    * @return True if the signal was connected.
127    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
128    */
129   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
130
131 protected:
132
133   /**
134    * A reference counted object may only be deleted by calling Unreference()
135    */
136   virtual ~TapGestureDetector();
137
138 private:
139
140   // Undefined
141   TapGestureDetector(const TapGestureDetector&);
142   TapGestureDetector& operator=(const TapGestureDetector& rhs);
143
144 private: // GestureDetector overrides
145
146   /**
147    * @copydoc Dali::Internal::GestureDetector::OnActorAttach(Actor&)
148    */
149   virtual void OnActorAttach(Actor& actor);
150
151   /**
152    * @copydoc Dali::Internal::GestureDetector::OnActorDetach(Actor&)
153    */
154   virtual void OnActorDetach(Actor& actor);
155
156   /**
157    * @copydoc Dali::Internal::GestureDetector::OnActorDestroyed(Object&)
158    */
159   virtual void OnActorDestroyed(Object& object);
160
161 private:
162
163   Dali::TapGestureDetector::DetectedSignalType mDetectedSignal;
164
165   unsigned int mMinimumTapsRequired;
166   unsigned int mMaximumTapsRequired;
167   unsigned int mTouchesRequired;
168 };
169
170 } // namespace Internal
171
172 // Helpers for public-api forwarding methods
173
174 inline Internal::TapGestureDetector& GetImplementation(Dali::TapGestureDetector& detector)
175 {
176   DALI_ASSERT_ALWAYS( detector && "TapGestureDetector handle is empty" );
177
178   BaseObject& handle = detector.GetBaseObject();
179
180   return static_cast<Internal::TapGestureDetector&>(handle);
181 }
182
183 inline const Internal::TapGestureDetector& GetImplementation(const Dali::TapGestureDetector& detector)
184 {
185   DALI_ASSERT_ALWAYS( detector && "TapGestureDetector handle is empty" );
186
187   const BaseObject& handle = detector.GetBaseObject();
188
189   return static_cast<const Internal::TapGestureDetector&>(handle);
190 }
191
192 } // namespace Dali
193
194 #endif // DALI_INTERNAL_TAP_GESTURE_DETECTOR_H