(TapGesture) Added min/max taps, removed touches as it's unsupported
[platform/core/uifw/dali-core.git] / dali / internal / event / events / tap-gesture-detector-impl.cpp
1 /*
2  * Copyright (c) 2014 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-detector-impl.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/events/tap-gesture.h>
23 #include <dali/public-api/object/type-registry.h>
24 #include <dali/integration-api/debug.h>
25 #include <dali/internal/event/events/gesture-event-processor.h>
26
27 namespace Dali
28 {
29
30 namespace Internal
31 {
32
33 namespace
34 {
35
36 const unsigned int DEFAULT_TAPS_REQUIRED = 1u;
37 const unsigned int DEFAULT_TOUCHES_REQUIRED = 1u;
38
39 // Signals
40 const char* const SIGNAL_TAP_DETECTED = "tap-detected";
41
42 BaseHandle Create()
43 {
44   return Dali::TapGestureDetector::New();
45 }
46
47 TypeRegistration mType( typeid(Dali::TapGestureDetector), typeid(Dali::GestureDetector), Create );
48
49 SignalConnectorType signalConnector1( mType, SIGNAL_TAP_DETECTED, &TapGestureDetector::DoConnectSignal );
50
51 }
52
53 TapGestureDetectorPtr TapGestureDetector::New()
54 {
55   return new TapGestureDetector;
56 }
57
58 TapGestureDetectorPtr TapGestureDetector::New( unsigned int tapsRequired )
59 {
60   return new TapGestureDetector( tapsRequired );
61 }
62
63 TapGestureDetector::TapGestureDetector()
64 : GestureDetector( Gesture::Tap ),
65   mMinimumTapsRequired( DEFAULT_TAPS_REQUIRED ),
66   mMaximumTapsRequired( DEFAULT_TAPS_REQUIRED ),
67   mTouchesRequired( DEFAULT_TOUCHES_REQUIRED )
68 {
69 }
70
71 TapGestureDetector::TapGestureDetector( unsigned int tapsRequired )
72 : GestureDetector( Gesture::Tap ),
73   mMinimumTapsRequired( tapsRequired ),
74   mMaximumTapsRequired( tapsRequired ),
75   mTouchesRequired( DEFAULT_TOUCHES_REQUIRED )
76 {
77 }
78
79 TapGestureDetector::~TapGestureDetector()
80 {
81 }
82
83 void TapGestureDetector::SetMinimumTapsRequired(unsigned int taps)
84 {
85   if ( mMinimumTapsRequired != taps )
86   {
87     mMinimumTapsRequired = taps;
88
89     if ( !mAttachedActors.empty() )
90     {
91       mGestureEventProcessor.GestureDetectorUpdated(this);
92     }
93   }
94 }
95
96 void TapGestureDetector::SetMaximumTapsRequired(unsigned int taps)
97 {
98   if ( mMaximumTapsRequired != taps )
99   {
100     mMaximumTapsRequired = taps;
101
102     if ( !mAttachedActors.empty() )
103     {
104       mGestureEventProcessor.GestureDetectorUpdated(this);
105     }
106   }
107 }
108
109 void TapGestureDetector::SetTouchesRequired(unsigned int touches)
110 {
111   if (mTouchesRequired != touches)
112   {
113     mTouchesRequired = touches;
114
115     if (!mAttachedActors.empty())
116     {
117       mGestureEventProcessor.GestureDetectorUpdated(this);
118     }
119   }
120 }
121
122 unsigned int TapGestureDetector::GetMinimumTapsRequired() const
123 {
124   return mMinimumTapsRequired;
125 }
126
127 unsigned int TapGestureDetector::GetMaximumTapsRequired() const
128 {
129   return mMaximumTapsRequired;
130 }
131
132 unsigned int TapGestureDetector::GetTouchesRequired() const
133 {
134   return mTouchesRequired;
135 }
136
137 void TapGestureDetector::EmitTapGestureSignal(Dali::Actor tappedActor, const TapGesture& tap)
138 {
139   // Guard against destruction during signal emission
140   Dali::TapGestureDetector handle( this );
141
142   mDetectedSignal.Emit( tappedActor, tap );
143 }
144
145 bool TapGestureDetector::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
146 {
147   bool connected( true );
148   TapGestureDetector* gesture = dynamic_cast<TapGestureDetector*>(object);
149
150   if ( 0 == strcmp( signalName.c_str(), SIGNAL_TAP_DETECTED ) )
151   {
152     gesture->DetectedSignal().Connect( tracker, functor );
153   }
154   else
155   {
156     // signalName does not match any signal
157     connected = false;
158   }
159
160   return connected;
161 }
162
163 void TapGestureDetector::OnActorAttach(Actor& actor)
164 {
165   // Do nothing
166 }
167
168 void TapGestureDetector::OnActorDetach(Actor& actor)
169 {
170   // Do nothing
171 }
172
173 void TapGestureDetector::OnActorDestroyed(Object& object)
174 {
175   // Do nothing
176 }
177
178 } // namespace Internal
179
180 } // namespace Dali