akntouchgesturefw/src/akntouchgesturefwdragtracer.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #include "akntouchgesturefwdragtracer.h"
       
    19 
       
    20 using namespace AknTouchGestureFw;
       
    21 
       
    22 
       
    23 // ---------------------------------------------------------------------------
       
    24 // Two-phased constructor.
       
    25 // ---------------------------------------------------------------------------
       
    26 //
       
    27 CAknTouchGestureFwDragTracer* CAknTouchGestureFwDragTracer::NewL()
       
    28     {
       
    29     CAknTouchGestureFwDragTracer* self =
       
    30         CAknTouchGestureFwDragTracer::NewLC();
       
    31     CleanupStack::Pop( self );
       
    32     return self;
       
    33     }
       
    34 
       
    35 
       
    36 // ---------------------------------------------------------------------------
       
    37 // Two-phased constructor.
       
    38 // ---------------------------------------------------------------------------
       
    39 //
       
    40 CAknTouchGestureFwDragTracer* CAknTouchGestureFwDragTracer::NewLC()
       
    41     {
       
    42     CAknTouchGestureFwDragTracer* self
       
    43         = new ( ELeave ) CAknTouchGestureFwDragTracer();
       
    44     CleanupStack::PushL( self );
       
    45     return self;
       
    46     }
       
    47 
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // Destructor
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 CAknTouchGestureFwDragTracer::~CAknTouchGestureFwDragTracer()
       
    54     {
       
    55     }
       
    56 
       
    57 
       
    58 // ---------------------------------------------------------------------------
       
    59 // Initializes the drag tracer state.
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 void CAknTouchGestureFwDragTracer::Initialize( const TPoint& aStartPosition )
       
    63     {
       
    64     iHorizDirection = EDirectionNone;
       
    65     iVertDirection = EDirectionNone;
       
    66 
       
    67     iHorizCounter = 0;
       
    68     iVertCounter = 0;
       
    69     iPosition = aStartPosition;
       
    70     }
       
    71 
       
    72 
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 // Checks if the drag direction has been changed.
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 TBool CAknTouchGestureFwDragTracer::IsDirectionChanged(
       
    79     const TPoint& aPosition,
       
    80     TInt aSensitivity )
       
    81     {
       
    82     if ( aPosition == iPosition )
       
    83         {
       
    84         // Can't calculate direction.
       
    85         return EFalse;
       
    86         }
       
    87 
       
    88     TBool directionChanged( EFalse );
       
    89 
       
    90     // Horizontal direction
       
    91 
       
    92     if ( iHorizDirection == EDirectionNone )
       
    93         {
       
    94         // Calculate first horizontal direction based on current and
       
    95         // previous point.
       
    96         if ( aPosition.iX > iPosition.iX )
       
    97             {
       
    98             iHorizDirection = EDirectionForward;
       
    99             }
       
   100         else if ( aPosition.iX < iPosition.iX )
       
   101             {
       
   102             iHorizDirection = EDirectionBackward;
       
   103             }
       
   104         }
       
   105     else
       
   106         {
       
   107         // Horizontal direction changes only if certain amount of new points
       
   108         // is to reversed direction.
       
   109 
       
   110         // Note: direction counter is updated with the following calls.
       
   111         if ( IsDirectionChanged(
       
   112                 aPosition.iX,
       
   113                 iPosition.iX,
       
   114                 iHorizDirection,
       
   115                 iHorizCounter,
       
   116                 aSensitivity ) )
       
   117             {
       
   118             directionChanged = ETrue;
       
   119             }
       
   120         }
       
   121 
       
   122     // Vertical direction
       
   123 
       
   124     if ( iVertDirection == EDirectionNone )
       
   125         {
       
   126         // Calculate first vertical direction based on current and
       
   127         // previous point.
       
   128         if ( aPosition.iY > iPosition.iY )
       
   129             {
       
   130             iVertDirection = EDirectionForward;
       
   131             }
       
   132         else if ( aPosition.iY < iPosition.iY )
       
   133             {
       
   134             iVertDirection = EDirectionBackward;
       
   135             }
       
   136         }
       
   137     else
       
   138         {
       
   139         // Vertical direction changes only if certain amount of new points
       
   140         // is to reversed direction.
       
   141 
       
   142         // Note: direction counter is updated with the following call.
       
   143         if ( IsDirectionChanged(
       
   144                 aPosition.iY,
       
   145                 iPosition.iY,
       
   146                 iVertDirection,
       
   147                 iVertCounter,
       
   148                 aSensitivity ) )
       
   149             {
       
   150             directionChanged = ETrue;
       
   151             }
       
   152         }
       
   153 
       
   154     iPosition = aPosition;
       
   155     return directionChanged;
       
   156     }
       
   157 
       
   158 
       
   159 // ---------------------------------------------------------------------------
       
   160 // Checks if the drag direction has been changed.
       
   161 // ---------------------------------------------------------------------------
       
   162 //
       
   163 TBool CAknTouchGestureFwDragTracer::IsDirectionChanged(
       
   164     TInt aCurrentCoordinate,
       
   165     TInt aPrevCoordinate,
       
   166     TDirection& aDirection,
       
   167     TInt& aCounter,
       
   168     TInt aSensitivity )
       
   169     {
       
   170     TBool directionChanged( EFalse );
       
   171 
       
   172     if ( aDirection == EDirectionForward )
       
   173         {
       
   174         if ( aCurrentCoordinate < aPrevCoordinate )
       
   175             {
       
   176             aCounter++;
       
   177             }
       
   178         else
       
   179             {
       
   180             aCounter = 0;
       
   181             }
       
   182 
       
   183         if ( aCounter == aSensitivity )
       
   184             {
       
   185             directionChanged = ETrue;
       
   186             aDirection = EDirectionBackward;
       
   187             aCounter = 0;
       
   188             }
       
   189         }
       
   190     else if ( aDirection == EDirectionBackward )
       
   191         {
       
   192         if ( aCurrentCoordinate > aPrevCoordinate )
       
   193             {
       
   194             aCounter++;
       
   195             }
       
   196         else
       
   197             {
       
   198             aCounter = 0;
       
   199             }
       
   200 
       
   201         if ( aCounter == aSensitivity )
       
   202             {
       
   203             directionChanged = ETrue;
       
   204             aDirection = EDirectionForward;
       
   205             aCounter = 0;
       
   206             }
       
   207         }
       
   208     return directionChanged;
       
   209     }
       
   210 
       
   211 
       
   212 // ---------------------------------------------------------------------------
       
   213 // Default C++ constructor.
       
   214 // ---------------------------------------------------------------------------
       
   215 //
       
   216 CAknTouchGestureFwDragTracer::CAknTouchGestureFwDragTracer():
       
   217     iHorizDirection( EDirectionNone ),
       
   218     iVertDirection( EDirectionNone ),
       
   219     iHorizCounter( 0 ),
       
   220     iVertCounter( 0 ),
       
   221     iPosition( 0, 0 )
       
   222     {
       
   223     }
       
   224 
       
   225 // End of File