examples/AppFramework/AnimExample/AnimMover.cpp

00001 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
00002 // All rights reserved.
00003 // This component and the accompanying materials are made available
00004 // under the terms of "Eclipse Public License v1.0"
00005 // which accompanies this distribution, and is available
00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00007 //
00008 // Initial Contributors:
00009 // Nokia Corporation - initial contribution.
00010 //
00011 // Contributors:
00012 //
00013 // Description:
00014 //
00015 
00016 
00017 #include "animMover.h"
00018 
00019 // Sprite Animation Mover
00020 
00021 CSpriteAnimMover::CSpriteAnimMover( TInt aPriority, TInt aMicroSeconds, CSpriteAnimation* aSpriteAnim )
00022 : CActive( aPriority ), iMicroSeconds( aMicroSeconds ), iSpriteAnim( aSpriteAnim )
00023         {
00024                 
00025         CActiveScheduler::Add( this );
00026         
00027         iTimer.CreateLocal();
00028         iTimer.After( iStatus, aMicroSeconds );
00029         SetActive();
00030         }
00031         
00032                 
00033 CSpriteAnimMover::~CSpriteAnimMover()
00034         {
00035         iTimer.Close(); 
00036         }
00037 
00038         
00039 void CSpriteAnimMover::DoCancel()
00040         {
00041         iTimer.Cancel();                
00042         }
00043 
00044         
00045 void CSpriteAnimMover::RunL()
00046         {
00047         
00048         if( !iSpriteAnim )
00049                 {
00050                 User::Leave( KErrNotReady );    
00051                 }
00052 
00053         if( iX++ <= KXDeflectionTerminalValue )
00054                 {
00055                 iSpriteAnim->SetPosition( TPoint(iX, iY) );     
00056                 }
00057         else
00058                 {
00059                 
00060                 Cancel();
00061                 iSpriteAnim->SetPosition( TPoint(KAnimExSpriteInitPosX, KAnimExSpriteInitPosY ) );      
00062                 }
00063                 
00064         iTimer.After( iStatus, iMicroSeconds ); 
00065         SetActive();
00066         }
00067         
00068         
00069         
00070 // Basic Animation Mover
00071 
00072 CBasicAnimMover::CBasicAnimMover( TInt aPriority, TInt aMicroSeconds, CBasicAnimation* aBasicAnim )
00073 : CActive( aPriority ), iMicroSeconds( aMicroSeconds ), iBasicAnim( aBasicAnim ), iX( 0 ), iY( 0 )
00074         {
00075                 
00076         CActiveScheduler::Add( this );
00077         
00078         iTimer.CreateLocal();
00079         iTimer.After( iStatus, aMicroSeconds );
00080         SetActive();
00081         }
00082         
00083         CBasicAnimMover::~CBasicAnimMover()
00084         {
00085         
00086         iTimer.Close(); 
00087         }
00088 
00089 void CBasicAnimMover::DoCancel()
00090         {
00091         
00092         iTimer.Cancel();                
00093         }
00094 
00095 void CBasicAnimMover::RunL()
00096         {
00097         
00098         if( !iBasicAnim )
00099                 {
00100                 User::Leave( KErrNotReady );    
00101                 }
00102         
00103         
00104         if( iX < KXDeflectionTerminalValue )
00105                 {
00106                 iY =TInt(KYDeflectionOffset + KYDeflectionMultiplier*sin( iX++ ));      
00107                 iBasicAnim->SetPosition( TPoint(iX, iY) );
00108                 
00109                 iX += KXDeflectionIncrement;    
00110                 }
00111         else
00112                 {
00113                 
00114                 Cancel();
00115                 iBasicAnim->SetPosition( TPoint(KAnimExBasicInitPosX, KAnimExBasicInitPosY) );                  
00116                 }
00117                 
00118                 
00119         iTimer.After( iStatus, iMicroSeconds ); 
00120         SetActive();
00121         }

Generated by  doxygen 1.6.2