Nokia N97 SDK
Example Applications Guide

CGraphicsAppView Class Reference

#include <graphicsappview.h>

Inheritance diagram for CGraphicsAppView:

List of all members.

Detailed Description

CGraphicsAppView view class. An instance of this class is the Application View object for the Graphics example application

Definition at line 40 of file graphicsappview.h.


Public Member Functions

virtual  ~CGraphicsAppView ()
void  StartOffScreenDemo ()
void  StartNoOffScreenDemo ()
void  StopDemo ()

Static Public Member Functions

static CGraphicsAppView *  NewL (const TRect &aRect)
static CGraphicsAppView *  NewLC (const TRect &aRect)

Private Member Functions

void  Draw (const TRect &aRect) const
void  HandleResourceChange (TInt aType, const TRect &aRect)
void  ConstructL (const TRect &aRect)
  CGraphicsAppView ()
void  DoPeriodTask ()
void  UpdateDisplay () const
void  SetUpSpritesL ()
void  StartTimer ()
void  ScaleImages ()

Static Private Member Functions

static TInt  Period (TAny *aPtr)

Private Attributes

CFbsBitmap *  iBackgroundImage
CFbsBitmap *  iSpriteImage
CFbsBitmap *  iSpriteMask
CFbsBitmap *  iSpriteImage2
CFbsBitmap *  iSpriteMask2
CFbsBitmap *  iOffScreenBitmap
CFbsBitmapDevice *  iOffScreenBitmapDevice
CFbsBitGc *  iOffScreenBitmapGc
CPeriodic *  iPeriodicTimer
TBool  iUsingOffScreenBitmap
CArrayPtrFlat< CSprite > *  iSprites
RFs  iFsSession
CIconFileProvider *  iIconProvider


Constructor & Destructor Documentation

CGraphicsAppView::~CGraphicsAppView (   )  [virtual]
 

~CGraphicsAppView Virtual Destructor.

Definition at line 141 of file graphicsappview.cpp.

References iBackgroundImage, iFsSession, iIconProvider, iOffScreenBitmap, iOffScreenBitmapDevice, iOffScreenBitmapGc, iPeriodicTimer, iSpriteImage, iSpriteImage2, iSpriteMask, iSpriteMask2, and iSprites.

00142     {
00143         if ( iPeriodicTimer )
00144                 {
00145                 // Stop the periodic timer
00146                 iPeriodicTimer->Cancel();
00147                 }
00148         delete iPeriodicTimer;
00149         iPeriodicTimer = NULL;
00150 
00151         delete iOffScreenBitmapGc;
00152         iOffScreenBitmapGc = NULL;
00153 
00154         delete iOffScreenBitmapDevice;
00155         iOffScreenBitmapDevice = NULL;
00156 
00157         delete iOffScreenBitmap;
00158         iOffScreenBitmap = NULL;
00159 
00160         delete iBackgroundImage;
00161         iBackgroundImage = NULL;
00162 
00163         if ( iSprites )
00164                 {
00165                 iSprites->ResetAndDestroy();
00166                 delete iSprites;
00167                 iSprites = NULL;
00168                 }
00169 
00170         delete iSpriteImage;
00171         iSpriteImage = NULL;
00172 
00173         delete iSpriteMask;
00174         iSpriteMask = NULL;
00175 
00176         delete iSpriteImage2;
00177         iSpriteImage2 = NULL;
00178 
00179         delete iSpriteMask2;
00180         iSpriteMask2 = NULL;
00181 
00182         iFsSession.Close();
00183         delete iIconProvider;
00184     }

CGraphicsAppView::CGraphicsAppView (   )  [private]
 

CGraphicsAppView. C++ default constructor.

Definition at line 36 of file graphicsappview.cpp.

00037     : iOffScreenBitmap(NULL)
00038     , iOffScreenBitmapDevice(NULL)
00039     , iOffScreenBitmapGc(NULL)
00040     {
00041     // No implementation required
00042     }


Member Function Documentation

CGraphicsAppView * CGraphicsAppView::NewL (  const TRect &  aRect  )  [static]
 

NewL. Two-phased constructor. Create a CGraphicsAppView object, which will draw itself to aRect.

Parameters:
aRect  The rectangle this view will be drawn to.
Returns:
a pointer to the created instance of CGraphicsAppView.

Definition at line 49 of file graphicsappview.cpp.

References NewLC().

Referenced by CGraphicsAppUi::ConstructL().

00050     {
00051     CGraphicsAppView* self = NewLC( aRect );
00052     CleanupStack::Pop( self );
00053     return self;
00054     }

CGraphicsAppView * CGraphicsAppView::NewLC (  const TRect &  aRect  )  [static]
 

NewLC. Two-phased constructor. Create a CGraphicsAppView object, which will draw itself to aRect.

Parameters:
aRect  Rectangle this view will be drawn to.
Returns:
A pointer to the created instance of CGraphicsAppView.

Definition at line 61 of file graphicsappview.cpp.

References ConstructL().

Referenced by NewL().

00062     {
00063     CGraphicsAppView* self = new ( ELeave ) CGraphicsAppView;
00064     CleanupStack::PushL( self );
00065     self->ConstructL( aRect );
00066     return self;
00067     }

void CGraphicsAppView::StartOffScreenDemo (   ) 
 

StartOffScreenDemo Start demo using off-screen bitmap.

Definition at line 359 of file graphicsappview.cpp.

References iUsingOffScreenBitmap, and StartTimer().

Referenced by CGraphicsAppUi::HandleCommandL().

00360         {
00361         iUsingOffScreenBitmap = ETrue;
00362         StartTimer();
00363         }

void CGraphicsAppView::StartNoOffScreenDemo (   ) 
 

StartNoOffScreenDemo Start demo without using off-screen bitmap.

Definition at line 370 of file graphicsappview.cpp.

References iUsingOffScreenBitmap, and StartTimer().

Referenced by CGraphicsAppUi::HandleCommandL().

00371         {
00372         iUsingOffScreenBitmap = EFalse;
00373         StartTimer();
00374         }

void CGraphicsAppView::StopDemo (   ) 
 

StopDemo Stop animation.

Definition at line 345 of file graphicsappview.cpp.

References iPeriodicTimer.

Referenced by CGraphicsAppUi::HandleCommandL().

00346         {
00347         // Stop the timer if it is active
00348         if ( iPeriodicTimer->IsActive() )
00349                 {
00350                 iPeriodicTimer->Cancel();
00351                 }
00352         }

void CGraphicsAppView::Draw (  const TRect &  aRect  )  const [private]
 

From CCoeControl, Draw Draw this CGraphicsAppView to the screen.

Parameters:
aRect  the rectangle of this view that needs updating

Definition at line 230 of file graphicsappview.cpp.

References UpdateDisplay().

00231     {
00232         // The system GC will already be activated when this function is called
00233         // by the framework
00234         UpdateDisplay();
00235     }

void CGraphicsAppView::ConstructL (  const TRect &  aRect  )  [private]
 

ConstructL 2nd phase constructor. Perform the second phase construction of a CGraphicsAppView object

Parameters:
aRect  The rectangle this view will be drawn to.

Definition at line 74 of file graphicsappview.cpp.

References iBackgroundImage, iFsSession, iIconProvider, iPeriodicTimer, iSpriteImage, iSpriteImage2, iSpriteMask, iSpriteMask2, iSprites, ScaleImages(), and SetUpSpritesL().

Referenced by NewLC().

00075     {
00076     // Create a window for this application view
00077     CreateWindowL();
00078 
00079     // Set the window's size and position
00080     SetRect( aRect );
00081 
00082     // Load in the bitmap images from the multi bitmap file
00083 
00084     // create and open file server session
00085     User::LeaveIfError(iFsSession.Connect());
00086     iFsSession.ShareProtected();
00087     TFileName filePath;
00088 
00089     // set path of the bitmap file
00090     User::LeaveIfError(iFsSession.PrivatePath(filePath));
00091 
00092     // append the MBM file name to the private path
00093     filePath.Append(KMultiBitmapFilename);
00094 
00095     // insert the drive to the private path
00096     TParsePtrC parse((CEikonEnv::Static()->EikAppUi()->Application())->AppFullName());
00097     filePath.Insert(0, parse.Drive());
00098 
00099     // with the help of icon-provider AknIconUtils can get get the file
00100     // from this application's private folder
00101         iIconProvider = CIconFileProvider::NewL( iFsSession, filePath );
00102 
00103     iBackgroundImage = AknIconUtils::CreateIconL(*iIconProvider,
00104                                                  EMbmGraphicsappimagesImage1);
00105         // Load sprite bitmap and mask with a single call
00106         AknIconUtils::CreateIconL(iSpriteImage,
00107                                   iSpriteMask,
00108                                   *iIconProvider,
00109                                   EMbmGraphicsappimagesImage2,
00110                                   EMbmGraphicsappimagesImage2_mask);
00111 
00112         // Load svg.-image and mask with a single call
00113         AknIconUtils::CreateIconL(iSpriteImage2,
00114                                   iSpriteMask2,
00115                                   *iIconProvider,
00116                                   EMbmGraphicsappimagesStar,
00117                                   EMbmGraphicsappimagesStar_mask);
00118     // This call preserves SVG-T vector data in memory so that the data is not needed to
00119     // load from the resource when the icon is subsequently scaled.
00120     AknIconUtils::PreserveIconData(iSpriteImage2);
00121 
00122     ScaleImages();
00123 
00124     // Create a periodic timer but don't start it yet
00125     iPeriodicTimer = CPeriodic::NewL( CActive::EPriorityStandard );
00126 
00127     // Create the array of sprite pointers
00128     iSprites = new ( ELeave ) CArrayPtrFlat<CSprite> ( 1 );
00129 
00130     SetUpSpritesL();
00131 
00132     // Activate the window, which makes it ready to be drawn
00133     ActivateL();
00134     }

void CGraphicsAppView::DoPeriodTask (   )  [private]
 

DoPeriodTask. Called by period task static function.

Definition at line 396 of file graphicsappview.cpp.

References CSprite::Image(), iSprites, CSprite::Move(), and UpdateDisplay().

00397         {
00398         for ( TInt count = 0; count < iSprites->Count(); ++count )
00399                 {
00400         CSprite *sprite = iSprites->At(count);
00401                 sprite->Move( sprite->Image()->SizeInPixels(), Rect() );
00402                 }
00403 
00404         // Update the screen
00405         CWindowGc& gc = SystemGc();
00406         gc.Activate( *DrawableWindow() );
00407         UpdateDisplay();
00408         gc.Deactivate();
00409         }

TInt CGraphicsAppView::Period (  TAny *  aPtr  )  [static, private]
 

Period. Call back function for a periodic timer

Parameters:
aPtr  a parameter passed to the timer when the timer is started.
Returns:
Value TRUE indicates the callback should be done again.

Definition at line 416 of file graphicsappview.cpp.

Referenced by StartTimer().

00417         {
00418     ( static_cast<CGraphicsAppView*>( aPtr ) )->DoPeriodTask();
00419     // Returning a value of TRUE indicates the callback should be done again
00420         return ETrue;
00421         }

void CGraphicsAppView::UpdateDisplay (   )  const [private]
 

UpdateDisplay. Perfom the drawing, does not activate the GC.

Definition at line 296 of file graphicsappview.cpp.

References iBackgroundImage, CSprite::Image(), iOffScreenBitmap, iOffScreenBitmapGc, iSprites, iUsingOffScreenBitmap, CSprite::Mask(), and CSprite::Position().

Referenced by DoPeriodTask(), and Draw().

00297     {
00298     CWindowGc& gc = SystemGc();
00299 
00300     if ( !iUsingOffScreenBitmap )
00301         {
00302         // Blit the background image onto the screen at the top left position
00303         gc.BitBlt( Rect().iTl,iBackgroundImage );
00304 
00305         // Blit the sprites on top of it using their mask to retain
00306                 // the background where necessary
00307         for ( TInt count = 0; count<iSprites->Count(); ++count )
00308             {
00309             CSprite *sprite = iSprites->At(count);
00310             TRect sourceRect( TPoint( 0,0 ), sprite->Image()->SizeInPixels() );
00311             gc.BitBltMasked( sprite->Position(),
00312                              sprite->Image(),
00313                              sourceRect,
00314                              sprite->Mask(),
00315                              ETrue );
00316             }
00317         }
00318     else
00319         {
00320         // Blit the background image onto the off screen bitmap
00321                 // at the top left position
00322         iOffScreenBitmapGc->BitBlt( TPoint( 0,0 ), iBackgroundImage );
00323 
00324         // Blit the sprites on top of it using its mask to retain
00325                 // the background where necessary
00326         for ( TInt count = 0; count<iSprites->Count(); ++count )
00327             {
00328             CSprite *sprite = iSprites->At(count);
00329             NBitmapMethods::BitBltMaskedEntireBitmap( *iOffScreenBitmapGc,
00330                                             sprite->Position(),
00331                                             *(sprite->Image()),
00332                                             *(sprite->Mask()));
00333             }
00334 
00335         // Blit the offscreen image onto the screen at the top left position
00336         gc.BitBlt( Rect().iTl,iOffScreenBitmap );
00337         }
00338     }

void CGraphicsAppView::SetUpSpritesL (   )  [private]
 

SetUpSpritesL. Initialise the objects being drawn.

Definition at line 191 of file graphicsappview.cpp.

References iSpriteImage, iSpriteImage2, iSpriteMask, iSpriteMask2, iSprites, and CSprite::NewLC().

Referenced by ConstructL().

00192         {
00193     ASSERT( iSpriteImage );
00194     ASSERT( iSpriteImage2 );
00195         ASSERT( iSprites );
00196 
00197         // Create the sprites
00198         CSprite* sprite = NULL;
00199 
00200         sprite = CSprite::NewLC( KInitialXSpeed,
00201                                  KInitialYSpeed+1,
00202                                  Rect().iTl,
00203                                  iSpriteImage,
00204                                  iSpriteMask );
00205         iSprites->AppendL( sprite );
00206         CleanupStack::Pop( sprite );
00207 
00208         sprite = CSprite::NewLC( -KInitialXSpeed,
00209                                  -KInitialYSpeed,
00210                                  Rect().iBr - iSpriteImage->SizeInPixels(),
00211                                  iSpriteImage,
00212                                  iSpriteMask );
00213         iSprites->AppendL( sprite );
00214         CleanupStack::Pop( sprite );
00215 
00216         sprite = CSprite::NewLC( KInitialXSpeed,
00217                                  -KInitialYSpeed+1,
00218                                  Rect().iTl + iSpriteImage2->SizeInPixels(),
00219                                  iSpriteImage2,
00220                                  iSpriteMask2 );
00221         iSprites->AppendL( sprite );
00222         CleanupStack::Pop( sprite );
00223         }

void CGraphicsAppView::StartTimer (   )  [private]
 

StartTimer. Start the timer.

Definition at line 381 of file graphicsappview.cpp.

References iPeriodicTimer, and Period().

Referenced by StartNoOffScreenDemo(), and StartOffScreenDemo().

00382         {
00383         // If the timer is not already running, start it
00384         if ( !iPeriodicTimer->IsActive() )
00385                 {
00386                 iPeriodicTimer->Start(1, 1, TCallBack( CGraphicsAppView::Period, this));
00387                 }
00388 
00389         }

void CGraphicsAppView::ScaleImages (   )  [private]
 

ScaleImages Scales background and sprite according to current layout.

Definition at line 264 of file graphicsappview.cpp.

References iBackgroundImage, iOffScreenBitmap, iOffScreenBitmapDevice, iOffScreenBitmapGc, iSpriteImage, and iSpriteImage2.

Referenced by ConstructL(), and HandleResourceChange().

00265     {
00266     TInt x = Size().iWidth;
00267     TInt y = Size().iHeight;
00268 
00269     AknIconUtils::SetSize(iBackgroundImage,
00270                           Size(),
00271                           EAspectRatioNotPreserved);
00272 
00273     // target size for the sprites is ~40x40 in 352x416 resolution.
00274     // orientation does not affect on scaling.
00275     AknIconUtils::SetSize(iSpriteImage, TSize((x+y)/19, (x+y)/19));
00276     AknIconUtils::SetSize(iSpriteImage2, TSize((x+y)/19, (x+y)/19));
00277 
00278         delete iOffScreenBitmapGc;
00279         iOffScreenBitmapGc = NULL;
00280         delete iOffScreenBitmapDevice;
00281         iOffScreenBitmapDevice = NULL;
00282         delete iOffScreenBitmap;
00283         iOffScreenBitmap = NULL;
00284 
00285     // Create the off screen bitmap and device / gc
00286     iOffScreenBitmap = NBitmapMethods::CreateBitmapL( Size(), KColourDepth );
00287     iOffScreenBitmapDevice = NBitmapMethods::CreateBitmapDeviceL( *iOffScreenBitmap );
00288     iOffScreenBitmapGc = NBitmapMethods::CreateGraphicsContextL( *iOffScreenBitmapDevice );
00289     }


Member Data Documentation

CFbsBitmap* CGraphicsAppView::iBackgroundImage [private]
 

iBackgroundImage The background bitmap Owned by CGraphicsAppView object.

Definition at line 161 of file graphicsappview.h.

Referenced by ConstructL(), ScaleImages(), UpdateDisplay(), and ~CGraphicsAppView().

CFbsBitmap* CGraphicsAppView::iSpriteImage [private]
 

iSpriteImage The "sprite" bitmap image Owned by CGraphicsAppView object.

Definition at line 168 of file graphicsappview.h.

Referenced by ConstructL(), ScaleImages(), SetUpSpritesL(), and ~CGraphicsAppView().

CFbsBitmap* CGraphicsAppView::iSpriteMask [private]
 

iSpriteMask The "sprite" bitblit mask Owned by CGraphicsAppView object.

Definition at line 175 of file graphicsappview.h.

Referenced by ConstructL(), SetUpSpritesL(), and ~CGraphicsAppView().

CFbsBitmap* CGraphicsAppView::iSpriteImage2 [private]
 

iSpriteImage The "sprite" bitmap image Owned by CGraphicsAppView object.

Definition at line 182 of file graphicsappview.h.

Referenced by ConstructL(), ScaleImages(), SetUpSpritesL(), and ~CGraphicsAppView().

CFbsBitmap* CGraphicsAppView::iSpriteMask2 [private]
 

iSpriteMask The "sprite" bitblit mask Owned by CGraphicsAppView object.

Definition at line 189 of file graphicsappview.h.

Referenced by ConstructL(), SetUpSpritesL(), and ~CGraphicsAppView().

CFbsBitmap* CGraphicsAppView::iOffScreenBitmap [private]
 

iOffScreenBitmap The off screen bitmap Owned by CGraphicsAppView object.

Definition at line 196 of file graphicsappview.h.

Referenced by ScaleImages(), UpdateDisplay(), and ~CGraphicsAppView().

CFbsBitmapDevice* CGraphicsAppView::iOffScreenBitmapDevice [private]
 

iOffScreenBitmapDevice The off screen bitmap device Owned by CGraphicsAppView object.

Definition at line 203 of file graphicsappview.h.

Referenced by ScaleImages(), and ~CGraphicsAppView().

CFbsBitGc* CGraphicsAppView::iOffScreenBitmapGc [private]
 

iOffScreenBitmapGc The off screen bitmap gc Owned by CGraphicsAppView object.

Definition at line 210 of file graphicsappview.h.

Referenced by ScaleImages(), UpdateDisplay(), and ~CGraphicsAppView().

CPeriodic* CGraphicsAppView::iPeriodicTimer [private]
 

iPeriodicTimer The periodic timer used to control the animation Owned by CGraphicsAppView object.

Definition at line 217 of file graphicsappview.h.

Referenced by ConstructL(), StartTimer(), StopDemo(), and ~CGraphicsAppView().

TBool CGraphicsAppView::iUsingOffScreenBitmap [private]
 

iUsingOffScreenBitmap The flag to keep track of whether or not the demo is using an off screen bitmap

Definition at line 224 of file graphicsappview.h.

Referenced by StartNoOffScreenDemo(), StartOffScreenDemo(), and UpdateDisplay().

CArrayPtrFlat<CSprite>* CGraphicsAppView::iSprites [private]
 

iSprites The array of sprites to be drawn Owned by CGraphicsAppView object.

Definition at line 231 of file graphicsappview.h.

Referenced by ConstructL(), DoPeriodTask(), HandleResourceChange(), SetUpSpritesL(), UpdateDisplay(), and ~CGraphicsAppView().


The documentation for this class was generated from the following files:

© Nokia 2009

Back to top