WeaponMenuItem Class Reference

#include <weapon_menu.h>

Collaboration diagram for WeaponMenuItem:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 WeaponMenuItem (uint num_sort)
void Reset ()
void Draw ()
void ChangeZoom ()
bool MouseOn (const Point2i &mousePos)

Public Attributes

Point2i position
double scale
Weaponweapon
Spriteweapon_icon
uint zoom_start_time
uint weapon_type

Private Member Functions

void ComputeScale ()

Private Attributes

bool zoom
bool dezoom

Detailed Description

Definition at line 32 of file weapon_menu.h.


Constructor & Destructor Documentation

WeaponMenuItem::WeaponMenuItem ( uint  num_sort  ) 

Definition at line 68 of file weapon_menu.cpp.

00069 {
00070   zoom_start_time = 0;
00071   weapon_type = num_sort;
00072   Reset();
00073 }

Here is the call graph for this function:


Member Function Documentation

void WeaponMenuItem::ChangeZoom (  ) 

Definition at line 82 of file weapon_menu.cpp.

00083 {
00084   zoom_start_time = Time::GetInstance()->Read();
00085 
00086   if(!zoom && scale < 1)
00087     {
00088       zoom = true;
00089       dezoom = false;
00090     }
00091   else
00092     {
00093       zoom = false;
00094       dezoom = true;
00095     }
00096 }

Here is the call graph for this function:

void WeaponMenuItem::ComputeScale (  )  [private]

Definition at line 98 of file weapon_menu.cpp.

00099 {
00100   double scale_range, time_range;
00101 
00102   time_range = ((double)Time::GetInstance()->Read() - zoom_start_time) / ICON_ZOOM_TIME;
00103   if (time_range > 1)
00104     time_range = 1;
00105 
00106   scale_range = sin (time_range * M_PI / 2) * (MAX_ICON_SCALE - DEFAULT_ICON_SCALE);
00107 
00108   if(zoom)
00109   {
00110     scale = DEFAULT_ICON_SCALE + scale_range ;
00111 
00112     if(time_range == 1)
00113       zoom = false;
00114   }
00115   else
00116     if(dezoom)
00117       {
00118         scale = MAX_ICON_SCALE - scale_range ;
00119 
00120         if(time_range == 1)
00121           dezoom = false;
00122       }
00123 }

Here is the call graph for this function:

Here is the caller graph for this function:

void WeaponMenuItem::Draw (  ) 

Definition at line 143 of file weapon_menu.cpp.

00144 {
00145   Interface * interface = Interface::GetInstance();
00146 
00147   ComputeScale();
00148   Point2i buttonCenter(interface->weapons_menu.GetPosition() + position);
00149   Point2i buttonSize( (int)(BUTTON_ICO_WIDTH * scale), (int)(BUTTON_ICO_HEIGHT * scale) );
00150   Point2i iconSize( (int)(WEAPON_ICO_WIDTH * scale), (int)(WEAPON_ICO_HEIGHT * scale) );
00151   std::ostringstream txt;
00152   int nb_bullets;
00153 
00154   Sprite *button;
00155 
00156   switch(weapon_type){
00157     case 1:
00158       button = interface->weapons_menu.my_button1;
00159       break ;
00160 
00161     case 2:
00162       button = interface->weapons_menu.my_button2;
00163       break ;
00164 
00165     case 3:
00166       button = interface->weapons_menu.my_button3;
00167       break ;
00168 
00169     case 4:
00170       button = interface->weapons_menu.my_button4;
00171       break ;
00172 
00173     case 5:
00174       button = interface->weapons_menu.my_button5;
00175       break ;
00176 
00177   default:
00178       button = interface->weapons_menu.my_button1;
00179       break ;
00180   }
00181 
00182   // Button display
00183   button->Scale(scale, scale);
00184   button->Blit(AppWormux::GetInstance()->video.window, buttonCenter - buttonSize/2);
00185 
00186   // Weapon display
00187   weapon_icon->Scale(scale, scale);
00188   weapon_icon->Blit(AppWormux::GetInstance()->video.window, buttonCenter - iconSize/2);
00189 
00190   // Amunitions display
00191   nb_bullets = ActiveTeam().ReadNbAmmos(weapon->GetName());
00192   txt.str ("");
00193   if (nb_bullets ==  INFINITE_AMMO)
00194     txt << ("§");
00195   else
00196     txt << nb_bullets;
00197 
00198   (*Font::GetInstance(Font::FONT_TINY)).WriteLeftBottom(buttonCenter + Point2i(-1, 1) * iconSize / 2,
00199                             txt.str(), white_color);
00200 }

Here is the call graph for this function:

bool WeaponMenuItem::MouseOn ( const Point2i mousePos  ) 

Definition at line 125 of file weapon_menu.cpp.

00126 {
00127   ComputeScale();
00128 
00129   Point2i scaled( (int)(BUTTON_ICO_WIDTH * scale), (int)(BUTTON_ICO_HEIGHT * scale) );
00130   Rectanglei rect(Interface::GetInstance()->weapons_menu.GetPosition() - scaled/2 + position, scaled );
00131 
00132   if( rect.Contains(mousePos) )
00133      return true;
00134   else
00135     {
00136       if(scale > DEFAULT_ICON_SCALE && !dezoom)
00137         dezoom = true;
00138       return false;
00139     }
00140 }

Here is the call graph for this function:

void WeaponMenuItem::Reset (  ) 

Definition at line 75 of file weapon_menu.cpp.

00076 {
00077   scale = DEFAULT_ICON_SCALE;
00078   zoom = false;
00079   dezoom = false;
00080 }

Here is the caller graph for this function:


Member Data Documentation

bool WeaponMenuItem::dezoom [private]

Definition at line 43 of file weapon_menu.h.

Point2i WeaponMenuItem::position

Definition at line 35 of file weapon_menu.h.

double WeaponMenuItem::scale

Definition at line 36 of file weapon_menu.h.

Weapon* WeaponMenuItem::weapon

Definition at line 37 of file weapon_menu.h.

Sprite* WeaponMenuItem::weapon_icon

Definition at line 38 of file weapon_menu.h.

uint WeaponMenuItem::weapon_type

Definition at line 40 of file weapon_menu.h.

bool WeaponMenuItem::zoom [private]

Definition at line 43 of file weapon_menu.h.

uint WeaponMenuItem::zoom_start_time

Definition at line 39 of file weapon_menu.h.


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