examples/AppFramework/AnimExample/Anim_AppView.cpp

00001 /*
00002 Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003 
00004 Redistribution and use in source and binary forms, with or without
00005 modification, are permitted provided that the following conditions are met:
00006 
00007 * Redistributions of source code must retain the above copyright notice, this
00008   list of conditions and the following disclaimer.
00009 * Redistributions in binary form must reproduce the above copyright notice,
00010   this list of conditions and the following disclaimer in the documentation
00011   and/or other materials provided with the distribution.
00012 * Neither the name of Nokia Corporation nor the names of its contributors
00013   may be used to endorse or promote products derived from this software
00014   without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 
00027 Description:  
00028 */
00029 
00030 #include "AnimExample.h"
00031 
00032 CAnimationAppView::CAnimationAppView()
00033         {
00034         }
00035 
00036 CAnimationAppView* CAnimationAppView::NewL(const TRect& aRect)
00037         {
00038         CAnimationAppView* self = new(ELeave) CAnimationAppView();
00039         CleanupStack::PushL(self);
00040         self->ConstructL(aRect);
00041         CleanupStack::Pop();
00042         return self;
00043         }
00044 
00045 CAnimationAppView::~CAnimationAppView()
00046         {
00047         delete iAnimTestText;
00048         delete iSpriteAnim;
00049         delete iBasicAnim;
00050         
00051         if( iSpriteAnimMover )
00052                 {
00053                 iSpriteAnimMover->Cancel();     
00054                 delete iSpriteAnimMover;
00055                 }
00056                         
00057         if( iBasicAnimMover )
00058                 {
00059                 iBasicAnimMover->Cancel();      
00060                 delete iBasicAnimMover;
00061                 }               
00062         }
00063 
00064 // Standard initialisation for a window-owning control.
00065 void CAnimationAppView::ConstructL( const TRect& aRect )
00066     {
00067     
00068         // Fetch the text from the resource file.
00069         iAnimTestText = iEikonEnv->AllocReadResourceL( R_EXAMPLE_TEXT_BASICANIM );
00070         
00071         // The control is window-owning.
00072         CreateWindowL();
00073    
00074         // Extent of the control.
00075         SetRect(aRect);
00076    
00077         // The control is ready to draw, so notify the UI framework.
00078         ActivateL();
00079         }
00080 
00081 
00082 void CAnimationAppView::ProduceSpriteAnimL()
00083         {
00084         
00085         // Simple sprite animation
00086         CICLAnimationDataProvider* spriteDataProvider = new (ELeave)CICLAnimationDataProvider;
00087         CleanupStack::PushL( spriteDataProvider );
00088         spriteDataProvider->SetFileL( iEikonEnv->FsSession(), KAnimExStopWatch() );
00089         CleanupStack::Pop( spriteDataProvider );
00090         
00091         iSpriteAnim = CSpriteAnimation::NewL( spriteDataProvider,TPoint(KAnimExSpritePositionX, KAnimExSpritePositionY), iEikonEnv->WsSession(), Window() );
00092         
00093         TAnimationConfig config;
00094         config.iFlags = TAnimationConfig::ELoop;
00095         config.iData = -1;
00096         
00097         iSpriteAnim->Start( config );
00098         }
00099 
00100 void CAnimationAppView::ProduceBasicAnimL()
00101         {
00102 
00103         TAnimationConfig config;
00104         config.iFlags = TAnimationConfig::ELoop;
00105         config.iData = -1;
00106 
00107         // The basic animation. Drawn in ::Draw()
00108         CICLAnimationDataProvider* basicDataProvider = new (ELeave)CICLAnimationDataProvider;
00109         CleanupStack::PushL( basicDataProvider );
00110         basicDataProvider->SetFileL( iEikonEnv->FsSession(), KAnimExStopWatch() );
00111 
00112         CleanupStack::Pop( basicDataProvider );
00113         
00114         iBasicAnim = CBasicAnimation::NewL( basicDataProvider,TPoint( KAnimExBasicPositionX, KAnimExBasicPositionY ), iEikonEnv->WsSession(), Window() );
00115                 
00116         iBasicAnim->Start( config );    
00117         }
00118 
00119 void CAnimationAppView::MoveAnimsL()
00120         {
00121         
00122         if( iSpriteAnimMover )
00123                 {
00124                 iSpriteAnimMover->Cancel();     
00125                 delete iSpriteAnimMover;
00126                 iSpriteAnimMover = NULL;        
00127                 }
00128                         
00129         iSpriteAnimMover = new (ELeave) CSpriteAnimMover( EPriorityNormal, KspriteInterval, iSpriteAnim );
00130         
00131 
00132         if( iBasicAnimMover )
00133                 {
00134                 iBasicAnimMover->Cancel();      
00135                 delete iBasicAnimMover;
00136                 iBasicAnimMover = NULL; 
00137                 }
00138                         
00139         iBasicAnimMover = new (ELeave) CBasicAnimMover( EPriorityNormal, KBasicInterval, iBasicAnim );
00140 
00141         }
00142 
00143 void CAnimationAppView::DoSpriteAnimOperationL( TAnimOperation aOperation )
00144         {
00145         
00146         if( !iSpriteAnim )
00147                 {       
00148                 iEikonEnv->InfoMsg( _L("Not Initialised") );
00149                 return;
00150                 }
00151                 
00152                 switch( aOperation )
00153                 {
00154                 
00155                 case EAnimPause:
00156                         iSpriteAnim->Pause();
00157                         break;
00158                 
00159                 case EAnimResume:
00160                         iSpriteAnim->Resume();
00161                         break;
00162         
00163                 case EAnimStop: 
00164                         iSpriteAnim->Stop();
00165                         break;
00166                 
00167                 default:
00168                         break;
00169                         
00170                 }
00171                 
00172         }
00173         
00174         
00175 void CAnimationAppView::DoBasicAnimOperationL( TAnimOperation aOperation )
00176         {
00177         
00178         if( !iBasicAnim )
00179                 {       
00180                 iEikonEnv->InfoMsg( _L("Not Initialised") );
00181                 return;
00182                 }
00183                 
00184                 switch( aOperation )
00185                 {
00186                 case EAnimPause:
00187                         iBasicAnim->Pause();
00188                         break;
00189                 
00190                 case EAnimResume:
00191                         iBasicAnim->Resume();
00192                         break;
00193                 
00194                 case EAnimStop: 
00195                         iBasicAnim->Stop();
00196                         break;
00197                 
00198                 default:
00199                         break;  
00200                 }
00201                 
00202         }
00203 
00204 
00205  // Delete the current anims and movers, if instantiated. 
00206  // Redraw the window after deleting a CBasicAnimation and call Invalidate()
00207            
00208 void CAnimationAppView::ResetSpriteAnimAndMover()
00209         {
00210         
00211         if( iSpriteAnimMover )
00212                 {
00213                 iSpriteAnimMover->Cancel();     
00214                 delete iSpriteAnimMover;
00215                 iSpriteAnimMover = NULL;        
00216                 }
00217                         
00218         if( iSpriteAnim )
00219                 {
00220                 iSpriteAnim->Stop();
00221                 delete iSpriteAnim;     
00222                 iSpriteAnim = NULL;
00223                 }
00224         }
00225         
00226 void CAnimationAppView::ResetBasicAnimAndMover()
00227         {
00228         if( iBasicAnimMover )
00229                 {
00230                 iBasicAnimMover->Cancel();      
00231                 delete iBasicAnimMover;
00232                 iBasicAnimMover = NULL; 
00233                 }
00234                                         
00235         if( iBasicAnim )
00236                 {
00237                 iBasicAnim->Stop();
00238                 delete iBasicAnim;      
00239                 iBasicAnim = NULL;
00240                 
00241                 Window().Invalidate();
00242                 }
00243                 
00244         }
00245         
00246     
00247 // Draw the view
00248 void CAnimationAppView::Draw(const TRect& /*aRect*/) const
00249         {
00250         
00251         // Window graphics context
00252         CWindowGc& gc = SystemGc();
00253         
00254         // Area in which we shall draw
00255         TRect drawRect = Rect();
00256         
00257         // Font used for drawing text
00258         const CFont*  fontUsed;
00259         
00260         // Clear the screen
00261         gc.Clear();
00262         
00263         // Use the title font supplied by the UI
00264         fontUsed = iEikonEnv->TitleFont();
00265         gc.UseFont( fontUsed );
00266 
00267         // Draw the text in the rectangle       
00268         TInt   baselineOffset=( drawRect.Height() - fontUsed->HeightInPixels() ); 
00269         gc.DrawText( *iAnimTestText,drawRect,0 + fontUsed->HeightInPixels(),CGraphicsContext::ECenter, 0 );
00270         
00271         gc.DrawText(  KAnimExBasicLabel, drawRect, baselineOffset - KBasicOffset, CGraphicsContext::ECenter, 0 );
00272         
00273 
00274         // CBasicAnimations need to be drawn by us.
00275         if( iBasicAnim )
00276                 {
00277                 iBasicAnim->Draw( gc ); 
00278                 }
00279 
00280         gc.DrawText( KAnimExSpriteLabel, drawRect, baselineOffset - KSpriteOffset, CGraphicsContext::ELeft, 0 );        
00281         
00282         // Discard the font.
00283         gc.DiscardFont();
00284         }
00285         
00286 
00287 
00288 

Generated by  doxygen 1.6.2