Back to index

extremetuxracer  0.5beta
Classes | Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Private Attributes
pp::Button Class Reference

#include <button.h>

Inheritance diagram for pp::Button:
Inheritance graph
[legend]
Collaboration diagram for pp::Button:
Collaboration graph
[legend]

List of all members.

Classes

struct  texture_region_t

Public Member Functions

 Button (pp::Vec2d pos, pp::Vec2d size, const char *binding, const char *label)
void setHighlight (bool highlight)
void setHilitFontBinding (const char *binding)
void setDisabledFontBinding (const char *binding)
void setImage (const char *binding, pp::Vec2d p0, pp::Vec2d p1, pp::Color color)
void setDisabledImage (const char *binding, pp::Vec2d p0, pp::Vec2d p1, pp::Color color)
void setHilitImage (const char *binding, pp::Vec2d p0, pp::Vec2d p1, pp::Color color)
void setClickedImage (const char *binding, pp::Vec2d p0, pp::Vec2d p1, pp::Color color)
void draw ()
void setSensitive (bool sensitive)
bool getSensitive ()
void setVisible (bool visible)
void setActive (bool active)
void setPosition (pp::Vec2d pos)
bool isInBox (const int x, const int y) const
void mouseDown (int button, int x, int y)
void mouseUp (int button, int x, int y)
void mouseMotion (int x, int y)
virtual bool keyboardEvent (SDLKey key, SDLMod mod, bool release)
void removeFocus ()
void setFocus (bool focus=true)
bool hasFocus ()
void simulateMouseClick ()
double getWidth () const
double getHeight () const

Public Attributes

pp::Signal0 signalClicked
pp::Alignment alignment
 the alignment of the widgets.

Protected Member Functions

virtual void performClickAction ()

Protected Attributes

pp::Vec2d m_position
pp::Vec2d m_size
bool m_clicked
 is the box currently pushed down?
bool m_focused
 is the mouse pointer currently in the box?
bool m_sensitive
 is the widget sensitive (click event and font)
bool m_visible
 is the box being drawn by the UI manager?
bool m_active
 is the box receiving mouse events?
bool m_hasFocus

Private Attributes

texture_region_t m_tex
texture_region_t m_hilitTex
texture_region_t m_clickedTex
texture_region_t m_disabledTex
pp::Fontmp_font
pp::Fontmp_hilitFont
pp::Fontmp_disabledFont
const char * mp_label

Detailed Description

Definition at line 30 of file button.h.


Class Documentation

struct pp::Button::texture_region_t

Definition at line 31 of file button.h.

Collaboration diagram for pp::Button::texture_region_t:
Class Members
const char * binding name of texture binding
Color color color to use when drawing texture
Vec2d ll lower left
Vec2d ur upper right

Constructor & Destructor Documentation

pp::Button::Button ( pp::Vec2d  pos,
pp::Vec2d  size,
const char *  binding,
const char *  label 
)

Definition at line 29 of file button.cpp.

 :     mp_font(NULL),
       mp_hilitFont(NULL),
       mp_disabledFont(NULL)
{
    m_position = pos;
    m_size = size;

    m_tex.binding = NULL;
    m_hilitTex.binding = NULL;
    m_clickedTex.binding = NULL;
    m_disabledTex.binding = NULL;
       
       if(binding!=NULL){
              mp_font = pp::Font::get(binding);
       }
       
    mp_label = label;

    m_clicked = false;
    m_focused = false;
    m_sensitive = true;
    m_visible = false;
    m_active = false;
}

Here is the call graph for this function:


Member Function Documentation

void pp::Button::draw ( ) [virtual]

Implements pp::Widget.

Definition at line 118 of file button.cpp.

{
    GLuint texobj;
    texture_region_t *tex;
       pp::Font *font=mp_font;

    glEnable( GL_TEXTURE_2D );

    tex = NULL;
    
    if ( !m_sensitive ) {
              if ( m_disabledTex.binding ) {
                     tex = &m_disabledTex;
              } else if ( m_tex.binding ) {
                     tex = &m_tex;
              }

              if ( mp_disabledFont ) {
                     font = mp_disabledFont;
              }
    } else if ( m_clicked ) {
              if ( m_clickedTex.binding ) {
                     tex = &m_clickedTex;
              } else if ( m_hilitTex.binding ) {
                     tex = &m_hilitTex;
              } else if ( m_tex.binding ) {
                     tex = &m_tex;
              } 

              if ( mp_hilitFont) {
                     font = mp_hilitFont;
              } 
    } else if ( m_focused ) {
              if ( m_hilitTex.binding ) {
                     tex = &m_hilitTex;
              } else if ( m_tex.binding ) {
                     tex = &m_tex;
              } 

              if ( mp_hilitFont ) {
                     font = mp_hilitFont;
              }
    } else {
              if ( m_tex.binding ) {
                     tex = &m_tex;
              }
    }

    if ( tex != NULL ) {
       if ( !get_texture_binding( tex->binding, &texobj ) ) {
           print_warning( IMPORTANT_WARNING,
                        "Couldnt get texture object for binding %s",
                        tex->binding );
           texobj = 0;
       }

       glBindTexture( GL_TEXTURE_2D, texobj );

       glColor4dv( (double*) &tex->color );

       glBegin( GL_QUADS );
       {
           glTexCoord2f( tex->ll.x, tex->ll.y );
           glVertex3f( m_position.x, m_position.y, 0 );

           glTexCoord2f( tex->ur.x, tex->ll.y );
           glVertex3f( m_position.x + m_size.x, m_position.y, 0 );

           glTexCoord2f( tex->ur.x, tex->ur.y );
           glVertex3f( m_position.x + m_size.x, m_position.y + m_size.y, 0 );

           glTexCoord2f( tex->ll.x, tex->ur.y );
           glVertex3f( m_position.x, m_position.y + m_size.y, 0 );
       }
       glEnd();
    }

       if(mp_font!=NULL){
       
              float width = font->advance(mp_label);
              float asc = font->ascender();
              float desc = font->descender();
       
              font->draw(mp_label,
                            m_position.x + m_size.x/2.0 - width/2.0,
                            m_position.y + m_size.y/2.0 - asc/2.0 - desc/2.0);
       }    
}

Here is the call graph for this function:

Here is the caller graph for this function:

double pp::Widget::getHeight ( ) const [inline, inherited]

Definition at line 84 of file widget.h.

{return m_size.y;};

Here is the caller graph for this function:

bool pp::Widget::getSensitive ( ) [inline, inherited]

Definition at line 63 of file widget.h.

{ return m_sensitive; };

Here is the caller graph for this function:

double pp::Widget::getWidth ( ) const [inline, inherited]

Definition at line 83 of file widget.h.

{return m_size.x;};

Here is the caller graph for this function:

bool pp::Widget::hasFocus ( ) [inline, inherited]

Definition at line 77 of file widget.h.

{return m_hasFocus;};

Here is the caller graph for this function:

bool pp::Widget::isInBox ( const int  x,
const int  y 
) const [inherited]

Definition at line 96 of file widget.cpp.

{
    return (bool) (
       ( x >= m_position.x ) &&
       ( x <= m_position.x + m_size.x ) &&
       ( y >= m_position.y ) &&
       ( y <= m_position.y + m_size.y ) );
}

Here is the caller graph for this function:

virtual bool pp::Widget::keyboardEvent ( SDLKey  key,
SDLMod  mod,
bool  release 
) [inline, virtual, inherited]

Reimplemented in pp::Entry.

Definition at line 73 of file widget.h.

{return false;};

Here is the caller graph for this function:

void pp::Widget::mouseDown ( int  button,
int  x,
int  y 
) [inherited]

Definition at line 127 of file widget.cpp.

{
    if ( button != SDL_BUTTON_LEFT ) {
              return;
    }

    if ( !isInBox(x, y) ) {
              return;
    }

    if ( !m_sensitive ) {
              return;
    }

    if ( m_clicked == false ) {
              print_debug( DEBUG_UI, "Button is down" );
              m_clicked = true;
              UIMgr.setDirty();
    }
}

Here is the call graph for this function:

void pp::Widget::mouseMotion ( int  x,
int  y 
) [inherited]

Definition at line 106 of file widget.cpp.

{
    if ( !m_sensitive ) {
              return;
    }

    if ( isInBox(x, y) ) {
              if ( m_focused == false ) {
                     print_debug( DEBUG_UI, "Mouse entered button" );
                  m_focused = true;
                  UIMgr.setDirty();
              }
    } else {
              if ( m_focused == true ) {
                     print_debug( DEBUG_UI, "Mouse left button" );
                  m_focused = false;
                  UIMgr.setDirty();
              }
    }
}

Here is the call graph for this function:

void pp::Widget::mouseUp ( int  button,
int  x,
int  y 
) [inherited]

Definition at line 149 of file widget.cpp.

{
       if ( button != SDL_BUTTON_LEFT ) {
              return;
       }

    if ( !m_sensitive ) {
              return;
    }

    if ( !isInBox(x, y) ) {
              if ( m_clicked ) {
                  print_debug( DEBUG_UI, "Button is up (not clicked)" );
                  m_clicked = false;
                  UIMgr.setDirty();
              }
              return;
    } 

    if ( m_clicked ) {
              m_clicked = false;
              print_debug( DEBUG_UI, "Button was clicked" );
              performClickAction();
              UIMgr.setDirty();
    }
}

Here is the call graph for this function:

void pp::Widget::performClickAction ( ) [protected, virtual, inherited]

Reimplemented in pp::SSButton, and pp::Entry.

Definition at line 89 of file widget.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void pp::Widget::removeFocus ( ) [inherited]

Definition at line 183 of file widget.cpp.

{
       m_hasFocus=false;
}

Here is the caller graph for this function:

void pp::Widget::setActive ( bool  active) [inherited]

Definition at line 73 of file widget.cpp.

{
    if ( !m_active && active ) {
              UIMgr.setDirty();
    } else if ( m_active && !active ) {
              UIMgr.setDirty();
    }

    m_active = active;

    if ( !active ) {
              setVisible( false );
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pp::Button::setClickedImage ( const char *  binding,
pp::Vec2d  p0,
pp::Vec2d  p1,
pp::Color  color 
)

Definition at line 102 of file button.cpp.

{
    m_clickedTex.binding = binding;
    m_clickedTex.ll = p0;
    m_clickedTex.ur = p1;
    m_clickedTex.color = color;
}

Here is the caller graph for this function:

void pp::Button::setDisabledFontBinding ( const char *  binding)

Definition at line 112 of file button.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void pp::Button::setDisabledImage ( const char *  binding,
pp::Vec2d  p0,
pp::Vec2d  p1,
pp::Color  color 
)

Definition at line 73 of file button.cpp.

Here is the caller graph for this function:

void pp::Widget::setFocus ( bool  focus = true) [inherited]

Definition at line 189 of file widget.cpp.

{
       if(focus!=m_hasFocus){
              UIMgr.grabFocus(this,focus);
              m_hasFocus=focus;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pp::Button::setHighlight ( bool  highlight)

Definition at line 83 of file button.cpp.

{
    if (!(m_focused == highlight)) {
              UIMgr.setDirty();
    }
    m_focused = highlight;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pp::Button::setHilitFontBinding ( const char *  binding)

Definition at line 57 of file button.cpp.

{
       mp_hilitFont = pp::Font::get(binding);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pp::Button::setHilitImage ( const char *  binding,
pp::Vec2d  p0,
pp::Vec2d  p1,
pp::Color  color 
)

Definition at line 92 of file button.cpp.

{
    m_hilitTex.binding = binding;
    m_hilitTex.ll = p0;
    m_hilitTex.ur = p1;
    m_hilitTex.color = color;
}

Here is the caller graph for this function:

void pp::Button::setImage ( const char *  binding,
pp::Vec2d  p0,
pp::Vec2d  p1,
pp::Color  color 
)

Definition at line 63 of file button.cpp.

{
    m_tex.binding = binding;
    m_tex.ll = p0;
    m_tex.ur = p1;
    m_tex.color = color;
}

Here is the caller graph for this function:

void pp::Widget::setPosition ( pp::Vec2d  pos) [inline, inherited]
void pp::Widget::setSensitive ( bool  sensitive) [inherited]

Reimplemented in pp::Listbox< T >, pp::Listbox< multisample_t >, pp::Listbox< bpp_t >, pp::Listbox< button_t >, pp::Listbox< bps_t >, pp::Listbox< CourseData >, pp::Listbox< resolution_t >, pp::Listbox< model_t >, pp::Listbox< freq_t >, pp::Listbox< CupData >, pp::Listbox< HighscoreData >, and pp::Listbox< EventData >.

Definition at line 42 of file widget.cpp.

{
       if ( m_sensitive != sensitive ) {
              UIMgr.setDirty();
    }

    m_sensitive = sensitive;

    if ( !m_sensitive ) {
              m_clicked = false;
              m_focused = false;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pp::Widget::setVisible ( bool  visible) [inherited]

Definition at line 57 of file widget.cpp.

{
    /* This check is necessary to prevent infinite mutual recursion */
    if ( m_active != visible ) {
              setActive( visible );
    }

    if ( !m_visible && visible ) {
              UIMgr.setDirty();
    } else if ( m_visible && !visible ) {
              UIMgr.setDirty();
    }
    m_visible = visible;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pp::Widget::simulateMouseClick ( ) [inherited]

Definition at line 177 of file widget.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

the alignment of the widgets.

Definition at line 90 of file widget.h.

bool pp::Widget::m_active [protected, inherited]

is the box receiving mouse events?

Definition at line 52 of file widget.h.

bool pp::Widget::m_clicked [protected, inherited]

is the box currently pushed down?

Definition at line 40 of file widget.h.

Definition at line 44 of file button.h.

Definition at line 45 of file button.h.

bool pp::Widget::m_focused [protected, inherited]

is the mouse pointer currently in the box?

Definition at line 43 of file widget.h.

bool pp::Widget::m_hasFocus [protected, inherited]

Definition at line 54 of file widget.h.

Definition at line 43 of file button.h.

pp::Vec2d pp::Widget::m_position [protected, inherited]

Definition at line 36 of file widget.h.

bool pp::Widget::m_sensitive [protected, inherited]

is the widget sensitive (click event and font)

Definition at line 46 of file widget.h.

pp::Vec2d pp::Widget::m_size [protected, inherited]

Definition at line 37 of file widget.h.

Definition at line 42 of file button.h.

bool pp::Widget::m_visible [protected, inherited]

is the box being drawn by the UI manager?

Definition at line 49 of file widget.h.

Definition at line 49 of file button.h.

Definition at line 47 of file button.h.

Definition at line 48 of file button.h.

const char* pp::Button::mp_label [private]

Definition at line 51 of file button.h.

Definition at line 84 of file widget.h.


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