S60UIExampleHighScoreContainer.cpp
上传用户:laixiong
上传日期:2007-03-11
资源大小:2994k
文件大小:7k
源码类别:
Symbian
开发平台:
C/C++
- // Copyright (c) 2006 Nokia Corporation.
- #include "S60UIExampleHighScoreContainer.h"
- #include "S60UIExampleModel.h"
- #include <akntitle.h>
- #include <eikspane.h>
- #include <aknViewAppUi.h>
- #include <aknutils.h>
- #include <akniconutils.h>
- #include <S60UIExample.mbg>
- #include <S60UIExample.rsg>
- #include <stringloader.h>
- // -----------------------------------------------------------------------------
- // CS60UIExampleHighScoreContainer::NewL()
- // Two-phased constructor.
- // -----------------------------------------------------------------------------
- //
- CS60UIExampleHighScoreContainer* CS60UIExampleHighScoreContainer::NewL(
- const TRect& aRect,
- CS60UIExampleModel& aModel)
- {
- CS60UIExampleHighScoreContainer* self =
- CS60UIExampleHighScoreContainer::NewLC(aRect, aModel);
- CleanupStack::Pop(self);
- return self;
- }
- // -----------------------------------------------------------------------------
- // CS60UIExampleHighScoreContainer::NewLC()
- // Two-phased constructor.
- // -----------------------------------------------------------------------------
- //
- CS60UIExampleHighScoreContainer* CS60UIExampleHighScoreContainer::NewLC(
- const TRect& aRect,
- CS60UIExampleModel& aModel)
- {
- CS60UIExampleHighScoreContainer* self =
- new (ELeave) CS60UIExampleHighScoreContainer(aModel);
- CleanupStack::PushL(self);
- self->ConstructL(aRect);
- return self;
- }
- // -----------------------------------------------------------------------------
- // CS60UIExampleHighScoreContainer::CS60UIExampleHighScoreContainer()
- // First stage constructor
- // -----------------------------------------------------------------------------
- //
- CS60UIExampleHighScoreContainer::CS60UIExampleHighScoreContainer(
- CS60UIExampleModel& aModel)
- : iModel(aModel)
- {
- }
- // -----------------------------------------------------------------------------
- // CS60UIExampleHighScoreContainer::ConstructL()
- // Symbian 2nd phase constructor can leave.
- // -----------------------------------------------------------------------------
- //
- void CS60UIExampleHighScoreContainer::ConstructL(const TRect& aRect)
- {
- CreateWindowL();
- CEikStatusPane* statusPane = iAvkonViewAppUi->StatusPane();
- CAknTitlePane* titlePane = (CAknTitlePane*)statusPane->
- ControlL(TUid::Uid(EEikStatusPaneUidTitle));
- // Set the text string.
- iTitle = StringLoader::LoadL(R_S60UIEXAMPLE_HIGHSCORE_TITLE_TEXT, iCoeEnv);
- titlePane->SetTextL(*iTitle);
- // Get background graphic
- _LIT(KSvgFile,"z:\resource\apps\S60UIExample.mif");
- iBkgBitmap = AknIconUtils::CreateIconL(KSvgFile,
- EMbmS60uiexampleGraduated_bkg);
- SetRect(aRect);
- ActivateL();
- }
- // -----------------------------------------------------------------------------
- // CS60UIExampleHighScoreContainer::~CS60UIExampleHighScoreContainer()
- // Destructor
- // -----------------------------------------------------------------------------
- //
- CS60UIExampleHighScoreContainer::~CS60UIExampleHighScoreContainer()
- {
- delete iTitle;
- delete iBkgBitmap;
- }
- // -----------------------------------------------------------------------------
- // CS60UIExampleHighScoreContainer::SizeChanged()
- // Handles necessary size changes, in this case resizing the bitmap.
- // -----------------------------------------------------------------------------
- //
- void CS60UIExampleHighScoreContainer::SizeChanged()
- {
- TRect rect = Rect();
- TInt error = AknIconUtils::SetSize(iBkgBitmap,
- rect.Size(),
- EAspectRatioNotPreserved);
- }
- // -----------------------------------------------------------------------------
- // CS60UIExampleHighScoreContainer::HandleResourceChange()
- // Called by framework when screen size changes. Use to cause necessary
- // resizing to be performed.
- // -----------------------------------------------------------------------------
- //
- void CS60UIExampleHighScoreContainer::HandleResourceChange(TInt aType)
- {
- CCoeControl::HandleResourceChange(aType);
- if (aType == KEikDynamicLayoutVariantSwitch)
- {
- // Screen size has changed. Get the new Main Pane size
- TRect rect;
- AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect);
- // Pass it on. Eventually SizeChanged() performs the necessary
- // resizing
- SetRect(rect);
- }
- }
- // -----------------------------------------------------------------------------
- // CS60UIExampleHighScoreContainer::Draw() const
- // Draws the display
- // -----------------------------------------------------------------------------
- //
- void CS60UIExampleHighScoreContainer::Draw(const TRect& aRect) const
- {
- CWindowGc& gc = SystemGc();
- // Generate scalable text positions based on aRect
- TInt numXPos = aRect.Width() / 30;
- TInt nameXPos = aRect.Width() / 3;
- TInt firstLine = aRect.Height() / 4;
- TInt lineSpace = aRect.Height() / 8;
- // draw the background
- gc.BitBlt(TPoint(0, 0), iBkgBitmap);
- // Overlay the title
- gc.SetPenColor(KRgbBlack);
- gc.SetPenStyle(CGraphicsContext::ESolidPen);
- gc.UseFont(AknLayoutUtils::FontFromId(EAknLogicalFontPrimaryFont));
- // Get pointer to the high scores
- RArray<THighScore>* array = iModel.HighScoreArray();
- TInt index = array->Count();
- if (index > 0)
- {
- // they are held in increasing order, so list last first
- index--;
- TInt linePos = firstLine;
- while (index >= 0)
- {
- THighScore highScore = (*array)[index];
- TBuf<10> numText;
- numText.NumFixedWidth(highScore.iScore,EDecimal, 6);
- TPoint numTextPos(numXPos, linePos);
- gc.DrawText(numText, numTextPos);
- TPoint nameTextPos(nameXPos, linePos);
- gc.DrawText(highScore.iName, nameTextPos);
- linePos += lineSpace;
- index--;
- }
- }
- else
- {
- _LIT(KNoHighscoresText,"No High Scores");
- gc.DrawText(KNoHighscoresText, TPoint(nameXPos,firstLine + lineSpace));
- }
- gc.DiscardFont();
- }
- // End of File