Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

CGameAppView Class Reference

Draw the app window. More...

#include <CGameAppView.h>

Collaboration diagram for CGameAppView:

Collaboration graph
[legend]
List of all members.

Public Methods

void ConstructL (const TRect &aRect, CGameState *aState)
 2nd phase construction. More...

 ~CGameAppView ()
 Delete localised strings. More...


Private Methods

void Draw (const TRect &aRect) const
 Draw the window. More...

void DrawHighScores () const
 Draw high score table. More...

void DrawPaused () const
 Draw a paused screen. More...

void DrawLevelCompleted () const
 Draw a level complete screen. More...


Private Attributes

CGameStateiGameState
 Game state. More...

HBufC * iCompleteString
 String to display when a level is finished. More...

HBufC * iPausedString
 String to display when a game is paused. More...

HBufC * iScoresString
 String to display on high score screen. More...


Detailed Description

Draw the app window.

This draws the application window to reflect the game state

Definition at line 33 of file CGameAppView.h.


Constructor & Destructor Documentation

CGameAppView::~CGameAppView  
 

Delete localised strings.

Definition at line 42 of file CGameAppView.cpp.

References iCompleteString, iPausedString, and iScoresString.

00042                             {
00043   delete iCompleteString;
00044   delete iPausedString;
00045   delete iScoresString;
00046 }


Member Function Documentation

void CGameAppView::ConstructL const TRect &    aRect,
CGameState   aGameState
 

2nd phase construction.

Load strings from resource file, and create the window.

Definition at line 28 of file CGameAppView.cpp.

References iCompleteString, iGameState, iPausedString, and iScoresString.

Referenced by CGameAppUi::ConstructL().

00028                                                                         {
00029   iGameState=aGameState;
00030   CEikonEnv* eikonEnv=CEikonEnv::Static();
00031   iCompleteString = eikonEnv->AllocReadResourceL(R_COMPLETE_STRING);
00032   iPausedString = eikonEnv->AllocReadResourceL(R_PAUSED_STRING);
00033   iScoresString = eikonEnv->AllocReadResourceL(R_SCORES_STRING);
00034 
00035   CreateWindowL();
00036   SetRect(aRect);
00037   ActivateL();
00038 }

void CGameAppView::Draw const TRect &    aRect const [private]
 

Draw the window.

Redraw the window depending on the game state

Definition at line 52 of file CGameAppView.cpp.

References DrawHighScores(), DrawLevelCompleted(), DrawPaused(), CGameState::ENextLevel, CGameState::ENoGame, CGameState::EPaused, iGameState, and CGameState::State().

00052                                                     {   
00053   switch(iGameState->State()) {
00054   case CGameState::ENoGame:
00055     DrawHighScores();
00056     break;
00057   case CGameState::EPaused:
00058     DrawPaused();
00059     break;
00060   case CGameState::ENextLevel:
00061     DrawLevelCompleted();
00062     break;
00063   }
00064 }

void CGameAppView::DrawHighScores   const [private]
 

Draw high score table.

Draws the high score table, highliting the most recently added entry if there is one.

Definition at line 71 of file CGameAppView.cpp.

References CGameState::HighScores(), iGameState, iScoresString, CHighScores::LastAdded(), CHighScores::Name(), CHighScores::Number(), and CHighScores::Score().

Referenced by Draw().

00071                                         {
00072   CWindowGc& gc = SystemGc();
00073   const CFont*     fontUsed;
00074   CEikonEnv* eikonEnv=CEikonEnv::Static();
00075   gc.Clear();
00076   fontUsed = eikonEnv->TitleFont();
00077   gc.UseFont(fontUsed);
00078 
00079   TInt y=60;
00080   const TInt KFontHeight=fontUsed->HeightInPixels();
00081 
00082   TRgb red(230,0,0);
00083   TRgb blue(0,0,230);
00084   TRgb black(0,0,0);
00085 
00086   const TRect& area=Rect();
00087 
00088   const TInt KMargin=60;
00089   gc.SetPenColor(red);
00090   gc.DrawText(*iScoresString,TPoint((area.Width()-fontUsed->TextWidthInPixels(*iScoresString))/2,30));
00091 
00092   const TInt count=iGameState->HighScores().Number();
00093   for(TInt i=0;i<count;i++) {
00094     if(iGameState->HighScores().LastAdded()==i) {
00095       gc.SetPenColor(blue);
00096     } else {
00097       gc.SetPenColor(black);
00098     }
00099 
00100     gc.DrawText(iGameState->HighScores().Name(i),TPoint(KMargin,y));
00101 
00102     TBuf<15> temp;
00103     _LIT(KScoreFormat,"%+ 8d");
00104     
00105     temp.Format(KScoreFormat,iGameState->HighScores().Score(i));
00106     gc.DrawText(temp,TPoint(area.Width()-fontUsed->TextWidthInPixels(temp)-KMargin,y));
00107 
00108     y+=KFontHeight;
00109   }
00110   gc.SetPenColor(black);
00111   gc.DiscardFont();
00112 }

void CGameAppView::DrawPaused   const [private]
 

Draw a paused screen.

Definition at line 117 of file CGameAppView.cpp.

References iPausedString.

Referenced by Draw().

00117                                     {
00118   CWindowGc& gc = SystemGc();
00119   const CFont*     fontUsed;
00120   CEikonEnv* eikonEnv=CEikonEnv::Static();
00121   gc.Clear();
00122   fontUsed = eikonEnv->TitleFont();
00123   gc.UseFont(fontUsed);
00124   TRect      drawRect = Rect();
00125   TInt baselineOffset=(drawRect.Height() - fontUsed->HeightInPixels())/2; 
00126   gc.DrawText(*iPausedString,drawRect,baselineOffset,CGraphicsContext::ECenter,0);
00127   gc.DiscardFont();
00128 }

void CGameAppView::DrawLevelCompleted   const [private]
 

Draw a level complete screen.

Definition at line 132 of file CGameAppView.cpp.

References iCompleteString.

Referenced by Draw().

00132                                             {
00133   CWindowGc& gc = SystemGc();
00134   const CFont*     fontUsed;
00135   CEikonEnv* eikonEnv=CEikonEnv::Static();
00136   gc.Clear();
00137   fontUsed = eikonEnv->TitleFont();
00138   gc.UseFont(fontUsed);
00139   TRect      drawRect = Rect();
00140   TInt baselineOffset=(drawRect.Height() - fontUsed->HeightInPixels())/2; 
00141   gc.DrawText(*iCompleteString,drawRect,baselineOffset,CGraphicsContext::ECenter,0);
00142   gc.DiscardFont();
00143 }


Member Data Documentation

CGameState* CGameAppView::iGameState [private]
 

Game state.

Definition at line 44 of file CGameAppView.h.

Referenced by ConstructL(), Draw(), and DrawHighScores().

HBufC* CGameAppView::iCompleteString [private]
 

String to display when a level is finished.

Definition at line 45 of file CGameAppView.h.

Referenced by ConstructL(), DrawLevelCompleted(), and ~CGameAppView().

HBufC* CGameAppView::iPausedString [private]
 

String to display when a game is paused.

Definition at line 46 of file CGameAppView.h.

Referenced by ConstructL(), DrawPaused(), and ~CGameAppView().

HBufC* CGameAppView::iScoresString [private]
 

String to display on high score screen.

Definition at line 47 of file CGameAppView.h.

Referenced by ConstructL(), DrawHighScores(), and ~CGameAppView().


The documentation for this class was generated from the following files:
Documentation for Game (Beta) version 1.44.