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>
37 const char* const SIGNAL_TAP_DETECTED = "tap-detected";
41 return Dali::TapGestureDetector::New();
44 TypeRegistration mType( typeid(Dali::TapGestureDetector), typeid(Dali::GestureDetector), Create );
46 SignalConnectorType signalConnector1( mType, SIGNAL_TAP_DETECTED, &TapGestureDetector::DoConnectSignal );
50 TapGestureDetectorPtr TapGestureDetector::New()
52 return new TapGestureDetector;
55 TapGestureDetectorPtr TapGestureDetector::New(unsigned int tapsRequired, unsigned int touchesRequired)
57 return new TapGestureDetector(tapsRequired, touchesRequired);
60 TapGestureDetector::TapGestureDetector()
61 : GestureDetector(Gesture::Tap),
67 TapGestureDetector::TapGestureDetector(unsigned int tapsRequired, unsigned int touchesRequired)
68 : GestureDetector(Gesture::Tap),
69 mTapsRequired(tapsRequired),
70 mTouchesRequired(touchesRequired)
74 TapGestureDetector::~TapGestureDetector()
78 void TapGestureDetector::SetTapsRequired(unsigned int taps)
80 DALI_ASSERT_ALWAYS(taps > 0 && "Can only set a positive number of taps" );
82 if (mTapsRequired != taps)
86 if (!mAttachedActors.empty())
88 mGestureEventProcessor.GestureDetectorUpdated(this);
93 void TapGestureDetector::SetTouchesRequired(unsigned int touches)
95 DALI_ASSERT_ALWAYS(touches > 0 && "Can only set a positive number of touches" );
97 if (mTouchesRequired != touches)
99 mTouchesRequired = touches;
101 if (!mAttachedActors.empty())
103 mGestureEventProcessor.GestureDetectorUpdated(this);
108 unsigned int TapGestureDetector::GetTapsRequired() const
110 return mTapsRequired;
113 unsigned int TapGestureDetector::GetTouchesRequired() const
115 return mTouchesRequired;
118 void TapGestureDetector::EmitTapGestureSignal(Dali::Actor tappedActor, const TapGesture& tap)
120 // Guard against destruction during signal emission
121 Dali::TapGestureDetector handle( this );
123 mDetectedSignal.Emit( tappedActor, tap );
126 bool TapGestureDetector::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
128 bool connected( true );
129 TapGestureDetector* gesture = dynamic_cast<TapGestureDetector*>(object);
131 if ( 0 == strcmp( signalName.c_str(), SIGNAL_TAP_DETECTED ) )
133 gesture->DetectedSignal().Connect( tracker, functor );
137 // signalName does not match any signal
144 void TapGestureDetector::OnActorAttach(Actor& actor)
149 void TapGestureDetector::OnActorDetach(Actor& actor)
154 void TapGestureDetector::OnActorDestroyed(Object& object)
159 } // namespace Internal