idlehomescreen/xmluirendering/uiengine/src/xngesturerecogniser.cpp
branchRCL_3
changeset 16 9674c1a575e9
parent 0 f72a12da539e
child 30 b8fae6b8a148
equal deleted inserted replaced
15:ff572dfe6d86 16:9674c1a575e9
    20 #include "xngesturerecogniser.h"
    20 #include "xngesturerecogniser.h"
    21 #include "xngesturedefs.h"
    21 #include "xngesturedefs.h"
    22 #include "xnpointarray.h"
    22 #include "xnpointarray.h"
    23 
    23 
    24 using namespace XnGestureHelper;
    24 using namespace XnGestureHelper;
       
    25 
       
    26 const TInt minPointCount = 5;
    25 
    27 
    26 /**
    28 /**
    27  * Vector class (math)
    29  * Vector class (math)
    28  */
    30  */
    29 NONSHARABLE_CLASS( TVector )
    31 NONSHARABLE_CLASS( TVector )
   178         }
   180         }
   179     return aPoints[0];
   181     return aPoints[0];
   180     }
   182     }
   181 
   183 
   182 /** @return direction between last two points */
   184 /** @return direction between last two points */
   183 inline TXnGestureCode LastDirection( const TXnPointArray& aPoints )
   185 TXnGestureCode TXnGestureRecogniser::LastDirection( const TXnPointArray& aPoints ) const
   184     {
   186     {
   185     if ( aPoints.Count() > 1 )
   187     if ( aPoints.Count() > minPointCount )
   186         {
   188         {
   187         // return direction between latest and previous points.
   189         // return direction between latest and previous points.
   188         // pick the previous point that is different than the last point
   190         // pick the previous point that is different than the last point
   189         // because while using an x or y filter array, more than one
   191         // because while using an x or y filter array, more than one
   190         // sequential points may look like the same point because
   192         // sequential points may look like the same point because
   191         // the differing coordinate coordinate is filtered out. For example,
   193         // the differing coordinate coordinate is filtered out. For example,
   192         // if dragging left and slightly up, many y coordinates will have the
   194         // if dragging left and slightly up, many y coordinates will have the
   193         // same value, while only x differs.
   195         // same value, while only x differs.
   194         return Direction( PreviousPoint( aPoints ), aPoints[aPoints.Count() - 1] );
   196         return Direction( aPoints[ aPoints.Count() - minPointCount ],
   195         }
   197                           aPoints[ aPoints.Count() - 1 ] );
   196     return EGestureUnknown;
   198         }
       
   199     return GeneralDirection( aPoints );
   197     }
   200     }
   198 
   201 
   199 // ----------------------------------------------------------------------------
   202 // ----------------------------------------------------------------------------
   200 // Return gesture code of a gesture formed by a sequence of points
   203 // Return gesture code of a gesture formed by a sequence of points
   201 // ----------------------------------------------------------------------------
   204 // ----------------------------------------------------------------------------
   203 TXnGestureCode TXnGestureRecogniser::GestureCode( const TXnPointArray& aPoints ) const
   206 TXnGestureCode TXnGestureRecogniser::GestureCode( const TXnPointArray& aPoints ) const
   204     {
   207     {
   205     __ASSERT_DEBUG( aPoints.Count() > 0, Panic( EGesturePanicIllegalLogic ) );
   208     __ASSERT_DEBUG( aPoints.Count() > 0, Panic( EGesturePanicIllegalLogic ) );
   206 
   209 
   207     if (aPoints.Count() <= 0)
   210     if (aPoints.Count() <= 0)
       
   211         {
   208         return EGestureUnknown;
   212         return EGestureUnknown;
   209         
       
   210     if ( IsTap( aPoints ) )
       
   211         {
       
   212         return EGestureTap;
       
   213         }
   213         }
   214 
   214 
   215     if ( GestureLength( aPoints ) >= KMinSwipeLength )
   215     if ( GestureLength( aPoints ) >= KMinSwipeLength )
   216         {
   216         {
   217         TXnGestureCode direction = GeneralDirection( aPoints );
   217         return GeneralDirection( aPoints );
   218         if ( direction != LastDirection( aPoints ) )
       
   219             {
       
   220             direction = EGestureUnknown;
       
   221             }
       
   222         return direction;
       
   223         }
   218         }
   224 
   219 
   225     // the pointer was moved but was either not moved far enough, or was
   220     // the pointer was moved but was either not moved far enough, or was
   226     // brought back to close to the starting point
   221     // brought back to close to the starting point
   227     return EGestureUnknown;
   222     return EGestureUnknown;