Wt examples  3.2.2
/home/koen/project/wt/public-git/wt/examples/hangman/ImagesWidget.C
Go to the documentation of this file.
00001 /* 
00002  * Copyright (C) 2011 Emweb bvba, Heverlee, Belgium
00003  *
00004  * See the LICENSE file for terms of use.
00005  */
00006 
00007 #include "ImagesWidget.h"
00008 
00009 #include <Wt/WImage>
00010 
00011 using namespace Wt;
00012 
00013 const int ImagesWidget::HURRAY = -1;
00014 
00015 ImagesWidget::ImagesWidget(int maxGuesses, WContainerWidget *parent)
00016   : WContainerWidget(parent)
00017 {
00018   for (int i = 0; i <= maxGuesses; ++i) {
00019     std::string fname = "icons/hangman";
00020     fname += boost::lexical_cast<std::string>(i) + ".jpg";
00021     WImage *theImage = new WImage(fname, this);
00022     images_.push_back(theImage);
00023 
00024     // Although not necessary, we can avoid flicker (on konqueror)
00025     // by presetting the image size.
00026     theImage->resize(256, 256);
00027     theImage->hide();
00028   }
00029 
00030   WImage *hurray = new WImage("icons/hangmanhurray.jpg", this);
00031   hurray->hide();
00032   images_.push_back(hurray);
00033 
00034   image_ = 0;
00035   showImage(maxGuesses);
00036 }
00037 
00038 void ImagesWidget::showImage(int index)
00039 {
00040   image(image_)->hide();
00041   image_ = index;
00042   image(image_)->show();
00043 }
00044 
00045 WImage *ImagesWidget::image(int index) const
00046 {
00047   return index == HURRAY ? images_.back() : images_[index];
00048 }

Generated on Fri Jul 27 2012 for the C++ Web Toolkit (Wt) by doxygen 1.7.5.1