/home/koen/project/wt/cvs/wt/examples/dragdrop/Character.C

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <boost/lexical_cast.hpp>
00003 
00004 #include "Character.h"
00005 
00006 Character::Character(const std::wstring name, WContainerWidget *parent)
00007   : WText(parent),
00008     name_(name),
00009     redDrops_(0),
00010     blueDrops_(0)
00011 {
00012   setText(name_ + L" 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 }
00024 
00025 void Character::dropEvent(WDropEvent event)
00026 {
00027   if (event.mimeType() == "red-pill")
00028     ++redDrops_;
00029   if (event.mimeType() == "blue-pill")
00030     ++blueDrops_;
00031 
00032   std::wstring text = name_ + L" got ";
00033 
00034   if (redDrops_ != 0)
00035     text += boost::lexical_cast<std::wstring>(redDrops_) + L" red pill";
00036   if (redDrops_ > 1)
00037     text += L"s";
00038 
00039   if (redDrops_ != 0 && blueDrops_ != 0)
00040     text += L" and ";
00041 
00042   if (blueDrops_ != 0)
00043     text += boost::lexical_cast<std::wstring>(blueDrops_) + L" blue pill";
00044   if (blueDrops_ > 1)
00045     text += L"s";
00046 
00047   setText(text);
00048 }

Generated on Fri Jul 25 17:05:59 2008 for Wt by doxygen 1.5.3