/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
#include <cmath>
// INTERNAL INCLUDES
-#include <dali/public-api/events/touch-point.h>
+#include <dali/devel-api/events/touch-point.h>
#include <dali/public-api/math/vector2.h>
-#include <dali/devel-api/events/gesture-devel.h>
#include <dali/integration-api/events/touch-event-integ.h>
#include <dali/internal/event/events/rotation-gesture/rotation-gesture-event.h>
#include <dali/internal/event/common/scene-impl.h>
namespace
{
-const unsigned int MINIMUM_TOUCH_EVENTS_REQUIRED = 4;
-const unsigned int MINIMUM_TOUCH_EVENTS_REQUIRED_AFTER_START = 4;
inline float GetAngle( const Integration::Point& point1, const Integration::Point& point2 )
{
} // unnamed namespace
-RotationGestureRecognizer::RotationGestureRecognizer( Observer& observer )
-: GestureRecognizer( DevelGesture::Rotation ),
+RotationGestureRecognizer::RotationGestureRecognizer( Observer& observer, uint32_t minimumTouchEvents, uint32_t minimumTouchEventsAfterStart )
+: GestureRecognizer( Gesture::Rotation ),
mObserver( observer ),
mState( Clear ),
mTouchEvents(),
- mStartingAngle( 0.0f )
+ mStartingAngle( 0.0f ),
+ mMinimumTouchEvents( minimumTouchEvents ),
+ mMinimumTouchEventsAfterStart( minimumTouchEventsAfterStart )
{
}
void RotationGestureRecognizer::SendEvent( const Integration::TouchEvent& event )
{
int pointCount = event.GetPointCount();
+ GestureRecognizerPtr ptr(this); // To keep us from being destroyed during the life-time of this method
switch( mState )
{
const Integration::Point& currentPoint1 = event.points[0];
const Integration::Point& currentPoint2 = event.points[1];
- if( currentPoint1.GetState() == PointState::UP || currentPoint2.GetState() == PointState::UP )
+ if( currentPoint1.GetState() == PointState::UP || currentPoint2.GetState() == PointState::UP || currentPoint1.GetState() == PointState::INTERRUPTED )
{
// One of our touch points has an Up event so change our state back to Clear.
mState = Clear;
mTouchEvents.push_back( event );
// We can only determine a rotation after a certain number of touch points have been collected.
- if( mTouchEvents.size() >= MINIMUM_TOUCH_EVENTS_REQUIRED )
+ if( mTouchEvents.size() >= mMinimumTouchEvents )
{
// Remove the first few events from the vector otherwise values are exaggerated
- mTouchEvents.erase( mTouchEvents.begin(), mTouchEvents.end() - MINIMUM_TOUCH_EVENTS_REQUIRED_AFTER_START );
+ mTouchEvents.erase( mTouchEvents.begin(), mTouchEvents.end() - mMinimumTouchEvents );
if( !mTouchEvents.empty() )
{
case Started:
{
- if( pointCount != 2 )
+ if(event.points[0].GetState() == PointState::INTERRUPTED)
+ {
+ // System interruption occurred, rotation should be cancelled
+ mTouchEvents.clear();
+ SendRotation(Gesture::Cancelled, event);
+ mState = Clear;
+ mTouchEvents.clear();
+ }
+ else if( pointCount != 2 )
{
// Send rotation finished event
SendRotation( Gesture::Finished, event );
{
mTouchEvents.push_back( event );
- if( mTouchEvents.size() >= MINIMUM_TOUCH_EVENTS_REQUIRED_AFTER_START )
+ if( mTouchEvents.size() >= mMinimumTouchEventsAfterStart )
{
// Send rotation continuing
SendRotation( Gesture::Continuing, event );
}
}
+void RotationGestureRecognizer::SetMinimumTouchEvents( uint32_t value )
+{
+ mMinimumTouchEvents = value;
+}
+
+void RotationGestureRecognizer::SetMinimumTouchEventsAfterStart( uint32_t value )
+{
+ mMinimumTouchEventsAfterStart = value;
+}
+
void RotationGestureRecognizer::SendRotation( Gesture::State state, const Integration::TouchEvent& currentEvent )
{
RotationGestureEvent gesture( state );