Back to index

extremetuxracer  0.5beta
Classes | Public Member Functions | Private Member Functions | Private Attributes
HUD Class Reference

#include <hud.h>

Collaboration diagram for HUD:
Collaboration graph
[legend]

List of all members.

Classes

struct  Element

Public Member Functions

 HUD (void)
void draw (Player &plyr)
void reset (void)
bool add (Element newElement)
bool update (const int i, Element newElement)

Private Member Functions

void text (const int i)
void fps (const int i)
void herring (const int i, const int herring_count)
void image (const int i)
void time (const int i)
void speed (const int i, const double speed)
void gauge (const int i, const double speed, const double energy)
void bar (const int i, double percentage)
void coursePercentage (const int i)
void objectives_time (const int i, bool outline_font)
void objectives_herring (const int i, bool outline_font)
void icon_time (const int i)
void icon_herring (const int i)
void draw_partial_tri_fan (const double fraction)
pp::Vec2d calc_new_fan_pt (const double angle)
void start_tri_fan (void)
void fix_xy (int &x, int &y, const int asc=0, const int width=0)
void initGauge ()

Private Attributes

Element m_element [HUD_MAX_ITEMS]
int m_numElements
GLuint m_energymaskTex
GLuint m_speedmaskTex
GLuint m_outlineTex

Detailed Description

Definition at line 29 of file hud.h.


Constructor & Destructor Documentation

HUD::HUD ( void  )

Definition at line 49 of file hud.cpp.


Member Function Documentation

bool HUD::add ( Element  newElement)

Definition at line 62 of file hud.cpp.

                          {
       if( m_numElements < HUD_MAX_ITEMS){
              m_element[m_numElements] = newElement;
              m_numElements++;
              return true;
       }else{
              return false;
       }      
}

Here is the caller graph for this function:

void HUD::bar ( const int  i,
double  percentage 
) [private]

Definition at line 282 of file hud.cpp.

{
       if(!m_element[i].texture) return;
       
       if(percentage>1)percentage=1;
       
       double temp_sin=sin(double(m_element[i].angle)/180.0*M_PI);
       double temp_cos=cos(double(m_element[i].angle)/180.0*M_PI);
       
    glBindTexture( GL_TEXTURE_2D, m_element[i].texture );

       fix_xy(m_element[i].x,m_element[i].y,int(m_element[i].height));
       
    glPushMatrix();
    {
       glTranslatef(m_element[i].x, m_element[i].y,0);

       glBegin( GL_QUADS );
       {
              glTexCoord2f(0,0);
           glVertex2f(0,0);

           glTexCoord2f(1,0);
           glVertex2f(temp_cos*m_element[i].width,temp_sin*m_element[i].width);

       glTexCoord2f(1,percentage);
       glVertex2f(temp_cos*m_element[i].width+temp_sin*m_element[i].height*percentage,
                     temp_sin*m_element[i].width-temp_cos*m_element[i].height*percentage);

       glTexCoord2f(0,percentage);
       glVertex2f(temp_sin*m_element[i].height*percentage, (-1)*temp_cos*m_element[i].height*percentage);

       }
       glEnd();
    }
    glPopMatrix();
       
}

Here is the call graph for this function:

Here is the caller graph for this function:

pp::Vec2d HUD::calc_new_fan_pt ( const double  angle) [private]

Definition at line 525 of file hud.cpp.

Here is the caller graph for this function:

void HUD::coursePercentage ( const int  i) [private]

Definition at line 562 of file hud.cpp.

{
       if ( !getparam_display_course_percentage() ) {
              return;
    }
       
       if(m_element[i].font){
              char string[BUFF_LEN];
              sprintf( string, m_element[i].string.c_str(), players[0].getCoursePercentage() );
              
              pp::Font::utf8ToUnicode(m_element[i].u_string,string);
              int width = int(m_element[i].font->advance(m_element[i].u_string));
              
              fix_xy(m_element[i].x,m_element[i].y,m_element[i].height,width);
              m_element[i].font->draw(m_element[i].u_string, m_element[i].x, m_element[i].y);            
              
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void HUD::draw ( Player plyr)

Definition at line 84 of file hud.cpp.

{
       UIMgr.setupDisplay();
       set_gl_options( TEXFONT );
       
       for(int i=0; i<m_numElements; i++){       
              switch(m_element[i].type){
                     case 0:
                            text(i);
                            break;
                     case 1:
                            fps(i);
                            break;
                     case 2:
                            herring(i,plyr.herring);
                            break;
                     case 3:
                            image(i);
                            break;
                     case 4:
                            time(i);
                            break; 
                     case 5:
                            {
                            pp::Vec3d vel = plyr.vel;
                     speed(i,vel.normalize()* M_PER_SEC_TO_KM_PER_H);
                            }
                            break;
                     case 6:
                            {
                            pp::Vec3d vel = plyr.vel;
                            gauge(i,vel.normalize()* M_PER_SEC_TO_KM_PER_H,plyr.control.jump_amt);
                            }
                            break;
                     case 7:
                            bar(i,plyr.control.jump_amt);
                            break;
                     case 8:
                            {
                            pp::Vec3d vel = plyr.vel;
                            bar(i,vel.normalize()* M_PER_SEC_TO_KM_PER_H/135);
                            }      
                            break;
                     case 9:
                            coursePercentage(i);
                            break;
                     case 10:
                            if ( getparam_display_course_percentage() ){            
                                   bar(i,players[0].getCoursePercentage()/100);
                            }
                            break;
            case 11:
                objectives_time(i,false);
                break;
            case 12:
                objectives_herring(i,false);
                break;
            case 13:
                objectives_time(i,true);
                break;
            case 14:
                objectives_herring(i,true);
                break;
           case 15:
              icon_time(i);
              break;
           case 16:
              icon_herring(i);
              break;
              }
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void HUD::draw_partial_tri_fan ( const double  fraction) [private]

Definition at line 476 of file hud.cpp.

{
    int divs;
    double angle, angle_incr, cur_angle;
    int i;
    bool trifan = false;
    pp::Vec2d pt;

    angle = SPEEDBAR_BASE_ANGLE + 
       ( SPEEDBAR_MAX_ANGLE - SPEEDBAR_BASE_ANGLE ) * fraction;

    divs = int(( SPEEDBAR_BASE_ANGLE - angle ) * CIRCLE_DIVISIONS / 360.0);

    cur_angle = SPEEDBAR_BASE_ANGLE;

    angle_incr = 360.0 / CIRCLE_DIVISIONS;

    for (i=0; i<divs; i++) {
       if ( !trifan ) {
           start_tri_fan();
           trifan = true;
       }

       cur_angle -= angle_incr;

       pt = calc_new_fan_pt( cur_angle );

       glVertex2f( pt.x, pt.y );
    }

    if ( cur_angle > angle + EPS ) {
       cur_angle = angle;
       if ( !trifan ) {
           start_tri_fan();
           trifan = true;
       }

       pt = calc_new_fan_pt( cur_angle );

       glVertex2f( pt.x, pt.y );
    }

    if ( trifan ) {
       glEnd();
       trifan = false;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void HUD::fix_xy ( int &  x,
int &  y,
const int  asc = 0,
const int  width = 0 
) [private]

Definition at line 551 of file hud.cpp.

{
       if(x<0){
              x=getparam_x_resolution()+x-width;
       }
       if(y<0){
              y=getparam_y_resolution()+y-asc;
       }
}

Here is the caller graph for this function:

void HUD::fps ( const int  i) [private]

Definition at line 170 of file hud.cpp.

{
       if ( ! getparam_display_fps() ) {
              return;
    }
       
    if(m_element[i].font){
              char string[BUFF_LEN];
              sprintf( string, m_element[i].string.c_str(), fpsCounter.get() );
              
              pp::Font::utf8ToUnicode(m_element[i].u_string,string);
              int width = int(m_element[i].font->advance(m_element[i].u_string));
              
              fix_xy(m_element[i].x,m_element[i].y,m_element[i].height,width);
              m_element[i].font->draw(m_element[i].u_string, m_element[i].x, m_element[i].y);            
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void HUD::gauge ( const int  i,
const double  speed,
const double  energy 
) [private]

Definition at line 367 of file hud.cpp.

{
       GLfloat xplane[4] = { 1.0/m_element[i].size, 0.0, 0.0, 0.0 };
    GLfloat yplane[4] = { 0.0, 1.0/m_element[i].size, 0.0, 0.0 };
    double y;
    double speedbar_frac;

       //the gauge bar needs it's own mode
       //we reset the mode at the end of the function
    set_gl_options( GAUGE_BARS );

    glTexGenfv( GL_S, GL_OBJECT_PLANE, xplane );
    glTexGenfv( GL_T, GL_OBJECT_PLANE, yplane );

    glPushMatrix();
    {
       glTranslatef( getparam_x_resolution() - m_element[i].width,
                    0,
                    0 );

       glColor4fv( energy_background_color );

       glBindTexture( GL_TEXTURE_2D, m_energymaskTex );

       y = ENERGY_GAUGE_BOTTOM + energy * m_element[i].height;

       glBegin( GL_QUADS );
       {
           glVertex2f( 0.0, y );
           glVertex2f( m_element[i].size, y );
           glVertex2f( m_element[i].size, m_element[i].size );
           glVertex2f( 0.0, m_element[i].size );
       }
       glEnd();

       glColor4fv( energy_foreground_color );

       glBegin( GL_QUADS );
       {
           glVertex2f( 0.0, 0.0 );
           glVertex2f( m_element[i].size, 0.0 );
           glVertex2f( m_element[i].size, y );
           glVertex2f( 0.0, y );
       }
       glEnd();

       /* Calculate the fraction of the speed bar to fill */
       speedbar_frac = 0.0;

       if ( speed > SPEEDBAR_GREEN_MAX_SPEED ) {
           speedbar_frac = SPEEDBAR_GREEN_FRACTION;
           
           if ( speed > SPEEDBAR_YELLOW_MAX_SPEED ) {
              speedbar_frac += SPEEDBAR_YELLOW_FRACTION;
              
              if ( speed > SPEEDBAR_RED_MAX_SPEED ) {
                  speedbar_frac += SPEEDBAR_RED_FRACTION;
              } else {
                  speedbar_frac +=
                     ( speed - SPEEDBAR_YELLOW_MAX_SPEED ) /
                     ( SPEEDBAR_RED_MAX_SPEED - SPEEDBAR_YELLOW_MAX_SPEED ) *
                     SPEEDBAR_RED_FRACTION;
              }

           } else {
              speedbar_frac += 
                  ( speed - SPEEDBAR_GREEN_MAX_SPEED ) /
                  ( SPEEDBAR_YELLOW_MAX_SPEED - SPEEDBAR_GREEN_MAX_SPEED ) *
                  SPEEDBAR_YELLOW_FRACTION;
           }
           
       } else {
           speedbar_frac +=  speed/SPEEDBAR_GREEN_MAX_SPEED * 
              SPEEDBAR_GREEN_FRACTION;
       }

       glColor4fv( speedbar_background_color );

       glBindTexture( GL_TEXTURE_2D, m_speedmaskTex );

       draw_partial_tri_fan( 1.0 );

       glColor4fv( white );

       draw_partial_tri_fan( MIN( 1.0, speedbar_frac ) );

       glColor4fv( white );

       glBindTexture( GL_TEXTURE_2D, m_outlineTex );

       glBegin( GL_QUADS );
       {
           glVertex2f( 0.0, 0.0 );
           glVertex2f( m_element[i].size, 0.0 );
           glVertex2f( m_element[i].size, m_element[i].size );
           glVertex2f( 0.0, m_element[i].size );
       }
       glEnd();
       
    }
    glPopMatrix();
       
       //we reset this because all other elements need TEXFONT
       set_gl_options( TEXFONT );
}

Here is the call graph for this function:

Here is the caller graph for this function:

void HUD::herring ( const int  i,
const int  herring_count 
) [private]

Definition at line 189 of file hud.cpp.

{
       if(m_element[i].font){
              char string[BUFF_LEN];
              sprintf( string, m_element[i].string.c_str(), herring_count );
              
              pp::Font::utf8ToUnicode(m_element[i].u_string,string);
              int width = int(m_element[i].font->advance(m_element[i].u_string));
              
              fix_xy(m_element[i].x,m_element[i].y,m_element[i].height,width);
              m_element[i].font->draw(m_element[i].u_string, m_element[i].x, m_element[i].y);            
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void HUD::icon_herring ( const int  i) [private]

Definition at line 669 of file hud.cpp.

{
       int m;
       m = i;

       if(players[0].herring >= gameMgr->getCurrentRace().herring_req[gameMgr->difficulty] && gameMgr->gametype!=GameMgr::PRACTICING)
              m_element[m].texture = m_element[i].texture2;

       image(m);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void HUD::icon_time ( const int  i) [private]

Definition at line 657 of file hud.cpp.

{
       int m;
       m = i;
       
       if(gameMgr->time > gameMgr->getCurrentRace().time_req[gameMgr->difficulty] && gameMgr->gametype!=GameMgr::PRACTICING)
              m_element[m].texture = m_element[i].texture2;
       
       image(m);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void HUD::image ( const int  i) [private]

Definition at line 204 of file hud.cpp.

{
       if(!m_element[i].texture) return;

       if ( !getparam_display_course_percentage() && m_element[i].texture == 47) {
              return;
       }

    glColor3f( 1.0, 1.0, 1.0 );

    glBindTexture( GL_TEXTURE_2D, m_element[i].texture );

       fix_xy( m_element[i].x, m_element[i].y, m_element[i].height, m_element[i].width);
       
    glPushMatrix();
    {
       glTranslatef( m_element[i].x, m_element[i].y,0);

       glBegin( GL_QUADS );
       {
              glTexCoord2f( 0, 0 );
           glVertex2f( 0, 0 );

           glTexCoord2f( double(m_element[i].width) / m_element[i].size,
                       0 );
           glVertex2f( m_element[i].width, 0 );

           glTexCoord2f( 
                     double(m_element[i].width) / m_element[i].size,
                     double(m_element[i].height) / m_element[i].size );
           glVertex2f( m_element[i].width, m_element[i].height );

           glTexCoord2f( 
                     0,
                     double(m_element[i].height) / m_element[i].size );
           glVertex2f( 0, m_element[i].height );
       }
       glEnd();
    }
    glPopMatrix();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void HUD::initGauge ( ) [private]

Definition at line 342 of file hud.cpp.

{
    const char *binding;
       
       binding = "gauge_energy_mask";
    if ( !get_texture_binding( binding, &m_energymaskTex ) ) {
              print_warning( IMPORTANT_WARNING,
                     "Couldn't get texture for binding %s", binding );
    }
       
       binding = "gauge_speed_mask";
    if ( !get_texture_binding( binding, &m_speedmaskTex ) ) {
              print_warning( IMPORTANT_WARNING,
                     "Couldn't get texture for binding %s", binding );
    }
           
       binding = "gauge_outline";
    if ( !get_texture_binding( binding, &m_outlineTex ) ) {
              print_warning( IMPORTANT_WARNING,
                     "Couldn't get texture for binding %s", binding );
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void HUD::objectives_herring ( const int  i,
bool  outline_font 
) [private]

Definition at line 621 of file hud.cpp.

{
    if(gameMgr->gametype!=GameMgr::PRACTICING ) {
        pp::Color green(0.0,1.0,0.0);
        pp::Color red(1.0,0.0,0.0);
        pp::Color black(0.0,0.0,0.0);
        
        int req_herring = -1;
        
       if(m_element[i].font){
            if(players[0].herring >= gameMgr->getCurrentRace().herring_req[gameMgr->difficulty]) {
                m_element[i].font->setColor(green);
                req_herring = 0;
            } else {
                m_element[i].font->setColor(red);
                req_herring = gameMgr->getCurrentRace().herring_req[gameMgr->difficulty] - players[0].herring;
            }
            
            if(outline_font) {
                m_element[i].font->setColor(black);
            }
        
              char string[BUFF_LEN];
              sprintf( string, m_element[i].string.c_str(), req_herring );
              
              pp::Font::utf8ToUnicode(m_element[i].u_string,string);
              int width = int(m_element[i].font->advance(m_element[i].u_string));
              
              fix_xy(m_element[i].x,m_element[i].y,m_element[i].height,width);
              m_element[i].font->draw(m_element[i].u_string, m_element[i].x-(width/2), m_element[i].y);         
              
       }      
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void HUD::objectives_time ( const int  i,
bool  outline_font 
) [private]

Definition at line 582 of file hud.cpp.

{
    if(gameMgr->gametype!=GameMgr::PRACTICING ) {
        int minsLeft = -1;
        int secsLeft = -1;
        int centsLeft = -1;
        pp::Color green(0.0,1.0,0.0);
        pp::Color red(1.0,0.0,0.0);
        pp::Color black(0.0,0.0,0.0);
            
       if(m_element[i].font){
            if(      gameMgr->time <= gameMgr->getCurrentRace().time_req[gameMgr->difficulty]) {
                m_element[i].font->setColor(green);
                getTimeComponents( gameMgr->getCurrentRace().time_req[gameMgr->difficulty] - gameMgr->time, minsLeft, secsLeft, centsLeft );
            } else {
                m_element[i].font->setColor(red);
                minsLeft = 0;
                secsLeft = 0;
                centsLeft = 0;
            }

            if(outline_font) {
                m_element[i].font->setColor(black);
            }

              char string[BUFF_LEN];
              sprintf( string, m_element[i].string.c_str(), minsLeft, secsLeft, centsLeft );
              
              pp::Font::utf8ToUnicode(m_element[i].u_string,string);
              int width = int(m_element[i].font->advance(m_element[i].u_string));
              
              fix_xy(m_element[i].x,m_element[i].y,m_element[i].height,width);
              m_element[i].font->draw(m_element[i].u_string, m_element[i].x-(width/2), m_element[i].y);         
              
       }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void HUD::reset ( void  )

Definition at line 55 of file hud.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void HUD::speed ( const int  i,
const double  speed 
) [private]

Definition at line 266 of file hud.cpp.

{
       if(m_element[i].font){
              char string[BUFF_LEN];
              sprintf( string, m_element[i].string.c_str(), speed );
              
              pp::Font::utf8ToUnicode(m_element[i].u_string,string);
              int width = int(m_element[i].font->advance(m_element[i].u_string));
              
              fix_xy(m_element[i].x,m_element[i].y,m_element[i].height,width);
              m_element[i].font->draw(m_element[i].u_string, m_element[i].x-(width/2), m_element[i].y);         
              
       }      
}

Here is the call graph for this function:

Here is the caller graph for this function:

void HUD::start_tri_fan ( void  ) [private]

Definition at line 537 of file hud.cpp.

{
    pp::Vec2d pt;

    glBegin( GL_TRIANGLE_FAN );
    glVertex2f( ENERGY_GAUGE_CENTER_X, 
              ENERGY_GAUGE_CENTER_Y );

    pt = calc_new_fan_pt( SPEEDBAR_BASE_ANGLE ); 

    glVertex2f( pt.x, pt.y );
}

Here is the call graph for this function:

Here is the caller graph for this function:

void HUD::text ( const int  i) [private]

Definition at line 158 of file hud.cpp.

{
    if(m_element[i].font){
              fix_xy(m_element[i].x, m_element[i].y,
                        m_element[i].height, m_element[i].width);
              
              m_element[i].font->draw(m_element[i].string.c_str(),
                               m_element[i].x, m_element[i].y);              
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void HUD::time ( const int  i) [private]

Definition at line 247 of file hud.cpp.

{
    if(m_element[i].font){
              char string[BUFF_LEN];
              int minutes, seconds, hundredths;
                  
              getTimeComponents( gameMgr->time, minutes, seconds, hundredths );
              sprintf( string, m_element[i].string.c_str(), minutes, seconds, hundredths);
              
              pp::Font::utf8ToUnicode(m_element[i].u_string,string);
              int width = int(m_element[i].font->advance(m_element[i].u_string));
              
              fix_xy(m_element[i].x,m_element[i].y,m_element[i].height,width);
              m_element[i].font->draw(m_element[i].u_string, m_element[i].x, m_element[i].y);            
       
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool HUD::update ( const int  i,
Element  newElement 
)

Definition at line 73 of file hud.cpp.

                                          {
       if( m_numElements > i ){
              m_element[i] = newElement;
              return true;  
       }else{
              //element i not available
              return false;
       }      
}

Here is the caller graph for this function:


Member Data Documentation

Definition at line 55 of file hud.h.

GLuint HUD::m_energymaskTex [private]

Definition at line 79 of file hud.h.

int HUD::m_numElements [private]

Definition at line 56 of file hud.h.

GLuint HUD::m_outlineTex [private]

Definition at line 81 of file hud.h.

GLuint HUD::m_speedmaskTex [private]

Definition at line 80 of file hud.h.


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