Character Class Reference
[Drag and Drop example]

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

#include <Character.h>

Inheritance diagram for Character:

Inheritance graph
[legend]

List of all members.

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.


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 ( const std::string &  name,
WContainerWidget parent = 0 
)

Create a new character with the given name.

Definition at line 6 of file Character.C.

00007   : WText(parent),
00008     name_(name),
00009     redDrops_(0),
00010     blueDrops_(0)
00011 {
00012   setText(name_ + " got no pills");
00013 
00014   setStyleClass("character");
00015 
00016   /*
00017    * Accept drops, and indicate this with a change in CSS style class.
00018    */
00019   acceptDrops("red-pill", "red-drop-site");
00020   acceptDrops("blue-pill", "blue-drop-site");
00021 
00022   setInline(false);
00023 }


Member Function Documentation

void Character::dropEvent ( WDropEvent  event  )  [virtual]

React to a drop event.

Reimplemented from Wt::WWidget.

Definition at line 25 of file Character.C.

00026 {
00027   if (event.mimeType() == "red-pill")
00028     ++redDrops_;
00029   if (event.mimeType() == "blue-pill")
00030     ++blueDrops_;
00031 
00032   std::string text = name_ + " got ";
00033 
00034   if (redDrops_ != 0)
00035     text += boost::lexical_cast<std::string>(redDrops_) + " red pill";
00036   if (redDrops_ > 1)
00037     text += "s";
00038 
00039   if (redDrops_ != 0 && blueDrops_ != 0)
00040     text += " and ";
00041 
00042   if (blueDrops_ != 0)
00043     text += boost::lexical_cast<std::string>(blueDrops_) + " blue pill";
00044   if (blueDrops_ > 1)
00045     text += "s";
00046 
00047   setText(text);
00048 }


Member Data Documentation

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.

int Character::blueDrops_ [private]

The current number of blue pills.

Definition at line 43 of file Character.h.


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

Generated on Mon Jan 26 14:14:20 2009 for Wt by doxygen 1.5.6