Back to index

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

#include <ssbutton.h>

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

List of all members.

Classes

struct  texture_region_t

Public Member Functions

 SSButton (pp::Vec2d pos, pp::Vec2d size, int num_states)
 ~SSButton ()
void performClickAction ()
void draw ()
int getState ()
void setState (int state)
void setStateImage (int state, const char *binding, pp::Vec2d ll, pp::Vec2d ur, pp::Color color)
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 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

int m_numStates
texture_region_tm_regions
int m_currentState

Detailed Description

Definition at line 32 of file ssbutton.h.


Class Documentation

struct pp::SSButton::texture_region_t

Definition at line 35 of file ssbutton.h.

Collaboration diagram for pp::SSButton::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::SSButton::SSButton ( pp::Vec2d  pos,
pp::Vec2d  size,
int  num_states 
)

Definition at line 33 of file ssbutton.cpp.

{
    m_position=pos;
       m_size= size;
    m_sensitive = true;
    m_visible = false;
    m_active = false;
       m_numStates = num_states;
       m_regions = new texture_region_t[num_states];

    for (int i=0; i<num_states; i++) {
              m_regions[i].binding = NULL;
    }

    m_currentState = 0;
}

Definition at line 50 of file ssbutton.cpp.

{
    setVisible( false );
    setActive( false );
    delete m_regions;       
}

Here is the call graph for this function:


Member Function Documentation

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

Implements pp::Widget.

Definition at line 88 of file ssbutton.cpp.

{
       GLuint texobj;
       
       glEnable( GL_TEXTURE_2D );
       
       if ( !get_texture_binding( m_regions[m_currentState].binding, &texobj ) ) {
              print_warning( IMPORTANT_WARNING,
                        "Couldnt get texture object for binding %s",
                        m_regions[m_currentState].binding );
           texobj = 0;
       }

       glBindTexture( GL_TEXTURE_2D, texobj );

       glColor4dv( (double*) &m_regions[m_currentState].color );

       glBegin( GL_QUADS );
       {
           glTexCoord2f( m_regions[m_currentState].ll.x, m_regions[m_currentState].ll.y );
           glVertex3f( m_position.x, m_position.y, 0 );

           glTexCoord2f( m_regions[m_currentState].ur.x, m_regions[m_currentState].ll.y );
           glVertex3f( m_position.x + m_size.x, m_position.y, 0 );

           glTexCoord2f( m_regions[m_currentState].ur.x, m_regions[m_currentState].ur.y );
           glVertex3f( m_position.x + m_size.x, m_position.y + m_size.y, 0 );

           glTexCoord2f( m_regions[m_currentState].ll.x, m_regions[m_currentState].ur.y );
           glVertex3f( m_position.x, m_position.y + m_size.y, 0 );
       }
       glEnd();

}

Here is the call 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:

int pp::SSButton::getState ( ) [inline]

Definition at line 57 of file ssbutton.h.

{return m_currentState;};

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:

Reimplemented from pp::Widget.

Definition at line 81 of file ssbutton.cpp.

Here is the call 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::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::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::SSButton::setState ( int  state)

Definition at line 58 of file ssbutton.cpp.

{
       m_currentState = state;

    if ( m_visible ) {
              UIMgr.setDirty();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pp::SSButton::setStateImage ( int  state,
const char *  binding,
pp::Vec2d  ll,
pp::Vec2d  ur,
pp::Color  color 
)

Definition at line 69 of file ssbutton.cpp.

{
       m_regions[state].binding = binding;
    m_regions[state].color = color;
    m_regions[state].ll = ll;
    m_regions[state].ur = ur;
}

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 48 of file ssbutton.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 46 of file ssbutton.h.

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

Definition at line 36 of file widget.h.

Definition at line 47 of file ssbutton.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.

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 84 of file widget.h.


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