ImagesWidget.C 1.1 KB

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