os/graphics/graphicstest/uibench/s60/src/te_gesturegenerator.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicstest/uibench/s60/src/te_gesturegenerator.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,62 @@
     1.4 +// Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +/**
    1.20 + @file
    1.21 + @test
    1.22 + @internalComponent - Internal Symbian test code 
    1.23 +*/
    1.24 +
    1.25 +
    1.26 +#include "te_gesturegenerator.h"
    1.27 +
    1.28 +#include <e32cmn.h>
    1.29 +#include <e32math.h>
    1.30 +
    1.31 +
    1.32 +void GestureGenerator::SimulateFlickGestureL(RSemaphore& aSemaphore, TPoint aStartPoint, TPoint aEndPoint)
    1.33 +	{
    1.34 +	GenerateEventL(aSemaphore, TRawEvent::EButton1Down, aStartPoint.iX, aStartPoint.iY);
    1.35 +	TPoint currentPosition(aStartPoint);
    1.36 +	TReal currentX = 0;
    1.37 +	TReal currentY = 0;
    1.38 +	TReal distance = 0;
    1.39 +	Math::Sqrt(distance, (aEndPoint.iX - aStartPoint.iX)*(aEndPoint.iX - aStartPoint.iX) + (aEndPoint.iY - aStartPoint.iY)*(aEndPoint.iY - aStartPoint.iY));	
    1.40 +	
    1.41 +	TReal deltaX = (aEndPoint.iX - aStartPoint.iX) / distance;
    1.42 +	TReal deltaY = (aEndPoint.iY - aStartPoint.iY) / distance;	
    1.43 +	while (currentPosition != aEndPoint)
    1.44 +	    {
    1.45 +	    currentX += deltaX;
    1.46 +	    currentY += deltaY;
    1.47 +	    currentPosition.SetXY(aStartPoint.iX + currentX, aStartPoint.iY + currentY);
    1.48 +	    GenerateEventL(aSemaphore, TRawEvent::EPointerMove, currentPosition.iX, currentPosition.iY);
    1.49 +	    }	
    1.50 +	GenerateEventL(aSemaphore, TRawEvent::EButton1Up, aStartPoint.iX, aStartPoint.iY);
    1.51 +	}
    1.52 +
    1.53 +/**
    1.54 + * Generates events to communicate with the control. Each time the control receives an event
    1.55 + * it redraws itself. That's necessary because the draw method can't be called directly from
    1.56 + * a different thread.
    1.57 + */
    1.58 +void GestureGenerator::GenerateEventL(RSemaphore& aSemaphore, TRawEvent::TType aEventType, TInt aX, TInt aY)
    1.59 +    {
    1.60 +    TRawEvent rawEvent;
    1.61 +    rawEvent.Set(aEventType, aX, aY);
    1.62 +    User::LeaveIfError(UserSvr::AddEvent(rawEvent));
    1.63 +    aSemaphore.Wait();
    1.64 +    }
    1.65 +