examples/AppFramework/AnimExample/Anim_AppView.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 #include "AnimExample.h"
00017 
00018 CAnimationAppView::CAnimationAppView()
00019         {
00020         }
00021 
00022 CAnimationAppView* CAnimationAppView::NewL(const TRect& aRect)
00023         {
00024         CAnimationAppView* self = new(ELeave) CAnimationAppView();
00025         CleanupStack::PushL(self);
00026         self->ConstructL(aRect);
00027         CleanupStack::Pop();
00028         return self;
00029         }
00030 
00031 CAnimationAppView::~CAnimationAppView()
00032         {
00033         delete iAnimTestText;
00034         delete iSpriteAnim;
00035         delete iBasicAnim;
00036         
00037         if( iSpriteAnimMover )
00038                 {
00039                 iSpriteAnimMover->Cancel();     
00040                 delete iSpriteAnimMover;
00041                 }
00042                         
00043         if( iBasicAnimMover )
00044                 {
00045                 iBasicAnimMover->Cancel();      
00046                 delete iBasicAnimMover;
00047                 }               
00048         }
00049 
00050 // Standard initialisation for a window-owning control.
00051 void CAnimationAppView::ConstructL( const TRect& aRect )
00052     {
00053     
00054         // Fetch the text from the resource file.
00055         iAnimTestText = iEikonEnv->AllocReadResourceL( R_EXAMPLE_TEXT_BASICANIM );
00056         
00057         // The control is window-owning.
00058         CreateWindowL();
00059    
00060         // Extent of the control.
00061         SetRect(aRect);
00062    
00063         // The control is ready to draw, so notify the UI framework.
00064         ActivateL();
00065         }
00066 
00067 
00068 void CAnimationAppView::ProduceSpriteAnimL()
00069         {
00070         
00071         // Simple sprite animation
00072         CICLAnimationDataProvider* spriteDataProvider = new (ELeave)CICLAnimationDataProvider;
00073         CleanupStack::PushL( spriteDataProvider );
00074         spriteDataProvider->SetFileL( iEikonEnv->FsSession(), KAnimExStopWatch() );
00075         CleanupStack::Pop( spriteDataProvider );
00076         
00077         iSpriteAnim = CSpriteAnimation::NewL( spriteDataProvider,TPoint(KAnimExSpritePositionX, KAnimExSpritePositionY), iEikonEnv->WsSession(), Window() );
00078         
00079         TAnimationConfig config;
00080         config.iFlags = TAnimationConfig::ELoop;
00081         config.iData = -1;
00082         
00083         iSpriteAnim->Start( config );
00084         }
00085 
00086 void CAnimationAppView::ProduceBasicAnimL()
00087         {
00088 
00089         TAnimationConfig config;
00090         config.iFlags = TAnimationConfig::ELoop;
00091         config.iData = -1;
00092 
00093         // The basic animation. Drawn in ::Draw()
00094         CICLAnimationDataProvider* basicDataProvider = new (ELeave)CICLAnimationDataProvider;
00095         CleanupStack::PushL( basicDataProvider );
00096         basicDataProvider->SetFileL( iEikonEnv->FsSession(), KAnimExStopWatch() );
00097 
00098         CleanupStack::Pop( basicDataProvider );
00099         
00100         iBasicAnim = CBasicAnimation::NewL( basicDataProvider,TPoint( KAnimExBasicPositionX, KAnimExBasicPositionY ), iEikonEnv->WsSession(), Window() );
00101                 
00102         iBasicAnim->Start( config );    
00103         }
00104 
00105 void CAnimationAppView::MoveAnimsL()
00106         {
00107         
00108         if( iSpriteAnimMover )
00109                 {
00110                 iSpriteAnimMover->Cancel();     
00111                 delete iSpriteAnimMover;
00112                 iSpriteAnimMover = NULL;        
00113                 }
00114                         
00115         iSpriteAnimMover = new (ELeave) CSpriteAnimMover( EPriorityNormal, KspriteInterval, iSpriteAnim );
00116         
00117 
00118         if( iBasicAnimMover )
00119                 {
00120                 iBasicAnimMover->Cancel();      
00121                 delete iBasicAnimMover;
00122                 iBasicAnimMover = NULL; 
00123                 }
00124                         
00125         iBasicAnimMover = new (ELeave) CBasicAnimMover( EPriorityNormal, KBasicInterval, iBasicAnim );
00126 
00127         }
00128 
00129 void CAnimationAppView::DoSpriteAnimOperationL( TAnimOperation aOperation )
00130         {
00131         
00132         if( !iSpriteAnim )
00133                 {       
00134                 iEikonEnv->InfoMsg( _L("Not Initialised") );
00135                 return;
00136                 }
00137                 
00138                 switch( aOperation )
00139                 {
00140                 
00141                 case EAnimPause:
00142                         iSpriteAnim->Pause();
00143                         break;
00144                 
00145                 case EAnimResume:
00146                         iSpriteAnim->Resume();
00147                         break;
00148         
00149                 case EAnimStop: 
00150                         iSpriteAnim->Stop();
00151                         break;
00152                 
00153                 default:
00154                         break;
00155                         
00156                 }
00157                 
00158         }
00159         
00160         
00161 void CAnimationAppView::DoBasicAnimOperationL( TAnimOperation aOperation )
00162         {
00163         
00164         if( !iBasicAnim )
00165                 {       
00166                 iEikonEnv->InfoMsg( _L("Not Initialised") );
00167                 return;
00168                 }
00169                 
00170                 switch( aOperation )
00171                 {
00172                 case EAnimPause:
00173                         iBasicAnim->Pause();
00174                         break;
00175                 
00176                 case EAnimResume:
00177                         iBasicAnim->Resume();
00178                         break;
00179                 
00180                 case EAnimStop: 
00181                         iBasicAnim->Stop();
00182                         break;
00183                 
00184                 default:
00185                         break;  
00186                 }
00187                 
00188         }
00189 
00190 
00191  // Delete the current anims and movers, if instantiated. 
00192  // Redraw the window after deleting a CBasicAnimation and call Invalidate()
00193            
00194 void CAnimationAppView::ResetSpriteAnimAndMover()
00195         {
00196         
00197         if( iSpriteAnimMover )
00198                 {
00199                 iSpriteAnimMover->Cancel();     
00200                 delete iSpriteAnimMover;
00201                 iSpriteAnimMover = NULL;        
00202                 }
00203                         
00204         if( iSpriteAnim )
00205                 {
00206                 iSpriteAnim->Stop();
00207                 delete iSpriteAnim;     
00208                 iSpriteAnim = NULL;
00209                 }
00210         }
00211         
00212 void CAnimationAppView::ResetBasicAnimAndMover()
00213         {
00214         if( iBasicAnimMover )
00215                 {
00216                 iBasicAnimMover->Cancel();      
00217                 delete iBasicAnimMover;
00218                 iBasicAnimMover = NULL; 
00219                 }
00220                                         
00221         if( iBasicAnim )
00222                 {
00223                 iBasicAnim->Stop();
00224                 delete iBasicAnim;      
00225                 iBasicAnim = NULL;
00226                 
00227                 Window().Invalidate();
00228                 }
00229                 
00230         }
00231         
00232     
00233 // Draw the view
00234 void CAnimationAppView::Draw(const TRect& /*aRect*/) const
00235         {
00236         
00237         // Window graphics context
00238         CWindowGc& gc = SystemGc();
00239         
00240         // Area in which we shall draw
00241         TRect drawRect = Rect();
00242         
00243         // Font used for drawing text
00244         const CFont*  fontUsed;
00245         
00246         // Clear the screen
00247         gc.Clear();
00248         
00249         // Use the title font supplied by the UI
00250         fontUsed = iEikonEnv->TitleFont();
00251         gc.UseFont( fontUsed );
00252 
00253         // Draw the text in the rectangle       
00254         TInt   baselineOffset=( drawRect.Height() - fontUsed->HeightInPixels() ); 
00255         gc.DrawText( *iAnimTestText,drawRect,0 + fontUsed->HeightInPixels(),CGraphicsContext::ECenter, 0 );
00256         
00257         gc.DrawText(  KAnimExBasicLabel, drawRect, baselineOffset - KBasicOffset, CGraphicsContext::ECenter, 0 );
00258         
00259 
00260         // CBasicAnimations need to be drawn by us.
00261         if( iBasicAnim )
00262                 {
00263                 iBasicAnim->Draw( gc ); 
00264                 }
00265 
00266         gc.DrawText( KAnimExSpriteLabel, drawRect, baselineOffset - KSpriteOffset, CGraphicsContext::ELeft, 0 );        
00267         
00268         // Discard the font.
00269         gc.DiscardFont();
00270         }
00271         
00272 
00273 
00274 

Generated by  doxygen 1.6.2