Wt examples  3.3.6
Public Member Functions | Private Attributes | List of all members
Character Class Reference

A Matrix character that takes red and/or blue pills. More...

#include <Character.h>

Inheritance diagram for Character:
Inheritance graph
[legend]

Public Member Functions

 Character (const std::string &name, WContainerWidget *parent=0)
 Create a new character with the given name. More...
 
void dropEvent (WDropEvent event)
 React to a drop event. More...
 

Private Attributes

std::string name_
 The name. More...
 
int redDrops_
 The current number of red pills. More...
 
int blueDrops_
 The current number of blue pills. More...
 

Detailed Description

A Matrix character that takes red and/or blue pills.

The Character class demonstrates how to accept and react to drop events.

Definition at line 24 of file Character.h.

Constructor & Destructor Documentation

§ Character()

Character::Character ( const std::string &  name,
WContainerWidget *  parent = 0 
)

Create a new character with the given name.

Definition at line 6 of file Character.C.

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 }
std::string name_
The name.
Definition: Character.h:37
int redDrops_
The current number of red pills.
Definition: Character.h:40
int blueDrops_
The current number of blue pills.
Definition: Character.h:43

Member Function Documentation

§ dropEvent()

void Character::dropEvent ( WDropEvent  event)

React to a drop event.

Definition at line 25 of file Character.C.

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 }
std::string name_
The name.
Definition: Character.h:37
int redDrops_
The current number of red pills.
Definition: Character.h:40
int blueDrops_
The current number of blue pills.
Definition: Character.h:43

Member Data Documentation

§ blueDrops_

int Character::blueDrops_
private

The current number of blue pills.

Definition at line 43 of file Character.h.

§ name_

std::string Character::name_
private

The name.

Definition at line 37 of file Character.h.

§ redDrops_

int Character::redDrops_
private

The current number of red pills.

Definition at line 40 of file Character.h.


The documentation for this class was generated from the following files:

Generated on Thu Jan 12 2017 for the C++ Web Toolkit (Wt) by doxygen 1.8.12