Wt examples
4.3.0
builddir
build
BUILD
wt-4.3.0
examples
hangman
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.h>
10
#include <Wt/WAny.h>
11
12
const
int
ImagesWidget::HURRAY
= -1;
13
14
ImagesWidget::ImagesWidget
(
int
maxGuesses)
15
{
16
for
(
int
i = 0; i <= maxGuesses; ++i) {
17
std::string fname =
"icons/hangman"
;
18
fname += std::to_string(i) +
".jpg"
;
19
WImage
*theImage =
addWidget
(cpp14::make_unique<WImage>(fname));
20
images_
.push_back(theImage);
21
22
// Although not necessary, we can avoid flicker (on konqueror)
23
// by presetting the image size.
24
theImage->
resize
(256, 256);
25
theImage->
hide
();
26
}
27
28
WImage
*hurray =
addWidget
(cpp14::make_unique<WImage>(
"icons/hangmanhurray.jpg"
));
29
hurray->
hide
();
30
images_
.push_back(hurray);
31
32
image_
= 0;
33
showImage
(maxGuesses);
34
}
35
36
void
ImagesWidget::showImage
(
int
index)
37
{
38
image
(
image_
)->
hide
();
39
image_
= index;
40
image
(
image_
)->
show
();
41
}
42
43
WImage
*
ImagesWidget::image
(
int
index)
const
44
{
45
return
index ==
HURRAY
?
images_
.back() :
images_
[index];
46
}
ImagesWidget::image
WImage * image(int index) const
Definition:
ImagesWidget.C:43
Wt::WWidget::hide
void hide()
Wt::WWebWidget::resize
virtual void resize(const WLength &width, const WLength &height) override
Wt::WWidget::show
void show()
ImagesWidget::image_
int image_
Definition:
ImagesWidget.h:33
ImagesWidget.h
Wt::WImage
Wt::WContainerWidget::addWidget
virtual void addWidget(std::unique_ptr< WWidget > widget)
ImagesWidget::images_
std::vector< WImage * > images_
Definition:
ImagesWidget.h:32
ImagesWidget::HURRAY
static const int HURRAY
Definition:
ImagesWidget.h:20
ImagesWidget::showImage
void showImage(int index)
Definition:
ImagesWidget.C:36
ImagesWidget::ImagesWidget
ImagesWidget(int maxGuesses)
Definition:
ImagesWidget.C:14
Generated on Thu Mar 26 2020 for
the C++ Web Toolkit (Wt)
by
1.8.17