Wt examples 3.1.10
Public Member Functions | Private Attributes
HighScoresWidget Class Reference

#include <HighScoresWidget.h>

Inheritance diagram for HighScoresWidget:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 HighScoresWidget (const std::wstring &user, WContainerWidget *parent=0)
void update ()

Private Attributes

std::wstring User

Detailed Description

Definition at line 11 of file HighScoresWidget.h.


Constructor & Destructor Documentation

HighScoresWidget::HighScoresWidget ( const std::wstring &  user,
WContainerWidget parent = 0 
)

Definition at line 21 of file HighScoresWidget.C.

                                                            :
   WContainerWidget(parent),
   User(user)
{
   setContentAlignment(AlignCenter);
   setStyleClass("highscores");
}

Member Function Documentation

void HighScoresWidget::update ( )

Definition at line 30 of file HighScoresWidget.C.

{
   clear();

   WText *title = new WText("Hall of fame", this);
   title->decorationStyle().font().setSize(WFont::XLarge);
   title->setMargin(10, Top | Bottom);

   new WBreak(this);

   HangmanDb::Score s = HangmanDb::getUserPosition(User);

   std::string yourScore;
   if (s.number == 1)
     yourScore = "Congratulations! You are currently leading the pack.";
   else {
     yourScore = "You are currently ranked number "
       + boost::lexical_cast<std::string>(s.number)
       + ". Almost there !";
   }

   WText *score = new WText("<p>" + yourScore + "</p>", this);
   score->decorationStyle().font().setSize(WFont::Large);

   std::vector<HangmanDb::Score> top = HangmanDb::getHighScores(20);

   WTable *table = new WTable(this);
   new WText("Rank", table->elementAt(0, 0));
   new WText("User", table->elementAt(0, 1));
   new WText("Games", table->elementAt(0, 2));
   new WText("Score", table->elementAt(0, 3));
   new WText("Last game", table->elementAt(0, 4));
   for(unsigned int i = 0; i < top.size(); ++i) {
      new WText(boost::lexical_cast<string>(top[i].number),
                table->elementAt(i + 1, 0));
      new WText(top[i].user, table->elementAt(i + 1, 1));
      new WText(boost::lexical_cast<std::string>(top[i].numgames),
                table->elementAt(i+ 1, 2));
      new WText(boost::lexical_cast<std::string>(top[i].score),
                table->elementAt(i + 1, 3));
      new WText(top[i].lastseen, table->elementAt(i + 1, 4));
   }

   table->resize(WLength(60, WLength::FontEx), WLength::Auto);
   table->setMargin(20, Top | Bottom);
   table->decorationStyle().setBorder(WBorder(WBorder::Solid));

   /*
    * Apply cell styles
    */
   for (int row = 0; row < table->rowCount(); ++row) {
     for (int col = 0; col < table->columnCount(); ++col) {
       WTableCell *cell = table->elementAt(row, col);
       cell->setContentAlignment(AlignMiddle | AlignCenter);

       if (row == 0)
         cell->setStyleClass("highscoresheader");

       if (row == s.number)
         cell->setStyleClass("highscoresself");
     }
   }

   WText *fineprint
     = new WText("<p>For each game won, you gain 20 points, "
                 "minus one point for each wrong letter guess.<br />"
                 "For each game lost, you loose 10 points, so you "
                 "better try hard to guess the word!</p>", this);
   fineprint->decorationStyle().font().setSize(WFont::Smaller);
}

Member Data Documentation

std::wstring HighScoresWidget::User [private]

Definition at line 19 of file HighScoresWidget.h.


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

Generated on Wed Jul 27 2011 for the C++ Web Toolkit (Wt) by doxygen 1.7.4