Wt examples 3.1.10
|
A Matrix character that takes red and/or blue pills. More...
#include <Character.h>
Public Member Functions | |
Character (const std::string &name, WContainerWidget *parent=0) | |
Create a new character with the given name. | |
void | dropEvent (WDropEvent event) |
React to a drop event. | |
Private Attributes | |
std::string | name_ |
The name. | |
int | redDrops_ |
The current number of red pills. | |
int | blueDrops_ |
The current number of blue pills. |
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.
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.
: WText(parent), name_(name), redDrops_(0), blueDrops_(0) { setText(name_ + " got no pills"); setStyleClass("character"); /* * Accept drops, and indicate this with a change in CSS style class. */ acceptDrops("red-pill", "red-drop-site"); acceptDrops("blue-pill", "blue-drop-site"); setInline(false); }
void Character::dropEvent | ( | WDropEvent | event | ) | [virtual] |
React to a drop event.
Reimplemented from Wt::WWidget.
Definition at line 25 of file Character.C.
{ if (event.mimeType() == "red-pill") ++redDrops_; if (event.mimeType() == "blue-pill") ++blueDrops_; std::string text = name_ + " got "; if (redDrops_ != 0) text += boost::lexical_cast<std::string>(redDrops_) + " red pill"; if (redDrops_ > 1) text += "s"; if (redDrops_ != 0 && blueDrops_ != 0) text += " and "; if (blueDrops_ != 0) text += boost::lexical_cast<std::string>(blueDrops_) + " blue pill"; if (blueDrops_ > 1) text += "s"; setText(text); }
int Character::blueDrops_ [private] |
The current number of blue pills.
Definition at line 43 of file Character.h.
std::string Character::name_ [private] |
The name.
Definition at line 37 of file Character.h.
int Character::redDrops_ [private] |
The current number of red pills.
Definition at line 40 of file Character.h.