(Gestures) Moved into separate folders
[platform/core/uifw/dali-core.git] / dali / internal / event / events / tap-gesture / tap-gesture-detector-impl.cpp
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/event/events/tap-gesture/tap-gesture-detector-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <cstring> // for strcmp
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/events/tap-gesture.h>
26 #include <dali/public-api/object/type-registry.h>
27 #include <dali/integration-api/debug.h>
28 #include <dali/internal/event/events/gesture-event-processor.h>
29
30 namespace Dali
31 {
32
33 namespace Internal
34 {
35
36 namespace
37 {
38
39 const unsigned int DEFAULT_TAPS_REQUIRED = 1u;
40 const unsigned int DEFAULT_TOUCHES_REQUIRED = 1u;
41
42 // Signals
43 const char* const SIGNAL_TAP_DETECTED = "tapDetected";
44
45 BaseHandle Create()
46 {
47   return Dali::TapGestureDetector::New();
48 }
49
50 TypeRegistration mType( typeid(Dali::TapGestureDetector), typeid(Dali::GestureDetector), Create );
51
52 SignalConnectorType signalConnector1( mType, SIGNAL_TAP_DETECTED, &TapGestureDetector::DoConnectSignal );
53
54 }
55
56 TapGestureDetectorPtr TapGestureDetector::New()
57 {
58   return new TapGestureDetector;
59 }
60
61 TapGestureDetectorPtr TapGestureDetector::New( unsigned int tapsRequired )
62 {
63   return new TapGestureDetector( tapsRequired );
64 }
65
66 TapGestureDetector::TapGestureDetector()
67 : GestureDetector( Gesture::Tap ),
68   mMinimumTapsRequired( DEFAULT_TAPS_REQUIRED ),
69   mMaximumTapsRequired( DEFAULT_TAPS_REQUIRED ),
70   mTouchesRequired( DEFAULT_TOUCHES_REQUIRED )
71 {
72 }
73
74 TapGestureDetector::TapGestureDetector( unsigned int tapsRequired )
75 : GestureDetector( Gesture::Tap ),
76   mMinimumTapsRequired( tapsRequired ),
77   mMaximumTapsRequired( tapsRequired ),
78   mTouchesRequired( DEFAULT_TOUCHES_REQUIRED )
79 {
80 }
81
82 TapGestureDetector::~TapGestureDetector()
83 {
84 }
85
86 void TapGestureDetector::SetMinimumTapsRequired(unsigned int taps)
87 {
88   if ( mMinimumTapsRequired != taps )
89   {
90     mMinimumTapsRequired = taps;
91
92     if ( !mAttachedActors.empty() )
93     {
94       mGestureEventProcessor.GestureDetectorUpdated(this);
95     }
96   }
97 }
98
99 void TapGestureDetector::SetMaximumTapsRequired(unsigned int taps)
100 {
101   if ( mMaximumTapsRequired != taps )
102   {
103     mMaximumTapsRequired = taps;
104
105     if ( !mAttachedActors.empty() )
106     {
107       mGestureEventProcessor.GestureDetectorUpdated(this);
108     }
109   }
110 }
111
112 void TapGestureDetector::SetTouchesRequired(unsigned int touches)
113 {
114   if (mTouchesRequired != touches)
115   {
116     mTouchesRequired = touches;
117
118     if (!mAttachedActors.empty())
119     {
120       mGestureEventProcessor.GestureDetectorUpdated(this);
121     }
122   }
123 }
124
125 unsigned int TapGestureDetector::GetMinimumTapsRequired() const
126 {
127   return mMinimumTapsRequired;
128 }
129
130 unsigned int TapGestureDetector::GetMaximumTapsRequired() const
131 {
132   return mMaximumTapsRequired;
133 }
134
135 unsigned int TapGestureDetector::GetTouchesRequired() const
136 {
137   return mTouchesRequired;
138 }
139
140 void TapGestureDetector::EmitTapGestureSignal(Dali::Actor tappedActor, const TapGesture& tap)
141 {
142   // Guard against destruction during signal emission
143   Dali::TapGestureDetector handle( this );
144
145   mDetectedSignal.Emit( tappedActor, tap );
146 }
147
148 bool TapGestureDetector::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
149 {
150   bool connected( true );
151   TapGestureDetector* gesture = static_cast< TapGestureDetector* >(object); // TypeRegistry guarantees that this is the correct type.
152
153   if ( 0 == strcmp( signalName.c_str(), SIGNAL_TAP_DETECTED ) )
154   {
155     gesture->DetectedSignal().Connect( tracker, functor );
156   }
157   else
158   {
159     // signalName does not match any signal
160     connected = false;
161   }
162
163   return connected;
164 }
165
166 void TapGestureDetector::OnActorAttach(Actor& actor)
167 {
168   // Do nothing
169 }
170
171 void TapGestureDetector::OnActorDetach(Actor& actor)
172 {
173   // Do nothing
174 }
175
176 void TapGestureDetector::OnActorDestroyed(Object& object)
177 {
178   // Do nothing
179 }
180
181 } // namespace Internal
182
183 } // namespace Dali