S60UIExampleHighScoreContainer.cpp
上传用户:laixiong
上传日期:2007-03-11
资源大小:2994k
文件大小:7k
源码类别:

Symbian

开发平台:

C/C++

  1. // Copyright (c) 2006 Nokia Corporation.
  2. #include "S60UIExampleHighScoreContainer.h"
  3. #include "S60UIExampleModel.h"
  4. #include <akntitle.h>
  5. #include <eikspane.h>
  6. #include <aknViewAppUi.h>
  7. #include <aknutils.h>
  8. #include <akniconutils.h>
  9. #include <S60UIExample.mbg>
  10. #include <S60UIExample.rsg>
  11. #include <stringloader.h>    
  12. // -----------------------------------------------------------------------------
  13. // CS60UIExampleHighScoreContainer::NewL()
  14. // Two-phased constructor.
  15. // -----------------------------------------------------------------------------
  16. //
  17. CS60UIExampleHighScoreContainer* CS60UIExampleHighScoreContainer::NewL(
  18.                                                   const TRect& aRect,
  19.                                                   CS60UIExampleModel& aModel)
  20.     {
  21.     CS60UIExampleHighScoreContainer* self = 
  22.                      CS60UIExampleHighScoreContainer::NewLC(aRect, aModel);
  23.     CleanupStack::Pop(self);
  24.     return self;
  25.     }
  26. // -----------------------------------------------------------------------------
  27. // CS60UIExampleHighScoreContainer::NewLC()
  28. // Two-phased constructor.
  29. // -----------------------------------------------------------------------------
  30. //
  31. CS60UIExampleHighScoreContainer* CS60UIExampleHighScoreContainer::NewLC(
  32.                                                  const TRect& aRect,
  33.                                                  CS60UIExampleModel& aModel)
  34.     {
  35.     CS60UIExampleHighScoreContainer* self = 
  36.                          new (ELeave) CS60UIExampleHighScoreContainer(aModel);
  37.     CleanupStack::PushL(self);
  38.     self->ConstructL(aRect);
  39.     return self;
  40.     }
  41. // -----------------------------------------------------------------------------
  42. // CS60UIExampleHighScoreContainer::CS60UIExampleHighScoreContainer()
  43. // First stage constructor
  44. // -----------------------------------------------------------------------------
  45. //
  46. CS60UIExampleHighScoreContainer::CS60UIExampleHighScoreContainer(
  47.                                               CS60UIExampleModel& aModel)
  48.     : iModel(aModel)
  49.     {
  50.     }
  51.     
  52. // -----------------------------------------------------------------------------
  53. // CS60UIExampleHighScoreContainer::ConstructL()
  54. // Symbian 2nd phase constructor can leave.
  55. // -----------------------------------------------------------------------------
  56. //
  57. void CS60UIExampleHighScoreContainer::ConstructL(const TRect& aRect)
  58.     {
  59.     CreateWindowL();
  60.     CEikStatusPane* statusPane = iAvkonViewAppUi->StatusPane();
  61.     CAknTitlePane* titlePane = (CAknTitlePane*)statusPane->
  62.                             ControlL(TUid::Uid(EEikStatusPaneUidTitle));
  63.     // Set the text string.
  64.     iTitle = StringLoader::LoadL(R_S60UIEXAMPLE_HIGHSCORE_TITLE_TEXT, iCoeEnv);
  65.     titlePane->SetTextL(*iTitle); 
  66.     
  67.     // Get background graphic
  68.     _LIT(KSvgFile,"z:\resource\apps\S60UIExample.mif");
  69.     iBkgBitmap = AknIconUtils::CreateIconL(KSvgFile, 
  70.                                            EMbmS60uiexampleGraduated_bkg);
  71.     SetRect(aRect);
  72.     
  73.     ActivateL();
  74.     }
  75.     
  76.     
  77. // -----------------------------------------------------------------------------
  78. // CS60UIExampleHighScoreContainer::~CS60UIExampleHighScoreContainer()
  79. // Destructor
  80. // -----------------------------------------------------------------------------
  81. //
  82. CS60UIExampleHighScoreContainer::~CS60UIExampleHighScoreContainer()
  83.     {
  84.     delete iTitle;
  85.     delete iBkgBitmap;
  86.     }
  87.     
  88.     
  89. // -----------------------------------------------------------------------------
  90. // CS60UIExampleHighScoreContainer::SizeChanged()
  91. // Handles necessary size changes, in this case resizing the bitmap.
  92. // -----------------------------------------------------------------------------
  93. //
  94. void CS60UIExampleHighScoreContainer::SizeChanged()
  95.     {
  96.     TRect rect = Rect();
  97.     TInt error = AknIconUtils::SetSize(iBkgBitmap, 
  98.                                        rect.Size(), 
  99.                                        EAspectRatioNotPreserved);
  100.     }
  101. // -----------------------------------------------------------------------------
  102. // CS60UIExampleHighScoreContainer::HandleResourceChange()
  103. // Called by framework when screen size changes. Use to cause necessary
  104. // resizing to be performed.
  105. // -----------------------------------------------------------------------------
  106. //
  107. void CS60UIExampleHighScoreContainer::HandleResourceChange(TInt aType)
  108.     {
  109.     CCoeControl::HandleResourceChange(aType);
  110.     if (aType == KEikDynamicLayoutVariantSwitch)
  111.         {
  112.         // Screen size has changed. Get the new Main Pane size
  113.         TRect rect;
  114.         AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect);
  115.         // Pass it on. Eventually SizeChanged() performs the necessary
  116.         // resizing
  117.         SetRect(rect);
  118.         }
  119.         
  120.     }
  121. // -----------------------------------------------------------------------------
  122. // CS60UIExampleHighScoreContainer::Draw() const
  123. // Draws the display
  124. // -----------------------------------------------------------------------------
  125. //
  126. void CS60UIExampleHighScoreContainer::Draw(const TRect& aRect) const
  127.     {
  128.     CWindowGc& gc = SystemGc();
  129.     // Generate scalable text positions based on aRect
  130.     TInt numXPos = aRect.Width() / 30;
  131.     TInt nameXPos = aRect.Width() / 3;
  132.     TInt firstLine = aRect.Height() / 4;
  133.     TInt lineSpace = aRect.Height() / 8;
  134.     // draw the background
  135.     gc.BitBlt(TPoint(0, 0), iBkgBitmap);
  136.     // Overlay the title
  137.     gc.SetPenColor(KRgbBlack);
  138.     gc.SetPenStyle(CGraphicsContext::ESolidPen);
  139.     gc.UseFont(AknLayoutUtils::FontFromId(EAknLogicalFontPrimaryFont));
  140.     // Get pointer to the high scores
  141.     RArray<THighScore>* array = iModel.HighScoreArray();
  142.     TInt index = array->Count();
  143.     if (index > 0)
  144.         {
  145.         // they are held in increasing order, so list last first
  146.         index--;
  147.         TInt linePos = firstLine;
  148.         while (index >= 0)
  149.             {
  150.             THighScore highScore = (*array)[index];
  151.             TBuf<10> numText;
  152.             numText.NumFixedWidth(highScore.iScore,EDecimal, 6);
  153.             TPoint numTextPos(numXPos, linePos);
  154.             gc.DrawText(numText, numTextPos);
  155.             TPoint nameTextPos(nameXPos, linePos);
  156.             gc.DrawText(highScore.iName, nameTextPos);
  157.             linePos += lineSpace;
  158.             index--;
  159.             }
  160.         
  161.         }
  162.     else
  163.         {
  164.         _LIT(KNoHighscoresText,"No High Scores");
  165.         gc.DrawText(KNoHighscoresText, TPoint(nameXPos,firstLine + lineSpace));
  166.         }
  167.     gc.DiscardFont();
  168.     }
  169. // End of File