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

CGameAppView.cpp

Go to the documentation of this file.
00001 // Copyright 2002 Kenneth Guy,
00002 // 
00003 // You are free to take the source and do as you wish with it.
00004 // However it would be nice if you let me know if the code was useful
00005 // to you and give me an acknowledgement if you use a significant portion
00006 // of the code in an application.
00007 // 
00008 // CGameAppView.cpp
00009 
00013 //
00014 
00015 #include "CGameAppUi.h"
00016 #include "CGameAppView.h"
00017 #include "CGameApplication.h"
00018 #include "CGameDocument.h"
00019 #include "CGameState.h"
00020 #include "CScoreDialog.h"
00021 #include "CHighScores.h"
00022 
00028 void CGameAppView::ConstructL(const TRect& aRect, CGameState* aGameState) {
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 }
00039 
00042 CGameAppView::~CGameAppView() {
00043   delete iCompleteString;
00044   delete iPausedString;
00045   delete iScoresString;
00046 }
00047 
00052 void CGameAppView::Draw(const TRect& /*aRect*/) const { 
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 }
00065 
00071 void CGameAppView::DrawHighScores() const {
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 }
00113 
00114 
00117 void CGameAppView::DrawPaused() const {
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 }
00129 
00132 void CGameAppView::DrawLevelCompleted() const {
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 }
00144 

Documentation for Game (Beta) version 1.44.