2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/internal/event/events/tap-gesture-detector-impl.h>
22 #include <cstring> // for strcmp
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>
39 const unsigned int DEFAULT_TAPS_REQUIRED = 1u;
40 const unsigned int DEFAULT_TOUCHES_REQUIRED = 1u;
43 const char* const SIGNAL_TAP_DETECTED = "tap-detected";
47 return Dali::TapGestureDetector::New();
50 TypeRegistration mType( typeid(Dali::TapGestureDetector), typeid(Dali::GestureDetector), Create );
52 SignalConnectorType signalConnector1( mType, SIGNAL_TAP_DETECTED, &TapGestureDetector::DoConnectSignal );
56 TapGestureDetectorPtr TapGestureDetector::New()
58 return new TapGestureDetector;
61 TapGestureDetectorPtr TapGestureDetector::New( unsigned int tapsRequired )
63 return new TapGestureDetector( tapsRequired );
66 TapGestureDetector::TapGestureDetector()
67 : GestureDetector( Gesture::Tap ),
68 mMinimumTapsRequired( DEFAULT_TAPS_REQUIRED ),
69 mMaximumTapsRequired( DEFAULT_TAPS_REQUIRED ),
70 mTouchesRequired( DEFAULT_TOUCHES_REQUIRED )
74 TapGestureDetector::TapGestureDetector( unsigned int tapsRequired )
75 : GestureDetector( Gesture::Tap ),
76 mMinimumTapsRequired( tapsRequired ),
77 mMaximumTapsRequired( tapsRequired ),
78 mTouchesRequired( DEFAULT_TOUCHES_REQUIRED )
82 TapGestureDetector::~TapGestureDetector()
86 void TapGestureDetector::SetMinimumTapsRequired(unsigned int taps)
88 if ( mMinimumTapsRequired != taps )
90 mMinimumTapsRequired = taps;
92 if ( !mAttachedActors.empty() )
94 mGestureEventProcessor.GestureDetectorUpdated(this);
99 void TapGestureDetector::SetMaximumTapsRequired(unsigned int taps)
101 if ( mMaximumTapsRequired != taps )
103 mMaximumTapsRequired = taps;
105 if ( !mAttachedActors.empty() )
107 mGestureEventProcessor.GestureDetectorUpdated(this);
112 void TapGestureDetector::SetTouchesRequired(unsigned int touches)
114 if (mTouchesRequired != touches)
116 mTouchesRequired = touches;
118 if (!mAttachedActors.empty())
120 mGestureEventProcessor.GestureDetectorUpdated(this);
125 unsigned int TapGestureDetector::GetMinimumTapsRequired() const
127 return mMinimumTapsRequired;
130 unsigned int TapGestureDetector::GetMaximumTapsRequired() const
132 return mMaximumTapsRequired;
135 unsigned int TapGestureDetector::GetTouchesRequired() const
137 return mTouchesRequired;
140 void TapGestureDetector::EmitTapGestureSignal(Dali::Actor tappedActor, const TapGesture& tap)
142 // Guard against destruction during signal emission
143 Dali::TapGestureDetector handle( this );
145 mDetectedSignal.Emit( tappedActor, tap );
148 bool TapGestureDetector::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
150 bool connected( true );
151 TapGestureDetector* gesture = dynamic_cast<TapGestureDetector*>(object);
153 if ( 0 == strcmp( signalName.c_str(), SIGNAL_TAP_DETECTED ) )
155 gesture->DetectedSignal().Connect( tracker, functor );
159 // signalName does not match any signal
166 void TapGestureDetector::OnActorAttach(Actor& actor)
171 void TapGestureDetector::OnActorDetach(Actor& actor)
176 void TapGestureDetector::OnActorDestroyed(Object& object)
181 } // namespace Internal