2 * Copyright (c) 2021 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/tap-gesture-detector-impl.h>
22 #include <cstring> // for strcmp
25 #include <dali/integration-api/debug.h>
26 #include <dali/internal/event/events/gesture-event-processor.h>
27 #include <dali/public-api/events/tap-gesture.h>
28 #include <dali/public-api/object/type-registry.h>
36 const unsigned int DEFAULT_TAPS_REQUIRED = 1u;
37 const unsigned int DEFAULT_TOUCHES_REQUIRED = 1u;
40 const char* const SIGNAL_TAP_DETECTED = "tapDetected";
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(GestureType::TAP),
65 mMinimumTapsRequired(DEFAULT_TAPS_REQUIRED),
66 mMaximumTapsRequired(DEFAULT_TAPS_REQUIRED),
67 mTouchesRequired(DEFAULT_TOUCHES_REQUIRED)
71 TapGestureDetector::TapGestureDetector(unsigned int tapsRequired)
72 : GestureDetector(GestureType::TAP),
73 mMinimumTapsRequired(tapsRequired),
74 mMaximumTapsRequired(tapsRequired),
75 mTouchesRequired(DEFAULT_TOUCHES_REQUIRED)
79 TapGestureDetector::~TapGestureDetector() = default;
81 void TapGestureDetector::SetMinimumTapsRequired(unsigned int taps)
83 if(mMinimumTapsRequired != taps)
85 mMinimumTapsRequired = taps;
87 if(!mAttachedActors.empty())
89 mGestureEventProcessor.GestureDetectorUpdated(this);
94 void TapGestureDetector::SetMaximumTapsRequired(unsigned int taps)
96 if(mMaximumTapsRequired != taps)
98 mMaximumTapsRequired = taps;
100 if(!mAttachedActors.empty())
102 mGestureEventProcessor.GestureDetectorUpdated(this);
107 void TapGestureDetector::SetTouchesRequired(unsigned int touches)
109 if(mTouchesRequired != touches)
111 mTouchesRequired = touches;
113 if(!mAttachedActors.empty())
115 mGestureEventProcessor.GestureDetectorUpdated(this);
120 unsigned int TapGestureDetector::GetMinimumTapsRequired() const
122 return mMinimumTapsRequired;
125 unsigned int TapGestureDetector::GetMaximumTapsRequired() const
127 return mMaximumTapsRequired;
130 unsigned int TapGestureDetector::GetTouchesRequired() const
132 return mTouchesRequired;
135 void TapGestureDetector::EmitTapGestureSignal(Dali::Actor tappedActor, const Dali::TapGesture& tap)
137 // Guard against destruction during signal emission
138 Dali::TapGestureDetector handle(this);
140 mDetectedSignal.Emit(tappedActor, tap);
143 bool TapGestureDetector::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor)
145 bool connected(true);
146 TapGestureDetector* gesture = static_cast<TapGestureDetector*>(object); // TypeRegistry guarantees that this is the correct type.
148 if(0 == strcmp(signalName.c_str(), SIGNAL_TAP_DETECTED))
150 gesture->DetectedSignal().Connect(tracker, functor);
154 // signalName does not match any signal
161 void TapGestureDetector::OnActorAttach(Actor& actor)
166 void TapGestureDetector::OnActorDetach(Actor& actor)
171 void TapGestureDetector::OnActorDestroyed(Object& object)
176 } // namespace Internal