Menu Class Reference

#include <menu.h>

Inheritance diagram for Menu:

Inheritance graph
[legend]
Collaboration diagram for Menu:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Menu (char *bg, t_action actions=vOkCancel)
virtual ~Menu ()
void Run ()
virtual void Redraw (const Rectanglei &rect, Surface &surf)

Public Attributes

WidgetList widgets
const t_action actions

Protected Member Functions

virtual void sig_ok ()
virtual void sig_cancel ()
virtual void DrawBackground (const Point2i &mousePosition)
virtual void key_ok ()
virtual void key_cancel ()
virtual void __sig_ok ()=0
virtual void __sig_cancel ()=0
virtual void Draw (const Point2i &mousePosition)=0
virtual void OnClic (const Point2i &mousePosition, int button)=0
void SetActionButtonsXY (int x, int y)
void Display (const Point2i &mousePosition)

Protected Attributes

Buttonb_cancel
Buttonb_ok
bool close_menu

Private Member Functions

bool BasicOnClic (const Point2i &mousePosition)

Private Attributes

Spritebackground
HBoxactions_buttons

Detailed Description

Definition at line 49 of file menu.h.


Constructor & Destructor Documentation

Menu::Menu ( char *  bg,
t_action  actions = vOkCancel 
)

Definition at line 29 of file menu.cpp.

00029                                        :
00030   actions(_actions)
00031 {
00032   close_menu = false ;
00033   AppWormux * app = AppWormux::GetInstance();
00034 
00035   uint x = app->video.window.GetWidth() / 2;
00036   uint y = app->video.window.GetHeight() - 50;
00037 
00038   Profile *res = resource_manager.LoadXMLProfile( "graphism.xml", false);
00039   background = new Sprite( resource_manager.LoadImage( res, bg));
00040   background->cache.EnableLastFrameCache();
00041 
00042   b_ok = NULL;
00043   b_cancel = NULL;
00044   if (actions == vNo) {
00045     actions_buttons = NULL;    
00046   } else {
00047 
00048     actions_buttons = new HBox( Rectanglei(x, y, 1, 40), false);
00049 
00050     if (actions == vOk || actions == vOkCancel) {
00051       b_ok = new Button( Point2i(0, 0), res, "menu/valider"); 
00052       actions_buttons->AddWidget(b_ok);
00053     }
00054 
00055     if (actions == vCancel  || actions == vOkCancel) {
00056       b_cancel = new Button( Point2i(0, 0), res, "menu/annuler");
00057       actions_buttons->AddWidget(b_cancel);
00058     }
00059 
00060     widgets.AddWidget(actions_buttons);
00061   }
00062 
00063   widgets.SetContainer(this);
00064   resource_manager.UnLoadXMLProfile(res);
00065 }

Here is the call graph for this function:

Menu::~Menu (  )  [virtual]

Definition at line 67 of file menu.cpp.

00068 {
00069   delete background;
00070 }


Member Function Documentation

virtual void Menu::__sig_cancel (  )  [protected, pure virtual]

Implemented in CreditsMenu, GameMenu, InternetMenu, Main_Menu, NetworkConnectionMenu, NetworkMenu, OptionMenu, and ResultsMenu.

Here is the caller graph for this function:

virtual void Menu::__sig_ok (  )  [protected, pure virtual]

Implemented in CreditsMenu, GameMenu, InternetMenu, Main_Menu, NetworkConnectionMenu, NetworkMenu, OptionMenu, and ResultsMenu.

Here is the caller graph for this function:

bool Menu::BasicOnClic ( const Point2i mousePosition  )  [private]

Definition at line 86 of file menu.cpp.

00087 {
00088   if( b_ok != NULL &&  b_ok->Contains(mousePosition) )
00089     sig_ok();
00090   else if( b_cancel != NULL && b_cancel->Contains(mousePosition) )
00091     sig_cancel();
00092   else
00093     return false;
00094   
00095   return true;
00096 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Menu::Display ( const Point2i mousePosition  )  [protected]

Definition at line 168 of file menu.cpp.

00169 {
00170   // to limit CPU  
00171   uint sleep_fps=0;
00172   uint delay = 0;
00173   uint start = SDL_GetTicks();
00174 
00175   widgets.Update(mousePosition, AppWormux::GetInstance()->video.window);
00176   Draw(mousePosition);
00177   AppWormux::GetInstance()->video.Flip();
00178 
00179   // to limit CPU
00180   delay = SDL_GetTicks()-start;   
00181   if (delay < 200)
00182     sleep_fps = 200 - delay;
00183   else
00184     sleep_fps = 0;
00185   SDL_Delay(sleep_fps);
00186 }

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void Menu::Draw ( const Point2i mousePosition  )  [protected, pure virtual]

Implemented in CreditsMenu, GameMenu, InternetMenu, Main_Menu, NetworkConnectionMenu, NetworkMenu, OptionMenu, and ResultsMenu.

Here is the caller graph for this function:

void Menu::DrawBackground ( const Point2i mousePosition  )  [protected, virtual]

Reimplemented in Main_Menu.

Definition at line 98 of file menu.cpp.

00099 {
00100   background->ScaleSize(AppWormux::GetInstance()->video.window.GetSize());
00101   background->Blit(AppWormux::GetInstance()->video.window, 0, 0);
00102 }

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void Menu::key_cancel (  )  [inline, protected, virtual]

Reimplemented in Main_Menu.

Definition at line 79 of file menu.h.

00079 {};

Here is the caller graph for this function:

virtual void Menu::key_ok (  )  [inline, protected, virtual]

Reimplemented in Main_Menu.

Definition at line 78 of file menu.h.

00078 {};

Here is the caller graph for this function:

virtual void Menu::OnClic ( const Point2i mousePosition,
int  button 
) [protected, pure virtual]

Implemented in CreditsMenu, GameMenu, InternetMenu, Main_Menu, NetworkConnectionMenu, NetworkMenu, OptionMenu, and ResultsMenu.

Here is the caller graph for this function:

void Menu::Redraw ( const Rectanglei rect,
Surface surf 
) [virtual]

Implements Container.

Reimplemented in Main_Menu.

Definition at line 104 of file menu.cpp.

00105 {
00106   background->Blit(surf, rect, rect.GetPosition());
00107 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Menu::Run (  ) 

Reimplemented in Main_Menu.

Definition at line 109 of file menu.cpp.

00110 { 
00111   int x=0, y=0;
00112 
00113   close_menu = false;
00114 
00115   // Display the background
00116   DrawBackground(Point2i(0,0));
00117 
00118   do
00119   {
00120     // Poll and treat events
00121     SDL_Event event;
00122      
00123     while( SDL_PollEvent( &event) )
00124     {
00125       Point2i mousePosition(event.button.x, event.button.y);
00126            
00127       if( event.type == SDL_QUIT )
00128         sig_cancel();
00129       else if( event.type == SDL_KEYDOWN )
00130         switch( event.key.keysym.sym)
00131         {
00132         case SDLK_ESCAPE:
00133           if(b_cancel != NULL)
00134             sig_cancel();
00135           else
00136             key_cancel();
00137           break;
00138         case SDLK_RETURN:
00139           if(b_ok != NULL)
00140             sig_ok();
00141           else
00142             key_ok();
00143           break;
00144         case SDLK_F10:
00145           AppWormux::GetInstance()->video.ToggleFullscreen();
00146           break;
00147         default:
00148           widgets.SendKey(event.key.keysym);
00149           break;
00150         }
00151       else if( event.type == SDL_MOUSEBUTTONUP)
00152       if( !BasicOnClic(mousePosition) )
00153         OnClic(mousePosition, event.button.button);
00154     }
00155 
00156     // Avoid to calculate redraw menu when comming back for closing.
00157     if (!close_menu) {
00158 
00159       SDL_GetMouseState( &x, &y );
00160       Point2i mousePosition(x, y);
00161       
00162       Display(mousePosition);
00163     }
00164 
00165   } while (!close_menu);
00166 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Menu::SetActionButtonsXY ( int  x,
int  y 
) [protected]

Definition at line 188 of file menu.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void Menu::sig_cancel (  )  [protected, virtual]

Definition at line 79 of file menu.cpp.

00080 {
00081   jukebox.Play("share", "menu/cancel");
00082   __sig_cancel();
00083   close_menu = true;
00084 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Menu::sig_ok (  )  [protected, virtual]

Reimplemented in NetworkConnectionMenu, and NetworkMenu.

Definition at line 72 of file menu.cpp.

00073 {
00074   jukebox.Play("share", "menu/ok");
00075   __sig_ok();
00076   close_menu = true;
00077 }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

const t_action Menu::actions

Definition at line 53 of file menu.h.

HBox* Menu::actions_buttons [private]

Definition at line 65 of file menu.h.

Button* Menu::b_cancel [protected]

Definition at line 70 of file menu.h.

Button* Menu::b_ok [protected]

Definition at line 71 of file menu.h.

Sprite* Menu::background [private]

Definition at line 62 of file menu.h.

bool Menu::close_menu [protected]

Definition at line 72 of file menu.h.

WidgetList Menu::widgets

Definition at line 52 of file menu.h.


The documentation for this class was generated from the following files:
Generated on Mon Jan 1 13:59:24 2007 for Wormux by  doxygen 1.4.7