examples/AppFramework/BmpAnim/BmpAnimGui_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 // BmpAnimGuiAppView.cpp
00015 //
00016 
00017 #include "BmpAnimGui.h"
00018 
00019         
00020 // Animate the balls such that they move across the screen in a sinusoidal pattern
00021 void CExampleAppView::LoadMbmL( const TDesC& aMbmFile )
00022         {
00023         // Construct BitmapAnimClientData 
00024         if( !iAnimFrames )
00025                 {
00026                 CFbsBitmap* bitmap;
00027                 CFbsBitmap* mask;
00028                 CBitmapFrameData* frameGeneral;
00029                 iAnimFrames = CBitmapAnimClientData::NewL();
00030                 CleanupStack::PushL( iAnimFrames );
00031                 
00032                 iX = KColorBallsAnimXDeflectionStart;
00033                 TInt ballIndex = KColorBallsMbmFirstBallIndex;
00034                 
00035                 while( iX < KColorBallsAnimXDeflectionTerminalValue )
00036                         {
00037                         // Load the image
00038                         bitmap = new (ELeave) CFbsBitmap();
00039                         CleanupStack::PushL( bitmap );
00040                         User::LeaveIfError( bitmap->Load(aMbmFile, ballIndex) );                
00041                         ballIndex = ( KColorBallsMbmLastBallIndex == ballIndex ) ? KColorBallsMbmFirstBallIndex : ballIndex + 1;
00042                                 
00043                         // Load the mask
00044                         mask = new (ELeave) CFbsBitmap();
00045                         CleanupStack::PushL( mask );
00046                         User::LeaveIfError( mask->Load(aMbmFile, KColorBallsMbmMaskIndex) );            
00047                                 
00048                         // Calculate the y deflection
00049                         iY =TInt( KColorBallsAnimYDeflectionOffset + KColorBallsAnimYDeflectionMultiplier*sin( iX ));   
00050                                 
00051                         // Construct the frame
00052                         frameGeneral = CBitmapFrameData::NewL( bitmap, mask, KColorBallsAnimFrameDelay, TPoint(iX, iY) );
00053                         CleanupStack::PushL( frameGeneral );
00054                                 
00055                         // Add it to the sequence
00056                         iAnimFrames->AppendFrameL( frameGeneral );
00057                                 
00058                         // Popping order- mask, bitmap, iFrameGeneral
00059                         CleanupStack::Pop( 3 ); 
00060                                 
00061                         iX += KColorBallsAnimXDeflectionIncrement;
00062                         }
00063                         
00064                 iBitmapAnimPlayer.SetBitmapAnimDataL( *iAnimFrames );
00065                 CleanupStack::Pop( iAnimFrames );
00066                 }
00067         }       
00068         
00069 CExampleAppView::CExampleAppView()
00070 : iBitmapAnimPlayer( iAnimDll ),iAnimDll( iEikonEnv->WsSession() )
00071   
00072         {
00073         }
00074 
00075 CExampleAppView* CExampleAppView::NewL(const TRect& aRect)
00076         {
00077         CExampleAppView* self = new(ELeave) CExampleAppView();
00078         CleanupStack::PushL(self);
00079         self->ConstructL(aRect);
00080         CleanupStack::Pop();
00081         return self;
00082         }
00083 
00084 CExampleAppView::~CExampleAppView()
00085         {
00086         iBitmapAnimPlayer.Close();
00087         delete( iAnimFrames );
00088         iAnimDll.Close();
00089         delete iExampleText;
00090         }
00091 
00092 
00093 // Standard initialisation for a window-owning control.
00094 void CExampleAppView::ConstructL(const TRect& aRect)
00095         {
00096         // Fetch the text from the resource file.
00097         iExampleText = iEikonEnv->AllocReadResourceL( R_EXAMPLE_TEXT_BB );
00098         
00099         // The control is window-owning.
00100         CreateWindowL();
00101         
00102         // Extent of the control. 
00103         SetRect(aRect);
00104         
00105         // The control is ready to draw, so notify the UI framework.
00106         ActivateL();
00107         
00108         // Some animation preamble.
00109         _LIT(KDllName, "BMPANSRV.DLL" );
00110         User::LeaveIfError( iAnimDll.Load( KDllName ) );
00111         iBitmapAnimPlayer.ConstructL( Window() );
00112         
00113         LoadMbmL( KColorBallsMbmPath ); 
00114         }       
00115         
00116                                           
00117 
00118 // Draws the view with a simple outline rectangle 
00119 void CExampleAppView::Draw(const TRect& /*aRect*/) const
00120         {
00121         // Window graphics context
00122         CWindowGc& gc = SystemGc();
00123         
00124         // Area in which we shall draw
00125         TRect drawRect = Rect();
00126         
00127         // The font used for drawing the text
00128         const CFont* fontUsed;
00129         
00130         // Clear the screen
00131         gc.Clear();
00132             
00133         // Use the title font supplied by the UI
00134         fontUsed = iEikonEnv->TitleFont();
00135         gc.UseFont(fontUsed);
00136         
00137         // Draw the text in the rectangle and discard the font.
00138         TInt   baselineOffset=(drawRect.Height() - fontUsed->HeightInPixels())/5; 
00139         gc.DrawText(*iExampleText,drawRect,baselineOffset,CGraphicsContext::ECenter, 0);
00140         gc.DiscardFont();               
00141         }
00142 
00143         
00144         
00145 
00146 
00147 
00148 
00149 
00150 
00151 
00152         
00153         
00154 
00155 
00156 
00157 
00158 

Generated by  doxygen 1.6.2