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

Generated by  doxygen 1.6.2