END_TEST;
}
+
+int UtcDaliTapGestureSetMaximumMotionAllowedDistance(void)
+{
+ TestApplication application;
+
+ TapGestureDetector detector = TapGestureDetector::New();
+
+ Actor actor = Actor::New();
+ actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
+ actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+ application.GetScene().Add(actor);
+
+ // Render and notify
+ application.SendNotification();
+ application.Render();
+
+ detector.Attach(actor);
+
+ try
+ {
+ Integration::SetTapMaximumMotionAllowedDistance(0);
+ }
+ catch(...)
+ {
+ DALI_TEST_CHECK(false); // Should not get here
+ }
+
+ // increase the distance. 20 -> 50
+ Integration::SetTapMaximumMotionAllowedDistance(50);
+
+ SignalData data;
+ GestureReceivedFunctor functor(data);
+ detector.DetectedSignal().Connect(&application, functor);
+
+ application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
+
+ application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(60.0f, 60.0f), 200));
+
+ application.SendNotification();
+
+ DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
+ data.Reset();
+
+ application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 300));
+
+ application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(80.0f, 80.0f), 450));
+
+ application.SendNotification();
+
+ // The tap fails because the distance has been exceeded
+ DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
+
+ // reset distance
+ Integration::SetTapMaximumMotionAllowedDistance(20);
+
+ END_TEST;
+}
eventProcessor.SetTapRecognizerTime(time);
}
+void SetTapMaximumMotionAllowedDistance(float distance)
+{
+ GestureEventProcessor& eventProcessor = ThreadLocalStorage::Get().GetGestureEventProcessor();
+ eventProcessor.SetTapMaximumMotionAllowedDistance(distance);
+}
+
} // namespace Integration
} // namespace Dali
*/
DALI_CORE_API void SetTapRecognizerTime(uint32_t time);
+/**
+ * @brief Sets the recognizer distance required to be recognized as a tap gesture
+ *
+ * This distance is from touch down to touch up to recognize the tap gesture.
+ *
+ * @note The tab is like below:
+ * touch down <--distance--> touch up
+ * If the distance between touch down and touch up is longer than distance, it is not recognized as a tap gesture.
+ * Default value is 20
+ *
+ * @see SetTapMaximumMotionAllowedDistance()
+ *
+ * @param[in] distance The distance
+ */
+DALI_CORE_API void SetTapMaximumMotionAllowedDistance(float distance);
+
} // namespace Integration
} // namespace Dali
mTapGestureProcessor.SetRecognizerTime(time);
}
+void GestureEventProcessor::SetTapMaximumMotionAllowedDistance(float distance)
+{
+ mTapGestureProcessor.SetMaximumMotionAllowedDistance(distance);
+}
+
const TapGestureProcessor& GestureEventProcessor::GetTapGestureProcessor()
{
return mTapGestureProcessor;
*/
void SetTapRecognizerTime(uint32_t time);
+ /**
+ * @brief Sets the recognizer distance required to be recognized as a tap gesture
+ *
+ * This distance is from touch down to touch up to recognize the tap gesture.
+ *
+ * @param[in] distance The distance
+ */
+ void SetTapMaximumMotionAllowedDistance(float distance);
+
public: // needed for PanGesture
/**
* @return the pan gesture processor
DALI_INIT_TRACE_FILTER(gTraceFilter, DALI_TRACE_PERFORMANCE_MARKER, false);
constexpr uint32_t DEFAULT_MAXIMUM_ALLOWED_TIME = 330u;
constexpr uint32_t DEFAULT_RECOGNIZER_TIME = 330u;
+// TODO: Set these according to DPI
+constexpr float DEFAULT_MAXIMUM_MOTION_ALLOWED = 20.0f;
/**
* Creates a TapGesture and asks the specified detector to emit its detected signal.
mCurrentTapEvent(nullptr),
mPossibleProcessed(false),
mMaximumAllowedTime(DEFAULT_MAXIMUM_ALLOWED_TIME),
- mRecognizerTime(DEFAULT_RECOGNIZER_TIME)
+ mRecognizerTime(DEFAULT_RECOGNIZER_TIME),
+ mMaximumMotionAllowedDistance(DEFAULT_MAXIMUM_MOTION_ALLOWED)
{
}
request.maxTouches = mMaxTouchesRequired;
Size size = scene.GetSize();
- mGestureRecognizer = new TapGestureRecognizer(*this, Vector2(size.width, size.height), static_cast<const TapGestureRequest&>(request), mMaximumAllowedTime, mRecognizerTime);
+ mGestureRecognizer = new TapGestureRecognizer(*this, Vector2(size.width, size.height), static_cast<const TapGestureRequest&>(request), mMaximumAllowedTime, mRecognizerTime, mMaximumMotionAllowedDistance);
}
else
{
}
}
+void TapGestureProcessor::SetMaximumMotionAllowedDistance(float distance)
+{
+ if(distance < 0.0f)
+ {
+ DALI_LOG_WARNING("distance must be greater than zero.");
+ return;
+ }
+
+ mMaximumMotionAllowedDistance = distance;
+
+ if(mGestureRecognizer)
+ {
+ TapGestureRecognizer* tapRecognizer = dynamic_cast<TapGestureRecognizer*>(mGestureRecognizer.Get());
+ if(tapRecognizer)
+ {
+ tapRecognizer->SetMaximumMotionAllowedDistance(distance);
+ }
+ }
+}
+
void TapGestureProcessor::UpdateDetection()
{
DALI_ASSERT_DEBUG(!mTapGestureDetectors.empty());
*/
void SetRecognizerTime(uint32_t time);
+ /**
+ * @brief This method sets the recognizer distance required to be recognized as a tap gesture
+ *
+ * This distance is from touch down to touch up to recognize the tap gesture.
+ *
+ * @param[in] distance The distance
+ */
+ void SetMaximumMotionAllowedDistance(float distance);
+
private:
// Undefined
TapGestureProcessor(const TapGestureProcessor&);
private:
TapGestureDetectorContainer mTapGestureDetectors;
- unsigned int mMinTouchesRequired;
- unsigned int mMaxTouchesRequired;
+ uint32_t mMinTouchesRequired;
+ uint32_t mMaxTouchesRequired;
ActorObserver mCurrentTapActor; ///< Observer for the current gesture actor
const TapGestureEvent* mCurrentTapEvent; ///< Pointer to current TapEvent, used when calling ProcessAndEmit()
bool mPossibleProcessed; ///< Indication of whether we've processed a touch down for this gestuee
- uint32_t mMaximumAllowedTime; ///< The maximum allowed time required to be recognized as a multi tap gesture (millisecond)
- uint32_t mRecognizerTime; ///< The recognizer time required to be recognized as a tap gesture (millisecond)
+ uint32_t mMaximumAllowedTime; ///< The maximum allowed time required to be recognized as a multi tap gesture (millisecond)
+ uint32_t mRecognizerTime; ///< The recognizer time required to be recognized as a tap gesture (millisecond)
+ float mMaximumMotionAllowedDistance; ///< The recognizer distance required to be recognized as a tap gesture
};
} // namespace Internal
{
namespace Internal
{
-namespace
-{
-// TODO: Set these according to DPI
-constexpr float MAXIMUM_MOTION_ALLOWED = 20.0f;
-} // unnamed namespace
-TapGestureRecognizer::TapGestureRecognizer(Observer& observer, Vector2 screenSize, const TapGestureRequest& request, uint32_t maximumAllowedTime, uint32_t recognizerTime)
+TapGestureRecognizer::TapGestureRecognizer(Observer& observer, Vector2 screenSize, const TapGestureRequest& request, uint32_t maximumAllowedTime, uint32_t recognizerTime, float maximumMotionAllowedDistance)
: GestureRecognizer(screenSize, GestureType::TAP),
mObserver(observer),
mState(CLEAR),
mLastTapTime(0u),
mDeltaBetweenTouchDownTouchUp(0u),
mMaximumAllowedTime(maximumAllowedTime),
- mRecognizerTime(recognizerTime)
+ mRecognizerTime(recognizerTime),
+ mMaximumMotionAllowedDistance(maximumMotionAllowedDistance)
{
}
mDeltaBetweenTouchDownTouchUp = event.time - mTouchTime;
if(mDeltaBetweenTouchDownTouchUp < mRecognizerTime)
{
- EmitGesture(GestureState::STARTED, event.time);
+ const Vector2& screen(point.GetScreenPosition());
+ Vector2 distanceDelta(std::abs(mTouchPosition.x - screen.x),
+ std::abs(mTouchPosition.y - screen.y));
+ if(distanceDelta.x > mMaximumMotionAllowedDistance ||
+ distanceDelta.y > mMaximumMotionAllowedDistance)
+ {
+ mState = CLEAR;
+ DALI_LOG_RELEASE_INFO("There is a long distance between touch down and touch up. (%f or %f > %f)\n", distanceDelta.x, distanceDelta.y, mMaximumMotionAllowedDistance);
+ }
+ else
+ {
+ EmitGesture(GestureState::STARTED, event.time);
+ }
}
else // Clear if the time between touch down and touch up is long.
{
uint32_t timeDelta = event.time - mLastTapTime;
mTouchTime = event.time;
- if(distanceDelta.x > MAXIMUM_MOTION_ALLOWED ||
- distanceDelta.y > MAXIMUM_MOTION_ALLOWED ||
+ if(distanceDelta.x > mMaximumMotionAllowedDistance ||
+ distanceDelta.y > mMaximumMotionAllowedDistance ||
timeDelta > mMaximumAllowedTime) // If the time between tabs is long, it starts over from SetupForTouchDown.
{
SetupForTouchDown(event, point);
mRecognizerTime = time;
}
+void TapGestureRecognizer::SetMaximumMotionAllowedDistance(float distance)
+{
+ mMaximumMotionAllowedDistance = distance;
+}
+
void TapGestureRecognizer::EmitGesture(GestureState state, uint32_t time)
{
TapGestureEvent event(state);
Vector2 distanceDelta(std::abs(mTouchPosition.x - screen.x),
std::abs(mTouchPosition.y - screen.y));
- if(distanceDelta.x > MAXIMUM_MOTION_ALLOWED ||
- distanceDelta.y > MAXIMUM_MOTION_ALLOWED)
+ if(distanceDelta.x > mMaximumMotionAllowedDistance ||
+ distanceDelta.y > mMaximumMotionAllowedDistance)
{
event.state = GestureState::CANCELLED;
}
* @param[in] request The tap gesture request.
* @param[in] maximumAllowedTime The maximum allowed time required in milliseconds.
* @param[in] recognizerTime This recognizer time required in milliseconds.
+ * @param[in] maximumMotionAllowedDistance This recognizer distance required.
*/
- TapGestureRecognizer(Observer& observer, Vector2 screenSize, const TapGestureRequest& request, uint32_t maximumAllowedTime, uint32_t recognizerTime);
+ TapGestureRecognizer(Observer& observer, Vector2 screenSize, const TapGestureRequest& request, uint32_t maximumAllowedTime, uint32_t recognizerTime, float maximumMotionAllowedDistance);
/**
* Virtual destructor.
*/
void SetRecognizerTime(uint32_t time);
+
+ /**
+ * @brief This method sets the recognizer distance required to be recognized as a tap gesture
+ *
+ * This distance is from touch down to touch up to recognize the tap gesture.
+ *
+ * @param[in] distance The distance
+ */
+ void SetMaximumMotionAllowedDistance(float distance);
+
+
private:
/**
* Checks if registered taps are within required bounds and emits tap gesture if they are.
uint32_t mDeltaBetweenTouchDownTouchUp; ///< Time from touchdown to touchup
uint32_t mMaximumAllowedTime; ///< The maximum allowed time required to be recognized as a multi tap gesture (millisecond)
uint32_t mRecognizerTime; ///< The recognizer time required to be recognized as a tap gesture (millisecond)
+ float mMaximumMotionAllowedDistance; ///< The recognizer distance required to be recognized as a tap gesture
};
} // namespace Internal