Wt examples
3.7.1
public-git
wt
examples
dragdrop
Character.C
Go to the documentation of this file.
1
#include <iostream>
2
#include <boost/lexical_cast.hpp>
3
4
#include "
Character.h
"
5
6
Character::Character
(
const
std::string& name,
WContainerWidget
*
parent
)
7
:
WText
(parent),
8
name_(name),
9
redDrops_(0),
10
blueDrops_(0)
11
{
12
setText
(
name_
+
" got no pills"
);
13
14
setStyleClass
(
"character"
);
15
16
/*
17
* Accept drops, and indicate this with a change in CSS style class.
18
*/
19
acceptDrops
(
"red-pill"
,
"red-drop-site"
);
20
acceptDrops
(
"blue-pill"
,
"blue-drop-site"
);
21
22
setInline
(
false
);
23
}
24
25
void
Character::dropEvent
(
WDropEvent
event)
26
{
27
if
(event.
mimeType
() ==
"red-pill"
)
28
++
redDrops_
;
29
if
(event.
mimeType
() ==
"blue-pill"
)
30
++
blueDrops_
;
31
32
std::string
text
=
name_
+
" got "
;
33
34
if
(
redDrops_
!= 0)
35
text += boost::lexical_cast<std::string>(
redDrops_
) +
" red pill"
;
36
if
(
redDrops_
> 1)
37
text +=
"s"
;
38
39
if
(
redDrops_
!= 0 &&
blueDrops_
!= 0)
40
text +=
" and "
;
41
42
if
(
blueDrops_
!= 0)
43
text += boost::lexical_cast<std::string>(
blueDrops_
) +
" blue pill"
;
44
if
(
blueDrops_
> 1)
45
text +=
"s"
;
46
47
setText
(text);
48
}
Wt::WWebWidget::setStyleClass
virtual void setStyleClass(const WString &styleClass) override
Character::dropEvent
void dropEvent(WDropEvent event)
React to a drop event.
Definition:
Character.C:25
Wt::WText
Character::name_
std::string name_
The name.
Definition:
Character.h:37
Wt::WText::setText
bool setText(const WString &text)
Character::redDrops_
int redDrops_
The current number of red pills.
Definition:
Character.h:40
Character::Character
Character(const std::string &name, WContainerWidget *parent=0)
Create a new character with the given name.
Definition:
Character.C:6
Character.h
Wt::WWidget::parent
WWidget * parent() const
Wt::WDropEvent::mimeType
const std::string & mimeType() const
Wt::WContainerWidget
Wt::WDropEvent
Character::blueDrops_
int blueDrops_
The current number of blue pills.
Definition:
Character.h:43
Wt::WWidget::acceptDrops
virtual void acceptDrops(const std::string &mimeType, const WString &hoverStyleClass=WString())
Wt::WWebWidget::setInline
virtual void setInline(bool isInline) override
Wt::WText::text
const WString & text() const
Generated on Tue Dec 15 2020 for
the C++ Web Toolkit (Wt)
by
1.8.13