// INTERNAL INCLUDES
#include <dali/integration-api/debug.h>
+#include <dali/integration-api/platform-abstraction.h>
+#include <dali/internal/event/common/thread-local-storage.h>
#include <dali/internal/event/events/gesture-event-processor.h>
+#include <dali/internal/event/events/tap-gesture/tap-gesture-impl.h>
#include <dali/public-api/events/tap-gesture.h>
#include <dali/public-api/object/type-registry.h>
{
namespace
{
-const unsigned int DEFAULT_TAPS_REQUIRED = 1u;
-const unsigned int DEFAULT_TOUCHES_REQUIRED = 1u;
+constexpr uint32_t DEFAULT_TAPS_REQUIRED = 1u;
+constexpr uint32_t DEFAULT_TOUCHES_REQUIRED = 1u;
+constexpr uint32_t DEFAULT_TAP_WAIT_TIME = 330u;
// Signals
const char* const SIGNAL_TAP_DETECTED = "tapDetected";
: GestureDetector(GestureType::TAP),
mMinimumTapsRequired(DEFAULT_TAPS_REQUIRED),
mMaximumTapsRequired(DEFAULT_TAPS_REQUIRED),
- mTouchesRequired(DEFAULT_TOUCHES_REQUIRED)
+ mTouchesRequired(DEFAULT_TOUCHES_REQUIRED),
+ mTimerId(0),
+ mTappedActor(),
+ mTap()
{
}
: GestureDetector(GestureType::TAP),
mMinimumTapsRequired(tapsRequired),
mMaximumTapsRequired(tapsRequired),
- mTouchesRequired(DEFAULT_TOUCHES_REQUIRED)
+ mTouchesRequired(DEFAULT_TOUCHES_REQUIRED),
+ mTimerId(0),
+ mTappedActor(),
+ mTap()
{
}
-TapGestureDetector::~TapGestureDetector() = default;
+TapGestureDetector::~TapGestureDetector()
+{
+ if(mTimerId != 0 && ThreadLocalStorage::Created())
+ {
+ Dali::Integration::PlatformAbstraction& platformAbstraction = ThreadLocalStorage::Get().GetPlatformAbstraction();
+ platformAbstraction.CancelTimer(mTimerId);
+ }
+}
void TapGestureDetector::SetMinimumTapsRequired(unsigned int taps)
{
void TapGestureDetector::EmitTapGestureSignal(Dali::Actor tappedActor, const Dali::TapGesture& tap)
{
+ Dali::Integration::PlatformAbstraction& platformAbstraction = ThreadLocalStorage::Get().GetPlatformAbstraction();
+ if(mTimerId != 0)
+ {
+ platformAbstraction.CancelTimer(mTimerId);
+ mTimerId = 0;
+ }
+ if(mMaximumTapsRequired > tap.GetNumberOfTaps())
+ {
+ mTappedActor = tappedActor;
+
+ Internal::TapGesturePtr internalTap(new Internal::TapGesture(tap.GetState()));
+ internalTap->SetTime(tap.GetTime());
+ internalTap->SetNumberOfTaps(tap.GetNumberOfTaps());
+ internalTap->SetNumberOfTouches(tap.GetNumberOfTouches());
+ internalTap->SetScreenPoint(tap.GetScreenPoint());
+ internalTap->SetLocalPoint(tap.GetLocalPoint());
+ internalTap->SetGestureSourceType(tap.GetSourceType());
+ mTap = Dali::TapGesture(internalTap.Get());
+
+ mTimerId = platformAbstraction.StartTimer(DEFAULT_TAP_WAIT_TIME, MakeCallback(this, &TapGestureDetector::TimerCallback));
+ }
+ else
+ {
+ // Guard against destruction during signal emission
+ Dali::TapGestureDetector handle(this);
+
+ mDetectedSignal.Emit(tappedActor, tap);
+ }
+}
+
+bool TapGestureDetector::TimerCallback()
+{
// Guard against destruction during signal emission
Dali::TapGestureDetector handle(this);
- mDetectedSignal.Emit(tappedActor, tap);
+ mDetectedSignal.Emit(mTappedActor, mTap);
+
+ mTimerId = 0;
+ return false;
}
bool TapGestureDetector::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor)
} // namespace Internal
-} // namespace Dali
+} // namespace Dali
\ No newline at end of file
TapGestureDetector(const TapGestureDetector&);
TapGestureDetector& operator=(const TapGestureDetector& rhs);
+ /**
+ * Timer Callback
+ * @return will return false; one-shot timer.
+ */
+ bool TimerCallback();
+
private: // GestureDetector overrides
/**
* @copydoc Dali::Internal::GestureDetector::OnActorAttach(Actor&)
private:
Dali::TapGestureDetector::DetectedSignalType mDetectedSignal;
- unsigned int mMinimumTapsRequired;
- unsigned int mMaximumTapsRequired;
- unsigned int mTouchesRequired;
+ unsigned int mMinimumTapsRequired;
+ unsigned int mMaximumTapsRequired;
+ unsigned int mTouchesRequired;
+ uint32_t mTimerId;
+ Dali::Actor mTappedActor;
+ Dali::TapGesture mTap;
};
} // namespace Internal
} // namespace Dali
-#endif // DALI_INTERNAL_TAP_GESTURE_DETECTOR_H
+#endif // DALI_INTERNAL_TAP_GESTURE_DETECTOR_H
\ No newline at end of file
#include <dali/public-api/math/vector2.h>
-// INTERNAL INCLUDES
#include <dali/integration-api/events/touch-event-integ.h>
-#include <dali/integration-api/platform-abstraction.h>
+
+// INTERNAL INCLUDES
#include <dali/internal/event/common/scene-impl.h>
-#include <dali/internal/event/common/thread-local-storage.h>
#include <dali/internal/event/events/gesture-requests.h>
namespace Dali
// TODO: Set these according to DPI
const float MAXIMUM_MOTION_ALLOWED = 20.0f;
const unsigned long MAXIMUM_TIME_ALLOWED = 500u;
-const uint32_t WAIT_TIME = 330u;
} // unnamed namespace
TapGestureRecognizer::TapGestureRecognizer(Observer& observer, Vector2 screenSize, const TapGestureRequest& request)
mTouchPosition(),
mTouchTime(0u),
mLastTapTime(0u),
- mEventTime(0u),
- mGestureSourceType(GestureSourceType::INVALID),
- mTimerId(0)
+ mGestureSourceType(GestureSourceType::INVALID)
{
}
-TapGestureRecognizer::~TapGestureRecognizer()
-{
- if(mTimerId != 0 && ThreadLocalStorage::Created())
- {
- Dali::Integration::PlatformAbstraction& platformAbstraction = ThreadLocalStorage::Get().GetPlatformAbstraction();
- platformAbstraction.CancelTimer(mTimerId);
- }
-}
+TapGestureRecognizer::~TapGestureRecognizer() = default;
void TapGestureRecognizer::SendEvent(const Integration::TouchEvent& event)
{
if(event.GetPointCount() == 1)
{
- const Integration::Point& point = event.points[0];
- PointState::Type pointState = point.GetState();
- Dali::Integration::PlatformAbstraction& platformAbstraction = ThreadLocalStorage::Get().GetPlatformAbstraction();
+ const Integration::Point& point = event.points[0];
+ PointState::Type pointState = point.GetState();
MouseButton::Type mouseButton = point.GetMouseButton();
switch(mouseButton)
{
if(deltaBetweenTouchDownTouchUp < MAXIMUM_TIME_ALLOWED)
{
- if(mMaximumTapsRequired > mMinimumTapsRequired)
- {
- mEventTime = event.time;
- mTimerId = platformAbstraction.StartTimer(WAIT_TIME, MakeCallback(this, &TapGestureRecognizer::TimerCallback));
- }
-
mLastTapTime = mTouchTime;
EmitSingleTap(event.time, point);
mState = REGISTERED;
else if(deltaBetweenTouchDownTouchUp < MAXIMUM_TIME_ALLOWED)
{
++mTapsRegistered;
- if(mMaximumTapsRequired > mMinimumTapsRequired)
- {
- mEventTime = event.time;
- mTimerId = platformAbstraction.StartTimer(WAIT_TIME, MakeCallback(this, &TapGestureRecognizer::TimerCallback));
- }
- else
- {
- EmitGesture(GestureState::STARTED, event.time);
- }
+ EmitGesture(GestureState::STARTED, event.time);
}
else // Delta between touch down and touch up too long to be considered a TAP event
{
{
EmitPossibleState(event);
}
-
- if(mTimerId != 0)
- {
- platformAbstraction.CancelTimer(mTimerId);
- mTimerId = 0;
- }
}
break;
}
}
}
-bool TapGestureRecognizer::TimerCallback()
-{
- EmitGesture(GestureState::STARTED, mEventTime);
-
- mTimerId = 0;
- return false;
-}
-
void TapGestureRecognizer::SetupForTouchDown(const Integration::TouchEvent& event, const Integration::Point& point)
{
mTouchPosition = point.GetScreenPosition();
Vector2 distanceDelta(std::abs(mTouchPosition.x - screen.x),
std::abs(mTouchPosition.y - screen.y));
- mTapsRegistered = 1u;
if(distanceDelta.x > MAXIMUM_MOTION_ALLOWED ||
distanceDelta.y > MAXIMUM_MOTION_ALLOWED)
{
event.state = GestureState::CANCELLED;
- if(mTimerId != 0)
- {
- Dali::Integration::PlatformAbstraction& platformAbstraction = ThreadLocalStorage::Get().GetPlatformAbstraction();
- platformAbstraction.CancelTimer(mTimerId);
- mTimerId = 0;
- }
- }
- if(mTimerId == 0)
- {
- EmitTap(time, event);
}
+ mTapsRegistered = 1u;
+ EmitTap(time, event);
}
void TapGestureRecognizer::EmitTap(uint32_t time, TapGestureEvent& event)
*/
void ProcessEvent(TapGestureEvent& event);
- /**
- * Timer Callback
- * @return will return false; one-shot timer.
- */
- bool TimerCallback();
-
private:
// Reference to the gesture processor for this recognizer
Observer& mObserver;
Vector2 mTouchPosition; ///< The initial touch down position.
uint32_t mTouchTime; ///< The initial touch down time.
uint32_t mLastTapTime; ///< Time last tap gesture was registered
- uint32_t mEventTime; ///< The touch event time.
GestureSourceType mGestureSourceType; /// < Gesture input source type value.
-
- uint32_t mTimerId;
};
} // namespace Internal