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 <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>
36 const unsigned int DEFAULT_TAPS_REQUIRED = 1u;
37 const unsigned int DEFAULT_TOUCHES_REQUIRED = 1u;
40 const char* const SIGNAL_TAP_DETECTED = "tap-detected";
44 return Dali::TapGestureDetector::New();
47 TypeRegistration mType( typeid(Dali::TapGestureDetector), typeid(Dali::GestureDetector), Create );
49 SignalConnectorType signalConnector1( mType, SIGNAL_TAP_DETECTED, &TapGestureDetector::DoConnectSignal );
53 TapGestureDetectorPtr TapGestureDetector::New()
55 return new TapGestureDetector;
58 TapGestureDetectorPtr TapGestureDetector::New( unsigned int tapsRequired )
60 return new TapGestureDetector( tapsRequired );
63 TapGestureDetector::TapGestureDetector()
64 : GestureDetector( Gesture::Tap ),
65 mMinimumTapsRequired( DEFAULT_TAPS_REQUIRED ),
66 mMaximumTapsRequired( DEFAULT_TAPS_REQUIRED ),
67 mTouchesRequired( DEFAULT_TOUCHES_REQUIRED )
71 TapGestureDetector::TapGestureDetector( unsigned int tapsRequired )
72 : GestureDetector( Gesture::Tap ),
73 mMinimumTapsRequired( tapsRequired ),
74 mMaximumTapsRequired( tapsRequired ),
75 mTouchesRequired( DEFAULT_TOUCHES_REQUIRED )
79 TapGestureDetector::~TapGestureDetector()
83 void TapGestureDetector::SetMinimumTapsRequired(unsigned int taps)
85 if ( mMinimumTapsRequired != taps )
87 mMinimumTapsRequired = taps;
89 if ( !mAttachedActors.empty() )
91 mGestureEventProcessor.GestureDetectorUpdated(this);
96 void TapGestureDetector::SetMaximumTapsRequired(unsigned int taps)
98 if ( mMaximumTapsRequired != taps )
100 mMaximumTapsRequired = taps;
102 if ( !mAttachedActors.empty() )
104 mGestureEventProcessor.GestureDetectorUpdated(this);
109 void TapGestureDetector::SetTouchesRequired(unsigned int touches)
111 if (mTouchesRequired != touches)
113 mTouchesRequired = touches;
115 if (!mAttachedActors.empty())
117 mGestureEventProcessor.GestureDetectorUpdated(this);
122 unsigned int TapGestureDetector::GetMinimumTapsRequired() const
124 return mMinimumTapsRequired;
127 unsigned int TapGestureDetector::GetMaximumTapsRequired() const
129 return mMaximumTapsRequired;
132 unsigned int TapGestureDetector::GetTouchesRequired() const
134 return mTouchesRequired;
137 void TapGestureDetector::EmitTapGestureSignal(Dali::Actor tappedActor, const TapGesture& tap)
139 // Guard against destruction during signal emission
140 Dali::TapGestureDetector handle( this );
142 mDetectedSignal.Emit( tappedActor, tap );
145 bool TapGestureDetector::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
147 bool connected( true );
148 TapGestureDetector* gesture = dynamic_cast<TapGestureDetector*>(object);
150 if ( 0 == strcmp( signalName.c_str(), SIGNAL_TAP_DETECTED ) )
152 gesture->DetectedSignal().Connect( tracker, functor );
156 // signalName does not match any signal
163 void TapGestureDetector::OnActorAttach(Actor& actor)
168 void TapGestureDetector::OnActorDetach(Actor& actor)
173 void TapGestureDetector::OnActorDestroyed(Object& object)
178 } // namespace Internal