os/graphics/graphicstest/uibench/s60/src/te_gesturegenerator.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 /**
    17  @file
    18  @test
    19  @internalComponent - Internal Symbian test code 
    20 */
    21 
    22 
    23 #include "te_gesturegenerator.h"
    24 
    25 #include <e32cmn.h>
    26 #include <e32math.h>
    27 
    28 
    29 void GestureGenerator::SimulateFlickGestureL(RSemaphore& aSemaphore, TPoint aStartPoint, TPoint aEndPoint)
    30 	{
    31 	GenerateEventL(aSemaphore, TRawEvent::EButton1Down, aStartPoint.iX, aStartPoint.iY);
    32 	TPoint currentPosition(aStartPoint);
    33 	TReal currentX = 0;
    34 	TReal currentY = 0;
    35 	TReal distance = 0;
    36 	Math::Sqrt(distance, (aEndPoint.iX - aStartPoint.iX)*(aEndPoint.iX - aStartPoint.iX) + (aEndPoint.iY - aStartPoint.iY)*(aEndPoint.iY - aStartPoint.iY));	
    37 	
    38 	TReal deltaX = (aEndPoint.iX - aStartPoint.iX) / distance;
    39 	TReal deltaY = (aEndPoint.iY - aStartPoint.iY) / distance;	
    40 	while (currentPosition != aEndPoint)
    41 	    {
    42 	    currentX += deltaX;
    43 	    currentY += deltaY;
    44 	    currentPosition.SetXY(aStartPoint.iX + currentX, aStartPoint.iY + currentY);
    45 	    GenerateEventL(aSemaphore, TRawEvent::EPointerMove, currentPosition.iX, currentPosition.iY);
    46 	    }	
    47 	GenerateEventL(aSemaphore, TRawEvent::EButton1Up, aStartPoint.iX, aStartPoint.iY);
    48 	}
    49 
    50 /**
    51  * Generates events to communicate with the control. Each time the control receives an event
    52  * it redraws itself. That's necessary because the draw method can't be called directly from
    53  * a different thread.
    54  */
    55 void GestureGenerator::GenerateEventL(RSemaphore& aSemaphore, TRawEvent::TType aEventType, TInt aX, TInt aY)
    56     {
    57     TRawEvent rawEvent;
    58     rawEvent.Set(aEventType, aX, aY);
    59     User::LeaveIfError(UserSvr::AddEvent(rawEvent));
    60     aSemaphore.Wait();
    61     }
    62