/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
application.ProcessEvent(GenerateSingleTouch(PointState::UP, pos, time));
}
+void TestTriggerTap(TestApplication& application)
+{
+ application.GetPlatform().TriggerTimer();
+}
+
void TestGenerateTap(TestApplication& application, float x, float y, uint32_t time_down)
{
application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(x, y), time_down));
application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(x, y), time_down + 20));
+ TestTriggerTap(application);
}
void TestGenerateTwoPointTap(TestApplication& application, float x1, float y1, float x2, float y2, uint32_t time_down)
{
application.ProcessEvent(GenerateDoubleTouch(PointState::DOWN, Vector2(x1, y1), PointState::DOWN, Vector2(x2, y2), time_down));
application.ProcessEvent(GenerateDoubleTouch(PointState::UP, Vector2(x1, y1), PointState::UP, Vector2(x2, y2), time_down + 20));
+ TestTriggerTap(application);
}
void TestGenerateRotation(TestApplication& application)
#define DALI_TEST_GESTURE_GENERATOR_H
/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
void TestEndPan(TestApplication& application, Vector2 pos, uint32_t time = 500);
/**
+ * Triggers the timer to begin a tap gesture
+ */
+void TestTriggerTap(TestApplication& application);
+
+/**
* Produces a single point tap gesture with a 20ms interval
*/
void TestGenerateTap(TestApplication& application, float x = 20.0f, float y = 20.0f, uint32_t time_down = 100);
TestApplication application;
TapGestureDetector detector = TapGestureDetector::New();
+ detector.SetMaximumTapsRequired(2);
Actor actor = Actor::New();
actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
application.SendNotification();
+ application.GetPlatform().TriggerTimer();
DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
END_TEST;
application.SendNotification();
+ application.GetPlatform().TriggerTimer();
DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
DALI_TEST_EQUALS(true, actor == data.tappedActor, TEST_LOCATION);
data.Reset();
application.SendNotification();
+ application.GetPlatform().TriggerTimer();
DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
DALI_TEST_EQUALS(true, data2.functorCalled, TEST_LOCATION);
#include <dali/public-api/math/vector2.h>
-#include <dali/integration-api/events/touch-event-integ.h>
-
// INTERNAL INCLUDES
+#include <dali/integration-api/events/touch-event-integ.h>
+#include <dali/integration-api/platform-abstraction.h>
#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
mTouchPosition(),
mTouchTime(0u),
mLastTapTime(0u),
- mGestureSourceType(GestureSourceType::INVALID)
+ mEventTime(0u),
+ mGestureSourceType(GestureSourceType::INVALID),
+ mTimerId(0)
{
}
-TapGestureRecognizer::~TapGestureRecognizer() = default;
+TapGestureRecognizer::~TapGestureRecognizer()
+{
+ if(mTimerId != 0 && ThreadLocalStorage::Created())
+ {
+ Dali::Integration::PlatformAbstraction& platformAbstraction = ThreadLocalStorage::Get().GetPlatformAbstraction();
+ platformAbstraction.CancelTimer(mTimerId);
+ }
+}
void TapGestureRecognizer::SendEvent(const Integration::TouchEvent& event)
{
if(event.GetPointCount() == 1)
{
- const Integration::Point& point = event.points[0];
- PointState::Type pointState = point.GetState();
+ const Integration::Point& point = event.points[0];
+ PointState::Type pointState = point.GetState();
+ Dali::Integration::PlatformAbstraction& platformAbstraction = ThreadLocalStorage::Get().GetPlatformAbstraction();
MouseButton::Type mouseButton = point.GetMouseButton();
switch(mouseButton)
{
if(deltaBetweenTouchDownTouchUp < MAXIMUM_TIME_ALLOWED)
{
+ if(mMaximumTapsRequired > mMinimumTapsRequired)
+ {
+ mEventTime = event.time;
+ mTimerId = platformAbstraction.StartTimer(MAXIMUM_TIME_ALLOWED, MakeCallback(this, &TapGestureRecognizer::TimerCallback));
+ }
+
mLastTapTime = mTouchTime;
EmitSingleTap(event.time, point);
mState = REGISTERED;
else if(deltaBetweenTouchDownTouchUp < MAXIMUM_TIME_ALLOWED)
{
++mTapsRegistered;
- EmitGesture(GestureState::STARTED, event.time);
+ if(mMaximumTapsRequired > mMinimumTapsRequired)
+ {
+ mEventTime = event.time;
+ mTimerId = platformAbstraction.StartTimer(MAXIMUM_TIME_ALLOWED, MakeCallback(this, &TapGestureRecognizer::TimerCallback));
+ }
+ else
+ {
+ 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