Question Class Reference

#include <question.h>

Collaboration diagram for Question:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Question ()
 ~Question ()
void Set (const std::string &message, bool default_active, int default_value, const std::string &bg_sprite="")
int Ask ()
void Draw () const
void add_choice (int key, int value)

Private Types

typedef std::list< choice_t
>::iterator 
choice_iterator

Private Member Functions

int TreatsKey (SDL_Event &event)

Private Attributes

Spritebackground
std::list< choice_tchoices
Question::s_default_choice default_choice
std::string message

Classes

class  choice_t
struct  s_default_choice

Detailed Description

Definition at line 34 of file question.h.


Member Typedef Documentation

typedef std::list<choice_t>::iterator Question::choice_iterator [private]

Definition at line 53 of file question.h.


Constructor & Destructor Documentation

Question::Question (  ) 

Definition at line 33 of file question.cpp.

00034 {
00035   background = NULL;
00036 }

Question::~Question (  ) 

Definition at line 38 of file question.cpp.

00039 {
00040   if(background != NULL)
00041     delete background;
00042 }


Member Function Documentation

void Question::add_choice ( int  key,
int  value 
) [inline]

Definition at line 76 of file question.h.

00077   {
00078     return this->choices.push_back(choice_t(key,value));
00079   }

Here is the caller graph for this function:

int Question::Ask (  ) 

Definition at line 77 of file question.cpp.

00077                    {
00078   SDL_Event event;
00079 
00080   int answer = default_choice.value;
00081   bool end_of_boucle = false;
00082 
00083   Draw();
00084   Mouse::pointer_t prev_pointer = Mouse::GetInstance()->SetPointer(Mouse::POINTER_STANDARD);
00085   do{
00086     while( SDL_PollEvent( &event) ){
00087       if ( (event.type == SDL_QUIT || event.type == SDL_MOUSEBUTTONDOWN) &&
00088           default_choice.active ){
00089         answer = default_choice.value;
00090         end_of_boucle = true;
00091       }
00092 
00093       if (event.type == SDL_KEYUP) {
00094         answer = TreatsKey(event);
00095         if (answer != -1) 
00096           end_of_boucle = true;
00097       }
00098     } // SDL_PollEvent
00099 
00100     AppWormux::GetInstance()->video.Flip();
00101   } while (!end_of_boucle);
00102 
00103   Mouse::GetInstance()->SetPointer(prev_pointer);
00104 
00105   return answer;
00106 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Question::Draw (  )  const

Definition at line 62 of file question.cpp.

00062                          {
00063   AppWormux * app = AppWormux::GetInstance();
00064 
00065   if(background != NULL)
00066   {
00067     background->Blit(app->video.window,  app->video.window.GetSize() / 2 - background->GetSize() / 2);
00068   }
00069   if(message != "")
00070   {
00071     DrawTmpBoxTextWithReturns (*Font::GetInstance(Font::FONT_BIG),
00072                                app->video.window.GetSize() / 2,
00073                                message, 10);
00074   }
00075 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Question::Set ( const std::string &  message,
bool  default_active,
int  default_value,
const std::string &  bg_sprite = "" 
)

Definition at line 108 of file question.cpp.

00109                                                                                       {
00110   message = pmessage;
00111   default_choice.active = default_active;
00112   default_choice.value = default_value;
00113 
00114   if(background != NULL)
00115   {
00116     delete background;
00117     background = NULL;
00118   }
00119 
00120   if(bg_sprite != "")
00121   {
00122     Profile *res = resource_manager.LoadXMLProfile( "graphism.xml", false);
00123     background = new Sprite(resource_manager.LoadImage(res,bg_sprite));
00124     background->cache.EnableLastFrameCache();
00125     background->ScaleSize(AppWormux::GetInstance()->video.window.GetSize());
00126     resource_manager.UnLoadXMLProfile( res);
00127   }
00128 }

Here is the call graph for this function:

Here is the caller graph for this function:

int Question::TreatsKey ( SDL_Event &  event  )  [private]

Definition at line 44 of file question.cpp.

00044                                         {
00045 
00046   // Tests the key
00047   choice_iterator it=choices.begin(), end=choices.end();
00048   for (; it != end; ++it){
00049     if (event.key.keysym.sym == it -> key()) {
00050       return it -> val();
00051     }
00052   }
00053 
00054   // No key corresponding to the correct choice, so we use default choice
00055   if (default_choice.active) {
00056     return default_choice.value;
00057   }
00058 
00059   return -1;
00060 }

Here is the caller graph for this function:


Member Data Documentation

Sprite* Question::background [private]

Definition at line 36 of file question.h.

std::list<choice_t> Question::choices [private]

Definition at line 52 of file question.h.

struct Question::s_default_choice Question::default_choice [private]

std::string Question::message [private]

Definition at line 63 of file question.h.


The documentation for this class was generated from the following files:
Generated on Mon Jan 1 14:12:11 2007 for Wormux by  doxygen 1.4.7