Wt examples  3.7.1
ImagesWidget.C
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011 Emweb bv, Herent, Belgium
3  *
4  * See the LICENSE file for terms of use.
5  */
6 
7 #include "ImagesWidget.h"
8 
9 #include <Wt/WImage>
10 
11 using namespace Wt;
12 
13 const int ImagesWidget::HURRAY = -1;
14 
16  : WContainerWidget(parent)
17 {
18  for (int i = 0; i <= maxGuesses; ++i) {
19  std::string fname = "icons/hangman";
20  fname += boost::lexical_cast<std::string>(i) + ".jpg";
21  WImage *theImage = new WImage(fname, this);
22  images_.push_back(theImage);
23 
24  // Although not necessary, we can avoid flicker (on konqueror)
25  // by presetting the image size.
26  theImage->resize(256, 256);
27  theImage->hide();
28  }
29 
30  WImage *hurray = new WImage("icons/hangmanhurray.jpg", this);
31  hurray->hide();
32  images_.push_back(hurray);
33 
34  image_ = 0;
35  showImage(maxGuesses);
36 }
37 
38 void ImagesWidget::showImage(int index)
39 {
40  image(image_)->hide();
41  image_ = index;
42  image(image_)->show();
43 }
44 
45 WImage *ImagesWidget::image(int index) const
46 {
47  return index == HURRAY ? images_.back() : images_[index];
48 }
void showImage(int index)
Definition: ImagesWidget.C:38
std::vector< Wt::WImage * > images_
Definition: ImagesWidget.h:30
static const int HURRAY
Definition: ImagesWidget.h:18
Wt::WImage * image(int index) const
Definition: ImagesWidget.C:45
ImagesWidget(int maxGuesses, Wt::WContainerWidget *parent=0)
Definition: ImagesWidget.C:15

Generated on Tue Dec 15 2020 for the C++ Web Toolkit (Wt) by doxygen 1.8.13