mulwidgets/gesturehelper/src/utils.cpp
branchRCL_3
changeset 26 0e9bb658ef58
parent 0 e83bab7cf002
equal deleted inserted replaced
25:4ea6f81c838a 26:0e9bb658ef58
       
     1 /*
       
     2 * Copyright (c) 2008 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:  Gesture recognition utilities
       
    15 *
       
    16 */
       
    17 
       
    18 #include "utils.h"
       
    19 
       
    20 #include <coemain.h> // for CCoeEnv
       
    21 #include <eikappui.h>  // for CEikAppUi
       
    22 
       
    23 #include "gesturedefs.h"
       
    24 
       
    25 namespace GestureHelper
       
    26     {
       
    27     /** @return the longer edge of the size */
       
    28     inline TInt LongerEdge( const TSize& aSize ) 
       
    29         {
       
    30         return Max( aSize.iHeight, aSize.iWidth );
       
    31         }
       
    32     
       
    33     // for documentation, see header file
       
    34     TRect ToleranceRect( const TPoint& aCenterPoint ) 
       
    35         {
       
    36         TSize screenSize = static_cast<CEikAppUi*>( CCoeEnv::Static()->AppUi() )
       
    37             ->ApplicationRect().Size(); 
       
    38         // multiplication has to be done first, to avoid rounding integer to 0 with division
       
    39         int toleranceLength = ( KGestureTolerancePercent * LongerEdge( screenSize ) ) / 100; 
       
    40         TRect toleranceRect( aCenterPoint, TSize() );
       
    41         // grow by the tolerance length, while keeping the center point
       
    42         toleranceRect.Shrink( -toleranceLength, -toleranceLength );
       
    43         return toleranceRect;
       
    44         }
       
    45  
       
    46      // for documentation, see header file
       
    47     TRect ToleranceRect( const TPoint& aCenterPoint, MGestureEvent::TAxis aRelevantAxis ) 
       
    48         {
       
    49         TRect toleranceRect = ToleranceRect(aCenterPoint);
       
    50 
       
    51 		TSize screenSize = static_cast<CEikAppUi*>( CCoeEnv::Static()->AppUi() )
       
    52             ->ApplicationRect().Size();
       
    53             
       
    54 		if(aRelevantAxis == MGestureEvent::EAxisHorizontal)
       
    55 			{
       
    56 			toleranceRect.iTl.iY = 0;
       
    57         	toleranceRect.iBr.iY = screenSize.iHeight;	
       
    58 			}
       
    59 		else if(aRelevantAxis == MGestureEvent::EAxisVertical)
       
    60 			{
       
    61 			toleranceRect.iTl.iX = 0;
       
    62         	toleranceRect.iBr.iX = screenSize.iWidth;	
       
    63 			}
       
    64 		else // EAxisBoth
       
    65 			{
       
    66 			// nothing to be done	
       
    67 			}                   
       
    68 
       
    69         return toleranceRect;
       
    70         }
       
    71            
       
    72     } // namespace GestureHelper